:root {
  --bg: #0f1623;
  --panel: #16202f;
  --panel-2: #1d293b;
  --card: #1b2736;
  --line: #26344a;
  --text: #e6edf6;
  --muted: #8ea0b8;
  --accent: #2f81f7;
  --accent-2: #1f6feb;
  --green: #2ea043;
  --amber: #d2992a;
  --red: #e5534b;
  --purple: #8957e5;
  --radius: 12px;
  --shadow: 0 8px 30px rgba(0,0,0,.35);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.45;
}

/* ---------- top bar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; padding: 14px 24px;
  background: linear-gradient(180deg, #16202f, #131b27);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20;
}
.brand { display: flex; align-items: center; gap: 12px; }
.logo {
  width: 40px; height: 40px; border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), var(--purple));
  display: grid; place-items: center; font-weight: 800; letter-spacing: .5px;
}
.topbar h1 { font-size: 18px; margin: 0; }
.sub { margin: 0; font-size: 12px; color: var(--muted); }
.topbar-right { display: flex; align-items: center; gap: 10px; }
.whoami { font-size: 13px; color: var(--text); }
.whoami .who-role { color: var(--muted); }

/* login screen */
.login-screen { position: fixed; inset: 0; z-index: 60; display: grid; place-items: center; background: radial-gradient(1200px 600px at 50% -10%, #1b2740, var(--bg)); padding: 20px; }
.login-card { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow); padding: 30px 28px; width: 340px; max-width: 92vw; display: flex; flex-direction: column; gap: 12px; text-align: center; }
.login-card .logo { width: 52px; height: 52px; border-radius: 12px; margin: 0 auto 4px; font-size: 18px; }
.login-card h1 { margin: 0; font-size: 20px; }
.login-card .sub { margin: 0 0 8px; }
.login-card input { width: 100%; padding: 11px 12px; }
.login-card .btn { width: 100%; padding: 11px; margin-top: 4px; }
.login-err { background: rgba(229,83,75,.15); border: 1px solid var(--red); color: #ff9089; border-radius: 8px; padding: 8px 10px; font-size: 13px; }

/* ---------- generic ---------- */
main { max-width: 1180px; margin: 0 auto; padding: 22px; }
.muted { color: var(--muted); font-size: 12px; }
select, input[type="search"], input[type="text"], input[type="date"], input[type="number"], textarea {
  background: #0e1622; color: var(--text);
  border: 1px solid var(--line); border-radius: 8px;
  padding: 8px 10px; font: inherit; outline: none;
}
select:focus, input:focus, textarea:focus { border-color: var(--accent); }
textarea { width: 100%; resize: vertical; min-height: 64px; }

.btn {
  border: 1px solid var(--line); background: #1a2435; color: var(--text);
  border-radius: 8px; padding: 8px 14px; font: inherit; cursor: pointer;
  transition: background .15s, border-color .15s;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent-2); border-color: var(--accent-2); color: #fff; font-weight: 600; }
.btn.primary:hover { background: var(--accent); }
.btn.ghost { background: transparent; }
.btn.green { background: var(--green); border-color: var(--green); color: #fff; }
.btn.amber { background: var(--amber); border-color: var(--amber); color: #221a06; }
.btn.danger { background: transparent; border-color: var(--red); color: var(--red); }
.btn.sm { padding: 5px 10px; font-size: 12px; }

/* ---------- KPI cards ---------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 14px; margin-bottom: 18px; }
.kpi {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow);
}
.kpi .label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; }
.kpi .value { font-size: 30px; font-weight: 800; margin-top: 6px; }
.kpi .value small { font-size: 16px; font-weight: 600; color: var(--muted); }
.kpi .hint { font-size: 12px; color: var(--muted); margin-top: 4px; }
.kpi.target { grid-column: span 2; }
.progress { height: 10px; background: #0e1622; border-radius: 6px; overflow: hidden; margin-top: 10px; border: 1px solid var(--line); }
.progress > span { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), var(--green)); }
.tag-good { color: var(--green); } .tag-bad { color: var(--red); } .tag-warn { color: var(--amber); }

/* ---------- panels ---------- */
.panel {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 16px 18px; margin-bottom: 18px; box-shadow: var(--shadow);
}
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.panel-head h2 { font-size: 15px; margin: 0; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- trend ---------- */
.trend { display: flex; align-items: flex-end; gap: 14px; height: 140px; padding-top: 8px; }
.trend .bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; height: 100%; justify-content: flex-end; }
.trend .bar { width: 70%; max-width: 46px; border-radius: 6px 6px 0 0; background: linear-gradient(180deg, var(--accent), var(--accent-2)); position: relative; min-height: 2px; transition: height .3s; }
.trend .bar.hit { background: linear-gradient(180deg, var(--green), #1f7a32); }
.trend .bar .n { position: absolute; top: -18px; left: 50%; transform: translateX(-50%); font-size: 12px; font-weight: 700; }
.trend .bar-label { font-size: 11px; color: var(--muted); text-align: center; white-space: nowrap; }

/* ---------- table ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { font-size: 11px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); }
tbody tr { cursor: pointer; }
tbody tr:hover { background: #1a2435; }
.empty { text-align: center; color: var(--muted); padding: 24px; }

.badge { display: inline-block; padding: 3px 9px; border-radius: 999px; font-size: 11px; font-weight: 700; }
.type-badge { background: #0e1622; border: 1px solid var(--line); color: var(--text); }
.st-not_started { background: rgba(142,160,184,.15); color: #b7c4d6; }
.st-in_progress { background: rgba(47,129,247,.18); color: #79b2ff; }
.st-waiting { background: rgba(210,153,42,.18); color: #f0c46b; }
.st-review { background: rgba(137,87,229,.2); color: #c0a3ff; }
.st-completed { background: rgba(46,160,67,.2); color: #6fdd8b; }
.pill-overdue { color: var(--red); font-weight: 700; }
.pill-soon { color: var(--amber); font-weight: 700; }
.prio-high::before { content: "★ "; color: var(--amber); }
.clip { max-width: 360px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.col-num { width: 40px; text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; }

/* breakdown panels */
.breakdowns { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 18px; margin-bottom: 18px; }
.hbars { display: flex; flex-direction: column; gap: 9px; }
.hbar-row { display: flex; align-items: center; gap: 10px; font-size: 12px; }
.hbar-label { width: 120px; flex-shrink: 0; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hbar-track { flex: 1; height: 14px; background: #0e1622; border: 1px solid var(--line); border-radius: 5px; overflow: hidden; }
.hbar-fill { height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent-2)); }
.hbar-val { width: 86px; flex-shrink: 0; text-align: right; font-weight: 700; color: var(--text); }

.note { background: #131c28; border: 1px solid var(--line); border-radius: 8px; padding: 8px 11px; font-size: 13px; white-space: pre-wrap; }

/* ratings */
.rating { display: inline-block; margin-left: 6px; padding: 2px 7px; border-radius: 999px; font-size: 11px; font-weight: 800; }
.rate-good { background: rgba(46,160,67,.22); color: #6fdd8b; }
.rate-mid { background: rgba(210,153,42,.22); color: #f0c46b; }
.rate-bad { background: rgba(229,83,75,.22); color: #ff9089; }

.review-form { background: #131c28; border: 1px solid var(--line); border-left: 3px solid var(--amber); border-radius: 0 10px 10px 0; padding: 12px 14px; margin: 14px 0; }
.review-form textarea { margin-top: 10px; }
.score-picker { display: flex; gap: 5px; flex-wrap: wrap; margin-top: 10px; }
.score { width: 34px; height: 34px; border-radius: 8px; border: 1px solid var(--line); background: #0e1622; color: var(--muted); font-weight: 700; cursor: pointer; }
.score:hover { border-color: var(--accent); color: var(--text); }
.score.sel { color: #fff; border-color: transparent; transform: translateY(-1px); }
.score.sel.rate-good { background: var(--green); }
.score.sel.rate-mid { background: var(--amber); color: #221a06; }
.score.sel.rate-bad { background: var(--red); }
.score-legend { font-size: 11px; color: var(--muted); margin-top: 6px; }
.review-actions { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }

.review-item { border-left: 3px solid var(--amber); background: #131c28; border-radius: 0 8px 8px 0; padding: 7px 11px; margin-bottom: 10px; }
.review-item .body { font-size: 13px; margin: 4px 0; white-space: pre-wrap; }
.review-item .when { color: var(--muted); font-size: 11px; margin-left: 8px; }
.review-decision { font-size: 11px; font-weight: 700; margin-left: 8px; padding: 1px 7px; border-radius: 999px; }
.review-decision.ok { background: rgba(46,160,67,.2); color: #6fdd8b; }
.review-decision.back { background: rgba(229,83,75,.2); color: #ff9089; }

/* ---------- drawer ---------- */
.drawer-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 30; }
.drawer {
  position: fixed; top: 0; right: 0; height: 100vh; width: 460px; max-width: 94vw;
  background: var(--panel); border-left: 1px solid var(--line); z-index: 31;
  box-shadow: var(--shadow); overflow-y: auto; padding: 20px;
}
.drawer h2 { margin: 0 0 2px; font-size: 18px; }
.drawer .meta-grid { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; margin: 14px 0; font-size: 13px; }
.drawer .meta-grid dt { color: var(--muted); }
.drawer .meta-grid dd { margin: 0; }
.drawer-actions { display: flex; gap: 8px; flex-wrap: wrap; margin: 14px 0; }
.section-title { font-size: 12px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); margin: 18px 0 8px; border-top: 1px solid var(--line); padding-top: 14px; }

.comment { border-left: 3px solid var(--line); padding: 6px 10px; margin-bottom: 10px; background: #131c28; border-radius: 0 8px 8px 0; }
.comment.assigner { border-color: #b7c4d6; }
.comment.preparer { border-color: var(--accent); }
.comment.reviewer { border-color: var(--amber); }
.comment .who { font-weight: 700; font-size: 12px; }
.comment .who .role { font-weight: 500; color: var(--muted); margin-left: 6px; font-size: 11px; }
.comment .when { float: right; color: var(--muted); font-size: 11px; }
.comment .body { font-size: 13px; margin-top: 2px; white-space: pre-wrap; }

.log-item { font-size: 12px; color: var(--muted); padding: 3px 0; }
.log-item b { color: var(--text); font-weight: 600; }

.add-comment { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }

/* ---------- modal ---------- */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 40; display: grid; place-items: center; padding: 20px; }
.modal { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); width: 520px; max-width: 96vw; max-height: 92vh; overflow-y: auto; padding: 22px; box-shadow: var(--shadow); }
.modal h2 { margin: 0 0 16px; font-size: 18px; }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 5px; }
.field input, .field select, .field textarea { width: 100%; }
.field-row { display: flex; gap: 12px; }
.field-row .field { flex: 1; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 8px; }
.err { color: var(--red); font-size: 13px; margin-bottom: 10px; }
.close-x { float: right; cursor: pointer; color: var(--muted); font-size: 20px; line-height: 1; background: none; border: none; }

.people-list { margin: 6px 0 16px; }
.people-row { display: flex; align-items: center; gap: 8px; padding: 6px 0; border-bottom: 1px solid var(--line); }
.people-row .role-chip { font-size: 11px; padding: 2px 8px; border-radius: 999px; background: #0e1622; border: 1px solid var(--line); color: var(--muted); }

/* ---------- toast ---------- */
.toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); background: #0e1622; border: 1px solid var(--line); color: var(--text); padding: 10px 18px; border-radius: 8px; z-index: 50; box-shadow: var(--shadow); }
.toast.err { border-color: var(--red); }

@media (max-width: 640px) {
  .kpi.target { grid-column: span 2; }
  .topbar { flex-wrap: wrap; }
}
