/* =========================================================
   Project Hope — shared styles
   Breakpoints: 640px (auth/landing), 960px (app sidebar), 1200px (home 2-col)

   THEMING: every color lives in the tokens below. Components only use
   var(--token), so light/dark switch by changing <html data-theme="…">.
   Never hard-code a color in a component file — add a token instead.
   ========================================================= */

:root {
  color-scheme: light;

  /* Brand */
  --brand: #315f4d;          /* primary buttons, selected states */
  --brand-hover: #264f3e;
  --on-brand: #ffffff;       /* text on --brand */
  --accent: #315f4d;         /* links, icons, focus */
  --banner: #315f4d;         /* profile banner, fuel bar */
  --banner-deep: #244838;

  /* Surfaces (back to front) */
  --page: #f4f6f1;           /* app background */
  --sidebar: #eaf0e9;
  --surface: #fcfdfb;        /* cards */
  --surface-2: #f2f6f0;      /* inputs, inset buttons */
  --surface-tint: #e8f0e7;   /* soft green feature cards */
  --soft: #e1ece3;           /* hover / chips */
  --soft-strong: #d6e5d9;    /* active nav, selected chips */

  /* Text */
  --ink: #24342d;
  --body: #4f5f57;
  --muted: #6b7a72;
  --subtle: #8b968f;

  /* Lines */
  --line: #e3e9e1;
  --border: #d5ded3;
  --border-strong: #b9cdbf;

  /* Status */
  --success: #1f8a4c;
  --danger: #c93c3c;
  --warm: #d9b87e;           /* week-strip accent dot */
  --cool: #9dbda4;

  /* Chat */
  --chat-bg: #f1f5ef;
  --bubble-in: #ffffff;
  --bubble-in-border: #e0e7de;
  --bubble-out: #315f4d;
  --bubble-out-ink: #ffffff;

  /* Effects */
  --ring: rgba(49, 95, 77, .22);
  --shadow-sm: 0 1px 2px rgba(31, 52, 42, .05);
  --shadow: 0 8px 30px rgba(31, 52, 42, .05);
  --shadow-lg: 0 20px 50px rgba(17, 28, 23, .18);
  --scrim: rgba(17, 28, 23, .45);

  --font: "DM Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --serif: "DM Serif Display", Georgia, serif;
}

html[data-theme="dark"] {
  color-scheme: dark;

  --brand: #3e7560;
  --brand-hover: #4a8470;
  --on-brand: #ffffff;
  --accent: #9fcbb0;
  --banner: #2a4c3e;
  --banner-deep: #1b3229;

  --page: #131a17;
  --sidebar: #18211d;
  --surface: #1c2622;
  --surface-2: #232e29;
  --surface-tint: #1f2c26;
  --soft: #26352e;
  --soft-strong: #2d4037;

  --ink: #e6ede8;
  --body: #c3cfc7;
  --muted: #9eaca3;
  --subtle: #7d8b83;

  --line: #2a3530;
  --border: #33413a;
  --border-strong: #46594f;

  --success: #6fd394;
  --danger: #f07a7a;
  --warm: #c9a76c;
  --cool: #7fa68b;

  --chat-bg: #161e1b;
  --bubble-in: #222d28;
  --bubble-in-border: #2e3b35;
  --bubble-out: #3a6b56;
  --bubble-out-ink: #f4f8f5;

  --ring: rgba(159, 203, 176, .28);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .25);
  --shadow: 0 8px 30px rgba(0, 0, 0, .22);
  --shadow-lg: 0 20px 50px rgba(0, 0, 0, .5);
  --scrim: rgba(0, 0, 0, .6);
}

/* ---------- Reset / base ---------- */
*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; }
html { -webkit-text-size-adjust: 100%; background: var(--page); }
body {
  font-family: var(--font);
  color: var(--ink);
  background: var(--page);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: inherit; }
ul, ol { padding: 0; list-style: none; }
[hidden] { display: none !important; }
[tabindex="-1"]:focus { outline: none; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}
.desktop-only { display: none !important; }

.icon {
  width: 22px; height: 22px; flex: none;
  fill: none; stroke: currentColor; stroke-width: 1.75;
  stroke-linecap: round; stroke-linejoin: round;
}
.icon-sm { width: 18px; height: 18px; stroke-width: 2; }

/* Smooth theme switch (only after first paint; see app.js) */
html.theme-ready body, html.theme-ready body * {
  transition: background-color .2s ease, border-color .2s ease, color .2s ease;
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 40px; padding: 0 18px;
  border: 1px solid transparent; border-radius: 10px;
  font-size: 15px; font-weight: 600; text-decoration: none; white-space: nowrap;
}
.btn-primary { background: var(--brand); color: var(--on-brand); }
.btn-primary:hover { background: var(--brand-hover); }
.btn-outline { background: var(--surface); color: var(--ink); border-color: var(--border); }
.btn-outline:hover { background: var(--surface-2); }
.btn-block { width: 100%; height: 44px; }
.btn-wide { padding: 0 40px; height: 40px; }

