/* === DESIGN TOKENS === */
:root {
  /* Brand */
  --brand: #204a80;
  --brand-hover: #173a67;
  --brand-rgb: 32, 74, 128;
  --accent: #3767c7;
  --accent-end: #1f4d9d;
  --focus-ring: #0f62fe;
  --focus-shadow: rgba(15, 98, 254, 0.28);
  --on-brand: #ffffff;
  --on-warning: #ffffff;

  /* Text */
  --text-primary: #111827;
  --text-secondary: #253041;
  --text-muted: #4b5563;
  --text-faint: #556274;

  /* Surfaces */
  --bg-page: #edf2f8;
  --bg-card: #ffffff;
  --bg-subtle: #f6f8fb;
  --bg-code: #eef2f7;
  --bg-elevated: #ffffff;
  --bg-elevated-strong: #ffffff;

  /* Borders */
  --border-light: #d7dfeb;
  --border: var(--border-light);
  --border-dashed: #bcc7d6;

  /* Error */
  --error: #d14343;
  --error-hover: #b93636;
  --error-bg: #fdeaea;

  /* Status */
  --success: #166534;
  --success-alt: #0f9f6e;
  --warning: #b45309;
  --danger: #b42318;

  /* Badge surfaces (service-card status badges) */
  --badge-ok-bg: #dcfce7;
  --badge-ok-border: #86efac;
  --badge-neutral-bg: #e8eef5;
  --badge-neutral-text: #475569;
  --badge-neutral-border: #cbd5e1;

  /* Shadows */
  --shadow-sm: 0 2px 12px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 4px 24px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 5px 20px rgba(0, 0, 0, 0.1);

  /* Radii */
  --radius: 4px;
  --radius-sm: 2px;
  --radius-md: 4px;
  --radius-lg: 6px;
  --radius-xl: 8px;
  --radius-2xl: 10px;
  --radius-3xl: 12px;
  --radius-4xl: 16px;
  --radius-pill: 999px;

  /* Font */
  --font-sans: "Aptos", "IBM Plex Sans", "Segoe UI Variable Text", "Segoe UI", "Source Sans 3", "Noto Sans", sans-serif;
  --font-heading: "Aptos Display", "IBM Plex Sans", "Segoe UI Variable Display", "Segoe UI", "Source Sans 3", sans-serif;
  --font-mono: "IBM Plex Mono", "Cascadia Code", "SFMono-Regular", "Consolas", monospace;

  /* Typography scale */
  --fs-xs: 0.625rem;       /* 10px — tiny labels, badge text */
  --fs-label: 0.6875rem;   /* 11px — UPPERCASE section labels */
  --fs-sm: 0.75rem;        /* 12px — help text, secondary info */
  --fs-base-sm: 0.8125rem; /* 13px — small body, feedback messages */
  --fs-body: 0.875rem;     /* 14px — body text (default) */
  --fs-body-lg: 0.9375rem; /* 15px — chat messages, prominent body */
  --fs-base: 1rem;         /* 16px — base / form controls */
  --fs-md: 1.0625rem;      /* 17px — dialog titles, emphasized body */
  --fs-xl: 1.375rem;       /* 22px — page sub-headings */
  --fs-2xl: 1.625rem;      /* 26px — section stat values */
  --fs-stat: 2rem;         /* 32px — primary stat display */

  /* Spacing scale (4px grid — use for gap / single-side padding) */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-7: 28px;

  /* Elevation */
  --focus-ring-shadow: 0 0 0 4px var(--focus-shadow);
  --focus-ring-shadow-sm: 0 0 0 2px var(--focus-ring);
  --shadow-dialog: 0 20px 60px rgba(0, 0, 0, 0.25);

  /* Animation */
  --transition-fast: 0.15s;
  --transition-normal: 0.25s;
  --transition-slow: 0.4s;
  --ease-out-expo: cubic-bezier(0.19, 1, 0.22, 1);

  /* Shell sizing */
  --shell-rail-width: 3.5rem;
  --shell-sidebar-width: 16.25rem;
  --shell-sidebar-width-mobile: 17.5rem;
  --shell-header-height: 3.5rem;
  --shell-header-height-mobile: 3rem;
  --shell-control-size: 2.25rem;
  --shell-control-size-compact: 2rem;
  --shell-icon-size: 1.25rem;
  --shell-avatar-size: 2.5em;
  --shell-avatar-size-compact: 2.222222em;
}

/* === DARK THEME ===
 * Override block for all color tokens — structure mirrors :root exactly.
 * Toggled via JS: document.documentElement.setAttribute('data-theme', 'dark').
 * themeController.js persists the preference in localStorage('theme').
 * When adding a new color token, always add a dark-mode counterpart here.
 * Light backgrounds (#edf2f8 → #0b1220), surfaces (#fff → #182235), borders muted.
 */
