/* CaribWare AI OS — harbor-daylight UI.
   Brand palette from config/brand.yaml: teal #0E7490, amber #F59E0B,
   ink #0F172A, light #F8FAFC. Human copy in Inter; machine telemetry
   (cost, tokens, timestamps, slugs) in the mono utility face. */

:root {
  --bg: #F8FAFC;
  --card: #FFFFFF;
  --ink: #0F172A;
  --ink-2: #43546C;
  --muted: #7C8CA1;
  --line: #E3E9F0;
  --teal: #0E7490;
  --teal-deep: #0B5C73;
  --teal-wash: #E7F4F8;
  --amber: #F59E0B;
  --amber-ink: #92580A;
  --amber-wash: #FDF3E0;
  /* per-fix palette: fix N uses slot ((N-1) mod 4)+1; every hue ≥3:1 on
     white. Fix 1 keeps amber continuity with the revision identity. */
  --fix-1: #D97706;  --fix-1-ink: #92580A;  --fix-1-wash: #FDF3E0;
  --fix-2: #7C3AED;  --fix-2-ink: #5B21B6;  --fix-2-wash: #F1EAFD;
  --fix-3: #DB2777;  --fix-3-ink: #9D174D;  --fix-3-wash: #FCE9F1;
  --fix-4: #4F46E5;  --fix-4-ink: #3730A3;  --fix-4-wash: #EBEAFC;
  --good: #15803D;
  --good-wash: #E9F5EE;
  --bad: #B91C1C;
  --bad-wash: #FBEAEA;
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
  --sans: Inter, "Inter var", system-ui, -apple-system, "Segoe UI", sans-serif;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .05), 0 4px 16px rgba(15, 23, 42, .05);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.55;
}
a { color: var(--teal); text-decoration: none; }
a:hover { text-decoration: underline; }
:focus-visible { outline: 2px solid var(--teal); outline-offset: 2px; border-radius: 4px; }
.mono { font-family: var(--mono); font-size: .92em; }
.dim { color: var(--muted); }
[hidden] { display: none !important; }

/* ── chrome ─────────────────────────────────────────────────────── */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 28px; background: var(--card);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 10;
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--ink); }
.brand:hover { text-decoration: none; }
.brand-mark {
  width: 22px; height: 22px; border-radius: 50%;
  background: radial-gradient(circle at center, var(--bg) 0 5px, var(--teal) 6px);
}
.brand-name { font-size: 15px; letter-spacing: .01em; }
.brand-name strong { font-weight: 800; }
.topnav { display: flex; gap: 20px; }
.topnav a { color: var(--ink-2); font-weight: 550; font-size: 14px; }
.topnav a.active { color: var(--teal-deep); }

.view { max-width: 1160px; margin: 0 auto; padding: 36px 28px 80px; }

.eyebrow {
  font-family: var(--mono); font-size: 11px; font-weight: 600;
  text-transform: uppercase; letter-spacing: .14em;
  color: var(--teal-deep); margin: 0 0 10px;
}
.eyebrow a { color: inherit; }

.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 20px 22px;
}

/* ── dashboard ──────────────────────────────────────────────────── */
.dash-head h1 {
  font-size: clamp(28px, 4.5vw, 44px); line-height: 1.08;
  letter-spacing: -0.02em; font-weight: 800; margin: 0 0 12px;
}
.dash-head .lede { color: var(--ink-2); max-width: 560px; margin: 0 0 30px; }

.new-campaign { margin-bottom: 36px; }
.new-campaign label {
  display: block; font-weight: 600; font-size: 13px; margin: 14px 0 6px;
}
.new-campaign input, .new-campaign textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line);
  border-radius: 8px; font: inherit; color: var(--ink); background: var(--bg);
}
.new-campaign textarea { font-family: var(--mono); font-size: 13px; resize: vertical; }
.new-campaign input:focus, .new-campaign textarea:focus {
  outline: 2px solid var(--teal); outline-offset: 0; border-color: transparent;
}
.form-foot { display: flex; align-items: center; justify-content: space-between; margin-top: 16px; gap: 12px; }
.hint { font-family: var(--mono); font-size: 12px; color: var(--muted); }
.form-error { color: var(--bad); font-size: 13px; margin: 10px 0 0; min-height: 1em; }

