/* ---------- design tokens ---------- */
:root {
  --bg: #f4f5fb;
  --surface: #ffffff;
  --surface-2: #f8f9fe;
  --text: #17192e;
  --text-soft: #5b607a;
  --text-faint: #9aa0b8;
  --border: #e6e8f2;
  --primary: #6366f1;
  --primary-strong: #4f46e5;
  --primary-soft: #eef0fe;
  --green: #16a34a;
  --green-soft: #e7f7ed;
  --amber: #d97706;
  --amber-soft: #fdf3e2;
  --red: #dc2626;
  --red-soft: #fdeaea;
  --shadow: 0 1px 2px rgba(23, 25, 46, .05), 0 8px 24px -12px rgba(23, 25, 46, .12);
  --radius: 16px;
  --radius-sm: 10px;
  --font: 'Segoe UI Variable Text', 'Segoe UI', system-ui, -apple-system, 'Helvetica Neue', sans-serif;
}
[data-theme="dark"] {
  --bg: #101223;
  --surface: #1a1d33;
  --surface-2: #202440;
  --text: #eceef8;
  --text-soft: #a6abc8;
  --text-faint: #6d7394;
  --border: #2b2f4d;
  --primary: #818cf8;
  --primary-strong: #a5b0fc;
  --primary-soft: #262a4d;
  --green: #4ade80;
  --green-soft: #143323;
  --amber: #fbbf24;
  --amber-soft: #37290e;
  --red: #f87171;
  --red-soft: #3b1717;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px -12px rgba(0, 0, 0, .5);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
}
h1, h2, h3 { line-height: 1.25; margin: 0 0 .35em; }
h1 { font-size: 1.5rem; letter-spacing: -.02em; }
h2 { font-size: 1.05rem; }
a { color: var(--primary); text-decoration: none; }
p { margin: .3em 0; }

/* ---------- layout ---------- */
.shell { max-width: 1080px; margin: 0 auto; padding: 0 20px 96px; }
.topbar {
  position: sticky; top: 0; z-index: 40;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  margin-bottom: 24px;
}
.topbar-inner {
  max-width: 1080px; margin: 0 auto; padding: 12px 20px;
  display: flex; align-items: center; gap: 16px;
}
.brand { font-weight: 700; font-size: 1.05rem; display: flex; align-items: center; gap: 8px; color: var(--text); }
.nav { display: flex; gap: 2px; margin-left: 8px; flex: 1; }
.nav a {
  padding: 7px 13px; border-radius: 99px; color: var(--text-soft); font-weight: 500; font-size: .92rem;
}
.nav a.active { background: var(--primary-soft); color: var(--primary-strong); }
.nav a:hover { color: var(--text); }
.topbar-right { display: flex; align-items: center; gap: 10px; }

/* bottom tab bar on phones */
@media (max-width: 720px) {
  .nav {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 50; margin: 0;
    background: var(--surface); border-top: 1px solid var(--border);
    justify-content: space-around; padding: 6px 2px calc(6px + env(safe-area-inset-bottom));
    flex-wrap: nowrap; overflow-x: auto;
  }
  .nav a { font-size: .76rem; padding: 7px 7px; white-space: nowrap; }
}

/* ---------- cards & grids ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 20px;
}
.card + .card { margin-top: 16px; }
.card h2 { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: 1fr 1fr; }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
@media (max-width: 860px) { .grid-2, .grid-3 { grid-template-columns: 1fr; } }
.muted { color: var(--text-soft); }
.faint { color: var(--text-faint); font-size: .85rem; }
.spread { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }

/* ---------- buttons & inputs ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  border-radius: var(--radius-sm); padding: 8px 14px; font: inherit; font-weight: 600; font-size: .9rem;
  cursor: pointer; transition: filter .12s, transform .05s;
}
.btn:hover { filter: brightness(.97); }
[data-theme="dark"] .btn:hover { filter: brightness(1.15); }
.btn:active { transform: scale(.98); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
[data-theme="dark"] .btn-primary { color: #14163a; }
.btn-danger { color: var(--red); border-color: color-mix(in srgb, var(--red) 35%, var(--border)); }
.btn-sm { padding: 4px 10px; font-size: .82rem; border-radius: 8px; }
.btn-ghost { border-color: transparent; background: transparent; color: var(--text-soft); }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 14px; }
.field label { font-size: .84rem; font-weight: 600; color: var(--text-soft); }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface-2);
  border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 9px 12px;
  width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: 0; border-color: transparent; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

/* ---------- avatars, pills, status ---------- */
.avatar {
  width: 32px; height: 32px; border-radius: 50%; flex: none;
  display: inline-flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 700; font-size: .8rem; letter-spacing: .02em;
}
.avatar.sm { width: 24px; height: 24px; font-size: .65rem; }
.pill {
  display: inline-flex; align-items: center; gap: 5px;
  border-radius: 99px; padding: 3px 10px; font-size: .78rem; font-weight: 600;
}
.pill-ok { background: var(--green-soft); color: var(--green); }
.pill-due-soon { background: var(--amber-soft); color: var(--amber); }
.pill-overdue { background: var(--red-soft); color: var(--red); }
.pill-neutral { background: var(--primary-soft); color: var(--primary-strong); }
.dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.dot-ok { background: var(--green); }
.dot-due-soon { background: var(--amber); }
.dot-overdue { background: var(--red); }

