@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&family=IBM+Plex+Sans:wght@400;500;600;700&display=swap');

@tailwind base;
@tailwind components;
@tailwind utilities;

@layer base {
  :root {
    /* === Tailwind System Variables === */
    --tw-background: 0 0% 100%;
    --tw-foreground: 222.2 84% 4.9%;
    --tw-card: 0 0% 100%;
    --tw-card-foreground: 222.2 84% 4.9%;
    --tw-popover: 0 0% 100%;
    --tw-popover-foreground: 222.2 84% 4.9%;
    --tw-primary: 215 100% 33.5%;
    --tw-primary-foreground: 210 40% 98%;
    --tw-secondary: 210 40% 96.1%;
    --tw-secondary-foreground: 222.2 47.4% 11.2%;
    --tw-muted: 210 40% 96.1%;
    --tw-muted-foreground: 215.4 16.3% 46.9%;
    --tw-accent: 38.8 100% 50%;
    --tw-accent-foreground: 222.2 47.4% 11.2%;
    --tw-destructive: 0 84.2% 60.2%;
    --tw-destructive-foreground: 210 40% 98%;
    --tw-border: 214.3 31.8% 91.4%;
    --tw-input: 214.3 31.8% 91.4%;
    --tw-ring: 215 100% 33.5%;
    --tw-chart-1: 12 76% 61%;
    --tw-chart-2: 173 58% 39%;
    --tw-chart-3: 197 37% 24%;
    --tw-chart-4: 43 74% 66%;
    --tw-chart-5: 27 87% 67%;

    /* === Primary Brand Colors === */
    --primary: #0047AB;        /* Royal Blue */
    --primary-dark: #003080;
    --primary-light: #1a5cc0;
    --primary-50: #e6eef9;
    --primary-100: #c2d4f0;

    --accent: #FFA500;          /* Tangerine Orange */
    --accent-dark: #cc8400;
    --accent-light: #ffb733;
    --accent-50: #fff5e0;
    --accent-100: #ffe6b3;

    --slate: #002147;           /* Slate Navy */
    --slate-light: #1a3a66;
    --slate-50: #e6ebf2;

    /* === Surfaces === */
    --background: #ffffff;
    --background-alt: 247 249 252; /* #f7f9fc */
    --surface: 255 255 255; /* #ffffff */
    --card: #ffffff;
    --card-elevated: #ffffff;
    --border: #e3e8ef;
    --border-light: #f0f3f7;
    --divider: #e3e8ef;

    /* === Text Colors ===
       NFR6 fix (2026-07-29): --text-muted was #8696ad which only
       reaches 3:1 contrast on white — well below WCAG AA's 4.5:1
       threshold for normal text. Bumped to #4a6585 (formerly
       --text-light) so all `text-text-muted` instances pass AA.
       Anything that needs a softer gray now uses --text-light
       explicitly, or an opacity-suffixed Tailwind class.
    */
    --text: #002147;
    --text-secondary: #1a3a66;
    --text-light: #5a6a82;
    --text-muted: #4a6585;
    --text-inverse: #ffffff;

    /* === LMS & SMS Accents === */
    --lms: #008080;
    --sms: #4CAF50;

    /* === Shadows & Radius === */
    --shadow-sm: 0 1px 2px 0 rgba(0, 33, 71, 0.05);
    --shadow: 0 1px 3px 0 rgba(0, 33, 71, 0.08);
    --radius-xl: 1.5rem;
    --radius-full: 9999px;
    
    --font-heading: 'Inter', sans-serif;
    --font-body: 'IBM Plex Sans', sans-serif;
  }

  .dark {
    /* === Tailwind System Variables Overrides === */
    --tw-background: 222.2 84% 4.9%;
    --tw-foreground: 210 40% 98%;
    --tw-card: 222.2 84% 4.9%;
    --tw-card-foreground: 210 40% 98%;
    --tw-popover: 222.2 84% 4.9%;
    --tw-popover-foreground: 210 40% 98%;
    --tw-primary: 211 91% 59.4%; /* Lighter blue for dark mode */
    --tw-primary-foreground: 0 0% 100%;
    --tw-secondary: 217.2 32.6% 17.5%;
    --tw-secondary-foreground: 210 40% 98%;
    --tw-muted: 217.2 32.6% 17.5%;
    --tw-muted-foreground: 215 20.2% 65.1%;
    --tw-accent: 38.8 100% 50%; /* Keep NextGen Orange in Dark Mode */
    --tw-accent-foreground: 222.2 47.4% 11.2%;
    --tw-destructive: 0 62.8% 30.6%;
    --tw-destructive-foreground: 210 40% 98%;
    --tw-border: 217.2 32.6% 17.5%;
    --tw-input: 217.2 32.6% 17.5%;
    --tw-ring: 212.7 26.8% 83.9%;

    /* === Primary Brand Colors Overrides === */
    --primary: #3b82f6;        /* Lighter Blue for Dark Mode */
    --primary-50: #0d2a52;
    --primary-100: #1a3a66;

    --slate: #f1f5f9;          /* Invert slate for dark mode headers */
    --slate-light: #e2e8f0;
    --slate-50: #0d2a52;

    /* === Surfaces Overrides === */
    --background: #020617;     /* Very deep navy */
    --background-alt: 0 12 36;
    --surface: 0 26 56;        /* Sidebar-like surface */
    --card: #001a38;
    --card-elevated: #002147;
    --border: #1a3a66;
    --border-light: #0d2a52;
    --divider: #1a3a66;

    /* === Text Colors Overrides === */
    --text: #f1f5f9;
    --text-secondary: #cbd5e1;
    --text-light: #94a3b8;
    --text-muted: #64748b;
  }
}

