/* ============================================================
   Insurance Pricing Game — Design Token System
   ============================================================ */

/* --- Color Tokens (Light Theme) --- */
:root {
  --bg-body: #f8fafc;
  --bg-surface: #ffffff;
  --bg-surface-2: #f1f5f9;
  --bg-surface-3: #e2e8f0;
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #94a3b8;
  --text-inverse: #f8fafc;
  --border-color: rgba(15, 23, 42, 0.10);
  --border-strong: rgba(15, 23, 42, 0.20);
  --brand-primary: #2563eb;
  --brand-primary-hover: #1d4ed8;
  --brand-accent: #0ea5e9;
  --success: #16a34a;
  --success-light: #dcfce7;
  --danger: #dc2626;
  --danger-light: #fef2f2;
  --warning: #d97706;
  --warning-light: #fefce8;
  --info: #0284c7;

  /* Spacing */
  --radius: 12px;
  --radius-sm: 8px;
  --radius-lg: 16px;
  --shadow-sm: 0 1px 3px rgba(15, 23, 42, 0.06);
  --shadow-md: 0 4px 16px rgba(15, 23, 42, 0.10);
  --shadow-lg: 0 8px 32px rgba(15, 23, 42, 0.14);

  /* Typography */
  --font-sans: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'Roboto Mono', ui-monospace, SFMono-Regular, monospace;

  /* Chat message colors */
  --chat-user: #2563eb;
  --chat-server: #475569;
  --chat-special: #dc2626;
  --chat-green: #16a34a;
  --chat-orange: #b45309;
  --chat-purple: #7c3aed;
}

/* --- Color Tokens (Dark Theme) --- */
[data-bs-theme="dark"] {
  --bg-body: #0b1220;
  --bg-surface: #0f1b2d;
  --bg-surface-2: #13243b;
  --bg-surface-3: #1a2e4a;
  --text-primary: #e8eefc;
  --text-secondary: #a9b7d0;
  --text-muted: #6b7f9e;
  --text-inverse: #0f172a;
  --border-color: rgba(232, 238, 252, 0.12);
  --border-strong: rgba(232, 238, 252, 0.20);
  --brand-primary: #4c8dff;
  --brand-primary-hover: #3b7df5;
  --brand-accent: #22d3ee;
  --success: #2ecc71;
  --success-light: rgba(46, 204, 113, 0.15);
  --danger: #ff5a6a;
  --danger-light: rgba(255, 90, 106, 0.15);
  --warning: #f5c84c;
  --warning-light: rgba(245, 200, 76, 0.15);
  --info: #38bdf8;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.20);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.30);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.40);

  --chat-user: #4c8dff;
  --chat-server: #a9b7d0;
  --chat-special: #ff5a6a;
  --chat-green: #2ecc71;
  --chat-orange: #f5c84c;
  --chat-purple: #a78bfa;
}

/* --- Global Overrides --- */
body {
  font-family: var(--font-sans);
  background-color: var(--bg-body);
  color: var(--text-primary);
}

/* --- Utility Classes --- */
.u-mono { font-family: var(--font-mono); }
.u-text-muted { color: var(--text-muted); }
.u-text-secondary { color: var(--text-secondary); }

/* --- Widescreen Container --- */
.container-game { max-width: 1200px; margin-inline: auto; padding-inline: 1rem; }
@media (min-width: 1400px) { .container-game { max-width: 1360px; } }
@media (min-width: 1600px) { .container-game { max-width: 1520px; } }

/* --- Navbar Override --- */
.navbar-game {
  background-color: var(--bg-surface);
  border-bottom: 1px solid var(--border-color);
  box-shadow: var(--shadow-sm);
}
.navbar-game .navbar-brand {
  font-weight: 600;
  color: var(--text-primary);
}
.navbar-game .brand-mark {
  height: 36px;
  width: auto;
}
.navbar-game .nav-link {
  color: var(--text-secondary);
  font-weight: 500;
}
.navbar-game .nav-link:hover,
.navbar-game .nav-link.active {
  color: var(--brand-primary);
}

