:root {
  --bg: #EDF0F4;
  --surface: #FFFFFF;
  --ink: #172239;
  --muted: #5E6A7D;
  --line: #D6DCE5;
  --agency: #0B7A75;
  --client: #6A4BAE;
  --good: #1E8449;
  --mid: #B9770E;
  --bad: #B83227;
  --wait: #8391A5;
  --radius: 10px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: 'Onest', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--bg);
}
a { color: var(--agency); }
h1, h2, h3 { line-height: 1.2; margin: 0; }
h3 { font-size: 1.05rem; font-weight: 600; margin-bottom: .9rem; }
.muted { color: var(--muted); }
.sub { display: block; color: var(--muted); font-size: .82rem; margin-top: 2px; }
.nowrap { white-space: nowrap; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid color-mix(in srgb, var(--agency) 55%, transparent); outline-offset: 2px; }

/* ---------- Top bar ---------- */
.topbar {
  display: flex; align-items: center; gap: 24px; flex-wrap: wrap;
  padding: 12px 28px;
  background: var(--ink); color: #fff;
}
.brand { display: flex; flex-direction: column; line-height: 1.15; }
.brand strong { font-size: 1rem; }
.brand span { font-size: .78rem; color: #AEB8C8; }
.mainnav { display: flex; gap: 4px; flex: 1; }
.mainnav a {
  color: #C9D1DD; text-decoration: none; padding: 7px 14px; border-radius: 6px; font-weight: 500;
}
.mainnav a:hover { color: #fff; background: rgba(255,255,255,.07); }
.mainnav a.on { color: #fff; background: rgba(255,255,255,.14); }
.who { display: flex; gap: 14px; align-items: center; font-size: .88rem; }
.who a { color: #AEB8C8; }

/* ---------- Context bar ---------- */
.context {
  display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap;
  padding: 18px 28px; background: var(--surface); border-bottom: 1px solid var(--line);
}
.client-name { font-size: 1.35rem; font-weight: 700; }
.client-pick { display: flex; align-items: center; gap: 10px; }
.client-pick label { color: var(--muted); font-size: .88rem; }
.client-pick select { font-size: 1.15rem; font-weight: 600; padding: 6px 10px; min-width: 240px; }
.month-nav { display: flex; align-items: center; gap: 6px; }
.month-nav a {
  display: grid; place-items: center; width: 36px; height: 36px; border-radius: 8px;
  border: 1px solid var(--line); text-decoration: none; color: var(--ink); font-size: 1.3rem;
}
.month-nav a:hover { background: var(--bg); }

.wrap { max-width: 1240px; margin: 0 auto; padding: 24px 28px 40px; }

/* ---------- Scoreboard: the two sides of the agreement ---------- */
.scoreboard {
  display: grid; grid-template-columns: 1fr 1fr;
  background: var(--surface); border-radius: var(--radius); overflow: hidden;
  border: 1px solid var(--line); margin-bottom: 24px;
}
.side { padding: 22px 26px 20px; border-top: 5px solid; }
.side-agency { border-top-color: var(--agency); }
.side-client { border-top-color: var(--client); border-left: 1px solid var(--line); }
.side h2 { font-size: 1.1rem; }
.side-role { margin: 2px 0 0; color: var(--muted); font-size: .85rem; }
.score {
  margin: 10px 0 12px; font-size: 4rem; font-weight: 700; line-height: 1;
  font-variant-numeric: tabular-nums; letter-spacing: -.02em;
}
.side-agency .score { color: var(--agency); }
.side-client .score { color: var(--client); }
.score small { font-size: 1.6rem; font-weight: 600; margin-left: 2px; }
.segbar { display: flex; gap: 3px; height: 10px; margin-bottom: 12px; }
.segbar span { border-radius: 3px; }
.segbar .good, .dot.good { background: var(--good); }
.segbar .mid, .dot.mid { background: var(--mid); }
.segbar .bad, .dot.bad { background: var(--bad); }
.segbar .wait, .dot.wait { background: var(--wait); opacity: .45; }
.tally { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 4px 18px; font-size: .85rem; color: var(--muted); }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; vertical-align: 1px; }

/* ---------- Panels & tables ---------- */
.panel {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 20px 22px; margin-bottom: 20px;
}
.panel-agency { border-left: 4px solid var(--agency); }
.panel-client { border-left: 4px solid var(--client); }
.panel-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: .9rem; }
.panel-head h3 { margin: 0; }
.table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th {
  text-align: left; font-weight: 500; color: var(--muted); font-size: .82rem;
  padding: 8px 10px; border-bottom: 1px solid var(--line);
}
td { padding: 12px 10px; border-bottom: 1px solid #EBEEF3; vertical-align: top; }
tbody tr:last-child td { border-bottom: 0; }
.kra-table td:first-child { min-width: 240px; }
.remarks { min-width: 200px; max-width: 340px; }
tr.dim td { opacity: .5; }

.chip {
  display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: .8rem; font-weight: 500;
  white-space: nowrap;
}
.chip.good { background: #E3F2E9; color: #17663A; }
.chip.mid  { background: #FBF0DC; color: #8A5808; }
.chip.bad  { background: #F8E1DF; color: #97271E; }
.chip.wait { background: #EBEEF3; color: #465265; }
.chip.off  { background: #F1F2F4; color: #7A8394; }

.chart-box { position: relative; height: 260px; }

/* ---------- Forms & buttons ---------- */
input, select, textarea {
  font: inherit; color: inherit; width: 100%;
  padding: 8px 10px; border: 1px solid var(--line); border-radius: 7px; background: #fff;
}
input[type=checkbox] { width: auto; }
.month-nav input { width: auto; }
label { display: block; font-size: .88rem; font-weight: 500; }
label > input, label > select, label > textarea { margin-top: 4px; font-weight: 400; }
label.check { display: flex; gap: 8px; align-items: center; font-weight: 400; margin: 6px 0; }
.stack > * + * { margin-top: 12px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.inline-form { display: flex; gap: 10px; align-items: end; margin-bottom: 16px; flex-wrap: wrap; }
.inline-form select { width: auto; min-width: 220px; }
form.inline, details.inline { display: inline-block; vertical-align: top; }

.btn {
  display: inline-block; font: inherit; font-weight: 500; font-size: .9rem; cursor: pointer;
  padding: 8px 16px; border-radius: 7px; border: 1px solid var(--line);
  background: #fff; color: var(--ink); text-decoration: none; list-style: none;
}
.btn::-webkit-details-marker { display: none; }
.btn:hover { background: var(--bg); }
.btn.primary { background: var(--agency); border-color: var(--agency); color: #fff; }
.btn.primary:hover { background: #09625E; }
.btn.danger { color: var(--bad); }
.btn.small { padding: 4px 11px; font-size: .82rem; }

.seg { display: flex; border: 1px solid var(--line); border-radius: 7px; overflow: hidden; }
.seg a { padding: 5px 14px; text-decoration: none; color: var(--muted); font-size: .85rem; }
.seg a.on { background: var(--ink); color: #fff; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 20px; }
.tabs a {
  padding: 10px 16px; text-decoration: none; color: var(--muted); font-weight: 500;
  border-bottom: 3px solid transparent; margin-bottom: -1px;
}
.tabs a.on { color: var(--ink); border-bottom-color: var(--agency); }

.split { display: grid; grid-template-columns: minmax(0, 1.7fr) minmax(280px, 1fr); gap: 20px; align-items: start; }

.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 18px; background: #E3F2E9; color: #17663A; }
.flash.err { background: #F8E1DF; color: #97271E; }

.empty { background: var(--surface); border: 1px dashed var(--line); border-radius: var(--radius); padding: 32px; text-align: center; margin-bottom: 20px; }
.empty h2 { font-size: 1.15rem; margin-bottom: 6px; }

/* ---------- Queries ---------- */
.qlist { list-style: none; margin: 0; padding: 0; }
.q { padding: 14px 0 14px 14px; border-bottom: 1px solid #EBEEF3; border-left: 3px solid; }
.q:last-child { border-bottom: 0; }
.q-client { border-left-color: var(--client); }
.q-agency { border-left-color: var(--agency); }
.q + .q { margin-top: 2px; }
.q-top { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.q p { margin: 6px 0 0; }
.reply { margin-top: 10px; padding: 8px 12px; background: var(--bg); border-radius: 7px; }
.reply p { margin: 2px 0; }
.q-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; align-items: start; }
.q-actions details[open] { flex-basis: 100%; }
.q-actions details form { margin-top: 10px; max-width: 460px; }

/* ---------- Dialog ---------- */
.dlg { border: 0; border-radius: 12px; padding: 0; width: min(520px, 94vw); color: var(--ink); }
.dlg::backdrop { background: rgba(23, 34, 57, .45); }
.dlg form { padding: 22px; }
.dlg form > * + * { margin-top: 12px; }
.dlg-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }

/* ---------- Login ---------- */
.login-page { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: var(--ink); }
.login-card {
  width: min(400px, 100%); background: #fff; border-radius: 12px; padding: 30px;
  border-top: 5px solid var(--agency);
}
.login-card > * + * { margin-top: 14px; }
.login-brand { margin: 0; color: var(--muted); font-size: .9rem; }
.login-card h1 { font-size: 1.5rem; }
.login-card .btn { width: 100%; padding: 10px; }

.foot { max-width: 1240px; margin: 0 auto; padding: 0 28px 32px; color: var(--muted); font-size: .8rem; }

/* ---------- Mobile ---------- */
@media (max-width: 860px) {
  .split { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  .topbar, .context { padding-left: 16px; padding-right: 16px; }
  .wrap { padding: 16px; }
  .topbar { gap: 10px; }
  .mainnav { order: 3; flex-basis: 100%; overflow-x: auto; }
  .who { margin-left: auto; }
  .scoreboard { grid-template-columns: 1fr; }
  .side-client { border-left: 0; }
  .score { font-size: 3.2rem; }
  .client-pick select { min-width: 0; width: 100%; }
  .client-pick { flex: 1; }
  .grid2 { grid-template-columns: 1fr; }
  .panel { padding: 16px; }
}
@media (prefers-reduced-motion: reduce) { * { scroll-behavior: auto !important; } }
