:root {
  color-scheme: light;
  --ink: #1f2733;
  --muted: #687281;
  --paper: #f7f5f0;
  --panel: #ffffff;
  --line: #e5e0d7;
  --navy: #18395e;
  --blue: #2e6fa3;
  --coral: #e86f61;
  --coral-soft: #fff0ed;
  --gold: #d1a844;
  --shadow: 0 16px 44px rgba(24, 57, 94, 0.08);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background:
    radial-gradient(circle at 90% 0%, rgba(232, 111, 97, 0.12), transparent 28rem),
    var(--paper);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

[hidden] { display: none !important; }
body.auth-pending { overflow: hidden; }
body.auth-pending #dashboard { visibility: hidden; }

.auth-gate {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  overflow-y: auto;
  padding: 32px;
  background:
    radial-gradient(circle at 12% 18%, rgba(232, 111, 97, 0.22), transparent 25rem),
    radial-gradient(circle at 87% 82%, rgba(209, 168, 68, 0.18), transparent 28rem),
    var(--paper);
}
.auth-shell { display: grid; grid-template-columns: minmax(250px, 0.78fr) minmax(360px, 1fr); width: min(850px, 100%); overflow: hidden; border: 1px solid rgba(24, 57, 94, 0.1); border-radius: 28px; background: white; box-shadow: 0 30px 90px rgba(24, 57, 94, 0.18); }
.auth-brand { display: flex; min-height: 520px; padding: 42px; flex-direction: column; justify-content: space-between; background: linear-gradient(145deg, #214b78, var(--navy)); color: white; }
.auth-brand::after { content: "Sisterhood, clearly."; max-width: 220px; color: rgba(255, 255, 255, 0.82); font-family: Georgia, serif; font-size: 2.2rem; line-height: 1.05; }
.auth-mark { display: inline-grid; width: 76px; height: 76px; place-items: center; border: 1px solid rgba(255, 255, 255, 0.35); border-radius: 22px; background: rgba(255, 255, 255, 0.1); font-family: Georgia, serif; font-size: 1.45rem; letter-spacing: 0.04em; }
.auth-brand p { margin: -75px 0 0 94px; font-size: 0.82rem; font-weight: 800; letter-spacing: 0.08em; text-transform: uppercase; }
.auth-card { align-self: center; padding: 50px; }
.auth-card h1 { margin: 8px 0 10px; color: var(--navy); font-family: Georgia, serif; font-size: clamp(2.5rem, 5vw, 4.2rem); font-weight: 500; letter-spacing: -0.045em; line-height: 1; }
.auth-copy { margin: 0 0 28px; color: var(--muted); line-height: 1.55; }
.auth-form { display: grid; gap: 9px; }
.auth-form label { margin-top: 7px; color: var(--ink); font-size: 0.77rem; font-weight: 800; letter-spacing: 0.04em; text-transform: uppercase; }
.auth-form input { width: 100%; border: 1px solid var(--line); border-radius: 12px; padding: 14px 15px; background: #faf9f6; color: var(--ink); font: inherit; }
.auth-form input:focus { outline: 3px solid rgba(46, 111, 163, 0.18); border-color: var(--blue); }
.auth-form button[type="submit"] { min-height: 50px; margin-top: 13px; border: 0; border-radius: 12px; background: var(--navy); color: white; cursor: pointer; font: inherit; font-weight: 800; }
.auth-form button[type="submit"]:hover { background: var(--blue); }
.auth-form button[type="submit"].loading span { opacity: 0.45; }
.auth-form button[type="submit"].loading::after { content: "Working…"; margin-left: -2.9rem; }
.auth-form small, .password-hint { margin: 3px 0 0; color: var(--muted); font-size: 0.7rem; line-height: 1.45; }
.auth-error { margin: 0 0 17px; padding: 11px 13px; border: 1px solid rgba(232, 111, 97, 0.35); border-radius: 10px; background: var(--coral-soft); color: #8c3329; font-size: 0.8rem; line-height: 1.45; }
.auth-back { border: 0; padding: 7px; background: transparent; color: var(--blue); cursor: pointer; font: inherit; font-size: 0.76rem; font-weight: 800; }
.auth-privacy { position: absolute; bottom: 18px; margin: 0; color: var(--muted); font-size: 0.68rem; letter-spacing: 0.05em; text-transform: uppercase; }

main { width: min(1500px, calc(100% - 40px)); margin: 0 auto; padding: 52px 0 72px; }

.hero { display: flex; align-items: flex-end; justify-content: space-between; gap: 32px; margin-bottom: 36px; }
.hero h1 { margin: 3px 0 10px; color: var(--navy); font-family: Georgia, serif; font-size: clamp(3rem, 7vw, 6.4rem); font-weight: 500; letter-spacing: -0.055em; line-height: 0.92; }
.lede { max-width: 720px; margin: 0; color: var(--muted); font-size: 1.08rem; line-height: 1.6; }
.eyebrow { margin: 0; color: var(--coral); font-size: 0.73rem; font-weight: 800; letter-spacing: 0.16em; }

.source-card { min-width: 260px; padding: 18px 20px; border: 1px solid var(--line); border-radius: 16px; background: rgba(255, 255, 255, 0.7); box-shadow: var(--shadow); }
.source-card span, .source-card small { display: block; color: var(--muted); font-size: 0.7rem; letter-spacing: 0.08em; }
.source-card strong { display: block; max-width: 280px; margin: 6px 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 0.88rem; }
.sign-out { margin-top: 10px; border: 0; padding: 0; background: transparent; color: var(--blue); cursor: pointer; font: inherit; font-size: 0.72rem; font-weight: 800; }

.workspace-nav { display: inline-flex; gap: 6px; margin-bottom: 22px; padding: 6px; border-radius: 16px; background: var(--navy); box-shadow: var(--shadow); }
.view-button { border: 0; border-radius: 11px; padding: 12px 20px; background: transparent; color: rgba(255, 255, 255, 0.68); cursor: pointer; font: inherit; font-size: 0.9rem; font-weight: 800; }
.view-button.active { background: white; color: var(--navy); }
.workspace-view.hidden { display: none; }
.scope-row { display: inline-flex; gap: 4px; margin-bottom: 20px; padding: 5px; border: 1px solid var(--line); border-radius: 14px; background: #eeeae2; }
.scope-button { border: 0; border-radius: 10px; padding: 11px 18px; background: transparent; color: var(--muted); cursor: pointer; font: inherit; font-size: 0.9rem; font-weight: 750; }
.scope-button.active { background: var(--panel); color: var(--navy); box-shadow: 0 3px 12px rgba(31, 39, 51, 0.08); }

.metric-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }
.metric { min-height: 154px; padding: 22px; border: 1px solid var(--line); border-radius: 18px; background: var(--panel); box-shadow: var(--shadow); }
.metric span, .metric small { display: block; color: var(--muted); }
.metric span { font-size: 0.79rem; font-weight: 750; letter-spacing: 0.04em; text-transform: uppercase; }
.metric strong { display: block; margin: 13px 0 4px; color: var(--navy); font-family: Georgia, serif; font-size: 3.2rem; font-weight: 500; line-height: 1; }
.metric small { font-size: 0.75rem; }
.metric.accent { border-color: var(--coral); background: var(--coral-soft); }
.metric.accent strong { color: var(--coral); }

.panel { margin-top: 18px; padding: 28px; border: 1px solid var(--line); border-radius: 20px; background: var(--panel); box-shadow: var(--shadow); }
.panel h2 { margin: 5px 0 6px; color: var(--navy); font-family: Georgia, serif; font-size: 2rem; font-weight: 500; }
.panel-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; }
.panel-note { margin: 0; color: var(--muted); font-size: 0.86rem; }
.story-panel { display: grid; grid-template-columns: 1fr minmax(300px, 0.7fr); align-items: center; gap: 50px; }
#scope-copy { max-width: 720px; margin: 9px 0 0; color: var(--muted); line-height: 1.6; }
.exceptions { display: grid; grid-template-columns: 1fr 1fr; gap: 1px; overflow: hidden; margin: 0; border-radius: 14px; background: var(--line); }
.exceptions div { padding: 18px; background: #faf9f6; }
.exceptions dt { color: var(--coral); font-family: Georgia, serif; font-size: 2rem; }
.exceptions dd { margin: 3px 0 0; color: var(--muted); font-size: 0.72rem; line-height: 1.4; }

.trend { display: flex; align-items: stretch; gap: 10px; min-height: 250px; margin-top: 26px; overflow-x: auto; }
.year-column { display: grid; grid-template-rows: 1fr auto auto; min-width: 116px; flex: 1 0 116px; border: 0; border-radius: 14px; background: #f6f4ef; color: var(--ink); cursor: pointer; overflow: hidden; text-align: left; }
.year-column:hover, .year-column.active { outline: 2px solid var(--coral); outline-offset: -2px; }
.bar-stage { display: flex; align-items: flex-end; padding: 14px 16px 0; }
.bar { width: 100%; min-height: 8px; border-radius: 8px 8px 0 0; background: linear-gradient(180deg, var(--blue), var(--navy)); }
.year-value { padding: 10px 16px 2px; color: var(--navy); font-family: Georgia, serif; font-size: 1.7rem; }
.year-label { padding: 0 16px 14px; color: var(--muted); font-size: 0.74rem; font-weight: 750; }
.trend-caveat { margin: 16px 0 0; color: var(--muted); font-size: 0.72rem; line-height: 1.5; }

.detail-heading { align-items: center; }
.detail-actions { display: flex; gap: 10px; align-items: center; }
input[type="search"] { width: min(360px, 36vw); border: 1px solid var(--line); border-radius: 10px; padding: 11px 13px; background: #faf9f6; color: var(--ink); font: inherit; }
input[type="search"]:focus { outline: 2px solid rgba(46, 111, 163, 0.3); border-color: var(--blue); }
.download { border-radius: 10px; padding: 11px 15px; background: var(--navy); color: white; font-size: 0.86rem; font-weight: 750; text-decoration: none; white-space: nowrap; }
.download:hover { background: var(--blue); }

.table-wrap { margin-top: 22px; overflow: auto; border: 1px solid var(--line); border-radius: 14px; }
table { width: 100%; border-collapse: collapse; font-size: 0.79rem; white-space: nowrap; }
th { position: sticky; top: 0; z-index: 1; padding: 11px 13px; background: var(--navy); color: white; text-align: left; text-transform: uppercase; letter-spacing: 0.04em; }
td { max-width: 280px; overflow: hidden; padding: 10px 13px; border-bottom: 1px solid #eeeae2; text-overflow: ellipsis; }
tbody tr:nth-child(even) { background: #faf9f6; }
tbody tr:hover { background: var(--coral-soft); }
.privacy-note { margin: 12px 0 0; color: var(--muted); font-size: 0.72rem; }
.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; }

.tag-hero { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 40px; margin-top: 0; background: linear-gradient(125deg, var(--panel), #fff7f4); }
.tag-hero h2 { max-width: 820px; font-size: clamp(2rem, 4vw, 3.6rem); letter-spacing: -0.035em; }
.tag-hero p:last-child { max-width: 780px; margin: 10px 0 0; color: var(--muted); line-height: 1.6; }
.tag-total-card { min-width: 190px; padding: 23px; border: 1px solid rgba(232, 111, 97, 0.4); border-radius: 17px; background: var(--coral-soft); text-align: center; }
.tag-total-card strong { display: block; color: var(--coral); font-family: Georgia, serif; font-size: 3.8rem; font-weight: 500; line-height: 1; }
.tag-total-card span { color: var(--muted); font-size: 0.76rem; font-weight: 750; text-transform: uppercase; }
.tag-builder { padding-bottom: 32px; }
.tag-toolbar { display: grid; grid-template-columns: minmax(260px, 1fr) auto auto; align-items: end; gap: 16px; }
.tag-search-label span, .match-control legend { display: block; margin-bottom: 7px; color: var(--muted); font-size: 0.72rem; font-weight: 800; letter-spacing: 0.06em; text-transform: uppercase; }
.tag-search-label input { width: 100%; }
.match-control { display: flex; gap: 4px; margin: 0; padding: 0; border: 0; }
.match-control legend { width: 100%; }
.match-button, .clear-button { border: 1px solid var(--line); border-radius: 10px; padding: 11px 14px; background: #faf9f6; color: var(--muted); cursor: pointer; font: inherit; font-size: 0.8rem; font-weight: 750; }
.match-button.active { border-color: var(--blue); background: #eaf3fa; color: var(--navy); }
.clear-button:hover, .match-button:hover { border-color: var(--blue); color: var(--navy); }
.selection-line { display: flex; gap: 10px; align-items: baseline; margin: 24px 0 14px; }
.selection-line strong { color: var(--navy); }
.selection-line span { color: var(--muted); font-size: 0.8rem; }
.tag-cloud { display: flex; flex-wrap: wrap; gap: 8px; max-height: 430px; overflow-y: auto; padding: 3px; }
.tag-chip { display: inline-flex; align-items: center; gap: 8px; border: 1px solid var(--line); border-radius: 999px; padding: 8px 9px 8px 13px; background: #faf9f6; color: var(--ink); cursor: pointer; font: inherit; font-size: 0.78rem; transition: transform 120ms ease, border-color 120ms ease, background 120ms ease; }
.tag-chip:hover { border-color: var(--gold); transform: translateY(-1px); }
.tag-chip.selected { border-color: var(--navy); background: var(--navy); color: white; }
.tag-chip.sisterhood-positive:not(.selected) { border-color: rgba(232, 111, 97, 0.5); background: var(--coral-soft); }
.tag-chip.sisterhood-negative:not(.selected) { border-style: dashed; }
.tag-chip-count { display: inline-grid; min-width: 25px; height: 25px; place-items: center; border-radius: 999px; background: rgba(24, 57, 94, 0.09); color: inherit; font-size: 0.67rem; font-weight: 850; }
.tag-chip.selected .tag-chip-count { background: rgba(255, 255, 255, 0.17); }
.tag-empty { margin: 12px 0; color: var(--muted); }

.refresh-hero { display: flex; align-items: center; justify-content: space-between; gap: 30px; margin-top: 0; background: linear-gradient(125deg, white, #edf5fb); }
.refresh-hero p:last-child { max-width: 760px; margin: 10px 0 0; color: var(--muted); line-height: 1.6; }
.refresh-lock { border-radius: 999px; padding: 9px 13px; background: var(--navy); color: white; font-size: 0.68rem; font-weight: 850; letter-spacing: 0.1em; white-space: nowrap; }
.refresh-panel { max-width: 980px; }
.refresh-step { display: flex; align-items: center; gap: 14px; margin-bottom: 22px; }
.refresh-step > span { display: grid; width: 38px; height: 38px; place-items: center; border-radius: 50%; background: var(--coral-soft); color: var(--coral); font-family: Georgia, serif; font-size: 1.3rem; }
.refresh-step strong, .refresh-step small { display: block; }
.refresh-step small { margin-top: 3px; color: var(--muted); }
.upload-zone { display: grid; min-height: 155px; place-items: center; align-content: center; gap: 8px; border: 2px dashed #b9c8d7; border-radius: 16px; background: #f8fafb; cursor: pointer; text-align: center; }
.upload-zone:hover { border-color: var(--blue); background: #f0f6fa; }
.upload-zone input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.upload-zone strong { color: var(--navy); }
.upload-zone span { color: var(--muted); font-size: 0.78rem; }
.refresh-primary { margin-top: 18px; border: 0; border-radius: 11px; padding: 13px 18px; background: var(--navy); color: white; cursor: pointer; font: inherit; font-weight: 800; }
.refresh-primary:hover:not(:disabled) { background: var(--blue); }
.refresh-primary:disabled { cursor: not-allowed; opacity: 0.42; }
.refresh-primary.danger { background: var(--coral); }
.refresh-status { min-height: 1.3em; margin: 13px 0 0; color: var(--muted); font-size: 0.8rem; }
.refresh-status.success { color: #26704c; }
.refresh-status.error { color: #9a382d; }
.publish-notice { margin-bottom: 22px; padding: 18px 22px; border: 1px solid #b6d8c5; border-radius: 14px; background: #edf8f2; color: #26704c; line-height: 1.5; overflow-wrap: anywhere; }
.publish-notice p { margin: 0; }
.publish-notice.warning { border-color: #e7ce8a; background: #fff9e9; color: #6a5420; }
.publish-notice:focus { outline: 2px solid currentColor; outline-offset: 3px; }
.validation-file { padding: 16px 18px; border-radius: 13px; background: #f7f5f0; }
.validation-file span, .validation-file small { display: block; color: var(--muted); font-size: 0.7rem; }
.validation-file strong { display: block; margin: 4px 0; color: var(--navy); }
.validation-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-top: 14px; }
.validation-grid article { padding: 16px; border: 1px solid var(--line); border-radius: 13px; }
.validation-grid span, .validation-grid small { display: block; color: var(--muted); font-size: 0.69rem; line-height: 1.35; }
.validation-grid strong { display: block; margin: 9px 0 3px; color: var(--navy); font-family: Georgia, serif; font-size: 2rem; font-weight: 500; }
.validation-warnings, .validation-ok { margin-top: 14px; padding: 14px 17px; border-radius: 12px; font-size: 0.78rem; line-height: 1.5; }
.validation-warnings { border: 1px solid #e7ce8a; background: #fff9e9; color: #6a5420; }
.validation-warnings ul { margin: 6px 0 0; padding-left: 19px; }
.validation-ok { background: #edf8f2; color: #26704c; }
.publish-confirmation { display: flex; align-items: flex-start; gap: 10px; margin-top: 22px; color: var(--ink); font-size: 0.82rem; line-height: 1.45; }
.publish-confirmation input { margin-top: 3px; }

@media (max-width: 900px) {
  .hero, .panel-heading, .detail-heading { align-items: flex-start; flex-direction: column; }
  .source-card { width: 100%; }
  .metric-grid { grid-template-columns: repeat(2, 1fr); }
  .story-panel { grid-template-columns: 1fr; gap: 24px; }
  .tag-hero { grid-template-columns: 1fr; }
  .tag-total-card { width: 100%; }
  .tag-toolbar { grid-template-columns: 1fr; align-items: stretch; }
  .validation-grid { grid-template-columns: repeat(2, 1fr); }
  .clear-button { justify-self: start; }
  .detail-actions { width: 100%; }
  .detail-actions label { flex: 1; }
  input[type="search"] { width: 100%; }
}

@media (max-width: 560px) {
  .auth-gate { align-items: start; padding: 16px; }
  .auth-shell { grid-template-columns: 1fr; }
  .auth-brand { min-height: 130px; padding: 25px; }
  .auth-brand::after { display: none; }
  .auth-brand p { margin: -52px 0 0 70px; }
  .auth-mark { width: 58px; height: 58px; border-radius: 17px; font-size: 1.1rem; }
  .auth-card { padding: 30px 25px; }
  .auth-privacy { position: static; margin-top: 18px; }
  main { width: min(100% - 24px, 1500px); padding-top: 28px; }
  .metric-grid { grid-template-columns: 1fr; }
  .scope-row { display: flex; }
  .scope-button { flex: 1; padding-inline: 10px; }
  .workspace-nav { display: flex; }
  .view-button { flex: 1; padding-inline: 10px; }
  .panel { padding: 20px; }
  .exceptions { grid-template-columns: 1fr; }
  .detail-actions { align-items: stretch; flex-direction: column; }
  .refresh-hero { align-items: flex-start; flex-direction: column; }
  .validation-grid { grid-template-columns: 1fr; }
  .download { text-align: center; }
}