/* --- Section Title --- */
.section-title {
  font-weight: 600;
  color: var(--brand-primary);
  font-size: 1rem;
}

/* --- Panel Component --- */
.panel {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 1.5rem;
}
.panel--accent { border-left: 3px solid var(--brand-primary); }
.panel--success { border-left: 3px solid var(--success); }
.panel--danger { border-left: 3px solid var(--danger); }
.panel--warning { border-left: 3px solid var(--warning); }
.panel--dense { padding: 1rem; }
.panel-title {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 0.75rem;
}

/* --- Table Components --- */
.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--border-color);
  border-radius: var(--radius);
}
.table-financial {
  width: 100%;
  font-family: var(--font-mono);
  font-size: 0.9375rem;
  margin-bottom: 0;
  border-collapse: collapse;
}
.table-financial thead th {
  background: var(--bg-surface-2);
  color: var(--text-secondary);
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 2px solid var(--border-strong);
}
.table-financial th,
.table-financial td {
  white-space: nowrap;
  text-align: right;
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--border-color);
  color: var(--text-primary);
}
.table-financial th:first-child,
.table-financial td:first-child {
  text-align: left;
  font-weight: 600;
}
.table-financial tbody tr:hover {
  background: var(--bg-surface-2);
}
.table-financial tr:nth-child(even) {
  background: var(--bg-surface-2);
}

/* --- Report Grid (Dashboard) --- */
.report-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.75rem;
}
@media (max-width: 767.98px) {
  .report-grid { grid-template-columns: repeat(2, 1fr); }
}
.report-tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem;
  border-radius: var(--radius-sm);
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  text-decoration: none;
  color: var(--text-primary);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.report-tile:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
  color: var(--brand-primary);
  text-decoration: none;
}
.report-tile img {
  width: 48px;
  height: 48px;
}
@media (min-width: 992px) {
  .report-tile img { width: 56px; height: 56px; }
}
.report-tile--disabled {
  opacity: 0.45;
  filter: grayscale(100%);
  cursor: not-allowed;
  /* pointer-events: auto so title tooltip remains accessible on hover */
}
.report-tile--disabled:hover {
  transform: none;
  box-shadow: none;
  color: var(--text-primary);
}
.report-tile__label {
  font-size: 0.75rem;
  font-weight: 600;
  text-align: center;
}
/* Subtitle shown on disabled tiles to explain unavailability (#102) */
.report-tile__subtitle {
  font-size: 0.6rem;
  font-weight: 400;
  color: var(--text-muted);
  text-align: center;
  line-height: 1.2;
}

/* --- Chat Component --- */
.chat-panel {
  display: flex;
  flex-direction: column;
  height: 100%;
}
.chat-log {
  flex: 1;
  max-height: 320px;
  overflow-y: auto;
  font-size: 0.875rem;
  font-family: var(--font-mono);
  padding: 0.75rem;
  background: var(--bg-surface-2);
  border-radius: var(--radius-sm);
}
.chat-row { white-space: pre-wrap; word-break: break-word; padding: 0.125rem 0; }
.chat-row--user { color: var(--chat-user); }
.chat-row--server { color: var(--chat-server); }
.chat-row--special { color: var(--chat-special); font-weight: 600; }
.chat-row--green { color: var(--chat-green); }
.chat-row--orange { color: var(--chat-orange); }
.chat-row--purple { color: var(--chat-purple); }

.chat-status {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  font-size: 0.75rem;
  font-weight: 600;
}
.chat-status::before {
  content: '';
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--success);
  animation: pulse 2s infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

/* --- Countdown Timer --- */
.countdown-timer {
  font-family: var(--font-mono);
  font-size: 1.25rem;
  font-weight: 700;
  padding: 0.5rem 0;
}
.countdown-timer--ok { color: var(--success); }
.countdown-timer--warn { color: var(--warning); }
.countdown-timer--urgent { color: var(--danger); }

/* --- Indication / Decision Layout --- */
.kpi-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.375rem 0;
  font-family: var(--font-mono);
  font-size: 0.9375rem;
}
.kpi-row__label {
  color: var(--text-secondary);
  font-family: var(--font-sans);
  font-weight: 500;
}
.kpi-row__value {
  font-weight: 600;
  color: var(--text-primary);
}

