/* Site design system — layered on top of vendored Bootstrap 5.3.3.
 *
 * Sections:
 *   1. Theme tokens        (navy/teal palette, spacing, radii, shadows)
 *   2. Base elements       (typography, focus, links)
 *   3. App shell layout    (sidebar, topbar, content, footer, offcanvas)
 *   4. Page chrome         (page header, breadcrumbs, flash alerts)
 *   5. Components          (cards, stat cards, score meter, badges, tables,
 *                           buttons, forms, empty states, filter bar,
 *                           details, progress)
 *   6. Chatbot             (window, bubbles, typing indicator)
 *   7. Reasoning diagram + attribution  (Phase 9 / Phase 14 styles, preserved)
 *   8. Readiness report helpers
 *   9. Print
 *
 * Bootstrap semantic vars are overridden so bg-*, text-bg-*, border-* and
 * *-subtle utilities re-theme site-wide; button component props are
 * overridden explicitly (Bootstrap compiles those to literal hex).
 */

/* ── 1. Theme tokens ─────────────────────────────────────────────────────── */

:root {
  /* brand */
  --cc-navy: #1d3557;
  --cc-navy-hover: #16324f;
  --cc-teal: #0f766e;

  /* Bootstrap semantic overrides (contrast-checked on white) */
  --bs-primary: #1d3557;
  --bs-primary-rgb: 29, 53, 87;
  --bs-link-color: #1d3557;
  --bs-link-color-rgb: 29, 53, 87;
  --bs-link-hover-color: #16324f;
  --bs-link-hover-color-rgb: 22, 50, 79;
  --bs-info: #075985;
  --bs-info-rgb: 7, 89, 133;
  --bs-success: #1e7e4f;
  --bs-success-rgb: 30, 126, 79;
  --bs-warning: #b45309;
  --bs-warning-rgb: 180, 83, 9;
  --bs-danger: #b91c1c;
  --bs-danger-rgb: 185, 28, 28;
  --bs-body-bg: #f4f6f9;
  --bs-body-color: #212529;
  --bs-card-bg: #ffffff;
  --bs-border-color: #dde2e8;
  --bs-secondary-color: #5f6b7a;   /* darker than stock muted for AA */
  --bs-secondary-bg: #eef1f5;
  --bs-tertiary-bg: #f8f9fb;
  --bs-body-font-family: system-ui, -apple-system, "Segoe UI", Roboto,
    "Helvetica Neue", "Noto Sans Thai", "Leelawadee UI", sans-serif;

  /* component tokens */
  --cc-radius: 0.5rem;
  --cc-card-shadow: 0 1px 3px rgba(16, 24, 40, 0.08);
  --cc-sidebar-width: 250px;
  --cc-topbar-height: 60px;
  --cc-sidebar-bg: #ffffff;
  --cc-sidebar-border: #e5e9f0;
  --cc-nav-hover-bg: rgba(29, 53, 87, 0.05);
  --cc-nav-active-bg: rgba(29, 53, 87, 0.08);
}

/* ── 2. Base elements ────────────────────────────────────────────────────── */

body.app-body {
  background: var(--bs-body-bg);
  color: var(--bs-body-color);
}

a:focus-visible,
.btn:focus-visible,
.nav-link:focus-visible {
  outline: 2px solid var(--cc-navy);
  outline-offset: 2px;
}

h1, h2, h3, h4, h5, h6 {
  color: var(--cc-navy);
}

code, kbd {
  color: var(--cc-navy);
}

/* Button color props are compiled literal hex in Bootstrap — override here. */
.btn-primary {
  --bs-btn-bg: #1d3557;
  --bs-btn-border-color: #1d3557;
  --bs-btn-hover-bg: #16324f;
  --bs-btn-hover-border-color: #16324f;
  --bs-btn-active-bg: #16324f;
  --bs-btn-active-border-color: #16324f;
  --bs-btn-disabled-bg: #1d3557;
  --bs-btn-disabled-border-color: #1d3557;
  --bs-btn-focus-shadow-rgb: 29, 53, 87;
}
.btn-outline-primary {
  --bs-btn-color: #1d3557;
  --bs-btn-border-color: #1d3557;
  --bs-btn-hover-bg: #1d3557;
  --bs-btn-hover-border-color: #1d3557;
  --bs-btn-active-bg: #16324f;
  --bs-btn-active-border-color: #16324f;
  --bs-btn-disabled-color: #1d3557;
  --bs-btn-disabled-border-color: #1d3557;
  --bs-btn-focus-shadow-rgb: 29, 53, 87;
}

