/* BTI OKR — visual system.
   Chart colors follow the validated dataviz reference palette; chrome is a
   quiet command-center: ink-navy rail, soft warm plane, blue reserved for action. */

:root {
  color-scheme: light;
  --bg: #f9f9f7;            /* page plane */
  --surface: #fcfcfb;       /* cards & chart surface */
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --line: #c3c2b7;
  --border: rgba(11, 11, 11, 0.09);
  --accent: #2a78d6;
  --accent-strong: #1c5cab;
  --accent-soft: rgba(42, 120, 214, 0.10);
  --accent-track: #cde2fb;
  --s1: #2a78d6; --s2: #1baf7a; --s3: #eda100; --s4: #008300;
  --s5: #4a3aa7; --s6: #e34948; --s7: #e87ba4; --s8: #eb6834;
  --good: #0ca30c; --warning: #fab219; --serious: #ec835a; --critical: #d03b3b;
  --good-text: #006300;
  --warn-track: #f7e3b5; --bad-track: #f5cfcf;
  --shadow: 0 1px 2px rgba(15, 28, 46, 0.05), 0 8px 24px rgba(15, 28, 46, 0.05);
  --shadow-pop: 0 24px 60px rgba(15, 28, 46, 0.25);
  /* the rail keeps its own world in both themes */
  --side-bg: #0f1c2e;
  --side-ink: rgba(255, 255, 255, 0.92);
  --side-ink-2: rgba(255, 255, 255, 0.55);
  --side-label: rgba(255, 255, 255, 0.38);
  --side-hover: rgba(255, 255, 255, 0.07);
  --side-active: rgba(57, 135, 229, 0.28);
  --side-border: rgba(255, 255, 255, 0.08);
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #0d0d0d;
    --surface: #1a1a19;
    --ink: #ffffff;
    --ink-2: #c3c2b7;
    --muted: #898781;
    --grid: #2c2c2a;
    --line: #383835;
    --border: rgba(255, 255, 255, 0.09);
    --accent: #3987e5;
    --accent-strong: #86b6ef;
    --accent-soft: rgba(57, 135, 229, 0.16);
    --accent-track: #0d366b;
    --s1: #3987e5; --s2: #199e70; --s3: #c98500; --s4: #008300;
    --s5: #9085e9; --s6: #e66767; --s7: #d55181; --s8: #d95926;
    --good-text: #0ca30c;
    --warn-track: #4a3a10; --bad-track: #4a1a1a;
    --shadow: none;
    --shadow-pop: 0 24px 60px rgba(0, 0, 0, 0.5);
    --side-bg: #11161e;
    --side-border: rgba(255, 255, 255, 0.06);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 13.5px/1.55 system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.25; letter-spacing: -0.01em; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

/* ---------------- Shell ---------------- */
.shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 232px; flex-shrink: 0;
  background: var(--side-bg);
  padding: 20px 12px 14px;
  position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column; gap: 2px;
}
.sidebar .brand {
  display: flex; align-items: center; gap: 10px;
  padding: 0 8px 18px;
  color: var(--side-ink);
  font-size: 15px; font-weight: 700; letter-spacing: -0.01em;
}
.brand-mark {
  width: 30px; height: 30px; flex-shrink: 0;
  border-radius: 9px;
  background: linear-gradient(135deg, #3987e5, #1c5cab);
  display: flex; align-items: center; justify-content: center;
  color: #fff;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.25);
}
.brand-mark svg { display: block; }
.sidebar .brand small { display: block; font-size: 10.5px; font-weight: 600; letter-spacing: 0.09em; color: var(--side-ink-2); }

.nav-label {
  padding: 14px 10px 5px;
  font-size: 10px; font-weight: 700; letter-spacing: 0.12em; text-transform: uppercase;
  color: var(--side-label);
}
.sidebar a.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 7px 10px; border-radius: 8px;
  color: var(--side-ink-2); font-weight: 500; font-size: 13px;
  transition: background 0.12s ease, color 0.12s ease;
}
.sidebar a.nav-item:hover { background: var(--side-hover); color: var(--side-ink); text-decoration: none; }
.sidebar a.nav-item.active { background: var(--side-active); color: #fff; }
.sidebar a.nav-item svg { flex-shrink: 0; opacity: 0.8; }
.sidebar a.nav-item.active svg { opacity: 1; }
.sidebar .spacer { flex: 1; }

.whoami {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 8px 2px;
  border-top: 1px solid var(--side-border);
  color: var(--side-ink-2); font-size: 12px; line-height: 1.4;
}
.whoami .avatar {
  width: 30px; height: 30px; flex-shrink: 0; border-radius: 50%;
  background: var(--side-hover);
  border: 1px solid var(--side-border);
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 700; color: var(--side-ink);
  letter-spacing: 0.02em;
}
.whoami b { color: var(--side-ink); display: block; font-weight: 600; }
.whoami a { color: var(--side-ink-2); }
.whoami a:hover { color: var(--side-ink); }

.content { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.main { flex: 1; padding: 26px 32px 70px; min-width: 0; }
#view { animation: view-in 0.22s ease-out; }
@keyframes view-in { from { opacity: 0; transform: translateY(4px); } }

.page-head { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin-bottom: 20px; }
.page-head h1 { font-size: 21px; font-weight: 700; margin: 0; }
.page-head > .muted { font-size: 13px; }
.page-head .grow { flex: 1; }
.section-title { font-size: 12px; font-weight: 700; letter-spacing: 0.09em; text-transform: uppercase; color: var(--ink-2); margin: 22px 0 10px; }
.whoami .dept-line { display: block; max-width: 150px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---- Mobile chrome: top app bar + bottom tab bar (hidden on desktop) ---- */
.m-topbar, .m-tabbar { display: none; }
.m-topbar {
  position: sticky; top: 0; z-index: 30;
  align-items: center; gap: 10px;
  padding: 10px 14px;
  background: var(--side-bg); color: var(--side-ink);
}
.m-topbar .brand-mark { width: 26px; height: 26px; border-radius: 8px; }
.m-title { font-weight: 700; font-size: 15px; flex: 1; letter-spacing: -0.01em; }
.m-avatar { border: 1px solid var(--side-border); background: var(--side-hover); cursor: pointer; font: inherit; font-size: 11px; font-weight: 700; }
.m-menu {
  position: absolute; top: calc(100% + 6px); right: 10px;
  min-width: 210px;
  background: var(--surface); color: var(--ink);
  border: 1px solid var(--border); border-radius: 12px;
  box-shadow: var(--shadow-pop);
  padding: 6px;
  animation: modal-in 0.15s ease-out;
}
.m-menu-head { padding: 8px 10px; border-bottom: 1px solid var(--grid); margin-bottom: 4px; font-size: 12.5px; }
.m-menu-head b { display: block; }
.m-menu-head .muted { font-size: 11.5px; }
.m-menu a { display: block; padding: 9px 10px; border-radius: 8px; color: var(--ink); font-weight: 500; }
.m-menu a:hover { background: var(--accent-soft); text-decoration: none; }

.m-tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
  padding: 4px 6px calc(4px + env(safe-area-inset-bottom));
  overflow-x: auto;
  scrollbar-width: none;
}
.m-tabbar::-webkit-scrollbar { display: none; }
.tab-item {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  flex: 1 0 62px; min-width: 62px;
  padding: 6px 4px 5px;
  border-radius: 10px;
  color: var(--muted); font-size: 10px; font-weight: 600; letter-spacing: 0.01em;
}
.tab-item:hover { text-decoration: none; }
.tab-item.active { color: var(--accent); }
.tab-item svg { flex-shrink: 0; }

@media (max-width: 760px) {
  .sidebar { display: none; }
  .m-topbar { display: flex; }
  .m-tabbar { display: flex; }
  .main { padding: 18px 14px calc(84px + env(safe-area-inset-bottom)); }
  .page-head h1 { font-size: 19px; }
  .hero-num { font-size: 38px; }
  .grid.tiles { grid-template-columns: repeat(2, 1fr); }
  .btn { padding: 10px 16px; }
  .btn.small { padding: 7px 12px; font-size: 13px; }
}

/* ---------------- Cards & grids ---------------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 18px 20px;
  box-shadow: var(--shadow);
}
.card h3 { margin: 0 0 12px; font-size: 13px; font-weight: 650; color: var(--ink-2); }
.card .sub { color: var(--muted); font-size: 12.5px; }
.grid { display: grid; gap: 14px; }
.grid.cols-2 { grid-template-columns: repeat(auto-fit, minmax(330px, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.grid.tiles { grid-template-columns: repeat(auto-fit, minmax(155px, 1fr)); }

/* Stat tile: eyebrow label / large value / delta */
.tile { display: block; }
.tile .label {
  color: var(--muted); font-size: 10.5px; font-weight: 700;
  letter-spacing: 0.08em; text-transform: uppercase;
}
.tile .value { font-size: 27px; font-weight: 650; letter-spacing: -0.02em; margin-top: 4px; }
.tile .delta { font-size: 12px; color: var(--muted); margin-top: 2px; }
.tile .delta.up { color: var(--good-text); }
.tile .delta.down { color: var(--critical); }
a.tile { color: inherit; transition: border-color 0.12s ease, transform 0.12s ease; }
a.tile:hover { text-decoration: none; border-color: var(--accent); transform: translateY(-1px); }

.hero-num { font-size: 44px; font-weight: 650; letter-spacing: -0.03em; margin: 6px 0 10px; }

/* ---------------- Meters ---------------- */
.meter { height: 6px; border-radius: 999px; background: var(--accent-track); overflow: hidden; }
.meter > i {
  display: block; height: 100%; border-radius: 999px;
  background: var(--accent);
  transition: width 0.4s cubic-bezier(0.22, 1, 0.36, 1);
}
.meter.warn { background: var(--warn-track); } .meter.warn > i { background: var(--warning); }
.meter.bad { background: var(--bad-track); } .meter.bad > i { background: var(--critical); }

/* ---------------- Status chips (dot + label, never color alone) ---------------- */
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 11.5px; font-weight: 600; color: var(--ink-2);
  padding: 3px 10px; border: 1px solid var(--border); border-radius: 999px;
  background: color-mix(in srgb, var(--surface) 60%, transparent);
  white-space: nowrap;
}
.chip::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--muted); flex-shrink: 0; }
.chip.good::before { background: var(--good); }
.chip.warn::before { background: var(--warning); }
.chip.serious::before { background: var(--serious); }
.chip.bad::before { background: var(--critical); }
.chip.info::before { background: var(--accent); }