/* --- Hero Section --- */
.hero {
  position: relative;
  padding: 6rem 0 5rem;
  color: #fff;
  overflow: hidden;
  background-color: #1e293b; /* fallback when background image is absent or slow */
}
.hero::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(15, 23, 42, 0.82), rgba(8, 47, 73, 0.72));
  z-index: 1;
}
.hero > * { position: relative; z-index: 2; }
.hero--bg {
  background-size: cover;
  background-position: center;
}
/* Widescreen: reposition hero background so the CN Tower pod is visible */
@media (min-width: 992px) {
  .hero--bg {
    background-position: 52% 39%;
    padding: 10rem 0 8rem;
    min-height: 60vh;
  }
}

/* --- Dark Section Override --- */
.section-dark {
  background: var(--bg-surface-2);
  color: var(--text-primary);
}

/* --- Action Buttons --- */
.btn-game {
  background: var(--brand-primary);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font-weight: 600;
  padding: 0.5rem 1.25rem;
  transition: background 0.15s ease;
}
.btn-game:hover {
  background: var(--brand-primary-hover);
  color: #fff;
}
/* Dark mode: use the same darker blues as light mode for white-text buttons.
   --brand-primary dark (#4c8dff) looks great on dark backgrounds but gives
   only 3.2:1 contrast with white text — below WCAG AA (4.5:1).
   #2563eb / #1d4ed8 give 5.2:1 / 6.8:1. */
[data-bs-theme="dark"] .btn-game {
  background: #2563eb;
}
[data-bs-theme="dark"] .btn-game:hover {
  background: #1d4ed8;
}
/* Let Bootstrap manage border-radius inside input-groups */
.input-group .btn-game {
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

/* --- Messages container spacing for fixed navbar --- */
.messages-container {
  padding-top: 96px;
}

/* --- Color utility classes (for data display) --- */
.text-success-data { color: var(--success); }
.text-danger-data { color: var(--danger); }
.text-warning-data { color: var(--warning); }
.text-info-data { color: var(--info); }

/* --- Footer Override --- */
.page-footer {
  background: var(--bg-surface);
  border-top: 1px solid var(--border-color);
  color: var(--text-secondary);
  padding: 2rem 0 1rem;
}
.page-footer h5 {
  font-size: 0.875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-primary);
  margin-bottom: 0.75rem;
}
.page-footer ul {
  list-style: none;
  padding: 0;
}
.page-footer ul li {
  margin-bottom: 0.375rem;
}
.page-footer a {
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 0.875rem;
}
.page-footer a:hover {
  color: var(--brand-primary);
}
.footer-copyright {
  text-align: center;
  padding-top: 1rem;
  border-top: 1px solid var(--border-color);
  margin-top: 1.5rem;
  font-size: 0.8125rem;
  color: var(--text-secondary);
}
.footer-link-btn {
  background: none;
  border: none;
  padding: 0;
  margin: 0;
  cursor: pointer;
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 0.875rem;
  font-family: inherit;
}
.footer-link-btn:hover {
  color: var(--brand-primary);
}

/* --- Password Reset / allauth pages (clean-form) --- */
/* Bootstrap default link (#0d6efd) gives only 4.27:1 on the page's light-gray
   background (#f8f9fa). --brand-primary (#2563eb) gives 4.56:1 (WCAG AA). */
.clean-form a {
  color: var(--brand-primary);
}

/* --- Form Enhancements --- */
.form-control, .form-select {
  border-radius: var(--radius-sm);
}
/* Bootstrap's default .form-text / .text-muted uses BS internal vars that may
   give low contrast against our custom dark background (#0f1b2d). Override to
   use our theme token which is calibrated for both light and dark surfaces.
   Fixes #92: Register page password requirements text low contrast. */
.form-text {
  color: var(--text-secondary);
}

