:root {
  --primary: #00A69C;
  --primary-dark: #007A72;
  --primary-light: #35C1BC;
  --navy: #0B1D3A;
  --bg: #F7FBFA;
  --surface: #FFFFFF;
  --surface-2: #E8F5F3;
  --text: #222B45;
  --text-2: #3F4946;
  --text-3: #6F7976;
  --border: #BEC9C5;
  --error: #BA1A1A;
  --success: #166534;
  --radius: 16px;
  --radius-sm: 12px;
  --radius-full: 9999px;
  --shadow: 0 4px 24px rgba(11,29,58,0.08);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Montserrat", sans-serif;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --nav-h: 64px;
  --topbar-h: 56px;
  --sidebar-w: 240px;
  --content-max: 480px;
  --page-pad-x: 16px;
  --page-pad-y: 16px;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html {
  height: 100%;
  -webkit-text-size-adjust: 100%;
  scroll-behavior: auto;
}
html, body {
  height: 100%;
  overflow: hidden; /* fixed-viewport: no document scroll */
}
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  line-height: 1.5;
  height: 100dvh;
  max-height: 100dvh;
  display: flex;
  flex-direction: column;
}

a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
img { max-width: 100%; display: block; }

/* ========== APP SHELL ========== */
.app-shell {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-height: 100dvh;
  overflow: hidden;
  width: 100%;
  max-width: 100%;
  margin: 0 auto;
  background: var(--bg);
}

/* Full-bleed screens (splash, onboarding, landing, auth) opt out */
body.full-bleed {
  overflow: auto;
  height: auto;
  min-height: 100dvh;
  display: block;
}
body.full-bleed .app-shell { height: auto; max-height: none; overflow: visible; }

/* Top bar — fixed height inside shell */
.topbar {
  flex-shrink: 0;
  height: calc(var(--topbar-h) + var(--safe-t));
  padding: var(--safe-t) var(--page-pad-x) 0;
  background: rgba(247,251,250,0.96);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  z-index: 40;
  width: 100%;
}
.topbar .brand,
.topbar > .brand {
  display: flex; align-items: center; gap: 8px;
  font-weight: 700; font-size: 1.05rem; color: var(--navy);
  height: var(--topbar-h);
}
.brand img, .brand .logo-img { width: 28px; height: 28px; object-fit: contain; }
.topbar-actions { display: flex; gap: 8px; align-items: center; height: var(--topbar-h); }

/* Scrollable content region between top and bottom */
.app-content {
  flex: 1 1 auto;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  width: 100%;
  min-height: 0; /* critical for flex scroll */
}

.page {
  max-width: var(--content-max);
  margin: 0 auto;
  padding: var(--page-pad-y) var(--page-pad-x) 24px;
  width: 100%;
}

/* Bottom tab bar */
.bottom-nav {
  flex-shrink: 0;
  height: calc(var(--nav-h) + var(--safe-b));
  padding-bottom: var(--safe-b);
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-around;
  align-items: center;
  box-shadow: 0 -4px 20px rgba(11,29,58,0.06);
  z-index: 50;
  width: 100%;
}
.bottom-nav a, .bottom-nav button {
  flex: 1;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 3px;
  font-size: 0.65rem; font-weight: 600;
  color: var(--text-3);
  height: 100%;
  min-height: 44px;
  position: relative;
}
.bottom-nav a.active, .bottom-nav button.active { color: var(--primary); }
.bottom-nav i { font-size: 1.25rem; }
.bottom-nav .badge {
  position: absolute; top: 6px; right: calc(50% - 18px);
  background: var(--error); color: #fff;
  font-size: 0.6rem; font-weight: 700;
  min-width: 16px; height: 16px; border-radius: 99px;
  display: flex; align-items: center; justify-content: center;
}

