:root {
  --radius-sm: 10px;
  --radius-md: 16px;
  --radius-lg: 24px;
  --radius-full: 999px;
  --space-1: 8px;
  --space-2: 16px;
  --space-3: 24px;
  --space-4: 32px;
  --space-5: 48px;
  --font: "DM Sans", system-ui, -apple-system, sans-serif;
  --topbar-h: 56px;
  --bottom-nav-h: 72px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

:root,
[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0c1222;
  --bg-elevated: #131b2e;
  --bg-card: #1a2438;
  --bg-input: #0f1729;
  --border: rgba(255, 255, 255, 0.08);
  --border-focus: rgba(20, 184, 166, 0.6);
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --text-subtle: #64748b;
  --accent: #14b8a6;
  --accent-hover: #2dd4bf;
  --accent-soft: rgba(20, 184, 166, 0.12);
  --accent-glow: rgba(20, 184, 166, 0.25);
  --danger: #f87171;
  --warning: #fbbf24;
  --success: #34d399;
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.35);
  --shadow-glow: 0 0 40px var(--accent-glow);
  --topbar-bg: rgba(12, 18, 34, 0.85);
  --bottom-nav-bg: rgba(12, 18, 34, 0.92);
  --hero-glow-1: rgba(20, 184, 166, 0.15);
  --hero-glow-2: rgba(8, 145, 178, 0.1);
  --btn-primary-text: #042f2e;
}

[data-theme="light"] {
  color-scheme: light;
  --bg: #f8fafc;
  --bg-elevated: #ffffff;
  --bg-card: #ffffff;
  --bg-input: #f1f5f9;
  --border: rgba(15, 23, 42, 0.1);
  --border-focus: rgba(13, 148, 136, 0.55);
  --text: #0f172a;
  --text-muted: #475569;
  --text-subtle: #64748b;
  --accent: #0d9488;
  --accent-hover: #14b8a6;
  --accent-soft: rgba(13, 148, 136, 0.1);
  --accent-glow: rgba(13, 148, 136, 0.18);
  --danger: #dc2626;
  --warning: #d97706;
  --success: #059669;
  --shadow: 0 8px 32px rgba(15, 23, 42, 0.1);
  --shadow-glow: 0 0 40px var(--accent-glow);
  --topbar-bg: rgba(248, 250, 252, 0.92);
  --bottom-nav-bg: rgba(248, 250, 252, 0.95);
  --hero-glow-1: rgba(13, 148, 136, 0.12);
  --hero-glow-2: rgba(8, 145, 178, 0.08);
  --btn-primary-text: #ffffff;
}

*, *::before, *::after { box-sizing: border-box; }

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100dvh;
  overflow-x: hidden;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  background:
    radial-gradient(ellipse 80% 50% at 50% -20%, var(--hero-glow-1), transparent),
    radial-gradient(ellipse 60% 40% at 100% 100%, var(--hero-glow-2), transparent);
  pointer-events: none;
  z-index: 0;
}

.hidden { display: none !important; }

.app {
  position: relative;
  z-index: 1;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding-top: calc(var(--topbar-h) + var(--safe-top));
  padding-bottom: calc(var(--bottom-nav-h) + var(--safe-bottom));
}

.app--no-nav { padding-bottom: var(--safe-bottom); }

/* Topbar */
.topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
  height: calc(var(--topbar-h) + var(--safe-top));
  padding: var(--safe-top) var(--space-2) 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--topbar-bg);
  backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border);
}

.topbar__brand {
  display: flex;
  align-items: center;
  gap: var(--space-1);
}

.topbar__logo {
  width: 32px;
  height: 32px;
  color: var(--accent);
}

.topbar__name {
  font-weight: 700;
  font-size: 1.125rem;
  letter-spacing: -0.02em;
}

.topbar__actions {
  display: flex;
  align-items: center;
  gap: var(--space-1);
}

/* Main */
.main {
  flex: 1;
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  padding: var(--space-2);
}

/* Bottom nav */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 100;
  height: calc(var(--bottom-nav-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  display: flex;
  align-items: stretch;
  justify-content: space-around;
  background: var(--bottom-nav-bg);
  backdrop-filter: blur(16px);
  border-top: 1px solid var(--border);
}

.bottom-nav__item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  border: none;
  background: none;
  color: var(--text-subtle);
  font: inherit;
  font-size: 0.6875rem;
  font-weight: 500;
  cursor: pointer;
  min-height: 48px;
  transition: color 0.2s;
}

.bottom-nav__item svg {
  width: 22px;
  height: 22px;
}