/* --- Main Content Spacing (for fixed navbar) --- */
/* Navbar measured at ~85px (brand-mark 36px + brand padding 10px + navbar
   padding 2×19.2px + border 1px). Use 6rem (96px) for a comfortable 11px
   clear. Fixes: "Back to Game Select" and other elements hidden behind navbar. */
.content-main {
  padding-top: 6rem;
  padding-bottom: 2rem;
}
/* Allauth/account pages use <main class="page landing-page"> instead of
   .content-main — they need the same navbar clearance. */
.page.landing-page {
  padding-top: 6rem;
  padding-bottom: 2rem;
}

/* --- OSFI Regulatory --- */
.osfi-text {
  font-weight: 700;
  color: var(--danger);
}

/* --- Skip to Content --- */
.skip-link {
  position: absolute;
  top: -100%;
  left: 1rem;
  z-index: 9999;
  padding: 0.5rem 1rem;
  background: var(--brand-primary);
  color: #fff;
  border-radius: var(--radius-sm);
  font-weight: 600;
  text-decoration: none;
  transition: top 0.15s ease;
}
.skip-link:focus {
  top: 0.5rem;
  color: #fff;
}
/* Dark mode: --brand-primary (#4c8dff) gives only 3.2:1 with white text.
   Use same darker blue as light mode (#2563eb = 5.2:1). */
[data-bs-theme="dark"] .skip-link {
  background: #2563eb;
}

/* --- Focus Visible --- */
:focus-visible {
  outline: 2px solid var(--brand-primary);
  outline-offset: 2px;
}
.btn:focus-visible,
.form-control:focus-visible,
.form-select:focus-visible,
.nav-link:focus-visible {
  outline: 2px solid var(--brand-primary);
  outline-offset: 2px;
  box-shadow: none;
}

/* --- Touch Targets (min 44x44px) --- */
@media (pointer: coarse) {
  .btn { min-height: 44px; min-width: 44px; }
  .btn-sm { min-height: 44px; padding-inline: 0.75rem; }
  .form-select-sm { min-height: 44px; }
  .nav-link { padding: 0.75rem 0.5rem; }
  .report-tile { min-height: 88px; }
  .coverage-btn, .metric-btn { min-height: 44px; }
}

/* --- Navbar Mobile: prevent brand from pushing toggler to a second line --- */
/* On narrow viewports the brand text "Insurance Pricing Game" + icon can exceed
   available width, causing Bootstrap's flex-wrap to push the toggler down.
   Constraining max-width and enabling overflow:hidden keeps brand + toggler
   on a single line. Fixes #93: mobile hamburger on separate line. */
@media (max-width: 991.98px) {
  .navbar-game .navbar-brand {
    flex-shrink: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: calc(100% - 56px); /* 56px ≈ toggler width + gap */
  }
}

/* --- Responsive helpers --- */
@media (max-width: 575.98px) {
  /* Extra navbar clearance on narrow mobile (navbar may vary in height) */
  .content-main,
  .page.landing-page { padding-top: 6.5rem; }
  .panel { padding: 1rem; }
  .table-financial { font-size: 0.75rem; }
  .financial-data-table th,
  .financial-data-table td,
  .mktgsales-data-table th,
  .mktgsales-data-table td,
  .industry-data-table th,
  .industry-data-table td { font-size: 0.6875rem; padding: 0.25rem 0.375rem; }
  .countdown-timer { font-size: 1rem; }
  .section-title { font-size: 0.875rem; }
  .panel-title { font-size: 0.75rem; }
  h4 { font-size: 1.125rem; }
}

/* --- Dark Mode Select Options (#89) --- */
/* Native <select> dropdown options respect OS rendering, but we can hint the
   preferred dark colours for browsers that support option styling (Chromium,
   Firefox). Safari falls back to OS-native, which is acceptable. */
[data-bs-theme="dark"] .form-select option,
[data-bs-theme="dark"] select option {
  background-color: var(--bg-surface-2);
  color: var(--text-primary);
}

/* --- Reduced Motion --- */
@media (prefers-reduced-motion: reduce) {
  .report-tile { transition: none; }
  .chat-status::before { animation: none; }
  .skip-link { transition: none; }
}
