:root {
  --brand: #e8344e;
  --brand-soft: #fde8eb;
  --bg: #f4f6f9;
  --surface: #ffffff;
  --ink: #1d2330;
  --ink-2: #4b5563;
  --muted: #8a93a3;
  --line: #e6e9ef;
  --blue: #3b7dd8;
  --red: #e8344e;
  --orange: #f08a3c;
  --green: #1f9d55;
  --amber: #f2b632;
  --grey: #9aa3ad;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .06);
  --sidebar: 236px;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.45;
}
a { color: var(--blue); text-decoration: none; }
code, pre { font-family: ui-monospace, Consolas, monospace; font-size: 12.5px; }
pre { background: #f1f3f7; padding: 10px 12px; border-radius: 8px; overflow-x: auto; }
h1, h2, h3, h4 { margin: 0; }
h4 { margin: 18px 0 4px; font-size: 13.5px; }

.app { display: flex; min-height: 100vh; }

/* ---------- Sidebar ---------- */
.sidebar {
  width: var(--sidebar); flex: 0 0 var(--sidebar);
  background: #161b26; color: #cfd5df;
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
}
.sidebar .brand { display: flex; gap: 10px; align-items: center; padding: 20px 18px 18px; border-bottom: 1px solid #262d3b; }
.sidebar .brand img { width: 46px; height: auto; background: #fff; border-radius: 8px; padding: 4px; }
.sidebar .brand strong { display: block; color: #fff; font-size: 15px; }
.sidebar .brand span { font-size: 12px; color: #8d96a7; }
.nav { padding: 12px 10px; display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav a {
  color: #cfd5df; padding: 9px 12px; border-radius: 8px; display: flex; gap: 10px; align-items: center;
  font-weight: 500; font-size: 13.5px;
}
.nav a i { font-style: normal; width: 18px; text-align: center; opacity: .8; }
.nav a:hover { background: #222a38; color: #fff; }
.nav a.active { background: var(--brand); color: #fff; }
.sidebar-foot { padding: 14px 18px; font-size: 11.5px; color: #7c8597; border-top: 1px solid #262d3b; }
.sidebar-foot b { color: #cfd5df; font-weight: 500; }

/* ---------- Topbar ---------- */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 16px 24px; background: var(--surface); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20;
}
.title h1 { font-size: 20px; }
.title p { margin: 2px 0 0; color: var(--muted); font-size: 13px; }
.filters { margin-left: auto; display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }
.filters label { display: flex; flex-direction: column; font-size: 11px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; gap: 3px; }
select, input[type=date], input[type=search] {
  font: inherit; font-size: 13px; color: var(--ink);
  border: 1px solid var(--line); background: #fff; border-radius: 8px; padding: 7px 10px; min-width: 120px;
}
select:focus, input:focus { outline: 2px solid rgba(59,125,216,.35); border-color: var(--blue); }
.btn {
  font: inherit; font-size: 13px; font-weight: 600; cursor: pointer;
  border: 1px solid var(--brand); background: var(--brand); color: #fff; border-radius: 8px; padding: 7px 14px;
}
.btn:hover { filter: brightness(.95); }
.btn.ghost { background: #fff; color: var(--ink-2); border-color: var(--line); }
.menu-btn { display: none; font-size: 20px; background: none; border: 0; cursor: pointer; }

/* ---------- Views & layout ---------- */
.view { display: none; padding: 20px 24px 40px; flex-direction: column; gap: 16px; }
.view.active { display: flex; }
.view > * { min-width: 0; max-width: 100%; }
.grid { display: grid; gap: 16px; }
.g-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.span-2 { grid-column: span 2; }

.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px 18px; min-width: 0; }
.card-h { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.card-h h3 { font-size: 15px; }
.hint, .muted { color: var(--muted); font-size: 12.5px; }
.link { font-size: 12.5px; font-weight: 600; }

.chart { position: relative; width: 100%; }
.h-280 { height: 280px; } .h-320 { height: 320px; } .h-360 { height: 360px; }

/* ---------- KPI tiles ---------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.kpi { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 16px; border-top: 3px solid var(--line); }
.kpi .lbl { font-size: 12px; color: var(--muted); font-weight: 600; }
.kpi .val { font-size: 26px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi .val small { font-size: 13px; font-weight: 500; color: var(--muted); margin-left: 3px; }
.kpi .sub { font-size: 12px; color: var(--ink-2); margin-top: 2px; }
.kpi.brand { border-top-color: var(--brand); }
.kpi.blue { border-top-color: var(--blue); }
.kpi.green { border-top-color: var(--green); }
.kpi.amber { border-top-color: var(--amber); }
.kpi.grey { border-top-color: var(--grey); }
.up { color: var(--red); } .down { color: var(--green); }

/* ---------- Segmented control ---------- */
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { font: inherit; font-size: 12.5px; font-weight: 600; border: 0; background: #fff; color: var(--ink-2); padding: 6px 12px; cursor: pointer; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button.on { background: var(--ink); color: #fff; }

/* ---------- Flow diagram ---------- */
.flow { display: grid; grid-template-columns: repeat(9, minmax(0, 1fr)); gap: 0; overflow-x: auto; padding: 6px 2px 4px; }
.step {
  position: relative; background: #f7f8fb; border: 1px solid var(--line); border-radius: 10px;
  padding: 12px 10px 10px; margin-right: 18px; cursor: pointer; transition: .15s; min-width: 108px;
}
.step:not(:last-child)::after {
  content: ""; position: absolute; right: -15px; top: 50%; width: 12px; height: 12px;
  border-top: 2px solid #c3c9d4; border-right: 2px solid #c3c9d4; transform: translateY(-50%) rotate(45deg);
}
.step:hover { border-color: var(--blue); }
.step.on { background: var(--brand-soft); border-color: var(--brand); }
.step .n { width: 22px; height: 22px; border-radius: 50%; background: var(--ink); color: #fff; font-size: 11.5px; font-weight: 700; display: grid; place-items: center; }
.step.on .n { background: var(--brand); }
.step .t { font-weight: 600; font-size: 12.5px; margin-top: 8px; line-height: 1.25; min-height: 32px; }
.step .v { font-size: 20px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; }
.step .c { font-size: 11.5px; color: var(--muted); }
.flow-detail { margin-top: 14px; padding: 14px 16px; border-radius: 10px; background: #fafbfc; border: 1px dashed var(--line); }
.flow-detail h4 { margin: 0 0 6px; font-size: 14px; }
.flow-detail ul { margin: 6px 0 0; padding-left: 18px; color: var(--ink-2); }
.flow-detail .tags { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.tag { font-size: 11.5px; padding: 3px 8px; border-radius: 999px; background: #eef1f6; color: var(--ink-2); }

.lifecycle { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.lc { flex: 1; min-width: 84px; border-radius: 10px; padding: 14px; text-align: center; background: #f7f8fb; }
.lc b { display: block; font-size: 26px; font-variant-numeric: tabular-nums; }
.lc span { font-size: 12px; color: var(--ink-2); font-weight: 600; }
.lc-arrow { color: #b5bcc8; font-size: 20px; }

/* ---------- Mini funnel ---------- */
.mf { display: flex; flex-direction: column; gap: 6px; }
.mf-row { display: grid; grid-template-columns: 120px 1fr 48px; gap: 8px; align-items: center; font-size: 12.5px; }
.mf-bar { height: 20px; background: #eef1f6; border-radius: 4px; overflow: hidden; }
.mf-bar span { display: block; height: 100%; background: var(--blue); border-radius: 4px; }
.mf-row:last-child .mf-bar span { background: var(--green); }
.mf-row b { text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- Tables ---------- */
.tbl-wrap { overflow: auto; max-height: 460px; border: 1px solid var(--line); border-radius: 10px; }
.tbl-wrap.tall { max-height: 640px; }
.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl th, .tbl td { padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
.tbl th { background: #f7f8fb; font-size: 11.5px; text-transform: uppercase; letter-spacing: .03em; color: var(--ink-2); position: sticky; top: 0; z-index: 1; }
.tbl td.num, .tbl th.num { text-align: right; font-variant-numeric: tabular-nums; }
.tbl tbody tr:hover { background: #fafbfd; }
.tbl tbody tr.click { cursor: pointer; }
.tbl.compact th, .tbl.compact td { padding: 6px 10px; }
.tbl.sortable th { cursor: pointer; user-select: none; }
.tbl.sortable th.sorted::after { content: " ▾"; }
.tbl.sortable th.sorted.asc::after { content: " ▴"; }
.tbl td.wrap { white-space: normal; min-width: 220px; }
.matrix td.num.z { color: #c7ccd4; }
.matrix td.num.hi { font-weight: 700; }

.pill { display: inline-block; font-size: 11.5px; font-weight: 600; padding: 2px 9px; border-radius: 999px; }
.pill.Open { background: #e6f0fb; color: #22609f; }
.pill.Closed { background: #e4f5ea; color: #157a40; }
.pill.On.Hold, .pill.Hold { background: #fdf3dc; color: #946505; }
.pill.Unmarked { background: #eef0f3; color: #6b7280; }
.bar-in { display: inline-block; height: 6px; border-radius: 3px; background: var(--blue); vertical-align: middle; margin-right: 6px; }
.bar-in.over { background: var(--red); }
.swatch { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 6px; vertical-align: -1px; }

.toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 12px; flex-wrap: wrap; }
.toolbar input[type=search] { flex: 1; min-width: 220px; }
.toolbar .count { color: var(--muted); font-size: 12.5px; margin-left: auto; }

.legend-note { margin: 8px 0 0; font-size: 12.5px; color: var(--ink-2); display: flex; gap: 6px 14px; align-items: center; flex-wrap: wrap; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: -8px; }
.dash { display: inline-block; width: 20px; border-top: 2px dashed var(--orange); margin-right: -8px; }

/* ---------- Data page ---------- */
.drop { display: flex; align-items: center; justify-content: center; border: 2px dashed #cdd3dd; border-radius: 10px; padding: 26px; cursor: pointer; background: #fafbfc; color: var(--ink-2); margin-top: 10px; }
.drop.over { border-color: var(--brand); background: var(--brand-soft); }
.drop input { display: none; }
.status-line { font-size: 13px; min-height: 18px; }
.status-line.ok { color: var(--green); } .status-line.err { color: var(--red); }
.checks { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.checks li { display: flex; gap: 10px; align-items: flex-start; font-size: 13px; padding: 9px 10px; border-radius: 8px; background: #fafbfc; }
.checks li b { font-variant-numeric: tabular-nums; min-width: 34px; text-align: right; }
.checks li.warn b { color: #b45309; } .checks li.ok b { color: var(--green); }

/* ---------- Modal ---------- */
.modal { position: fixed; inset: 0; background: rgba(17, 22, 33, .45); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal[hidden] { display: none; }
.modal-box { background: #fff; border-radius: 14px; width: min(860px, 100%); max-height: 88vh; overflow: auto; padding: 22px 24px; position: relative; }
.modal-x { position: absolute; right: 14px; top: 10px; font-size: 26px; border: 0; background: none; cursor: pointer; color: var(--muted); }
.m-head h2 { font-size: 19px; padding-right: 30px; }
.m-meta { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin: 14px 0; }
.m-meta div { background: #f7f8fb; border-radius: 8px; padding: 8px 10px; }
.m-meta span { display: block; font-size: 11px; text-transform: uppercase; color: var(--muted); font-weight: 600; }
.m-meta b { font-size: 14px; }
.m-notes { font-size: 13px; color: var(--ink-2); background: #fffaf0; border-radius: 8px; padding: 8px 12px; margin-bottom: 12px; }
.stagebar { display: flex; height: 14px; border-radius: 7px; overflow: hidden; margin: 6px 0 14px; background: #eef1f6; }
.stagebar span { height: 100%; }

/* ---------- Responsive ---------- */
@media (max-width: 1200px) {
  .g-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .span-2 { grid-column: span 2; }
}
@media (max-width: 900px) {
  .sidebar { position: fixed; left: 0; top: 0; z-index: 40; transform: translateX(-100%); transition: transform .2s; }
  .sidebar.open { transform: none; box-shadow: 0 0 0 100vmax rgba(0,0,0,.35); }
  .menu-btn { display: block; }
  .g-2, .g-3 { grid-template-columns: minmax(0, 1fr); }
  .span-2 { grid-column: auto; }
  .topbar { padding: 12px 16px; }
  .view { padding: 16px; }
  .filters { margin-left: 0; width: 100%; }
  .filters label { flex: 1 1 140px; }
  .filters select, .filters input { min-width: 0; width: 100%; }
  .flow { grid-template-columns: repeat(9, 130px); }
}

/* =====================================================================
   Smooth animations (layout unchanged)
   ===================================================================== */
:root { --ease: cubic-bezier(.22, .8, .24, 1); }
html { scroll-behavior: smooth; }

@keyframes fadeUp { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
@keyframes pop    { from { opacity: 0; transform: scale(.92); } to { opacity: 1; transform: none; } }
@keyframes grow   { from { width: 0; } }
@keyframes fadeIn { from { opacity: 0; } }
@keyframes modalIn { from { opacity: 0; transform: translateY(16px) scale(.97); } }

/* page title + staggered cards when a page opens */
.title > * { animation: fadeUp .45s var(--ease) both; }
.title p { animation-delay: .06s; }
.view.active > *, .view.active .grid > *, .kpis > .kpi {
  animation: fadeUp .55s var(--ease) both;
  animation-delay: calc(var(--i, 0) * 70ms);
}

/* hover lift */
.card, .kpi { transition: transform .3s var(--ease), box-shadow .3s var(--ease); }
.card:hover { box-shadow: 0 8px 24px rgba(16, 24, 40, .09); }
.kpi:hover { transform: translateY(-3px); box-shadow: 0 8px 24px rgba(16, 24, 40, .10); }

/* sidebar */
.nav a { transition: background .25s var(--ease), color .25s, transform .25s var(--ease); }
.nav a:hover { transform: translateX(3px); }
.nav a.active { box-shadow: 0 6px 16px rgba(232, 52, 78, .35); }

/* buttons, inputs, toggles */
.btn { transition: transform .2s var(--ease), box-shadow .2s, filter .2s; }
.btn:hover { transform: translateY(-1px); box-shadow: 0 4px 12px rgba(232, 52, 78, .22); }
.btn.ghost:hover { box-shadow: 0 2px 8px rgba(16, 24, 40, .08); }
.btn:active { transform: none; }
select, input[type=date], input[type=search] { transition: border-color .2s, box-shadow .2s; }
.seg button { transition: background .25s var(--ease), color .25s; }

/* funnel & table bars grow in */
.mf-bar span { animation: grow 1s var(--ease) both; }
.mf-row:nth-child(2) .mf-bar span { animation-delay: .08s; } .mf-row:nth-child(3) .mf-bar span { animation-delay: .16s; }
.mf-row:nth-child(4) .mf-bar span { animation-delay: .24s; } .mf-row:nth-child(5) .mf-bar span { animation-delay: .32s; }
.mf-row:nth-child(6) .mf-bar span { animation-delay: .40s; } .mf-row:nth-child(7) .mf-bar span { animation-delay: .48s; }
.bar-in { animation: grow .9s var(--ease) both; }
.stagebar span { animation: grow .9s var(--ease) both; }

/* flow steps pop in one by one; detail panel fades */
.step { transition: transform .3s var(--ease), box-shadow .3s var(--ease), background .3s, border-color .3s;
  animation: pop .45s var(--ease) both; animation-delay: calc(var(--i, 0) * 70ms); }
.step:hover, .step.on { transform: translateY(-3px); box-shadow: 0 8px 20px rgba(16, 24, 40, .10); }
.flow-detail { animation: fadeUp .4s var(--ease) both; }
.lc { animation: pop .45s var(--ease) both; }
.lifecycle .lc:nth-of-type(2) { animation-delay: .08s; } .lifecycle .lc:nth-of-type(3) { animation-delay: .16s; } .lifecycle .lc:nth-of-type(4) { animation-delay: .24s; }

/* tables */
.tbl tbody tr { transition: background .2s; }
.checks li { animation: fadeUp .4s var(--ease) both; }

/* modal */
.modal { animation: fadeIn .25s ease both; backdrop-filter: blur(2px); }
.modal-box { animation: modalIn .35s var(--ease) both; }
.modal-x { transition: transform .2s, color .2s; }
.modal-x:hover { transform: rotate(90deg); color: var(--ink); }

/* drag & drop */
.drop { transition: border-color .25s, background .25s, transform .25s var(--ease); }
.drop:hover { border-color: var(--blue); }
.drop.over { transform: scale(1.01); }

/* mobile sidebar slide */
@media (max-width: 900px) { .sidebar { transition: transform .3s var(--ease); } }

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