:root {
  --bg: #f4f6fb;
  --surface: #fff;
  --border: #e2e8f0;
  --input-border: #cbd5e1;
  --text: #0f172a;
  --muted: #64748b;
  --brand: #1d4ed8;
  --brand-hover: #1e40af;
  --brand-soft: #e0e7ff;
  --on-brand: #fff;
  --link: #1d4ed8;
  --side: #0f172a;
  --side-title: #fff;
  --side-text: #cbd5e1;
  --side-hover: #1e293b;
  --guest-from: #0f172a;
  --guest-to: #1e3a8a;
  --ok: #15803d;
  --ok-soft: #dcfce7;
  --warn: #b45309;
  --warn-soft: #fef3c7;
  --bad: #b91c1c;
  --bad-soft: #fee2e2;
  --info: #0369a1;
  --info-soft: #e0f2fe;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .05), 0 1px 3px rgba(15, 23, 42, .07);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }
h2 { font-size: 16px; margin: 0 0 14px; }
h3 { font-size: 14px; margin: 18px 0 6px; }
code { background: #f1f5f9; padding: 1px 6px; border-radius: 5px; font-size: 13px; }
pre.code { background: #0f172a; color: #e2e8f0; padding: 14px; border-radius: 8px; font-size: 13px; overflow-x: auto; white-space: pre-wrap; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.nowrap { white-space: nowrap; }
.text-bad { color: var(--bad) !important; font-weight: 600; }
.mt { margin-top: 18px; }

/* ---- Shell ---- */
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: 236px; flex-shrink: 0; background: var(--side); color: var(--side-text);
  position: sticky; top: 0; height: 100vh; overflow-y: auto; padding: 18px 12px;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; color: var(--side-title); padding: 2px 8px 20px; }
.brand:hover { text-decoration: none; }
.brand-dark { color: var(--text); padding: 0 0 12px; }
.brand-mark { background: var(--brand); color: var(--on-brand); border-radius: 8px; padding: 3px 8px; font-size: 13px; letter-spacing: .06em; white-space: nowrap; }
.brand-logo { display: block; max-height: 36px; max-width: 150px; width: auto; height: auto; object-fit: contain; }
.logo-row { display: flex; gap: 14px; align-items: flex-start; flex-wrap: wrap; }
.logo-row .form { flex: 1; min-width: 200px; gap: 8px; }
.logo-preview { display: flex; align-items: center; justify-content: center; min-width: 120px; min-height: 64px; padding: 12px; border: 1px dashed var(--input-border); border-radius: 8px; background: #fff; }
.logo-preview-dark { background: var(--side); color: var(--side-text); }
.public-card .brand-logo, .auth-card .brand-logo { max-height: 56px; max-width: 200px; }
.nav a {
  display: flex; align-items: center; gap: 10px; color: var(--side-text);
  padding: 9px 10px; border-radius: 8px; margin-bottom: 2px; font-size: 14px;
}
.nav a:hover { background: var(--side-hover); color: #fff; text-decoration: none; }
.nav a.active { background: var(--brand); color: var(--on-brand); }
.nav svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }
.nav .count { margin-left: auto; background: #ef4444; color: #fff; border-radius: 999px; font-size: 12px; padding: 0 7px; font-weight: 600; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 12px; background: var(--surface);
  border-bottom: 1px solid var(--border); padding: 12px 24px; position: sticky; top: 0; z-index: 5;
}
.topbar h1 { font-size: 18px; margin: 0; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar-user { display: flex; align-items: center; gap: 10px; font-size: 14px; }
.topbar-user form { margin: 0; }
.nav-toggle { display: none; border: 1px solid var(--border); background: #fff; border-radius: 8px; font-size: 18px; padding: 2px 10px; cursor: pointer; }
.content { padding: 24px; width: 100%; max-width: 1320px; }

/* ---- Cards, grids, stats ---- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; margin-bottom: 20px; }
.card.flush { padding: 0; overflow: hidden; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.card-head h2 { margin: 0; }
.narrow { max-width: 640px; }
.grid { display: grid; gap: 20px; align-items: start; }
.grid > * { min-width: 0; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-main { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 16px; margin-bottom: 20px; }
.stat {
  display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; color: inherit;
}
a.stat:hover { border-color: var(--brand); text-decoration: none; }
.stat .label { color: var(--muted); font-size: 13px; font-weight: 600; }
.stat .value { font-size: 30px; font-weight: 700; line-height: 1.2; }
.list { list-style: none; margin: 0; padding: 0; }
.list li { padding: 10px 0; border-bottom: 1px solid var(--border); display: grid; gap: 2px; }
.list li:last-child { border-bottom: 0; }
.empty { text-align: center; color: var(--muted); padding: 28px 12px; margin: 0; }

.bars { display: grid; gap: 10px; }
.bar-row { display: grid; grid-template-columns: 140px 1fr 36px; gap: 10px; align-items: center; font-size: 14px; }
.bar-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar { height: 10px; background: #eef2f7; border-radius: 999px; overflow: hidden; }
.bar span { display: block; height: 100%; border-radius: 999px; background: var(--brand); }
.bar-value { text-align: right; font-weight: 600; }
.pipeline { display: grid; grid-template-columns: repeat(auto-fit, minmax(84px, 1fr)); gap: 6px; }
.pipeline-step { background: #f8fafc; border: 1px solid var(--border); border-radius: 8px; padding: 8px 4px; text-align: center; color: inherit; display: grid; }
.pipeline-step:hover { border-color: var(--brand); text-decoration: none; }
.pipeline-step .value { font-size: 20px; font-weight: 700; }

/* ---- Forms ---- */
input, select, textarea {
  font: inherit; color: inherit; width: 100%; background: #fff;
  border: 1px solid var(--input-border); border-radius: 8px; padding: 8px 10px;
}
input:focus, select:focus, textarea:focus { outline: 3px solid var(--brand-soft); border-color: var(--brand); }
input[type=checkbox], input[type=radio] { width: auto; accent-color: var(--brand); }
input[type=color] { padding: 2px; height: 40px; width: 64px; }
textarea { min-height: 90px; resize: vertical; }
fieldset { border: 0; padding: 0; margin: 0; min-width: 0; }
fieldset[disabled] input, fieldset[disabled] select, fieldset[disabled] textarea { background: #f8fafc; color: var(--text); }
.form { display: grid; gap: 14px; }
.form > h2 { margin: 6px 0 0; }
.form label, .form .label { display: grid; gap: 5px; font-weight: 600; font-size: 14px; }
.form .row { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; align-items: end; }
.hint { font-weight: 400; color: var(--muted); font-size: 13px; }
.form label.check, label.check { display: flex; align-items: center; gap: 8px; font-weight: 500; }
.checks { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 6px; }
.form label.chip-check {
  display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--border); border-radius: 999px;
  padding: 5px 12px; cursor: pointer; font-size: 14px; font-weight: 500;
}
.chip-check:has(input:checked) { border-color: var(--brand); background: var(--brand-soft); }
.field-error { color: var(--bad); font-size: 13px; margin: -8px 0 0; font-weight: 600; }
.hp { position: absolute; left: -10000px; width: 1px; height: 1px; overflow: hidden; }
.danger-zone { margin: 0 0 20px; }
.inline-form { display: inline; margin: 0; }

.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 16px; }
.toolbar p { margin: 0; max-width: 720px; }
.spacer { flex: 1; }
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.filters input, .filters select { width: auto; min-width: 150px; }
.filters input[type=search] { min-width: 230px; }
.filters label.inline { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); font-weight: 600; }
.filters-card { padding: 14px; }
.month-title { margin: 0 6px; min-width: 150px; text-align: center; }

/* ---- Buttons ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; white-space: nowrap;
  border: 1px solid var(--input-border); background: #fff; color: var(--text); border-radius: 8px;
  padding: 8px 14px; font: inherit; font-size: 14px; font-weight: 600; cursor: pointer;
}
.btn:hover { background: #f1f5f9; text-decoration: none; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: var(--on-brand); }
.btn-primary:hover { background: var(--brand-hover); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-danger { color: var(--bad); border-color: #fecaca; }
.btn-danger:hover { background: var(--bad-soft); }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-sm { padding: 4px 10px; font-size: 13px; }
.btn-block { width: 100%; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ---- Tables, badges ---- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--border); vertical-align: top; font-size: 14px; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; background: #f8fafc; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: #fafcff; }
tr.inactive td { opacity: .55; }
.badge { display: inline-block; border-radius: 999px; padding: 2px 9px; font-size: 12px; font-weight: 600; background: #f1f5f9; color: #334155; white-space: nowrap; vertical-align: middle; }
.badge-new, .badge-idea { background: var(--info-soft); color: var(--info); }
.badge-contacted, .badge-draft, .badge-review { background: var(--warn-soft); color: var(--warn); }
.badge-qualified, .badge-proposal, .badge-scheduled { background: var(--brand-soft); color: var(--link); }
.badge-won, .badge-published { background: var(--ok-soft); color: var(--ok); }
.badge-lost, .badge-archived { background: #f1f5f9; color: var(--muted); }
.badge-high { background: var(--bad-soft); color: var(--bad); }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; vertical-align: middle; flex-shrink: 0; }
.pill { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; border: 1px solid var(--border); border-radius: 999px; padding: 1px 8px; margin: 0 4px 4px 0; white-space: nowrap; background: #fff; }

.alert { padding: 12px 14px; border-radius: 8px; margin: 0 0 16px; border: 1px solid; }
.alert-success { background: var(--ok-soft); border-color: #bbf7d0; color: #14532d; }
.alert-error { background: var(--bad-soft); border-color: #fecaca; color: #7f1d1d; }
.alert-info { background: var(--info-soft); border-color: #bae6fd; color: #0c4a6e; }
.pagination { display: flex; gap: 14px; align-items: center; justify-content: center; margin: 4px 0 20px; font-size: 14px; }

dl.details { display: grid; grid-template-columns: 140px 1fr; gap: 8px 14px; margin: 0; font-size: 14px; }
dl.details dt { color: var(--muted); }
dl.details dd { margin: 0; overflow-wrap: anywhere; }
dl.details.stacked { grid-template-columns: 1fr; gap: 2px; }
dl.details.stacked dt { font-weight: 600; color: var(--text); }
dl.details.stacked dd { margin-bottom: 10px; color: var(--muted); }
.message { background: #f8fafc; border: 1px solid var(--border); border-radius: 8px; padding: 12px 14px; overflow-wrap: anywhere; }
.note { border-left: 3px solid var(--brand); padding: 2px 0 2px 12px; margin-bottom: 14px; overflow-wrap: anywhere; }
.note.system { border-color: var(--border); color: var(--muted); font-size: 13px; }
.note-meta { font-size: 12px; color: var(--muted); }

/* ---- Media ---- */
.upload-card summary { cursor: pointer; }
.upload-card[open] summary { margin-bottom: 14px; }
.media-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 14px; margin-bottom: 16px; }
.media-item {
  position: relative; display: flex; flex-direction: column; background: var(--surface); color: inherit;
  border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden;
}
a.media-item:hover { border-color: var(--brand); text-decoration: none; }
.media-thumb { position: relative; aspect-ratio: 4 / 3; background: #e2e8f0; display: flex; align-items: center; justify-content: center; overflow: hidden; }
.media-thumb img, .media-thumb video { width: 100%; height: 100%; object-fit: cover; display: block; }
.media-thumb .kind { position: absolute; top: 6px; left: 6px; background: rgba(15, 23, 42, .75); color: #fff; font-size: 11px; border-radius: 6px; padding: 1px 6px; }
.doc-icon { font-weight: 700; color: #475569; border: 2px solid #94a3b8; border-radius: 6px; padding: 10px 8px; }
.media-meta { padding: 8px 10px; font-size: 13px; display: grid; }
.media-meta strong { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 600; }
.media-picker .media-item { cursor: pointer; font-weight: 400; }
.media-picker input { position: absolute; top: 8px; right: 8px; width: 20px; height: 20px; z-index: 2; }
.media-picker .media-item:has(input:checked) { outline: 3px solid var(--brand); outline-offset: -1px; }
.preview { display: block; max-width: 100%; max-height: 70vh; margin: 0 auto; border-radius: 8px; background: #0f172a; }

/* ---- Calendar ---- */
.cal-wrap { overflow-x: auto; margin-bottom: 12px; }
.cal { display: grid; grid-template-columns: repeat(7, minmax(110px, 1fr)); border-left: 1px solid var(--border); border-top: 1px solid var(--border); background: #fff; border-radius: var(--radius); overflow: hidden; }
.cal-head { background: #f8fafc; font-size: 12px; text-transform: uppercase; color: var(--muted); padding: 8px; font-weight: 600; border-right: 1px solid var(--border); border-bottom: 1px solid var(--border); }
.cal-day { min-height: 116px; padding: 6px; border-right: 1px solid var(--border); border-bottom: 1px solid var(--border); font-size: 13px; min-width: 0; }
.cal-day.other { background: #f8fafc; color: #94a3b8; }
.cal-day.today { box-shadow: inset 0 0 0 2px var(--brand); }
.cal-num { display: flex; justify-content: space-between; font-weight: 700; font-size: 12px; margin-bottom: 4px; }
.cal-add { opacity: 0; font-weight: 700; padding: 0 4px; }
.cal-day:hover .cal-add { opacity: 1; }
.cal-post {
  display: block; border-left: 3px solid var(--brand); background: #f1f5ff; border-radius: 4px; padding: 2px 6px;
  margin-bottom: 4px; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.cal-post:hover { background: var(--brand-soft); text-decoration: none; }
.cal-post.status-idea, .cal-post.status-draft, .cal-post.status-review { opacity: .55; background: #f8fafc; }
.cal-post.status-published { background: var(--ok-soft); }

/* ---- Sign-in, public form, errors ---- */
.guest, .public { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px 16px; }
.guest { background: linear-gradient(135deg, var(--guest-from), var(--guest-to)); }
.auth-card, .public-card { background: #fff; border-radius: 14px; padding: 32px; width: 100%; max-width: 420px; box-shadow: 0 20px 50px rgba(15, 23, 42, .25); }
.public-card { max-width: 560px; box-shadow: var(--shadow); border: 1px solid var(--border); }
.auth-card h1, .public-card h1 { font-size: 22px; margin: 0 0 14px; }
.error-page { text-align: center; padding: 20px 8px; }
.error-code { font-size: 56px; font-weight: 800; color: var(--link); margin: 0; line-height: 1; }
.error-detail { text-align: left; white-space: pre-wrap; background: #0f172a; color: #e2e8f0; padding: 12px; border-radius: 8px; font-size: 12px; }

/* ---- Reports & charts (single series colour: validated palette slot 1) ---- */
.chart, .spark, .meter, .bars {
  --series-1: #2a78d6;
  --chart-grid: #e1e0d9;
  --chart-base: #c3c2b7;
  --chart-muted: #6b6a65;
}
.section-title { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 8px 0 12px; }
.report-range { margin: 10px 0 0; }
.card-head.padded { padding: 16px 20px 0; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
th.num { text-align: right; }
tr.zero td { color: var(--muted); }
.report-table td { vertical-align: middle; }
.delta { font-size: 13px; color: var(--muted); }
.delta-up { color: #006300; }
.delta-down { color: var(--bad); }

.chart { margin: 0; }
.chart-plot { position: relative; height: 220px; margin-left: 34px; }
.chart-gridline { position: absolute; left: 0; right: 0; border-top: 1px solid var(--chart-grid); }
.chart-gridline.base { border-top-color: var(--chart-base); }
.chart-gridline span { position: absolute; right: calc(100% + 8px); top: -9px; font-size: 12px; color: var(--chart-muted); font-variant-numeric: tabular-nums; }
.chart-cols { position: absolute; inset: 0; display: flex; align-items: flex-end; }
.chart-col { flex: 1 1 0; min-width: 0; height: 100%; display: flex; align-items: flex-end; justify-content: center; padding: 0 1px; outline: none; cursor: default; }
.chart-col:hover, .chart-col:focus-visible { background: rgba(42, 120, 214, .07); }
.chart-col:focus-visible { box-shadow: inset 0 0 0 2px var(--series-1); }
.chart-bar { position: relative; display: block; width: 100%; max-width: 24px; background: var(--series-1); border-radius: 4px 4px 0 0; }
.chart-value { position: absolute; bottom: calc(100% + 4px); left: 50%; transform: translateX(-50%); font-size: 12px; font-weight: 600; color: var(--text); white-space: nowrap; }
.chart-x { display: flex; margin: 6px 0 0 34px; }
.chart-x span { flex: 1 1 0; min-width: 0; font-size: 12px; color: var(--chart-muted); white-space: nowrap; overflow: visible; text-align: left; }
.chart-table { margin-top: 12px; font-size: 14px; }
.chart-table summary { cursor: pointer; color: var(--link); font-size: 13px; }
.chart-table table { margin-top: 8px; max-width: 420px; }
.chart-tip {
  position: fixed; z-index: 50; pointer-events: none; background: #0f172a; color: #fff; font-size: 13px;
  padding: 6px 10px; border-radius: 6px; box-shadow: 0 6px 18px rgba(15, 23, 42, .25); white-space: nowrap; transform: translate(-50%, calc(-100% - 10px));
}
.spark { display: block; width: 110px; height: 26px; }
.spark polyline { fill: none; stroke: var(--series-1); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.spark-base { stroke: var(--chart-grid); stroke-width: 1; }
.meter { display: inline-block; vertical-align: middle; width: 90px; height: 8px; background: #eef2f7; border-radius: 999px; overflow: hidden; }
.meter span { display: block; height: 100%; background: var(--series-1); border-radius: 999px; }
a.bar-row { color: inherit; border-radius: 6px; }
a.bar-row:hover { background: #f8fafc; text-decoration: none; }
.bars .bar span { background: var(--series-1); }

.mini-stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin-bottom: 16px; }
.mini-stats > div { display: grid; }
.mini-stats .label { font-size: 13px; color: var(--muted); font-weight: 600; }
.mini-stats .value { font-size: 22px; font-weight: 700; }

.prose { font-size: 15px; }
.prose h2 { font-size: 16px; margin: 20px 0 6px; }
.prose ul, .prose ol { padding-left: 20px; }
.prose li { margin-bottom: 6px; }

/* ---- Meta ---- */
.guide { padding-left: 20px; margin: 14px 0; display: grid; gap: 10px; font-size: 14px; }
.guide ul { margin: 6px 0 0; padding-left: 18px; }
div.code { background: #f1f5f9; border-radius: 6px; padding: 8px 10px; margin: 6px 0; word-break: break-word; font-family: ui-monospace, Consolas, monospace; }
.actions-cell { white-space: nowrap; text-align: right; }
.actions-cell .inline-form { margin-left: 4px; }
details.card > summary { cursor: pointer; }

/* ---- Small screens ---- */
@media (max-width: 960px) {
  .grid-2, .grid-main { grid-template-columns: minmax(0, 1fr); }
  .sidebar { position: fixed; left: -250px; z-index: 30; transition: left .2s ease; }
  body.nav-open .sidebar { left: 0; }
  body.nav-open::after { content: ""; position: fixed; inset: 0; background: rgba(15, 23, 42, .45); z-index: 20; }
  .nav-toggle { display: inline-flex; }
}
@media (max-width: 640px) {
  .topbar { padding: 10px 16px; }
  .topbar-user .name, .topbar-user .badge { display: none; }
  .content { padding: 16px; }
  .card { padding: 16px; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .stat .value { font-size: 24px; }
  .filters, .filters input, .filters select, .filters input[type=search] { width: 100%; min-width: 0; }
  dl.details { grid-template-columns: 1fr; gap: 2px; }
  dl.details dd { margin-bottom: 8px; }
  .bar-row { grid-template-columns: 96px 1fr 30px; }
  .pipeline { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .media-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .auth-card, .public-card { padding: 24px 20px; }
  .chart-x .x-alt { visibility: hidden; }
  .chart-plot { height: 180px; }
}