.btn {
  font: inherit; font-weight: 650; border-radius: 8px; cursor: pointer;
  padding: 10px 18px; border: 1px solid var(--line);
  background: var(--card); color: var(--ink);
}
.btn.primary { background: var(--teal); border-color: var(--teal); color: #fff; }
.btn.primary:hover { background: var(--teal-deep); }
.btn.quiet:hover { background: var(--bg); }
.btn:disabled { opacity: .55; cursor: default; }

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 14px; }
.campaign-card { display: block; color: var(--ink); }
.campaign-card:hover { text-decoration: none; border-color: var(--teal); }
.campaign-card h3 { margin: 2px 0 10px; font-size: 16px; letter-spacing: -.01em; }
.campaign-card .row { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.empty { color: var(--muted); }

/* ── status chips ───────────────────────────────────────────────── */
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; font-weight: 650; padding: 3px 10px;
  border-radius: 999px; white-space: nowrap;
}
.chip::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.chip.running { background: var(--teal-wash); color: var(--teal-deep); }
.chip.paused  { background: var(--amber-wash); color: var(--amber-ink); }
.chip.done    { background: var(--good-wash); color: var(--good); }
.chip.failed  { background: var(--bad-wash); color: var(--bad); }
.chip.draft   { background: var(--bg); color: var(--ink-2); }

/* ── campaign run view ──────────────────────────────────────────── */
.run-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 18px; flex-wrap: wrap; margin-bottom: 20px; }
.run-head h1 { margin: 0; font-size: clamp(22px, 3vw, 32px); letter-spacing: -.02em; font-weight: 800; }
.run-meta { display: flex; align-items: center; gap: 14px; }
.ticker {
  display: inline-flex; align-items: baseline; gap: 8px;
  background: var(--card); border: 1px solid var(--line);
  border-radius: 8px; padding: 6px 12px;
}
.ticker-label { font-family: var(--mono); font-size: 10px; text-transform: uppercase; letter-spacing: .12em; color: var(--muted); }
#c-cost { font-weight: 700; }

/* ── the route (signature element) ──────────────────────────────── */
.route { padding: 40px 22px 14px; margin-bottom: 18px; overflow-x: auto; }
.route-wrap { position: relative; min-width: 760px; }
.loops {
  position: absolute; left: 0; top: -36px; width: 100%; height: 60px;
  overflow: visible; pointer-events: none; z-index: 3;
}
.loops path { fill: none; stroke: var(--amber); stroke-width: 2;
  stroke-dasharray: 5 4; }
.loops path.latest { animation: current-rev 0.9s linear infinite; }
.loops text { fill: var(--amber-ink); font-family: var(--mono);
  font-size: 9.5px; font-weight: 700; }