/* ---------------- Tables ---------------- */
table.data { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data th {
  text-align: left; color: var(--muted);
  font-weight: 700; font-size: 10.5px; letter-spacing: 0.07em; text-transform: uppercase;
  padding: 8px 10px; border-bottom: 1px solid var(--grid);
}
table.data td { padding: 9px 10px; border-bottom: 1px solid var(--grid); vertical-align: top; }
table.data tr:last-child td { border-bottom: 0; }
table.data tbody tr { transition: background 0.1s ease; }
table.data tbody tr:hover { background: color-mix(in srgb, var(--accent) 3%, transparent); }
table.data td.num, table.data th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.data tr.clickable { cursor: pointer; }
.table-scroll { overflow-x: auto; margin: 0 -6px; padding: 0 6px; }
.table-scroll table.data { min-width: 620px; }

/* ---------------- Buttons & forms ---------------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--accent); color: #fff;
  border: 0; border-radius: 9px;
  padding: 8px 15px; font: inherit; font-size: 13px; font-weight: 600;
  cursor: pointer;
  transition: background 0.12s ease, transform 0.08s ease, border-color 0.12s ease;
}
.btn:hover { background: var(--accent-strong); }
.btn:active { transform: translateY(1px); }
.btn.ghost { background: transparent; color: var(--ink-2); border: 1px solid var(--line); }
.btn.ghost:hover { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); }
.btn.danger { background: var(--critical); }
.btn.danger:hover { background: #a82f2f; }
.btn.small { padding: 4px 11px; font-size: 12px; border-radius: 7px; }
.btn:disabled { opacity: 0.5; cursor: default; }

input, select, textarea {
  font: inherit; color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line); border-radius: 9px;
  padding: 8px 11px; width: 100%;
  transition: border-color 0.12s ease, box-shadow 0.12s ease;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
label.field { display: block; margin-bottom: 13px; }
label.field > span {
  display: block; margin-bottom: 5px;
  font-size: 11px; font-weight: 700; letter-spacing: 0.05em; text-transform: uppercase;
  color: var(--muted);
}
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 560px) { .form-row { grid-template-columns: 1fr; } }

/* Checkbox groups (e.g. a user's departments) */
.check-group {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 6px;
  border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px;
}
.check-item {
  display: flex; align-items: center; gap: 8px;
  font-size: 13.5px; font-weight: 500; cursor: pointer;
  padding: 4px 2px; text-transform: none; letter-spacing: 0;
}
.check-item input[type=checkbox] { width: 16px; height: 16px; accent-color: var(--accent); margin: 0; flex-shrink: 0; }

/* ---------------- Modal ---------------- */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(9, 14, 22, 0.45);
  backdrop-filter: blur(3px);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 7vh 16px; overflow-y: auto;
  animation: fade-in 0.15s ease-out;
}
.modal {
  background: var(--surface);
  border: 1px solid var(--border); border-radius: 16px;
  width: 100%; max-width: 560px; padding: 22px 24px;
  box-shadow: var(--shadow-pop);
  animation: modal-in 0.2s cubic-bezier(0.22, 1, 0.36, 1);
}
.modal h2 { margin: 0 0 18px; font-size: 16px; font-weight: 700; }
.modal .actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }
/* On phones the modal becomes a bottom sheet. */
@media (max-width: 640px) {
  .modal-backdrop { padding: 0; align-items: flex-end; }
  .modal {
    max-width: none; max-height: 92dvh; overflow-y: auto;
    border-radius: 18px 18px 0 0; border-bottom: 0;
    padding: 20px 18px calc(18px + env(safe-area-inset-bottom));
    animation: sheet-in 0.22s cubic-bezier(0.22, 1, 0.36, 1);
  }
  .modal .actions { position: sticky; bottom: 0; background: var(--surface); padding-top: 10px; }
}
@keyframes sheet-in { from { opacity: 0.5; transform: translateY(40px); } }
@keyframes fade-in { from { opacity: 0; } }
@keyframes modal-in { from { opacity: 0; transform: translateY(10px) scale(0.99); } }

