:root {
  --bg: #f3f6f9;
  --surface: #ffffff;
  --surface-2: #eef2f6;
  --ink: #0f1c2b;
  --ink-2: #4a5a6c;
  --ink-3: #7a8899;
  --line: #dbe2ea;
  --navy: #0d1b2a;
  --ice: #2b8fd6;
  --ice-soft: #e2f1fc;
  --orange: #e8730c;          /* Type I fluid */
  --orange-soft: #fff0e2;
  --green: #1f8a4c;           /* Type IV fluid */
  --green-soft: #e3f5ea;
  --red: #c8352f;
  --red-soft: #fde9e8;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(15, 28, 43, .06), 0 4px 14px rgba(15, 28, 43, .05);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0a1420;
    --surface: #111e2d;
    --surface-2: #172838;
    --ink: #e6edf4;
    --ink-2: #a9b7c6;
    --ink-3: #7d8c9c;
    --line: #22364a;
    --ice: #59b4f2;
    --ice-soft: #12304a;
    --orange: #ff9a3d;
    --orange-soft: #3a2410;
    --green: #4cc47e;
    --green-soft: #12301f;
    --red: #ff6b63;
    --red-soft: #3a1514;
    --shadow: 0 1px 2px rgba(0,0,0,.3);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  min-height: 100vh;
}
a { color: var(--ice); }
img { display: block; }
h1, h2, h3 { line-height: 1.2; margin: 0; letter-spacing: -.01em; }
[hidden] { display: none !important; }

.wrap { max-width: 880px; margin: 0 auto; padding: 20px 16px 80px; outline: none; }

