/* ============================================
   UI v2 - THE NEW LOOK (appearance only)
   Loaded only when <html> has .ui-v2: admins who switched it on, or everyone
   once UI_V2_FOR_ALL is set (see ui_v2_template in main.py).
   Language of the monthly-report mockup: Sora + IBM Plex, indigo accent,
   cool neutrals, cards and pills, light and dark (.dark-mode from app.js).
   Every rule starts with html.ui-v2 so it outranks page styles and the old
   .dark-mode rules without !important.
   ============================================ */

/* === 1. TOKENS === */
html.ui-v2 {
  --bg: #eef1f6;
  --surface: #ffffff;
  --surface-2: #f6f8fb;
  --fg: #131a2a;
  --muted: #5e6a80;
  --line: #d9dfe9;
  --line-strong: #c3cbd9;
  --hover: #e9edf4;
  --accent: #3b47b5;
  --accent-hover: #323d9e;
  --accent-press: #2a3388;
  --accent-soft: #e4e7fb;
  --on-accent: #ffffff;
  --c-boost: #1d8a5b;
  --c-settings: #6b7a99;
  --c-meta: #c08414;
  --c-ours: #c8372d;
  --c-access: #7b4fc4;
  --c-boost-soft: #e1f3ea;
  --c-boost-ink: #176e49;
  --c-meta-soft: #fbf0d9;
  --c-meta-ink: #8a5c0a;
  --c-ours-soft: #fbe5e3;
  --c-ours-ink: #a52b22;
  --c-access-soft: #efe7fa;
  --c-settings-soft: #e9edf4;
  --font-display: "Sora", "Avenir Next", "Segoe UI", sans-serif;
  --font-body: "IBM Plex Sans", "Segoe UI", system-ui, sans-serif;
  --shadow: 0 1px 2px rgba(19, 26, 42, .06), 0 6px 18px rgba(19, 26, 42, .06);
  --shadow-lift: 0 8px 24px rgba(59, 71, 181, .18);
  --shadow-overlay: 0 24px 60px rgba(19, 26, 42, .25);
  --ring: 0 0 0 3px rgba(59, 71, 181, .25);
  --radius-card: 14px;
  --radius-control: 10px;

  /* Old design-system variables, so existing page styles follow the new look. */
  --font-sans: var(--font-body);
  --font-mono: "IBM Plex Mono", ui-monospace, Menlo, monospace;
  --color-white: var(--surface);
  --color-gray-50: var(--surface-2);
  --color-gray-100: var(--hover);
  --color-gray-200: var(--line);
  --color-gray-300: var(--line-strong);
  --color-gray-400: #8d98ad;
  --color-gray-500: var(--muted);
  --color-gray-600: #465165;
  --color-gray-700: #343d50;
  --color-gray-800: #1f2738;
  --color-gray-900: var(--fg);
  --color-primary-50: #eef0fc;
  --color-primary-100: var(--accent-soft);
  --color-primary-200: #c9cef5;
  --color-primary-300: #a3abee;
  --color-primary-400: #7d87e0;
  --color-primary-500: #4b57c7;
  --color-primary-600: var(--accent);
  --color-primary-700: var(--accent-hover);
  --color-primary-800: var(--accent-press);
  --color-primary-900: #222a70;
  --color-success-50: #eef8f3;
  --color-success-100: var(--c-boost-soft);
  --color-success-200: #bfe5d1;
  --color-success-400: #4fc98f;
  --color-success-500: #24a06b;
  --color-success-600: var(--c-boost);
  --color-success-700: var(--c-boost-ink);
  --color-warning-50: #fdf7ea;
  --color-warning-100: var(--c-meta-soft);
  --color-warning-200: #f3d9a0;
  --color-warning-400: #e6b04a;
  --color-warning-500: #d6961f;
  --color-warning-600: var(--c-meta);
  --color-warning-700: var(--c-meta-ink);
  --color-error-50: #fdf1f0;
  --color-error-100: var(--c-ours-soft);
  --color-error-200: #f3c2bd;
  --color-error-400: #f0796f;
  --color-error-500: #dc4a3f;
  --color-error-600: var(--c-ours);
  --color-error-700: var(--c-ours-ink);
  --color-info-50: #eef0fc;
  --color-info-100: var(--accent-soft);
  --color-info-500: #4b57c7;
  --color-info-600: var(--accent);
  --color-info-700: var(--accent-hover);
  --primary-color: var(--accent);
  --secondary-color: var(--c-boost);
  --danger-color: var(--c-ours);
  --warning-color: var(--c-meta);
  --success-color: var(--c-boost);
  --dark-color: var(--fg);
  --light-color: var(--bg);
  --border-color: var(--line);
  --text-color: var(--fg);
  --text-secondary: var(--muted);
  --muted-color: var(--muted);
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-xl: var(--radius-card);
  --shadow-sm: 0 1px 2px rgba(19, 26, 42, .06);
  --shadow-md: var(--shadow);
  --shadow-lg: 0 10px 28px rgba(19, 26, 42, .10);
  --shadow-xl: var(--shadow-overlay);
  --shadow-focus: var(--ring);
  --shadow-focus-error: 0 0 0 3px rgba(200, 55, 45, .25);
}

