/* ==========================================================================
   Tailored Properties — shared.css
   One file, CSS custom properties, no preprocessor, no build step.

   MOBILE FIRST, both shells. The owner is a phone user too — they have a day
   job and check this between other things — so .shell-staff is NOT a desktop
   layout with a hamburger fallback. Below 768px it gets the same bottom tab bar
   the resident shell uses.
   ========================================================================== */

/* --------------------------------------------------------------------------
   Tokens
   -------------------------------------------------------------------------- */
:root {
  color-scheme: light;

  /* ------------------------------------------------------------------------
     THEMING LIVES HERE AND ONLY HERE.
     Nothing in this block controls size or position, so changing a colour
     cannot move the layout. Spacing, radii and the shell dimensions are at the
     bottom and are shared by both themes.
     ------------------------------------------------------------------------ */

  /* Neutrals carry a trace of warmth on purpose. A page that is mostly cards
     in pure #ffffff reads as a lightbox; an off-white surface on a slightly
     deeper field reads as paper, and the card edges stop needing a hard
     border to be legible. */
  --n-0:#ffffff;
  --n-25:#fcfcfd;
  --n-50:#f7f8fa;
  --n-100:#eef0f4;
  --n-200:#e3e6ec;
  --n-300:#cfd4dd;
  --n-400:#9aa2b1;
  --n-500:#6b7484;
  --n-600:#4d5563;
  --n-700:#363d49;
  --n-800:#232935;
  --n-900:#151a23;

  --bg:            var(--n-100);
  --surface:       var(--n-25);
  --surface-2:     var(--n-50);
  --border:        var(--n-200);
  --border-strong: var(--n-300);
  /* Body text is n-800, not n-900. Near-black on near-white measures 17.8:1,
     which is well past the point of diminishing returns and is the single
     biggest source of eye strain in a screen someone reads all day. This is
     14.2:1 — still far above AA, noticeably calmer. */
  --text:          var(--n-800);
  --text-muted:    var(--n-500);

  /* TWO ROLES, TWO TOKENS. `--ok` is a TEXT colour, used on `--ok-bg`.
     `--ok-fill` is a SOLID BACKGROUND, used with `--fill-text` on top.
     They were one token before, which is exactly why dark mode broke: a colour
     dark enough for white text is far too dark to read against a dark tint. */
  --ok:#137a43;      --ok-bg:#e2f4e9;      --ok-fill:#137a43;
  --warn:#96560a;    --warn-bg:#fbf0da;    --warn-fill:#b0670c;
  --danger:#b3201f;  --danger-bg:#fbe4e3;  --danger-fill:#c02725;
  --info:#1f4bc4;    --info-bg:#e4eafc;    --info-fill:#1f4bc4;
  --fill-text:#ffffff;

  /* A toast sits above everything, so it inverts against the page rather than
     borrowing a surface colour that would vanish in one theme or the other. */
  --toast-bg:   var(--n-800);
  --toast-text: var(--n-25);

  /* The landlord's own colours, set from /api/me.
     shared.js writes --brand-raw, NOT --brand: an inline custom property beats
     every stylesheet rule, so writing --brand directly would make it
     impossible for the dark theme to lighten it. Derived tokens stay in CSS
     where a theme can still reach them. */
  --brand-raw:#1e40af;
  --brand-2-raw:#3b82f6;
  --brand:          var(--brand-raw);
  --brand-2:        var(--brand-2-raw);
  --brand-contrast: var(--brand-on-light, #ffffff);

  --s1:4px; --s2:8px; --s3:12px; --s4:16px; --s5:24px; --s6:32px; --s7:40px; --s8:48px;
  --r-sm:6px; --r:10px; --r-lg:16px; --r-full:999px;

  --shadow-1: 0 1px 2px rgba(21,26,35,.05);
  --shadow-2: 0 2px 8px rgba(21,26,35,.07);
  --shadow-3: 0 12px 32px rgba(21,26,35,.14);

  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  --tabbar-h: 64px;
  --topbar-h: 56px;
  --sidebar-w: 240px;
}

/* --------------------------------------------------------------------------
   Dark.
   Applied by attribute, not by media query, because the toggle has to be able
   to override the operating system — plenty of people run a dark OS and still
   want a light spreadsheet. shared.js sets data-theme synchronously on every
   page, resolving "system" to a concrete value.

   Status colours are LIGHTENED here, which the previous dark theme did not do:
   it left #15803d green text on a #052e16 green tint, a contrast ratio of 2.97
   against a 4.5 floor. The pills were unreadable.
   -------------------------------------------------------------------------- */
:root[data-theme="dark"] {
  color-scheme: dark;

  --bg:            #0f1319;
  --surface:       #171c24;
  --surface-2:     #1e242e;
  --border:        #272e3a;
  --border-strong: #3a4453;
  --text:          #e6eaf0;
  --text-muted:    #98a2b3;

  --ok:#5fd48b;      --ok-bg:#0e2c1c;      --ok-fill:#1a7f4b;
  --warn:#f5bd4e;    --warn-bg:#33260a;    --warn-fill:#a86a12;
  --danger:#fa8b86;  --danger-bg:#361618;  --danger-fill:#c23b38;
  --info:#79aefb;    --info-bg:#12203c;    --info-fill:#2a5fd0;
  --fill-text:#ffffff;

  --toast-bg:   #e6eaf0;
  --toast-text: #151a23;

  /* Lighten whatever the landlord chose, or a navy brand disappears entirely
     against a dark page — #1e40af on #0f172a measured 2.05:1. If a browser
     lacks color-mix the declaration is simply invalid and --brand falls back to
     the raw colour, which is worse-looking but never broken. */
  --brand: color-mix(in srgb, var(--brand-raw) 55%, #ffffff);
  --brand-2: color-mix(in srgb, var(--brand-2-raw) 70%, #ffffff);
  --brand-contrast: #101620;

  --shadow-1: 0 1px 2px rgba(0,0,0,.5);
  --shadow-2: 0 2px 10px rgba(0,0,0,.5);
  --shadow-3: 0 14px 36px rgba(0,0,0,.65);
}

/* --------------------------------------------------------------------------
   Reset + base
   -------------------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin:0; padding:0; }
html { -webkit-text-size-adjust: 100%; }

body {
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

h1,h2,h3,h4 { margin:0 0 var(--s3); line-height:1.25; font-weight:650; }
h1 { font-size:24px; } h2 { font-size:20px; } h3 { font-size:16px; } h4 { font-size:14px; }
p { margin:0 0 var(--s3); }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

/* Keyboard focus is not optional — owners live in this all day. */
:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
  border-radius: var(--r-sm);
}

.num, .money { font-variant-numeric: tabular-nums; }
.money.is-negative { color: var(--danger); }
.muted { color: var(--text-muted); }
.small { font-size:13px; }
.tiny { font-size:12px; }
.center { text-align:center; }
.right { text-align:right; }
.stack > * + * { margin-top: var(--s3); }
.row { display:flex; gap: var(--s3); align-items:center; }
.row-between { display:flex; gap: var(--s3); align-items:center; justify-content:space-between; }
.grow { flex:1; }
.hidden { display:none !important; }

/* --------------------------------------------------------------------------
   Shells
   -------------------------------------------------------------------------- */

/* ---- Staff ---- */
.shell-staff { min-height:100dvh; display:flex; flex-direction:column; }

.topbar {
  height: var(--topbar-h);
  display:flex; align-items:center; gap: var(--s3);
  padding: 0 var(--s4);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top:0; z-index: 30;
}
.topbar .brand-mark {
  width:28px; height:28px; border-radius: var(--r-sm);
  background: var(--brand); color: var(--brand-contrast);
  display:grid; place-items:center; font-weight:700; font-size:14px; flex:none;
}
.topbar .org-name { font-weight:650; font-size:15px; }

.shell-body { flex:1; display:flex; min-height:0; }

.sidebar {
  display:none;
  width: var(--sidebar-w); flex:none;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: var(--s3) var(--s2);
  overflow-y:auto;
}
.nav-group + .nav-group { margin-top: var(--s4); }
.nav-group-label {
  font-size:11px; text-transform:uppercase; letter-spacing:.06em;
  color: var(--text-muted); padding: 0 var(--s3) var(--s2); font-weight:600;
}
.nav-item {
  display:flex; align-items:center; gap: var(--s3);
  padding: 9px var(--s3); border-radius: var(--r-sm);
  color: var(--text); font-size:14px; font-weight:500;
  border-left: 3px solid transparent;
}
.nav-item:hover { background: var(--surface-2); text-decoration:none; }
.nav-item.is-active {
  background: var(--surface-2); border-left-color: var(--brand);
  color: var(--brand); font-weight:650;
}
/* Not built yet. Shown, but honestly — never a link that 404s. */
.nav-item.is-soon { color: var(--text-muted); cursor: default; }
.nav-item.is-soon:hover { background: transparent; }

.content { flex:1; min-width:0; padding: var(--s4); padding-bottom: calc(var(--tabbar-h) + var(--s6)); }
.content-inner { max-width: 1200px; margin: 0 auto; }

@media (min-width: 768px) {
  .sidebar { display:block; }
  .content { padding: var(--s5); padding-bottom: var(--s6); }
  .shell-staff .tabbar { display:none; }
}

/* ---- Resident / vendor ---- */
.shell-resident { min-height:100dvh; display:flex; flex-direction:column; }
.shell-resident .content {
  flex:1;
  padding: var(--s4);
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + var(--s4));
  max-width: 720px; width:100%; margin:0 auto;
}
/* On a big screen this stays a phone layout that happens to fit, rather than
   growing a fake dashboard. */

.tabbar {
  position: fixed; left:0; right:0; bottom:0; z-index: 40;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  display:flex; background: var(--surface);
  border-top: 1px solid var(--border);
}
.tabbar a {
  flex:1; display:flex; flex-direction:column; align-items:center; justify-content:center;
  gap:3px; font-size:11px; font-weight:600; color: var(--text-muted);
  text-decoration:none; padding-top: 6px;
}
.tabbar a.is-active { color: var(--brand); }
.tabbar .tab-icon { font-size:19px; line-height:1; }

/* --------------------------------------------------------------------------
   Cards, KPIs
   -------------------------------------------------------------------------- */
.card {
  background: var(--surface); border:1px solid var(--border);
  border-radius: var(--r); box-shadow: var(--shadow-1);
}
.card + .card { margin-top: var(--s4); }
.card-head {
  padding: var(--s4); border-bottom:1px solid var(--border);
  display:flex; align-items:center; justify-content:space-between; gap: var(--s3);
}
.card-head h2, .card-head h3 { margin:0; }
.card-body { padding: var(--s4); }
.card-actions { padding: var(--s3) var(--s4); border-top:1px solid var(--border); display:flex; gap: var(--s2); }

.kpi-row { display:grid; gap: var(--s3); grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.kpi { background: var(--surface); border:1px solid var(--border); border-radius: var(--r); padding: var(--s4); }
.kpi-label { font-size:12px; text-transform:uppercase; letter-spacing:.05em; color: var(--text-muted); font-weight:600; }
.kpi-value { font-size:26px; font-weight:700; font-variant-numeric: tabular-nums; margin-top:2px; }
.kpi-sub { font-size:12px; color: var(--text-muted); }

/* --------------------------------------------------------------------------
   Status pills — ONE vocabulary used identically for lease status, work-order
   status, payment status and COI status, so the color code is learned once.
   -------------------------------------------------------------------------- */
.pill {
  display:inline-flex; align-items:center; gap:5px;
  padding: 2px 9px; border-radius: var(--r-full);
  font-size:12px; font-weight:650; white-space:nowrap;
  background: var(--surface-2); color: var(--text-muted);
}
.pill-ok      { background: var(--ok-bg);     color: var(--ok); }
.pill-warn    { background: var(--warn-bg);   color: var(--warn); }
.pill-danger  { background: var(--danger-bg); color: var(--danger); }
.pill-info    { background: var(--info-bg);   color: var(--info); }
.pill-neutral { background: var(--surface-2); color: var(--text-muted); }

/* --------------------------------------------------------------------------
   Buttons — 44px tall, because thumbs
   -------------------------------------------------------------------------- */
.btn {
  display:inline-flex; align-items:center; justify-content:center; gap: var(--s2);
  min-height:44px; padding: 0 var(--s4);
  border-radius: var(--r-sm); border:1px solid var(--border-strong);
  background: var(--surface); color: var(--text);
  font: inherit; font-weight:600; font-size:14px;
  cursor:pointer; text-decoration:none; white-space:nowrap;
}
.btn:hover { background: var(--surface-2); text-decoration:none; }
.btn:disabled, .btn[aria-busy="true"] { opacity:.55; cursor:not-allowed; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: var(--brand-contrast); }
.btn-primary:hover { filter: brightness(1.08); background: var(--brand); }
.btn-danger { background: var(--danger-fill); border-color: var(--danger-fill); color: var(--fill-text); }
.btn-ghost { background:transparent; border-color:transparent; }
.btn-ghost:hover { background: var(--surface-2); }
.btn-block { width:100%; }
.btn-sm { min-height:34px; padding: 0 var(--s3); font-size:13px; }
.btn-lg { min-height:52px; font-size:16px; }

.btn[aria-busy="true"]::after {
  content:""; width:14px; height:14px; border-radius:50%;
  border:2px solid currentColor; border-right-color:transparent;
  animation: spin .6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* --------------------------------------------------------------------------
   Forms — 16px font on every input, which is what stops iOS zooming on focus
   -------------------------------------------------------------------------- */
.field { margin-bottom: var(--s4); }
.label { display:block; font-size:13px; font-weight:650; margin-bottom:6px; }
.hint { font-size:12px; color: var(--text-muted); margin-top:4px; }
.error-text { font-size:12px; color: var(--danger); margin-top:4px; font-weight:600; }

.input, .select, .textarea {
  width:100%; min-height:44px; padding: 10px var(--s3);
  font-family: inherit; font-size:16px; color: var(--text);
  background: var(--surface); border:1px solid var(--border-strong);
  border-radius: var(--r-sm);
}
.textarea { min-height:88px; resize:vertical; }
.input:focus, .select:focus, .textarea:focus { border-color: var(--brand); }
.input.has-error, .select.has-error, .textarea.has-error { border-color: var(--danger); }
.input::placeholder { color: var(--n-400); }

.checkbox { display:flex; align-items:flex-start; gap: var(--s2); font-size:14px; }
.checkbox input { width:18px; height:18px; margin-top:2px; flex:none; accent-color: var(--brand); }

/* --------------------------------------------------------------------------
   Tables — .table-cards is the key responsive trick in a no-build app:
   below 640px every row collapses into a stacked card using data-label on <td>.
   -------------------------------------------------------------------------- */
.table-wrap { overflow-x:auto; }
.table { width:100%; border-collapse: collapse; font-size:14px; }
.table th, .table td { padding: 10px var(--s3); text-align:left; border-bottom:1px solid var(--border); }
.table th {
  font-size:12px; text-transform:uppercase; letter-spacing:.04em;
  color: var(--text-muted); font-weight:650;
  position: sticky; top:0; background: var(--surface);
}
.table td.num, .table th.num { text-align:right; font-variant-numeric: tabular-nums; }
.table tbody tr:hover { background: var(--surface-2); }

@media (max-width: 639px) {
  .table-cards thead { display:none; }
  .table-cards tr {
    display:block; margin-bottom: var(--s3); padding: var(--s3);
    border:1px solid var(--border); border-radius: var(--r); background: var(--surface);
  }
  .table-cards td { display:flex; justify-content:space-between; gap: var(--s3); border:0; padding: 5px 0; }
  .table-cards td::before {
    content: attr(data-label);
    font-size:12px; font-weight:650; color: var(--text-muted); text-transform:uppercase;
  }
  .table-cards td.num { text-align:right; }
}

/* --------------------------------------------------------------------------
   Empty states — every list page gets a real one. Never a blank box, never the
   words "No data", never more than one action.
   -------------------------------------------------------------------------- */
.empty { text-align:center; padding: var(--s7) var(--s4); }
.empty-icon { font-size:40px; line-height:1; margin-bottom: var(--s3); opacity:.75; }
.empty h3 { margin-bottom: var(--s2); }
.empty p { color: var(--text-muted); max-width: 42ch; margin: 0 auto var(--s4); }

/* Setup checklist — the dashboard's content until the first door is live */
.checklist { list-style:none; margin:0; padding:0; }
.checklist li {
  display:flex; align-items:center; gap: var(--s3);
  padding: var(--s3) 0; border-bottom:1px solid var(--border);
}
.checklist li:last-child { border-bottom:0; }
.checklist .tick {
  width:24px; height:24px; border-radius:50%; flex:none;
  display:grid; place-items:center; font-size:13px; font-weight:700;
  border:2px solid var(--border-strong); color: var(--text-muted);
}
.checklist li.is-done .tick { background: var(--ok-fill); border-color: var(--ok-fill); color: var(--fill-text); }
.checklist li.is-done .checklist-label { color: var(--text-muted); text-decoration: line-through; }
.checklist-label { flex:1; font-weight:600; font-size:14px; }

.progress { height:8px; border-radius: var(--r-full); background: var(--surface-2); overflow:hidden; }
.progress > span { display:block; height:100%; background: var(--brand); border-radius: var(--r-full); }

/* --------------------------------------------------------------------------
   Feed — two lanes. "Needs You" is sticky and actionable; "Activity" is
   chronological and ages out. A purely chronological feed buries the late
   resident under six payment confirmations.
   -------------------------------------------------------------------------- */
.feed { display:flex; flex-direction:column; gap: var(--s2); }
.feed-day {
  font-size:12px; font-weight:700; text-transform:uppercase; letter-spacing:.05em;
  color: var(--text-muted); margin: var(--s4) 0 var(--s2);
}
.feed-item {
  display:flex; gap: var(--s3); padding: var(--s3);
  background: var(--surface); border:1px solid var(--border);
  border-left:4px solid var(--border-strong); border-radius: var(--r-sm);
}
.feed-item.sev-money  { border-left-color: var(--danger); }
.feed-item.sev-urgent { border-left-color: var(--warn); }
.feed-item.sev-in     { border-left-color: var(--ok); }
.feed-item.sev-info   { border-left-color: var(--info); }
.feed-item.is-unread { font-weight:600; }
.feed-item.is-unread .feed-title::after {
  content:""; display:inline-block; width:7px; height:7px; border-radius:50%;
  background: var(--brand); margin-left:6px; vertical-align:middle;
}
.feed-title { font-size:14px; font-weight:650; }
.feed-sub { font-size:13px; color: var(--text-muted); }
.feed-actions { display:flex; flex-wrap:wrap; gap: var(--s2); margin-top: var(--s2); }

/* --------------------------------------------------------------------------
   Toasts, modals, banners
   -------------------------------------------------------------------------- */
.toast-stack {
  position: fixed; z-index: 100; right: var(--s4); top: var(--s4);
  display:flex; flex-direction:column; gap: var(--s2); max-width: min(360px, calc(100vw - 32px));
}
@media (max-width: 639px) {
  .toast-stack { left: var(--s3); right: var(--s3); top:auto; bottom: calc(var(--tabbar-h) + var(--s3)); max-width:none; }
}
.toast {
  background: var(--toast-bg); color: var(--toast-text); padding: var(--s3) var(--s4);
  border-radius: var(--r-sm); box-shadow: var(--shadow-3); font-size:14px; font-weight:500;
}
.toast-error { background: var(--danger-fill); color: var(--fill-text); }
.toast-ok { background: var(--ok-fill); color: var(--fill-text); }

.banner {
  padding: var(--s3) var(--s4); font-size:14px; font-weight:600;
  display:flex; align-items:center; gap: var(--s3);
}
.banner-warn { background: var(--warn-bg); color: var(--warn); }
.banner-danger { background: var(--danger-bg); color: var(--danger); }
/* Impersonation must be impossible to miss. */
.banner-impersonating { background:#f59e0b; color:#1f1300; position:sticky; top:0; z-index:60; }

.auth-page {
  min-height:100dvh; display:grid; place-items:center; padding: var(--s4);
  background: linear-gradient(160deg, var(--bg), var(--surface-2));
}
.auth-card { width:100%; max-width: 400px; }
.auth-logo {
  width:52px; height:52px; border-radius: var(--r); margin: 0 auto var(--s4);
  background: var(--brand); color: var(--brand-contrast);
  display:grid; place-items:center; font-size:22px; font-weight:700;
}

.skeleton {
  background: linear-gradient(90deg, var(--surface-2) 25%, var(--border) 37%, var(--surface-2) 63%);
  background-size: 400% 100%; animation: shimmer 1.4s ease infinite;
  border-radius: var(--r-sm); height:1em;
}
@keyframes shimmer { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }

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

@media print {
  .topbar, .sidebar, .tabbar, .btn, .toast-stack { display:none !important; }
  body { background:#fff; }
  .card { border:1px solid #999; box-shadow:none; }
}

/* --------------------------------------------------------------------------
   Appearance toggle. Injected into every top bar by shared.js.
   Fixed width so cycling between ◐ ☀ ☾ does not nudge the sign-out button.
   -------------------------------------------------------------------------- */
.theme-toggle {
  width: 34px; min-width: 34px; padding: 0;
  font-size: 15px; line-height: 1;
  display: inline-grid; place-items: center;
  color: var(--text-muted);
}
.theme-toggle:hover { color: var(--text); }

/* Colour changes get a short transition so flipping the theme reads as a
   deliberate change rather than a flicker. Deliberately NOT on transform or
   size — animating layout is how a UI starts to feel loose. */
body, .card, .topbar, .sidebar, .tabbar, .input, .select, .btn, .pill {
  transition: background-color .18s ease, border-color .18s ease, color .18s ease;
}
@media (prefers-reduced-motion: reduce) {
  body, .card, .topbar, .sidebar, .tabbar, .input, .select, .btn, .pill {
    transition: none;
  }
}