/* ---------- lists ---------- */
.list { display: flex; flex-direction: column; }
.list-item {
  display: flex; align-items: center; gap: 12px; padding: 11px 2px;
  border-bottom: 1px solid var(--border);
}
.list-item:last-child { border-bottom: none; }
.list-item .grow { flex: 1; min-width: 0; }
.list-item .title { font-weight: 600; }

/* status accent on open-task rows */
.task-row { border-left: 3px solid transparent; padding-left: 10px; border-radius: 4px; }
.task-row.ok { border-left-color: var(--green); }
.task-row.due-soon { border-left-color: var(--amber); }
.task-row.overdue { border-left-color: var(--red); }

/* ---------- tables ---------- */
table { width: 100%; border-collapse: collapse; font-size: .92rem; }
th { text-align: left; color: var(--text-soft); font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; padding: 8px 10px; border-bottom: 1px solid var(--border); }
td { padding: 9px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
.table-wrap { overflow-x: auto; }

/* ---------- bars (charts) ---------- */
.bar-row { display: grid; grid-template-columns: 130px 1fr 46px; gap: 10px; align-items: center; padding: 5px 0; }
.bar-track { background: var(--surface-2); border-radius: 99px; height: 14px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 99px; min-width: 2px; transition: width .4s ease; }
.bar-val { font-size: .84rem; color: var(--text-soft); text-align: right; font-variant-numeric: tabular-nums; }

.cols-chart { display: flex; align-items: flex-end; gap: 6px; height: 120px; padding-top: 8px; }
.cols-chart .col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; min-width: 0; }
.cols-chart .col .stick { width: 100%; max-width: 34px; background: var(--primary); border-radius: 6px 6px 2px 2px; opacity: .85; }
.cols-chart .col .lbl { font-size: .68rem; color: var(--text-faint); white-space: nowrap; }

/* ---------- calendar ---------- */
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal-head { font-size: .72rem; font-weight: 700; color: var(--text-faint); text-transform: uppercase; text-align: center; padding: 4px 0; }
.cal-cell {
  min-height: 76px; background: var(--surface-2); border-radius: 8px; padding: 5px 6px;
  font-size: .78rem; border: 1px solid transparent;
}
.cal-cell.other { opacity: .4; }
.cal-cell.today { border-color: var(--primary); }
.cal-daynum { font-weight: 700; color: var(--text-soft); font-size: .75rem; }
.cal-ev {
  display: flex; gap: 4px; align-items: center; border-radius: 5px; padding: 1px 4px; margin-top: 3px;
  font-size: .68rem; font-weight: 600; color: #fff; overflow: hidden; white-space: nowrap; text-overflow: ellipsis;
}
.cal-ev.done { opacity: .45; text-decoration: line-through; }
@media (max-width: 720px) { .cal-cell { min-height: 56px; } .cal-ev { font-size: .6rem; } }

/* ---------- modal / toast ---------- */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 100; background: rgba(10, 12, 30, .5);
  display: flex; align-items: flex-end; justify-content: center; padding: 16px;
}
@media (min-width: 640px) { .modal-backdrop { align-items: center; } }
.modal {
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
  width: 100%; max-width: 460px; max-height: 88vh; overflow: auto; padding: 22px;
  animation: pop .16s ease;
}
@keyframes pop { from { transform: translateY(14px); opacity: .5; } }
#toast-root { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 200; display: flex; flex-direction: column; gap: 8px; align-items: center; }
@media (max-width: 720px) { #toast-root { bottom: 72px; } }
.toast {
  background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 99px;
  font-weight: 600; font-size: .9rem; box-shadow: var(--shadow); animation: pop .16s ease;
  display: flex; gap: 10px; align-items: center; max-width: 90vw;
}
.toast button { background: none; border: none; color: inherit; font: inherit; font-weight: 700; cursor: pointer; text-decoration: underline; }

/* ---------- auth screen ---------- */
.auth-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.auth-card { width: 100%; max-width: 400px; }
.auth-logo { text-align: center; font-size: 2.4rem; margin-bottom: 4px; }

/* ---------- misc ---------- */
.stat-num { font-size: 1.7rem; font-weight: 800; letter-spacing: -.02em; }
.section-note { font-size: .85rem; color: var(--text-soft); margin: -6px 0 12px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  border: 1px solid var(--border); border-radius: 99px; padding: 7px 14px; cursor: pointer;
  background: var(--surface-2); font: inherit; font-size: .88rem; font-weight: 600; color: var(--text);
}
.chip:hover { border-color: var(--primary); color: var(--primary-strong); }
.empty { text-align: center; color: var(--text-faint); padding: 24px 8px; }
.fab {
  position: fixed; right: 20px; bottom: 20px; z-index: 45;
  border-radius: 99px; padding: 14px 20px; font-size: 1rem;
  box-shadow: 0 10px 30px -8px color-mix(in srgb, var(--primary) 60%, transparent);
}
@media (max-width: 720px) { .fab { bottom: 76px; right: 16px; } }
@media print {
  .topbar, .fab, .no-print { display: none !important; }
  body { background: #fff; }
  .card { box-shadow: none; break-inside: avoid; }
}