html.ui-v2.dark-mode {
  color-scheme: dark;
  --bg: #0e121b;
  --surface: #161c29;
  --surface-2: #1c2333;
  --fg: #e8ecf4;
  --muted: #9aa5ba;
  --line: #2a3346;
  --line-strong: #3a4560;
  --hover: #232b3d;
  --accent: #8f9bff;
  --accent-hover: #a6b0ff;
  --accent-press: #7c88f0;
  --accent-soft: #252b52;
  --on-accent: #0e121b;
  --c-boost: #4fc98f;
  --c-settings: #95a3c2;
  --c-meta: #e6b04a;
  --c-ours: #f0796f;
  --c-access: #b38cf2;
  --c-boost-soft: rgba(79, 201, 143, .14);
  --c-boost-ink: #6fd8a6;
  --c-meta-soft: rgba(230, 176, 74, .14);
  --c-meta-ink: #f0c470;
  --c-ours-soft: rgba(240, 121, 111, .14);
  --c-ours-ink: #f59a92;
  --c-access-soft: rgba(179, 140, 242, .14);
  --c-settings-soft: rgba(149, 163, 194, .14);
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 18px rgba(0, 0, 0, .25);
  --shadow-lift: 0 8px 24px rgba(0, 0, 0, .4);
  --shadow-overlay: 0 24px 60px rgba(0, 0, 0, .55);
  --ring: 0 0 0 3px rgba(143, 155, 255, .35);

  --color-gray-400: #6f7b92;
  --color-gray-600: #b4bdcf;
  --color-gray-700: #ccd3e0;
  --color-gray-800: #dde2ec;
  /* Pale tints become translucent so tinted boxes stay dark. */
  --color-primary-50: var(--accent-soft);
  --color-primary-200: rgba(143, 155, 255, .28);
  --color-primary-400: #a9b2ff;
  --color-primary-500: var(--accent);
  --color-info-50: var(--accent-soft);
  --color-success-50: var(--c-boost-soft);
  --color-success-200: rgba(79, 201, 143, .28);
  --color-success-700: var(--c-boost-ink);
  --color-warning-50: var(--c-meta-soft);
  --color-warning-200: rgba(230, 176, 74, .28);
  --color-warning-700: var(--c-meta-ink);
  --color-error-50: var(--c-ours-soft);
  --color-error-200: rgba(240, 121, 111, .28);
  --color-error-700: var(--c-ours-ink);
  --primary-color: var(--accent);
  --light-color: var(--bg);
  --text-color: var(--fg);
  --text-secondary: var(--muted);
  --border-color: var(--line);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .3);
  --shadow-lg: 0 10px 28px rgba(0, 0, 0, .45);
  --shadow-focus-error: 0 0 0 3px rgba(240, 121, 111, .35);

  /* Dark-only variables of the old design system. */
  --color-bg-primary: var(--bg);
  --color-bg-secondary: var(--surface);
  --color-bg-tertiary: var(--surface-2);
  --color-bg-hover: var(--hover);
  --color-border: var(--line);
  --color-border-hover: var(--line-strong);
  --color-text-primary: var(--fg);
  --color-text-secondary: var(--muted);
  --color-text-tertiary: #7a869c;
  --color-text-disabled: #566178;
}

/* === 2. BASE === */
html.ui-v2 body,
html.ui-v2.dark-mode body {
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.55;
  background: var(--bg);
  color: var(--fg);
  -webkit-font-smoothing: antialiased;
}

