:root {
  --bg: #f5f6f4;
  --surface: #ffffff;
  --surface-2: #f0f2ef;
  --border: #e2e5e0;
  --text: #1c2420;
  --muted: #66706a;
  --accent: #0f5e57;
  --accent-ink: #ffffff;
  --accent-soft: #e3f0ee;
  --danger: #b42318;
  --danger-soft: #fdecea;
  --warn: #a15c07;
  --warn-soft: #fdf3e2;
  --ok: #1d7a3e;
  --ok-soft: #e5f4ea;
  --info: #2457a6;
  --info-soft: #e7eefa;
  --hold: #6b5b95;
  --hold-soft: #efebf6;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 20, .06), 0 4px 16px rgba(16, 24, 20, .06);
  --sidebar: 228px;
  font-family: Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); }
body { font-size: 14px; line-height: 1.45; -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
h1 { font-size: 22px; margin: 0; letter-spacing: -.01em; }
h2 { font-size: 16px; margin: 0 0 12px; }
h3 { font-size: 14px; margin: 0 0 8px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.hidden { display: none !important; }

/* ---------- layout ---------- */
.shell { display: flex; min-height: 100vh; }
.sidebar {
  width: var(--sidebar); flex-shrink: 0; background: #12302c; color: #dfe9e6;
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; padding: 18px 12px;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 20px; font-weight: 700; font-size: 15px; color: #fff; }
.brand-mark { width: 28px; height: 28px; border-radius: 8px; background: #2a8a7f; display: grid; place-items: center; }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 8px;
  color: #c8d8d4; text-decoration: none; font-weight: 500; margin-bottom: 2px;
}
.nav a:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav a.active { background: rgba(255,255,255,.12); color: #fff; }
.nav svg { width: 18px; height: 18px; flex-shrink: 0; }
.sidebar .me { margin-top: auto; padding: 12px 10px 0; border-top: 1px solid rgba(255,255,255,.1); }
.sidebar .me .name { color: #fff; font-weight: 600; }
.sidebar .me button { background: none; border: 0; color: #a9c3bd; padding: 4px 0; cursor: pointer; font-size: 13px; margin-right: 12px; }
.sidebar .me button:hover { color: #fff; }
.main { flex: 1; min-width: 0; padding: 24px 28px 48px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head .actions { display: flex; gap: 8px; flex-wrap: wrap; }
.bottom-nav { display: none; }

@media (max-width: 860px) {
  .sidebar { display: none; }
  .main { padding: 16px 16px 92px; }
  .bottom-nav {
    display: flex; position: fixed; bottom: 0; left: 0; right: 0; background: var(--surface);
    border-top: 1px solid var(--border); z-index: 20; padding-bottom: env(safe-area-inset-bottom);
  }
  .bottom-nav a {
    flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 2px;
    color: var(--muted); text-decoration: none; font-size: 11px; font-weight: 500;
  }
  .bottom-nav a.active { color: var(--accent); }
  .bottom-nav svg { width: 20px; height: 20px; }
  .mobile-top { display: flex !important; }
}
.mobile-top { display: none; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.mobile-top .brand { padding: 0; color: var(--text); }

/* ---------- controls ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--border); background: var(--surface);
  padding: 8px 14px; border-radius: 8px; cursor: pointer; font-weight: 500; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { background: #0b4c46; }
.btn.danger { color: var(--danger); }
.btn.danger:hover { background: var(--danger-soft); }
.btn.ghost { border-color: transparent; background: none; }
.btn.sm { padding: 5px 10px; font-size: 13px; }
.btn:disabled { opacity: .55; cursor: default; }
.btn svg { width: 16px; height: 16px; }
.input, select.input, textarea.input {
  width: 100%; border: 1px solid var(--border); background: var(--surface); border-radius: 8px; padding: 8px 10px; min-height: 36px;
}
.input:focus, .btn:focus-visible, .chip:focus-visible { outline: 2px solid #7fb8b0; outline-offset: 1px; border-color: var(--accent); }
textarea.input { min-height: 84px; resize: vertical; }
label.field { display: block; margin-bottom: 12px; }
label.field > span { display: block; font-weight: 500; margin-bottom: 4px; font-size: 13px; }
.row { display: flex; gap: 12px; }
.row > * { flex: 1; min-width: 0; }
@media (max-width: 560px) { .row.wrap-sm { flex-direction: column; gap: 0; } }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.pad { padding: 16px 18px; }

/* ---------- auth ---------- */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: linear-gradient(160deg, #12302c 0%, #0f5e57 100%); }
.auth-card { width: 100%; max-width: 380px; background: var(--surface); border-radius: 14px; padding: 28px 26px; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.auth-card .brand { color: var(--text); padding: 0 0 18px; font-size: 18px; }
.auth-card p { margin: 0 0 18px; color: var(--muted); }
.auth-card .btn { width: 100%; justify-content: center; padding: 10px; }
.form-error { color: var(--danger); background: var(--danger-soft); border-radius: 8px; padding: 8px 10px; margin-bottom: 12px; font-size: 13px; }

/* ---------- KPIs ---------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 18px; }
.kpi { padding: 14px 16px; }
.kpi .label { color: var(--muted); font-size: 12px; font-weight: 500; text-transform: uppercase; letter-spacing: .04em; }
.kpi .value { font-size: 26px; font-weight: 700; margin-top: 4px; letter-spacing: -.02em; }
.kpi .sub { font-size: 12px; color: var(--muted); }
.kpi.alert .value { color: var(--danger); }
.kpi.clickable { cursor: pointer; }
.kpi.clickable:hover { border-color: #b9cdc8; }

.grid-2 { display: grid; grid-template-columns: 1.4fr 1fr; gap: 16px; margin-bottom: 16px; }
@media (max-width: 1000px) { .grid-2 { grid-template-columns: 1fr; } }

.statusbar { display: flex; height: 12px; border-radius: 6px; overflow: hidden; background: var(--surface-2); margin: 6px 0 12px; }
.statusbar span { display: block; height: 100%; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 13px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }

.chart { width: 100%; height: 180px; display: block; }
.chart text { font-size: 11px; fill: var(--muted); font-family: inherit; }

/* ---------- filters ---------- */
.filters { padding: 12px; margin-bottom: 14px; }
.filters .fgrid { display: grid; grid-template-columns: 2fr repeat(4, 1fr); gap: 8px; }
.filters .fgrid2 { display: grid; grid-template-columns: repeat(4, 1fr) auto; gap: 8px; margin-top: 8px; align-items: center; }
@media (max-width: 1000px) {
  .filters .fgrid, .filters .fgrid2 { grid-template-columns: 1fr 1fr; }
  .filters .fgrid > :first-child { grid-column: 1 / -1; }
}
.filter-toggle { display: none; }
@media (max-width: 760px) {
  .filter-toggle { display: inline-flex; margin-bottom: 8px; }
  .filters:not(.open) .fgrid > :not(:first-child), .filters:not(.open) .fgrid2 { display: none; }
}
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 10px; align-items: center; }
.chip {
  border: 1px solid var(--border); background: var(--surface); border-radius: 999px; padding: 4px 11px; cursor: pointer; font-size: 13px; font-weight: 500;
}
.chip.on { background: var(--accent-soft); border-color: #a9cdc7; color: var(--accent); }
.check { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; cursor: pointer; white-space: nowrap; }
.result-count { font-size: 13px; color: var(--muted); margin-left: auto; }

/* ---------- table ---------- */
.table-wrap { overflow-x: auto; }
table.list { width: 100%; border-collapse: collapse; }
table.list th {
  text-align: left; font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em;
  padding: 10px 12px; border-bottom: 1px solid var(--border); background: var(--surface-2); white-space: nowrap;
}
table.list td { padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.list tr:last-child td { border-bottom: 0; }
table.list tbody tr.clickable { cursor: pointer; }
table.list tbody tr.clickable:hover { background: #fafbf9; }
table.list .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.task-title { font-weight: 600; }
.task-title .parent { display: block; font-weight: 400; font-size: 12px; color: var(--muted); }
.sub-prog { font-size: 12px; color: var(--muted); font-weight: 400; margin-left: 6px; white-space: nowrap; }
.nowrap { white-space: nowrap; }
.overdue { color: var(--danger); font-weight: 600; }
.empty { padding: 36px 16px; text-align: center; color: var(--muted); }

.pill { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.st-todo { background: var(--info-soft); color: var(--info); }
.st-in_progress { background: var(--warn-soft); color: var(--warn); }
.st-on_hold { background: var(--hold-soft); color: var(--hold); }
.st-done { background: var(--ok-soft); color: var(--ok); }
.pr-high { background: var(--danger-soft); color: var(--danger); }
.pr-medium { background: var(--warn-soft); color: var(--warn); }
.pr-low { background: var(--surface-2); color: var(--muted); }
select.status-select { border: 0; border-radius: 999px; padding: 3px 8px; font-size: 12px; font-weight: 600; cursor: pointer; appearance: auto; }
.role-admin { background: var(--accent-soft); color: var(--accent); }
.role-staff { background: var(--surface-2); color: var(--muted); }

/* mobile cards instead of table */
.cards { display: none; }
@media (max-width: 760px) {
  .table-wrap.responsive { display: none; }
  .cards { display: block; }
}
.tcard { padding: 12px 14px; border-bottom: 1px solid var(--border); cursor: pointer; }
.tcard:last-child { border-bottom: 0; }
.tcard .meta { display: flex; flex-wrap: wrap; gap: 6px 10px; align-items: center; margin-top: 6px; font-size: 12px; color: var(--muted); }

/* ---------- modal ---------- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(15, 25, 22, .45); z-index: 50; display: flex; justify-content: flex-end; }
.modal {
  background: var(--surface); width: 100%; max-width: 620px; height: 100%; overflow-y: auto; box-shadow: -10px 0 40px rgba(0,0,0,.15);
  display: flex; flex-direction: column;
}
.modal.center { margin: auto; height: auto; max-height: 92vh; border-radius: 14px; max-width: 520px; }
.modal-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 18px 20px 12px; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--surface); z-index: 1; }
.modal-body { padding: 16px 20px 24px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 20px; border-top: 1px solid var(--border); position: sticky; bottom: 0; background: var(--surface); }
.icon-btn { border: 0; background: none; cursor: pointer; padding: 6px; border-radius: 6px; color: var(--muted); line-height: 0; }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn svg { width: 18px; height: 18px; }
.section { margin-top: 22px; }
.section-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.facts { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 10px 0 4px; }
@media (max-width: 560px) { .facts { grid-template-columns: 1fr 1fr; } }
.fact .k { font-size: 12px; color: var(--muted); }
.fact .v { font-weight: 600; }
.desc { white-space: pre-wrap; background: var(--surface-2); border-radius: 8px; padding: 10px 12px; }
.sublist .subrow { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--border); }
.sublist .subrow:last-child { border-bottom: 0; }
.sublist .subrow .t { flex: 1; min-width: 0; cursor: pointer; }
.sublist .subrow .t:hover { color: var(--accent); }
.logrow { display: flex; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--border); align-items: flex-start; }
.logrow:last-child { border-bottom: 0; }
.logrow .when { width: 92px; flex-shrink: 0; color: var(--muted); font-size: 13px; }
.logrow .what { flex: 1; min-width: 0; }
.logrow .dur { font-weight: 600; white-space: nowrap; }
.inline-form { background: var(--surface-2); border-radius: 8px; padding: 12px; margin-top: 8px; }
.inline-form .row { gap: 8px; }

#toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px); opacity: 0; pointer-events: none;
  background: #1c2420; color: #fff; padding: 10px 16px; border-radius: 8px; z-index: 100; transition: all .2s; font-weight: 500; max-width: 90vw;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.err { background: var(--danger); }
@media (max-width: 860px) { #toast { bottom: 84px; } }

.loading { padding: 40px; text-align: center; color: var(--muted); }
.person-head { display: flex; align-items: center; gap: 14px; }
.avatar { width: 40px; height: 40px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; font-weight: 700; flex-shrink: 0; }
.avatar.sm { width: 28px; height: 28px; font-size: 12px; }
.who { display: inline-flex; align-items: center; gap: 8px; }
.range { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.range .input { width: auto; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 14px; }
.tabs button { border: 0; background: none; padding: 10px 12px; cursor: pointer; font-weight: 600; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs button.on { color: var(--accent); border-color: var(--accent); }
