/**
 * RouteManager — token globali per tema
 * Classi su <html>: .theme-light | .theme-dark | .theme-light-2
 * (RmTheme in rm-theme.js applica una sola classe alla volta)
 */

html {
  overflow-x: hidden;
  max-width: 100vw;
}

/* ═══ Tema 1 — Chiaro (default) ═══════════════════════════════ */
html.theme-light {
  color-scheme: light;

  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface2: #f3f4f6;
  --surface-elevated: #ffffff;
  --border: #e5e7eb;
  --border-strong: #d1d5db;

  --text: #111827;
  --muted: #6b7280;

  --primary: #2563eb;
  --accent: #2563eb;
  --accent2: #4f46e5;
  --accent-soft: #dbeafe;

  --green: #059669;
  --yellow: #b45309;
  --red: #dc2626;
  --blue: #2563eb;

  --header-bg: rgba(255, 255, 255, 0.92);
  --modal-backdrop: rgba(15, 23, 42, 0.45);
  --overlay-strong: rgba(248, 250, 252, 0.97);
  --map-canvas: #0f172a;
  --map-legend-bg: rgba(255, 255, 255, 0.92);
  --map-attrib-bg: rgba(255, 255, 255, 0.85);

  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05);
  --shadow-md: 0 4px 24px rgba(15, 23, 42, 0.08);
  --shadow-card: 0 8px 32px rgba(15, 23, 42, 0.08);
  --shadow-hover: 0 12px 36px rgba(37, 99, 235, 0.12);

  --input-bg: #ffffff;
  --input-placeholder: #9ca3af;
  --focus-ring: #2563eb;

  --font-head: "Syne", system-ui, sans-serif;
  --font-mono: "DM Mono", ui-monospace, monospace;

  --grid-fade: 0.2;
  --toast-border: rgba(37, 99, 235, 0.35);
  --btn-grad: linear-gradient(135deg, var(--accent), var(--accent2));
}

/* ═══ Tema 2 — Scuro Premium (SaaS) ════════════════════════════ */
html.theme-dark {
  color-scheme: dark;

  --bg: #0f172a;
  --surface: #111827;
  --surface2: #1e293b;
  --surface-elevated: #1e293b;
  --border: #334155;
  --border-strong: #475569;

  --text: #f8fafc;
  --muted: #94a3b8;

  --primary: #3b82f6;
  --accent: #3b82f6;
  --accent2: #6366f1;
  --accent-soft: rgba(59, 130, 246, 0.15);

  --green: #34d399;
  --yellow: #fbbf24;
  --red: #f87171;
  --blue: #60a5fa;

  --header-bg: rgba(15, 23, 42, 0.88);
  --modal-backdrop: rgba(2, 6, 23, 0.72);
  --overlay-strong: rgba(15, 23, 42, 0.95);
  --map-canvas: #020617;
  --map-legend-bg: rgba(30, 41, 59, 0.92);
  --map-attrib-bg: rgba(15, 23, 42, 0.75);

  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.35);
  --shadow-md: 0 10px 40px rgba(0, 0, 0, 0.45);
  --shadow-card: 0 8px 32px rgba(0, 0, 0, 0.4);
  --shadow-hover: 0 16px 48px rgba(59, 130, 246, 0.22);

  --input-bg: #1e293b;
  --input-placeholder: #64748b;
  --focus-ring: #60a5fa;

  --font-head: "Syne", system-ui, sans-serif;
  --font-mono: "DM Mono", ui-monospace, monospace;

  --grid-fade: 0.12;
  --toast-border: rgba(59, 130, 246, 0.45);
  --btn-grad: linear-gradient(135deg, #3b82f6, #6366f1);
}

