:root {
  --bg: #f4f6fa;
  --card: #fff;
  --text: #1a202c;
  --muted: #6b7280;
  --primary: #2563eb;
  --accent: #10b981;
  --danger: #dc2626;
  --border: #e5e7eb;
  --radius: 8px;
  --shadow: 0 2px 8px rgba(0,0,0,0.04);
  --font: 'Inter', 'Segoe UI', Arial, sans-serif;
}

html[data-theme="dark"] {
  --bg: #181a20;
  --card: #23262f;
  --text: #e5e7eb;
  --muted: #9ca3af;
  --primary: #7aa2f7;
  --accent: #34d399;
  --danger: #ef4444;
  --border: #2a2f3a;
  --radius: 8px;
  --shadow: 0 2px 8px rgba(0,0,0,0.18);
  --font: 'Inter', 'Segoe UI', Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
#app, body > .container { flex: 1 1 auto; }
body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
}
a { color: var(--primary); text-decoration: none; }
main { flex: 1 1 auto; }
.container { max-width: 1100px; margin: 32px auto; padding: 0 24px; }

.site-header, .site-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 32px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  border-radius: var(--radius) var(--radius) 0 0;
  box-shadow: var(--shadow);
}
.site-footer {
  border-top: 1px solid var(--border);
  border-bottom: none;
  margin-top: auto;
  width: 100%;
  border-radius: 0 0 var(--radius) var(--radius);
  box-shadow: var(--shadow);
}
.site-header .logo { height: 36px; width: auto; vertical-align: middle; }
.site-header .app-title { font-weight: 600; font-size: 18px; margin-left: 10px; }
.site-header .left { display:flex; align-items:center; gap:10px; }
.nav a { margin: 0 8px; }
.right { display:flex; align-items:center; gap:8px; }

.card {
  background: var(--card);
  padding: 24px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 24px;
  box-shadow: var(--shadow);
}
.auth { max-width: 420px; margin: 0 auto; }

.btn {
  background: var(--primary);
  color: #fff;
  padding: 8px 18px;
  border: none;
  border-radius: var(--radius);
  cursor:pointer;
  display:inline-block;
  font-weight: 500;
  box-shadow: 0 1px 2px rgba(37,99,235,0.04);
  transition: background 0.15s, box-shadow 0.15s;
}
.btn:hover, .btn:focus {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 2px 8px rgba(16,185,129,0.10);
}
  .btn.icon {
    padding: 8px;
    min-width: 36px;
    display: inline-grid;
    place-items: center;
    border-radius: 8px;
  }
  .btn.icon svg { width: 16px; height: 16px; display:block; }
  .actions .btn + .btn { margin-left: 8px; }
.btn.small { padding: 6px 10px; font-size: 14px; }
.btn.primary { background: var(--primary); }
.btn.danger { background: var(--danger); }

