:root {
  --primary: #149947;
  --primary-dark: #0b4a3e;
  --accent: #b8d336;
  --ink: #17251f;
  --muted: #64736c;
  --bg: #f4f7f4;
  --surface: #ffffff;
  --line: #dbe5de;
  --danger: #c62828;
  --warning: #a46a00;
  --info: #1b5fa7;
  --shadow: 0 12px 30px rgba(14, 40, 28, 0.08);
  --radius: 8px;
  font-family: "Segoe UI", Roboto, Arial, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: var(--bg);
}

a { color: var(--primary-dark); text-decoration: none; }
a:hover { text-decoration: underline; }

.site-header {
  width: min(1080px, calc(100% - 32px));
  margin: 0 auto;
  padding: 18px 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.brand, .admin-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 800;
  color: var(--primary-dark);
}

.brand img { height: 44px; width: auto; }
.site-nav { display: flex; align-items: center; gap: 14px; font-size: 14px; }
.site-nav form { margin: 0; }
.link-button {
  border: 0;
  background: transparent;
  color: var(--primary-dark);
  font: inherit;
  cursor: pointer;
  padding: 0;
}

.page {
  width: min(1080px, calc(100% - 32px));
  margin: 0 auto;
  padding: 10px 0 48px;
}

.page-narrow { width: min(720px, calc(100% - 32px)); }

.hero-panel, .panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.hero-panel {
  padding: 28px;
  margin-bottom: 18px;
  border-left: 5px solid var(--accent);
}

.panel { padding: 24px; margin-bottom: 18px; }
.center-panel { text-align: center; }

h1, h2, h3 { color: var(--primary-dark); margin-top: 0; line-height: 1.18; }
h1 { font-size: 30px; }
h2 { font-size: 20px; }

.eyebrow {
  margin: 0 0 8px;
  color: var(--primary);
  font-weight: 800;
  font-size: 12px;
  text-transform: uppercase;
}

.muted { color: var(--muted); }
.tiny-text { font-size: 12px; }

.form-stack { display: grid; gap: 14px; }
.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

label {
  display: grid;
  gap: 6px;
  font-weight: 700;
  font-size: 13px;
}

input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: var(--ink);
  padding: 11px 12px;
  font: inherit;
  font-size: 14px;
}

textarea { resize: vertical; line-height: 1.5; }
input:focus, select:focus, textarea:focus {
  outline: 2px solid rgba(20, 153, 71, 0.22);
  border-color: var(--primary);
}

.btn {
  display: inline-flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  border: 0;
  border-radius: var(--radius);
  background: var(--primary);
  color: #fff;
  min-height: 40px;
  padding: 10px 16px;
  font-weight: 800;
  font-size: 14px;
  cursor: pointer;
  text-decoration: none;
}

