:root {
  --deep: #0B3D2A;
  --deep-2: #11492F;
  --deep-3: #16503A;
  --brand: #15803D;
  --brand-hover: #116B33;
  --accent: #22C55E;
  --mint: #E8F7EE;
  --ground: #F3F7F4;
  --card: #FFFFFF;
  --line: #DCE8E0;
  --line-soft: #EEF3EF;
  --text: #0B3D2A;
  --muted: #4A5F55;
  --on-deep: #CFE9D9;
  --error: #9B1C1C;
  --error-bg: #FDE8E8;
  --success-bg: #DCF3E4;
  --radius-lg: 18px;
  --radius: 12px;
  --radius-sm: 8px;
  --display: 'Sora', 'Segoe UI', system-ui, sans-serif;
  --body: 'Manrope', 'Segoe UI', system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: var(--body);
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  background: var(--ground);
}
a { color: var(--brand); font-weight: 700; text-decoration: none; }
a:hover { color: var(--deep); text-decoration: underline; }
h1, h2 { font-family: var(--display); margin: 0; line-height: 1.2; }
h1 { font-size: 28px; }
p { margin: 0; }
img { max-width: 100%; display: block; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.icon { width: 18px; height: 18px; flex-shrink: 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.strong { font-weight: 700; }
.nowrap { white-space: nowrap; }
.error-text { color: var(--error); }

/* Layout */
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: 248px; flex-shrink: 0; background: var(--deep); color: #fff;
  display: flex; flex-direction: column; gap: 32px; padding: 28px 18px;
  position: sticky; top: 0; height: 100vh;
}
.main { flex: 1; min-width: 0; padding: 36px 44px 60px; display: flex; flex-direction: column; gap: 24px; }

.brand { display: flex; align-items: center; gap: 12px; padding: 0 8px; }
.brand > span:last-child { display: flex; flex-direction: column; }
.brand-mark {
  width: 40px; height: 40px; border-radius: 11px; background: #16A34A; color: #fff;
  display: inline-flex; align-items: center; justify-content: center;
}
.brand-mark .icon { width: 22px; height: 22px; }
.brand-name { font-family: var(--display); font-weight: 700; font-size: 18px; letter-spacing: .5px; }
.brand-sub { font-size: 12px; color: #A7D7B9; }
.brand-dark .brand-name { color: var(--deep); }
.brand-dark .brand-sub { color: var(--muted); }

.nav { display: flex; flex-direction: column; gap: 4px; }
.nav-link {
  display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-radius: 10px;
  color: var(--on-deep); font-weight: 600; text-decoration: none;
}
.nav-link:hover { background: var(--deep-2); color: #fff; text-decoration: none; }
.nav-link.is-active { background: var(--deep-3); color: #fff; font-weight: 700; }
.nav-label { flex: 1; }
.nav-badge { background: var(--accent); color: var(--deep); font-size: 12px; font-weight: 800; border-radius: 999px; padding: 2px 9px; }

.agent-card { margin-top: auto; background: var(--deep-2); border-radius: 14px; padding: 16px; display: flex; flex-direction: column; gap: 8px; font-size: 13px; color: var(--on-deep); }
.agent-row { display: flex; align-items: center; gap: 8px; color: #fff; font-weight: 700; font-size: 14px; }
.dot { width: 9px; height: 9px; border-radius: 999px; background: var(--accent); flex-shrink: 0; }
.dot-warn { background: #F59E0B; }
.logout { display: inline-flex; align-items: center; gap: 6px; color: #A7D7B9; font-weight: 600; margin-top: 4px; }
.logout:hover { color: #fff; }
.logout .icon { width: 15px; height: 15px; }

/* Page head */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; flex-wrap: wrap; }
.page-head p { margin-top: 6px; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 46px; padding: 0 20px; border-radius: var(--radius); border: 1.5px solid transparent;
  font: 700 15px var(--body); cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-hover); color: #fff; }
.btn-outline { background: #fff; color: var(--deep); border-color: var(--deep); }
.btn-outline:hover { background: var(--mint); color: var(--deep); }
.btn-ghost { background: transparent; color: var(--muted); }
.btn-ghost:hover { background: var(--line-soft); color: var(--deep); }
.btn-block { width: 100%; }
.link-btn { background: none; border: 0; padding: 6px 4px; font: 700 14px var(--body); color: var(--brand); cursor: pointer; }
.link-btn:hover { color: var(--deep); text-decoration: underline; }
.link-danger { color: var(--error); }

/* Forms */
.stack { display: flex; flex-direction: column; gap: 16px; }
.field { display: flex; flex-direction: column; gap: 7px; font-weight: 700; font-size: 13px; }
.field-inline { flex-direction: row; align-items: center; gap: 14px; flex-wrap: wrap; }
.field input, .field textarea, .field select {
  font: 500 15px var(--body); color: var(--text); background: #FBFDFB;
  border: 1px solid #C9DDD0; border-radius: var(--radius); padding: 11px 13px; min-height: 46px;
}
.field textarea { resize: vertical; line-height: 1.55; }
.field input:focus, .field textarea:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(34, 197, 94, .25); }
.grow { flex: 1; min-width: 220px; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; }

/* Flash */
.flash { padding: 12px 16px; border-radius: var(--radius); font-weight: 600; }
.flash-success { background: var(--success-bg); color: var(--deep); }
.flash-error { background: var(--error-bg); color: var(--error); }

/* Panels */
.panel { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius-lg); padding: 24px; }
.panel-title { font-size: 17px; margin-bottom: 14px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 8px; }
.panel-head .panel-title { margin: 0; }

/* Stats */
.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 18px 20px; display: flex; flex-direction: column; gap: 4px; }
.stat-label { font-size: 13px; font-weight: 600; color: var(--muted); }
.stat-value { font-family: var(--display); font-size: 28px; font-weight: 700; }

/* Review */
.review-layout { display: grid; grid-template-columns: minmax(0, 1fr) 330px; gap: 24px; align-items: start; }
.review { display: grid; grid-template-columns: minmax(260px, 420px) minmax(0, 1fr); gap: 28px; }
.preview { display: block; border-radius: 14px; overflow: hidden; background: var(--mint); box-shadow: 0 12px 30px rgba(11, 61, 42, .14); aspect-ratio: 4 / 5; }
.preview img { width: 100%; height: 100%; object-fit: cover; }
.preview-empty { display: flex; align-items: center; justify-content: center; color: var(--muted); }
.versions { margin-top: 14px; display: flex; flex-direction: column; gap: 8px; }
.version-list { display: flex; gap: 8px; flex-wrap: wrap; }
.version {
  width: 56px; padding: 0; border: 2px solid var(--line); border-radius: var(--radius-sm); background: var(--mint);
  cursor: pointer; overflow: hidden; display: flex; flex-direction: column;
}
.version img { aspect-ratio: 4 / 5; object-fit: cover; width: 100%; }
.version span { font: 700 11px var(--body); color: var(--muted); padding: 2px 0; }
.version.is-current { border-color: var(--brand); }
.version.is-current span { color: var(--brand); }
.details-col { display: flex; flex-direction: column; gap: 18px; min-width: 0; }
.topic { font-size: 24px; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip { background: var(--mint); font-size: 12px; font-weight: 700; padding: 5px 11px; border-radius: 999px; }
.changes { padding-top: 18px; border-top: 1px solid var(--line-soft); }

.empty { padding: 48px 20px; text-align: center; display: flex; flex-direction: column; align-items: center; gap: 12px; }
.empty h2 { font-size: 21px; }
.empty p { max-width: 46ch; color: var(--muted); }

.side-col { display: flex; flex-direction: column; gap: 20px; }
.post-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.post-row { display: flex; align-items: center; gap: 12px; padding: 8px; border-radius: var(--radius); color: var(--text); font-weight: 400; }
a.post-row:hover { background: var(--ground); text-decoration: none; color: var(--text); }
.post-row.is-selected { background: var(--mint); }
.thumb { width: 40px; height: 50px; border-radius: 7px; background: var(--mint); overflow: hidden; flex-shrink: 0; }
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.post-row-text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.post-row-title { font-weight: 700; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Pills: colors differ in lightness, not just hue */
.pill { display: inline-block; font-size: 11px; font-weight: 800; padding: 4px 10px; border-radius: 999px; white-space: nowrap; }
.pill-pending { background: #EEF0EE; color: #3F4A44; }
.pill-generating, .pill-revising { background: #E6EEF9; color: #1E3A8A; }
.pill-review { background: #FEF3C7; color: #7A4B00; }
.pill-approved { background: var(--success-bg); color: var(--deep); }
.pill-posting { background: #E6EEF9; color: #1E3A8A; }
.pill-posted { background: var(--deep); color: #fff; }
.pill-failed { background: var(--error-bg); color: var(--error); }

/* Brief */
.brief { background: var(--ground); border-radius: var(--radius); padding: 10px 14px; }
.brief summary { cursor: pointer; font-weight: 700; font-size: 14px; color: var(--brand); }
.brief p { margin-top: 10px; white-space: pre-line; font-size: 14px; }
.brief-snippet { display: inline-block; max-width: 60ch; }

/* Topics */
.add-row { display: flex; gap: 14px; align-items: flex-end; flex-wrap: wrap; }
.bulk { margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--line-soft); }
.bulk summary { cursor: pointer; font-weight: 700; color: var(--brand); padding: 4px 0; }
.bulk[open] summary { margin-bottom: 14px; }

.week { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 10px; }
.day { background: var(--ground); border-radius: var(--radius); padding: 12px; display: flex; flex-direction: column; gap: 8px; min-height: 110px; }
.day-empty { background: #fff; border: 1px dashed #B8C4BD; }
.day-name { font-size: 12px; font-weight: 800; color: var(--muted); }
.day-item { display: flex; flex-direction: column; border-radius: var(--radius-sm); padding: 7px 8px; font-size: 12px; font-weight: 700; color: var(--deep); background: #EEF0EE; line-height: 1.35; }
.day-item:hover { text-decoration: none; color: var(--deep); filter: brightness(.97); }
.day-item .small { font-size: 11px; opacity: .8; }
.day-review { background: #FEF3C7; color: #7A4B00; }
.day-approved { background: var(--success-bg); }
.day-posted { background: var(--deep); color: #fff; }
.day-posted:hover { color: #fff; }
.day-generating, .day-revising, .day-posting { background: #E6EEF9; color: #1E3A8A; }
.day-failed { background: var(--error-bg); color: var(--error); }

.tabs { display: flex; gap: 6px; flex-wrap: wrap; }
.tab { padding: 8px 14px; border-radius: 999px; background: var(--ground); border: 1px solid var(--line); color: var(--deep); font-size: 13px; }
.tab:hover { text-decoration: none; background: var(--mint); color: var(--deep); }
.tab.is-active { background: var(--deep); border-color: var(--deep); color: #fff; }

.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 700; padding: 10px 12px; border-bottom: 1px solid var(--line); }
.table td { padding: 12px; border-bottom: 1px solid var(--line-soft); vertical-align: top; }
.table tr:last-child td { border-bottom: 0; }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; align-items: center; flex-wrap: wrap; }
.row-actions form { margin: 0; }

/* Settings */
.settings-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; }
.span-2 { grid-column: span 2; }
.conn-row { display: flex; gap: 12px; align-items: flex-start; }
.conn-row .dot { margin-top: 7px; }
.how { margin: 0 0 14px; padding-left: 20px; display: flex; flex-direction: column; gap: 8px; }

/* Login */
.login-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; background: var(--mint); }
.login-card { width: 100%; max-width: 400px; background: #fff; border-radius: 20px; padding: 32px; box-shadow: 0 20px 50px rgba(11, 61, 42, .12); display: flex; flex-direction: column; gap: 20px; }
.login-card .brand { padding: 0; }
.login-card h1 { font-size: 22px; }

/* Responsive */
@media (max-width: 1200px) {
  .review-layout { grid-template-columns: minmax(0, 1fr); }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 900px) {
  .app { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; flex-direction: row; flex-wrap: wrap; align-items: center; gap: 12px; padding: 14px 16px; }
  .nav { flex-direction: row; flex-wrap: wrap; flex: 1; }
  .nav-link { padding: 10px 12px; }
  .agent-card { display: none; }
  .main { padding: 24px 16px 48px; }
  .review { grid-template-columns: minmax(0, 1fr); }
  .preview-col { max-width: 420px; }
  .week { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .settings-grid { grid-template-columns: minmax(0, 1fr); }
  .span-2 { grid-column: auto; }
}
@media (max-width: 520px) {
  h1 { font-size: 24px; }
  .nav-label { display: none; }
  .nav-link.is-active .nav-label { display: inline; }
  .stats { gap: 10px; }
  .stat { padding: 14px; }
  .stat-value { font-size: 24px; }
  .actions .btn { flex: 1; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}