@layer base {
  * {
    @apply border-border transition-colors duration-200;
  }
  body {
    @apply bg-background text-text;
    font-family: var(--font-body);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
  }
  h1, h2, h3, h4, h5, h6 {
    font-family: var(--font-heading);
    color: var(--slate);
    font-weight: 700;
    letter-spacing: -0.01em;
  }
}

/* === Base Styles & Dynamic Font Scaling === */
:root {
  --font-scale-factor: 1;
  --base-font-size: 16px;
  font-size: calc(var(--base-font-size) * var(--font-scale-factor));
}

[data-font-size="100"] { --font-scale-factor: 1.00; }
[data-font-size="125"] { --font-scale-factor: 1.25; }
[data-font-size="150"] { --font-scale-factor: 1.50; }
[data-font-size="175"] { --font-scale-factor: 1.75; }
[data-font-size="200"] { --font-scale-factor: 2.00; }

/* Fluid Typography Utilities */
.text-fluid-xs   { font-size: clamp(0.75rem,  0.70rem + 0.25vw, 0.875rem); }
.text-fluid-sm   { font-size: clamp(0.875rem, 0.80rem + 0.35vw, 1.00rem);  }
.text-fluid-base { font-size: clamp(1.00rem,  0.90rem + 0.50vw, 1.125rem); }
.text-fluid-lg   { font-size: clamp(1.125rem, 1.00rem + 0.60vw, 1.25rem);  }
.text-fluid-xl   { font-size: clamp(1.25rem,  1.10rem + 0.75vw, 1.50rem);  }
.text-fluid-2xl  { font-size: clamp(1.50rem,  1.30rem + 1.00vw, 2.00rem);  }

/* Dynamic Mobile Screen Features Adaptation at High Font Scale (150% and up) */
html[data-font-size="150"] aside.hidden.lg\:flex,
html[data-font-size="175"] aside.hidden.lg\:flex,
html[data-font-size="200"] aside.hidden.lg\:flex {
  display: none !important;
}

html[data-font-size="150"] header.lg\:hidden,
html[data-font-size="175"] header.lg\:hidden,
html[data-font-size="200"] header.lg\:hidden,
html[data-font-size="150"] nav.lg\:hidden,
html[data-font-size="175"] nav.lg\:hidden,
html[data-font-size="200"] nav.lg\:hidden,
html[data-font-size="150"] .mobile-drawer-aside,
html[data-font-size="175"] .mobile-drawer-aside,
html[data-font-size="200"] .mobile-drawer-aside {
  display: flex !important;
}

