:root {
  --bg:#fff; --ink:#0f0f0f; --muted:#606060; --line:#e5e5e5; --nav:#f2f2f2; --stage:#fff;
  --accent:#065fd4; --chip:#0f0f0f; --chip-bg:#f2f2f2; --ok:#0d7a4f; --warn:#b06000;
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  background: var(--bg); color: var(--ink);
  font-family: Arial, Helvetica, "Segoe UI", sans-serif; font-size: 14px; line-height: 1.4;
}
a { color: inherit; }
button { font: inherit; }
.app-shell {
  display: grid; grid-template-columns: 240px minmax(0, 1fr); min-height: 100vh;
}
.side-nav {
  position: sticky; top: 0; display: flex; flex-direction: column; height: 100vh;
  padding: 16px 12px 12px; border-right: 1px solid var(--line); background: #fff; overflow: auto;
}
.wordmark {
  display: block; margin: 4px 12px 18px; color: var(--ink); font-size: 1.25rem;
  font-weight: 700; letter-spacing: -0.03em; text-decoration: none; background: none; border: 0;
  cursor: pointer; text-align: left; padding: 0;
}
.side-nav nav { display: flex; flex-direction: column; gap: 2px; }
.nav-label {
  margin: 16px 12px 6px; color: var(--muted); font-size: 12px; font-weight: 700;
  letter-spacing: 0.04em; text-transform: uppercase;
}
.nav-link {
  display: flex; align-items: center; gap: 12px; min-height: 40px; padding: 8px 12px;
  border-radius: 10px; color: var(--ink); text-decoration: none; font-weight: 500;
  border: 0; background: transparent; cursor: pointer; text-align: left; width: 100%;
}
.nav-link:hover, .nav-link[aria-current="page"] { background: var(--nav); }
.nav-link[aria-current="page"] { font-weight: 700; }
.nav-foot { margin-top: auto; padding-top: 16px; }
.nav-foot p { margin: 8px 12px 0; color: var(--muted); font-size: 12px; }
.stage { min-width: 0; padding: 24px 28px 64px; background: var(--stage); }
.stage-head { margin-bottom: 12px; }
.stage-head h1, .channel-head h1, .panel h1, .admin-page h1, .item-copy h1 {
  margin: 0; font-size: 1.35rem; font-weight: 700; letter-spacing: -0.02em; line-height: 1.2;
}
.item-copy h1 { font-size: 1.5rem; margin-top: 10px; }
.sub, .muted { color: var(--muted); }
.sub { margin: 6px 0 0; max-width: 52rem; }
.sub a { color: var(--accent); }
.notice {
  margin: 0 0 16px; padding: 10px 12px; border-radius: 8px; background: #e8f0fe; color: #174ea6;
}
.newsletter-notice { background: #fff4e5; color: #8a4b00; }
.mode-tabs {
  display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 16px;
}
.mode-tabs button {
  padding: 8px 14px; border-radius: 999px; border: 1px solid var(--line);
  background: #fff; color: var(--ink); font-weight: 600; cursor: pointer;
}
.mode-tabs button:hover { background: var(--nav); }
.mode-tabs button[aria-selected="true"] {
  background: var(--ink); color: #fff; border-color: var(--ink);
}
.media-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 28px 16px; list-style: none; margin: 0; padding: 0;
}
.thumb {
  position: relative; display: block; aspect-ratio: 16/9; overflow: hidden;
  border-radius: 12px; background: #e8e8e8; text-decoration: none;
}
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb-fallback {
  display: flex; flex-direction: column; align-items: flex-start; justify-content: flex-end;
  width: 100%; height: 100%; padding: 16px; color: #fff;
}
.thumb-fallback strong { font-size: 3rem; line-height: 1; letter-spacing: -0.04em; }
.thumb-fallback em {
  margin-top: 8px; font-style: normal; font-size: 13px; font-weight: 700;
  letter-spacing: 0.04em; text-transform: uppercase;
}
.thumb-chip {
  position: absolute; left: 8px; bottom: 8px; padding: 2px 6px; border-radius: 4px;
  background: rgba(0,0,0,.75); color: #fff; font-size: 12px; font-weight: 700;
}
.media-body {
  display: grid; grid-template-columns: 36px minmax(0,1fr); gap: 12px; margin-top: 12px;
}
.media-body.solo { grid-template-columns: minmax(0,1fr); }
.avatar {
  display: grid; place-items: center; width: 36px; height: 36px; border-radius: 50%;
  color: #fff; font-size: 13px; font-weight: 700; text-decoration: none; flex: none;
  border: 0; cursor: pointer; padding: 0;
}
.avatar.lg { width: 80px; height: 80px; font-size: 28px; cursor: default; }
.media-copy { min-width: 0; }
.media-copy h2 {
  margin: 0; font-size: 16px; font-weight: 600; line-height: 1.35;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.media-copy h2 a { color: var(--ink); text-decoration: none; }
.channel, .media-copy time {
  display: block; margin-top: 4px; color: var(--muted); font-size: 14px; text-decoration: none;
  background: none; border: 0; padding: 0; cursor: pointer; font: inherit; text-align: left;
}
.channel:hover { color: var(--ink); }
.meta-row {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 6px;
}
.meta-row time { margin-top: 0; font-size: 13px; }
.rank-chip {
  display: inline-flex; align-items: center; padding: 2px 8px; border-radius: 999px;
  background: var(--chip-bg); color: var(--chip); font-size: 12px; font-weight: 700;
  letter-spacing: 0.01em; white-space: nowrap;
}
.rank-chip.lg { font-size: 13px; padding: 4px 10px; }
.topic-chip {
  display: inline-flex; align-items: center; padding: 2px 7px; border-radius: 999px;
  background: #e8f0fe; color: #174ea6; font-size: 12px; font-weight: 700; white-space: nowrap;
}
.channel-head { display: flex; align-items: flex-start; gap: 16px; margin-bottom: 8px; }
.source-line {
  display: flex; flex-wrap: wrap; gap: 8px 18px; margin: 10px 0 0; padding: 0;
  list-style: none; color: var(--muted);
}
.source-line a { color: var(--accent); }
.source-line code, .empty code, .panel code, .admin-page code {
  margin-left: 2px; font-family: ui-monospace, SFMono-Regular, monospace; font-size: 12px;
  background: #f0f0f0; padding: 1px 5px; border-radius: 4px;
}
.channel-tabs {
  display: flex; gap: 8px; margin: 18px 0 22px; border-bottom: 1px solid var(--line);
}
.channel-tabs button {
  margin-bottom: -1px; padding: 12px 16px; border: 0; border-bottom: 2px solid transparent;
  color: var(--muted); background: transparent; font-weight: 600; cursor: pointer;
}
.channel-tabs button[aria-selected="true"] {
  color: var(--ink); border-bottom-color: var(--ink);
}
.empty, .stub, .panel { padding: 28px 8px; color: var(--muted); }
.stub, .panel {
  max-width: 720px; padding: 28px; border-radius: 12px; background: #f8f8f8;
}
.stub h2, .panel h2, .empty h2 { margin: 0 0 8px; color: var(--ink); font-size: 1.15rem; }
.newsletter-empty {
  max-width: 640px; padding: 28px; border-radius: 12px; background: #fff8ef;
  border: 1px solid #f0d9b5; color: #5c3b12;
}
.newsletter-empty h2 { color: #3d2508; }
.empty-steps { margin: 12px 0; padding-left: 1.25rem; }
.empty-steps li { margin: 6px 0; }
.admin-page { max-width: 980px; }

/* Item / knowledge page */
.item-page { max-width: 980px; }
.crumb { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin: 0 0 18px; color: var(--muted); }
.crumb .channel { display: inline; margin: 0; }
.item-hero {
  display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr); gap: 24px; align-items: start;
  margin-bottom: 24px;
}
.detail-thumb {
  width: 100%; aspect-ratio: 16/9; object-fit: cover; border-radius: 14px; background: #e8e8e8; display: block;
}
.detail-thumb.fallback {
  display: flex; flex-direction: column; align-items: flex-start; justify-content: flex-end;
  padding: 20px; color: #fff;
}
.detail-thumb.fallback strong { font-size: 3rem; line-height: 1; }
.detail-thumb.fallback em { margin-top: 8px; font-style: normal; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; }
.item-meta { display: flex; flex-wrap: wrap; gap: 10px 14px; align-items: center; margin-top: 10px; color: var(--muted); }
.item-meta .channel, .item-meta time { margin: 0; display: inline; }
.kind-pill {
  display: inline-flex; padding: 2px 8px; border-radius: 999px; background: #eee; font-size: 12px; font-weight: 700;
}
.detail-stats {
  display: flex; flex-wrap: wrap; gap: 8px 14px; margin: 12px 0 0; color: var(--muted); font-size: 13px;
}
.item-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 18px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px 16px; border-radius: 999px; border: 0; background: var(--ink); color: #fff;
  font-weight: 700; cursor: pointer; text-decoration: none;
}
.btn:hover { filter: brightness(1.08); }
.btn-secondary {
  background: #fff; color: var(--ink); border: 1px solid var(--line);
}
.summary-panel {
  padding: 22px 24px; border-radius: 14px; background: #f7f9fc; border: 1px solid #d6e2f5;
}
.summary-panel.cached { background: #f3faf5; border-color: #c6e6d3; }
.summary-head { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.summary-head h2 { margin: 0; font-size: 1.1rem; }
.badge {
  display: inline-flex; padding: 2px 8px; border-radius: 999px; background: #d1f0dd; color: var(--ok);
  font-size: 12px; font-weight: 700;
}
.badge.warn { background: #ffe8c2; color: var(--warn); }
.summary-headline { margin: 0 0 10px; font-weight: 600; }
.summary-panel ul { margin: 0; padding-left: 1.2rem; }
.summary-panel li { margin: 6px 0; }
.summary-note { margin-top: 12px; }
.summary-hint { margin-top: 10px; }

@media (max-width: 960px) {
  .app-shell { grid-template-columns: 1fr; }
  .side-nav { position: static; height: auto; border-right: 0; border-bottom: 1px solid var(--line); }
  .item-hero { grid-template-columns: 1fr; }
}


.filter-block { display: flex; flex-direction: column; gap: 8px; margin: 10px 0 18px; }
.chip-row { display: flex; flex-wrap: wrap; gap: 8px; }
a.chip {
  display: inline-flex; align-items: center; padding: 6px 12px; border-radius: 999px;
  background: #1f1f1f; color: #ddd; text-decoration: none; font-size: 13px; border: 1px solid #333;
}
a.chip.active, a.chip:hover { background: #fff; color: #111; border-color: #fff; }
.media-thumb { position: relative; }
.duration-badge {
  position: absolute; right: 8px; bottom: 8px; background: rgba(0,0,0,.85);
  color: #fff; font-size: 12px; padding: 2px 6px; border-radius: 4px;
}

/* Home filter controls */
.filters {
  display: flex; flex-direction: column; gap: 10px; margin: 0 0 18px; padding: 14px 16px;
  border: 1px solid var(--line); border-radius: 12px; background: #fafafa;
}
.filter-group { display: flex; align-items: center; flex-wrap: wrap; gap: 8px 14px; }
.filter-label { min-width: 62px; color: var(--muted); font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; }
.filter-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.filter-chip {
  padding: 5px 10px; border: 1px solid var(--line); border-radius: 999px; background: #fff;
  color: var(--ink); cursor: pointer; font-size: 13px;
}
.filter-chip:hover, .filter-chip[aria-selected="true"] { border-color: var(--ink); background: var(--ink); color: #fff; }
.topic-chip { display: inline-flex; padding: 2px 8px; border-radius: 999px; background: #eef3ff; color: #174ea6; font-size: 12px; font-weight: 700; white-space: nowrap; }

/* Knowledge page sections */
.knowledge-panel, .library-panel, .related-panel {
  margin-top: 18px; padding: 22px 24px; border: 1px solid var(--line); border-radius: 14px; background: #fff;
}
.knowledge-panel { background: #fbfcff; border-color: #dce5f5; }
.knowledge-panel h2, .library-panel h2, .related-panel h2 { margin: 0 0 8px; font-size: 1.12rem; }
.knowledge-panel h3 { margin: 18px 0 4px; font-size: .92rem; }
.knowledge-panel p { max-width: 70ch; }
.section-kicker { margin-bottom: 5px; color: var(--accent); font-size: 11px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; }
.knowledge-reason { margin: 0; font-weight: 700; }
.tag-list { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 14px; }
.tag { padding: 4px 9px; border-radius: 999px; background: #f1f1f1; color: #444; font-size: 12px; }
.library-panel { display: grid; gap: 12px; }
.library-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.note-label { font-size: 12px; font-weight: 700; color: var(--muted); }
.note-input { width: 100%; min-height: 70px; resize: vertical; padding: 10px; border: 1px solid var(--line); border-radius: 8px; font: inherit; }
.related-panel .media-grid { margin-top: 16px; }

@media (max-width: 640px) {
  .stage { padding: 18px 16px 48px; }
  .filter-label { min-width: 100%; }
  .media-grid { grid-template-columns: 1fr; }
}

/* Newsletter cards and sender mapping */
.sender-line { display: block; margin-top: 2px; color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-snippet { margin: 8px 0 0; color: var(--muted); font-size: 13px; line-height: 1.35; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.inline-link { border: 0; padding: 0; background: none; color: inherit; text-decoration: underline; font-weight: 700; cursor: pointer; }
.newsletter-knowledge { margin-top: 18px; }
.newsletter-fields { display: grid; gap: 8px; margin: 14px 0 20px; }
.newsletter-fields > div { display: grid; grid-template-columns: 92px minmax(0, 1fr); gap: 12px; }
.newsletter-fields dt { color: var(--muted); font-weight: 700; }
.newsletter-fields dd { margin: 0; overflow-wrap: anywhere; }
.body-preview { white-space: pre-wrap; max-height: 18rem; overflow: auto; padding: 12px; border-radius: 8px; background: #fafafa; border: 1px solid var(--line); }
.unknown-list { display: grid; gap: 10px; margin-top: 22px; max-width: 980px; }
.unknown-row { display: flex; align-items: center; justify-content: space-between; gap: 18px; padding: 16px 18px; border: 1px solid #f0d9b5; border-radius: 12px; background: #fff8ef; }
.unknown-row p { margin: 3px 0 0; }
.map-controls { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.map-controls select { min-height: 40px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--ink); }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
@media (max-width: 680px) {
  .unknown-row { align-items: flex-start; flex-direction: column; }
  .map-controls { justify-content: flex-start; }
  .newsletter-fields > div { grid-template-columns: 76px minmax(0, 1fr); }
}


/* Length split: Shorts vs Long-form */
.chip-row[aria-label="Length"] .chip {
  font-weight: 600;
}
.short-badge {
  position: absolute;
  left: 8px;
  top: 8px;
  background: #111;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  padding: 3px 7px;
  border-radius: 4px;
  text-transform: uppercase;
}
.length-hint {
  font-size: 13px;
  color: #888;
  margin: 0 0 12px;
}


/* Cost saver + length */
.cost-badge {
  display: block;
  width: 100%;
  text-align: left;
  margin: 0 0 10px;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid rgba(255,255,255,0.12);
  background: rgba(34, 197, 94, 0.12);
  color: #86efac;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}
.cost-badge:hover { background: rgba(34, 197, 94, 0.2); }
.load-more-wrap {
  grid-column: 1 / -1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 18px 0 8px;
}
button.load-more, .btn.load-more {
  padding: 10px 18px;
  border-radius: 999px;
  border: 1px solid rgba(255,255,255,0.16);
  background: #1f1f1f;
  color: #fff;
  font-weight: 600;
  cursor: pointer;
}
button.load-more:hover { background: #2a2a2a; }
.length-hint { font-size: 13px; color: #9ca3af; margin: 0 0 12px; }
.short-badge, .short-chip {
  position: absolute;
  left: 8px;
  top: 8px;
  background: #111;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  padding: 3px 7px;
  border-radius: 4px;
  text-transform: uppercase;
}
.cost-panel .cost-stats { line-height: 1.7; margin: 0 0 16px; padding-left: 18px; }
.cost-actions { display: grid; gap: 12px; max-width: 420px; }
.cost-actions label { display: grid; gap: 6px; font-size: 13px; color: #d1d5db; }
.cost-actions input, .cost-actions select {
  padding: 8px 10px; border-radius: 8px; border: 1px solid #333; background: #111; color: #fff;
}
.badge.warn { background: #78350f; color: #fde68a; }
