:root {
  --bg: #F4F5F2;
  --surface: #FFFFFF;
  --surface-2: #EEF0F2;
  --line: #E3E6E9;
  --line-soft: #EEF0F2;
  --ink: #16191D;
  --ink-2: #3F4650;
  --muted: #5B636E;
  --accent: #0E6E66;
  --accent-ink: #0A4F49;
  --accent-soft: #E3F1EF;
  --accent-on: #FFFFFF;
  --warn: #7A3E00;
  --warn-strong: #C25E00;
  --warn-soft: #FDF1E4;
  --warn-line: #F3D9BC;
  --blue: #2B4C8C;
  --blue-soft: #EAEFF8;
  --danger: #A12C2C;
  --shadow: 0 1px 2px rgba(22, 25, 29, 0.12);
  --radius: 16px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111416;
    --surface: #1A1E21;
    --surface-2: #252A2E;
    --line: #2C3236;
    --line-soft: #252A2E;
    --ink: #ECEEF0;
    --ink-2: #C9CED3;
    --muted: #9AA3AD;
    --accent: #2FA396;
    --accent-ink: #8FD6CC;
    --accent-soft: #163A36;
    --accent-on: #0B1F1C;
    --warn: #F2B477;
    --warn-strong: #E08A3C;
    --warn-soft: #34261A;
    --warn-line: #4A3522;
    --blue: #8DA9E0;
    --blue-soft: #1E2738;
    --danger: #F08C8C;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Manrope, system-ui, -apple-system, 'Segoe UI', sans-serif;
  font-size: 15px;
  line-height: 1.45;
  font-variant-numeric: tabular-nums;
}
a { color: var(--accent); }
a:hover { color: var(--accent-ink); }
h1, h2, h3 { margin: 0; letter-spacing: -0.01em; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
[hidden] { display: none !important; }

/* ---- Shell ---- */
.topbar { background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
.topbar-inner { max-width: 1280px; margin: 0 auto; padding: 12px 24px; display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 18px; color: var(--ink); text-decoration: none; margin-right: 8px; }
.brand-mark { width: 32px; height: 32px; border-radius: 9px; background: var(--accent); color: var(--accent-on); display: grid; place-items: center; }
.nav { display: flex; gap: 4px; }
.nav a { height: 40px; padding: 0 14px; border-radius: 10px; display: flex; align-items: center; color: var(--ink-2); text-decoration: none; font-weight: 600; font-size: 14px; }
.nav a[aria-current="page"] { background: var(--accent-soft); color: var(--accent-ink); font-weight: 700; }
.spacer { flex: 1 1 auto; }
.main { max-width: 1280px; margin: 0 auto; padding: 28px 24px 64px; display: flex; flex-direction: column; gap: 24px; }

.bottom-nav { display: none; }

@media (max-width: 760px) {
  .topbar-inner { padding: 10px 16px; }
  .topbar .nav, .topbar .desktop-only { display: none; }
  .main { padding: 20px 16px calc(110px + env(safe-area-inset-bottom)); gap: 20px; }
  .bottom-nav {
    display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
    background: var(--surface); border-top: 1px solid var(--line);
    padding: 6px 8px calc(6px + env(safe-area-inset-bottom)); justify-content: space-around; align-items: center;
  }
  .bottom-nav a { width: 64px; min-height: 48px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
    text-decoration: none; color: var(--muted); font-size: 11px; font-weight: 600; }
  .bottom-nav a[aria-current="page"] { color: var(--accent); font-weight: 700; }
  .bottom-nav .fab { width: 52px; height: 52px; border-radius: 16px; background: var(--accent); color: var(--accent-on); justify-content: center; }
}

/* ---- Building blocks ---- */
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 12px; }
.page-head h1 { font-size: 30px; font-weight: 800; letter-spacing: -0.02em; }
.sub { color: var(--muted); font-size: 14px; margin: 4px 0 0; }
.small { font-size: 13px; }
.muted { color: var(--muted); }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 24px; min-width: 0; }
.card h2 { font-size: 18px; font-weight: 800; }
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.row { display: flex; flex-wrap: wrap; gap: 24px; align-items: flex-start; }
.grow { flex: 999 1 560px; min-width: 0; }
.side { flex: 1 1 340px; min-width: 0; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; }
.stat .label { font-size: 13px; font-weight: 600; color: var(--muted); }
.stat .value { font-size: 30px; font-weight: 800; letter-spacing: -0.02em; margin-top: 8px; }
.stat .hint { font-size: 13px; color: var(--muted); margin-top: 4px; }
.stat.warn { background: var(--warn-soft); border-color: var(--warn-line); }
.stat.warn .label, .stat.warn .value, .stat.warn .hint { color: var(--warn); }