/* ---------------- Toast ---------------- */
#toast-root {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%);
  z-index: 90; display: flex; flex-direction: column; gap: 8px; align-items: center;
}
.toast {
  background: var(--ink); color: var(--bg);
  padding: 9px 18px; border-radius: 999px;
  font-size: 13px; font-weight: 600;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.28);
  animation: toast-in 0.2s cubic-bezier(0.22, 1, 0.36, 1);
}
.toast.error { background: var(--critical); color: #fff; }
@keyframes toast-in { from { opacity: 0; transform: translateY(10px); } }

/* ---------------- Login ---------------- */
.login-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  padding: 20px;
  background:
    radial-gradient(600px 420px at 12% 0%, var(--accent-soft), transparent 70%),
    radial-gradient(500px 380px at 100% 100%, var(--accent-soft), transparent 70%),
    var(--bg);
}
.login-card { width: 100%; max-width: 384px; padding: 28px; }
.login-card .brand-mark { width: 42px; height: 42px; border-radius: 12px; margin-bottom: 16px; }
.login-card h1 { font-size: 20px; font-weight: 700; margin: 0 0 2px; }
.login-card .sub { margin-bottom: 20px; }

/* ---------------- OKRs ---------------- */
.dept-section { margin-bottom: 30px; }
.dept-section > .dept-head { display: flex; align-items: center; gap: 12px; margin: 0 0 10px; }
.dept-section > .dept-head h2 {
  font-size: 11.5px; font-weight: 700; letter-spacing: 0.09em; text-transform: uppercase;
  color: var(--ink-2); margin: 0;
}
.objective { margin-bottom: 12px; }
.objective .obj-head { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.objective .obj-head h3 { font-size: 15px; font-weight: 650; color: var(--ink); margin: 0; }
.objective .obj-meta { color: var(--muted); font-size: 12px; }
.kr-row {
  display: grid; grid-template-columns: minmax(180px, 1fr) 130px max-content max-content;
  gap: 14px; align-items: center;
  padding: 9px 0; border-top: 1px solid var(--grid);
}
.kr-row .kr-title { font-size: 13px; }
.kr-row .kr-nums {
  font-size: 12.5px; color: var(--ink-2); text-align: right;
  font-variant-numeric: tabular-nums; white-space: nowrap;
}
/* On phones each key result stacks: title, then meter beside the numbers, then actions. */
@media (max-width: 680px) {
  .kr-row {
    grid-template-columns: 1fr max-content;
    grid-template-areas: "title title" "meter nums" "actions actions";
    gap: 8px 12px; padding: 12px 0;
  }
  .kr-title { grid-area: title; }
  .kr-meter { grid-area: meter; align-self: center; }
  .kr-nums { grid-area: nums; }
  .kr-actions { grid-area: actions; justify-content: flex-end; }
}

/* ---------------- Pipeline (sales) ---------------- */
.pipeline { display: grid; grid-template-columns: repeat(6, minmax(172px, 1fr)); gap: 10px; overflow-x: auto; align-items: start; padding-bottom: 6px; }
@media (max-width: 760px) {
  .pipeline { grid-template-columns: repeat(6, minmax(240px, 75vw)); scroll-snap-type: x proximity; }
  .stage-col { scroll-snap-align: start; }
}
.stage-col {
  background: color-mix(in srgb, var(--surface) 55%, var(--bg));
  border: 1px solid var(--border); border-radius: 12px;
  padding: 10px; min-height: 64px;
}
.stage-col h4 {
  margin: 0 2px 10px;
  font-size: 10.5px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--muted);
  display: flex; justify-content: space-between; align-items: center;
}
.stage-col h4 span {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 999px; padding: 0 7px;
  font-size: 10.5px; font-variant-numeric: tabular-nums;
}
.lead-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  padding: 9px 11px; margin-bottom: 8px; cursor: pointer;
  transition: border-color 0.12s ease, transform 0.1s ease, box-shadow 0.12s ease;
}
.lead-card:hover { border-color: var(--accent); transform: translateY(-1px); box-shadow: var(--shadow); }
.lead-card .nm { font-weight: 600; font-size: 12.5px; }
.lead-card .mt { color: var(--muted); font-size: 11.5px; margin-top: 1px; }

