:root {
  --forest: #1f4d3a; --forest-700: #183d2e; --forest-50: #eaf1ed;
  --ivory: #faf7f0; --ivory-2: #f3efe5; --paper: #ffffff;
  --teal: #3f7a7b; --teal-50: #e6f0f0;
  --ink: #262a29; --ink-2: #4b524f; --ink-3: #6e7571; --line: #e2ddd1; --line-2: #ece8de;
  --ok: #2f6b45; --ok-bg: #e4f0e8; --warn: #8a5a00; --warn-bg: #fbf0d9; --err: #9b2c2c; --err-bg: #f9e3e1; --info-bg: #e6eef5; --info: #2c5577;
  --radius: 10px; --shadow: 0 1px 2px rgba(20, 30, 25, .06), 0 2px 8px rgba(20, 30, 25, .04);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font: 15px/1.5 var(--font); color: var(--ink); background: var(--ivory); -webkit-font-smoothing: antialiased; }
a { color: var(--teal); }
h1, h2, h3, h4 { margin: 0; color: var(--ink); letter-spacing: -.01em; }
h1 { font-size: 22px; font-weight: 650; } h2 { font-size: 17px; font-weight: 650; } h3 { font-size: 15px; font-weight: 650; }
p { margin: 0 0 8px; }
.muted { color: var(--ink-3); } .small { font-size: 13px; } .tiny { font-size: 12px; }
.mono { font-family: var(--mono); font-size: 12.5px; }
:focus-visible { outline: 3px solid #8fbcbc; outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; left: -999px; top: 8px; background: var(--paper); padding: 8px 12px; z-index: 100; }
.skip:focus { left: 8px; }

/* ---------- layout */
.layout { display: grid; grid-template-columns: 248px 1fr; min-height: 100vh; }
.sidebar { background: var(--forest); color: #dfe9e3; padding: 18px 12px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { display: flex; gap: 10px; align-items: center; padding: 4px 10px 18px; color: #fff; }
.brand-mark { width: 30px; height: 30px; border-radius: 8px; background: #fff1; display: grid; place-items: center; font-weight: 700; color: #fff; border: 1px solid #ffffff2a; }
.brand b { display: block; font-size: 15px; } .brand span { font-size: 12px; color: #b8cec2; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; color: #dfe9e3; text-decoration: none; font-size: 14px; }
.nav a:hover { background: #ffffff12; }
.nav a[aria-current="page"] { background: #ffffff1f; color: #fff; font-weight: 600; }
.nav .num { width: 20px; font-size: 11px; color: #9fb9ab; text-align: right; }
.nav .badge { margin-left: auto; background: #f2c14e; color: #3a2a00; border-radius: 10px; padding: 0 7px; font-size: 11px; font-weight: 700; }
.main { min-width: 0; }
.topbar { display: flex; align-items: center; gap: 12px; padding: 14px 28px; border-bottom: 1px solid var(--line); background: var(--ivory); position: sticky; top: 0; z-index: 10; flex-wrap: wrap; }
.topbar .spacer { flex: 1; }
.content { padding: 24px 28px 60px; max-width: 1400px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head p { margin: 4px 0 0; color: var(--ink-3); }
.demo-banner { background: #fff4d6; color: #5c4300; border-bottom: 1px solid #ecd9a5; padding: 8px 28px; font-size: 13px; }
.demo-banner b { font-weight: 700; }

/* ---------- cards & grid */
.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); } .g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.g5 { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.span2 { grid-column: span 2; } .span3 { grid-column: span 3; }
.card { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); min-width: 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.card-head .sub { font-size: 12.5px; color: var(--ink-3); }
.section { margin-top: 22px; }
.kpi .label { font-size: 12.5px; color: var(--ink-3); font-weight: 550; display: flex; gap: 6px; align-items: center; }
.kpi .value { font-size: 28px; font-weight: 650; letter-spacing: -.02em; margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi .foot { font-size: 12px; color: var(--ink-3); margin-top: 2px; }
.kpi .bar { height: 5px; border-radius: 3px; background: var(--ivory-2); margin-top: 10px; overflow: hidden; }
.kpi .bar i { display: block; height: 100%; background: var(--teal); }
.kpi.accent { border-top: 3px solid var(--forest); }
.delta-up { color: var(--ok); } .delta-down { color: var(--err); }

/* ---------- controls */
button, .btn { font: inherit; font-size: 14px; border: 1px solid var(--line); background: var(--paper); color: var(--ink); padding: 7px 13px; border-radius: 8px; cursor: pointer; display: inline-flex; gap: 6px; align-items: center; text-decoration: none; line-height: 1.3; }
button:hover, .btn:hover { border-color: #c9c2b2; }
button.primary, .btn.primary { background: var(--forest); color: #fff; border-color: var(--forest); }
button.primary:hover { background: var(--forest-700); }
button.danger { color: var(--err); border-color: #e7c3c0; }
button.ghost { background: transparent; border-color: transparent; color: var(--teal); padding: 4px 8px; }
button.sm { font-size: 12.5px; padding: 4px 9px; }
button:disabled { opacity: .5; cursor: not-allowed; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
input, select, textarea { font: inherit; font-size: 14px; color: var(--ink); background: var(--paper); border: 1px solid #d8d2c3; border-radius: 8px; padding: 7px 10px; width: 100%; }
textarea { min-height: 90px; resize: vertical; }
input[type="checkbox"] { width: auto; }
label.field { display: block; font-size: 13px; font-weight: 550; color: var(--ink-2); }
label.field > span { display: block; margin-bottom: 4px; }
.hint { font-size: 12px; color: var(--ink-3); font-weight: 400; margin-top: 3px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 14px; }
.form-grid .full { grid-column: 1 / -1; }
.check { display: flex; gap: 8px; align-items: flex-start; font-size: 14px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: var(--paper); }
.seg button { border: 0; border-radius: 0; border-right: 1px solid var(--line); padding: 6px 11px; font-size: 13px; }
.seg button:last-child { border-right: 0; }
.seg button[aria-pressed="true"] { background: var(--forest-50); color: var(--forest); font-weight: 600; }

/* ---------- tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th { text-align: left; font-weight: 600; color: var(--ink-3); font-size: 12px; text-transform: uppercase; letter-spacing: .03em; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 9px 10px; border-bottom: 1px solid var(--line-2); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.empty { padding: 26px; text-align: center; color: var(--ink-3); font-size: 14px; }

/* ---------- pills & alerts */
.pill { display: inline-block; font-size: 11.5px; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: var(--ivory-2); color: var(--ink-2); white-space: nowrap; }
.pill.ok { background: var(--ok-bg); color: var(--ok); } .pill.warn { background: var(--warn-bg); color: var(--warn); } .pill.err { background: var(--err-bg); color: var(--err); }
.pill.info { background: var(--info-bg); color: var(--info); } .pill.teal { background: var(--teal-50); color: var(--teal); }
.pill.demo { background: #fff4d6; color: #6b4f00; }
.alert { border-radius: 8px; padding: 10px 12px; font-size: 13.5px; margin: 8px 0; border: 1px solid transparent; }
.alert.warn { background: var(--warn-bg); color: #5f3f00; border-color: #efd9a8; }
.alert.err { background: var(--err-bg); color: #6e1f1f; border-color: #eec3bf; }
.alert.info { background: var(--info-bg); color: #1e3d57; border-color: #c9d9e7; }
.alert.ok { background: var(--ok-bg); color: #1f4a30; border-color: #c4dfcc; }
.alert ul { margin: 4px 0 0 18px; padding: 0; }
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; gap: 10px; align-items: center; justify-content: space-between; padding: 8px 0; border-bottom: 1px solid var(--line-2); font-size: 14px; }
.list li:last-child { border-bottom: 0; }
.check-ok::before { content: "✓"; color: var(--ok); font-weight: 700; margin-right: 8px; }
.check-no::before { content: "○"; color: var(--warn); font-weight: 700; margin-right: 8px; }

/* ---------- charts */
.chart { width: 100%; height: auto; display: block; }
.chart text { font: 11px var(--font); fill: var(--ink-3); }
.chart .grid-line { stroke: var(--line-2); }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12.5px; color: var(--ink-2); margin-top: 6px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 6px; vertical-align: -1px; }
.funnel-row { display: grid; grid-template-columns: 170px 1fr 90px; gap: 12px; align-items: center; padding: 6px 0; font-size: 14px; }
.funnel-row .track { background: var(--ivory-2); border-radius: 6px; height: 26px; overflow: hidden; }
.funnel-row .fill { height: 100%; background: linear-gradient(90deg, var(--forest), var(--teal)); border-radius: 6px; }
.funnel-row .v { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
.hbar { display: grid; grid-template-columns: 150px 1fr 48px; gap: 10px; align-items: center; font-size: 13px; padding: 3px 0; }
.hbar .track { background: var(--ivory-2); border-radius: 4px; height: 14px; overflow: hidden; }
.hbar .fill { height: 100%; background: var(--teal); }

/* ---------- calendar */
.cal { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; background: var(--paper); }
.cal .dow { background: var(--ivory-2); padding: 6px 8px; font-size: 12px; font-weight: 600; color: var(--ink-3); border-bottom: 1px solid var(--line); }
.cal .day { min-height: 112px; border-right: 1px solid var(--line-2); border-bottom: 1px solid var(--line-2); padding: 6px; font-size: 12px; }
.cal .day:nth-child(7n) { border-right: 0; }
.cal .day.out { background: #fbfaf6; color: #b3b0a6; }
.cal .day.today { box-shadow: inset 0 0 0 2px var(--teal); }
.cal .day.drop { background: var(--teal-50); }
.cal .dn { font-weight: 600; margin-bottom: 4px; display: block; }
.chip { display: block; padding: 4px 6px; margin-bottom: 4px; border-radius: 6px; background: var(--forest-50); border-left: 3px solid var(--forest); cursor: grab; font-size: 12px; line-height: 1.25; color: var(--ink); text-align: left; width: 100%; }
.chip.st-draft { border-left-color: #a8a395; background: #f4f2ec; }
.chip.st-in_review, .chip.st-fact_check { border-left-color: #c58b00; background: #fcf3de; }
.chip.st-approved, .chip.st-scheduled { border-left-color: var(--teal); background: var(--teal-50); }
.chip.st-published { border-left-color: var(--ok); background: var(--ok-bg); }
.tray { display: flex; gap: 8px; flex-wrap: wrap; min-height: 48px; padding: 10px; border: 1px dashed #cfc8b7; border-radius: var(--radius); background: #fdfcf8; }
.tray .chip { width: auto; max-width: 260px; }

/* ---------- modal & toast */
dialog { border: 0; border-radius: 14px; padding: 0; width: min(860px, 94vw); max-height: 90vh; box-shadow: 0 20px 60px rgba(0, 0, 0, .25); color: var(--ink); }
dialog::backdrop { background: rgba(20, 30, 25, .45); }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--paper); z-index: 1; }
.modal-body { padding: 18px 20px; overflow-y: auto; max-height: calc(90vh - 64px); }
.toasts { position: fixed; right: 18px; bottom: 18px; display: grid; gap: 8px; z-index: 1000; }
.toast { background: var(--ink); color: #fff; padding: 10px 14px; border-radius: 8px; font-size: 14px; box-shadow: var(--shadow); max-width: 420px; }
.toast.err { background: var(--err); } .toast.ok { background: var(--forest); }

/* ---------- login */
.login { min-height: 100vh; display: grid; place-items: center; background: radial-gradient(circle at 20% 10%, #e7efe9, var(--ivory) 60%); padding: 20px; }
.login .card { width: min(420px, 100%); padding: 28px; }
.login h1 { margin-bottom: 4px; }
.login form { display: grid; gap: 12px; margin-top: 16px; }
.code { background: var(--ivory-2); border-radius: 8px; padding: 10px 12px; font-family: var(--mono); font-size: 12.5px; overflow-wrap: anywhere; white-space: pre-wrap; }
.swatch { display: inline-block; width: 14px; height: 12px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; border-left: 3px solid; }
.swatch.st-draft { border-color: #a8a395; background: #f4f2ec; } .swatch.st-in_review { border-color: #c58b00; background: #fcf3de; } .swatch.st-approved { border-color: var(--teal); background: var(--teal-50); } .swatch.st-published { border-color: var(--ok); background: var(--ok-bg); }
.loading { padding: 40px; text-align: center; color: var(--ink-3); }
.status-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; background: #b5b0a3; }
.status-dot.connected { background: var(--ok); } .status-dot.connection_failed { background: var(--err); } .status-dot.temporarily_unavailable, .status-dot.awaiting_authorization { background: #d39b1b; } .status-dot.manual_workflow_required { background: var(--teal); }
.menu-btn { display: none; }
.notif { position: relative; }
.notif-panel { position: absolute; right: 0; top: 40px; width: 360px; background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 10px 30px rgba(0,0,0,.12); padding: 8px; z-index: 20; max-height: 70vh; overflow-y: auto; }
.notif-panel .list li { font-size: 13px; }

@media (max-width: 1100px) { .g4, .g5 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .g3 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 820px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: 260px; transform: translateX(-100%); transition: transform .2s; z-index: 50; }
  .sidebar.open { transform: none; }
  .menu-btn { display: inline-flex; }
  .g2, .g3, .g4, .g5, .form-grid { grid-template-columns: 1fr; }
  .span2, .span3 { grid-column: auto; }
  .content, .topbar { padding-left: 16px; padding-right: 16px; }
  .funnel-row { grid-template-columns: 110px 1fr 70px; }
  .cal .day { min-height: 70px; }
}
@media print {
  .sidebar, .topbar, .no-print, .demo-banner button { display: none !important; }
  .layout { display: block; } body { background: #fff; } .card { box-shadow: none; break-inside: avoid; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
