:root {
  --bg: #f3f6f8;
  --surface: #ffffff;
  --surface-2: #e9eff3;
  --ink: #002a3f;
  --muted: #4a6578;
  --faint: #6b8494;
  --border: #dbe4ea;
  --accent: #005e8f;
  --accent-ink: #ffffff;
  --cta: #93e100;
  --cta-ink: #002a3f;
  --green: oklch(0.5 0.09 150);
  --amber: oklch(0.55 0.1 70);
  --mono: "SFMono-Regular", "JetBrains Mono", ui-monospace, Menlo, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif;
}

:root[data-theme="dark"] {
  --bg: #002a3f;
  --surface: #0d3850;
  --surface-2: #164863;
  --ink: #eaf3f7;
  --muted: #a9c2d1;
  --faint: #7f9db0;
  --border: #1c4a63;
  --accent: #7fb8dc;
  --accent-ink: #002a3f;
  --cta: #93e100;
  --cta-ink: #002a3f;
  --green: oklch(0.7 0.09 150);
  --amber: oklch(0.73 0.1 70);
}

* { box-sizing: border-box; }

#top-loading-bar { position: fixed; top: 0; left: 0; height: 3px; width: 100%; background: var(--cta); z-index: 200; opacity: 0; transform: scaleX(0); transform-origin: left; transition: transform 0.25s ease-out, opacity 0.2s; }
#top-loading-bar.active { opacity: 1; transform: scaleX(0.6); }
#global-error-banner { position: fixed; top: 0; left: 0; right: 0; z-index: 199; background: var(--amber); color: #241a00; padding: 10px 16px; font-size: 0.85rem; display: flex; align-items: center; gap: 12px; box-shadow: 0 2px 8px rgb(0 0 0 / 0.15); }
#global-error-banner button { background: none; border: none; color: inherit; cursor: pointer; margin-left: auto; font-size: 0.9rem; padding: 2px 6px; opacity: 0.7; }
#global-error-banner button:hover { opacity: 1; }

@keyframes w-spin { to { transform: rotate(360deg); } }
.w-spinner-svg { animation: w-spin 0.9s linear infinite; }
@media (prefers-reduced-motion: reduce) { .w-spinner-svg { animation-duration: 2.4s; } }
.w-spinner { display: inline-flex; align-items: center; gap: 10px; color: var(--muted); font-size: 0.9rem; }
.w-spinner svg { width: 22px; height: 22px; animation: w-spin 0.9s linear infinite; flex-shrink: 0; }
@media (prefers-reduced-motion: reduce) { .w-spinner svg { animation-duration: 2.4s; } }

html, body {
  margin: 0;
  padding: 0;
  overflow-x: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.wrap { max-width: 1200px; margin: 0 auto; padding: 28px 24px 96px; }

header { display: flex; flex-wrap: wrap; align-items: baseline; gap: 12px 24px; margin-bottom: 24px; }
header h1 { font-size: 1.6rem; font-weight: 650; letter-spacing: -0.02em; margin: 0; }
header .sub { color: var(--muted); font-size: 0.9rem; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 1px; background: var(--border); border: 1px solid var(--border); border-radius: 10px; overflow: hidden; margin-bottom: 20px; }
.stat { background: var(--surface); padding: 16px 20px; }
.stat .num { font-family: var(--mono); font-size: 1.4rem; font-weight: 600; letter-spacing: -0.01em; }
.stat .lbl { color: var(--muted); font-size: 0.78rem; margin-top: 2px; }
.stat .num small { font-size: 0.7rem; color: var(--faint); font-weight: 400; }

.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 14px; border-bottom: 1px solid var(--border); padding-bottom: 0; }
.toolbar .tabs { display: flex; flex-wrap: wrap; gap: 2px; margin-right: auto; }
.tab { background: var(--surface); border: 1px solid var(--border); color: var(--muted); padding: 7px 16px; border-radius: 5px; cursor: pointer; font-size: 0.85rem; font-family: var(--sans); }
.tab.active { background: var(--surface-2); color: var(--ink); border-color: var(--accent); }

.toolbar .tabs .tab { background: none; border: none; border-bottom: 2px solid transparent; border-radius: 0; padding: 10px 10px 8px; margin-bottom: -1px; color: var(--muted); font-weight: 500; }
.toolbar .tabs .tab.active { background: none; color: var(--ink); border-color: var(--cta); }
.toolbar .tabs .tab:hover:not(.active) { color: var(--ink); }

select, input { background: var(--surface); border: 1px solid var(--border); color: var(--ink); border-radius: 5px; padding: 7px 10px; font-size: 0.85rem; font-family: var(--sans); }
select:focus, input:focus { outline: none; border-color: var(--accent); }

.view { display: none; }
.view.active { display: block; }