.brand {
  font-weight: 700; font-size: 20px; letter-spacing: -0.035em;
  text-decoration: none; color: var(--accent);
}

/* ---------- Form controls ---------- */
input[type="text"], input[type="email"], input[type="password"], input[type="date"], select, textarea {
  width: 100%; height: 40px; padding: 0 14px;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px;
  font-size: 16px; color: var(--ink);
}
textarea { height: auto; padding: 10px 14px; resize: vertical; line-height: 1.5; }
::placeholder { color: var(--subtle); opacity: 1; }
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--ring);
}

/* =========================================================
   Landing
   ========================================================= */
.landing { min-height: 100dvh; display: flex; flex-direction: column; background: var(--page); }
.site-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 20px; gap: 12px;
}
.site-nav { display: flex; gap: 12px; }
.site-header .btn { height: 34px; padding: 0 14px; font-size: 14px; border-radius: 8px; }

.hero {
  flex: 1; display: flex; flex-direction: column; justify-content: center;
  text-align: center; padding: 24px 24px 72px; width: 100%; max-width: 760px; margin: 0 auto;
}
.hero h1 {
  font-family: var(--serif); font-weight: 400;
  font-size: clamp(32px, 7vw, 54px); letter-spacing: -0.02em; line-height: 1.12;
  text-wrap: balance;
}
.hero p { color: var(--muted); font-size: 16px; margin: 16px auto 36px; max-width: 560px; }

.email-form {
  display: flex; width: 100%; max-width: 560px; margin: 0 auto;
  border: 1px solid var(--border-strong); border-radius: 12px; overflow: hidden;
  background: var(--surface); box-shadow: var(--shadow);
}
.email-form:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--ring); }
.email-form input[type="email"] {
  flex: 1; min-width: 0; height: 48px; padding: 0 16px;
  border: 0; border-radius: 0; background: transparent; box-shadow: none; font-size: 16px;
}
.email-form input:focus { box-shadow: none; }
.email-form .btn { height: auto; border-radius: 0; padding: 0 20px; }

.site-footer { padding: 20px; text-align: center; color: var(--subtle); font-size: 13px; }

/* =========================================================
   Auth (login + sign up)
   ========================================================= */
.auth { min-height: 100dvh; display: flex; justify-content: center; padding: 72px 24px 32px; background: var(--page); }
.auth-card { width: 100%; max-width: 480px; }
.auth-card h1 { font-family: var(--serif); font-size: 32px; font-weight: 400; text-align: center; letter-spacing: -0.01em; }
.auth-sub { text-align: center; color: var(--muted); margin: 4px 0 28px; font-size: 16px; }

.field { margin-bottom: 16px; min-width: 0; }
.field--tight { margin-bottom: 0; }
.field label, .field legend { display: block; font-size: 15px; font-weight: 500; margin-bottom: 8px; padding: 0; }
.req { color: var(--muted); margin-left: 2px; }
fieldset { border: 0; padding: 0; min-width: 0; }

.field-row { display: grid; gap: 16px; margin-bottom: 16px; }
.field-row .field { margin-bottom: 0; }
.date-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.date-row select { padding: 0 10px; }

.forgot {
  display: block; width: fit-content; margin: 8px 0 24px auto;
  color: var(--accent); font-size: 15px; text-decoration: underline; text-underline-offset: 2px;
}
.field--group { margin: 4px 0 24px; }
.auth-foot { text-align: center; color: var(--muted); font-size: 15px; margin-top: 20px; }
.auth-foot a { color: var(--accent); font-weight: 600; text-decoration: underline; text-underline-offset: 2px; }

/* =========================================================
   App shell (mobile: header / content / bottom tab bar)
   ========================================================= */
.app {
  position: relative; height: 100dvh; background: var(--page);
  display: grid; grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr) auto;
}
.sidebar { display: contents; }
.sidebar .brand { display: none; }

.topbar {
  grid-row: 1; position: relative; height: 52px; padding: 0 20px;
  display: flex; align-items: center; justify-content: center;
  background: var(--sidebar); border-bottom: 1px solid var(--line); z-index: 30;
}
.topbar-title { font-size: 19px; font-weight: 700; letter-spacing: -0.03em; color: var(--accent); }
.app:not([data-current="profile"]) .menu-wrap { display: none; }

.menu-wrap { position: absolute; right: 12px; top: 50%; transform: translateY(-50%); }
.menu-btn {
  display: grid; place-items: center; width: 38px; height: 38px;
  background: transparent; border: 1px solid transparent; border-radius: 10px; color: var(--ink);
}
.menu-btn:hover { background: var(--soft); }
.menu-btn[aria-expanded="true"] { background: var(--soft-strong); border-color: var(--border-strong); color: var(--accent); }
.menu {
  position: absolute; right: 0; top: calc(100% + 8px); width: 184px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  box-shadow: var(--shadow-lg); overflow: hidden;
}
.menu li + li { border-top: 1px solid var(--line); }
.menu button {
  display: block; width: 100%; text-align: left; padding: 12px 16px;
  background: none; border: 0; font-size: 15px; font-weight: 500; color: var(--ink);
}
.menu button:hover, .menu button:focus-visible { background: var(--soft); outline-offset: -2px; }
.menu .is-danger { color: var(--danger); }

