:root {
  --bg: #faf7f4;
  --panel: #ffffff;
  --sunken: #f3eee9;
  --line: #e6dfd8;
  --text: #2a2522;
  --muted: #776d66;
  --accent: #1f5f5b;
  --accent-soft: #e2efed;
  --accent-text: #ffffff;
  --coral: #d9644f;
  --coral-soft: #fbe6e0;
  --amber: #b7791f;
  --amber-soft: #fbf0d9;
  --green: #2f7d4f;
  --green-soft: #e1f2e7;
  --shadow: 0 1px 2px rgba(42, 37, 34, .06), 0 4px 16px rgba(42, 37, 34, .06);
  --radius: 10px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #171514;
    --panel: #211e1c;
    --sunken: #1b1917;
    --line: #36312d;
    --text: #efe9e4;
    --muted: #a39890;
    --accent: #5fb3aa;
    --accent-soft: #1d3533;
    --accent-text: #0f1f1e;
    --coral: #ef8a76;
    --coral-soft: #3a2420;
    --amber: #e0a94d;
    --amber-soft: #352a17;
    --green: #6cc28f;
    --green-soft: #1b3123;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h1 { font-size: 24px; font-weight: 700; }
h2 { font-size: 17px; font-weight: 650; }
h3 { font-size: 13px; font-weight: 650; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.boot { display: grid; place-items: center; height: 100vh; color: var(--muted); }
.icon { flex: none; display: block; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.grow { flex: 1; min-width: 0; }
.row { display: flex; align-items: center; gap: 8px; }
.wrap { flex-wrap: wrap; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* Layout */
.app { display: grid; grid-template-columns: 232px 1fr; height: 100vh; height: 100dvh; }
.sidebar {
  background: var(--panel); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; padding: 16px 10px; gap: 2px; overflow-y: auto;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px 16px; font-weight: 700; font-size: 16px; }
.brand img { width: 30px; height: 30px; border-radius: 8px; }
.nav-item {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px;
  color: var(--text); text-decoration: none; font-weight: 500; border: 0; background: none; width: 100%; text-align: left; cursor: pointer;
}
.nav-item:hover { background: var(--sunken); }
.nav-item.active { background: var(--accent-soft); color: var(--accent); }
.nav-item .count { margin-left: auto; font-size: 12px; color: var(--muted); }
.nav-section { margin: 18px 10px 6px; }
.dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.sidebar-foot { margin-top: auto; padding-top: 12px; }
.main { overflow-y: auto; min-width: 0; }
.page { max-width: 1200px; margin: 0 auto; padding: 24px 28px 96px; }
.page-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.page-head h1 { margin-right: auto; }
.bottom-nav { display: none; }
.demo-banner {
  background: var(--amber-soft); color: var(--text); font-size: 13px; padding: 8px 16px; text-align: center;
  border-bottom: 1px solid var(--line);
}

@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .page { padding: 16px 16px calc(96px + env(safe-area-inset-bottom)); }
  h1 { font-size: 21px; }
  .bottom-nav {
    display: grid; grid-template-columns: repeat(5, 1fr); position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
    background: var(--panel); border-top: 1px solid var(--line); padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
  }
  .bottom-nav a {
    display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 11px; color: var(--muted);
    text-decoration: none; padding: 4px 0;
  }
  .bottom-nav a.active { color: var(--accent); }
  .hide-mobile { display: none !important; }
}
@media (min-width: 761px) { .show-mobile { display: none !important; } }

/* Controls */
.btn {
  display: inline-flex; align-items: center; gap: 6px; justify-content: center; padding: 8px 14px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--panel); cursor: pointer; font-weight: 550; white-space: nowrap; min-height: 38px;
}
.btn:hover { background: var(--sunken); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--coral); }
.btn.ghost { border-color: transparent; background: none; }
.btn.ghost:hover { background: var(--sunken); }
.btn.sm { padding: 4px 10px; min-height: 30px; font-size: 13px; }
.btn.icon-only { padding: 6px; min-width: 38px; }
.btn:disabled { opacity: .5; cursor: default; }
.input, .select, .textarea {
  width: 100%; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel); min-height: 38px;
}
.input:focus, .select:focus, .textarea:focus, .btn:focus-visible, .check:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; border-color: transparent; }
.textarea { resize: vertical; min-height: 80px; }
.select { appearance: none; padding-right: 28px; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 15px) 16px, calc(100% - 10px) 16px; background-size: 5px 5px; background-repeat: no-repeat; }
.select.compact { width: auto; }
.search { position: relative; }
.search .icon { position: absolute; left: 10px; top: 10px; color: var(--muted); }
.search .input { padding-left: 34px; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field > span { font-size: 12px; font-weight: 600; color: var(--muted); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 520px) { .grid2 { grid-template-columns: 1fr; } }
.segmented { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: var(--panel); }
.segmented button { border: 0; background: none; padding: 7px 12px; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; font-size: 14px; }
.segmented button.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.toggle { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; user-select: none; }
.toggle input { width: 18px; height: 18px; accent-color: var(--accent); }

/* Cards & lists */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 16px; }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 16px; }
@media (max-width: 760px) { .stats { grid-template-columns: repeat(2, 1fr); } }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.stat b { display: block; font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat span { font-size: 13px; color: var(--muted); }
.stat.warn b { color: var(--coral); }
.list { display: flex; flex-direction: column; }
.list-row {
  display: flex; align-items: center; gap: 10px; padding: 9px 4px; border-bottom: 1px solid var(--line); cursor: pointer; min-height: 44px;
}
.list-row:last-child { border-bottom: 0; }
.list-row:hover { background: var(--sunken); }
.group-title { display: flex; align-items: center; gap: 8px; margin: 18px 0 4px; }
.group-title .n { font-size: 12px; color: var(--muted); }
.empty { padding: 28px 12px; text-align: center; color: var(--muted); }

.chip {
  display: inline-flex; align-items: center; gap: 5px; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 550;
  background: var(--sunken); color: var(--muted); white-space: nowrap; max-width: 100%;
}
.chip.accent { background: var(--accent-soft); color: var(--accent); }
.chip.coral { background: var(--coral-soft); color: var(--coral); }
.chip.amber { background: var(--amber-soft); color: var(--amber); }
.chip.green { background: var(--green-soft); color: var(--green); }
.chip button { border: 0; background: none; padding: 0; cursor: pointer; display: inline-flex; color: inherit; }
.due { font-size: 13px; color: var(--muted); white-space: nowrap; }
.due.overdue { color: var(--coral); font-weight: 600; }
.due.today { color: var(--green); font-weight: 600; }
.avatar {
  width: 26px; height: 26px; border-radius: 50%; display: inline-grid; place-items: center; font-size: 11px; font-weight: 700;
  color: #fff; flex: none;
}
.avatar.lg { width: 40px; height: 40px; font-size: 15px; }
.check {
  width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--line); background: var(--panel); flex: none; cursor: pointer;
  display: grid; place-items: center; padding: 0; color: transparent;
}
.check:hover { border-color: var(--green); color: var(--green); }
.check.on { background: var(--green); border-color: var(--green); color: #fff; }
.done-text { text-decoration: line-through; color: var(--muted); }
.prio-high { color: var(--coral); }

/* Table */
.table-wrap { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; padding: 10px 12px; border-bottom: 1px solid var(--line); background: var(--sunken); }
td { padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
tbody tr { cursor: pointer; }
tbody tr:hover { background: var(--sunken); }
td .sub { font-size: 13px; color: var(--muted); }

/* Board */
.board { display: flex; gap: 14px; overflow-x: auto; padding-bottom: 12px; align-items: flex-start; }
.column { flex: 0 0 290px; background: var(--sunken); border-radius: var(--radius); padding: 10px; min-height: 120px; border: 1px solid transparent; }
.column.drop { border-color: var(--accent); background: var(--accent-soft); }
.column-head { display: flex; align-items: center; gap: 8px; padding: 2px 4px 10px; font-weight: 650; }
.column-head .n { margin-left: auto; font-size: 12px; color: var(--muted); font-weight: 500; }
.bcard {
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; margin-bottom: 8px; cursor: pointer;
  box-shadow: 0 1px 1px rgba(0,0,0,.03); display: flex; flex-direction: column; gap: 6px;
}
.bcard:hover { border-color: var(--accent); }
.bcard.dragging { opacity: .4; }
.bcard .title { font-weight: 550; }
.money { font-variant-numeric: tabular-nums; font-weight: 650; }

/* Calendar */
.cal { display: grid; grid-template-columns: repeat(7, 1fr); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; background: var(--line); gap: 1px; }
.cal-head { background: var(--sunken); padding: 6px 8px; font-size: 12px; font-weight: 600; color: var(--muted); }
.cal-day { background: var(--panel); min-height: 108px; padding: 6px; display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.cal-day.other { background: var(--sunken); }
.cal-day.today .num { background: var(--accent); color: var(--accent-text); }
.cal-day .num { font-size: 12px; font-weight: 600; width: 22px; height: 22px; display: grid; place-items: center; border-radius: 50%; }
.cal-task { font-size: 12px; padding: 2px 6px; border-radius: 4px; background: var(--accent-soft); color: var(--text); cursor: pointer; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; border-left: 3px solid var(--accent); }
.cal-task.done { opacity: .5; text-decoration: line-through; }
@media (max-width: 760px) { .cal-day { min-height: 70px; padding: 3px; } .cal-task { font-size: 10px; padding: 1px 3px; } }

/* Drawer */
.overlay { position: fixed; inset: 0; background: rgba(20, 16, 14, .35); z-index: 40; animation: fade .15s ease; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(520px, 100vw); background: var(--panel); z-index: 41;
  display: flex; flex-direction: column; box-shadow: -8px 0 30px rgba(0,0,0,.15); animation: slide .18s ease;
}
.drawer-head { display: flex; align-items: center; gap: 8px; padding: 12px 14px 12px 20px; border-bottom: 1px solid var(--line); padding-top: calc(12px + env(safe-area-inset-top)); }
.drawer-head h2 { flex: 1; min-width: 0; }
.drawer-body { flex: 1; overflow-y: auto; padding: 18px 20px calc(32px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 16px; }
.title-input { font-size: 20px; font-weight: 650; border: 1px solid transparent; padding: 4px 6px; margin-left: -7px; border-radius: 6px; background: none; width: 100%; }
.title-input:hover { border-color: var(--line); }
.title-input:focus { outline: 2px solid var(--accent); }
.section { display: flex; flex-direction: column; gap: 8px; }
.section-head { display: flex; align-items: center; gap: 8px; }
.section-head h3 { flex: 1; }
.timeline { display: flex; flex-direction: column; gap: 10px; }
.tl-item { display: flex; gap: 10px; }
.tl-item .body { flex: 1; min-width: 0; background: var(--sunken); border-radius: 8px; padding: 8px 10px; }
.tl-item .meta { font-size: 12px; color: var(--muted); display: flex; gap: 6px; align-items: center; margin-bottom: 2px; }
.tl-item p { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
@keyframes slide { from { transform: translateX(30px); opacity: 0; } }
@keyframes fade { from { opacity: 0; } }

.tags-input { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; border: 1px solid var(--line); border-radius: 8px; padding: 5px 8px; min-height: 38px; background: var(--panel); }
.tags-input input { border: 0; outline: 0; background: none; flex: 1; min-width: 100px; padding: 2px; }

/* Toasts */
.toasts { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(80px + env(safe-area-inset-bottom)); z-index: 60; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast { background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 8px; font-size: 14px; box-shadow: var(--shadow); animation: fade .2s; max-width: 90vw; }
.toast.error { background: var(--coral); color: #fff; }

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login .card { width: min(380px, 100%); display: flex; flex-direction: column; gap: 14px; padding: 28px; }
.login img { width: 56px; height: 56px; border-radius: 14px; }
.notice { background: var(--sunken); border-radius: 8px; padding: 10px 12px; font-size: 13px; }
.notice.warn { background: var(--amber-soft); }
.quick-add { display: flex; gap: 8px; margin-bottom: 8px; }

a.btn { text-decoration: none; color: inherit; }
a.btn.primary { color: var(--accent-text); }