.btn { height: 44px; padding: 0 16px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  font-weight: 600; font-size: 14px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; text-decoration: none; white-space: nowrap; }
.btn:hover { border-color: var(--muted); color: var(--ink); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-on); font-weight: 700; }
.btn.primary:hover { filter: brightness(1.05); color: var(--accent-on); }
.btn.small { height: 36px; padding: 0 12px; font-size: 13px; border-radius: 8px; }
.btn.danger { color: var(--danger); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn:disabled { opacity: 0.55; cursor: default; }
.icon-btn { width: 44px; height: 44px; padding: 0; }

.seg { display: inline-flex; background: var(--surface-2); border-radius: 10px; padding: 3px; }
.seg button { height: 38px; min-width: 56px; padding: 0 12px; border: none; border-radius: 8px; background: transparent; color: var(--ink-2); font-weight: 600; font-size: 13px; }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--ink); font-weight: 700; box-shadow: var(--shadow); }
.seg.wide { display: flex; }
.seg.wide button { flex: 1 1 0; }

.pill { display: inline-block; font-size: 12px; font-weight: 700; border-radius: 999px; padding: 3px 10px; background: var(--surface-2); color: var(--ink-2); white-space: nowrap; }
.pill.watch, .pill.ok { background: var(--accent-soft); color: var(--accent-ink); }
.pill.soon { background: var(--warn-soft); color: var(--warn); }
.pill.ended { background: var(--surface-2); color: var(--muted); }
.flag { font-size: 12px; font-weight: 600; color: var(--warn); }

.list { list-style: none; margin: 0; padding: 0; }
.list > li { border-top: 1px solid var(--line-soft); }

/* Decisions */
.timeline { position: relative; height: 54px; margin: 20px 0 8px; }
.timeline .track { position: absolute; left: 0; right: 0; top: 14px; height: 4px; border-radius: 4px; background: var(--surface-2); }
.timeline .soon-zone { position: absolute; left: 0; width: 33.3%; top: 14px; height: 4px; border-radius: 4px; background: var(--warn-line); }
.timeline .tick { position: absolute; top: 6px; width: 1px; height: 20px; background: var(--line); }
.timeline .tick-label { position: absolute; top: 26px; font-size: 11px; font-weight: 600; color: var(--muted); }
.timeline .dot { position: absolute; top: 9px; width: 14px; height: 14px; margin-left: -7px; border-radius: 50%; border: 2px solid var(--surface); background: var(--muted); }
.timeline .dot.soon { background: var(--warn-strong); }
.timeline .today { position: absolute; left: 0; top: 40px; font-size: 11px; color: var(--muted); }
.deadline { display: flex; align-items: center; gap: 16px; padding: 14px 0; color: inherit; text-decoration: none; }
.deadline:hover .name { text-decoration: underline; }
.datebox { width: 52px; flex: none; text-align: center; border-radius: 12px; background: var(--bg); padding: 6px 0; }
.datebox.soon { background: var(--warn-soft); color: var(--warn); }
.datebox .d { font-size: 20px; font-weight: 800; line-height: 1.1; }
.datebox .m { font-size: 11px; font-weight: 700; color: inherit; opacity: 0.8; text-transform: uppercase; letter-spacing: 0.04em; }
.deadline .body { flex: 1 1 auto; min-width: 0; }
.deadline .name { font-weight: 700; }
.deadline .right { text-align: right; flex: none; }
.deadline .amt { font-weight: 700; font-size: 14px; }
@media (max-width: 560px) {
  .deadline { gap: 12px; }
  .deadline .per { display: none; }
  .deadline .amt { font-size: 13px; }
  .datebox { width: 46px; }
}
.empty { padding: 24px 0 8px; color: var(--muted); font-size: 14px; }