.content { grid-row: 2; min-width: 0; overflow-y: auto; display: flex; flex-direction: column; background: var(--page); }

/* Bottom tab bar */
.nav {
  grid-row: 3; display: grid; grid-template-columns: repeat(4, 1fr); justify-items: center;
  padding: 8px 12px calc(8px + env(safe-area-inset-bottom)); gap: 4px;
  background: var(--sidebar); border-top: 1px solid var(--line);
}
.nav a {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  min-width: 68px; padding: 8px 12px 6px; border-radius: 12px;
  font-size: 12px; font-weight: 500; color: var(--muted); text-decoration: none;
}
.nav a:hover:not([aria-current]) { color: var(--ink); }
.nav a[aria-current="page"] { background: var(--soft-strong); color: var(--accent); font-weight: 600; }

/* ---------- Pages ---------- */
.page { flex: 1 0 auto; display: flex; flex-direction: column; padding: 24px 20px 28px; background: var(--page); color: var(--ink); }
.page-head { margin-bottom: 20px; }
.page-head h2 {
  font-family: var(--serif); font-weight: 400;
  font-size: 26px; letter-spacing: -0.01em; line-height: 1.2; color: var(--ink);
}
.page-head p { color: var(--muted); font-size: 14px; margin-top: 4px; }

/* ---------- Dialog + toast ---------- */
dialog {
  width: min(92vw, 460px); padding: 24px; border: 1px solid var(--border); border-radius: 18px;
  background: var(--surface); color: var(--ink); box-shadow: var(--shadow-lg);
}
dialog::backdrop { background: var(--scrim); }
dialog h2 { font-family: var(--serif); font-weight: 400; font-size: 24px; margin-bottom: 16px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 8px; }

.toast {
  position: fixed; left: 50%; bottom: 92px; z-index: 100;
  transform: translate(-50%, 12px); opacity: 0; pointer-events: none;
  max-width: calc(100vw - 40px); padding: 10px 16px;
  background: var(--ink); color: var(--page); border-radius: 10px; font-size: 14px; font-weight: 500;
  box-shadow: var(--shadow-lg);
  transition: opacity .2s, transform .2s !important;
}
.toast.is-visible { opacity: 1; transform: translate(-50%, 0); }

@media (prefers-reduced-motion: reduce) {
  *, html.theme-ready body * { transition: none !important; }
}

/* =========================================================
   >= 640px — landing / auth get desktop treatment
   ========================================================= */
@media (min-width: 640px) {
  .site-header { padding: 0 28px; height: 64px; border-bottom: 1px solid var(--line); background: var(--sidebar); }
  .site-header .btn { height: 36px; padding: 0 20px; font-size: 15px; }
  .hero p { font-size: 17px; }
  .email-form input[type="email"] { height: 54px; }
  .email-form .btn { padding: 0 28px; font-size: 16px; }

  .auth { align-items: center; padding: 40px 24px; }
  .auth-card {
    max-width: 470px; padding: 40px; background: var(--surface);
    border: 1px solid var(--border); border-radius: 20px; box-shadow: var(--shadow);
  }
  .auth-card--narrow { max-width: 400px; }
  .field-row { grid-template-columns: 1fr 1fr; }
}

/* =========================================================
   >= 960px — sidebar layout
   ========================================================= */
@media (min-width: 960px) {
  .desktop-only { display: block !important; }
  .mobile-only { display: none !important; }

  .app { grid-template-columns: 216px minmax(0, 1fr); grid-template-rows: minmax(0, 1fr); }

  .sidebar {
    display: block; grid-column: 1; grid-row: 1; padding: 24px 20px;
    background: var(--sidebar); border-right: 1px solid var(--line);
  }
  .sidebar .brand { display: block; }
  .nav {
    display: flex; flex-direction: column; justify-items: stretch; gap: 6px;
    margin-top: 36px; padding: 0; background: none; border: 0;
  }
  .nav a {
    flex-direction: row; gap: 12px; min-width: 0; padding: 0 12px; height: 38px;
    font-size: 15px; border-radius: 10px;
  }
  .nav a:hover:not([aria-current]) { background: var(--soft); }

  /* Header collapses to just the profile menu button */
  .topbar {
    position: absolute; top: 24px; right: 24px; height: auto; padding: 0;
    background: none; border: 0; z-index: 30;
  }
  .topbar-title { display: none; }
  .menu-wrap { position: relative; right: auto; top: auto; transform: none; }
  .menu-btn { width: 40px; height: 40px; background: var(--surface); border-color: var(--border); color: var(--accent); }

  .content { grid-column: 2; grid-row: 1; }

  .page { padding: 28px; }
  .page-head { margin-bottom: 24px; }
  .page-head h2 { font-size: 30px; }
  .page-head p { font-size: 15px; }

  .toast { bottom: 28px; }
}
