:root {
  --navy: #2f5bd6;
  --navy-deep: #161b27;
  --red: #b42318;
  --red-soft: rgba(180, 35, 24, 0.1);
  --bg: #f4f5f8;
  --surface: #ffffff;
  --surface-2: #f8f9fb;
  --text: #17181c;
  --muted: #61656f;
  --border: #dfe2e8;
  --accent: var(--navy);
  --accent-soft: rgba(47, 91, 214, 0.1);
  --ok: #1f7a4d;
  --warn: #b7791f;
  --shadow: 0 1px 2px rgba(15, 20, 35, 0.06), 0 8px 24px rgba(15, 20, 35, 0.06);
  --sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: light;
}

:root[data-theme="dark"] {
  --navy: #8fabf5;
  --navy-deep: #0f131c;
  --red: #f06a5e;
  --red-soft: rgba(240, 106, 94, 0.16);
  --bg: #0f1218;
  --surface: #171c26;
  --surface-2: #1d2331;
  --text: #e8eaf0;
  --muted: #9aa3b5;
  --border: #2a3242;
  --accent-soft: rgba(143, 171, 245, 0.14);
  --ok: #4fc38a;
  --warn: #e0a83a;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.35);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--sans);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--navy); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0 0 0.5rem; line-height: 1.2; letter-spacing: -0.01em; }
h1 { font-size: 1.6rem; font-weight: 800; }
h2 { font-size: 1.2rem; font-weight: 700; }
h3 { font-size: 1rem; font-weight: 700; }
p { margin: 0 0 0.75rem; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.mono { font-family: var(--mono); font-size: 0.85em; }
.hidden { display: none !important; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.flex { display: flex; gap: 0.75rem; align-items: center; flex-wrap: wrap; }
.between { justify-content: space-between; }
.grow { flex: 1 1 auto; }
.stack > * + * { margin-top: 1rem; }

/* Buttons and inputs ------------------------------------------------------- */
button, .btn {
  font: inherit;
  font-weight: 600;
  font-size: 0.9rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  padding: 0.5rem 0.9rem;
  cursor: pointer;
  line-height: 1.2;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}
button:hover, .btn:hover { border-color: var(--navy); text-decoration: none; }
button:disabled { opacity: 0.5; cursor: default; }
button.primary, .btn.primary { background: var(--navy); border-color: var(--navy); color: #fff; }
:root[data-theme="dark"] button.primary, :root[data-theme="dark"] .btn.primary { color: var(--navy-deep); }
button.danger { color: var(--red); border-color: var(--red-soft); }
button.danger:hover { background: var(--red-soft); border-color: var(--red); }
button.ghost { border-color: transparent; background: transparent; }
button.ghost:hover { background: var(--accent-soft); }
button.sm, .btn.sm { padding: 0.3rem 0.6rem; font-size: 0.8rem; }
button.icon { padding: 0.35rem; }

input, select, textarea {
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.5rem 0.65rem;
  width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--navy); }
textarea { min-height: 6rem; resize: vertical; }
label { display: block; font-weight: 600; font-size: 0.85rem; margin-bottom: 0.3rem; }
.field { margin-bottom: 0.9rem; }
.field .hint { font-size: 0.8rem; color: var(--muted); margin-top: 0.25rem; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 1rem; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0 1rem; }
@media (max-width: 720px) { .grid-2, .grid-3 { grid-template-columns: 1fr; } }
input[type="checkbox"] { width: auto; }
.checkbox { display: inline-flex; align-items: center; gap: 0.4rem; font-weight: 500; font-size: 0.9rem; cursor: pointer; }

/* Layout ------------------------------------------------------------------- */
.shell { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.sidebar {
  background: var(--navy-deep);
  color: #e6e9f2;
  padding: 1.25rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  position: sticky;
  top: 0;
  height: 100vh;
}
.sidebar .brand { display: flex; align-items: center; gap: 0.6rem; color: #fff; font-weight: 800; font-size: 0.95rem; letter-spacing: -0.01em; }
.sidebar .brand img { width: 30px; height: 30px; border-radius: 8px; }
.sidebar nav a {
  display: flex; align-items: center; gap: 0.6rem;
  color: #c6cde0; padding: 0.55rem 0.7rem; border-radius: 8px; font-weight: 600; font-size: 0.92rem;
}
.sidebar nav a:hover { background: rgba(255, 255, 255, 0.07); text-decoration: none; color: #fff; }
.sidebar nav a.active { background: rgba(255, 255, 255, 0.12); color: #fff; }
.sidebar nav a svg { width: 18px; height: 18px; opacity: 0.85; }
.sidebar .foot { margin-top: auto; font-size: 0.8rem; color: #9aa3bd; }
.sidebar .foot strong { color: #fff; display: block; }
.sidebar .foot button { background: transparent; border-color: rgba(255,255,255,0.2); color: #fff; margin-top: 0.5rem; }
.main { padding: 1.5rem 2rem 4rem; max-width: 1280px; width: 100%; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1.25rem; flex-wrap: wrap; }
.topbar .crumbs { color: var(--muted); font-size: 0.85rem; }
.topbar .crumbs a { color: var(--muted); }
@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; padding: 0.75rem 1rem; gap: 0.5rem; }
  .sidebar nav { display: flex; flex-wrap: wrap; gap: 0.25rem; }
  .sidebar nav a { padding: 0.4rem 0.6rem; }
  .sidebar .foot { margin-left: auto; }
  .main { padding: 1rem; }
}

/* Cards, tables, badges --------------------------------------------------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 1.1rem 1.25rem; box-shadow: var(--shadow); }
.card + .card { margin-top: 1rem; }
.card h2 { margin-bottom: 0.75rem; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 0.75rem; margin-bottom: 1rem; }
.stats.compact { grid-template-columns: repeat(3, minmax(100px, 1fr)); }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 0.9rem 1rem; }
.stat .n { font-size: 1.7rem; font-weight: 800; letter-spacing: -0.02em; line-height: 1.1; }
.stat .l { color: var(--muted); font-size: 0.8rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
th, td { text-align: left; padding: 0.55rem 0.6rem; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); font-weight: 700; }
tr:hover td { background: var(--surface-2); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.badge { display: inline-block; font-size: 0.75rem; font-weight: 700; padding: 0.15rem 0.5rem; border-radius: 999px; background: var(--accent-soft); color: var(--navy); white-space: nowrap; }
.badge.red { background: var(--red-soft); color: var(--red); }
.badge.ok { background: rgba(31, 122, 77, 0.12); color: var(--ok); }
.badge.warn { background: rgba(183, 121, 31, 0.14); color: var(--warn); }
.badge.grey { background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); }
.empty { text-align: center; color: var(--muted); padding: 2.5rem 1rem; }
.empty h3 { color: var(--text); }
.toast {
  position: fixed; bottom: 1.25rem; left: 50%; transform: translateX(-50%);
  background: var(--navy-deep); color: #fff; padding: 0.6rem 1rem; border-radius: 10px; font-size: 0.9rem; font-weight: 600;
  box-shadow: var(--shadow); z-index: 50; max-width: 90vw;
}
.toast.error { background: var(--red); }
.alert { border-radius: 10px; padding: 0.7rem 0.9rem; font-size: 0.9rem; border: 1px solid var(--border); background: var(--surface-2); }
.alert.error { border-color: var(--red); background: var(--red-soft); color: var(--red); }
.alert.ok { border-color: var(--ok); color: var(--ok); }
.tabs { display: flex; gap: 0.25rem; border-bottom: 1px solid var(--border); margin-bottom: 1rem; overflow-x: auto; }
.tabs button { border: 0; border-bottom: 2px solid transparent; border-radius: 0; background: none; color: var(--muted); padding: 0.55rem 0.8rem; margin-bottom: -1px; }
.tabs button.active { color: var(--text); border-bottom-color: var(--red); }
.searchbar { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; margin-bottom: 1rem; }
.searchbar input, .searchbar select { width: auto; min-width: 12rem; }
.searchbar input[type="search"] { flex: 1 1 16rem; }
.kbd { font-family: var(--mono); font-size: 0.75rem; border: 1px solid var(--border); border-radius: 4px; padding: 0 0.3rem; color: var(--muted); }

/* Plenary workspace ----------------------------------------------------------- */
.workspace { display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: 1rem; align-items: start; }
@media (max-width: 1100px) { .workspace { grid-template-columns: 1fr; } .workspace .side { position: static; } }
.workspace .side { position: sticky; top: 1rem; }
.video { aspect-ratio: 16 / 9; width: 100%; border-radius: 10px; overflow: hidden; background: #000; }
.video iframe { width: 100%; height: 100%; border: 0; }
.statement {
  display: grid; grid-template-columns: 6.5rem minmax(0, 1fr); gap: 0.75rem;
  padding: 0.85rem 0; border-bottom: 1px solid var(--border);
}
.statement:last-child { border-bottom: 0; }
.statement .ts { font-family: var(--mono); font-size: 0.8rem; color: var(--muted); }
.statement .ts a { color: var(--navy); font-weight: 600; }
.statement .speaker { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; margin-bottom: 0.3rem; }
.statement .speaker strong { font-size: 0.95rem; }
.statement .speaker .label { color: var(--muted); font-size: 0.85rem; }
.statement .text { white-space: pre-wrap; margin: 0; }
.statement .meta { display: flex; gap: 0.4rem; align-items: center; flex-wrap: wrap; margin-top: 0.4rem; }
.statement.flagged { background: linear-gradient(90deg, var(--red-soft), transparent 40%); border-radius: 8px; padding-left: 0.5rem; margin-left: -0.5rem; }
.statement.unattributed .speaker strong { color: var(--warn); }
.statement .edit-panel { margin-top: 0.6rem; padding: 0.75rem; background: var(--surface-2); border-radius: 8px; border: 1px solid var(--border); }
.statement .edit-panel textarea { min-height: 5rem; }
.speaker-row { display: flex; gap: 0.5rem; align-items: center; padding: 0.4rem 0; border-bottom: 1px solid var(--border); font-size: 0.9rem; flex-wrap: wrap; }
.speaker-row:last-child { border-bottom: 0; }
.speaker-row .name { font-weight: 600; flex: 1 1 8rem; }
.speaker-row select { width: auto; flex: 1 1 10rem; font-size: 0.85rem; padding: 0.3rem 0.5rem; }
.speaker-row .count { color: var(--muted); font-size: 0.8rem; }
.preview { max-height: 22rem; overflow: auto; border: 1px solid var(--border); border-radius: 8px; padding: 0.5rem 0.75rem; background: var(--surface-2); font-size: 0.88rem; }
.preview .statement { padding: 0.5rem 0; }
.profile-head { display: flex; gap: 1.5rem; align-items: flex-start; flex-wrap: wrap; }
.profile-head .avatar { width: 64px; height: 64px; border-radius: 50%; background: var(--navy); color: #fff; display: grid; place-items: center; font-weight: 800; font-size: 1.4rem; flex: 0 0 auto; }
.profile-head dl { display: grid; grid-template-columns: auto 1fr; gap: 0.2rem 1rem; margin: 0.5rem 0 0; font-size: 0.9rem; }
.profile-head dt { color: var(--muted); font-weight: 600; }
.profile-head dd { margin: 0; }
.quote { border-left: 3px solid var(--red); padding-left: 0.8rem; margin: 0.5rem 0; white-space: pre-wrap; }
.tag-list { display: flex; gap: 0.35rem; flex-wrap: wrap; }
.tag-list button { border-radius: 999px; }
.dropzone { border: 2px dashed var(--border); border-radius: 10px; padding: 1rem; text-align: center; color: var(--muted); font-size: 0.9rem; }

/* Login -------------------------------------------------------------------- */
.login-page { min-height: 100vh; display: grid; place-items: center; padding: 1.5rem; background: radial-gradient(1200px 600px at 10% -10%, rgba(47, 91, 214, 0.14), transparent 60%), radial-gradient(900px 500px at 100% 100%, rgba(47, 91, 214, 0.08), transparent 60%), var(--bg); }
.login-card { width: 100%; max-width: 400px; background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 2rem; box-shadow: var(--shadow); }
.login-card .logo { display: flex; justify-content: center; margin-bottom: 1.25rem; }
.login-card .logo img { height: 52px; border-radius: 12px; }
.login-card h1 { text-align: center; font-size: 1.3rem; margin-bottom: 0.25rem; }
.login-card .sub { text-align: center; color: var(--muted); font-size: 0.9rem; margin-bottom: 1.5rem; }
.login-card button.primary { width: 100%; justify-content: center; padding: 0.7rem; margin-top: 0.5rem; }
.login-card .foot { margin-top: 1.25rem; text-align: center; font-size: 0.8rem; color: var(--muted); }