/* Attention */
.notice { display: flex; gap: 12px; padding: 12px 0; }
.notice .ic { width: 36px; height: 36px; flex: none; border-radius: 10px; display: grid; place-items: center; background: var(--surface-2); color: var(--ink-2); }
.notice .ic.warn { background: var(--warn-soft); color: var(--warn); }
.notice .ic.accent { background: var(--accent-soft); color: var(--accent); }
.notice .ic.blue { background: var(--blue-soft); color: var(--blue); }
.notice .t { font-weight: 700; font-size: 14px; }
.notice .b { font-size: 13px; color: var(--muted); margin-top: 2px; }
.notice .actions { display: flex; gap: 8px; margin-top: 8px; flex-wrap: wrap; }

/* Bars */
.bars { display: flex; flex-direction: column; gap: 16px; margin-top: 20px; }
.bar-row { display: grid; grid-template-columns: minmax(0, 170px) minmax(0, 1fr) minmax(120px, auto); align-items: center; gap: 16px; }
.bar { height: 12px; border-radius: 6px; background: var(--surface-2); overflow: hidden; }
.bar > span { display: block; height: 100%; border-radius: 6px; background: var(--accent); }
.bar > span.blue { background: var(--blue); }
.bar-row .amt { text-align: right; font-size: 14px; }
@media (max-width: 560px) {
  .bar-row { grid-template-columns: 1fr auto; gap: 6px 12px; }
  .bar-row .bar { grid-column: 1 / -1; grid-row: 2; }
}

/* Table */
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.chip { height: 40px; padding: 0 14px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); color: var(--ink-2); font-weight: 600; font-size: 13px; }
.chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-on); font-weight: 700; }
.search { display: flex; align-items: center; gap: 8px; height: 40px; padding: 0 12px; border: 1px solid var(--line); border-radius: 10px; min-width: 200px; color: var(--muted); background: var(--surface); }
.search input { border: none; outline: none; background: transparent; flex: 1 1 auto; min-width: 0; font-size: 14px; color: var(--ink); }
.table-wrap { overflow-x: auto; margin-top: 16px; }
table { width: 100%; min-width: 900px; border-collapse: collapse; font-size: 14px; }
th { text-align: left; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; padding: 10px 12px; font-weight: 700; white-space: nowrap; }
td { padding: 12px; border-top: 1px solid var(--line-soft); vertical-align: top; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--bg); }
td.num, th.num { text-align: right; }
tfoot td { border-top: 2px solid var(--line); font-weight: 800; }
.item-cards { display: none; }
@media (max-width: 760px) {
  .table-wrap { display: none; }
  .item-cards { display: block; margin-top: 12px; }
  .item-card { display: flex; gap: 12px; align-items: center; padding: 14px 0; border-top: 1px solid var(--line-soft); color: inherit; text-decoration: none; }
  .item-card .body { flex: 1 1 auto; min-width: 0; }
}

/* Forms */
.form { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.form .full { grid-column: 1 / -1; }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field label, .field .label { font-size: 13px; font-weight: 700; color: var(--ink-2); }
.field .help { font-size: 12px; color: var(--muted); }
.field .err { font-size: 12px; color: var(--danger); font-weight: 600; }
input[type=text], input[type=number], input[type=date], input[type=url], input[type=password], select, textarea {
  height: 44px; padding: 0 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); font-size: 15px; width: 100%; min-width: 0;
}
textarea { height: auto; min-height: 88px; padding: 10px 12px; resize: vertical; }
.inline { display: flex; gap: 8px; }
.inline > * { flex: 1 1 0; min-width: 0; }
.check { display: flex; align-items: center; gap: 10px; min-height: 44px; font-weight: 600; }
.check input { width: 20px; height: 20px; accent-color: var(--accent); }
fieldset { border: none; padding: 0; margin: 0; }
legend { font-size: 16px; font-weight: 800; padding: 0; margin-bottom: 4px; }
.form-section { grid-column: 1 / -1; padding-top: 8px; border-top: 1px solid var(--line-soft); }
@media (max-width: 560px) { .form { grid-template-columns: 1fr; } }