.table {
  width: 100%;
  border-collapse: collapse;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.table th, .table td {
  padding: 14px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
.table thead th {
  background: #f4f6fa;
  color: var(--muted);
  font-weight: 600;
  letter-spacing: 0.02em;
}
.table tbody tr:hover {
  background: #f0f4fa;
}

.alert { padding: 10px; border-radius: 6px; margin-bottom: 12px; }
.alert.error { background: #fee2e2; color: #991b1b; }
.alert.success { background: #dcfce7; color: #166534; }

.badge { display:inline-block; padding: 2px 8px; border-radius: 999px; background: rgba(0,0,0,0.08); font-size: 12px; }

.grid2 { display:grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid3 { display:grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }

label { display:block; margin: 8px 0; }
input[type="text"], input[type="email"], input[type="password"], input[type="number"], input[type="datetime-local"], textarea, select {
  width: 100%; padding: 8px; border:1px solid var(--border); border-radius: 6px; background: transparent; color: var(--text);
}
textarea { min-height: 80px; }

.inline { display:inline-block; }
.actions { display:flex; gap: 8px; align-items:center; margin-top: 10px; }

.stats { display:flex; gap: 16px; }
.stat { background: var(--card); padding: 12px; border:1px solid var(--border); border-radius: 8px; min-width: 120px; text-align:center; }
.muted { color: var(--muted); font-size: 15px; }

.questions { list-style: decimal; padding-left: 20px; }
.qtext { font-weight: 600; margin-bottom: 6px; }
.likert label { margin-right: 12px; display: inline-block; vertical-align: top; max-width: 150px; }
.checkbox { border:1px solid var(--border); padding: 6px; border-radius: 6px; background: var(--card); }
.pagination a { margin: 0 4px; padding: 2px 6px; border:1px solid var(--border); border-radius:4px; }
.pagination a.active { background: var(--primary); color: #fff; border-color: var(--primary); }
/* Grid Preview */
.grid-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  background: var(--card);
  border: 1px solid var(--border);
}

.grid-table th,
.grid-table td {
  border: 1px solid var(--border);
  padding: 8px;
  vertical-align: middle;
}

.grid-table thead th {
  background: rgba(0,0,0,0.04);
  text-align: center;
}

.grid-table .col-code { width: 80px; text-align: center; font-weight: 600; }
.grid-table .col-desc { width: auto; }
.grid-table .col-scale { width: 90px; text-align: center; }
/* Left-align level descriptions in body cells */
.grid-table td.col-scale { text-align: left; }

.grid-table .scale-top { font-weight: 700; }
.grid-table .scale-sub { font-size: 12px; color: var(--muted); line-height: 1.2; }

.grid-table .cat-row td {
  background: rgba(0,0,0,0.06);
  font-weight: 700;
}

 .grid-table .scale-text { margin-top: 6px; font-size: 12px; color: var(--muted); line-height: 1.3; text-align: left; }

.bubble {
  display: inline-block;
  width: 14px; height: 14px;
  border: 2px solid var(--border);
  border-radius: 50%;
}

/* Print tweaks for PDF export */
@media print {
  .site-header, .site-footer, .actions { display: none !important; }
  .grid-table th, .grid-table td { padding: 6px; }
}
@media print {
  .no-export { display: none !important; }
}



.likert .scale-label { display: inline-block; text-align: left; }
.scale-desc { display: block; margin-top: 4px; font-size: 12px; color: var(--muted); line-height: 1.3; }
/* Tune inside grid table */
.grid-table .col-scale { padding: 0; }
.grid-table .likert-option { border: none; background: transparent; padding: 12px; min-height: auto; display:block; width:100%; height:100%; border-radius: 0; cursor: pointer; }
.grid-table .likert-option:hover { box-shadow: none; }
.grid-table .scale-desc { font-size: 13px; text-align: left; }
/* Disabled/empty cells not selectable */
.grid-table .likert-option.disabled { pointer-events: none; background: transparent !important; }

/* Assessment conduct UI enhancements */
:root { --level1:#374151; --level2:#ef4444; --level3:#f59e0b; --level4:#fbbf24; --level5:#86efac; }
.likert-grid { display:grid; grid-template-columns: repeat(var(--scale-count), minmax(0,1fr)); gap: 8px; align-items: start; }
.likert-header .lh { text-align:center; background: var(--card); border:1px dashed var(--border); padding: 6px; border-radius:6px; }
.likert-row { margin-bottom: 8px; }
.likert-option { display:flex; flex-direction: column; gap:6px; padding: 8px; border:1px solid var(--border); border-radius:6px; cursor: pointer; background: var(--card); min-height: 54px; }
.likert-option input { display:none; }
.scale-bubble { width: 28px; height: 28px; border-radius: 50%; display: inline-grid; place-items: center; border:1px solid var(--border); font-size: 12px; color: var(--muted); background: rgba(0,0,0,0.03); }
.likert-option:hover { box-shadow: var(--shadow); }

/* Hover + selected coloring for descriptions and bubble */
.likert-option.level-1:hover .scale-desc, .likert-option.level-1.selected .scale-desc { color: var(--level1); }
.likert-option.level-2:hover .scale-desc, .likert-option.level-2.selected .scale-desc { color: var(--level2); }
.likert-option.level-3:hover .scale-desc, .likert-option.level-3.selected .scale-desc { color: var(--level3); }
.likert-option.level-4:hover .scale-desc, .likert-option.level-4.selected .scale-desc { color: #eab308; }
.likert-option.level-5:hover .scale-desc, .likert-option.level-5.selected .scale-desc { color: #16a34a; }

.likert-option.level-1:hover .scale-bubble, .likert-option.level-1.selected .scale-bubble { background: rgba(55,65,81,0.15); color: var(--level1); border-color: var(--level1); }
.likert-option.level-2:hover .scale-bubble, .likert-option.level-2.selected .scale-bubble { background: rgba(239,68,68,0.12); color: var(--level2); border-color: var(--level2); }
.likert-option.level-3:hover .scale-bubble, .likert-option.level-3.selected .scale-bubble { background: rgba(245,158,11,0.15); color: var(--level3); border-color: var(--level3); }
.likert-option.level-4:hover .scale-bubble, .likert-option.level-4.selected .scale-bubble { background: rgba(251,191,36,0.18); color: #ca8a04; border-color: #eab308; }
.likert-option.level-5:hover .scale-bubble, .likert-option.level-5.selected .scale-bubble { background: rgba(134,239,172,0.25); color: #16a34a; border-color: #10b981; }

/* Full-bright cell background by level in grid and regular views */
.grid-table .likert-option.level-1:hover,
.grid-table .likert-option.level-1.selected,
.likert-option.level-1.selected { background: #374151; color: #ffffff; }
.grid-table .likert-option.level-2:hover,
.grid-table .likert-option.level-2.selected,
.likert-option.level-2.selected { background: #ef4444; color: #ffffff; }
.grid-table .likert-option.level-3:hover,
.grid-table .likert-option.level-3.selected,
.likert-option.level-3.selected { background: #f59e0b; color: #111827; }
.grid-table .likert-option.level-4:hover,
.grid-table .likert-option.level-4.selected,
.likert-option.level-4.selected { background: #ffff00; color: #111827; }
.grid-table .likert-option.level-5:hover,
.grid-table .likert-option.level-5.selected,
.likert-option.level-5.selected { background: #10b981; color: #ffffff; }

/* Apply color to entire td using :has() so the full cell is tinted */
.grid-table td.col-scale:has(.level-1:hover),
.grid-table td.col-scale:has(.level-1.selected) { background: #374151 !important; color: #ffffff; }
.grid-table td.col-scale:has(.level-2:hover),
.grid-table td.col-scale:has(.level-2.selected) { background: #ef4444 !important; color: #ffffff; }
.grid-table td.col-scale:has(.level-3:hover),
.grid-table td.col-scale:has(.level-3.selected) { background: #f59e0b !important; color: #111827; }
.grid-table td.col-scale:has(.level-4:hover),
.grid-table td.col-scale:has(.level-4.selected) { background: #ffff00 !important; color: #111827; }
.grid-table td.col-scale:has(.level-5:hover),
.grid-table td.col-scale:has(.level-5.selected) { background: #10b981 !important; color: #ffffff; }

/* Ensure description text follows contrast color */
.grid-table .likert-option.level-1:hover .scale-desc,
.grid-table .likert-option.level-1.selected .scale-desc,
.likert-option.level-1.selected .scale-desc { color: #ffffff; }
.grid-table .likert-option.level-2:hover .scale-desc,
.grid-table .likert-option.level-2.selected .scale-desc,
.likert-option.level-2.selected .scale-desc { color: #ffffff; }
.grid-table .likert-option.level-3:hover .scale-desc,
.grid-table .likert-option.level-3.selected .scale-desc,
.likert-option.level-3.selected .scale-desc { color: #111827; }
.grid-table .likert-option.level-4:hover .scale-desc,
.grid-table .likert-option.level-4.selected .scale-desc,
.likert-option.level-4.selected .scale-desc { color: #111827; }
.grid-table .likert-option.level-5:hover .scale-desc,
.grid-table .likert-option.level-5.selected .scale-desc,
.likert-option.level-5.selected .scale-desc { color: #ffffff; }

/* Result view: disable hover highlight; keep selected highlight only */
#reportRoot .grid-table .likert-option:hover:not(.selected) {
  background: transparent !important;
  color: inherit !important;
}
#reportRoot .grid-table .likert-option:hover:not(.selected) .scale-desc {
  color: inherit !important;
}
#reportRoot .grid-table td.col-scale:has(.likert-option:hover):not(:has(.selected)) {
  background: transparent !important;
  color: inherit !important;
}

/* Sticky save progress button */
#saveDraft { position: fixed; right: 24px; bottom: 24px; z-index: 1000; box-shadow: 0 8px 24px rgba(0,0,0,0.15); }

/* Question answered/missing indicators */
.qa-indicator { display:flex; align-items:center; gap:4px; margin-top:4px; min-height: 16px; }
.qa-indicator.ok { color:#10b981; }
.qa-indicator.missing { color:#f59e0b; }

/* Submit button states */
#submitBtn[disabled] {
  background: #9ca3af !important; /* gray */
  color: #ffffff !important;
  cursor: not-allowed;
  box-shadow: none;
}
#resultSummary .grid2 { display:grid; grid-template-columns: 420px 1fr; gap: 16px; }
.global-score-box { background: var(--card); border:1px solid var(--border); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; }
.global-score-box .gs-label { color: var(--muted); font-size: 13px; }
.global-score-box .gs-score { font-size: 28px; font-weight: 800; }
.global-score-box .gs-level { font-weight: 600; margin-top: 4px; }
.gauge { margin-top: 12px; }
.gauge-bar { position: relative; height: 18px; border-radius: 999px; overflow: visible; display: grid; grid-template-columns: repeat(5, 1fr); }
.gauge-bar .seg1 { border-top-left-radius: 999px; border-bottom-left-radius: 999px; }
.gauge-bar .seg5 { border-top-right-radius: 999px; border-bottom-right-radius: 999px; }
.gauge-bar .seg { height: 100%; }
.gauge-bar .seg1 { background: #111827; }
.gauge-bar .seg2 { background: #ef4444; }
.gauge-bar .seg3 { background: #f59e0b; }
.gauge-bar .seg4 { background: #ffff00; }
.gauge-bar .seg5 { background: #10b981; }
.gauge-bar .indicator { position: absolute; top: calc(100% + 6px); left: 0; transform: translateX(-50%); width: 24px; height: 16px; }
.gauge-bar .indicator::before, .gauge-bar .indicator::after { content: none !important; }
.gauge-bar .indicator svg { display:block; width:100%; height:100%; }

/* TLBO House */
.tlbo-house { position: relative; }
.tlbo-roof { width: 100%; height: 34px; margin: 0 auto 4px auto; position: relative; }
/* Use an inline SVG for the triangular roof to ensure PDF compatibility */
.tlbo-roof .roof-svg { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.tlbo-roof .roof-text { position: absolute; top: 4px; left: 50%; transform: translateX(-50%); color: #e5e7eb; text-align:center; font-weight: 800; text-transform: none; font-size: 15px; line-height: 1.1; }
.tlbo-roof .roof-text small { display:block; font-weight:600; font-size:12px; color:#c7d2fe; }
.tlbo-body { display: flex; flex-direction: column; gap: 3px; }
.tlbo-level { display: grid; gap: 3px; align-items: stretch; border-top: 3px solid #0f172a; padding-top: 2px; }
.tlbo-brick { display:block; border: 1px solid #0f172a; background: #fef08a; padding: 6px 8px; min-height: 40px; border-radius: 3px; box-shadow: inset 0 -3px 0 rgba(0,0,0,0.12); }
.tlbo-brick .tlbo-brick-text { font-weight: 600; line-height: 1.2; }
.tlbo-brick.level-0 { background: #f8fafc; color: #111827; }
.tlbo-brick.level-1 { background: #374151; color: #ffffff; }
.tlbo-brick.level-2 { background: #ef4444; color: #ffffff; }
.tlbo-brick.level-3 { background: #f59e0b; color: #111827; }
.tlbo-brick.level-4 { background: #ffff00; color: #111827; }
.tlbo-brick.level-5 { background: #10b981; color: #ffffff; }
.tlbo-brick.empty { background: transparent; border-color: transparent; box-shadow: none; }

/* Vertical gauge for TLBO */
#tlboSummary .grid2 { grid-template-columns: 1fr 200px; }
.gauge-vertical .gv-wrap { display:flex; align-items:flex-end; gap:10px; }
.global-score-box .gauge-vertical.centered .gv-wrap { margin: 8px auto 0 auto; }
.gv-bar { position: relative; width: 22px; height: 220px; display: flex; flex-direction: column-reverse; border-radius: 6px; overflow: visible; }
.gv-bar .segv { width:100%; height:auto; flex: 1 1 0; }
.gv-bar .segv1 { background:#111827; }
.gv-bar .segv2 { background:#ef4444; }
.gv-bar .segv3 { background:#f59e0b; }
.gv-bar .segv4 { background:#ffff00; }
.gv-bar .segv5 { background:#10b981; }
.indicator-v { position:absolute; left: -12px; transform: translateY(50%); width: 18px; height: 14px; z-index: 2; }
.gv-scale { display:flex; flex-direction:column; height: 220px; justify-content:space-between; font-size:12px; color: var(--muted); }
.gauge-scale { display:flex; justify-content: space-between; font-size: 12px; color: var(--muted); margin-top: 6px; }
#submitBtn[disabled]:hover, #submitBtn[disabled]:focus { background: #9ca3af !important; box-shadow: none; }
#submitBtn:not([disabled]) { background: var(--primary); }
#submitBtn:not([disabled]):hover, #submitBtn:not([disabled]):focus {
  background: var(--primary); /* keep blue on hover */
  color: #fff;
  box-shadow: 0 2px 8px rgba(37,99,235,0.20);
}