/* Drawer */
.drawer-overlay {
  position: fixed; inset: 0; z-index: 60;
  background: rgba(11,29,58,0.45);
  opacity: 0; pointer-events: none;
  transition: opacity 0.25s;
}
.drawer-overlay.open { opacity: 1; pointer-events: auto; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 70;
  width: min(320px, 85vw);
  background: var(--surface);
  box-shadow: -8px 0 30px rgba(11,29,58,0.12);
  transform: translateX(100%);
  transition: transform 0.28s cubic-bezier(0.22,1,0.36,1);
  display: flex; flex-direction: column;
  padding-top: var(--safe-t);
}
.drawer.open { transform: translateX(0); }
.drawer-header {
  padding: 20px 20px 16px;
  display: flex; align-items: center; justify-content: space-between;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.drawer-nav { flex: 1; overflow-y: auto; padding: 12px 0; min-height: 0; }
.drawer-nav a {
  display: flex; align-items: center; gap: 14px;
  padding: 14px 20px;
  font-weight: 500; font-size: 0.95rem; color: var(--text);
}
.drawer-nav a:active { background: var(--surface-2); }
.drawer-nav i { width: 22px; text-align: center; color: var(--primary); }
.drawer-footer {
  padding: 16px 20px calc(16px + var(--safe-b));
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 14px 22px; border-radius: var(--radius-full);
  font-weight: 600; font-size: 0.95rem;
  transition: transform 0.12s, opacity 0.12s;
  min-height: 48px;
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-secondary { background: var(--surface); color: var(--primary); border: 1.5px solid var(--primary); }
.btn-ghost { background: transparent; color: var(--primary); }
.btn-block { width: 100%; }
.btn:disabled { opacity: 0.55; pointer-events: none; }

/* Cards & typography */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  border: 1px solid rgba(190,201,197,0.4);
}
.section-title {
  font-size: 1.35rem; font-weight: 800; color: var(--navy);
  margin-bottom: 6px;
}
.section-lead { color: var(--text-2); font-size: 0.95rem; margin-bottom: 20px; }

.empty {
  text-align: center; padding: 48px 20px; color: var(--text-3);
}
.empty i { font-size: 2.5rem; color: var(--primary); margin-bottom: 12px; opacity: 0.7; display: block; }

.hide { display: none !important; }
.text-center { text-align: center; }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }

/* Sheets / Modals */
.sheet-overlay {
  position: fixed; inset: 0; z-index: 80;
  background: rgba(11,29,58,0.45);
  opacity: 0; pointer-events: none;
  transition: opacity 0.25s;
}
.sheet-overlay.open { opacity: 1; pointer-events: auto; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 90;
  max-height: 90dvh;
  background: var(--surface);
  border-radius: 20px 20px 0 0;
  box-shadow: 0 -8px 40px rgba(11,29,58,0.15);
  transform: translateY(100%);
  transition: transform 0.3s cubic-bezier(0.22,1,0.36,1);
  display: flex; flex-direction: column;
  padding-bottom: var(--safe-b);
}
.sheet.open { transform: translateY(0); }
.sheet-handle {
  width: 40px; height: 4px; border-radius: 99px;
  background: var(--border); margin: 10px auto 0; flex-shrink: 0;
}
.sheet-header {
  padding: 16px 20px 12px;
  display: flex; align-items: center; justify-content: space-between;
  border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.sheet-header h3 { font-size: 1.1rem; font-weight: 700; color: var(--navy); }
.sheet-body { flex: 1; overflow-y: auto; padding: 16px 20px 24px; min-height: 0; }
.sheet-footer {
  padding: 12px 20px;
  border-top: 1px solid var(--border);
  display: flex; gap: 10px; flex-shrink: 0;
}
@media (min-width: 600px) {
  .sheet {
    left: 50%; right: auto; bottom: auto; top: 50%;
    width: min(440px, 92vw);
    max-height: 85vh;
    border-radius: 20px;
    transform: translate(-50%, -40%) scale(0.96);
    opacity: 0;
  }
  .sheet.open { transform: translate(-50%, -50%) scale(1); opacity: 1; }
  .sheet-handle { display: none; }
}

/* Forms */
.field { margin-bottom: 16px; }
.field label {
  display: block; font-size: 0.82rem; font-weight: 600;
  color: var(--text-2); margin-bottom: 6px;
}
.field input, .field select, .field textarea {
  width: 100%; padding: 14px 16px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 16px; background: var(--surface); color: var(--text);
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none; border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(0,166,156,0.15);
}
.field-error { color: var(--error); font-size: 0.8rem; margin-top: 4px; display: none; }
.field.has-error input, .field.has-error select { border-color: var(--error); }
.field.has-error .field-error { display: block; }

/* Status pills */
.status-pill {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 0.75rem; font-weight: 700;
  padding: 6px 12px; border-radius: 99px;
  text-transform: uppercase;
}
.status-pill.confirmed, .status-pill.upcoming { background: #E0F2FE; color: #0369A1; }
.status-pill.in_progress { background: #FEF3C7; color: #92400E; }
.status-pill.completed { background: #DCFCE7; color: #166534; }
.status-pill.cancelled { background: #FEE2E2; color: #991B1B; }
.status-pill.pending { background: var(--surface-2); color: var(--text-3); }

.list-row {
  display: flex; align-items: center; gap: 14px;
  padding: 14px 0; border-bottom: 1px solid var(--border);
}
.list-row:last-child { border-bottom: none; }
.list-row .icon-box {
  width: 44px; height: 44px; border-radius: 12px;
  background: rgba(0,166,156,0.12); color: var(--primary);
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.list-row .meta { flex: 1; min-width: 0; }
.list-row .meta strong { display: block; font-size: 0.95rem; color: var(--navy); }
.list-row .meta span { font-size: 0.82rem; color: var(--text-3); }

/* Loading */
.loading-center {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 48px 20px; color: var(--text-3); gap: 12px;
}

/* ========== Tablet ========== */
@media (min-width: 600px) {
  :root {
    --content-max: 640px;
    --page-pad-x: 24px;
    --page-pad-y: 24px;
  }
  .brand { font-size: 1.1rem; }
  .brand img { width: 32px; height: 32px; }
  .section-title { font-size: 1.5rem; }
  .section-lead { font-size: 1rem; }
  .card { padding: 24px; }
  .bottom-nav a, .bottom-nav button { font-size: 0.7rem; gap: 4px; }
  .bottom-nav i { font-size: 1.35rem; }
  .btn { min-height: 50px; padding: 14px 24px; font-size: 1rem; }
}

/* ========== Desktop: sidebar ========== */
@media (min-width: 900px) {
  :root {
    --content-max: 1100px;
    --page-pad-x: 36px;
    --page-pad-y: 32px;
    --nav-h: 0px;
  }
  body {
    background: #eef4f2;
  }
  .app-shell {
    flex-direction: row;
    height: 100dvh;
  }
  /* Sidebar from bottom-nav */
  .bottom-nav {
    position: relative;
    width: var(--sidebar-w);
    height: 100dvh;
    flex-direction: column;
    justify-content: flex-start;
    align-items: stretch;
    padding: 24px 12px 20px;
    border-top: none;
    border-right: 1px solid var(--border);
    box-shadow: 4px 0 24px rgba(11,29,58,0.04);
    gap: 4px;
  }
  .bottom-nav::before {
    content: "TerraCelest";
    display: block;
    font-weight: 800;
    font-size: 1.05rem;
    color: var(--navy);
    padding: 8px 14px 20px;
    margin-bottom: 8px;
    border-bottom: 1px solid var(--border);
  }
  .bottom-nav a, .bottom-nav button {
    flex: 0 0 auto;
    flex-direction: row;
    justify-content: flex-start;
    gap: 12px;
    padding: 12px 14px;
    border-radius: 12px;
    font-size: 0.9rem;
    min-height: 48px;
    height: auto;
    color: var(--text-2);
  }
  .bottom-nav a:hover { background: var(--surface-2); color: var(--navy); }
  .bottom-nav a.active {
    background: rgba(0,166,156,0.12);
    color: var(--primary);
  }
  .bottom-nav i { font-size: 1.15rem; width: 22px; text-align: center; }
  .bottom-nav .badge { position: static; margin-left: auto; }

  .app-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    height: 100dvh;
    overflow: hidden;
  }
  .topbar #btnDrawer, .topbar-actions #btnDrawer { display: none !important; }
  .drawer-overlay, .drawer { display: none !important; }
  .page { max-width: var(--content-max); margin: 0 auto; padding: var(--page-pad-y) var(--page-pad-x) 48px; }
  .card { padding: 28px; border-radius: 18px; }
  .section-title { font-size: 1.65rem; }
  .btn { min-height: 52px; padding: 15px 28px; font-size: 1rem; }
}

@media (min-width: 1200px) {
  :root { --sidebar-w: 260px; --content-max: 1200px; --page-pad-x: 48px; }
}
@media (min-width: 1400px) {
  :root { --content-max: 1280px; }
}