/* Item detail */
.detail-grid { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); gap: 24px; align-items: start; }
@media (max-width: 900px) { .detail-grid { grid-template-columns: 1fr; } }
.deadline-card { background: var(--warn-soft); border: 1px solid var(--warn-line); color: var(--warn); border-radius: var(--radius); padding: 18px; }
.deadline-card .k { font-size: 12px; font-weight: 800; letter-spacing: 0.04em; text-transform: uppercase; }
.deadline-card .v { font-size: 22px; font-weight: 800; margin-top: 4px; }
.deadline-card.calm { background: var(--surface); border-color: var(--line); color: var(--ink); }
dl.facts { margin: 0; font-size: 14px; }
dl.facts > div { display: flex; justify-content: space-between; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line-soft); }
dl.facts > div:last-child { border-bottom: none; }
dl.facts dt { color: var(--muted); }
dl.facts dd { margin: 0; font-weight: 600; text-align: right; overflow-wrap: anywhere; }
.price-big { font-size: 28px; font-weight: 800; }

/* Hero (mobile overview) */
.hero { display: none; }
@media (max-width: 760px) {
  .stats.desktop { display: none; }
  .hero { display: block; background: var(--accent); color: var(--accent-on); border-radius: 20px; padding: 22px; }
  .hero .label { font-size: 13px; font-weight: 600; opacity: 0.85; }
  .hero .value { font-size: 36px; font-weight: 800; letter-spacing: -0.02em; margin-top: 6px; }
  .hero .hint { font-size: 13px; opacity: 0.85; }
  .hero .split { display: flex; gap: 8px; margin-top: 16px; }
  .hero .split > div { flex: 1 1 0; background: rgba(255, 255, 255, 0.14); border-radius: 12px; padding: 10px 12px; }
  .hero .split .k { font-size: 12px; opacity: 0.85; }
  .hero .split .v { font-size: 15px; font-weight: 700; }
  .card { padding: 18px; }
  .page-head h1 { font-size: 26px; }
}

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login form { width: 100%; max-width: 360px; display: flex; flex-direction: column; gap: 16px; }
.login .brand { justify-content: center; font-size: 22px; margin: 0 0 8px; }

/* Toast */
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 12px 18px; border-radius: 12px; font-weight: 600; font-size: 14px; z-index: 50; max-width: calc(100vw - 32px); box-shadow: 0 8px 24px rgba(0,0,0,0.2); }
@media (max-width: 760px) { .toast { bottom: calc(96px + env(safe-area-inset-bottom)); } }

/* Import */
.steps { display: flex; gap: 8px; flex-wrap: wrap; font-size: 13px; font-weight: 700; color: var(--muted); }
.steps .on { color: var(--accent-ink); }
.dropzone { border: 2px dashed var(--line); border-radius: var(--radius); padding: 32px; text-align: center; background: var(--surface); }
.dropzone.drag { border-color: var(--accent); background: var(--accent-soft); }
.mini-table { width: 100%; min-width: 0; font-size: 13px; }
.mini-table td, .mini-table th { padding: 8px; }
.suggestion { display: flex; gap: 12px; align-items: center; padding: 14px 0; border-top: 1px solid var(--line-soft); flex-wrap: wrap; }
.suggestion .body { flex: 1 1 240px; min-width: 0; }

/* Weekly */
.stack-bar { display: flex; height: 12px; border-radius: 6px; overflow: hidden; gap: 2px; margin-top: 14px; background: var(--surface-2); }
.stack-bar span { display: block; height: 100%; }
.legend { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px; font-size: 13px; margin-top: 8px; }
.swatch { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: baseline; }
.kv { display: flex; justify-content: space-between; gap: 12px; font-size: 14px; padding: 6px 0; }