/* ═══ Tema 3 — Chiaro 2 (premium SaaS) ═════════════════════════ */
html.theme-light-2 {
  color-scheme: light;

  --bg: #eef2ff;
  --surface: #ffffff;
  --surface2: #f5f3ff;
  --surface-elevated: #ffffff;
  --border: #e0e7ff;
  --border-strong: #c7d2fe;

  --text: #0f172a;
  --muted: #64748b;

  --primary: #4f46e5;
  --accent: #2563eb;
  --accent2: #7c3aed;
  --accent-soft: #ede9fe;

  --green: #059669;
  --yellow: #b45309;
  --red: #dc2626;
  --blue: #2563eb;

  --header-bg: rgba(255, 255, 255, 0.78);
  --modal-backdrop: rgba(15, 23, 42, 0.42);
  --overlay-strong: rgba(255, 255, 255, 0.96);
  --map-canvas: #0f172a;
  --map-legend-bg: rgba(255, 255, 255, 0.95);
  --map-attrib-bg: rgba(255, 255, 255, 0.88);

  --shadow-sm: 0 1px 3px rgba(79, 70, 229, 0.06);
  --shadow-md: 0 12px 40px rgba(79, 70, 229, 0.1);
  --shadow-card: 0 16px 48px rgba(15, 23, 42, 0.08);
  --shadow-hover: 0 20px 50px rgba(124, 58, 237, 0.12);

  --input-bg: #ffffff;
  --input-placeholder: #94a3b8;
  --focus-ring: #7c3aed;

  --font-head: "Syne", system-ui, sans-serif;
  --font-mono: "DM Mono", ui-monospace, monospace;

  --grid-fade: 0.14;
  --toast-border: rgba(124, 58, 237, 0.35);
  --btn-grad: linear-gradient(135deg, #2563eb, #7c3aed);
}

/* Mesh leggero solo Chiaro 2 */
html.theme-light-2 body::after {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  opacity: 0.55;
  background: radial-gradient(
      1200px 600px at 10% -10%,
      rgba(99, 102, 241, 0.12),
      transparent 55%
    ),
    radial-gradient(
      900px 500px at 100% 0%,
      rgba(124, 58, 237, 0.1),
      transparent 50%
    );
  transition: opacity 0.25s ease;
}

html.theme-light body::after,
html.theme-dark body::after {
  display: none;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  background-image: linear-gradient(var(--border) 1px, transparent 1px),
    linear-gradient(90deg, var(--border) 1px, transparent 1px);
  background-size: 40px 40px;
  opacity: var(--grid-fade);
  pointer-events: none;
  z-index: 0;
  transition: opacity 0.25s ease;
}

body,
.card,
.table-card,
.modal,
.toast,
.btn,
.btn-main,
.btn-nav,
.btn-nav-primary,
.icon-btn,
.pag-btn,
input,
select,
textarea,
.header,
.nav,
.top-bar,
.user-pill,
.rm-profile-trigger,
.kpi-card,
.tbl-header,
.modal-overlay,
.rm-profile-dropdown {
  transition: background-color 0.22s ease, color 0.18s ease,
    border-color 0.22s ease, box-shadow 0.22s ease, opacity 0.2s ease;
}

button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
.rm-profile-trigger:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
}

/* Ombre card temi chiari */
html.theme-light .table-card,
html.theme-light .deliveries-list-card,
html.theme-light .card,
html.theme-light .kpi-card,
html.theme-light .table-wrap,
html.theme-light .wrap .card,
html.theme-light .login-inner .card,
html.theme-light .form-card,
html.theme-light .summary {
  box-shadow: var(--shadow-sm);
}

html.theme-light-2 .table-card,
html.theme-light-2 .deliveries-list-card,
html.theme-light-2 .card,
html.theme-light-2 .kpi-card,
html.theme-light-2 .table-wrap,
html.theme-light-2 .wrap .card,
html.theme-light-2 .login-inner .card,
html.theme-light-2 .form-card,
html.theme-light-2 .summary {
  box-shadow: var(--shadow-card);
}

html.theme-light .modal,
html.theme-light-2 .modal {
  box-shadow: var(--shadow-md);
}

html.theme-dark .table-card,
html.theme-dark .deliveries-list-card,
html.theme-dark .card,
html.theme-dark .kpi-card {
  box-shadow: var(--shadow-sm);
}

html.theme-dark .modal {
  box-shadow: var(--shadow-md);
}

/* Hover premium tabelle / card */
.table-card:hover,
.deliveries-list-card:hover,
.kpi-card:hover {
  transition: box-shadow 0.2s ease, transform 0.2s ease;
}

html.theme-dark .kpi-card:hover,
html.theme-dark .table-card:hover {
  box-shadow: var(--shadow-hover);
}

html.theme-light-2 .kpi-card:hover,
html.theme-light-2 .table-card:hover {
  box-shadow: var(--shadow-hover);
}

/* ═══ Menu profilo (dropdown) ═════════════════════════════════ */
.rm-profile {
  position: relative;
  align-self: center;
  z-index: 50;
}

.rm-profile-trigger {
  cursor: pointer;
  border: none;
  font: inherit;
  text-align: left;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 12px 6px 6px;
  background: var(--surface2);
  border-radius: 30px;
  border: 1px solid var(--border);
  max-width: 260px;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.rm-profile-trigger:hover {
  border-color: var(--accent);
  box-shadow: var(--shadow-sm);
}

.rm-profile-chevron {
  margin-left: auto;
  font-size: 0.65rem;
  color: var(--muted);
  flex-shrink: 0;
}

.rm-profile-dropdown {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  min-width: 200px;
  padding: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow-md);
  z-index: 2000;
  display: none;
  flex-direction: column;
  gap: 2px;
}

.rm-profile-dropdown.is-open {
  display: flex;
  animation: rm-dd-in 0.18s ease;
}

@keyframes rm-dd-in {
  from {
    opacity: 0;
    transform: translateY(-6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.rm-profile-dropdown__item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-radius: 8px;
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--text);
  text-decoration: none;
  background: transparent;
  border: none;
  width: 100%;
  cursor: pointer;
  text-align: left;
  transition: background 0.15s ease;
}

.rm-profile-dropdown__item:hover {
  background: var(--surface2);
}

.rm-profile-dropdown__item--danger:hover {
  background: color-mix(in srgb, var(--red) 12%, transparent);
  color: var(--red);
}

@media (max-width: 520px) {
  .rm-profile-dropdown {
    right: auto;
    left: 0;
    min-width: min(260px, calc(100vw - 32px));
  }
}