.btn:hover { background: var(--primary-dark); text-decoration: none; }
.btn.secondary { background: #e8eee9; color: var(--ink); }
.btn.secondary:hover { background: #d8e3da; }
.btn.danger, .danger-confirm { background: var(--danger); }
.btn.tiny { min-height: 30px; padding: 6px 10px; font-size: 12px; }
.btn-block { width: 100%; }

.alert {
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 14px;
  font-size: 14px;
  border: 1px solid transparent;
}
.alert-error { background: #fff1f1; color: var(--danger); border-color: #ffc9c9; }
.alert-success { background: #edf8f0; color: var(--primary-dark); border-color: #bde6c8; }

.empty-state {
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  padding: 18px;
  color: var(--muted);
  background: #fafcfb;
}

.ticket {
  display: grid;
  gap: 0;
  margin: 20px 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  text-align: left;
}
.ticket.compact { margin: 18px 0; }
.ticket div {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}
.ticket div:last-child { border-bottom: 0; }
.ticket span { color: var(--muted); }
.ticket strong { text-align: right; }

.countdown-box {
  display: grid;
  gap: 6px;
  place-items: center;
  padding: 18px;
  margin: 18px 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #f8fbf9;
}
.countdown-value {
  font-size: 34px;
  font-weight: 900;
  color: var(--primary-dark);
  font-variant-numeric: tabular-nums;
}
.countdown-label { color: var(--muted); font-size: 13px; }

.auth-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.auth-card { width: min(430px, 100%); }
.auth-logo { display: block; height: 78px; width: auto; margin: 0 auto 16px; }
.back-link { display: block; text-align: center; margin-top: 16px; font-size: 13px; }

.exam-shell { min-height: 100vh; background: var(--bg); }
.exam-topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 14px max(18px, calc((100vw - 860px) / 2));
}
.exam-topbar div:first-child { display: grid; gap: 3px; }
.exam-topbar span { color: var(--muted); font-size: 13px; }
.countdown-inline { text-align: right; }
.countdown-inline .countdown-value { display: block; font-size: 24px; }
.countdown-inline small { color: var(--muted); }

.exam-content {
  width: min(860px, calc(100% - 32px));
  margin: 0 auto;
  padding: 20px 0 76px;
}
.question-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px;
  margin-bottom: 16px;
  box-shadow: 0 6px 20px rgba(14, 40, 28, 0.05);
}
.question-meta {
  color: var(--muted);
  text-transform: uppercase;
  font-size: 12px;
  font-weight: 900;
  margin-bottom: 8px;
}
.question-text {
  line-height: 1.6;
  white-space: pre-wrap;
  margin-bottom: 14px;
}
.question-image {
  display: block;
  max-width: 100%;
  max-height: 440px;
  object-fit: contain;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  margin-bottom: 14px;
}
.option-row {
  display: flex;
  grid-template-columns: auto 1fr;
  align-items: flex-start;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 12px;
  margin-bottom: 8px;
  cursor: pointer;
  font-weight: 500;
}
.option-row:hover { background: #f8fbf9; }
.option-row input { width: auto; margin-top: 3px; }
.submit-bar {
  display: flex;
  justify-content: flex-end;
  padding: 10px 0;
}

.admin-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 250px minmax(0, 1fr);
}
.admin-sidebar {
  background: var(--primary-dark);
  color: #fff;
  padding: 18px 0;
}
.admin-brand {
  padding: 0 18px 18px;
  color: #fff;
  border-bottom: 1px solid rgba(255,255,255,0.16);
}
.admin-brand img { height: 42px; background: #fff; border-radius: 6px; padding: 3px; }
.admin-sidebar nav { display: grid; padding: 12px 0; }
.admin-sidebar a {
  color: #eaf4ed;
  padding: 11px 18px;
  text-decoration: none;
  border-left: 3px solid transparent;
}
.admin-sidebar a:hover { background: rgba(255,255,255,0.08); border-left-color: var(--accent); }
.sidebar-logout { padding: 10px 18px; margin: 0; }
.sidebar-logout button {
  width: 100%;
  border: 1px solid rgba(255,255,255,0.28);
  background: transparent;
  color: #fff;
  border-radius: var(--radius);
  padding: 10px;
  cursor: pointer;
}

.admin-main { padding: 26px; min-width: 0; }
.admin-heading {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 14px;
  margin-bottom: 16px;
}
.admin-heading h1 { margin-bottom: 4px; }
.inline-filter { min-width: 220px; }

.stat-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(140px, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}
.stat-card span { display: block; color: var(--muted); font-size: 13px; }
.stat-card strong { display: block; font-size: 28px; margin-top: 6px; color: var(--primary-dark); }
.alert-stat strong { color: var(--warning); }
.action-row { display: flex; gap: 10px; flex-wrap: wrap; }

.table-wrap { overflow-x: auto; }
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}
th, td {
  padding: 10px 11px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}
th {
  color: var(--muted);
  background: #f3f6f4;
  font-weight: 900;
}
.table-actions { display: flex; align-items: center; gap: 8px; }
.table-actions form { margin: 0; }

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 3px 9px;
  border-radius: 999px;
  background: #e9eef0;
  color: var(--ink);
  font-size: 12px;
  font-weight: 800;
}
.badge.success { background: #e3f6e9; color: var(--primary-dark); }

.form-actions {
  display: flex;
  align-items: end;
  gap: 10px;
  flex-wrap: wrap;
}
.pg-fields { display: block; }
.score-summary {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}
.score-summary div {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
}
.score-summary span { display: block; color: var(--muted); font-size: 13px; }
.score-summary strong { display: block; font-size: 24px; color: var(--primary-dark); }
.essay-answer {
  min-height: 84px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  background: #f9fbfa;
  white-space: pre-wrap;
  font-weight: 500;
}

.footer {
  width: min(1080px, calc(100% - 32px));
  margin: 0 auto;
  padding: 8px 0 28px;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}

@media (max-width: 900px) {
  .admin-shell { grid-template-columns: 1fr; }
  .admin-sidebar {
    position: static;
    display: block;
    padding-bottom: 8px;
  }
  .admin-sidebar nav {
    grid-auto-flow: column;
    grid-auto-columns: max-content;
    overflow-x: auto;
  }
  .sidebar-logout { max-width: 180px; }
  .stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 640px) {
  .site-header, .admin-heading, .exam-topbar {
    flex-direction: column;
    align-items: stretch;
  }
  .site-nav { justify-content: space-between; }
  .form-grid, .score-summary, .stat-grid { grid-template-columns: 1fr; }
  .panel, .hero-panel, .question-card { padding: 18px; }
  h1 { font-size: 24px; }
  .ticket div { display: grid; }
  .ticket strong { text-align: left; }
  .countdown-value { font-size: 28px; }
  .submit-bar { justify-content: stretch; }
  .submit-bar .btn { width: 100%; }
}