html[data-font-size="150"] .mobile-overlay-active,
html[data-font-size="175"] .mobile-overlay-active,
html[data-font-size="200"] .mobile-overlay-active {
  display: block !important;
}

html[data-font-size="150"] .lg\:pl-64,
html[data-font-size="175"] .lg\:pl-64,
html[data-font-size="200"] .lg\:pl-64 {
  padding-left: 0 !important;
}

html[data-font-size="150"] .lg\:pt-8,
html[data-font-size="175"] .lg\:pt-8,
html[data-font-size="200"] .lg\:pt-8 {
  padding-top: 5rem !important;
}

html[data-font-size="150"] .lg\:pb-8,
html[data-font-size="175"] .lg\:pb-8,
html[data-font-size="200"] .lg\:pb-8 {
  padding-bottom: 6rem !important;
}

html { scroll-behavior: smooth; }
#root { min-height: 100vh; }
h1 { font-size: 2rem; }
h2 { font-size: 1.5rem; }
h3 { font-size: 1.25rem; }
h4 { font-size: 1.125rem; }

/* === Card Components === */
.card {
  background-color: var(--card);
  color: var(--text);
  border-radius: 1.5rem;
  padding: 1.5rem;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  transition: all 0.2s ease;
}

.card-header {
  margin-bottom: 1.25rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--divider);
}

.card-title {
  font-size: 1.125rem;
  font-weight: 700;
  color: var(--slate);
  margin: 0;
}

.dark .card-title {
  color: var(--text);
}

.stat-card {
  display: flex;
  align-items: center;
  gap: 1.25rem;
}