html.ui-v2 h1, html.ui-v2 h2, html.ui-v2 h3, html.ui-v2 h4,
html.ui-v2.dark-mode h1, html.ui-v2.dark-mode h2, html.ui-v2.dark-mode h3, html.ui-v2.dark-mode h4 {
  font-family: var(--font-display);
  font-weight: 600;
  letter-spacing: -.01em;
  color: var(--fg);
  text-wrap: balance;
}

html.ui-v2 h1 { font-size: 28px; }
html.ui-v2 h2 { font-size: 21px; }
html.ui-v2 h3 { font-size: 17px; }
html.ui-v2 h4 { font-size: 15px; }

html.ui-v2 ::selection { background: var(--accent-soft); color: var(--fg); }

html.ui-v2 a:focus-visible,
html.ui-v2 button:focus-visible,
html.ui-v2 [tabindex]:focus-visible {
  outline: 3px solid var(--c-meta);
  outline-offset: 2px;
}

html.ui-v2 .muted,
html.ui-v2 .text-muted { color: var(--muted); }

html.ui-v2 code,
html.ui-v2 .mono { font-family: var(--font-mono); font-size: .86em; }

/* Side padding only: the old .container shorthand also zeroed main's top padding. */
html.ui-v2 .container { max-width: 1200px; padding-inline: 20px; }

html.ui-v2 main.container,
html.ui-v2 main { padding-block: 28px 56px; }

/* === 3. NAVBAR === */
html.ui-v2 .navbar,
html.ui-v2.dark-mode .navbar {
  background: color-mix(in srgb, var(--surface) 86%, transparent);
  -webkit-backdrop-filter: saturate(1.4) blur(10px);
  backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--line);
  box-shadow: none;
  padding: 10px 0;
}

html.ui-v2 .navbar-brand h1,
html.ui-v2.dark-mode .navbar-brand h1 {
  font-family: var(--font-display);
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -.02em;
  color: var(--fg);
}

html.ui-v2 .navbar-brand a {
  display: inline-flex;
  align-items: center;
  gap: 10px;
}

html.ui-v2 .navbar-brand a::before {
  content: "";
  width: 24px;
  height: 24px;
  border-radius: 7px;
  background:
    radial-gradient(circle at 70% 30%, rgba(255, 255, 255, .45) 0 18%, transparent 19%),
    linear-gradient(135deg, var(--accent) 0%, #6f7ae0 100%);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .15), 0 2px 6px rgba(59, 71, 181, .3);
  flex: none;
}

html.ui-v2 .navbar-menu { gap: 4px; }

html.ui-v2 .navbar-menu a,
html.ui-v2.dark-mode .navbar-menu a {
  color: var(--muted);
  padding: 7px 12px;
  border-radius: 8px;
  font-size: 13.5px;
  font-weight: 600;
}

html.ui-v2 .navbar-menu a:hover,
html.ui-v2.dark-mode .navbar-menu a:hover {
  background: var(--hover);
  color: var(--fg);
}

html.ui-v2 .navbar-menu a[aria-current="page"],
html.ui-v2.dark-mode .navbar-menu a[aria-current="page"] {
  background: var(--accent-soft);
  color: var(--accent);
}

html.ui-v2 .navbar-menu a.ui-switch {
  border: 1px dashed color-mix(in srgb, var(--accent) 55%, transparent);
  color: var(--accent);
  border-radius: 999px;
  padding: 4px 11px;
  font-size: 12.5px;
  margin-left: 4px;
}

html.ui-v2 .navbar-menu .lang-btn { padding: 4px 6px; font-size: 12.5px; }

html.ui-v2 .navbar-menu .user-name,
html.ui-v2.dark-mode .navbar-menu .user-name {
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
  padding: 0 4px;
}

html.ui-v2 .theme-toggle,
html.ui-v2.dark-mode .theme-toggle {
  color: var(--muted);
  border-radius: 8px;
}

html.ui-v2 .theme-toggle:hover,
html.ui-v2.dark-mode .theme-toggle:hover {
  background: var(--hover);
  color: var(--fg);
}

/* === 4. FOOTER === */
html.ui-v2 footer,
html.ui-v2.dark-mode footer {
  background: transparent;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 13px;
}

html.ui-v2 footer a { color: var(--muted); text-decoration: none; }
html.ui-v2 footer a:hover { color: var(--fg); text-decoration: underline; }

/* === 5. BUTTONS === */
html.ui-v2 .btn {
  font-family: var(--font-body);
  font-size: 14px;
  font-weight: 600;
  letter-spacing: .005em;
  padding: 9px 16px;
  border-radius: var(--radius-control);
  box-shadow: none;
}

html.ui-v2 .btn:focus-visible { outline: none; box-shadow: var(--ring); }

html.ui-v2 .btn-primary { background: var(--accent); color: var(--on-accent); }

html.ui-v2 .btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
  box-shadow: var(--shadow-lift);
  transform: none;
}