/* ---------- Top bar ---------- */
.topbar { background: var(--navy); color: #fff; position: sticky; top: 0; z-index: 20; padding-top: env(safe-area-inset-top); }
.topbar-inner { max-width: 880px; margin: 0 auto; padding: 10px 16px; display: flex; align-items: center; gap: 16px; }
.brand { display: flex; align-items: center; gap: 10px; color: #fff; text-decoration: none; font-size: 17px; white-space: nowrap; }
.brand b { font-weight: 700; }
.nav { display: flex; gap: 4px; margin-left: auto; }
.nav a { color: #c5d3e2; text-decoration: none; padding: 8px 12px; border-radius: 10px; font-size: 15px; font-weight: 500; position: relative; white-space: nowrap; }
.nav a:hover { color: #fff; background: rgba(255,255,255,.08); }
.nav a.active { color: #fff; background: rgba(255,255,255,.14); }
.badge { display: inline-block; min-width: 20px; padding: 0 6px; border-radius: 10px; background: var(--orange); color: #fff; font-size: 12px; line-height: 20px; text-align: center; font-weight: 700; margin-left: 4px; }
.me { flex: none; border-radius: 50%; outline-offset: 2px; text-decoration: none; }
.me.active .avatar { box-shadow: 0 0 0 2px #7fd3ff; }

@media (max-width: 640px) {
  .topbar-inner { flex-wrap: wrap; gap: 8px 12px; }
  .brand span { font-size: 16px; }
  .me { margin-left: auto; }
  .nav { order: 3; width: 100%; margin: 0 -4px; }
  .nav a { flex: 1; text-align: center; padding: 8px 6px; font-size: 14px; }
}

/* ---------- Avatars ---------- */
.avatar { width: 40px; height: 40px; border-radius: 50%; object-fit: cover; flex: none; background: var(--ice-soft); color: var(--ice); display: grid; place-items: center; font-weight: 700; font-size: 15px; }
.avatar.sm { width: 32px; height: 32px; font-size: 13px; }
.avatar.lg { width: 88px; height: 88px; font-size: 30px; }

/* ---------- Common ---------- */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin: 4px 0 16px; flex-wrap: wrap; }
.page-head h1 { font-size: 26px; }
.page-head p { margin: 4px 0 0; color: var(--ink-2); }

.notice { display: flex; gap: 10px; align-items: flex-start; background: var(--orange-soft); color: var(--ink); border: 1px solid color-mix(in srgb, var(--orange) 30%, transparent); padding: 10px 14px; border-radius: 12px; font-size: 14px; margin-bottom: 18px; }
.notice svg { flex: none; margin-top: 2px; color: var(--orange); }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.panel { padding: 20px; }

.btn { appearance: none; border: 1px solid transparent; border-radius: 10px; padding: 9px 16px; font: inherit; font-size: 15px; font-weight: 600; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 6px; text-decoration: none; line-height: 1.3; white-space: nowrap; }
.btn:disabled { opacity: .55; cursor: default; }
.btn-primary { background: var(--ice); color: #fff; }
.btn-primary:hover:not(:disabled) { filter: brightness(1.07); }
.btn-ghost { background: transparent; color: var(--ink); border-color: var(--line); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-2); }
.btn-soft { background: var(--ice-soft); color: var(--ice); }
.btn-danger { background: transparent; color: var(--red); border-color: color-mix(in srgb, var(--red) 35%, transparent); }
.btn-danger:hover { background: var(--red-soft); }
.btn-sm { padding: 6px 12px; font-size: 14px; border-radius: 9px; }
.btn-block { width: 100%; }

:focus-visible { outline: 2px solid var(--ice); outline-offset: 2px; }

/* ---------- Forms ---------- */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field label, .label { font-size: 14px; font-weight: 600; color: var(--ink-2); }
.field .hint { font-size: 13px; color: var(--ink-3); }
input, select, textarea {
  font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--line);
  border-radius: 10px; padding: 10px 12px; width: 100%; min-width: 0;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--ice); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ice) 20%, transparent); }
textarea { resize: vertical; min-height: 84px; }
.row { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; }
.row .field { margin-bottom: 14px; }
.form-error { background: var(--red-soft); color: var(--red); border-radius: 10px; padding: 10px 12px; font-size: 14px; margin-bottom: 14px; }

.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip-btn { border: 1px solid var(--line); background: var(--surface); color: var(--ink-2); border-radius: 999px; padding: 6px 12px; font: inherit; font-size: 14px; cursor: pointer; }
.chip-btn:hover { border-color: var(--ice); color: var(--ice); }

.segmented { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.segmented label { position: relative; cursor: pointer; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented span { display: block; text-align: center; padding: 10px 6px; border: 1px solid var(--line); border-radius: 10px; font-size: 14px; font-weight: 600; color: var(--ink-2); background: var(--surface); }
.segmented input:checked + span { border-color: var(--ice); background: var(--ice-soft); color: var(--ice); }
.segmented input:focus-visible + span { outline: 2px solid var(--ice); outline-offset: 2px; }

/* ---------- Auth ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; background:
  radial-gradient(1200px 500px at 50% -10%, #1d3a57 0%, transparent 60%), var(--navy); }
.auth-card { width: 100%; max-width: 420px; }
.auth-brand { text-align: center; color: #fff; margin-bottom: 20px; }
.auth-brand img { margin: 0 auto 12px; }
.auth-brand h1 { font-size: 26px; }
.auth-brand p { margin: 6px 0 0; color: #a9bdd1; font-size: 15px; }
.auth .card { padding: 24px; }
.auth-switch { text-align: center; margin: 16px 0 0; font-size: 14px; color: var(--ink-2); }
.photo-pick { display: flex; align-items: center; gap: 14px; }
.photo-pick .avatar { width: 64px; height: 64px; font-size: 22px; }

/* ---------- Board ---------- */
.filters { display: grid; grid-template-columns: 2fr 1fr 1fr; gap: 10px; margin-bottom: 8px; }
.filters-foot { display: flex; justify-content: space-between; align-items: center; margin-bottom: 18px; font-size: 14px; color: var(--ink-2); gap: 12px; flex-wrap: wrap; }
.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--ice); }
@media (max-width: 720px) {
  .filters { grid-template-columns: 1fr 1fr; }
  .filters .search { grid-column: 1 / -1; }
}

.day { margin-bottom: 22px; }
.day-head { display: flex; align-items: baseline; gap: 10px; margin: 0 2px 10px; }
.day-head h2 { font-size: 16px; }
.day-head span { color: var(--ink-3); font-size: 14px; }
.list { display: grid; gap: 10px; }

.trade { padding: 14px 16px; display: grid; grid-template-columns: auto 1fr auto; gap: 4px 14px; align-items: start; }
.trade.is-mine { border-left: 4px solid var(--ice); }
.trade.is-closed { opacity: .7; }
.trade .who { font-weight: 600; }
.trade .time { font-size: 20px; font-weight: 700; letter-spacing: -.01em; font-variant-numeric: tabular-nums; }
.trade .meta { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.trade .notes { margin: 8px 0 0; color: var(--ink-2); font-size: 15px; white-space: pre-wrap; overflow-wrap: anywhere; }
.trade .actions { display: flex; flex-direction: column; gap: 6px; align-items: stretch; }
.trade .sub { color: var(--ink-3); font-size: 13px; }
@media (max-width: 560px) {
  .trade { grid-template-columns: auto 1fr; }
  .trade .actions { grid-column: 1 / -1; flex-direction: row; flex-wrap: wrap; margin-top: 8px; }
  .trade .actions .btn { flex: 1; }
}

.tag { display: inline-flex; align-items: center; gap: 4px; font-size: 12.5px; font-weight: 600; padding: 3px 9px; border-radius: 999px; background: var(--surface-2); color: var(--ink-2); }
.tag-day { background: #fff6d6; color: #8a6400; }
.tag-night { background: #e6e4ff; color: #4b3fb5; }
@media (prefers-color-scheme: dark) {
  .tag-day { background: #3a3110; color: #f2cf63; }
  .tag-night { background: #25224a; color: #aca4ff; }
}
.tag-swap { background: var(--ice-soft); color: var(--ice); }
.tag-giveaway { background: var(--orange-soft); color: var(--orange); }
.tag-either { background: var(--green-soft); color: var(--green); }
.tag-closed { background: var(--surface-2); color: var(--ink-3); }

.empty { text-align: center; padding: 48px 20px; color: var(--ink-2); }
.empty h2 { font-size: 18px; color: var(--ink); margin-bottom: 6px; }
.empty p { margin: 0 0 16px; }

/* ---------- My trades ---------- */
.section-title { font-size: 18px; margin: 26px 0 12px; display: flex; align-items: center; gap: 8px; }
.section-title:first-of-type { margin-top: 8px; }
.interested { grid-column: 1 / -1; margin-top: 12px; border-top: 1px solid var(--line); padding-top: 12px; display: grid; gap: 10px; }
.interested .person { display: flex; gap: 10px; align-items: flex-start; }
.interested .person .msg { margin: 2px 0 0; color: var(--ink-2); font-size: 14px; white-space: pre-wrap; overflow-wrap: anywhere; }
.interested .none { color: var(--ink-3); font-size: 14px; }

/* ---------- Profile ---------- */
.profile-grid { display: grid; gap: 16px; }
.profile-top { display: flex; align-items: center; gap: 18px; margin-bottom: 18px; }

/* ---------- Dialog ---------- */
dialog { border: none; border-radius: 16px; padding: 0; width: min(460px, calc(100vw - 32px)); background: var(--surface); color: var(--ink); box-shadow: 0 20px 60px rgba(0,0,0,.3); }
dialog::backdrop { background: rgba(8, 16, 26, .55); }
dialog form { padding: 22px; }
dialog h2 { font-size: 19px; margin-bottom: 8px; }
dialog p { margin: 0 0 14px; color: var(--ink-2); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }

/* ---------- Toast ---------- */
.toast { position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); background: var(--navy); color: #fff; padding: 10px 18px; border-radius: 12px; font-size: 15px; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 50; max-width: calc(100vw - 32px); }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: var(--red); }

.loading { color: var(--ink-3); padding: 40px 0; text-align: center; }
.date-label { margin: 0 2px 6px; }
.pw-title { font-size: 18px; margin-bottom: 14px; }
.signout-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.segmented.shifts { grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); }
.segmented small { display: block; font-weight: 500; font-size: 13px; opacity: .85; font-variant-numeric: tabular-nums; }
.forgot-link { align-self: flex-end; text-decoration: none; color: var(--ice); }
.auth-title { font-size: 20px; margin-bottom: 6px; }
.auth-sub { margin: 0 0 16px; color: var(--ink-2); font-size: 15px; }
.contact { margin-top: 10px; padding: 10px 12px; border-radius: 10px; background: var(--surface-2); font-size: 14.5px; display: grid; gap: 3px; user-select: text; }
.contact.compact { margin-top: 4px; padding: 6px 10px; }
.contact-title { font-weight: 600; margin-bottom: 2px; }
.contact-row { display: flex; gap: 8px; overflow-wrap: anywhere; }
.contact-key { color: var(--ink-3); min-width: 44px; flex: none; }
.contact-hint { margin: 8px 0 0; }
.tag-assignment { background: var(--ice-soft); color: var(--ice); }
.segmented small.assignment { font-weight: 600; opacity: 1; }
.phone-callout { border: 1px solid color-mix(in srgb, var(--ice) 45%, transparent); background: var(--ice-soft); border-radius: 12px; padding: 14px 14px 2px; margin-bottom: 16px; }
.phone-callout input { background: var(--surface); }
.important-badge { display: inline-block; margin-left: 6px; padding: 1px 8px; border-radius: 999px; background: var(--ice); color: #fff; font-size: 12px; font-weight: 700; vertical-align: 1px; }
.phone-why { font-size: 14px; color: var(--ink); font-weight: 500; }
.resend-btn { margin-top: 8px; display: flex; }
.form-error .resend-btn { margin-top: 10px; }
.email-current { margin: -6px 0 12px; }