.stat-icon {
  width: 3.5rem;
  height: 3.5rem;
  border-radius: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.stat-icon.blue { background-color: rgba(0, 71, 171, 0.1); color: #0047AB; }
.stat-icon.green { background-color: rgba(76, 175, 80, 0.1); color: #4CAF50; }
.stat-icon.purple { background-color: rgba(107, 70, 193, 0.1); color: #6B46C1; }
.stat-icon.orange { background-color: rgba(255, 165, 0, 0.1); color: #FFA500; }

.dark .stat-icon.blue { background-color: rgba(59, 130, 246, 0.2); color: #60a5fa; }
.dark .stat-icon.green { background-color: rgba(16, 185, 129, 0.2); color: #34d399; }
.dark .stat-icon.purple { background-color: rgba(139, 92, 246, 0.2); color: #a78bfa; }
.dark .stat-icon.orange { background-color: rgba(245, 158, 11, 0.2); color: #fbbf24; }

.stat-info h3 {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--text);
}

.stat-info p {
  margin: 0;
  font-size: 0.875rem;
  color: var(--text-muted);
  font-weight: 500;
}

/* === Grid Layouts === */
.grid { display: grid; gap: 1.5rem; }
.grid-2 { grid-template-columns: repeat(1, minmax(0, 1fr)); }
@media (min-width: 768px) { .grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.grid-3 { grid-template-columns: repeat(1, minmax(0, 1fr)); }
@media (min-width: 768px) { .grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
.grid-4 { grid-template-columns: repeat(1, minmax(0, 1fr)); }
@media (min-width: 640px) { .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (min-width: 1024px) { .grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); } }

/* === Badges === */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.25rem 0.75rem;
  border-radius: 9999px;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.badge-success {
  background-color: rgba(76, 175, 80, 0.1);
  color: #4CAF50;
  border: 1px solid rgba(76, 175, 80, 0.2);
}

/* === NextGen Brand Utilities === */
.ng-gradient {
  background: linear-gradient(135deg, #0047AB 0%, #002147 100%);
}
.ng-gradient-accent {
  background: linear-gradient(135deg, #FFA500 0%, #FF6B00 100%);
}

/* === LMS & SMS Helpers === */
.ng-lms-bar { background: linear-gradient(90deg, #008080 0%, #00a3a3 100%); }
.ng-sms-bar { background: linear-gradient(90deg, #4CAF50 0%, #6ec071 100%); }

.form-input {
  width: 100%;
  font-family: var(--font-body);
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  padding: 0.75rem 0.875rem;
  font-size: 0.95rem;
  color: var(--text);
  background: var(--background);
  transition: all 0.15s ease;
}
.dark .form-input {
  background: #00112b;
}
.form-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(0, 71, 171, 0.12);
}

.custom-scrollbar::-webkit-scrollbar { width: 4px; }
.custom-scrollbar::-webkit-scrollbar-track { background: transparent; }
.custom-scrollbar::-webkit-scrollbar-thumb { background: rgba(0, 71, 171, 0.1); border-radius: 10px; }
.dark .custom-scrollbar::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.1); }

/* === Adaptive Table System === */
.ng-table-container {
  @apply overflow-x-auto rounded-xl border border-border bg-surface shadow-sm;
}

.ng-table {
  @apply w-full text-left border-collapse;
}

.ng-table-header {
  @apply bg-background-alt/50 border-b border-border text-xs uppercase tracking-wider text-text-muted font-bold;
}

.ng-table-header th {
  @apply px-6 py-4 font-bold;
}

.ng-table-row {
  @apply border-b border-border/50 last:border-0 hover:bg-background-alt/40 transition-colors duration-200 cursor-default;
}

.ng-table-cell {
  @apply px-6 py-4 text-sm text-text-secondary;
}

.dark .ng-table-row:hover {
  @apply bg-white/5;
}

.ng-table-badge {
  @apply inline-flex items-center gap-1 px-2.5 py-1 rounded-full text-[0.65rem] font-black uppercase border transition-all duration-200;
}

/* === Recharts Custom Tooltip Wrapper Adaptation === */
.recharts-tooltip-wrapper {
  background-color: transparent !important;
  border: none !important;
  box-shadow: none !important;
  outline: none !important;
}

/* === Theme-Adaptive Native Selects === */
/* Native <select>/<option> dropdown panels are rendered by the OS, so they
   don't honor Tailwind classes — force the open panel to use our theme
   tokens in both light and dark mode. */
select {
  color: var(--text);
}
select option {
  background-color: var(--card);
  color: var(--text);
}
select option:checked,
select option:hover {
  background-color: var(--primary);
  color: var(--text-inverse);
}

/* === NFR6 — global keyboard focus indicator ===
   Every <a>, <button>, <input>, <select>, <textarea>, and [tabindex] should
   show a visible focus ring on keyboard navigation. We rely on :focus-visible
   (not :focus) so mouse users don't see a ring on click. Sites that need
   pixel-perfect control can override per-component with focus-visible:ring-* */
*:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
  border-radius: 0.5rem;
}
.dark select option {
  background-color: var(--card);
  color: var(--text);
}

/* === Theme-Adaptive Native Date / Time Pickers === */
/* The native calendar/time popups (and the inline picker chrome) are
   rendered by the OS. `color-scheme: dark` is the modern, browser-native
   way to tell Chrome / Edge / Safari to render those widgets in dark
   tones when the app is in dark mode. Without this the picker stays
   light-themed even when the input itself is dark — making the icon and
   selected value unreadable. */
.dark {
  color-scheme: dark;
}
:root {
  color-scheme: light;
}

/* Webkit (Chrome/Edge/Safari) tweak — keep the picker caret and icon
   visible on dark backgrounds even when the input uses a translucent
   surface. Inherits text color so the placeholder and value are readable. */
.dark input[type="date"],
.dark input[type="time"],
.dark input[type="datetime-local"] {
  color-scheme: dark;
  color: var(--text);
}
.dark input[type="date"]::-webkit-calendar-picker-indicator,
.dark input[type="time"]::-webkit-calendar-picker-indicator,
.dark input[type="datetime-local"]::-webkit-calendar-picker-indicator {
  filter: invert(1) opacity(0.7);
  cursor: pointer;
}
.dark input[type="date"]::-webkit-calendar-picker-indicator:hover,
.dark input[type="time"]::-webkit-calendar-picker-indicator:hover,
.dark input[type="datetime-local"]::-webkit-calendar-picker-indicator:hover {
  filter: invert(1) opacity(1);
}
