:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-2: #eef1f5;
  --border: #dde3ea;
  --text: #16212b;
  --text-dim: #5b6b7b;
  --brand: #0f4c5c;
  --brand-2: #14657a;
  --accent: #0e9f8a;
  --accent-soft: #d9f2ee;
  --danger: #c0392b;
  --warn: #b7791f;
  --warn-soft: #fdf1dc;
  --ok: #1e7e4e;
  --ok-soft: #ddf2e5;
  --info-soft: #e1ecf7;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(22,33,43,.08), 0 4px 16px rgba(22,33,43,.05);
  --nav-h: 60px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1220;
    --surface: #131c2b;
    --surface-2: #1a2537;
    --border: #263349;
    --text: #e8edf4;
    --text-dim: #8fa1b5;
    --brand: #4fd1c5;
    --brand-2: #38b2a5;
    --accent: #4fd1c5;
    --accent-soft: #12332f;
    --warn-soft: #33270f;
    --ok-soft: #11301f;
    --info-soft: #16263c;
    --shadow: 0 1px 3px rgba(0,0,0,.4);
  }
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg); color: var(--text);
  padding-bottom: env(safe-area-inset-bottom);
}
a { color: var(--brand); text-decoration: none; }
.boot { padding: 40vh 20px 0; text-align: center; color: var(--text-dim); }

/* ---------- layout ---------- */
.layout { display: flex; min-height: 100vh; }
.sidebar {
  width: 232px; flex-shrink: 0; background: var(--surface); border-right: 1px solid var(--border);
  position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; padding: 18px 12px;
}
.sidebar .logo { display: flex; align-items: center; gap: 10px; padding: 4px 10px 18px; font-weight: 700; font-size: 17px; color: var(--brand); }
.sidebar .logo img { width: 32px; height: 32px; border-radius: 8px; }
.sidebar nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.sidebar nav a {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 9px;
  color: var(--text-dim); font-weight: 500;
}
.sidebar nav a.active, .sidebar nav a:hover { background: var(--surface-2); color: var(--text); }
.sidebar nav a .ico { width: 20px; text-align: center; }
.sidebar .me { padding: 10px 12px; border-top: 1px solid var(--border); font-size: 13px; color: var(--text-dim); }
.sidebar .me b { display: block; color: var(--text); }