/* ── 3. App shell layout ─────────────────────────────────────────────────── */

.app-main {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.app-content {
  flex: 1;
  padding: 1.5rem 1.5rem 2.5rem;
}

@media (min-width: 992px) {
  .sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 1030;
  }
  .app-main {
    margin-left: var(--cc-sidebar-width);
  }
}

.sidebar {
  display: flex;
  flex-direction: column;
  width: var(--cc-sidebar-width);
  background: var(--cc-sidebar-bg);
  border-right: 1px solid var(--cc-sidebar-border);
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 1rem 1.1rem;
  border-bottom: 1px solid var(--cc-sidebar-border);
  text-decoration: none;
  color: var(--bs-body-color);
  font-weight: 700;
}
.sidebar-brand:hover { color: var(--cc-navy); }

.sidebar-brand-mark {
  width: 2.2rem;
  height: 2.2rem;
  border-radius: 0.55rem;
  background: var(--cc-navy);
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 0.8rem;
  letter-spacing: 0.02em;
  flex: none;
}

.sidebar-brand-text {
  line-height: 1.15;
  font-size: 0.95rem;
}

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 0.85rem 0.85rem 1rem;
}

.sidebar-group-title {
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--bs-secondary-color);
  padding: 0.85rem 0.6rem 0.35rem;
}

.sidebar .nav-link {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.5rem 0.65rem;
  border-radius: var(--cc-radius);
  color: var(--bs-body-color);
  font-size: 0.92rem;
  font-weight: 500;
  border-left: 3px solid transparent;
}
.sidebar .nav-link svg {
  width: 1.05rem;
  height: 1.05rem;
  flex: none;
  opacity: 0.85;
}
.sidebar .nav-link:hover {
  background: var(--cc-nav-hover-bg);
  color: var(--cc-navy);
}
.sidebar .nav-link.active {
  background: var(--cc-nav-active-bg);
  color: var(--cc-navy);
  font-weight: 600;
  border-left-color: var(--cc-navy);
}
.sidebar .nav-link.active svg { opacity: 1; }

.sidebar-footer {
  border-top: 1px solid var(--cc-sidebar-border);
  padding: 0.6rem 0.85rem;
}

/* Top bar */
.topbar {
  display: flex;
  align-items: center;
  gap: 0.9rem;
  min-height: var(--cc-topbar-height);
  padding: 0.5rem 1.5rem;
  background: #fff;
  border-bottom: 1px solid var(--bs-border-color);
  position: sticky;
  top: 0;
  z-index: 1020;
}

.topbar-spacer { flex: 1; }

.topbar-breadcrumb { font-size: 0.85rem; }
.topbar-breadcrumb .breadcrumb { margin: 0; }
.topbar-breadcrumb .breadcrumb-item { color: var(--bs-secondary-color); }
.topbar-breadcrumb .breadcrumb-item.active {
  color: var(--bs-body-color);
  font-weight: 600;
}

/* Language switcher keeps the old active-locale underline affordance. */
.lang-switch .btn-link {
  text-decoration: none;
  color: inherit;
}
.lang-switch .btn-link.disabled {
  text-decoration: underline;
  text-underline-offset: 4px;
  opacity: 1;
}
/* Legacy selector kept for templates that predate the topbar. */
.navbar .nav-link.disabled {
  text-decoration: underline;
  text-underline-offset: 4px;
}