.route-line { display: flex; list-style: none; margin: 0; padding: 0; }
.station { flex: 1; position: relative; text-align: center; min-width: 76px; }
.station .stat-time {
  display: block; height: 15px; margin-bottom: 5px;
  font-size: 10.5px; color: var(--muted);
}
.station.active .stat-time { color: var(--teal-deep); font-weight: 700; }
.station .visits {
  position: absolute; top: 14px; left: calc(50% + 9px); z-index: 4;
  background: var(--amber); color: #fff; font-style: normal;
  font-family: var(--mono); font-size: 9px; font-weight: 800;
  border-radius: 999px; padding: 0 4px; line-height: 13px;
}
.station .dot {
  width: 26px; height: 26px; border-radius: 50%;
  margin: 0 auto; position: relative; z-index: 2;
  background: var(--card); border: 2.5px solid var(--line);
  display: grid; place-items: center;
  font-size: 13px; color: #fff; font-weight: 800;
  transition: background .3s, border-color .3s;
}
.station .name {
  display: block; margin-top: 9px; font-size: 11.5px; font-weight: 600;
  color: var(--muted); line-height: 1.25;
}
/* connector: the current between stations (dot sits below the timer) */
.station + .station::before {
  content: ""; position: absolute; z-index: 1;
  top: 32px; right: 50%; width: 100%; height: 2.5px;
  background: var(--line);
}
.station.done .dot { background: var(--teal); border-color: var(--teal); }
.station.done .dot::after { content: "✓"; font-size: 12px; }
.station.done .name { color: var(--ink-2); }
.station.done + .station::before,
.station.active + .station::before { background: var(--teal); }
/* the flowing current feeds the active station */
.station.active + .station::before,
.station.flow::before {
  background: repeating-linear-gradient(90deg,
    var(--teal) 0 7px, var(--teal-wash) 7px 14px);
  animation: current 0.9s linear infinite;
}
.station.active .dot {
  background: var(--teal); border-color: var(--teal);
  animation: pulse 1.6s ease-in-out infinite;
}
.station.active .dot::after { content: ""; width: 8px; height: 8px; border-radius: 50%; background: #fff; animation: breathe 1.6s ease-in-out infinite; }
.station.active .name { color: var(--teal-deep); font-weight: 700; }
.station.attention .dot { background: var(--amber); border-color: var(--amber); animation: pulse-amber 1.6s ease-in-out infinite; }
.station.attention .dot::after { content: "!"; }
.station.attention .name { color: var(--amber-ink); font-weight: 700; }
/* revision: current flows backwards, in amber */
.station.reflow::before {
  background: repeating-linear-gradient(90deg,
    var(--amber) 0 7px, var(--amber-wash) 7px 14px) !important;
  animation: current-rev 0.9s linear infinite !important;
}
@keyframes current { to { background-position: -14px 0; } }
@keyframes current-rev { to { background-position: 14px 0; } }
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(14, 116, 144, .35); }
  55% { box-shadow: 0 0 0 9px rgba(14, 116, 144, 0); }
}
@keyframes pulse-amber {
  0%, 100% { box-shadow: 0 0 0 0 rgba(245, 158, 11, .4); }
  55% { box-shadow: 0 0 0 9px rgba(245, 158, 11, 0); }
}
@keyframes breathe { 0%, 100% { transform: scale(.7); } 50% { transform: scale(1); } }

/* ── run timeline strip ─────────────────────────────────────────── */
.timeline-row {
  display: flex; align-items: center; gap: 12px;
  margin-top: 16px; padding-top: 12px; border-top: 1px solid var(--bg);
  min-width: 760px;
}
.timeline-label, .timeline-legend {
  font-family: var(--mono); font-size: 10px; text-transform: uppercase;
  letter-spacing: .12em; color: var(--muted); white-space: nowrap;
}
.timeline-legend { display: flex; align-items: center; gap: 5px; }
.timeline-legend .sw { width: 9px; height: 9px; border-radius: 2px; margin-left: 7px; }
.timeline-legend .sw.teal { background: var(--teal); }
.timeline-legend .sw.amber { background: var(--amber); }
.timeline-legend .sw.fixes { background: linear-gradient(90deg,
  var(--fix-1) 0 25%, var(--fix-2) 0 50%, var(--fix-3) 0 75%, var(--fix-4) 0); }
