/* ---------------------------------------------------------------
   TAPS Exam Workflow - theme tokens
   Light (default): moss green on off-white.  Dark: charcoal-green.
   --------------------------------------------------------------- */
:root {
  --bg: #f4f7f5;
  --panel: #ffffff;
  --panel-2: #f3f8f5;
  --ink: #17251f;
  --muted: #5f6f67;
  --line: #cfdcd5;
  --line-strong: #a9c2b6;
  --brand: #047857;
  --brand-hover: #065f46;
  --brand-ink: #ffffff;
  --brand-soft: #ecfdf5;
  --danger: #a03b2c;
  --danger-soft: #f7e6e2;
  --ok: #047857;
  --ok-soft: #d7f2e5;
  --warn: #9a6b1f;
  --warn-soft: #f7ecd8;
  --info: #3c6079;
  --info-soft: #e4edf3;
  --purple: #5c4d7d;
  --purple-soft: #ebe6f3;
  --shadow: 0 1px 2px rgba(6, 60, 44, .08), 0 8px 20px rgba(6, 60, 44, .07);
  --radius: 10px;
  --speed: 180ms;
}
:root[data-theme="dark"] {
  --bg: #0f1714;
  --panel: #16211d;
  --panel-2: #1b2823;
  --ink: #e6efea;
  --muted: #9bb0a7;
  --line: #2c3f37;
  --line-strong: #3f5a4f;
  --brand: #34d399;
  --brand-hover: #6ee7b7;
  --brand-ink: #06241a;
  --brand-soft: #13332a;
  --danger: #e08d7c;
  --danger-soft: #3a2621;
  --ok: #34d399;
  --ok-soft: #13332a;
  --warn: #dcb26a;
  --warn-soft: #362c1a;
  --info: #8fb4cd;
  --info-soft: #1e2b33;
  --purple: #b3a3d4;
  --purple-soft: #2a2437;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 6px 18px rgba(0, 0, 0, .3);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font: 15px/1.5 "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }

/* ---- top bar ---- */
.topbar {
  display: flex; align-items: center; gap: 16px; padding: 10px 18px;
  background: var(--brand); color: var(--brand-ink); flex-wrap: wrap;
  box-shadow: var(--shadow); position: sticky; top: 0; z-index: 30;
}
.brand { font-weight: 600; display: flex; gap: 8px; align-items: center; }
.badge { background: rgba(255,255,255,.2); padding: 2px 8px; border-radius: 5px; font-size: 13px; letter-spacing: .04em; }
.nav { display: flex; gap: 4px; flex: 1; flex-wrap: wrap; }
.nav a {
  color: var(--brand-ink); text-decoration: none; padding: 6px 11px; border-radius: 7px;
  opacity: .85; transition: background var(--speed) ease, opacity var(--speed) ease;
}
.nav a.active, .nav a:hover { background: rgba(255,255,255,.2); opacity: 1; }
.who { display: flex; gap: 8px; align-items: center; font-size: 14px; }

/* In dark mode a full moss bar is too loud - use a panel bar with a green edge. */
:root[data-theme="dark"] .topbar {
  background: var(--panel-2); color: var(--ink); border-bottom: 2px solid var(--brand);
}
:root[data-theme="dark"] .badge { background: var(--brand-soft); color: var(--brand); }
:root[data-theme="dark"] .nav a.active { background: var(--brand-soft); color: var(--brand); }
:root[data-theme="dark"] .nav a:hover { background: var(--brand-soft); }
:root[data-theme="dark"] .theme-switch { background: var(--brand-soft); }
:root[data-theme="dark"] .theme-switch button { color: var(--muted); }
:root[data-theme="dark"] .theme-switch button.on { background: var(--brand); color: var(--brand-ink); }
:root[data-theme="dark"] .btn.ghost { color: var(--ink); border-color: var(--line); }
:root[data-theme="dark"] .btn.ghost:hover:not(:disabled) { background: var(--brand-soft); border-color: var(--brand); }

/* ---- layout ---- */
.view { max-width: 1200px; margin: 0 auto; padding: 22px 16px 70px; }
h1 { font-size: 23px; margin: 0 0 16px; letter-spacing: -.01em; }
h2 { font-size: 17px; margin: 0 0 12px; }
.panel {
  background: var(--panel); border: 2px solid var(--line); border-radius: var(--radius);
  padding: 18px; margin-bottom: 18px; box-shadow: var(--shadow);
  animation: rise var(--speed) ease both;
}
.panel > h2:first-child {
  margin: -18px -18px 14px; padding: 11px 18px;
  background: var(--panel-2); border-bottom: 2px solid var(--line);
  border-radius: 8px 8px 0 0;
}
.panel.accent { border-color: var(--brand); }
.panel.accent > h2:first-child { background: var(--brand-soft); border-bottom-color: var(--brand); color: var(--brand); }
@keyframes rise { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.login-wrap { max-width: 390px; margin: 8vh auto; }
.muted { color: var(--muted); }
.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; }
.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 13px; min-width: 160px; flex: 1; }
.field label { font-size: 13px; color: var(--muted); font-weight: 600; }
.field.check { flex-direction: row; align-items: center; gap: 8px; flex: 0; min-width: 0; }

