/*
 * style.css — Shared corporate stylesheet for the Narith AI Assessment Platform.
 *
 * RESPONSIBILITY: design tokens + base layout + shared components (cards,
 * buttons, forms, footer, banners) used by both the agent and manager portals.
 * Palette: white / silver / blue, minimal and professional, desktop-first with
 * responsive fallbacks. Page-specific styles live alongside their modules but
 * build on these tokens.
 *
 * © 2026 Narith AI. All Rights Reserved.
 */

/* ---- Design tokens ------------------------------------------------------- */
:root {
  --c-blue:        #1f4e8c;   /* primary corporate blue */
  --c-blue-dark:   #163a69;
  --c-blue-light:  #e8f0fb;
  --c-silver:      #c9d1da;   /* borders / dividers */
  --c-silver-soft: #eef1f5;   /* subtle fills */
  --c-white:       #ffffff;
  --c-ink:         #1f2933;   /* primary text */
  --c-ink-soft:    #55606c;   /* secondary text */
  --c-pass:        #1f8c4d;
  --c-fail:        #c0392b;
  --c-excellent:   #6d28d9;
  --c-warn-bg:     #fff4e5;
  --c-warn-ink:    #8a5300;

  --radius:   14px;
  --radius-sm: 9px;
  --shadow:   0 6px 24px rgba(31, 78, 140, 0.08);
  --shadow-sm: 0 2px 8px rgba(31, 41, 51, 0.06);
  --gap:      20px;
  --maxw:     1180px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;

  --transition: 160ms ease;
}

/* ---- Reset / base -------------------------------------------------------- */
* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
}

