:root {
  --bg: #f4f5f2;
  --surface: #ffffff;
  --surface-2: #f0f1ed;
  --border: #e1e3dc;
  --ink: #1b1d19;
  --ink-2: #4c5047;
  --ink-3: #80857a;
  --accent: #1f5f4a;
  --accent-ink: #ffffff;
  --accent-soft: #e2efe9;
  --good: #0ca30c;
  --good-soft: #e3f4e3;
  --good-ink: #0b6b0b;
  --warn: #fab219;
  --warn-soft: #fdf1d6;
  --warn-ink: #8a5a00;
  --bad: #d03b3b;
  --bad-soft: #f8e2e2;
  --bad-ink: #a52626;
  --shadow: 0 1px 2px rgba(20, 24, 18, .06), 0 4px 14px rgba(20, 24, 18, .05);
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121311;
    --surface: #1a1b19;
    --surface-2: #232521;
    --border: #2f322c;
    --ink: #eceee8;
    --ink-2: #b4b8ad;
    --ink-3: #848a7e;
    --accent: #5fc39c;
    --accent-ink: #0d1f18;
    --accent-soft: #1d332a;
    --good-soft: #17301a;
    --good-ink: #6fd36f;
    --warn-soft: #36290d;
    --warn-ink: #f6c55a;
    --bad-soft: #3a1c1c;
    --bad-ink: #f08a8a;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; line-height: 1.25; letter-spacing: -.01em; }
h1 { font-size: 22px; }
h2 { font-size: 17px; }
h3 { font-size: 15px; }
.muted { color: var(--ink-3); }
.small { font-size: 13px; }
.tnum { font-variant-numeric: tabular-nums; }
.hidden { display: none !important; }
.row { display: flex; align-items: center; gap: 10px; }
.row.wrap { flex-wrap: wrap; }
.spread { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.stack > * + * { margin-top: 12px; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* buttons & inputs */
.btn {
  appearance: none; border: 1px solid var(--border); background: var(--surface); color: var(--ink);
  font: inherit; font-weight: 600; padding: 9px 14px; border-radius: 10px; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 40px;
  transition: background .15s, transform .05s;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.danger { color: var(--bad-ink); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.block { width: 100%; }
.btn.lg { min-height: 52px; font-size: 16px; border-radius: 12px; }
.btn.sm { min-height: 32px; padding: 5px 10px; font-size: 13px; }
input, textarea, select {
  font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; padding: 10px 12px; width: 100%; min-height: 42px;
}
textarea { resize: vertical; min-height: 70px; }
input:focus, textarea:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
label.field { display: block; }
label.field > span { display: block; font-size: 13px; font-weight: 600; color: var(--ink-2); margin-bottom: 5px; }

/* cards */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }
.card.flush { padding: 0; overflow: hidden; }
.card-h { padding: 14px 16px; border-bottom: 1px solid var(--border); }

/* badges */
.badge { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--ink-2); white-space: nowrap; }
.badge.good { background: var(--good-soft); color: var(--good-ink); }
.badge.warn { background: var(--warn-soft); color: var(--warn-ink); }
.badge.bad { background: var(--bad-soft); color: var(--bad-ink); }
.badge.accent { background: var(--accent-soft); color: var(--accent); }

/* progress */
.progress { height: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; display: flex; gap: 2px; }
.progress > i { display: block; height: 100%; }
.progress .g { background: var(--good); }
.progress .w { background: var(--warn); }
.progress .b { background: var(--bad); }

/* login */
.login-wrap { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; }
.login { width: 100%; max-width: 380px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; }
.brand-mark { width: 34px; height: 34px; border-radius: 10px; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; }
.brand-mark svg { width: 20px; height: 20px; }
.error { color: var(--bad-ink); font-size: 14px; min-height: 1em; }

/* toast */
#toast { position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%) translateY(20px); opacity: 0; pointer-events: none;
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-weight: 600; transition: .2s; z-index: 100; max-width: calc(100vw - 32px); }
#toast.show { opacity: 1; transform: translateX(-50%); }

/* modal */
.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: grid; place-items: end center; z-index: 50; padding: 0; }
@media (min-width: 640px) { .modal-bg { place-items: center; padding: 16px; } }
.modal { background: var(--surface); width: 100%; max-width: 480px; border-radius: 18px 18px 0 0; padding: 20px 16px calc(20px + env(safe-area-inset-bottom)); max-height: 90vh; overflow: auto; }
@media (min-width: 640px) { .modal { border-radius: 18px; } }

/* stat tiles */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.tile .k { font-size: 13px; color: var(--ink-3); font-weight: 600; }
.tile .v { font-size: 26px; font-weight: 700; letter-spacing: -.02em; margin-top: 2px; font-variant-numeric: tabular-nums; }
.tile .s { font-size: 12px; color: var(--ink-3); }

/* tables */
.tbl-wrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
.tbl th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-3); font-weight: 600; padding: 10px 16px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.tbl td { padding: 11px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl tr.click { cursor: pointer; }
.tbl tr.click:hover td { background: var(--surface-2); }
.tbl td.num, .tbl th.num { text-align: right; font-variant-numeric: tabular-nums; }

/* chart */
.chart { position: relative; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .grid line { stroke: var(--border); }
.chart .axis text { fill: var(--ink-3); font-size: 11px; }
.legend { display: flex; flex-wrap: wrap; gap: 14px; font-size: 13px; color: var(--ink-2); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.tip { position: absolute; pointer-events: none; background: var(--surface); border: 1px solid var(--border); box-shadow: 0 6px 20px rgba(0,0,0,.15); border-radius: 10px; padding: 8px 10px; font-size: 13px; white-space: nowrap; z-index: 5; transform: translate(-50%, calc(-100% - 10px)); }

/* dashboard shell */
.shell { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.side { background: var(--surface); border-right: 1px solid var(--border); padding: 18px 12px; position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 4px; }
.side .brand { padding: 0 8px 16px; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 9px; color: var(--ink-2); font-weight: 600; }
.nav a:hover { background: var(--surface-2); text-decoration: none; }
.nav a.on { background: var(--accent-soft); color: var(--accent); }
.nav svg { width: 18px; height: 18px; flex: none; }
.side .foot { margin-top: auto; padding: 8px; font-size: 13px; }
.main { padding: 24px 28px 48px; min-width: 0; max-width: 1180px; }
.page-h { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.grid2 { display: grid; grid-template-columns: 1.4fr 1fr; gap: 16px; }
@media (max-width: 960px) { .grid2 { grid-template-columns: 1fr; } }
@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: sticky; top: 0; height: auto; flex-direction: row; align-items: center; padding: 8px 12px; z-index: 10; overflow-x: auto; gap: 2px; }
  .side .brand { padding: 0 8px 0 0; }
  .side .brand span { display: none; }
  .nav { display: flex; gap: 2px; }
  .nav a { padding: 8px 10px; white-space: nowrap; }
  .nav a svg { display: none; }
  .side .foot { margin: 0 0 0 auto; padding: 0; white-space: nowrap; }
  .side .foot .who { display: none; }
  .main { padding: 16px 16px 40px; }
}

/* item editor */
.item-row { display: grid; grid-template-columns: 28px 1fr auto; gap: 8px; align-items: start; padding: 10px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); }
.item-row .n { width: 28px; height: 28px; border-radius: 8px; background: var(--surface-2); display: grid; place-items: center; font-size: 13px; font-weight: 700; color: var(--ink-2); margin-top: 7px; }
.item-row .f > * + * { margin-top: 6px; }
.item-row input.desc { font-size: 13px; min-height: 36px; padding: 7px 10px; }
.item-row .acts { display: flex; flex-direction: column; gap: 2px; }
.icon-btn { appearance: none; border: 0; background: transparent; color: var(--ink-3); width: 32px; height: 30px; border-radius: 8px; cursor: pointer; display: grid; place-items: center; }
.icon-btn:hover { background: var(--surface-2); color: var(--ink); }
.icon-btn svg { width: 16px; height: 16px; }

/* timeline */
.tl { list-style: none; margin: 0; padding: 0; }
.tl li { display: grid; grid-template-columns: 26px 1fr auto; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--border); align-items: start; }
.tl li:last-child { border-bottom: 0; }
.tl .dot { width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; color: #fff; }
.tl .dot svg { width: 15px; height: 15px; }
.tl .ok .dot { background: var(--good); }
.tl .issue .dot { background: var(--warn); color: #3a2a00; }
.tl .pending .dot { background: var(--bad); }
.tl .note { margin-top: 4px; font-size: 13px; color: var(--ink-2); background: var(--surface-2); padding: 6px 10px; border-radius: 8px; }
.empty { text-align: center; padding: 36px 16px; color: var(--ink-3); }

/* ---------- brand intro / branded sign-in ---------- */
.logo-ink { display: block; height: 40px; width: auto; }
@media (prefers-color-scheme: dark) { .logo-ink { filter: invert(1); } }

.hero { position: fixed; inset: 0; z-index: 40; overflow: hidden; background: #070a14; color: #fff; transition: opacity .6s ease, visibility .6s; }
.hero.out { opacity: 0; visibility: hidden; pointer-events: none; }
.hero-bg { position: absolute; inset: 0; background: #070a14 url(/assets/intro-bg.jpg) 24% 50% / cover no-repeat; transform-origin: 30% 60%; animation: heroZoom 16s cubic-bezier(.2,.6,.2,1) forwards; }
@supports (background-image: url(x.webp)) { .hero-bg { background-image: url(/assets/intro-bg.webp); } }
@media (min-aspect-ratio: 4/3) { .hero-bg { background-position: 50% 50%; } }
.hero::after { content: ""; position: absolute; inset: 0; pointer-events: none;
  background: linear-gradient(180deg, rgba(4,6,16,.62) 0%, rgba(4,6,16,.38) 30%, rgba(4,6,16,.18) 52%, rgba(4,6,16,.9) 100%); }
@keyframes heroZoom { from { transform: scale(1.14); } to { transform: scale(1); } }
@keyframes heroUp { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
@keyframes heroLoad { from { transform: scaleX(0); } to { transform: scaleX(1); } }

.hero-content { position: relative; z-index: 1; height: 100%; max-width: 1180px; margin: 0 auto; display: flex; flex-direction: column; justify-content: space-between; gap: 24px;
  padding: calc(28px + env(safe-area-inset-top)) 24px calc(36px + env(safe-area-inset-bottom)); }
.hero-logo { width: clamp(108px, 30vw, 168px); height: auto; display: block; opacity: 0; animation: heroUp .9s .15s cubic-bezier(.2,.7,.2,1) forwards; filter: drop-shadow(0 2px 12px rgba(0,0,0,.35)); }
.hero-text { opacity: 0; animation: heroUp .9s .45s cubic-bezier(.2,.7,.2,1) forwards; }
.hero-title { font-size: clamp(40px, 11vw, 76px); font-weight: 700; line-height: .95; letter-spacing: -.035em; text-shadow: 0 2px 24px rgba(0,0,0,.35); }
.hero-rule { width: 44px; height: 3px; border-radius: 2px; background: #ff9a3c; margin: 16px 0 12px; }
.hero-sub { font-size: clamp(14px, 3.6vw, 17px); color: rgba(255,255,255,.9); max-width: 30ch; text-shadow: 0 1px 2px rgba(0,0,0,.6), 0 0 18px rgba(0,0,0,.5); }
.hero-load { position: absolute; left: 24px; right: 24px; bottom: calc(18px + env(safe-area-inset-bottom)); height: 2px; z-index: 2; background: rgba(255,255,255,.18); border-radius: 2px; overflow: hidden; max-width: 1132px; margin: 0 auto; }
.hero-load i { display: block; height: 100%; background: #fff; transform-origin: left; animation: heroLoad 1.8s cubic-bezier(.4,0,.2,1) forwards; }
.hero.is-login .hero-load { display: none; }
.hero-slot:empty { display: none; }

/* sign-in card on the photo */
.glass { width: 100%; max-width: 400px; background: rgba(12,14,24,.58); -webkit-backdrop-filter: blur(20px) saturate(1.3); backdrop-filter: blur(20px) saturate(1.3);
  border: 1px solid rgba(255,255,255,.14); border-radius: 20px; padding: 22px 20px; color: #fff; animation: heroUp .7s cubic-bezier(.2,.7,.2,1) both; }
.glass h2 { font-size: 20px; }
.glass p { margin: 4px 0 16px; color: rgba(255,255,255,.7); font-size: 14px; }
.glass label.field > span { color: rgba(255,255,255,.75); }
.glass input { background: rgba(255,255,255,.08); border-color: rgba(255,255,255,.16); color: #fff; min-height: 48px; }
.glass input::placeholder { color: rgba(255,255,255,.45); }
.glass input:focus { outline-color: #ff9a3c; }
.glass .btn.primary { background: #fff; border-color: #fff; color: #10131c; }
.glass .error { color: #ffb4a8; }
.glass .error:empty { display: none; }
.glass .stack > * + * { margin-top: 12px; }

/* tall phones: brand top, card bottom. Wide screens: brand bottom-left, card bottom-right */
@media (min-width: 900px) {
  .hero-content { flex-direction: row; align-items: flex-end; justify-content: space-between; padding: 48px 56px 64px; }
  .hero-brand { display: flex; flex-direction: column; justify-content: space-between; height: 100%; }
  .hero-load { left: 56px; right: 56px; bottom: 32px; max-width: 1068px; }
  .glass { padding: 28px 26px; }
}
@media (max-width: 899px) {
  .hero-brand { display: flex; flex-direction: column; gap: 28px; flex: 1; justify-content: space-between; }
  .hero.is-login .hero-brand { flex: 0; justify-content: flex-start; }
  .hero.is-login .hero-title { font-size: clamp(34px, 9vw, 52px); }
  .hero.is-login .hero-content { justify-content: space-between; }
  .glass { max-width: none; }
}
@media (max-height: 640px) and (max-width: 899px) {
  .hero.is-login .hero-text { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  .hero-bg, .hero-logo, .hero-text, .glass, .hero-load i { animation: none !important; opacity: 1; transform: none; }
}

/* small-screen polish for dashboards */
@media (max-width: 760px) {
  .hide-sm { display: none !important; }
  .side .logo-ink { height: 30px; }
  .nav a { padding: 7px 9px; font-size: 14px; }
  .tbl th, .tbl td { padding: 10px 12px; }
  .page-h .row { width: 100%; }
  .page-h .row .btn { flex: 1; }
}
