:root {
  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-2: #f1f3f9;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --accent: #4f46e5;
  --accent-2: #6366f1;
  --accent-soft: #eef2ff;
  --on-accent: #ffffff;
  --ok: #059669;
  --ok-soft: #d1fae5;
  --warn: #b45309;
  --warn-soft: #fef3c7;
  --danger: #dc2626;
  --danger-soft: #fee2e2;
  --radius: 16px;
  --shadow: 0 1px 2px rgb(15 23 42 / .04), 0 4px 16px rgb(15 23 42 / .06);
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1020;
    --surface: #131a2e;
    --surface-2: #1b2340;
    --text: #e5e9f5;
    --muted: #93a0bd;
    --border: #26304f;
    --accent: #818cf8;
    --accent-2: #a5b4fc;
    --accent-soft: #1e2350;
    --on-accent: #0b1020;
    --ok: #34d399;
    --ok-soft: #0f3a2e;
    --warn: #fbbf24;
    --warn-soft: #3a2e0f;
    --danger: #f87171;
    --danger-soft: #3d1717;
    --shadow: 0 1px 2px rgb(0 0 0 / .3), 0 6px 20px rgb(0 0 0 / .25);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
a { color: var(--accent); text-decoration: none; }
h1, h2, h3 { margin: 0; line-height: 1.25; letter-spacing: -.01em; }
h2 { font-size: 1.05rem; font-weight: 650; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .9em; }
.hidden { display: none !important; }

/* ---------- boot / spinner ---------- */
.boot { min-height: 100vh; display: grid; place-items: center; }
.spinner {
  width: 28px; height: 28px; border-radius: 50%;
  border: 3px solid var(--border); border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- login ---------- */
.login-wrap {
  min-height: 100vh; display: grid; place-items: center; padding: 24px 16px;
  background: radial-gradient(1200px 600px at 10% -10%, var(--accent-soft), transparent 60%), var(--bg);
}
.login-card { width: 100%; max-width: 380px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 1.05rem; }
.brand img { width: 30px; height: 30px; }
.login-card .brand { margin-bottom: 20px; justify-content: center; font-size: 1.25rem; }
.login-card .brand img { width: 40px; height: 40px; }

/* ---------- shell ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  padding-top: env(safe-area-inset-top);
}
.topbar-inner {
  max-width: 980px; margin: 0 auto; padding: 12px 16px;
  display: flex; align-items: center; gap: 16px;
}
.topnav { display: flex; gap: 4px; margin-left: auto; }
.topnav a, .bottomnav a {
  color: var(--muted); font-weight: 550; border-radius: 10px;
  display: flex; align-items: center; gap: 6px;
}
.topnav a { padding: 7px 12px; }
.topnav a:hover { background: var(--surface-2); color: var(--text); }
.topnav a.active { background: var(--accent-soft); color: var(--accent); }

main { max-width: 980px; margin: 0 auto; padding: 20px 16px 110px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 8px 0 16px; }
.page-head h1 { font-size: 1.45rem; font-weight: 700; }
.page-note { margin: -8px 0 14px; }

.bottomnav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 10;
  display: none; justify-content: space-around;
  background: var(--surface); border-top: 1px solid var(--border);
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
}
.bottomnav a { flex-direction: column; gap: 2px; font-size: .72rem; padding: 6px 10px; flex: 1; }
.bottomnav a.active { color: var(--accent); }
.icon { width: 20px; height: 20px; flex: none; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

@media (max-width: 720px) {
  .topnav { display: none; }
  .bottomnav { display: flex; }
  .page-head h1 { font-size: 1.3rem; }
  .desktop-only { display: none !important; }
}
@media (min-width: 721px) { .mobile-only { display: none !important; } }

/* ---------- cards ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px;
}
.card + .card, .grid-2 + .card, .card + .grid-2, .stack > * + * { margin-top: 16px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.grid-2 { display: grid; grid-template-columns: 1.4fr 1fr; gap: 16px; }
@media (max-width: 720px) { .grid-2 { grid-template-columns: 1fr; } }

.hero {
  position: relative; overflow: hidden; color: #fff; border: none;
  background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 55%, #db2777 120%);
}
.hero.normal { background: linear-gradient(135deg, #0f766e 0%, #0891b2 100%); }
.hero::after {
  content: ""; position: absolute; right: -60px; top: -60px; width: 220px; height: 220px;
  border-radius: 50%; background: rgb(255 255 255 / .1);
}
.hero .label { font-size: .78rem; text-transform: uppercase; letter-spacing: .08em; opacity: .85; font-weight: 600; }
.hero .who { font-size: 1.7rem; font-weight: 750; margin: 6px 0 2px; letter-spacing: -.02em; }
.hero .num { font-size: 1.1rem; font-weight: 600; color: #fff; opacity: .95; display: inline-flex; gap: 6px; align-items: center; }
.hero .meta { margin-top: 14px; font-size: .88rem; opacity: .9; display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: center; }
.hero .pill { background: rgb(255 255 255 / .18); color: #fff; }


/* ---------- pills ---------- */
.pill {
  display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px;
  font-size: .76rem; font-weight: 650; background: var(--surface-2); color: var(--muted); white-space: nowrap;
}
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.danger { background: var(--danger-soft); color: var(--danger); }
.pill.accent { background: var(--accent-soft); color: var(--accent); }
.dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.pill.ok .dot { animation: pulse 2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .35; } }

/* ---------- timeline list ---------- */
.day-label {
  font-size: .76rem; font-weight: 700; text-transform: uppercase; letter-spacing: .06em;
  color: var(--muted); margin: 18px 4px 8px;
}
.day-label:first-child { margin-top: 0; }
.list { list-style: none; margin: 0; padding: 0; }
.item {
  display: flex; align-items: center; gap: 14px; padding: 12px 14px;
  border: 1px solid var(--border); border-radius: 12px; background: var(--surface);
}
.item + .item { margin-top: 8px; }
.item .time {
  flex: none; width: 62px; text-align: center; font-weight: 700; font-variant-numeric: tabular-nums;
  padding: 6px 0; border-radius: 10px; background: var(--accent-soft); color: var(--accent); font-size: .92rem;
}
.item.default .time { background: var(--surface-2); color: var(--muted); }
.item .body { flex: 1; min-width: 0; }
.item .title { font-weight: 620; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .sub { color: var(--muted); font-size: .85rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .actions { display: flex; gap: 4px; }
.sub .icon, p .icon { width: 13px; height: 13px; vertical-align: -2px; }
.avatar {
  flex: none; width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center;
  font-weight: 700; font-size: .85rem; color: #fff; background: var(--accent);
}
.av0 { background: #4f46e5; } .av1 { background: #0891b2; } .av2 { background: #db2777; }
.av3 { background: #059669; } .av4 { background: #d97706; } .av5 { background: #7c3aed; }
.empty { text-align: center; padding: 28px 12px; color: var(--muted); }
.empty .icon { width: 34px; height: 34px; margin-bottom: 6px; opacity: .6; }

details.history summary { cursor: pointer; color: var(--muted); font-weight: 600; padding: 4px; list-style: none; }
details.history summary::-webkit-details-marker { display: none; }
details.history[open] summary { margin-bottom: 10px; }
.item.past { opacity: .7; }

/* ---------- buttons ---------- */
.btn {
  appearance: none; border: 1px solid transparent; border-radius: 11px; cursor: pointer;
  font: inherit; font-weight: 620; padding: 9px 16px; display: inline-flex; align-items: center;
  justify-content: center; gap: 8px; transition: background .15s, transform .05s, opacity .15s;
  background: var(--accent); color: var(--on-accent); min-height: 40px; white-space: nowrap;
}
.btn:hover { background: var(--accent-2); }
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .55; cursor: default; }
.btn.secondary { background: var(--surface-2); color: var(--text); border-color: var(--border); }
.btn.secondary:hover { background: var(--border); }
.btn.ghost { background: transparent; color: var(--muted); }
.btn.ghost:hover { background: var(--surface-2); color: var(--text); }
.btn.danger { background: var(--danger-soft); color: var(--danger); }
.btn.block { width: 100%; }
.btn.icon-btn { padding: 0; width: 36px; min-height: 36px; border-radius: 10px; }
.btn .icon { width: 18px; height: 18px; }

.fab {
  position: fixed; right: 18px; bottom: calc(78px + env(safe-area-inset-bottom)); z-index: 11;
  width: 56px; height: 56px; border-radius: 18px; box-shadow: 0 8px 24px rgb(79 70 229 / .4);
}
.fab .icon { width: 24px; height: 24px; }

/* ---------- forms ---------- */
.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-size: .84rem; font-weight: 600; margin-bottom: 6px; color: var(--muted); }
.input, select.input, textarea.input {
  width: 100%; font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 11px; padding: 10px 12px; min-height: 44px;
  transition: border-color .15s, box-shadow .15s;
}
.input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.row { display: flex; gap: 10px; }
.row > * { flex: 1; min-width: 0; }
.check { display: flex; align-items: center; gap: 10px; font-weight: 550; margin-bottom: 14px; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); }
.form-error { color: var(--danger); background: var(--danger-soft); border-radius: 10px; padding: 8px 12px; font-size: .88rem; margin-bottom: 12px; }
.form-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 6px; }

/* ---------- dialog ---------- */
dialog {
  border: none; padding: 0; background: var(--surface); color: var(--text);
  border-radius: 20px; width: min(480px, calc(100vw - 32px)); box-shadow: 0 20px 60px rgb(0 0 0 / .3);
  max-height: calc(100vh - 40px);
}
dialog::backdrop { background: rgb(15 23 42 / .45); backdrop-filter: blur(2px); }
dialog .dlg-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 20px 6px; }
dialog .dlg-head h2 { font-size: 1.15rem; }
dialog form { padding: 12px 20px 20px; }
@media (max-width: 720px) {
  dialog {
    width: 100vw; max-width: 100vw; margin: auto 0 0; border-radius: 22px 22px 0 0;
    padding-bottom: env(safe-area-inset-bottom); max-height: 92vh;
  }
  dialog[open] { animation: sheet .22s ease-out; }
}
@keyframes sheet { from { transform: translateY(40px); opacity: 0; } }