/* ---- controls ---- */
input, select, textarea {
  font: inherit; padding: 9px 11px; border: 1.5px solid var(--line); border-radius: 7px;
  background: var(--panel); color: var(--ink); width: 100%;
  transition: border-color var(--speed) ease, box-shadow var(--speed) ease;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-soft);
}
.field.check input { width: auto; }
input[type=file] { padding: 6px; background: var(--panel-2); }
.btn {
  font: inherit; border: 1px solid var(--brand); background: var(--brand); color: var(--brand-ink);
  padding: 9px 15px; border-radius: 7px; cursor: pointer; text-decoration: none; display: inline-block;
  transition: background var(--speed) ease, transform var(--speed) ease, opacity var(--speed) ease;
}
.btn:hover:not(:disabled) { background: var(--brand-hover); border-color: var(--brand-hover); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: default; }
.btn.ghost { background: transparent; color: inherit; border-color: currentColor; }
.btn.ghost:hover:not(:disabled) { background: rgba(255,255,255,.18); }
.btn.light { background: var(--panel); color: var(--brand); border-color: var(--line); }
.btn.light:hover:not(:disabled) { background: var(--brand-soft); border-color: var(--brand); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.danger:hover:not(:disabled) { filter: brightness(1.08); background: var(--danger); }
.btn.small { padding: 5px 11px; font-size: 13px; }

/* password reveal */
.pw-wrap { position: relative; display: block; }
.pw-wrap input { padding-right: 42px; }
.pw-toggle {
  position: absolute; right: 4px; top: 50%; transform: translateY(-50%);
  background: none; border: 0; cursor: pointer; padding: 6px; line-height: 0;
  color: var(--muted); border-radius: 6px;
}
.pw-toggle:hover { color: var(--brand); background: var(--brand-soft); }
.pw-toggle svg { width: 19px; height: 19px; display: block; }

/* ---- tabs, tables ---- */
.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 16px; }
.tabs a {
  padding: 7px 13px; border-radius: 7px; text-decoration: none; color: var(--ink);
  background: var(--panel); border: 2px solid var(--line); transition: all var(--speed) ease;
}
.tabs a:hover { border-color: var(--brand); color: var(--brand); }
.tabs a.active { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 9px 11px; border-bottom: 1px solid var(--line); vertical-align: top; }
thead th { border-bottom: 2px solid var(--line-strong); }
th { color: var(--muted); font-weight: 600; font-size: 13px; background: var(--panel-2); }
tbody tr { transition: background var(--speed) ease; }
tbody tr:hover { background: var(--panel-2); }
a { color: var(--brand); }