.topbar-user {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.topbar-user .dropdown-toggle {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--bs-body-color);
  text-decoration: none;
  font-weight: 600;
  font-size: 0.92rem;
  background: none;
  border: 1px solid var(--bs-border-color);
  border-radius: 999px;
  padding: 0.35rem 0.85rem;
}
.topbar-user .dropdown-toggle:hover { background: var(--bs-tertiary-bg); }
.topbar-user .dropdown-toggle::after { margin-left: 0.15rem; }

/* Mobile offcanvas reuses the same sidebar include. */
#mobileNav { width: 280px; }
#mobileNav .offcanvas-body { padding: 0; display: flex; }
#mobileNav .sidebar { width: 100%; border-right: 0; }

/* Footer */
.app-footer {
  border-top: 1px solid var(--bs-border-color);
  background: #fff;
  padding: 0.9rem 1.5rem;
  font-size: 0.85rem;
  color: var(--bs-secondary-color);
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

/* ── 4. Page chrome ──────────────────────────────────────────────────────── */

.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1.25rem;
}

.page-title {
  font-size: 1.4rem;
  font-weight: 700;
  margin: 0;
}

.page-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

/* Flash messages */
.flash-alert {
  display: flex;
  align-items: flex-start;
  gap: 0.6rem;
}
.flash-alert .flash-icon {
  flex: none;
  margin-top: 0.1rem;
}

/* ── 5. Components ───────────────────────────────────────────────────────── */

.card {
  border: 1px solid var(--bs-border-color);
  border-radius: var(--cc-radius);
  box-shadow: var(--cc-card-shadow);
}
.card-header {
  background: transparent;
  border-bottom: 1px solid var(--bs-border-color);
  font-weight: 600;
  padding: 0.7rem 1rem;
}
.card-header:first-child {
  border-radius: calc(var(--cc-radius) - 1px) calc(var(--cc-radius) - 1px) 0 0;
}
.card-footer {
  background: transparent;
  border-top: 1px solid var(--bs-border-color);
}

/* Stat cards */
.stat-card {
  display: flex;
  align-items: flex-start;
  gap: 0.9rem;
  padding: 1rem 1.1rem;
  background: var(--bs-card-bg);
  border: 1px solid var(--bs-border-color);
  border-radius: var(--cc-radius);
  box-shadow: var(--cc-card-shadow);
  height: 100%;
}