[data-theme="dark"] {
  /* Brand */
  --brand: #9fc3ff;
  --brand-hover: #c2d7ff;
  --brand-rgb: 159, 195, 255;
  --accent: #7fb0ff;
  --accent-end: #a8c7ff;
  --focus-ring: #c2d7ff;
  --focus-shadow: rgba(159, 195, 255, 0.34);
  --on-brand: #08111f;
  --on-warning: #1f1600;

  /* Text */
  --text-primary: #f8fbff;
  --text-secondary: #e7eef8;
  --text-muted: #c3d0e0;
  --text-faint: #9fb0c7;

  /* Surfaces */
  --bg-page: #0b1220;
  --bg-card: #182235;
  --bg-subtle: #22304a;
  --bg-code: #111b2c;
  --bg-elevated: #0f1724;
  --bg-elevated-strong: #121c2b;

  /* Borders */
  --border-light: #44546d;
  --border: var(--border-light);
  --border-dashed: #5b6b85;

  /* Error */
  --error: #ff8f8f;
  --error-hover: #ffb0b0;
  --error-bg: #472427;

  /* Status */
  --success: #7ee2a8;
  --success-alt: #10b981;
  --warning: #ffd166;
  --danger: #ff9b8f;

  /* Badge surfaces */
  --badge-ok-bg: color-mix(in srgb, var(--success) 22%, var(--bg-page));
  --badge-ok-border: color-mix(in srgb, var(--success) 46%, var(--bg-page));
  --badge-neutral-bg: #1a2436;
  --badge-neutral-text: #b0bfd2;
  --badge-neutral-border: #405069;

  /* Quill Editor Dark */
  --ql-bg: #1a2538;
  --ql-bg-hover: #22304a;
  --ql-bg-editor: #141d2d;
  --ql-bg-code: #0f1726;
  --ql-border: #43536d;
  --ql-border-light: #5b6b85;

  /* Shadows */
  --shadow-sm: 0 2px 12px rgba(0, 0, 0, 0.2);
  --shadow-md: 0 4px 24px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 5px 20px rgba(0, 0, 0, 0.4);
}

/* === RESET ===
 * Global reset + typography baseline.
 * Key classes:
 *   .skip-link        — keyboard-accessible "skip to content" link (visually hidden until :focus-visible)
 *   .visually-hidden  — SR-only content (accessibility, not display:none)
 *   .hidden           — utility: display:none !important (toggled by JS)
 * Focus ring: :focus-visible uses --focus-ring / --focus-shadow tokens.
 * Reduced motion: all transitions/animations compressed to 0.01ms.
 */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: var(--font-sans);
  min-height: 100vh;
  background: var(--bg-page);
  color: var(--text-primary);
  line-height: 1.55;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

html {
  color-scheme: light;
}

[data-theme="dark"] {
  color-scheme: dark;
}

h1,
h2,
h3,
h4,
h5,
h6,
.login-title,
.login-welcome,
.page-header h1,
.app-page-title,
.docs-brand h1,
.docs-hero h2 {
  font-family: var(--font-heading);
  letter-spacing: -0.02em;
}

a,
button,
input,
select,
textarea,
[tabindex]:not([tabindex="-1"]) {
  -webkit-tap-highlight-color: transparent;
}

:focus-visible {
  outline: 3px solid var(--focus-ring);
  outline-offset: 3px;
}

:focus:not(:focus-visible) {
  outline: none;
}

@media (prefers-reduced-motion: reduce) {

  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}

.skip-link {
  position: absolute;
  inset-inline-start: 16px;
  top: 12px;
  z-index: 2000;
  padding: 10px 14px;
  border-radius: var(--radius-md);
  background: var(--brand);
  color: var(--on-brand);
  text-decoration: none;
  transform: translateY(-160%);
  transition: transform var(--transition-fast);
}

.skip-link:focus-visible {
  transform: translateY(0);
}

/* === SCREENS ===
 * Top-level visibility switch between login and app shell.
 * HTML: <div class="screen" id="loginScreen"> and <div class="screen" id="contentScreen">
 * JS: routeController.showScreen('loginScreen' | 'contentScreen')
 * Only one .screen is .active at a time. .active triggers fadeIn animation.
 * #contentScreen uses display:flex (not block) — never override to block.
 */
.screen {
  display: none;
  width: 100%;
  animation: fadeIn var(--transition-slow) ease-in;
}