.bottom-nav__item.active,
.bottom-nav__item--active {
  color: var(--accent);
}

@media (hover: hover) and (pointer: fine) {
  .bottom-nav__item:hover { color: var(--text-muted); }
  .bottom-nav__item.active:hover,
  .bottom-nav__item--active:hover { color: var(--accent-hover); }
}

/* Typography */
h1, h2, h3 {
  margin: 0 0 var(--space-2);
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.2;
}

h1 { font-size: clamp(1.75rem, 5vw, 2rem); }
h2 { font-size: 1.25rem; }
h3 { font-size: 1rem; }

p { margin: 0 0 var(--space-2); color: var(--text-muted); }

.lead {
  font-size: 1rem;
  color: var(--text-muted);
  margin-bottom: var(--space-3);
}

.section-title {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-subtle);
  margin: var(--space-3) 0 var(--space-1);
}

/* Cards */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--space-2);
  margin-bottom: var(--space-2);
}

.card--glow {
  box-shadow: var(--shadow-glow);
  border-color: rgba(20, 184, 166, 0.2);
}

.card--interactive {
  cursor: pointer;
  transition: transform 0.15s, border-color 0.15s, box-shadow 0.15s;
}

@media (hover: hover) and (pointer: fine) {
  .card--interactive:hover {
    transform: translateY(-2px);
    border-color: rgba(20, 184, 166, 0.3);
    box-shadow: var(--shadow);
  }
}

.card__header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-1);
  margin-bottom: var(--space-1);
}

.card__title {
  font-weight: 600;
  font-size: 1rem;
  margin: 0;
}

.card__meta {
  font-size: 0.8125rem;
  color: var(--text-subtle);
}

/* Service grid */
.service-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--space-1);
}

.service-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: var(--space-1);
  padding: var(--space-2);
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  cursor: pointer;
  text-align: left;
  color: inherit;
  font: inherit;
  min-height: 120px;
  transition: transform 0.15s, border-color 0.15s;
}

.service-card__icon {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--accent-soft);
  border-radius: var(--radius-sm);
  color: var(--accent);
  font-size: 1.25rem;
  line-height: 1;
}

.service-card__icon svg {
  width: 22px;
  height: 22px;
}

.service-card__name {
  font-weight: 600;
  font-size: 0.9375rem;
}

.service-card__price {
  font-size: 0.75rem;
  color: var(--text-subtle);
  margin-top: auto;
}

@media (hover: hover) and (pointer: fine) {
  .service-card:hover {
    transform: translateY(-2px);
    border-color: rgba(20, 184, 166, 0.35);
  }
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-1);
  min-height: 48px;
  padding: 0 var(--space-3);
  border: none;
  border-radius: var(--radius-full);
  font: inherit;
  font-size: 0.9375rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s, opacity 0.15s;
  text-decoration: none;
}

.btn:active { transform: scale(0.98); }

