:root {
  --bg: #f3f5f8;
  --surface: #ffffff;
  --border: #dde2ea;
  --text: #1c2430;
  --muted: #5d6b7e;
  --primary: #123c73;
  --primary-hover: #0d2f5c;
  --primary-soft: #e6eef9;
  --success: #17803d;
  --success-soft: #e3f4e8;
  --warning: #a15c00;
  --warning-soft: #fdf1dc;
  --danger: #b42318;
  --danger-soft: #fdecea;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.08);
  font-family: 'Segoe UI', system-ui, -apple-system, Roboto, Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); font-size: 15px; line-height: 1.5; }
a { color: var(--primary); }
h1, h2, h3 { line-height: 1.25; margin: 0 0 0.5em; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.2rem; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }

/* ---------- Top bar ---------- */
.topbar {
  background: var(--primary);
  color: #fff;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 24px;
  height: 56px;
}
.topbar .brand { font-weight: 600; font-size: 1.05rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .brand span { opacity: 0.75; font-weight: 400; }
.topbar nav { margin-left: auto; display: flex; align-items: center; gap: 6px; }
.topbar nav a, .topbar nav button {
  color: #fff; text-decoration: none; background: none; border: 0; font: inherit;
  padding: 6px 10px; border-radius: 6px; cursor: pointer; opacity: 0.9;
}
.topbar nav a:hover, .topbar nav button:hover, .topbar nav a.active { background: rgba(255,255,255,0.14); opacity: 1; }
.topbar .who { opacity: 0.8; font-size: 0.9rem; margin-right: 6px; }

.container { max-width: 1000px; margin: 0 auto; padding: 28px 20px 60px; }
.container.wide { max-width: 1320px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
}
.card + .card { margin-top: 20px; }

/* ---------- Forms ---------- */
label { display: block; font-weight: 600; font-size: 0.9rem; margin-bottom: 6px; }
.field { margin-bottom: 16px; }
.field .hint { font-weight: 400; color: var(--muted); font-size: 0.82rem; margin-top: 4px; }
input[type=text], input[type=email], input[type=number], input[type=date], input[type=url], select, textarea {
  width: 100%;
  font: inherit;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
}
textarea { min-height: 110px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: -1px; border-color: var(--primary); }
.check { display: flex; gap: 10px; align-items: flex-start; font-weight: 400; cursor: pointer; }
.check input { margin-top: 4px; width: 18px; height: 18px; flex: none; accent-color: var(--primary); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font: inherit; font-weight: 600; font-size: 0.92rem;
  padding: 9px 16px; border-radius: 8px; border: 1px solid transparent;
  background: var(--primary); color: #fff; cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover { background: var(--primary-hover); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.secondary { background: #fff; color: var(--text); border-color: var(--border); }
.btn.secondary:hover { background: #f5f7fa; }
.btn.danger { background: var(--danger); }
.btn.link { background: none; color: var(--primary); padding: 0; border: 0; font-weight: 500; }
.btn.small { padding: 6px 11px; font-size: 0.85rem; }
.btn.block { width: 100%; }
.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; }
.grow { flex: 1; }

.alert { padding: 10px 14px; border-radius: 8px; font-size: 0.92rem; margin-bottom: 16px; }
.alert.error { background: var(--danger-soft); color: var(--danger); }
.alert.success { background: var(--success-soft); color: var(--success); }
.alert.info { background: var(--primary-soft); color: var(--primary); }

/* ---------- Login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login-card { width: 100%; max-width: 400px; }
.login-card .logo { font-weight: 700; color: var(--primary); font-size: 1.1rem; margin-bottom: 18px; }
.code-input { font-size: 1.6rem !important; letter-spacing: 0.5em; text-align: center; font-variant-numeric: tabular-nums; }

/* ---------- Player ---------- */
.player {
  position: relative; background: #000; border-radius: var(--radius); overflow: hidden;
  aspect-ratio: 16 / 9; user-select: none;
}
.player video { width: 100%; height: 100%; display: block; background: #000; }
.player:fullscreen { border-radius: 0; aspect-ratio: auto; }
.player .big-play {
  position: absolute; inset: 0; margin: auto; width: 76px; height: 76px; border-radius: 50%;
  border: 0; background: rgba(18, 60, 115, 0.9); color: #fff; cursor: pointer; display: grid; place-items: center;
}
.player .big-play svg { width: 34px; height: 34px; margin-left: 4px; }
.player .toast {
  position: absolute; top: 14px; left: 50%; transform: translateX(-50%);
  background: rgba(0,0,0,0.78); color: #fff; padding: 7px 14px; border-radius: 6px; font-size: 0.88rem;
  opacity: 0; transition: opacity 0.2s; pointer-events: none;
}
.player .toast.show { opacity: 1; }
.controls {
  position: absolute; left: 0; right: 0; bottom: 0;
  padding: 18px 12px 8px; background: linear-gradient(transparent, rgba(0,0,0,0.75));
  color: #fff; transition: opacity 0.25s;
}
.player.idle.playing .controls { opacity: 0; }
.player.idle.playing { cursor: none; }
.controls .bar-row { display: flex; align-items: center; gap: 4px; margin-top: 6px; }
.controls button {
  background: none; border: 0; color: #fff; width: 38px; height: 38px; border-radius: 6px;
  display: grid; place-items: center; cursor: pointer; flex: none;
}
.controls button:hover { background: rgba(255,255,255,0.15); }
.controls svg { width: 22px; height: 22px; fill: currentColor; }
.controls .time { font-size: 0.85rem; font-variant-numeric: tabular-nums; margin: 0 8px; white-space: nowrap; }
.controls .spacer { flex: 1; }
.controls input[type=range] { width: 80px; accent-color: #fff; }
.track { position: relative; height: 16px; cursor: pointer; display: flex; align-items: center; touch-action: none; }
.track .rail { position: absolute; left: 0; right: 0; height: 5px; border-radius: 3px; background: rgba(255,255,255,0.25); overflow: hidden; }
.track .watched { position: absolute; left: 0; top: 0; bottom: 0; background: rgba(255,255,255,0.45); }
.track .played { position: absolute; left: 0; top: 0; bottom: 0; background: #4d9bff; }
.track .thumb { position: absolute; width: 13px; height: 13px; border-radius: 50%; background: #fff; transform: translateX(-50%); box-shadow: 0 0 3px rgba(0,0,0,0.5); }

.progress-line { display: flex; align-items: center; gap: 12px; margin-top: 14px; }
.meter { flex: 1; height: 8px; background: #e4e8ee; border-radius: 4px; overflow: hidden; }
.meter > div { height: 100%; background: var(--primary); border-radius: 4px; transition: width 0.4s; }
.meter.done > div { background: var(--success); }

.pill { display: inline-block; font-size: 0.78rem; font-weight: 600; padding: 2px 9px; border-radius: 999px; white-space: nowrap; }
.pill.completed { background: var(--success-soft); color: var(--success); }
.pill.needs_ack { background: var(--primary-soft); color: var(--primary); }
.pill.in_progress { background: var(--warning-soft); color: var(--warning); }
.pill.not_started { background: #eef0f3; color: var(--muted); }
.pill.inactive { background: #eef0f3; color: var(--muted); }
.pill.admin { background: #ede7fb; color: #5b34b0; }

.ack-list { display: grid; gap: 12px; margin: 16px 0 20px; }
.ack-list .check { padding: 12px 14px; border: 1px solid var(--border); border-radius: 8px; }

.done-banner { display: flex; gap: 16px; align-items: center; }
.done-banner .icon { width: 48px; height: 48px; border-radius: 50%; background: var(--success-soft); color: var(--success); display: grid; place-items: center; flex: none; }
.done-banner .icon svg { width: 26px; height: 26px; fill: currentColor; }

/* ---------- Admin ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 14px; margin-bottom: 20px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); cursor: pointer; }
.stat:hover { border-color: var(--primary); }
.stat .label { color: var(--muted); font-size: 0.85rem; }
.stat .value { font-size: 1.7rem; font-weight: 700; margin-top: 2px; }
.stat .sub { font-size: 0.8rem; color: var(--muted); }

.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 14px; }
.toolbar input[type=text] { max-width: 280px; }
.toolbar select { width: auto; }
.bulkbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 10px 14px; background: var(--primary-soft); border-radius: 8px; margin-bottom: 14px; }

.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { background: #f8f9fb; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.03em; color: var(--muted); white-space: nowrap; }
th.sortable { cursor: pointer; }
th.sortable:hover { color: var(--text); }
tbody tr:hover { background: #fafbfc; }
tbody tr:last-child td { border-bottom: 0; }
td .name { font-weight: 600; }
td .email { color: var(--muted); font-size: 0.85rem; }
td.pct { min-width: 150px; }
td.pct .meter { height: 6px; }
td.pct .row { gap: 8px; flex-wrap: nowrap; }
td.pct .num { width: 38px; text-align: right; font-variant-numeric: tabular-nums; font-size: 0.85rem; }
td.actions { white-space: nowrap; text-align: right; }
tr.inactive td { opacity: 0.55; }
.empty { padding: 40px; text-align: center; color: var(--muted); }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 20px; }
.tabs button { background: none; border: 0; font: inherit; padding: 10px 16px; cursor: pointer; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs button.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 20px; }
@media (max-width: 720px) { .grid-2 { grid-template-columns: 1fr; } .topbar { padding: 0 12px; } .topbar .who { display: none; } }

dialog { border: 0; border-radius: var(--radius); padding: 0; width: min(520px, calc(100vw - 32px)); box-shadow: 0 20px 50px rgba(0,0,0,0.25); }
dialog::backdrop { background: rgba(16, 24, 40, 0.45); }
dialog form { padding: 24px; }
dialog .actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 8px; }

pre.preview { background: #f8f9fb; border: 1px solid var(--border); border-radius: 8px; padding: 12px; max-height: 260px; overflow: auto; font-size: 0.82rem; }
code { background: #eef1f5; padding: 1px 5px; border-radius: 4px; font-size: 0.85em; }

#flash { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 50; min-width: 280px; text-align: center; box-shadow: var(--shadow); }

/* ---------- Course list / campaign list ---------- */
.course-list { display: grid; gap: 14px; }
.course-list .card + .card { margin-top: 0; }
.card.course { display: flex; align-items: center; gap: 20px; flex-wrap: wrap; }
.card.course .progress-line { max-width: 420px; }
.pill.draft { background: #eef0f3; color: var(--muted); }
.pill.active { background: var(--success-soft); color: var(--success); }
.pill.archived { background: #eef0f3; color: var(--muted); }
.pill.audience { background: var(--primary-soft); color: var(--primary); }
.pill.manager { background: #fdf1dc; color: var(--warning); }
.pill.employee { background: #eef0f3; color: var(--muted); }
.crumb { margin: 0 0 14px; font-size: 0.9rem; }
.campaign-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.campaign-head h1 { margin: 0; }
.subtabs { display: flex; gap: 6px; margin-bottom: 18px; }
.subtabs button { font: inherit; border: 1px solid var(--border); background: #fff; padding: 6px 14px; border-radius: 999px; cursor: pointer; color: var(--muted); }
.subtabs button.active { background: var(--primary); border-color: var(--primary); color: #fff; }