/* ---- chips ---- */
.pill { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; background: var(--panel-2); border: 1px solid var(--line); }
.pill.off { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.pill.on { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.chip { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.s-not_submitted { background: var(--panel-2); color: var(--muted); border: 1px solid var(--line); }
.s-submitted, .s-resubmitted { background: var(--info-soft); color: var(--info); }
.s-under_review { background: var(--warn-soft); color: var(--warn); }
.s-major_revision { background: var(--danger-soft); color: var(--danger); }
.s-minor_revision { background: var(--warn-soft); color: var(--warn); }
.s-final_pending, .s-final_submitted { background: var(--purple-soft); color: var(--purple); }
.s-needs_correction { background: var(--danger-soft); color: var(--danger); }
.s-ready_for_release { background: var(--ok-soft); color: var(--ok); }
.s-released { background: var(--ok); color: #fff; }
.late { color: var(--danger); font-size: 12px; font-weight: 700; letter-spacing: .03em; }
.legend { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.error { color: var(--danger); margin: 8px 0; min-height: 1em; font-size: 14px; }

/* ---- dashboard matrix ---- */
.matrix td, .matrix th { white-space: nowrap; }
.matrix th.rowhead { background: var(--panel-2); font-size: 14px; color: var(--ink); }
.cell {
  display: block; text-decoration: none; color: inherit; padding: 9px 10px; border-radius: 8px;
  background: var(--panel-2); min-width: 142px; border: 2px solid var(--line);
  transition: border-color var(--speed) ease, transform var(--speed) ease, box-shadow var(--speed) ease;
}
.cell:hover { border-color: var(--brand); transform: translateY(-1px); box-shadow: var(--shadow); }
.matrix td { border-right: 1px solid var(--line); }
.matrix td:last-child, .matrix th:last-child { border-right: 0; }
.matrix th.rowhead { border-right: 2px solid var(--line-strong); }
.matrix tbody tr { border-bottom: 1px solid var(--line); }

/* paper / TOS badges inside a dashboard cell */
.fbadges { display: flex; gap: 4px; margin: 6px 0 2px; }
.fbadge { font-size: 10.5px; font-weight: 700; letter-spacing: .03em; padding: 1px 6px; border-radius: 4px; border: 1px solid var(--line-strong); }
.fbadge.in { background: var(--brand-soft); color: var(--brand); border-color: var(--brand); }
.fbadge.out { background: transparent; color: var(--muted); border-style: dashed; }
.cell .who2 { display: block; font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; max-width: 150px; }
.cell.empty { background: transparent; color: var(--muted); }

/* ---- stage progress ---- */
.stages { display: flex; gap: 4px; flex-wrap: wrap; margin: 4px 0 14px; }
.stage {
  flex: 1; min-width: 92px; font-size: 11.5px; color: var(--muted); text-align: center;
  padding-top: 20px; position: relative;
}
.stage::before {
  content: ""; position: absolute; top: 6px; left: 0; right: 0; height: 6px;
  background: var(--line); border-radius: 4px;
}
.stage.done::before { background: var(--brand); }
.stage.now::before { background: var(--brand); animation: pulse 1.6s ease-in-out infinite; }
.stage.alert::before { background: var(--danger); }
.stage.done, .stage.now { color: var(--ink); font-weight: 600; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .45; } }

/* ---- upload progress ---- */
.progress { height: 8px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 999px; overflow: hidden; margin: 8px 0 4px; }
.progress span { display: block; height: 100%; width: 0; background: var(--brand); transition: width 120ms linear; }
.progress-row { display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--muted); width: 100%; }
.spinner {
  width: 14px; height: 14px; border: 2px solid currentColor; border-right-color: transparent;
  border-radius: 50%; display: inline-block; vertical-align: -2px; margin-right: 6px;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- skeletons ---- */
.skeleton { border-radius: 8px; background: linear-gradient(90deg, var(--panel-2) 25%, var(--line) 50%, var(--panel-2) 75%); background-size: 400% 100%; animation: shimmer 1.4s ease infinite; }
.skeleton.line { height: 13px; margin-bottom: 10px; }
.skeleton.line.short { width: 42%; }
.skeleton.block { height: 96px; }
@keyframes shimmer { from { background-position: 100% 0; } to { background-position: 0 0; } }

/* ---- bell ---- */
.bell { position: relative; }
.bell .count {
  position: absolute; top: -7px; right: -7px; background: var(--danger); color: #fff;
  border-radius: 999px; font-size: 11px; padding: 1px 6px; font-weight: 700;
}
.notif-list {
  position: absolute; right: 12px; top: 54px; width: min(390px, 92vw); background: var(--panel);
  color: var(--ink); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); z-index: 40; max-height: 70vh; overflow: auto;
  animation: rise var(--speed) ease both;
}
.notif-list .item { padding: 11px 13px; border-bottom: 1px solid var(--line); font-size: 14px; display: block; text-decoration: none; color: inherit; }
.notif-list .item.unread { background: var(--brand-soft); }
.notif-list .item:hover { background: var(--panel-2); }
.notif-head { display: flex; justify-content: space-between; align-items: center; padding: 9px 13px; border-bottom: 1px solid var(--line); }

/* ---- exam detail ---- */
.kv { display: grid; grid-template-columns: 160px 1fr; gap: 8px 14px; font-size: 14px; }
.kv dt { color: var(--muted); font-weight: 600; }
.kv dd { margin: 0; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.entry { border-left: 3px solid var(--line); padding: 7px 0 7px 13px; }
.entry.major { border-color: var(--danger); }
.entry.minor { border-color: var(--warn); }
.entry.ok { border-color: var(--ok); }
.entry .meta { font-size: 12px; color: var(--muted); }
.entry .comment { white-space: pre-wrap; margin-top: 5px; }
.back { display: inline-block; margin-bottom: 10px; text-decoration: none; color: var(--brand); }
.back:hover { text-decoration: underline; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ---- final materials ---- */
.slots { display: grid; grid-template-columns: repeat(auto-fit, minmax(290px, 1fr)); gap: 12px; }
.slot { border: 2px solid var(--line); border-radius: 9px; padding: 14px; background: var(--panel-2); }
.slot.ready { border-color: var(--brand); }
.slot-head { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 6px; }
.slot .meta { font-size: 12px; color: var(--muted); margin-bottom: 8px; word-break: break-word; }
.slot form { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 9px; }
.slot input[type=file] { width: auto; flex: 1; min-width: 150px; font-size: 13px; }
.slot details { margin-top: 8px; font-size: 13px; }
.slot .error { font-size: 13px; width: 100%; }
.code { font-family: Consolas, "Courier New", monospace; background: var(--brand-soft); color: var(--ink); padding: 3px 7px; border-radius: 5px; font-size: 13px; }
.small-cell { font-size: 12px; color: var(--muted); max-width: 320px; word-break: break-word; }

/* ---- modal ---- */
.modal-back {
  position: fixed; inset: 0; background: rgba(9, 30, 22, .55); z-index: 70;
  display: flex; align-items: center; justify-content: center; padding: 20px;
  animation: fade var(--speed) ease both;
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.modal {
  background: var(--panel); color: var(--ink); border: 2px solid var(--line);
  border-radius: 12px; width: min(460px, 100%); box-shadow: 0 20px 50px rgba(0, 0, 0, .3);
  animation: pop var(--speed) ease both;
}
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.98); } to { opacity: 1; transform: none; } }
.modal h2 {
  margin: 0; padding: 14px 18px; font-size: 17px;
  background: var(--panel-2); border-bottom: 2px solid var(--line); border-radius: 10px 10px 0 0;
}
.modal-body { padding: 16px 18px; }
.modal-body p { margin: 0; line-height: 1.55; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; padding: 0 18px 16px; }

/* ---- toasts (stacked) ---- */
.toast-stack {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  z-index: 60; display: flex; flex-direction: column; gap: 8px; align-items: center; max-width: 90vw;
}
.toast-item {
  background: var(--ink); color: var(--bg); padding: 11px 17px; border-radius: 8px;
  box-shadow: var(--shadow); animation: rise var(--speed) ease both;
}
.toast-item.bad { background: var(--danger); color: #fff; }

/* ---- theme switch ---- */
.theme-switch { display: flex; align-items: center; gap: 2px; background: rgba(255,255,255,.16); border-radius: 7px; padding: 2px; }
.theme-switch button {
  background: none; border: 0; color: var(--brand-ink); cursor: pointer; padding: 4px 7px;
  border-radius: 5px; font: inherit; font-size: 12px; opacity: .8; line-height: 1;
}
.theme-switch button.on { background: rgba(255,255,255,.28); opacity: 1; font-weight: 600; }

@media (max-width: 720px) {
  .who #who-name { display: none; }
  .field { min-width: 100%; }
  .kv { grid-template-columns: 1fr; gap: 2px 0; }
  .kv dd { margin-bottom: 8px; }
  .view { padding: 16px 12px 60px; }
}

/* ---- accessibility: honour the OS "reduce motion" setting ---- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; }
}

/* ---- printing ---- */
@media print {
  .topbar, .toast, .notif-list, .btn, form, .back, .tabs { display: none !important; }
  body { background: #fff; color: #000; }
  .panel { box-shadow: none; border-color: #999; break-inside: avoid; animation: none; }
  .view { max-width: none; padding: 0; }
  a { color: #000; text-decoration: none; }
}

/* ---- dashboard analytics ---- */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 4px; }
.card { background: var(--panel-2); border: 2px solid var(--line); border-radius: 9px; padding: 15px 17px; }
.card-value { font-size: 26px; font-weight: 700; letter-spacing: -.02em; color: var(--brand); }
.card-label { font-size: 13px; color: var(--muted); margin-top: 2px; }
.statusbar { width: 100%; height: 14px; display: block; margin-bottom: 4px; }
.statusbar rect { cursor: pointer; transition: opacity var(--speed) ease; }
.statusbar rect:hover { opacity: .75; }
.legend .chip { cursor: pointer; border: 0; font: inherit; font-size: 12px; font-weight: 600; }
.s-fill-not_submitted { fill: var(--line); }
.s-fill-submitted, .s-fill-resubmitted { fill: var(--info); }
.s-fill-under_review { fill: var(--warn); }
.s-fill-major_revision, .s-fill-needs_correction { fill: var(--danger); }
.s-fill-minor_revision { fill: var(--warn); opacity: .7; }
.s-fill-final_pending, .s-fill-final_submitted { fill: var(--purple); }
.s-fill-ready_for_release { fill: var(--ok); }
.s-fill-released { fill: var(--brand); }
.groupchart { width: 100%; max-width: 620px; height: auto; }
.groupchart .lbl { font-size: 11px; fill: var(--muted); font-family: inherit; }
.groupchart .num { font-weight: 700; fill: var(--ink); }
.bar-on_time { fill: var(--ok); }
.bar-late { fill: var(--danger); }
.bar-not_submitted { fill: var(--line); }


/* ---- checkbox as its own bordered control (never overflows a field row) ---- */
.toggle {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  border: 2px solid var(--line); border-radius: 8px; padding: 10px 13px;
  background: var(--panel-2); margin-bottom: 13px; cursor: pointer; width: 100%;
}
.toggle:hover { border-color: var(--brand); }
.toggle input { width: 18px; height: 18px; accent-color: var(--brand); flex: none; }
.toggle > span:first-of-type { font-weight: 600; font-size: 14px; }
.toggle .muted { font-size: 13px; }

/* ---- dashboard matrix: centred subjects, frozen grade column and header ---- */
.matrix { border-collapse: separate; border-spacing: 0; }
.matrix th, .matrix td { text-align: center; }
.matrix th:first-child, .matrix th.rowhead { text-align: left; }
.matrix thead th {
  position: sticky; top: 0; z-index: 2; background: var(--panel-2);
}
.matrix th.rowhead {
  position: sticky; left: 0; z-index: 1; background: var(--panel);
  box-shadow: 1px 0 0 var(--line-strong);
}
.matrix thead th:first-child { z-index: 3; left: 0; }
.matrix .cell { margin: 0 auto; text-align: left; max-width: 190px; }
.table-wrap.matrix-wrap { max-height: 70vh; overflow: auto; }

.copy-line { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.notice {
  background: var(--warn-soft); color: var(--warn); border: 1.5px solid var(--warn);
  border-radius: 8px; padding: 9px 12px; font-size: 14px; margin: 0 0 14px;
}