.screen.active {
  display: block;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes fadeInOpacity {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}

/* SVG sprite wrapper — inline styles ignored by Chrome on SVG/wrapper */
.svg-sprite-wrapper {
  display: none;
}

/* ==============================
   LOGIN PAGE
   Template: templates/login-screen.html
   Controller: authController.js (renderLoginScreen via routeController.js)
   ──────────────────────────────────────
   .login-page               full-viewport flex column
   .top-controls             lang + theme toggle (position:absolute top-right)
   .login-card               main card (max-width 520px)
   .login-btn                Microsoft sign-in button (background:--brand)
   .login-info-card          info link card below main card (hover: lift)
   .icon-brand / .icon-muted / .icon-ms — SVG stroke/fill helpers
   .theme-icon-dark / .theme-icon-light — toggled by [data-theme="dark"]
   Responsive: ≤600px — card padding reduced, info cards stack
   ============================== */
.login-page {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 20px 0;
  position: relative;
  background: var(--bg-page);
}

[data-theme="dark"] .login-page {
  background: var(--bg-page);
}

/* --- Header --- */
.login-header {
  text-align: center;
  margin-bottom: 32px;
}

.login-logo {
  width: 56px;
  height: 56px;
  margin: 0 auto 16px;
  background-color: var(--brand);
  border: 1px solid var(--border-light);
  border-radius: 10px;
  box-shadow: var(--shadow-sm);
  -webkit-mask-image: url("../img/logo.svg");
  mask-image: url("../img/logo.svg");
  -webkit-mask-size: contain;
  mask-size: contain;
  -webkit-mask-repeat: no-repeat;
  mask-repeat: no-repeat;
  -webkit-mask-position: center;
  mask-position: center;
}

.login-title {
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--brand);
  letter-spacing: -0.5px;
}

.login-subtitle {
  color: var(--text-muted);
  font-size: 0.875rem;
  margin-top: 4px;
}

/* --- Main Card --- */
.login-card {
  background: var(--bg-subtle);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border-light);
  padding: 36px;
  width: 100%;
  max-width: 520px;
  text-align: center;
}

.login-welcome {
  font-size: 1.375rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 8px;
  text-align: left;
}

.login-desc {
  color: var(--text-muted);
  font-size: 0.875rem;
  text-align: left;
  margin-bottom: 28px;
  line-height: 1.5;
}

/* --- Sign In Button --- */
.login-btn-wrapper {
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  padding: 8px;
  margin-bottom: 24px;
  background: var(--bg-card);
}

.login-btn {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: var(--brand);
  color: var(--on-brand);
  border: 1px solid var(--brand);
  padding: 14px 24px;
  font-size: 0.9375rem;
  font-weight: 600;
  border-radius: var(--radius-md);
  cursor: pointer;
  box-shadow: none;
  transition: background var(--transition-fast), border-color var(--transition-fast), transform var(--transition-fast);
}

.login-btn:hover {
  background: var(--brand-hover);
  border-color: var(--brand-hover);
  transform: translateY(-1px);
}

.login-btn:active {
  transform: translateY(0);
}

/* --- SVG icon colors (single source of truth) --- */

.icon-brand {
  fill: none;
  stroke: var(--brand);
}

.icon-muted {
  fill: none;
  stroke: var(--text-muted);
}

.icon-ms {
  fill: var(--on-brand);
  stroke: none;
}

/* --- Info Cards --- */
.login-info-cards {
  display: flex;
  gap: 16px;
  margin-top: 32px;
  width: 100%;
  max-width: 520px;
}

.login-info-card {
  flex: 1;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  background: var(--bg-card);
  border-radius: var(--radius-md);
  padding: 16px 20px;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border-light);
  text-decoration: none;
  color: inherit;
  transition: transform var(--transition-fast), box-shadow var(--transition-fast), border-color var(--transition-fast);
}

.login-info-card:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
  border-color: var(--brand);
  background: var(--bg-subtle);
}

.login-info-card strong {
  font-size: 0.8125rem;
  color: var(--text-primary);
  display: block;
}

.login-info-card p {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.login-info-card svg {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  padding: 8px;
  border-radius: 8px;
  background: var(--brand);
  border: 1px solid var(--brand);
  color: var(--on-brand);
}

.login-info-card .icon-brand {
  stroke: var(--on-brand);
  color: var(--on-brand);
}

/* --- Bottom Links --- */
.login-bottom-links {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-top: 24px;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.login-bottom-links a {
  color: var(--text-muted);
  text-decoration: none;
  transition: color var(--transition-normal);
}

.login-bottom-links a:hover {
  color: var(--brand);
}

.login-bottom-sep {
  color: var(--border-light);
}

/* --- Top Controls (lang + theme) --- */
.top-controls {
  position: absolute;
  top: 20px;
  right: 24px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.top-control-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-subtle);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  padding: 6px 12px;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition:
    color var(--transition-normal),
    border-color var(--transition-normal),
    box-shadow var(--transition-normal);
}

.top-control-btn:hover {
  color: var(--brand);
  border-color: var(--brand);
  background: var(--bg-card);
  box-shadow: var(--shadow-md);
}

.top-control-btn svg {
  flex-shrink: 0;
  display: block;
}

/* Theme icon visibility — CSS-driven via [data-theme] attribute on <html>. */
.theme-icon-dark { display: none; }
[data-theme="dark"] .theme-icon-dark { display: block; }
[data-theme="dark"] .theme-icon-light { display: none; }

/* --- Login Responsive --- */
@media (max-width: 600px) {
  .login-card {
    padding: 28px 20px;
  }

  .login-info-cards {
    flex-direction: column;
  }

  .login-bottom-links {
    flex-wrap: wrap;
    justify-content: center;
  }
}