/* ---------------- Charts ---------------- */
.chart-wrap { overflow-x: auto; }
svg text { font-family: system-ui, -apple-system, "Segoe UI", sans-serif; }
.legend { display: flex; gap: 16px; flex-wrap: wrap; font-size: 12px; color: var(--ink-2); margin-top: 10px; }
.legend .key { display: inline-flex; align-items: center; gap: 6px; }
.legend .key i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }

/* ---------------- Milestones ---------------- */
.ms-row { display: flex; align-items: center; gap: 10px; padding: 6px 0; border-top: 1px solid var(--grid); font-size: 13px; }
.ms-row input[type=checkbox] { width: 15px; height: 15px; accent-color: var(--accent); flex-shrink: 0; }
.ms-row .due { color: var(--muted); font-size: 11.5px; margin-left: auto; white-space: nowrap; }
.ms-row.done .t { text-decoration: line-through; color: var(--muted); }

/* ---------------- Utilities ---------------- */
.muted { color: var(--muted); }
.right { text-align: right; }
.mt { margin-top: 14px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.empty { color: var(--muted); text-align: center; padding: 34px 10px; }

/* Last in the cascade so it beats the base input rule:
   16px inputs stop iOS Safari from zooming the page on focus. */
@media (max-width: 760px) {
  input, select, textarea { font-size: 16px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
