:root {
  --navy: #0a1f52; --navy-2: #153d9a; --accent: #2563eb;
  --bg: #f4f6fb; --panel: #ffffff; --line: #e1e6f0; --text: #172033; --muted: #66708a;
  --ok: #0f9d58; --warn: #d97706; --bad: #c62828; --soft-bad: #fde8e8; --soft-ok: #e3f6ec; --soft-warn: #fff1dc;
  --soft-blue: #e8efff; --shadow: 0 1px 2px rgba(10,31,82,.06), 0 4px 14px rgba(10,31,82,.06);
  --radius: 10px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e1424; --panel: #151c30; --line: #263050; --text: #e6eaf5; --muted: #93a0c0;
    --soft-bad: #3a1c22; --soft-ok: #14301f; --soft-warn: #3a2a12; --soft-blue: #1a2650; --accent: #6b9bff;
    --shadow: 0 1px 2px rgba(0,0,0,.4);
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font: 14px/1.45 "Segoe UI", system-ui, -apple-system, Arial, sans-serif; background: var(--bg); color: var(--text); }
h1, h2, h3 { margin: 0; font-weight: 650; }
h1 { font-size: 20px; } h2 { font-size: 15px; } h3 { font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); text-decoration: none; cursor: pointer; } a:hover { text-decoration: underline; }
.muted { color: var(--muted); } .right { text-align: right; } .nowrap { white-space: nowrap; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.hidden { display: none !important; }

/* ---------- shell ---------- */
.shell { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.side { background: var(--navy); color: #cfd8f2; padding: 18px 12px; display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 18px; color: #fff; font-weight: 700; font-size: 16px; }
.brand .logo { width: 30px; height: 30px; border-radius: 8px; background: #fff; color: var(--navy); display: grid; place-items: center; font-weight: 800; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 8px; color: #cfd8f2; margin-bottom: 2px; }
.nav a:hover { background: rgba(255,255,255,.08); text-decoration: none; }
.nav a.active { background: rgba(255,255,255,.16); color: #fff; font-weight: 600; }
.nav .ico { width: 18px; text-align: center; opacity: .9; }
.badge-count { margin-left: auto; background: #ffd966; color: #3b2d00; border-radius: 10px; font-size: 11px; padding: 0 7px; font-weight: 700; }
.side .me { margin-top: auto; padding: 12px 10px; border-top: 1px solid rgba(255,255,255,.14); font-size: 13px; }
.side .me b { color: #fff; display: block; } .side .me .links { margin-top: 8px; display: flex; gap: 12px; }
.side .me a { color: #9db4ff; font-size: 12px; }
.main { padding: 22px 28px 60px; min-width: 0; }
.topbar { display: flex; align-items: center; gap: 14px; margin-bottom: 18px; flex-wrap: wrap; }
.topbar .spacer { flex: 1; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; background: var(--soft-blue); color: var(--navy-2); font-size: 12px; font-weight: 600; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .chip { color: #bcd0ff; } }
.chip.mock { background: var(--soft-warn); color: var(--warn); }
.chip.ok { background: var(--soft-ok); color: var(--ok); } .chip.bad { background: var(--soft-bad); color: var(--bad); }
.chip.warn { background: var(--soft-warn); color: var(--warn); }

/* ---------- controls ---------- */
.btn { border: 1px solid var(--line); background: var(--panel); border-radius: 8px; padding: 7px 14px; cursor: pointer; font-weight: 600; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--bad); }
.btn.small { padding: 3px 10px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
input[type=text], input[type=search], input[type=password], input[type=date], input[type=number], input[type=email], select, textarea {
  width: 100%; padding: 7px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); }
textarea { resize: vertical; min-height: 70px; }
input:focus, select:focus, textarea:focus, .btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
label.field { display: block; font-size: 12px; color: var(--muted); font-weight: 600; margin-bottom: 10px; }
label.field > :not(span) { margin-top: 4px; color: var(--text); font-weight: 400; }
.row { display: flex; gap: 12px; } .row > * { flex: 1; min-width: 0; }
.checkline { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; }

/* ---------- cards / grids ---------- */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px 18px; }
.card h2 { margin-bottom: 12px; display: flex; align-items: center; gap: 8px; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; margin-bottom: 16px; }
.kpi .label { color: var(--muted); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
.kpi .value { font-size: 24px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi .sub { color: var(--muted); font-size: 12px; margin-top: 2px; }
.kpi.alert .value { color: var(--bad); }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(380px, 1fr)); gap: 16px; margin-bottom: 16px; }
.bars .bar-row { display: grid; grid-template-columns: 110px 1fr 130px; align-items: center; gap: 10px; padding: 5px 0; cursor: default; }
.bars .bar-row.link { cursor: pointer; } .bars .bar-row.link:hover .bar-label { color: var(--accent); }
.bar-track { background: var(--bg); border-radius: 6px; height: 14px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 6px; background: var(--accent); min-width: 2px; }
.bar-val { text-align: right; font-variant-numeric: tabular-nums; font-size: 13px; }
.empty { text-align: center; padding: 60px 20px; color: var(--muted); }
.empty h2 { color: var(--text); font-size: 18px; margin-bottom: 8px; }

/* ---------- tables ---------- */
.tablewrap { overflow: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); box-shadow: var(--shadow); }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th { position: sticky; top: 0; background: var(--panel); text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--line); font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); white-space: nowrap; user-select: none; z-index: 1; }
th.sortable { cursor: pointer; } th.sortable:hover { color: var(--accent); }
td { padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr.clickable { cursor: pointer; } tbody tr.clickable:hover { background: var(--soft-blue); }
td .sub { color: var(--muted); font-size: 12px; }
.tag { display: inline-block; padding: 1px 9px; border-radius: 999px; font-size: 11.5px; font-weight: 600; background: var(--bg); border: 1px solid var(--line); white-space: nowrap; }
.tag.b0 { background: var(--soft-ok); color: var(--ok); border-color: transparent; }
.tag.b1 { background: #fff7d6; color: #8a6d00; border-color: transparent; }
.tag.b2 { background: var(--soft-warn); color: var(--warn); border-color: transparent; }
.tag.b3 { background: #ffe0cc; color: #b34700; border-color: transparent; }
.tag.b4, .tag.b5 { background: var(--soft-bad); color: var(--bad); border-color: transparent; }
.tag.pri-urgent, .tag.pri-high { background: var(--soft-bad); color: var(--bad); border-color: transparent; }
.tag.st-done { background: var(--soft-ok); color: var(--ok); border-color: transparent; }
.tag.st-in_progress { background: var(--soft-blue); color: var(--navy-2); border-color: transparent; }
.flagmark { color: var(--bad); font-weight: 700; }
.pager { display: flex; align-items: center; gap: 10px; padding: 10px 2px; color: var(--muted); font-size: 13px; }
.pager .spacer { flex: 1; }
.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: end; margin-bottom: 14px; }
.filters > * { width: auto; min-width: 140px; }
.filters .search { min-width: 240px; flex: 1; max-width: 380px; }
.bulkbar { position: sticky; bottom: 12px; margin-top: 12px; background: var(--navy); color: #fff; border-radius: 10px; padding: 10px 16px; display: flex; gap: 14px; align-items: center; box-shadow: var(--shadow); }
.bulkbar .btn { background: #fff; color: var(--navy); }

/* ---------- drawer / modal ---------- */
.overlay { position: fixed; inset: 0; background: rgba(10,20,45,.45); z-index: 40; display: flex; justify-content: flex-end; }
.drawer { background: var(--bg); width: min(720px, 100%); height: 100%; overflow: auto; padding: 20px 22px 60px; box-shadow: -8px 0 30px rgba(0,0,0,.25); animation: slide .15s ease-out; }
@keyframes slide { from { transform: translateX(30px); opacity: 0; } }
.drawer-head { display: flex; align-items: start; gap: 12px; margin-bottom: 16px; }
.drawer-head .spacer { flex: 1; }
.x { border: 0; background: transparent; font-size: 24px; line-height: 1; cursor: pointer; color: var(--muted); }
.modal-wrap { justify-content: center; align-items: center; }
.modal { background: var(--panel); border-radius: 12px; width: min(520px, 94vw); max-height: 92vh; overflow: auto; padding: 20px 22px; box-shadow: 0 20px 60px rgba(0,0,0,.35); }
.modal h2 { font-size: 17px; margin-bottom: 14px; }
.modal .actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 14px; }
.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px 16px; }
.facts dt { font-size: 11.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.facts dd { margin: 2px 0 0; font-weight: 600; word-break: break-word; }
.section { margin-top: 16px; }
.section > h3 { margin-bottom: 8px; }
.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { padding: 8px 0 8px 14px; border-left: 2px solid var(--line); margin-left: 4px; position: relative; }
.timeline li::before { content: ""; position: absolute; left: -6px; top: 14px; width: 10px; height: 10px; border-radius: 50%; background: var(--accent); }
.timeline li.k-status::before { background: var(--warn); } .timeline li.k-promise::before { background: var(--ok); }
.timeline li.k-assignment::before { background: var(--navy-2); }
.timeline .meta { color: var(--muted); font-size: 12px; }
.flagbox { background: var(--soft-bad); color: var(--bad); border-radius: 8px; padding: 8px 12px; font-size: 13px; }

/* ---------- toasts / login ---------- */
#toasts { position: fixed; right: 18px; bottom: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 100; }
.toast { background: var(--navy); color: #fff; padding: 10px 16px; border-radius: 8px; box-shadow: var(--shadow); max-width: 380px; }
.toast.err { background: var(--bad); }
.login { min-height: 100vh; display: grid; place-items: center; background: linear-gradient(160deg, var(--navy), var(--navy-2)); padding: 20px; }
.login .box { background: var(--panel); border-radius: 14px; padding: 30px; width: min(380px, 100%); box-shadow: 0 20px 60px rgba(0,0,0,.35); }
.login h1 { margin-bottom: 4px; } .login p { margin: 0 0 18px; color: var(--muted); }
.err-text { color: var(--bad); font-size: 13px; min-height: 18px; margin: 4px 0; }
.log { background: #0b1226; color: #b7c4ec; font: 12px/1.5 Consolas, monospace; padding: 10px 12px; border-radius: 8px; max-height: 200px; overflow: auto; white-space: pre-wrap; margin-top: 10px; }
.spin { display: inline-block; width: 14px; height: 14px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .7s linear infinite; vertical-align: -2px; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; padding: 10px; }
  .brand { padding: 0 8px 0 0; } .nav { display: flex; flex-wrap: wrap; } .side .me { margin: 0 0 0 auto; border: 0; padding: 0; }
  .main { padding: 16px 14px 60px; }
}