.btn--primary {
  background: linear-gradient(135deg, var(--accent), #0891b2);
  color: var(--btn-primary-text);
  box-shadow: 0 4px 20px var(--accent-glow);
}

@media (hover: hover) and (pointer: fine) {
  .btn--primary:hover { filter: brightness(1.08); }
}

.btn--secondary {
  background: var(--bg-elevated);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn--ghost {
  background: transparent;
  color: var(--text-muted);
  min-height: 40px;
  padding: 0 var(--space-2);
}

.btn--danger {
  background: rgba(248, 113, 113, 0.15);
  color: var(--danger);
}

.btn--sm {
  min-height: 36px;
  padding: 0 var(--space-2);
  font-size: 0.8125rem;
}

.btn--block { width: 100%; }

.btn--icon {
  width: 40px;
  min-width: 40px;
  padding: 0;
  border-radius: var(--radius-sm);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.btn-row {
  display: flex;
  gap: var(--space-1);
  flex-wrap: wrap;
  margin-top: var(--space-2);
}

.btn-row .btn { flex: 1; min-width: 120px; }

/* Forms */
.form-group {
  margin-bottom: var(--space-2);
}

.form-label {
  display: block;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.form-input,
.form-textarea,
.form-select {
  width: 100%;
  min-height: 48px;
  padding: 12px var(--space-2);
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font: inherit;
  font-size: 1rem;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.form-textarea {
  min-height: 96px;
  resize: vertical;
}

.form-input:focus,
.form-textarea:focus,
.form-select:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.form-hint {
  font-size: 0.75rem;
  color: var(--text-subtle);
  margin-top: 6px;
}

/* Status badges */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: var(--radius-full);
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.badge--pending,
.badge--pending_match { background: rgba(251, 191, 36, 0.15); color: var(--warning); }
.badge--confirmed { background: var(--accent-soft); color: var(--accent); }
.badge--awaiting_provider { background: rgba(251, 191, 36, 0.15); color: var(--warning); }
.badge--awaiting_payment { background: rgba(56, 189, 248, 0.15); color: #38bdf8; }
.badge--on_way { background: rgba(56, 189, 248, 0.15); color: #38bdf8; }
.badge--arrived { background: rgba(56, 189, 248, 0.2); color: #7dd3fc; }
.badge--in_progress { background: rgba(56, 189, 248, 0.15); color: #38bdf8; }
.badge--completed { background: rgba(52, 211, 153, 0.15); color: var(--success); }
.badge--cancelled,
.badge--cancel { background: rgba(248, 113, 113, 0.15); color: var(--danger); }

/* Hero / landing */
.hero {
  text-align: center;
  padding: var(--space-4) 0 var(--space-3);
}

.eyebrow {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--accent);
  margin: 0 0 var(--space-1);
}

.hero__title {
  font-size: clamp(1.75rem, 5vw, 2.25rem);
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.15;
  margin: 0 0 var(--space-2);
}

.hero__lead {
  font-size: 1rem;
  color: var(--text-muted);
  max-width: 320px;
  margin: 0 auto var(--space-3);
  line-height: 1.5;
}

/* Role picker */
.role-grid {
  display: grid;
  gap: var(--space-1);
  margin-bottom: var(--space-3);
}

.role-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  padding: var(--space-2);
  background: var(--bg-card);
  border: 2px solid var(--border);
  border-radius: var(--radius-md);
  cursor: pointer;
  text-align: left;
  color: inherit;
  font: inherit;
  transition: border-color 0.15s, transform 0.15s;
}

.role-card strong {
  font-weight: 600;
  font-size: 1rem;
}

.role-card span:last-child {
  font-size: 0.8125rem;
  color: var(--text-subtle);
}

.role-card__icon {
  font-size: 1.5rem;
  line-height: 1;
  margin-bottom: 4px;
}

@media (hover: hover) and (pointer: fine) {
  .role-card:hover {
    border-color: rgba(20, 184, 166, 0.35);
    transform: translateY(-2px);
  }
}

.role-card:active {
  transform: scale(0.98);
}

/* Page layout */
.page-title {
  font-size: 1.375rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin: 0 0 var(--space-2);
}

.page-sub {
  font-size: 0.9375rem;
  color: var(--text-muted);
  margin: -8px 0 var(--space-2);
}

.back-link {
  margin-bottom: var(--space-1);
  padding-left: 0;
}

/* Forms (app.js field stack) */
.form-stack {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field__label {
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text-muted);
}

.field__input {
  width: 100%;
  min-height: 48px;
  padding: 12px var(--space-2);
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font: inherit;
  font-size: 1rem;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.field__textarea {
  min-height: 96px;
  resize: vertical;
}

.field__input:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.form-msg {
  font-size: 0.875rem;
  color: var(--text-muted);
  margin: 0;
  min-height: 1.25em;
}

.price-chip {
  display: inline-block;
  padding: 8px 14px;
  background: var(--accent-soft);
  border: 1px solid rgba(20, 184, 166, 0.25);
  border-radius: var(--radius-full);
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--accent);
  margin-bottom: var(--space-2);
}

/* Service card selected state */
.service-card--selected {
  border-color: var(--accent) !important;
  background: var(--accent-soft);
  box-shadow: var(--shadow-glow);
}

.service-card strong {
  font-weight: 600;
  font-size: 0.9375rem;
}

.service-card small {
  font-size: 0.75rem;
  color: var(--text-subtle);
  margin-top: auto;
}

/* Job / booking cards */
.card-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.job-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--space-2);
}

.job-card__head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-1);
  margin-bottom: var(--space-1);
}

.job-card__head strong {
  font-weight: 600;
  font-size: 0.9375rem;
}

.job-card__meta {
  font-size: 0.8125rem;
  color: var(--text-subtle);
  margin: 0 0 4px;
}

.job-card__actions {
  display: flex;
  gap: var(--space-1);
  flex-wrap: wrap;
  margin-top: var(--space-1);
}

/* Stats grid (admin) */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--space-1);
  margin-bottom: var(--space-3);
}

.stat {
  padding: var(--space-2);
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  text-align: center;
}

.stat strong {
  display: block;
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--accent);
  line-height: 1;
}

.stat span {
  display: block;
  font-size: 0.75rem;
  color: var(--text-subtle);
  margin-top: 4px;
}