.timeline-legend .sw.gray { background: #B9C6D4; }
.timeline { flex: 1; display: flex; gap: 2px; height: 16px; }
.timeline .seg {
  background: var(--teal); border-radius: 3px; min-width: 4px;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-family: var(--mono); font-size: 9px; font-weight: 700;
  overflow: hidden; white-space: nowrap;
}
.timeline .seg.alt { background: var(--teal-deep); }
.timeline .seg.revision { background: var(--amber); }
.timeline .seg.human { background: #B9C6D4; }
.timeline .seg.open { animation: seg-breathe 1.6s ease-in-out infinite; }
@keyframes seg-breathe { 0%, 100% { opacity: 1; } 50% { opacity: .6; } }

/* ── approval banner ────────────────────────────────────────────── */
.gate-banner {
  display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap;
  background: var(--amber-wash); border: 1px solid #F4D9A6;
  color: var(--amber-ink); border-radius: var(--radius);
  padding: 12px 18px; margin-bottom: 18px;
}

/* ── run body: feed + tabs ──────────────────────────────────────── */
.run-body { display: grid; grid-template-columns: 320px 1fr; gap: 18px; align-items: start; }
.feed { max-height: 640px; overflow-y: auto; }
.feed-list { list-style: none; margin: 0; padding: 0; }
.feed-list li {
  display: grid; grid-template-columns: 52px 1fr; gap: 10px;
  padding: 8px 2px; border-bottom: 1px solid var(--bg);
  font-size: 13.5px; color: var(--ink-2);
}
.feed-list li .t { font-family: var(--mono); font-size: 11px; color: var(--muted); padding-top: 2px; }
.feed-list li.working { color: var(--teal-deep); font-weight: 600; }
.feed-list li.working .msg::after { content: "…"; animation: ellipsis 1.4s steps(4) infinite; }
.feed-list li .cost { font-family: var(--mono); font-size: 11px; color: var(--muted); }
@keyframes ellipsis { 0% { content: ""; } 50% { content: "…"; } }

.tabs { display: flex; gap: 4px; margin-bottom: 12px; }
.tabs button {
  font: inherit; font-weight: 600; font-size: 13.5px;
  border: none; background: none; color: var(--ink-2);
  padding: 8px 14px; border-radius: 8px; cursor: pointer;
}
.tabs button:hover { background: var(--card); }
.tabs button.active { background: var(--card); color: var(--teal-deep); box-shadow: var(--shadow); }
.tabs button .badge {
  background: var(--amber); color: #fff; border-radius: 999px;
  font-size: 10px; padding: 1px 6px; margin-left: 6px; vertical-align: 1px;
}
.tabs button .badge.good { background: var(--good); }
.tabpane { display: none; }
.tabpane.active { display: block; }

/* ── content item cards (review + preview) ──────────────────────── */
.items { display: grid; gap: 14px; }
.item-card { padding: 0; overflow: hidden; }
.item-head {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 18px; border-bottom: 1px solid var(--line);
  background: var(--bg);
}
.platform-tag {
  font-family: var(--mono); font-size: 11px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .08em;
  padding: 3px 9px; border-radius: 6px;
  background: var(--teal-wash); color: var(--teal-deep);
}
.platform-tag.video { background: var(--amber-wash); color: var(--amber-ink); }
.item-head .post-type { font-size: 12.5px; color: var(--muted); }
.item-head .sched { margin-left: auto; }
.item-body { padding: 16px 18px; }
.item-body h3 { margin: 0 0 8px; font-size: 15.5px; }
.item-body .text { white-space: pre-wrap; color: var(--ink-2); font-size: 14px; }
.hashtags { margin-top: 10px; display: flex; flex-wrap: wrap; gap: 6px; }
.hashtags span {
  font-family: var(--mono); font-size: 11.5px; color: var(--teal-deep);
  background: var(--teal-wash); border-radius: 5px; padding: 2px 7px;
}
.image-note {
  margin-top: 12px; padding: 10px 12px; border-radius: 8px;
  border: 1px dashed var(--line); background: var(--bg);
  font-size: 12.5px; color: var(--muted);
}
/* the rendered visual — the point of the review gate */
.rendered { margin: 12px 0 0; }
.rendered img {
  width: 100%; display: block; border-radius: 8px;
  border: 1px solid var(--line); background: var(--bg);
}
.rendered figcaption {
  margin-top: 6px; font-size: 12px; color: var(--muted); line-height: 1.45;
}
.image-note b { color: var(--ink-2); }
.qa-flag {
  margin-top: 12px; padding: 9px 12px; border-radius: 8px;
  font-size: 13px; font-weight: 550;
}
.qa-flag.warning { background: var(--amber-wash); color: var(--amber-ink); }
.qa-flag.blocker { background: var(--bad-wash); color: var(--bad); }

.item-foot {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 18px; border-top: 1px solid var(--line);
}
.item-foot label { font-size: 12.5px; font-weight: 600; color: var(--ink-2); }
.item-foot input[type="datetime-local"] {
  font-family: var(--mono); font-size: 13px; padding: 6px 8px;
  border: 1px solid var(--line); border-radius: 6px; color: var(--ink);
  background: var(--card);
}
.item-foot input.edited { border-color: var(--amber); background: var(--amber-wash); }

/* ── decision bar ───────────────────────────────────────────────── */
.decision {
  position: sticky; bottom: 14px; margin-top: 18px;
  display: flex; gap: 10px; align-items: flex-start; flex-wrap: wrap;
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: 0 6px 24px rgba(15,23,42,.12);
  padding: 14px 16px;
}
.decision textarea {
  flex: 1; min-width: 220px; font: inherit; font-size: 13.5px;
  border: 1px solid var(--line); border-radius: 8px; padding: 9px 11px;
  resize: vertical; min-height: 42px;
}
.decision .note { width: 100%; font-size: 12px; color: var(--muted); margin: 0; }

/* ── plan tab ───────────────────────────────────────────────────── */
.plan-doc {
  white-space: pre-wrap; font-size: 13.5px; line-height: 1.65;
  color: var(--ink-2); font-family: var(--sans);
}

/* ── spend (dataviz: single measure, one hue, table as base) ────── */
.spend-table table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.spend-table th {
  text-align: left; font-family: var(--mono); font-size: 10.5px;
  text-transform: uppercase; letter-spacing: .1em; color: var(--muted);
  font-weight: 600; padding: 6px 10px; border-bottom: 1px solid var(--line);
}
.spend-table td { padding: 8px 10px; border-bottom: 1px solid var(--bg); vertical-align: middle; }
.spend-table td.num { font-family: var(--mono); font-size: 12.5px; text-align: right; white-space: nowrap; }
.bar-cell { width: 34%; min-width: 120px; }
.bar { height: 14px; border-radius: 4px; background: var(--teal); min-width: 2px; }
.spend-note { color: var(--muted); font-size: 13px; }

/* ── published refs ─────────────────────────────────────────────── */
.refs { list-style: none; padding: 0; margin: 10px 0 0; }
.refs li { font-family: var(--mono); font-size: 12.5px; color: var(--ink-2); padding: 4px 0; }
.done-banner {
  background: var(--good-wash); border: 1px solid #CBE7D5; color: var(--good);
  border-radius: var(--radius); padding: 12px 18px; margin-bottom: 18px;
  font-weight: 600;
}
.failed-banner {
  background: var(--bad-wash); border: 1px solid #EFC9C9; color: var(--bad);
  border-radius: var(--radius); padding: 12px 18px; margin-bottom: 18px;
}

/* ── fix chip (completed tab: which fix last touched the item) ──── */
.fix-chip {
  font-family: var(--mono); font-size: 10.5px; font-weight: 700;
  padding: 2px 8px; border-radius: 999px; white-space: nowrap;
}
.fix-chip.neutral { background: var(--bg); color: var(--muted);
  border: 1px solid var(--line); }

/* ── campaign resources (draft uploads + read-only galleries) ───── */
.draft-body { display: grid; gap: 18px; }
.res-lede { color: var(--ink-2); font-size: 13.5px; margin: 0 0 16px; }
.res-grid {
  display: grid; gap: 14px; margin-bottom: 14px;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
}
.res-card { margin: 0; }
.res-card img {
  width: 100%; aspect-ratio: 1; object-fit: cover;
  border-radius: 8px; border: 1px solid var(--line); background: var(--bg);
}
.res-card figcaption { display: grid; gap: 4px; padding-top: 8px; }
.res-name { font-size: 11.5px; color: var(--ink-2); word-break: break-all; }
.res-note { font-size: 12.5px; color: var(--ink-2); }
.res-del { padding: 4px 10px; font-size: 12px; justify-self: start; }
.res-form { display: grid; gap: 10px; margin-top: 16px;
  padding-top: 16px; border-top: 1px solid var(--bg); }
.res-form input[type="file"] { font-size: 13px; color: var(--ink-2); }
.res-form textarea {
  font: inherit; font-size: 13.5px; padding: 9px 11px;
  border: 1px solid var(--line); border-radius: 8px; resize: vertical;
  background: var(--bg); color: var(--ink);
}
.res-form button { justify-self: start; }
.res-thumb {
  width: 44px; height: 44px; object-fit: cover; border-radius: 6px;
  vertical-align: middle; margin: 0 4px; border: 1px solid var(--line);
}
.launch-bar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 14px; flex-wrap: wrap; color: var(--ink-2);
}
.launch-bar .form-error { width: 100%; margin: 0; }

/* ── responsive & motion ────────────────────────────────────────── */
@media (max-width: 920px) {
  .run-body { grid-template-columns: 1fr; }
  .feed { max-height: 300px; order: 2; }
}
@media (max-width: 560px) {
  .view { padding: 24px 16px 60px; }
  .topbar { padding: 12px 16px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
