/* =====================================================================
   Koenig Pre Assessment Agent - blue gradient theme
   ===================================================================== */
:root {
  --blue-950: #061431;
  --blue-900: #0a1f44;
  --blue-800: #0f2f6b;
  --blue-700: #123c8f;
  --blue-600: #1a4fb3;
  --blue-500: #1f6feb;
  --blue-400: #3b82f6;
  --blue-300: #60a5fa;
  --sky: #38bdf8;
  --grad: linear-gradient(135deg, #0a1f44 0%, #1a4fb3 55%, #38bdf8 100%);
  --grad-btn: linear-gradient(135deg, #1f6feb 0%, #38bdf8 100%);
  --bg: #f2f6fc;
  --card: #ffffff;
  --text: #0f1b33;
  --muted: #5b6b86;
  --border: #dbe4f3;
  --success: #15803d;
  --danger: #dc2626;
  --warn: #d97706;
  --radius: 14px;
  --shadow: 0 10px 30px rgba(10, 31, 68, .10);
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: "Inter", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4 { margin: 0 0 .5rem; line-height: 1.25; color: var(--blue-900); }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1.02rem; }
p { margin: 0 0 1rem; }
a { color: var(--blue-500); text-decoration: none; }
a:hover { text-decoration: underline; }
ol, ul { padding-left: 1.3rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.center { text-align: center; }
.mt-1 { margin-top: .5rem; } .mt-2 { margin-top: 1rem; } .mt-3 { margin-top: 1.5rem; }
.mb-0 { margin-bottom: 0; } .mb-1 { margin-bottom: .5rem; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.flex { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  padding: .6rem 1.1rem; border-radius: 10px; border: 1px solid var(--border);
  font-weight: 600; font-size: .95rem; line-height: 1.2; cursor: pointer;
  background: #fff; color: var(--text); text-decoration: none; transition: all .15s ease;
  font-family: inherit;
}
.btn:hover { text-decoration: none; transform: translateY(-1px); box-shadow: 0 4px 14px rgba(10, 31, 68, .14); }
.btn-primary { background: var(--grad-btn); color: #fff; border-color: transparent; }
.btn-danger { color: var(--danger); border-color: #fecaca; }
.btn-danger:hover { background: #fef2f2; }
.btn-light { background: rgba(255, 255, 255, .16); color: #fff; border-color: rgba(255, 255, 255, .45); }
.btn-light:hover { background: rgba(255, 255, 255, .28); }
.btn-sm { padding: .35rem .7rem; font-size: .82rem; border-radius: 8px; }
.btn-lg { padding: .85rem 1.7rem; font-size: 1.05rem; border-radius: 12px; }
.btn-block { width: 100%; }
.btn[disabled] { opacity: .55; cursor: not-allowed; transform: none; box-shadow: none; }

/* ---------- Cards ---------- */
.card {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 1.5rem; border: 1px solid rgba(219, 228, 243, .7);
}
.card + .card { margin-top: 1.25rem; }
.card-title {
  font-size: 1.05rem; font-weight: 700; color: var(--blue-900); margin-bottom: 1rem;
  display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap;
}
.empty { color: var(--muted); text-align: center; padding: 1.5rem 0; }

/* ---------- Forms ---------- */
label.field { display: block; margin-bottom: .95rem; font-weight: 600; font-size: .9rem; color: var(--blue-900); }
label.field .hint { display: block; font-weight: 400; color: var(--muted); font-size: .8rem; margin-top: .25rem; }
input[type=text], input[type=password], input[type=number], select, textarea {
  width: 100%; padding: .65rem .8rem; border: 1px solid var(--border); border-radius: 10px;
  font: inherit; color: var(--text); background: #fff; margin-top: .35rem;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--blue-400); box-shadow: 0 0 0 3px rgba(59, 130, 246, .18);
}
textarea { min-height: 110px; resize: vertical; }
.check { display: flex; gap: .6rem; align-items: flex-start; font-weight: 500; cursor: pointer; }
.check input { margin-top: .3rem; flex-shrink: 0; }
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: .9rem; }
.form-actions { display: flex; gap: .6rem; flex-wrap: wrap; margin-top: .5rem; }
.inline-form { display: inline; }
.inline-form input[type=text], .inline-form input[type=password] { width: auto; margin: 0; padding: .35rem .6rem; border-radius: 8px; }

/* ---------- Alerts / badges ---------- */
.alert { padding: .8rem 1rem; border-radius: 10px; margin-bottom: 1rem; border: 1px solid; font-size: .93rem; }
.alert-success { background: #ecfdf5; border-color: #a7f3d0; color: #065f46; }
.alert-error, .alert-danger { background: #fef2f2; border-color: #fecaca; color: #991b1b; }
.alert-warning { background: #fffbeb; border-color: #fde68a; color: #92400e; }
.alert-info { background: #eff6ff; border-color: #bfdbfe; color: #1e3a8a; }
.alert strong { font-weight: 700; }
.badge { display: inline-block; padding: .2rem .6rem; border-radius: 999px; font-size: .74rem; font-weight: 700; letter-spacing: .02em; white-space: nowrap; }
.badge-blue { background: #dbeafe; color: #1e40af; }
.badge-green { background: #dcfce7; color: #166534; }
.badge-red { background: #fee2e2; color: #991b1b; }
.badge-amber { background: #fef3c7; color: #92400e; }
.badge-gray { background: #e5e7eb; color: #374151; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table.table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.table th {
  text-align: left; font-size: .72rem; text-transform: uppercase; letter-spacing: .06em;
  color: var(--muted); padding: .6rem .7rem; border-bottom: 2px solid var(--border); white-space: nowrap;
}
.table td { padding: .65rem .7rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tbody tr:hover td { background: #f7faff; }
.table.kv td:first-child { color: var(--muted); width: 45%; }
.actions { display: flex; gap: .4rem; flex-wrap: wrap; align-items: center; }

/* ---------- Brand ---------- */
.logo-mark {
  width: 40px; height: 40px; border-radius: 12px; background: var(--grad-btn); color: #fff;
  font-weight: 800; display: flex; align-items: center; justify-content: center; font-size: 1.2rem;
  box-shadow: 0 6px 16px rgba(31, 111, 235, .35); flex-shrink: 0;
}
.logo-mark.large { width: 66px; height: 66px; font-size: 2rem; border-radius: 18px; margin: 0 auto 1rem; }

/* ---------- Login ---------- */
.auth-body { background: var(--grad); background-attachment: fixed; }
.auth-wrap { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 1.5rem; }
.auth-card { width: 100%; max-width: 420px; background: #fff; border-radius: 22px; padding: 2.2rem 2rem; box-shadow: 0 25px 60px rgba(6, 20, 49, .45); }
.auth-brand { text-align: center; margin-bottom: 1.5rem; }
.auth-brand h1 { font-size: 1.35rem; }
.auth-brand p { color: var(--muted); margin: 0; }
.role-toggle { display: grid; grid-template-columns: 1fr 1fr; background: #eef3fb; border-radius: 12px; padding: 4px; margin-bottom: 1rem; }
.role-toggle label { text-align: center; padding: .55rem; border-radius: 9px; cursor: pointer; font-weight: 600; color: var(--muted); transition: all .15s; }
.role-toggle label.active { background: #fff; color: var(--blue-700); box-shadow: 0 2px 8px rgba(10, 31, 68, .14); }
.role-toggle input { display: none; }
.auth-foot { text-align: center; color: #fff; opacity: .85; margin-top: 1.2rem; font-size: .85rem; }

/* ---------- Admin layout ---------- */
.admin-shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 250px; flex-shrink: 0; background: var(--grad); color: #fff; padding: 1.5rem 1rem;
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh;
}
.sidebar-brand { display: flex; gap: .7rem; align-items: center; padding: .3rem .5rem 1.5rem; }
.brand-title { font-weight: 800; font-size: 1.1rem; line-height: 1.1; }
.brand-sub { font-size: .78rem; opacity: .85; }
.sidebar nav { display: flex; flex-direction: column; gap: .25rem; }
.sidebar nav a { color: #fff; padding: .65rem .9rem; border-radius: 10px; font-weight: 600; opacity: .85; }
.sidebar nav a:hover, .sidebar nav a.active { background: rgba(255, 255, 255, .17); opacity: 1; text-decoration: none; }
.sidebar-foot { margin-top: auto; padding: .5rem; font-size: .85rem; }
.sidebar-foot a { color: #fff; opacity: .85; }
.admin-content { flex: 1; min-width: 0; padding: 1.8rem 2rem; max-width: 1240px; width: 100%; }
.page-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; margin-bottom: 1.3rem; flex-wrap: wrap; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 1rem; margin-bottom: 1.3rem; }
.stat { background: #fff; border-radius: var(--radius); padding: 1rem 1.1rem; box-shadow: var(--shadow); border-top: 4px solid var(--blue-500); }
.stat .label { font-size: .74rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 700; }
.stat .value { font-size: 1.8rem; font-weight: 800; color: var(--blue-900); line-height: 1.2; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1.25rem; }
.status-dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: .4rem; }
.status-dot.on { background: #22c55e; } .status-dot.off { background: #ef4444; }

/* ---------- Trainee pages ---------- */
.topbar { background: var(--grad); color: #fff; padding: .8rem 1.2rem; display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; }
.topbar .brand { display: flex; align-items: center; gap: .6rem; font-weight: 800; }
.topbar .brand .logo-mark { width: 34px; height: 34px; font-size: 1rem; border-radius: 10px; box-shadow: none; background: rgba(255,255,255,.2); }
.topbar .spacer { flex: 1; }
.topbar a { color: #fff; }
.container { max-width: 1000px; margin: 0 auto; padding: 1.5rem 1rem 3rem; }
.container.narrow { max-width: 760px; }
.info-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: .8rem; margin: 1rem 0 1.4rem; }
.info { background: #eff6ff; border-radius: 12px; padding: .8rem; text-align: center; }
.info .label { font-size: .72rem; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; font-weight: 700; }
.info .value { font-size: 1.2rem; font-weight: 800; color: var(--blue-800); }
.rules li { margin-bottom: .35rem; }

/* ---------- Exam ---------- */
.exam-top {
  position: sticky; top: 0; z-index: 50; background: var(--grad); color: #fff;
  padding: .7rem 1.2rem; display: flex; align-items: center; gap: .9rem; flex-wrap: wrap;
  box-shadow: 0 6px 18px rgba(6, 20, 49, .3);
}
.exam-top .brand { font-weight: 800; display: flex; align-items: center; gap: .5rem; }
.exam-top .who { font-size: .85rem; opacity: .9; }
.timer {
  font-variant-numeric: tabular-nums; font-weight: 800; font-size: 1.25rem;
  background: rgba(255, 255, 255, .16); padding: .35rem .8rem; border-radius: 10px; min-width: 112px; text-align: center;
}
.timer.low { background: #dc2626; animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .65; } }
.progress-pill { font-size: .85rem; background: rgba(255,255,255,.14); padding: .35rem .7rem; border-radius: 999px; }
.save-state { font-size: .78rem; opacity: .9; }
.save-state.error { color: #fecaca; font-weight: 700; }
.section-title { margin: 1.8rem 0 .8rem; display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; flex-wrap: wrap; }
.section-title h2 { margin: 0; }
.q-card {
  background: #fff; border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 1.2rem 1.4rem; margin-bottom: 1rem; border-left: 4px solid var(--blue-500);
}
.q-num { font-size: .74rem; font-weight: 800; color: var(--blue-500); text-transform: uppercase; letter-spacing: .06em; }
.q-num .marks { color: var(--muted); font-weight: 600; }
.q-text { font-weight: 600; margin: .3rem 0 .9rem; font-size: 1.02rem; user-select: none; -webkit-user-select: none; }
.options { display: flex; flex-direction: column; gap: .5rem; }
.option {
  display: flex; gap: .7rem; align-items: flex-start; padding: .65rem .8rem;
  border: 1px solid var(--border); border-radius: 10px; cursor: pointer; user-select: none; -webkit-user-select: none; transition: all .12s;
}
.option:hover { background: #f5f9ff; border-color: var(--blue-300); }
.option input { margin-top: .25rem; flex-shrink: 0; }
.option .opt-label { font-weight: 700; color: var(--blue-600); min-width: 1.3rem; }
.option.selected { border-color: var(--blue-500); background: #eaf2ff; }
.q-card textarea { min-height: 130px; margin-top: 0; }
.word-count { font-size: .78rem; color: var(--muted); text-align: right; margin-top: .3rem; }
.exam-footer { display: flex; justify-content: flex-end; align-items: center; gap: 1rem; margin: 1.5rem 0 3rem; flex-wrap: wrap; }

/* ---------- Modals / overlays ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(6, 20, 49, .74); display: none;
  align-items: center; justify-content: center; z-index: 100; padding: 1rem;
}
.modal-backdrop.open { display: flex; }
.modal { background: #fff; border-radius: 18px; padding: 1.8rem; max-width: 480px; width: 100%; box-shadow: 0 30px 70px rgba(0, 0, 0, .4); text-align: center; }
.modal h2 { font-size: 1.3rem; }
.modal.warn h2 { color: var(--danger); }
.modal .icon { font-size: 2.6rem; margin-bottom: .4rem; line-height: 1; }
.modal-actions { display: flex; gap: .6rem; justify-content: center; margin-top: 1.2rem; flex-wrap: wrap; }
.overlay-text { color: #fff; font-size: 1.15rem; font-weight: 700; text-align: center; }

/* ---------- Results ---------- */
.score-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: .9rem; margin: 1.2rem 0; }
.score { background: #eff6ff; border-radius: 14px; padding: 1rem; text-align: center; }
.score .label { font-size: .72rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 700; }
.score .value { font-size: 1.7rem; font-weight: 800; color: var(--blue-800); line-height: 1.2; }
.score.total { background: var(--grad-btn); }
.score.total .value, .score.total .label { color: #fff; }
.spinner { width: 36px; height: 36px; border: 4px solid #dbe4f3; border-top-color: var(--blue-500); border-radius: 50%; animation: spin .9s linear infinite; margin: 1rem auto; }
@keyframes spin { to { transform: rotate(360deg); } }
.answer-box { background: #f7faff; border: 1px solid var(--border); border-radius: 10px; padding: .8rem 1rem; white-space: pre-wrap; margin: .5rem 0; word-break: break-word; }
.answer-box.empty { color: var(--muted); font-style: italic; }
.opt-review { padding: .45rem .7rem; border-radius: 8px; margin-bottom: .3rem; border: 1px solid var(--border); font-size: .92rem; display: flex; gap: .6rem; }
.opt-review .tag { margin-left: auto; font-size: .72rem; font-weight: 700; white-space: nowrap; }
.opt-review.correct { background: #dcfce7; border-color: #86efac; }
.opt-review.chosen { background: #fee2e2; border-color: #fca5a5; }
.opt-review.chosen.correct { background: #dcfce7; border-color: #86efac; }
.feedback { background: #fffbeb; border: 1px solid #fde68a; border-radius: 10px; padding: .7rem .9rem; font-size: .9rem; margin: .5rem 0; }
.score-input { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; }
.score-input input[type=number] { width: 90px; margin: 0; }
.big-status { font-size: 3rem; line-height: 1; margin-bottom: .5rem; }
.toast {
  position: fixed; bottom: 1.2rem; left: 50%; transform: translateX(-50%); background: #0a1f44; color: #fff;
  padding: .6rem 1rem; border-radius: 10px; font-size: .9rem; opacity: 0; transition: opacity .2s; pointer-events: none; z-index: 120;
}
.toast.show { opacity: 1; }
.result-pass { color: var(--success); } .result-fail { color: var(--danger); }

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  .grid-2 { grid-template-columns: 1fr; }
  .admin-shell { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; padding: 1rem; }
  .sidebar-brand { padding-bottom: .8rem; }
  .sidebar nav { flex-direction: row; flex-wrap: wrap; }
  .sidebar nav a { padding: .45rem .7rem; font-size: .9rem; }
  .sidebar-foot { margin-top: .5rem; padding: .2rem .5rem; }
  .admin-content { padding: 1.2rem 1rem; }
  .card { padding: 1.1rem; }
}
@media (max-width: 600px) {
  .exam-top { padding: .6rem .8rem; gap: .5rem; }
  .exam-top .who { display: none; }
  .timer { font-size: 1.05rem; min-width: 90px; }
  .q-card { padding: 1rem; }
  .auth-card { padding: 1.7rem 1.3rem; }
}