/* Provider bar */
.provider-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  margin-bottom: var(--space-2);
}

.provider-bar .page-title {
  margin: 0;
}

.toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.875rem;
  color: var(--text-muted);
  cursor: pointer;
  white-space: nowrap;
}

.toggle input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

/* Profile */
.profile-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--space-2);
}

.profile-card p {
  margin: 0 0 8px;
}

.profile-card p:last-child {
  margin-bottom: 0;
}

/* Empty state */
.empty-state {
  text-align: center;
  padding: var(--space-5) var(--space-2);
  color: var(--text-subtle);
  font-size: 0.9375rem;
}

/* Install banner */
.install-banner {
  position: fixed;
  bottom: calc(var(--bottom-nav-h) + var(--safe-bottom) + var(--space-1));
  left: var(--space-2);
  right: var(--space-2);
  z-index: 200;
  max-width: 448px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: var(--space-1);
  padding: var(--space-1) var(--space-2);
  background: var(--bg-card);
  border: 1px solid rgba(20, 184, 166, 0.3);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow);
}

.install-banner__text {
  flex: 1;
  min-width: 0;
}

.install-banner__text strong {
  display: block;
  font-size: 0.875rem;
}

.install-banner__text span {
  font-size: 0.75rem;
  color: var(--text-subtle);
}

/* Toast */
.toast {
  position: fixed;
  bottom: calc(var(--bottom-nav-h) + var(--safe-bottom) + var(--space-2));
  left: 50%;
  transform: translateX(-50%);
  z-index: 300;
  padding: 12px var(--space-2);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  font-size: 0.875rem;
  box-shadow: var(--shadow);
  max-width: calc(100% - 32px);
  text-align: center;
}

/* Booking detail */
.detail-row {
  display: flex;
  justify-content: space-between;
  gap: var(--space-2);
  padding: var(--space-1) 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.875rem;
}

.detail-row:last-child { border-bottom: none; }

.detail-row__label { color: var(--text-subtle); }

.price-range {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--accent);
}

/* Loading */
.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  margin: var(--space-4) auto;
}

@keyframes spin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

@media (min-width: 481px) {
  .main { padding: var(--space-3); }
  .service-grid { grid-template-columns: repeat(3, 1fr); }
}

.app--admin {
  padding-bottom: var(--safe-bottom);
}

.app--admin .main {
  max-width: 960px;
}

.admin-nav {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: var(--space-2);
  margin-bottom: var(--space-1);
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.admin-nav::-webkit-scrollbar { display: none; }

.admin-nav__item {
  flex: 0 0 auto;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-muted);
  border-radius: var(--radius-full);
  padding: 8px 14px;
  font: inherit;
  font-size: 0.8125rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}

.admin-nav__item--active {
  background: var(--accent-soft);
  border-color: rgba(20, 184, 166, 0.4);
  color: var(--accent);
}

.stats-grid--4 {
  grid-template-columns: repeat(4, 1fr);
}

@media (max-width: 640px) {
  .stats-grid--4 { grid-template-columns: repeat(2, 1fr); }
}

.admin-form-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--space-2);
  margin-bottom: var(--space-3);
}

.price-row {
  display: grid;
  grid-template-columns: 1fr 80px auto 80px;
  gap: 8px;
  align-items: center;
  font-size: 0.875rem;
  margin-bottom: 8px;
}

.field__input--sm {
  min-height: 40px;
  padding: 8px 10px;
  font-size: 0.875rem;
}

.live-map {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--space-2);
}

.live-map__pin {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.8125rem;
}

.live-map__pin:last-child { border-bottom: none; }

.live-map__pin strong { font-size: 0.875rem; }

.live-map__pin span { color: var(--text-subtle); }

/* Theme toggle */
.theme-toggle {
  position: relative;
  color: var(--text-muted);
}

.theme-toggle__icon {
  width: 20px;
  height: 20px;
}

.theme-toggle__icon--sun {
  display: none;
}

[data-theme="dark"] .theme-toggle__icon--sun {
  display: block;
}

[data-theme="dark"] .theme-toggle__icon--moon {
  display: none;
}

[data-theme="light"] .theme-toggle__icon--sun {
  display: none;
}

[data-theme="light"] .theme-toggle__icon--moon {
  display: block;
}

.profile-theme {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  margin-top: var(--space-2);
}

.profile-theme__label {
  font-size: 0.9375rem;
  font-weight: 500;
  margin: 0;
  color: var(--text);
}

.profile-theme__hint {
  font-size: 0.8125rem;
  color: var(--text-subtle);
  margin: 4px 0 0;
}