html.ui-v2 .btn-primary:active:not(:disabled) { background: var(--accent-press); }

html.ui-v2 .btn-secondary,
html.ui-v2.dark-mode .btn-secondary {
  background: var(--surface);
  color: var(--fg);
  border-color: var(--line);
}

html.ui-v2 .btn-secondary:hover:not(:disabled),
html.ui-v2.dark-mode .btn-secondary:hover:not(:disabled) {
  background: var(--hover);
  border-color: var(--line-strong);
  box-shadow: none;
  transform: none;
}

html.ui-v2 .btn-success { background: var(--c-boost); color: var(--on-accent); }
html.ui-v2 .btn-danger { background: var(--c-ours); color: var(--on-accent); }

html.ui-v2 .btn-success:hover:not(:disabled),
html.ui-v2 .btn-danger:hover:not(:disabled) {
  filter: brightness(1.06);
  box-shadow: var(--shadow-sm);
  transform: none;
}

html.ui-v2 .btn-ghost,
html.ui-v2.dark-mode .btn-ghost { color: var(--muted); }

html.ui-v2 .btn-ghost:hover:not(:disabled),
html.ui-v2.dark-mode .btn-ghost:hover:not(:disabled) {
  background: var(--hover);
  color: var(--fg);
}

html.ui-v2 .btn.btn-small,
html.ui-v2 .btn-small {
  padding: 6px 12px;
  font-size: 13px;
  border-radius: 8px;
}

/* === 6. BADGES (pills with a status dot) === */
html.ui-v2 .badge {
  gap: 6px;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0;
  text-transform: none;
}

html.ui-v2 .badge::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  flex: none;
}

html.ui-v2 .badge-active, html.ui-v2 .badge-success,
html.ui-v2.dark-mode .badge-active, html.ui-v2.dark-mode .badge-success {
  background: var(--c-boost-soft);
  color: var(--c-boost-ink);
}

html.ui-v2 .badge-paused, html.ui-v2 .badge-warning,
html.ui-v2.dark-mode .badge-paused, html.ui-v2.dark-mode .badge-warning {
  background: var(--c-meta-soft);
  color: var(--c-meta-ink);
}

html.ui-v2 .badge-error, html.ui-v2 .badge-danger,
html.ui-v2.dark-mode .badge-error, html.ui-v2.dark-mode .badge-danger {
  background: var(--c-ours-soft);
  color: var(--c-ours-ink);
}

html.ui-v2 .badge-info,
html.ui-v2.dark-mode .badge-info {
  background: var(--accent-soft);
  color: var(--accent);
}

html.ui-v2 .badge-neutral,
html.ui-v2.dark-mode .badge-neutral {
  background: var(--surface-2);
  color: var(--muted);
  box-shadow: inset 0 0 0 1px var(--line);
}

/* === 7. SURFACES: cards, landing sections, modals, alerts === */
html.ui-v2 .card,
html.ui-v2 .hero,
html.ui-v2 .features,
html.ui-v2 .how-it-works,
html.ui-v2.dark-mode .hero,
html.ui-v2.dark-mode .features,
html.ui-v2.dark-mode .how-it-works {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow);
}

html.ui-v2 .card-header {
  padding: 18px 20px 0;
}

html.ui-v2 .card-body {
  padding: 14px 20px 20px;
}

html.ui-v2 .feature-card,
html.ui-v2.dark-mode .feature-card {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 12px;
}

html.ui-v2 .feature-card:hover { box-shadow: var(--shadow-lift); }

html.ui-v2 .steps li::before { font-family: var(--font-display); font-size: 15px; }

html.ui-v2 .modal-backdrop {
  background: rgba(14, 18, 27, .45);
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
}

html.ui-v2 .modal-content,
html.ui-v2.dark-mode .modal-content {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow-overlay);
}

html.ui-v2 .alert {
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--fg);
}