/* ---------- table-ish ---------- */
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; font-size: .92rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; word-break: break-word; }
.log { font-size: .85rem; }
.log li { padding: 8px 0; border-bottom: 1px solid var(--border); display: flex; gap: 10px; }
.log li:last-child { border-bottom: none; }
.log time { color: var(--muted); flex: none; width: 120px; font-variant-numeric: tabular-nums; }
.log .detail { color: var(--muted); word-break: break-all; }

/* ---------- toast ---------- */
#toast {
  position: fixed; left: 50%; bottom: calc(90px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px);
  background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 12px; font-weight: 600;
  opacity: 0; pointer-events: none; transition: all .2s; z-index: 100; max-width: calc(100vw - 32px);
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.error { background: var(--danger); color: #fff; }
@media (min-width: 721px) { #toast { bottom: 28px; } }

/* ---------- date & time picker ---------- */
.dtp { position: relative; }
.dtp-field {
  display: flex; align-items: center; gap: 10px; text-align: left; cursor: pointer; font-weight: 550;
}
.dtp-field .dtp-text { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dtp-field .icon { color: var(--muted); width: 18px; height: 18px; }
.dtp-field .dtp-caret { transition: transform .15s; }
.dtp-field[aria-expanded="true"] { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.dtp-field[aria-expanded="true"] .dtp-caret { transform: rotate(180deg); }
.dtp-panel {
  margin-top: 8px; padding: 12px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 16px; box-shadow: var(--shadow); animation: dtp-pop .14s ease-out;
}
@keyframes dtp-pop { from { opacity: 0; transform: translateY(-4px); } }
.dtp-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.dtp-month { font-weight: 700; letter-spacing: -.01em; }
.dtp-head .btn:disabled { opacity: .3; }
.dtp-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; text-align: center; }
.dtp-dow { font-size: .7rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); padding: 4px 0 6px; }
.dtp-day {
  appearance: none; border: 0; background: transparent; color: var(--text); font: inherit; font-weight: 550;
  font-variant-numeric: tabular-nums; height: 38px; border-radius: 10px; cursor: pointer; transition: background .12s;
}
.dtp-day:hover { background: var(--surface-2); }
.dtp-day.out { color: var(--muted); }
.dtp-day.today { color: var(--accent); box-shadow: inset 0 0 0 1.5px var(--accent); }
.dtp-day.sel { background: var(--accent); color: var(--on-accent); box-shadow: none; font-weight: 700; }
.dtp-day:disabled { opacity: .28; cursor: default; background: transparent; }
.dtp-time {
  display: flex; align-items: center; gap: 6px; flex-wrap: wrap;
  margin-top: 10px; padding-top: 12px; border-top: 1px solid var(--border);
}
.dtp-label { display: flex; align-items: center; gap: 6px; margin-right: auto; color: var(--muted); font-weight: 600; font-size: .85rem; }
.dtp-label .icon { width: 16px; height: 16px; }
.dtp-spin, .dtp-ampm { display: flex; align-items: center; background: var(--surface-2); border-radius: 12px; padding: 2px; }
.dtp-spin button, .dtp-ampm button {
  appearance: none; border: 0; background: transparent; color: var(--muted); cursor: pointer;
  height: 34px; border-radius: 9px; display: grid; place-items: center; font: inherit; font-weight: 650;
}
.dtp-spin button { width: 28px; }
.dtp-spin button .icon { width: 16px; height: 16px; }
.dtp-spin button:hover, .dtp-ampm button:hover { color: var(--text); }
.dtp-num {
  width: 30px; border: 0; background: transparent; color: var(--text); text-align: center;
  font: inherit; font-weight: 700; font-size: 1.05rem; font-variant-numeric: tabular-nums; padding: 0;
}
.dtp-num:focus { outline: none; color: var(--accent); }
.dtp-colon { font-weight: 700; color: var(--muted); }
.dtp-ampm button { padding: 0 10px; }
.dtp-ampm button[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.dtp-foot { display: flex; justify-content: space-between; margin-top: 12px; }
@media (max-width: 380px) { .dtp-label { flex-basis: 100%; } }