.stat-icon {
  width: 2.6rem;
  height: 2.6rem;
  border-radius: 0.65rem;
  display: grid;
  place-items: center;
  flex: none;
}
.stat-icon svg { width: 1.3rem; height: 1.3rem; }
.stat-icon--primary { background: rgba(29, 53, 87, 0.10); color: #1d3557; }
.stat-icon--teal    { background: rgba(15, 118, 110, 0.12); color: #0f766e; }
.stat-icon--success { background: rgba(30, 126, 79, 0.12); color: #1e7e4f; }
.stat-icon--warning { background: rgba(180, 83, 9, 0.12); color: #b45309; }
.stat-icon--danger  { background: rgba(185, 28, 28, 0.10); color: #b91c1c; }
.stat-icon--info    { background: rgba(7, 89, 133, 0.12); color: #075985; }

.stat-body { min-width: 0; }
.stat-card-link:hover {
  border-color: var(--cc-navy);
  box-shadow: 0 2px 6px rgba(16, 24, 40, 0.14);
}
.stat-label {
  font-size: 0.78rem;
  color: var(--bs-secondary-color);
  font-weight: 600;
}
.stat-value {
  font-size: 1.45rem;
  font-weight: 700;
  line-height: 1.15;
  color: var(--bs-body-color);
}
.stat-sub {
  font-size: 0.78rem;
  color: var(--bs-secondary-color);
}

/* Score meter — conic-gradient ring driven by inline custom properties.
   Threshold colors are assigned in the template macro; never color-only. */
.score-meter {
  --meter-value: 0;
  --meter-color: var(--bs-primary);
  width: 7.5rem;
  height: 7.5rem;
  border-radius: 50%;
  background: conic-gradient(
    var(--meter-color) calc(var(--meter-value) * 1%),
    var(--bs-secondary-bg) 0
  );
  display: grid;
  place-items: center;
  position: relative;
  flex: none;
}
.score-meter::before {
  content: "";
  position: absolute;
  inset: 0.6rem;
  border-radius: 50%;
  background: var(--bs-card-bg);
}
.score-meter__inner {
  position: relative;
  z-index: 1;
  text-align: center;
  line-height: 1.1;
}
.score-meter__value {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--bs-body-color);
}
.score-meter__label {
  font-size: 0.7rem;
  color: var(--bs-secondary-color);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.score-meter--sm { width: 5rem; height: 5rem; }
.score-meter--sm::before { inset: 0.45rem; }
.score-meter--sm .score-meter__value { font-size: 1.1rem; }
.score-meter--lg { width: 9rem; height: 9rem; }
.score-meter--lg::before { inset: 0.7rem; }
.score-meter--lg .score-meter__value { font-size: 1.8rem; }

/* Badges — pill, heavier weight; light badges read as neutral chips. */
.badge {
  border-radius: 999px;
  font-weight: 600;
  padding: 0.4em 0.7em;
}
.badge.text-bg-light {
  border: 1px solid var(--bs-border-color);
  color: var(--bs-body-color);
}

/* Tables */
.table thead th {
  font-size: 0.76rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 700;
  color: var(--bs-secondary-color);
  background: var(--bs-tertiary-bg);
  border-bottom: 2px solid var(--bs-border-color);
  white-space: nowrap;
}
.table tbody td { padding: 0.6rem 0.75rem; }

/* Buttons + forms */
.btn { border-radius: 0.45rem; }

.form-label {
  font-weight: 600;
  font-size: 0.875rem;
  margin-bottom: 0.35rem;
}
.form-control,
.form-select {
  border-radius: 0.45rem;
}
.form-control:focus,
.form-select:focus {
  border-color: var(--cc-navy);
  box-shadow: 0 0 0 0.2rem rgba(29, 53, 87, 0.14);
}

/* WTForms error list (rendered by _form_macros.render_field) */
.field-errors {
  list-style: none;
  margin: 0.35rem 0 0;
  padding: 0;
  color: var(--bs-danger);
  font-size: 0.85rem;
}

/* Alerts — left accent border per category; default palette stays prominent. */
.alert {
  border-radius: var(--cc-radius);
  border-left-width: 0.35rem;
}
.alert-primary   { border-left-color: var(--bs-primary); }
.alert-secondary { border-left-color: var(--bs-secondary-color); }
.alert-success   { border-left-color: var(--bs-success); }
.alert-danger    { border-left-color: var(--bs-danger); }
.alert-warning   { border-left-color: var(--bs-warning); }
.alert-info      { border-left-color: var(--bs-info); }

/* Empty states */
.empty-state {
  text-align: center;
  padding: 2.5rem 1rem;
  color: var(--bs-secondary-color);
}
.empty-state--inline { padding: 1.25rem 0.75rem; }
.empty-state-icon {
  width: 3.2rem;
  height: 3.2rem;
  margin: 0 auto 0.9rem;
  border-radius: 50%;
  background: var(--bs-tertiary-bg);
  border: 1px solid var(--bs-border-color);
  display: grid;
  place-items: center;
  color: var(--bs-secondary-color);
}
.empty-state-icon svg { width: 1.5rem; height: 1.5rem; }
.empty-state-text { margin-bottom: 0.9rem; }

/* Filter bar (search/filter row above tables) */
.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  align-items: end;
  padding: 0.9rem 1rem;
  background: #fff;
  border: 1px solid var(--bs-border-color);
  border-radius: var(--cc-radius);
  margin-bottom: 1rem;
}
.filter-bar .form-label {
  margin-bottom: 0.2rem;
  font-size: 0.8rem;
}
.filter-bar .form-select,
.filter-bar .form-control {
  min-width: 11rem;
}

/* Evidence / explanation drill-downs */
details.details-inline {
  border-top: 1px solid var(--bs-border-color);
  padding-top: 0.35rem;
  margin-top: 0.35rem;
}
details.details-inline summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--bs-primary);
  list-style: none;
  display: flex;
  align-items: center;
  gap: 0.35rem;
}
details.details-inline summary::-webkit-details-marker { display: none; }
details.details-inline summary::before {
  content: "\25B8";
  font-size: 0.8em;
  transition: transform 0.15s ease;
}
details.details-inline[open] summary::before { transform: rotate(90deg); }

/* Progress bars (readiness + chatbot cards) */
.progress {
  border-radius: 999px;
  background: var(--bs-tertiary-bg);
}
.progress-bar {
  background-color: var(--bs-primary);
  border-radius: 999px;
}

/* ── 6. Chatbot ──────────────────────────────────────────────────────────── */

.chat-window {
  height: 55vh;
  overflow-y: auto;
}

/* Typing indicator (added by site.js, independent of chatbot.js) */
.chat-typing {
  display: flex;
  gap: 0.3rem;
  align-items: center;
  padding: 0.6rem 0.8rem;
}
.chat-typing-dot {
  width: 0.45rem;
  height: 0.45rem;
  border-radius: 50%;
  background: var(--bs-secondary-color);
  animation: chat-pulse 1.2s infinite ease-in-out;
}
.chat-typing-dot:nth-child(2) { animation-delay: 0.15s; }
.chat-typing-dot:nth-child(3) { animation-delay: 0.3s; }
@keyframes chat-pulse {
  0%, 60%, 100% { opacity: 0.35; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-3px); }
}

/* ── 7. Reasoning diagram + model attribution (Phase 9/14, preserved) ────── */

.rp-diagram svg {
  width: 100%;
  height: auto;
  display: block;
}

.rp-node-rect {
  stroke-width: 1.5;
}

.rp-node-rect--student   { fill: var(--bs-primary-bg-subtle);   stroke: var(--bs-primary); }
.rp-node-rect--position  { fill: var(--bs-success-bg-subtle);   stroke: var(--bs-success); }
.rp-node-rect--concept   { fill: var(--bs-secondary-bg-subtle); stroke: var(--bs-secondary); }
.rp-node-rect--artifact  { fill: var(--bs-warning-bg-subtle);   stroke: var(--bs-warning); }
.rp-node-rect--workproblem { fill: var(--bs-danger-bg-subtle);  stroke: var(--bs-danger); }

.rp-node-type {
  font-size: 10px;
  fill: var(--bs-secondary-color);
  font-weight: 600;
}

.rp-node-label {
  font-size: 12px;
  fill: var(--bs-body-color);
}

.rp-edge {
  fill: none;
  stroke: var(--bs-gray-600);
  stroke-width: 1.5;
}

.rp-edge--reversed {
  stroke: var(--bs-gray-500);
  stroke-dasharray: 5 4;
}

.rp-edge-label {
  font-size: 10px;
  fill: var(--bs-secondary-color);
  font-weight: 600;
}

.rp-attribution-card {
  border-left: 4px solid var(--bs-info);
}

.rp-attribution-track {
  background: var(--bs-secondary-bg-subtle);
  border-radius: 0.25rem;
  height: 0.5rem;
  overflow: hidden;
}

.rp-attribution-fill {
  background: var(--bs-info);
  height: 100%;
  border-radius: 0.25rem;
}

/* ── 8. Readiness report helpers (Phase 10, preserved) ───────────────────── */

.readiness-bar-label {
  font-size: 0.8rem;
  min-width: 8.5rem;
  white-space: nowrap;
}

/* ── 9. Print ────────────────────────────────────────────────────────────── */

.print-only { display: none; }

@media print {
  .no-print, nav, .sidebar, .topbar, .app-footer, .page-header, .alert-dismissible .btn-close {
    display: none !important;
  }
  .print-only { display: block; }
  .app-main { margin-left: 0; }
  .app-content, main.container {
    max-width: 100%;
    padding: 0;
    margin: 0;
  }
  .card { border: 1px solid #dee2e6; box-shadow: none; break-inside: avoid; }
  body { background: #fff; }
}