html.ui-v2 .alert-success {
  background: var(--c-boost-soft);
  border-color: color-mix(in srgb, var(--c-boost) 35%, transparent);
  color: var(--fg);
}

html.ui-v2 .alert-warning {
  background: var(--c-meta-soft);
  border-color: color-mix(in srgb, var(--c-meta) 35%, transparent);
  color: var(--fg);
}

html.ui-v2 .alert-error {
  background: var(--c-ours-soft);
  border-color: color-mix(in srgb, var(--c-ours) 35%, transparent);
  color: var(--fg);
}

/* === 8. FORM CONTROLS (colours, radius, focus; sizes stay per page) === */
html.ui-v2 input:not([type="checkbox"]):not([type="radio"]):not([type="range"]),
html.ui-v2 select,
html.ui-v2 textarea {
  font-family: var(--font-body);
  color: var(--fg);
  background-color: var(--surface);
  border-color: var(--line);
  border-radius: var(--radius-control);
}

html.ui-v2 input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):focus,
html.ui-v2 select:focus,
html.ui-v2 textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: var(--ring);
}

html.ui-v2 input::placeholder,
html.ui-v2 textarea::placeholder { color: var(--muted); opacity: .8; }

html.ui-v2 input[type="checkbox"],
html.ui-v2 input[type="radio"] { accent-color: var(--accent); }

/* === 9. TABLES === */
html.ui-v2 th {
  font-size: 11.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--muted);
}

html.ui-v2 th,
html.ui-v2 td { border-color: var(--line); }

/* === 10. TOASTS from app.js (inline styles, hence !important) === */
html.ui-v2 .notification {
  font-family: var(--font-body);
  font-weight: 500;
  font-size: 14px;
  border-radius: 12px !important;
  box-shadow: var(--shadow-overlay) !important;
  background: var(--accent) !important;
  color: var(--on-accent) !important;
}

html.ui-v2 .notification-success { background: var(--c-boost) !important; }
html.ui-v2 .notification-error { background: var(--c-ours) !important; }

/* === 11. BUILDING BLOCKS for the screen redesigns (v2- prefix, no effect in v1) === */
html.ui-v2 .v2-eyebrow {
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: .09em;
  text-transform: uppercase;
  color: var(--muted);
}

html.ui-v2 .v2-num { font-variant-numeric: tabular-nums; }

html.ui-v2 .v2-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow);
  padding: 18px;
  min-width: 0;
}

html.ui-v2 .v2-kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 10px;
}

html.ui-v2 .v2-kpi {
  display: grid;
  gap: 2px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
}

html.ui-v2 .v2-kpi .v {
  font-family: var(--font-display);
  font-size: 26px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

html.ui-v2 .v2-kpi .l { font-size: 12.5px; color: var(--muted); }

html.ui-v2 .v2-pill {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
  white-space: nowrap;
  color: var(--surface);
  background: var(--c-settings);
}

html.ui-v2 .v2-pill.boost { background: var(--c-boost); }
html.ui-v2 .v2-pill.meta { background: var(--c-meta); }
html.ui-v2 .v2-pill.ours { background: var(--c-ours); }
html.ui-v2 .v2-pill.access { background: var(--c-access); }
html.ui-v2 .v2-pill.accent { background: var(--accent); }

html.ui-v2 .v2-tabs {
  display: inline-flex;
  gap: 3px;
  padding: 3px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-control);
}

html.ui-v2 .v2-tabs > button,
html.ui-v2 .v2-tabs > a {
  font: inherit;
  font-size: 13.5px;
  font-weight: 600;
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 7px 14px;
  border-radius: 8px;
  cursor: pointer;
  text-decoration: none;
}

html.ui-v2 .v2-tabs > [aria-selected="true"],
html.ui-v2 .v2-tabs > [aria-current="page"] {
  background: var(--accent);
  color: var(--on-accent);
}

/* === 12. SMALL SCREENS AND MOTION === */
@media (max-width: 768px) {
  html.ui-v2 .navbar-menu { gap: 2px; }
  html.ui-v2 .navbar-menu a { padding: 6px 9px; }
  html.ui-v2 main.container,
  html.ui-v2 main { padding-block: 20px 40px; }
  html.ui-v2 .container { padding-inline: 16px; }
}

@media (prefers-reduced-motion: reduce) {
  html.ui-v2 *,
  html.ui-v2 *::before,
  html.ui-v2 *::after {
    animation: none !important;
    transition: none !important;
  }
}