.main { flex: 1; min-width: 0; padding: 22px 26px 90px; max-width: 1280px; }
.topbar { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.topbar h1 { font-size: 22px; flex: 1; }

.bottom-nav { display: none; }

@media (max-width: 860px) {
  .sidebar { display: none; }
  .main { padding: 14px 14px calc(var(--nav-h) + 24px + env(safe-area-inset-bottom)); }
  .bottom-nav {
    display: flex; position: fixed; bottom: 0; left: 0; right: 0; z-index: 50;
    background: var(--surface); border-top: 1px solid var(--border);
    height: calc(var(--nav-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
  }
  .bottom-nav a {
    flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
    color: var(--text-dim); font-size: 10.5px; font-weight: 500;
  }
  .bottom-nav a.active { color: var(--brand); }
  .bottom-nav a .ico { font-size: 20px; }
}

/* ---------- components ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }
.grid { display: grid; gap: 14px; }
.grid.cols-2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.grid.stats { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.stat { text-align: left; }
.stat .n { font-size: 26px; font-weight: 700; color: var(--brand); }
.stat .l { font-size: 12.5px; color: var(--text-dim); }

.btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; border-radius: 9px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font-size: 14px; font-weight: 600; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-2); }
@media (prefers-color-scheme: dark) { .btn.primary { color: #08131f; } }
.btn.danger { color: var(--danger); border-color: var(--danger); background: transparent; }
.btn.sm { padding: 4px 10px; font-size: 12.5px; }
.btn:disabled { opacity: .5; cursor: default; }

input, select, textarea {
  width: 100%; padding: 9px 11px; border: 1px solid var(--border); border-radius: 9px;
  background: var(--surface); color: var(--text); font: inherit; font-size: 14px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); outline-offset: -1px; }
label { display: block; font-size: 12.5px; font-weight: 600; color: var(--text-dim); margin: 10px 0 4px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.form-grid .full { grid-column: 1 / -1; }
@media (max-width: 560px) { .form-grid { grid-template-columns: 1fr; } }

.badge {
  display: inline-block; padding: 2px 9px; border-radius: 20px; font-size: 11.5px; font-weight: 600;
  background: var(--surface-2); color: var(--text-dim); white-space: nowrap;
}
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.info { background: var(--info-soft); color: var(--brand-2); }
.badge.accent { background: var(--accent-soft); color: var(--accent); }
.badge.danger { background: #fdecea; color: var(--danger); }
@media (prefers-color-scheme: dark) { .badge.danger { background: #3a1713; } }

table.list { width: 100%; border-collapse: collapse; font-size: 14px; }
table.list th { text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .4px; color: var(--text-dim); padding: 8px 10px; border-bottom: 1px solid var(--border); }
table.list td { padding: 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.list tr:last-child td { border-bottom: 0; }
table.list tr.click { cursor: pointer; }
table.list tr.click:hover td { background: var(--surface-2); }
.table-wrap { overflow-x: auto; }

.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.spread { justify-content: space-between; }
.muted { color: var(--text-dim); font-size: 13px; }
.right { text-align: right; }
.mt { margin-top: 14px; } .mb { margin-bottom: 14px; }
h2 { font-size: 16px; margin-bottom: 10px; }
h3 { font-size: 14px; margin-bottom: 8px; }
.empty { padding: 26px; text-align: center; color: var(--text-dim); }

/* kanban */
.kanban { display: flex; gap: 12px; overflow-x: auto; padding-bottom: 10px; }
.kanban .col { min-width: 240px; width: 240px; flex-shrink: 0; background: var(--surface-2); border-radius: var(--radius); padding: 10px; }
.kanban .col h4 { font-size: 12px; text-transform: uppercase; letter-spacing: .5px; color: var(--text-dim); padding: 2px 4px 8px; display: flex; justify-content: space-between; }
.kanban .kcard { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; margin-bottom: 8px; cursor: pointer; box-shadow: var(--shadow); }
.kanban .kcard:hover { border-color: var(--brand); }
.kanban .kcard .t { font-weight: 600; font-size: 13.5px; }
.kanban .kcard .s { font-size: 12px; color: var(--text-dim); margin-top: 3px; }

/* funnel */
.funnel-bar { display: flex; height: 26px; border-radius: 8px; overflow: hidden; background: var(--surface-2); font-size: 11px; color: #fff; }
.funnel-bar div { display: flex; align-items: center; justify-content: center; min-width: 0; overflow: hidden; }

/* timeline */
.timeline { list-style: none; }
.timeline li { display: flex; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.timeline li:last-child { border-bottom: 0; }
.timeline .dot { width: 34px; height: 34px; border-radius: 50%; background: var(--surface-2); display: flex; align-items: center; justify-content: center; flex-shrink: 0; font-size: 15px; }
.timeline .what { flex: 1; min-width: 0; }
.timeline .what .s { font-weight: 600; font-size: 13.5px; }
.timeline .what .b { font-size: 13px; color: var(--text-dim); white-space: pre-wrap; word-break: break-word; }
.timeline .when { font-size: 11.5px; color: var(--text-dim); white-space: nowrap; }

/* modal */
#modal-host .overlay {
  position: fixed; inset: 0; background: rgba(10,16,26,.55); z-index: 100;
  display: flex; align-items: flex-start; justify-content: center; padding: 4vh 14px; overflow-y: auto;
}
#modal-host .modal {
  background: var(--surface); border-radius: 14px; width: 100%; max-width: 620px;
  padding: 20px; box-shadow: 0 20px 60px rgba(0,0,0,.3); margin-bottom: 6vh;
}
#modal-host .modal h2 { margin-bottom: 4px; }
@media (max-width: 560px) { #modal-host .overlay { padding: 0; align-items: stretch; } #modal-host .modal { border-radius: 0; max-width: none; min-height: 100vh; } }

/* toast */
#toast-host { position: fixed; bottom: calc(var(--nav-h) + 14px); left: 50%; transform: translateX(-50%); z-index: 200; display: flex; flex-direction: column; gap: 8px; width: min(92vw, 420px); }
@media (min-width: 861px) { #toast-host { bottom: 20px; } }
.toast { background: var(--text); color: var(--bg); padding: 11px 16px; border-radius: 10px; font-size: 14px; box-shadow: var(--shadow); animation: pop .18s ease; }
.toast.err { background: var(--danger); color: #fff; }
@keyframes pop { from { opacity: 0; transform: translateY(8px); } }

/* login */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.login-card { width: 100%; max-width: 400px; text-align: center; }
.login-card img { width: 72px; height: 72px; border-radius: 18px; margin-bottom: 14px; }
.login-card h1 { font-size: 22px; margin-bottom: 6px; }
.login-card p { color: var(--text-dim); margin-bottom: 20px; }

.notif-item { display: flex; gap: 10px; padding: 12px 4px; border-bottom: 1px solid var(--border); }
.notif-item.unread { background: var(--info-soft); border-radius: 8px; padding: 12px 10px; }
.searchbar { flex: 1; min-width: 160px; max-width: 340px; }
.chip-row { display: flex; gap: 6px; flex-wrap: wrap; }
.localtime { font-variant-numeric: tabular-nums; }
.avatar { width: 38px; height: 38px; border-radius: 50%; background: var(--brand); color: #fff; display: inline-flex; align-items: center; justify-content: center; font-weight: 700; font-size: 14px; flex-shrink: 0; }
@media (prefers-color-scheme: dark) { .avatar { color: #08131f; } }