.table-scroll { overflow-x: auto; }
table { width: 100%; min-width: 560px; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { color: var(--muted); font-size: 0.72rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; position: sticky; top: 0; background: var(--bg); }
td.num { font-family: var(--mono); font-size: 0.85rem; white-space: nowrap; }
td.mobile-toggle { display: none; }
tr.row { cursor: pointer; }
tr.row:hover td { background: var(--surface-2); }
tr.row[data-analyzed="false"] td { opacity: 0.45; }

.platform { font-size: 0.7rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; padding: 2px 8px; border-radius: 5px; }
.platform.instagram { background: oklch(0.6 0.06 35 / 0.14); color: oklch(0.46 0.07 32); }
.platform.tiktok { background: oklch(0.55 0.03 210 / 0.14); color: oklch(0.42 0.04 210); }
:root[data-theme="dark"] .platform.instagram { color: oklch(0.74 0.06 32); }
:root[data-theme="dark"] .platform.tiktok { color: oklch(0.78 0.03 210); }

.tag { font-size: 0.72rem; padding: 2px 8px; border-radius: 5px; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.tag.hook { color: var(--accent); background: oklch(0.6 0.05 227 / 0.14); }
.tag.suite { color: oklch(0.42 0.08 130); background: oklch(0.6 0.09 130 / 0.13); }
:root[data-theme="dark"] .tag.suite { color: oklch(0.8 0.09 130); }
.tag.empty { color: var(--faint); background: transparent; border: none; padding-left: 0; }

.creator { font-weight: 550; }
.caption { color: var(--muted); font-size: 0.85rem; max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.detail { margin: 16px 0 24px; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 20px; display: none; overflow-wrap: break-word; max-width: 100%; }
.detail.open { display: block; }
.detail .grid { display: grid; grid-template-columns: 220px minmax(0, 1fr); gap: 20px; max-width: 100%; }
.detail .grid > div { min-width: 0; }
.detail video { width: 100%; max-height: 360px; border-radius: 8px; background: #000; aspect-ratio: 9/16; object-fit: contain; }
.detail h3 { margin: 0 0 8px; font-size: 1.05rem; }
.detail .meta { color: var(--muted); font-size: 0.85rem; margin-bottom: 12px; }
.detail .tags { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 14px; }
.detail .block { margin-bottom: 14px; max-width: 100%; }
.detail .block h4 { margin: 0 0 4px; font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); }
.detail .block p { margin: 0; color: var(--ink); font-size: 0.9rem; white-space: pre-wrap; overflow-wrap: anywhere; opacity: 0.88; }
.detail a { color: var(--accent); text-decoration: none; overflow-wrap: anywhere; }
.detail p.caption { overflow-wrap: anywhere; }

.empty { color: var(--faint); padding: 40px; text-align: center; }

#login-overlay .box { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 28px; width: min(320px, calc(100vw - 32px)); }
#login-overlay input { width: 100%; margin-bottom: 10px; }
.pw-field { position: relative; margin-bottom: 10px; }
.pw-field input { padding-right: 38px; margin-bottom: 0; }
.pw-toggle { position: absolute; right: 4px; top: 50%; transform: translateY(-50%); background: none; border: none; padding: 6px; display: flex; align-items: center; justify-content: center; color: var(--faint); cursor: pointer; }
.pw-toggle:hover { color: var(--muted); }
.pw-toggle.active { color: var(--accent); }

@media (max-width: 720px) {
  .detail .grid { grid-template-columns: 1fr; }
  .stats { grid-template-columns: 1fr 1fr; }
  .caption { max-width: 140px; }

  /* Tables become stacked cards — no sideways scrolling on a phone. */
  .table-scroll { overflow-x: visible; }
  .table-scroll table { min-width: 0; }
  table thead { display: none; }
  table, table tbody, table tr, table td { display: block; width: auto; }
  table tr { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 4px 12px; margin-bottom: 10px; }
  table tr:last-child { margin-bottom: 0; }
  table td { display: flex; align-items: baseline; justify-content: space-between; gap: 14px; padding: 7px 0; border-bottom: 1px solid var(--border); text-align: right; }
  table td:last-child { border-bottom: none; }
  table td::before { content: attr(data-label); color: var(--muted); font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.04em; text-align: left; flex-shrink: 0; }
  table td.caption { display: block; text-align: left; white-space: normal; max-width: none; }
  table td.caption::before { content: attr(data-label) ":"; display: block; margin-bottom: 3px; }
  tr.row:hover td { background: none; }

  /* Video cards: show the essentials, tap to reveal the rest — no swipe, no wall of text. */
  table tr:not(.expanded) td.mobile-secondary { display: none; }
  table td.mobile-toggle { display: block; text-align: center; color: var(--accent); font-size: 0.8rem; font-weight: 600; padding: 8px 0 2px; border-bottom: none; }

  .wrap { padding: 20px 16px 96px; }
  header { row-gap: 10px; }
  header h1 { font-size: 1.3rem; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
