:root {
  --bg: #f4f6f5;
  --surface: #ffffff;
  --surface-2: #eef2f0;
  --border: #dde3e0;
  --text: #17201d;
  --muted: #5f6d68;
  --primary: #0f5c4d;
  --primary-2: #137a66;
  --primary-soft: #e3f1ed;
  --on-primary: #ffffff;
  --ok: #1d7a46;   --ok-soft: #e2f4e9;
  --warn: #9a6200; --warn-soft: #fdf1d8;
  --danger: #b42318; --danger-soft: #fde7e5;
  --info: #1f5fa8; --info-soft: #e4eefa;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 20, .06), 0 2px 8px rgba(16, 24, 20, .05);
  --sidebar: 264px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e1412; --surface: #151d1a; --surface-2: #1c2622; --border: #2a3632; --text: #e6eeeb; --muted: #94a59f;
    --primary: #3fb59a; --primary-2: #56c7ac; --primary-soft: #183a32; --on-primary: #06221b;
    --ok: #5fd08f; --ok-soft: #173826; --warn: #f0b54a; --warn-soft: #3a2c10; --danger: #ff7b6e; --danger-soft: #3d1a17; --info: #7fb1f0; --info-soft: #162a42;
    --shadow: 0 1px 2px rgba(0,0,0,.4);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0e1412; --surface: #151d1a; --surface-2: #1c2622; --border: #2a3632; --text: #e6eeeb; --muted: #94a59f;
  --primary: #3fb59a; --primary-2: #56c7ac; --primary-soft: #183a32; --on-primary: #06221b;
  --ok: #5fd08f; --ok-soft: #173826; --warn: #f0b54a; --warn-soft: #3a2c10; --danger: #ff7b6e; --danger-soft: #3d1a17; --info: #7fb1f0; --info-soft: #162a42;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 1.45rem; }
h2 { font-size: 1.1rem; }
h3 { font-size: 1.02rem; }
p { margin: .4em 0; }
.muted { color: var(--muted); }
.small, small { font-size: .85rem; }
.pre { white-space: pre-wrap; word-break: break-word; }
.right { text-align: right; }
.icon { flex: none; }
code.secret { display: block; padding: 12px; margin: 8px 0; background: var(--surface-2); border-radius: 8px; font-size: 1.05rem; letter-spacing: .05em; word-break: break-all; user-select: all; }
:focus-visible { outline: 2px solid var(--primary-2); outline-offset: 2px; }

/* ---------- auth */
.auth { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; background: linear-gradient(160deg, var(--primary-soft), var(--bg)); }
.auth-card { width: 100%; max-width: 420px; background: var(--surface); border: 1px solid var(--border); border-radius: 18px; padding: 28px 24px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 12px; }
.center-screen { min-height: 100%; display: grid; place-content: center; gap: 12px; padding: 16px; }
.brand { display: flex; gap: 12px; align-items: center; }
.brand strong { display: block; }
.brand small { color: var(--muted); }
.brand-logo { width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center; background: var(--primary); color: var(--on-primary); }
.steps { padding-left: 20px; }

/* ---------- shell */
.shell { display: flex; min-height: 100%; }
.sidebar {
  width: var(--sidebar); flex: none; background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; padding: calc(16px + var(--safe-t)) 12px 12px;
}
.sidebar .brand { padding: 0 6px 14px; border-bottom: 1px solid var(--border); margin-bottom: 8px; }
.sidebar .brand-logo { width: 38px; height: 38px; }
.nav-scroll { flex: 1; overflow-y: auto; }
.nav-group { padding: 6px 0; }
.nav-group-label { font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 8px 10px 4px; font-weight: 600; }
.nav-link {
  display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px 10px; border-radius: 8px; color: var(--text);
  background: none; border: 0; font: inherit; cursor: pointer; text-align: left;
}
.nav-link:hover { background: var(--surface-2); text-decoration: none; }
.nav-link.active { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.nav-foot { border-top: 1px solid var(--border); padding-top: 8px; }
.main-col { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { display: none; }
.content { flex: 1; padding: 24px 28px 40px; max-width: 1280px; width: 100%; outline: none; }
.bottom-nav, .scrim, .menu-toggle { display: none; }
.icon-btn { display: inline-grid; place-items: center; width: 40px; height: 40px; border-radius: 10px; border: 0; background: none; color: var(--text); cursor: pointer; position: relative; }
.icon-btn:hover { background: var(--surface-2); }
.bell-count { position: absolute; top: 4px; right: 2px; min-width: 18px; height: 18px; padding: 0 4px; border-radius: 9px; background: var(--danger); color: #fff; font-size: .7rem; display: grid; place-items: center; font-weight: 700; }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--primary); color: var(--on-primary); display: grid; place-items: center; font-size: .8rem; font-weight: 700; }
.avatar:hover { text-decoration: none; }

@media (min-width: 901px) {
  .topbar { display: flex; position: fixed; top: 12px; right: 20px; z-index: 5; gap: 8px; align-items: center; }
  .topbar .topbar-title { display: none; }
  .content { padding-top: 28px; }
  .page-head { padding-right: 96px; }
}

@media (max-width: 900px) {
  .sidebar { position: fixed; z-index: 40; left: 0; top: 0; bottom: 0; transform: translateX(-102%); transition: transform .2s ease; box-shadow: var(--shadow); }
  body.nav-open .sidebar { transform: none; }
  body.nav-open .scrim { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 30; }
  .topbar { display: flex; align-items: center; gap: 6px; padding: calc(8px + var(--safe-t)) 10px 8px; background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 20; }
  .menu-toggle { display: inline-grid; }
  .topbar-title { flex: 1; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .content { padding: 16px 16px calc(88px + var(--safe-b)); }
  .bottom-nav {
    display: flex; position: fixed; bottom: 0; left: 0; right: 0; z-index: 20; background: var(--surface); border-top: 1px solid var(--border);
    padding: 6px 4px calc(6px + var(--safe-b));
  }
  .bottom-link { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: .7rem; color: var(--muted); background: none; border: 0; font-family: inherit; padding: 4px 0; cursor: pointer; }
  .bottom-link.active { color: var(--primary); }
  .bottom-link:hover { text-decoration: none; }
}

/* ---------- page */
.page { display: flex; flex-direction: column; gap: 16px; }
.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; }
.page-title { display: flex; gap: 10px; align-items: flex-start; }
.page-title .back { margin-top: 2px; color: var(--muted); }
.page-actions, .row-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.row-actions.wrap { margin-top: 12px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); min-width: 0; }
.card-title { margin-bottom: 10px; }
.card > header, .card > footer { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; }
.card > footer { margin-top: 10px; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 16px; }
@media (max-width: 480px) { .grid-2, .grid-3 { grid-template-columns: 1fr; } }
.feed { display: flex; flex-direction: column; gap: 12px; }
.announcement h3 { margin: 8px 0 4px; }
.announcement.pinned { border-left: 4px solid var(--warn); }
.announcement.unread h3::after { content: " •"; color: var(--primary); }
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; justify-content: space-between; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--border); }
.list li:last-child { border-bottom: 0; }
.list a { display: inline-flex; gap: 6px; align-items: center; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.toolbar > * { flex: 0 1 auto; }
.search { display: flex; align-items: center; gap: 6px; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 0 10px; min-width: 220px; flex: 1 1 220px; max-width: 420px; color: var(--muted); }
.search input { border: 0; outline: 0; background: none; padding: 9px 0; flex: 1; font: inherit; color: var(--text); min-width: 0; }

/* ---------- stats */
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; }
.stat { display: flex; gap: 12px; align-items: flex-start; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; color: var(--text); box-shadow: var(--shadow); }
a.stat:hover { text-decoration: none; border-color: var(--primary-2); }
.stat-icon { width: 40px; height: 40px; border-radius: 10px; display: grid; place-items: center; background: var(--primary-soft); color: var(--primary); flex: none; }
.stat-label { font-size: .82rem; color: var(--muted); }
.stat-value { font-size: 1.35rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat-hint { font-size: .8rem; color: var(--muted); }
.stat-ok .stat-icon { background: var(--ok-soft); color: var(--ok); }
.stat-warn .stat-icon { background: var(--warn-soft); color: var(--warn); }
.stat-danger .stat-icon { background: var(--danger-soft); color: var(--danger); }
.stat-info .stat-icon { background: var(--info-soft); color: var(--info); }
@media (max-width: 480px) { .stats { grid-template-columns: 1fr 1fr; } .stat { flex-direction: column; gap: 6px; } .stat-value { font-size: 1.15rem; } }

.quick-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 8px; }
.quick { display: flex; flex-direction: column; align-items: center; gap: 6px; text-align: center; padding: 14px 8px; border-radius: 10px; background: var(--surface-2); color: var(--text); font-size: .85rem; }
.quick:hover { text-decoration: none; background: var(--primary-soft); color: var(--primary); }

/* ---------- table */
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card .table-wrap { box-shadow: none; }
.table { width: 100%; border-collapse: collapse; font-size: .92rem; }
.table th { text-align: left; font-size: .76rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; padding: 10px 12px; border-bottom: 1px solid var(--border); background: var(--surface-2); white-space: nowrap; }
.table td { padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table .right { text-align: right; font-variant-numeric: tabular-nums; }
.table-click tbody tr { cursor: pointer; }
.table-click tbody tr:hover { background: var(--surface-2); }
@media (max-width: 700px) {
  .table-wrap { border: 0; background: none; box-shadow: none; overflow: visible; }
  .table thead { display: none; }
  .table, .table tbody, .table tr, .table td { display: block; width: 100%; }
  .table tr { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 10px; padding: 6px 12px; box-shadow: var(--shadow); }
  .table td { display: flex; justify-content: space-between; gap: 12px; padding: 6px 0; border-bottom: 1px dashed var(--border); text-align: right; }
  .table td::before { content: attr(data-label); color: var(--muted); font-size: .82rem; text-align: left; flex: none; max-width: 45%; }
  .table td[data-label=""]::before { content: none; }
  .table td:last-child { border-bottom: 0; }
  .table .right { text-align: right; }
}

/* ---------- badges, alerts */
.badge { display: inline-flex; align-items: center; padding: 2px 8px; border-radius: 999px; font-size: .75rem; font-weight: 600; white-space: nowrap; background: var(--surface-2); color: var(--muted); }
.badge-ok { background: var(--ok-soft); color: var(--ok); }
.badge-warn { background: var(--warn-soft); color: var(--warn); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }
.badge-info { background: var(--info-soft); color: var(--info); }
.alert { display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border-radius: 10px; }
.alert-danger { background: var(--danger-soft); color: var(--danger); }
.alert-info { background: var(--info-soft); color: var(--info); }
.alert-warn { background: var(--warn-soft); color: var(--warn); }
.alert-ok { background: var(--ok-soft); color: var(--ok); }
.empty { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 32px 16px; color: var(--muted); text-align: center; }
.loading { display: flex; align-items: center; justify-content: center; gap: 10px; padding: 40px; color: var(--muted); }
.spinner { width: 20px; height: 20px; border: 2px solid var(--border); border-top-color: var(--primary); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 9px 14px; border-radius: 10px; border: 1px solid transparent; font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap; min-height: 40px; }
.btn-sm { padding: 5px 10px; min-height: 32px; font-size: .85rem; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: var(--on-primary); }
.btn-primary:hover:not(:disabled) { background: var(--primary-2); }
.btn-ghost { background: var(--surface-2); color: var(--text); }
.btn-ghost:hover:not(:disabled) { background: var(--border); }
.btn-outline { background: var(--surface); border-color: var(--primary); color: var(--primary); }
.btn-outline:hover:not(:disabled) { background: var(--primary-soft); }
.btn-danger { background: var(--danger); color: #fff; }
.vote-options { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0; }

/* ---------- forms */
.form { display: flex; flex-direction: column; gap: 12px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px 14px; }
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field.full { grid-column: 1 / -1; }
.field label { font-size: .85rem; font-weight: 600; }
.field .req { color: var(--danger); }
.field input, .field select, .field textarea, .select {
  width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); color: var(--text); font: inherit; min-height: 42px;
}
.select { width: auto; min-width: 160px; }
.field textarea { resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus, .select:focus { outline: none; border-color: var(--primary-2); box-shadow: 0 0 0 3px var(--primary-soft); }
.field-check label { display: flex; gap: 8px; align-items: center; font-weight: 500; cursor: pointer; }
.field-check input { width: 18px; height: 18px; min-height: 0; accent-color: var(--primary); }
.hint { color: var(--muted); font-size: .78rem; }
.field-error, .form-error { color: var(--danger); font-size: .82rem; min-height: 0; }
.form-error:empty, .field-error:empty { display: none; }
.form-actions { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
.form-inline .form-actions { justify-content: flex-start; }

/* ---------- modal, toast */
.modal-overlay { position: fixed; inset: 0; background: rgba(10, 16, 14, .45); z-index: 100; display: grid; place-items: center; padding: 16px; animation: fade .15s ease; }
.modal { background: var(--surface); border-radius: 16px; width: 100%; max-width: 520px; max-height: calc(100vh - 32px); display: flex; flex-direction: column; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.modal-wide { max-width: 760px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 16px 10px 20px; border-bottom: 1px solid var(--border); }
.modal-body { padding: 16px 20px; overflow-y: auto; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 20px 16px; border-top: 1px solid var(--border); }
@media (max-width: 600px) {
  .modal-overlay { place-items: end center; padding: 0; }
  .modal, .modal-wide { max-width: 100%; border-radius: 16px 16px 0 0; max-height: 92vh; padding-bottom: var(--safe-b); }
}
@keyframes fade { from { opacity: 0; } }
#toasts { position: fixed; z-index: 200; left: 50%; transform: translateX(-50%); bottom: calc(80px + var(--safe-b)); display: flex; flex-direction: column; gap: 8px; width: min(92vw, 420px); }
.toast { display: flex; gap: 8px; align-items: center; padding: 12px 14px; border-radius: 12px; background: var(--text); color: var(--bg); box-shadow: 0 8px 24px rgba(0,0,0,.2); transition: opacity .4s, transform .4s; }
.toast-error { background: var(--danger); color: #fff; }
.toast.hide { opacity: 0; transform: translateY(8px); }

/* ---------- tabs, details, bars, notifications */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); overflow-x: auto; margin-bottom: 14px; scrollbar-width: none; }
.tab { padding: 10px 14px; background: none; border: 0; border-bottom: 2px solid transparent; font: inherit; color: var(--muted); cursor: pointer; white-space: nowrap; font-weight: 600; }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }
.tab-body { display: flex; flex-direction: column; gap: 14px; }
.details { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 0; }
.details dt { color: var(--muted); font-size: .88rem; }
.details dd { margin: 0; word-break: break-word; }
.bars, .poll-results { display: flex; flex-direction: column; gap: 8px; margin: 8px 0; }
.bar-row { display: grid; grid-template-columns: minmax(80px, 160px) 1fr auto; gap: 10px; align-items: center; font-size: .88rem; }
.bar-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { height: 10px; background: var(--surface-2); border-radius: 5px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--primary); border-radius: 5px; min-width: 2px; }
.bar-ok { background: var(--ok); } .bar-warn { background: var(--warn); } .bar-danger { background: var(--danger); } .bar-info { background: var(--info); }
.bar-value { font-variant-numeric: tabular-nums; color: var(--muted); }
.notif-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 8px; }
.notif-list a { display: block; padding: 12px 14px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); color: var(--text); }
.notif-list a:hover { text-decoration: none; border-color: var(--primary-2); }
.notif-list li.unread a { border-left: 4px solid var(--primary); }
.notif-list p { margin: 2px 0; color: var(--muted); }
.prose ul { padding-left: 20px; }
.timeline { list-style: none; padding: 0; margin: 0; border-left: 2px solid var(--border); }
.timeline li { padding: 0 0 12px 14px; position: relative; }
.timeline li::before { content: ""; position: absolute; left: -6px; top: 6px; width: 10px; height: 10px; border-radius: 50%; background: var(--primary); }
.calendar { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.calendar .cal-head { font-size: .72rem; color: var(--muted); text-align: center; font-weight: 600; text-transform: uppercase; }
.calendar .cal-day { min-height: 64px; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 4px; font-size: .75rem; overflow: hidden; }
.calendar .cal-day.other { opacity: .4; }
.calendar .cal-day.today { border-color: var(--primary); }
.calendar .cal-ev { display: block; background: var(--primary-soft); color: var(--primary); border-radius: 4px; padding: 1px 4px; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
@media (max-width: 600px) { .calendar .cal-day { min-height: 44px; } .calendar .cal-ev { font-size: 0; height: 6px; padding: 0; } }
.code-big { font-family: ui-monospace, Menlo, monospace; font-size: 1.8rem; letter-spacing: .2em; text-align: center; padding: 12px; background: var(--surface-2); border-radius: 10px; }
@media print { .sidebar, .topbar, .bottom-nav, .page-actions, .toolbar { display: none !important; } .content { padding: 0; } }
[hidden] { display: none !important; }
@media (min-width: 901px) { .menu-toggle { display: none !important; } }