body {
  font-family: var(--font);
  color: var(--c-ink);
  background: linear-gradient(180deg, var(--c-silver-soft) 0%, #f7f9fc 100%);
  font-size: 15px;
  line-height: 1.5;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

h1, h2, h3 { color: var(--c-blue-dark); margin: 0 0 0.5em; font-weight: 600; }
a { color: var(--c-blue); }

/* ---- Layout scaffolding -------------------------------------------------- */
.app-header {
  background: var(--c-white);
  border-bottom: 1px solid var(--c-silver);
  box-shadow: var(--shadow-sm);
}
.app-header .bar {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 14px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--gap);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; color: var(--c-blue-dark); }
.brand .logo { width: 30px; height: 30px; }

.main {
  flex: 1 0 auto;
  width: 100%;
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 28px 24px;
}

.center-wrap {
  min-height: 60vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ---- Card ---------------------------------------------------------------- */
.card {
  background: var(--c-white);
  border: 1px solid var(--c-silver);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 26px 28px;
}
.card.narrow { width: 100%; max-width: 420px; }
.card h2 { margin-top: 0; }
.muted { color: var(--c-ink-soft); }
.small { font-size: 13px; }

/* ---- Forms --------------------------------------------------------------- */
.field { margin-bottom: 16px; }
.field label { display: block; font-weight: 600; margin-bottom: 6px; font-size: 13px; color: var(--c-ink-soft); }
.field input[type="text"],
.field input[type="email"] {
  width: 100%;
  padding: 11px 12px;
  border: 1px solid var(--c-silver);
  border-radius: var(--radius-sm);
  font-size: 15px;
  transition: border-color var(--transition), box-shadow var(--transition);
}
.field input:focus {
  outline: none;
  border-color: var(--c-blue);
  box-shadow: 0 0 0 3px var(--c-blue-light);
}

/* ---- Buttons ------------------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 11px 20px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition), transform var(--transition), box-shadow var(--transition);
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--c-blue); color: #fff; }
.btn-primary:hover { background: var(--c-blue-dark); }
.btn-ghost { background: transparent; border-color: var(--c-silver); color: var(--c-ink); }
.btn-ghost:hover { background: var(--c-silver-soft); }
.btn-block { width: 100%; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }

/* ---- Settings editor (M10) ----------------------------------------------- */
.set-table td { vertical-align: middle; }
.set-key { font-weight: 600; color: var(--c-ink); white-space: nowrap; }
.set-key label { cursor: default; }
.set-num { width: 120px; padding: 7px 9px; border: 1px solid var(--c-silver); border-radius: var(--radius-sm); font-size: 14px; }
.set-desc { max-width: 420px; }
.set-ok { color: var(--c-pass); font-weight: 600; }
.set-err { color: var(--c-fail); font-weight: 600; }

/* ---- Accessibility utilities (M8) ---------------------------------------- */

/* Visible keyboard-focus indicator for all interactive elements. Uses
   :focus-visible so it appears for keyboard/AT users without adding a ring on
   mouse click. A high-contrast blue outline plus offset keeps it visible on
   both light cards and the blue active tab. */
a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
[tabindex]:focus-visible {
  outline: 3px solid var(--c-blue);
  outline-offset: 2px;
  border-radius: 4px;
}
.mgr-tab.active:focus-visible,
.btn-primary:focus-visible { outline-color: var(--c-blue-dark); }

/* Screen-reader-only text (visually hidden, still announced). */
.sr-only {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0);
  white-space: nowrap; border: 0;
}

/* Respect users who prefer reduced motion. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}

/* ---- Banners / status ---------------------------------------------------- */
.banner {
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-size: 14px;
  margin: 10px 0;
  border: 1px solid transparent;
}
.banner-error { background: #fdecea; color: var(--c-fail); border-color: #f5c6c0; }
.banner-warn  { background: var(--c-warn-bg); color: var(--c-warn-ink); border-color: #f2d9a8; }
.banner-ok    { background: #eaf7ef; color: var(--c-pass); border-color: #bfe6cd; }
.banner-info  { background: var(--c-blue-light); color: var(--c-blue-dark); border-color: #c5dbf5; }
.hidden { display: none !important; }

/* ---- Result badges ------------------------------------------------------- */
.badge { display: inline-block; padding: 4px 12px; border-radius: 999px; font-weight: 700; font-size: 13px; }
.badge-pass { background: #eaf7ef; color: var(--c-pass); }
.badge-fail { background: #fdecea; color: var(--c-fail); }
.badge-excellent { background: #f1ebfb; color: var(--c-excellent); }

/* ---- Footer -------------------------------------------------------------- */
.app-footer {
  flex-shrink: 0;
  text-align: center;
  padding: 16px;
  color: var(--c-ink-soft);
  font-size: 13px;
  border-top: 1px solid var(--c-silver);
  background: var(--c-white);
}

/* ---- Simple key/value table (smoke test, reports) ------------------------ */
.kv { width: 100%; border-collapse: collapse; }
.kv td { padding: 8px 10px; border-bottom: 1px solid var(--c-silver-soft); }
.kv td:first-child { color: var(--c-ink-soft); width: 45%; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px; }

/* ---- Login card + spinner ------------------------------------------------ */
.login-head { text-align: center; margin-bottom: 18px; }
.login-logo { width: 52px; height: 52px; margin-bottom: 8px; }
.login-head h2 { margin: 4px 0 2px; }
.login-foot { text-align: center; margin: 16px 0 0; }

.landing-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--gap);
  margin-bottom: 12px;
}

.spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255, 255, 255, 0.55);
  border-top-color: #fff;
  border-radius: 50%;
  animation: narith-spin 0.7s linear infinite;
  vertical-align: middle;
}
/* Spinner on light backgrounds (boot views) */
.spinner-row .spinner {
  border: 2px solid var(--c-silver);
  border-top-color: var(--c-blue);
}
.spinner-row { display: flex; align-items: center; gap: 10px; color: var(--c-ink-soft); }

@keyframes narith-spin { to { transform: rotate(360deg); } }

/* ---- Assessment runtime -------------------------------------------------- */
.assessment { width: 100%; max-width: 760px; margin: 0 auto; }

.assessment-bar { margin-bottom: 16px; }
.progress {
  height: 8px;
  background: var(--c-silver-soft);
  border: 1px solid var(--c-silver);
  border-radius: 999px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  width: 0%;
  background: var(--c-blue);
  transition: width 200ms ease;
}
.assessment-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 8px;
}
.assessment-meta .counter { font-weight: 600; color: var(--c-blue-dark); }
.assessment-meta .meta-right { display: flex; align-items: center; gap: 14px; }
.save-status { color: var(--c-pass); min-width: 60px; text-align: right; }
.save-status.offline { color: var(--c-warn-ink); }
#nav-flag.flagged { background: var(--c-warn-bg); border-color: #f2d9a8; color: var(--c-warn-ink); }

/* Result screen */
.result-score { margin: 18px 0 14px; }
.result-pct { font-size: 52px; font-weight: 800; color: var(--c-blue-dark); line-height: 1.1; }
.result-score .badge { font-size: 15px; padding: 6px 16px; }
.timer {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  color: var(--c-blue-dark);
  background: var(--c-blue-light);
  border: 1px solid var(--c-silver);
  border-radius: var(--radius-sm);
  padding: 4px 12px;
}
.timer.timer-low { color: #fff; background: var(--c-fail); border-color: var(--c-fail); }

.question-card { margin: 0; }
.q-stem { font-size: 17px; font-weight: 600; color: var(--c-ink); margin: 4px 0 18px; }

.options { display: flex; flex-direction: column; gap: 10px; }
.option {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 13px 15px;
  border: 1px solid var(--c-silver);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: border-color var(--transition), background var(--transition);
}
.option:hover { border-color: var(--c-blue); background: var(--c-blue-light); }
.option input { width: 16px; height: 16px; accent-color: var(--c-blue); }

.assessment-nav { display: flex; align-items: center; gap: 12px; margin-top: 18px; }
.assessment-nav .spacer { flex: 1 1 auto; }

/* ---- Anti-cheat (M3) ----------------------------------------------------- */
.no-select { user-select: none; -webkit-user-select: none; }

/* Tiled identity watermark across the whole viewport (non-interactive). */
.watermark-overlay {
  position: fixed;
  inset: 0;
  z-index: 40;
  pointer-events: none;
  overflow: hidden;
  display: flex;
  flex-wrap: wrap;
  align-content: flex-start;
  gap: 60px 40px;
  padding: 40px;
  opacity: 0.06;
  transform: rotate(-24deg) scale(1.4);
  transform-origin: center;
}
.watermark-overlay span {
  font-size: 12px;
  font-weight: 600;
  color: var(--c-ink);
  white-space: nowrap;
}

/* Transient warning toast. */
.anticheat-toast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  transform: translateX(-50%) translateY(20px);
  background: var(--c-ink);
  color: #fff;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 13px;
  z-index: 60;
  opacity: 0;
  transition: opacity 180ms ease, transform 180ms ease;
  pointer-events: none;
}
.anticheat-toast.show { opacity: 0.96; transform: translateX(-50%) translateY(0); }

/* Fullscreen re-entry prompt (covers the screen until fullscreen resumes). */
.fs-prompt {
  position: fixed;
  inset: 0;
  z-index: 70;
  background: rgba(22, 58, 105, 0.92);
  display: flex;
  align-items: center;
  justify-content: center;
}
.fs-prompt .fs-card {
  background: #fff;
  border-radius: var(--radius);
  padding: 28px 30px;
  max-width: 420px;
  text-align: center;
  box-shadow: var(--shadow);
}

/* Blank the page if a print is somehow triggered. */
@media print {
  body * { visibility: hidden !important; }
  body::after {
    content: "Printing is disabled during the Narith AI assessment.";
    visibility: visible;
    display: block;
  }
}

/* ---- Manager portal (M4) ------------------------------------------------- */
.mgr-main { max-width: 1440px; }

.mgr-nav {
  display: flex; align-items: center; gap: 6px; flex-wrap: wrap;
  background: var(--c-white); border: 1px solid var(--c-silver);
  border-radius: var(--radius); padding: 8px 12px; margin-bottom: 18px;
  box-shadow: var(--shadow-sm);
}
.mgr-tab {
  border: none; background: transparent; padding: 8px 14px; border-radius: var(--radius-sm);
  font-weight: 600; color: var(--c-ink-soft); cursor: pointer;
}
.mgr-tab.active { background: var(--c-blue); color: #fff; }
.mgr-tab:disabled { opacity: 0.4; cursor: not-allowed; }
.nav-spacer { flex: 1 1 auto; }
.refresh-toggle { display: flex; align-items: center; gap: 6px; }
.mini-select { padding: 7px 9px; border: 1px solid var(--c-silver); border-radius: var(--radius-sm); font-size: 13px; background: #fff; }

/* KPI cards */
.cards-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 18px; }
.kpi { background: #fff; border: 1px solid var(--c-silver); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow-sm); }
.kpi-value { font-size: 26px; font-weight: 800; color: var(--c-blue-dark); line-height: 1.1; }
.kpi-label { font-size: 12px; color: var(--c-ink-soft); margin-top: 4px; }
.kpi.risk-low .kpi-value { color: var(--c-pass); }
.kpi.risk-mod .kpi-value { color: #e0a800; }
.kpi.risk-high .kpi-value { color: #e8833a; }
.kpi.risk-crit .kpi-value { color: var(--c-fail); }

/* Charts */
.charts-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 14px; margin-bottom: 18px; }
.chart-card { padding: 16px; }
.chart-card h3 { font-size: 13px; margin: 0 0 10px; color: var(--c-ink-soft); text-transform: uppercase; letter-spacing: 0.03em; }
.chart-card canvas { height: 200px !important; }
.chart-card.wide { grid-column: 1 / -1; }

/* Controls + table */
.controls { padding: 12px 14px; margin-bottom: 14px; }
.controls-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.search { flex: 1 1 240px; min-width: 200px; padding: 8px 12px; border: 1px solid var(--c-silver); border-radius: var(--radius-sm); font-size: 14px; }
.table-card { padding: 0; overflow: hidden; }
.table-scroll { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table th, .data-table td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--c-silver-soft); white-space: nowrap; }
.data-table th { background: var(--c-silver-soft); color: var(--c-ink-soft); font-weight: 600; position: sticky; top: 0; }
.data-table tbody tr:hover { background: var(--c-blue-light); }
.btn-xs { padding: 5px 10px; font-size: 12px; }
.pager { display: flex; align-items: center; justify-content: center; gap: 14px; padding: 12px; }

/* Risk badges */
.risk-b-low { background: #eaf7ef; color: var(--c-pass); }
.risk-b-minor { background: #eef7e6; color: #5a8a1f; }
.risk-b-mod { background: #fff4e5; color: #8a5300; }
.risk-b-high { background: #fdeee3; color: #b5581f; }
.risk-b-crit { background: #fdecea; color: var(--c-fail); }

/* Detail modal */
.modal { position: fixed; inset: 0; z-index: 80; background: rgba(22,58,105,0.45); display: flex; align-items: center; justify-content: center; padding: 24px; }
.modal-card { background: #fff; border-radius: var(--radius); width: 100%; max-width: 860px; max-height: 88vh; display: flex; flex-direction: column; box-shadow: var(--shadow); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--c-silver); }
.modal-head h2 { margin: 0; font-size: 18px; }
.modal-tabs { display: flex; gap: 4px; padding: 8px 16px; border-bottom: 1px solid var(--c-silver); }
.d-tab { border: none; background: transparent; padding: 8px 14px; border-radius: var(--radius-sm); font-weight: 600; color: var(--c-ink-soft); cursor: pointer; }
.d-tab.active { background: var(--c-blue-light); color: var(--c-blue-dark); }
.modal-body { padding: 18px 20px; overflow-y: auto; }
.d-panel h3 { font-size: 13px; text-transform: uppercase; letter-spacing: 0.03em; color: var(--c-ink-soft); margin: 18px 0 8px; }

/* Question review */
.q-item { border: 1px solid var(--c-silver); border-radius: var(--radius-sm); padding: 14px; margin-bottom: 12px; }
.q-stem { font-weight: 600; margin: 0 0 8px; }
.q-head { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.q-num { font-weight: 700; color: var(--c-blue-dark); }
.q-opts { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.q-opt { padding: 8px 12px; border: 1px solid var(--c-silver); border-radius: var(--radius-sm); font-size: 13px; }
.q-opt.opt-correct { border-color: var(--c-pass); background: #eaf7ef; color: var(--c-pass); font-weight: 600; }
.q-opt.opt-wrong { border-color: var(--c-fail); background: #fdecea; color: var(--c-fail); }

/* Timeline */
.timeline { list-style: none; margin: 0; padding: 0; }
.tl-item { display: flex; align-items: baseline; gap: 12px; padding: 8px 10px; border-left: 3px solid var(--c-silver); margin-bottom: 4px; }
.tl-item.sev-high { border-left-color: #e8833a; }
.tl-item.sev-critical { border-left-color: var(--c-fail); }
.tl-item.sev-moderate { border-left-color: #e0a800; }
.tl-item.sev-info { border-left-color: var(--c-blue-soft, #7ea6d9); }
.tl-time { color: var(--c-ink-soft); font-size: 12px; min-width: 90px; }
.tl-type { font-weight: 600; min-width: 170px; }

/* ---- Question management (M5) -------------------------------------------- */
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 14px 20px; border-top: 1px solid var(--c-silver); }
.form-row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.modal-body textarea, .modal-body input[type="text"], .modal-body input[type="number"], .modal-body select {
  width: 100%; padding: 9px 11px; border: 1px solid var(--c-silver); border-radius: var(--radius-sm); font-size: 14px; font-family: inherit;
}
.q-cell { max-width: 340px; overflow: hidden; text-overflow: ellipsis; }
.q-actions { white-space: nowrap; }
.q-actions .btn-xs { padding: 3px 8px; margin-left: 2px; }

/* Status badges */
.st-active { background: #eaf7ef; color: var(--c-pass); }
.st-draft { background: var(--c-silver-soft); color: var(--c-ink-soft); }
.st-disabled { background: #fff4e5; color: #8a5300; }
.st-archived { background: #f1ebfb; color: var(--c-excellent); }
.st-expired { background: #fdecea; color: var(--c-fail); }

/* Diagnostics (M7) */
.cfg-invalid td { background: #fdecea; }

/* ---- Responsive ---------------------------------------------------------- */
@media (max-width: 720px) {
  .main { padding: 18px 14px; }
  .app-header .bar { padding: 12px 14px; }
}
