/* ============================================================
   NOVA CRM — Design System
   Space · Glassmorphism · Neon Gold Accents
   ============================================================ */

/* ── Google Fonts ──────────────────────────────────────────── */
@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@300;400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap');

/* ══════════════════════════════════════════════════════════════
   CSS CUSTOM PROPERTIES (Design Tokens)
══════════════════════════════════════════════════════════════ */
:root {
  /* ── Dark theme (default) ─────────────────────────────────── */
  --bg-void:        #050508;
  --bg-deep:        #080c18;
  --bg-space:       #0a0f1e;
  --bg-panel:       rgba(8, 14, 35, 0.95);
  --bg-card:        rgba(255, 255, 255, 0.04);
  --bg-card-hover:  rgba(255, 255, 255, 0.08);
  --bg-input:       rgba(255, 255, 255, 0.06);
  --bg-sidebar:     rgba(5, 10, 25, 0.85);

  /* ── Gold accent palette ─────────────────────────────────── */
  --gold-50:   #fffbeb;
  --gold-100:  #fef3c7;
  --gold-300:  #fcd34d;
  --gold-400:  #fbbf24;
  --gold:      #f59e0b;
  --gold-600:  #d97706;
  --gold-glow: rgba(245, 158, 11, 0.35);

  /* ── Blue/Navy accents ───────────────────────────────────── */
  --blue-deep:  #0f172a;
  --blue-mid:   #1e3a5f;
  --blue-light: #3b82f6;
  --blue-glow:  rgba(59, 130, 246, 0.3);

  /* ── Text ────────────────────────────────────────────────── */
  --text-primary:   rgba(255, 255, 255, 0.95);
  --text-secondary: rgba(255, 255, 255, 0.55);
  --text-muted:     rgba(255, 255, 255, 0.30);
  --text-gold:      var(--gold-400);

  /* ── Borders ─────────────────────────────────────────────── */
  --border:       rgba(255, 255, 255, 0.08);
  --border-gold:  rgba(245, 158, 11, 0.4);
  --border-focus: rgba(245, 158, 11, 0.7);

  /* ── Radius ──────────────────────────────────────────────── */
  --radius-sm: 6px;
  --radius:    12px;
  --radius-lg: 20px;
  --radius-xl: 28px;

  /* ── Shadows ─────────────────────────────────────────────── */
  --shadow-sm:   0 2px 8px rgba(0,0,0,0.4);
  --shadow:      0 4px 24px rgba(0,0,0,0.5);
  --shadow-lg:   0 8px 48px rgba(0,0,0,0.6);
  --shadow-gold: 0 0 20px var(--gold-glow), 0 0 60px rgba(245,158,11,0.15);
  --shadow-blue: 0 0 20px var(--blue-glow);

  /* ── Typography ──────────────────────────────────────────── */
  --font-sans: 'Outfit', system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;

  /* ── Transitions ─────────────────────────────────────────── */
  --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition:      250ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-slow: 400ms cubic-bezier(0.4, 0, 0.2, 1);

  /* ── Sidebar ─────────────────────────────────────────────── */
  --sidebar-w: 260px;
  --topbar-h:  64px;
}

/* ── Light mode overrides ─────────────────────────────────── */
[data-theme="light"] {
  --bg-void:       #f0f4ff;
  --bg-deep:       #e8edf8;
  --bg-space:      #dce3f2;
  --bg-panel:      rgba(255, 255, 255, 0.95);
  --bg-card:       rgba(255, 255, 255, 0.3);
  --bg-card-hover: rgba(255, 255, 255, 0.95);
  --bg-input:      rgba(0, 0, 0, 0.04);
  --bg-sidebar:    rgba(240, 244, 255, 0.9);

  --text-primary:   rgba(10, 15, 40, 0.95);
  --text-secondary: rgba(10, 15, 40, 0.55);
  --text-muted:     rgba(10, 15, 40, 0.30);

  --border:       rgba(0, 0, 0, 0.10);
  --border-gold:  rgba(180, 120, 0, 0.4);
  --border-focus: rgba(180, 120, 0, 0.7);
}

/* ══════════════════════════════════════════════════════════════
   RESET & BASE
══════════════════════════════════════════════════════════════ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 16px; scroll-behavior: smooth; }

body {
  font-family:      var(--font-sans);
  background-color: var(--bg-void);
  color:            var(--text-primary);
  min-height:       100vh;
  overflow-x:       hidden;
  line-height:      1.6;
  -webkit-font-smoothing: antialiased;
}

/* ══════════════════════════════════════════════════════════════
   SPACE BACKGROUND — CSS STAR FIELD
══════════════════════════════════════════════════════════════ */
#space-bg {
  position: fixed;
  inset: 0;
  z-index: 0;
  background:
    radial-gradient(ellipse at 20% 50%, rgba(30, 58, 95, 0.4) 0%, transparent 50%),
    radial-gradient(ellipse at 80% 20%, rgba(15, 23, 42, 0.6) 0%, transparent 40%),
    radial-gradient(ellipse at 60% 80%, rgba(245, 158, 11, 0.06) 0%, transparent 40%),
    var(--bg-deep);
  overflow: hidden;
}

/* ── Star layers (pure CSS, 3 parallax levels) ────────────── */
.stars-layer {
  position: absolute;
  inset: -20%;
  width: 140%;
  height: 140%;
  border-radius: 50%;
}

.stars-sm {
  background-image:
    radial-gradient(1px 1px at 15% 10%, rgba(255,255,255,0.8) 0%, transparent 100%),
    radial-gradient(1px 1px at 32% 78%, rgba(255,255,255,0.6) 0%, transparent 100%),
    radial-gradient(1px 1px at 47% 25%, rgba(255,255,255,0.9) 0%, transparent 100%),
    radial-gradient(1px 1px at 63% 55%, rgba(255,255,255,0.5) 0%, transparent 100%),
    radial-gradient(1px 1px at 78% 12%, rgba(255,255,255,0.7) 0%, transparent 100%),
    radial-gradient(1px 1px at 91% 68%, rgba(255,255,255,0.8) 0%, transparent 100%),
    radial-gradient(1px 1px at  5% 45%, rgba(255,255,255,0.6) 0%, transparent 100%),
    radial-gradient(1px 1px at 25% 90%, rgba(255,255,255,0.7) 0%, transparent 100%),
    radial-gradient(1px 1px at 55% 88%, rgba(255,255,255,0.5) 0%, transparent 100%),
    radial-gradient(1px 1px at 72% 35%, rgba(255,255,255,0.9) 0%, transparent 100%),
    radial-gradient(1px 1px at 88% 92%, rgba(255,255,255,0.6) 0%, transparent 100%),
    radial-gradient(1px 1px at 10% 62%, rgba(255,255,255,0.8) 0%, transparent 100%),
    radial-gradient(1px 1px at 39% 42%, rgba(255,255,255,0.5) 0%, transparent 100%),
    radial-gradient(1px 1px at 58% 18%, rgba(255,255,255,0.7) 0%, transparent 100%),
    radial-gradient(1px 1px at 83% 48%, rgba(255,255,255,0.9) 0%, transparent 100%),
    radial-gradient(1px 1px at 95% 28%, rgba(255,255,255,0.6) 0%, transparent 100%),
    radial-gradient(1px 1px at 20% 33%, rgba(255,255,255,0.8) 0%, transparent 100%),
    radial-gradient(1px 1px at 44% 70%, rgba(255,255,255,0.5) 0%, transparent 100%),
    radial-gradient(1px 1px at 67% 82%, rgba(255,255,255,0.7) 0%, transparent 100%),
    radial-gradient(1px 1px at 85% 5%,  rgba(255,255,255,0.9) 0%, transparent 100%);
  background-size: 100% 100%;
  animation: drift-slow 120s linear infinite;
}

.stars-md {
  background-image:
    radial-gradient(1.5px 1.5px at 18% 22%, rgba(255,255,255,0.9) 0%, transparent 100%),
    radial-gradient(2px   2px   at 36% 61%, rgba(200,220,255,0.8) 0%, transparent 100%),
    radial-gradient(1.5px 1.5px at 52% 14%, rgba(255,255,255,0.7) 0%, transparent 100%),
    radial-gradient(2px   2px   at 71% 73%, rgba(255,220,180,0.8) 0%, transparent 100%),
    radial-gradient(1.5px 1.5px at 87% 38%, rgba(255,255,255,0.9) 0%, transparent 100%),
    radial-gradient(2px   2px   at  8% 85%, rgba(200,220,255,0.7) 0%, transparent 100%),
    radial-gradient(1.5px 1.5px at 42% 96%, rgba(255,255,255,0.8) 0%, transparent 100%),
    radial-gradient(2px   2px   at 60% 50%, rgba(255,230,150,0.6) 0%, transparent 100%),
    radial-gradient(1.5px 1.5px at 79% 19%, rgba(255,255,255,0.9) 0%, transparent 100%),
    radial-gradient(2px   2px   at 94% 77%, rgba(200,220,255,0.8) 0%, transparent 100%);
  animation: drift-mid 80s linear infinite;
}

.stars-lg {
  background-image:
    radial-gradient(3px 3px at 22% 30%, rgba(255,230,150,1.0) 0%, transparent 100%),
    radial-gradient(2.5px 2.5px at 55% 65%, rgba(255,255,255,1.0) 0%, transparent 100%),
    radial-gradient(3px   3px   at 80% 15%, rgba(180,210,255,1.0) 0%, transparent 100%),
    radial-gradient(2.5px 2.5px at 12% 75%, rgba(255,200,150,1.0) 0%, transparent 100%),
    radial-gradient(3px   3px   at 68% 88%, rgba(255,255,255,1.0) 0%, transparent 100%);
  animation: drift-fast 50s linear infinite, twinkle 4s ease-in-out infinite alternate;
}

/* ── Nebula glow ──────────────────────────────────────────── */
.nebula {
  position: absolute;
  border-radius: 50%;
  filter: blur(80px);
  opacity: 0.12;
  animation: nebula-pulse 8s ease-in-out infinite alternate;
}
.nebula-1 { width: 600px; height: 400px; background: #3b82f6; top: -10%; left: -5%; }
.nebula-2 { width: 400px; height: 500px; background: #f59e0b; bottom: 5%; right: 10%; }
.nebula-3 { width: 300px; height: 300px; background: #8b5cf6; top: 40%; left: 45%; }

/* ── Animations ───────────────────────────────────────────── */
@keyframes drift-slow {
  from { transform: rotate(0deg) translateX(10px); }
  to   { transform: rotate(360deg) translateX(10px); }
}
@keyframes drift-mid {
  from { transform: rotate(0deg) translateX(-8px); }
  to   { transform: rotate(-360deg) translateX(-8px); }
}
@keyframes drift-fast {
  from { transform: rotate(0deg); }
  to   { transform: rotate(360deg); }
}
@keyframes twinkle {
  0%   { opacity: 0.6; }
  50%  { opacity: 1.0; }
  100% { opacity: 0.7; }
}
@keyframes nebula-pulse {
  from { transform: scale(1) translate(0, 0); opacity: 0.10; }
  to   { transform: scale(1.15) translate(20px, -10px); opacity: 0.18; }
}

/* ── Shooting star ────────────────────────────────────────── */
.shooting-star {
  position: absolute;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.9), transparent);
  top: 20%;
  left: -5%;
  width: 120px;
  transform: rotate(-30deg);
  animation: shoot 6s ease-out infinite;
  animation-delay: var(--delay, 0s);
}
@keyframes shoot {
  0%   { transform: translateX(0) translateY(0) rotate(-30deg); opacity: 1; }
  100% { transform: translateX(110vw) translateY(40vh) rotate(-30deg); opacity: 0; }
}

/* ══════════════════════════════════════════════════════════════
   LAYOUT
══════════════════════════════════════════════════════════════ */
#app-shell {
  position: relative;
  z-index: 1;
  display: flex;
  min-height: 100vh;
}

/* ── Sidebar ──────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  height: 100vh;
  height: 100dvh; /* Dynamic viewport: esclude la barra del browser su mobile */
  position: fixed;
  right: 0; top: 0;
  left: auto;
  background: var(--bg-sidebar);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  border-left: 1px solid var(--border);
  border-right: none;
  display: flex;
  flex-direction: column;
  z-index: 100;
  overflow: hidden;
  transition: transform var(--transition);
}

.sidebar-logo {
  padding: 24px 20px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
}
.sidebar-logo-icon {
  width: 38px; height: 38px;
  background: linear-gradient(135deg, var(--gold-600), var(--gold-400));
  border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  font-size: 18px;
  box-shadow: var(--shadow-gold);
  flex-shrink: 0;
}
.sidebar-logo-text {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.02em;
  background: linear-gradient(135deg, var(--gold-400), var(--gold-300));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}
.sidebar-logo-sub {
  font-size: 11px;
  color: var(--text-muted);
  font-family: var(--font-mono);
  letter-spacing: 0.05em;
}

.sidebar-nav { flex: 1; min-height: 0; padding: 12px 0; overflow-y: auto; }
.sidebar-nav::-webkit-scrollbar { width: 3px; }
.sidebar-nav::-webkit-scrollbar-track { background: transparent; }
.sidebar-nav::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.nav-section-title {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-muted);
  padding: 16px 20px 6px;
  font-family: var(--font-mono);
}

/* ── Sezione Moduli collassabile ─────────────────────────── */
.nav-modules-header {
  border-radius: var(--radius-sm);
  margin: 0 8px;
  transition: background var(--transition-fast);
}
.nav-modules-header:hover {
  background: rgba(255,255,255,0.04);
}
[data-theme="light"] .nav-modules-header:hover {
  background: rgba(124,58,237,0.06);
}
#nav-modules-panel {
  max-height: 0px; /* chiuso di default — la search bar è fuori dal pannello */
}
#nav-modules-search {
  transition: border-color var(--transition-fast);
  font-family: var(--font-sans);
}
#nav-modules-search::placeholder {
  color: var(--text-muted);
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 20px;
  margin: 1px 8px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition-fast);
  border: 1px solid transparent;
  position: relative;
}
.nav-item:hover {
  background: var(--bg-card-hover);
  color: var(--text-primary);
  border-color: var(--border);
}
.nav-item.active {
  background: linear-gradient(135deg, rgba(245,158,11,0.15), rgba(245,158,11,0.05));
  color: var(--gold-400);
  border-color: var(--border-gold);
}
.nav-item.active .nav-icon { color: var(--gold-400); }
.nav-icon { width: 18px; font-size: 16px; flex-shrink: 0; opacity: 0.8; display: inline-flex; align-items: center; justify-content: center; }
.nav-icon svg { display: block; flex-shrink: 0; }
.nav-badge {
  margin-left: auto;
  background: var(--gold-glow);
  color: var(--gold-400);
  font-size: 10px;
  font-family: var(--font-mono);
  padding: 2px 6px;
  border-radius: 20px;
  border: 1px solid var(--border-gold);
}

.sidebar-footer {
  padding: 12px;
  border-top: 1px solid var(--border);
  /* Su mobile: lascia spazio per bottom nav e safe area */
  padding-bottom: max(12px, env(safe-area-inset-bottom, 12px));
}

@media (max-width: 768px) {
  .sidebar-footer {
    padding-bottom: calc(max(12px, env(safe-area-inset-bottom, 12px)));
  }
}
.user-card {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  border: 1px solid var(--border);
  cursor: pointer;
  transition: all var(--transition-fast);
}
.user-card:hover { border-color: var(--border-gold); box-shadow: var(--shadow-gold); }
.user-avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--gold-600), var(--blue-mid));
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 700; color: white; flex-shrink: 0;
}
.user-name { font-size: 13px; font-weight: 600; color: var(--text-primary); }
.user-role { font-size: 11px; color: var(--text-muted); font-family: var(--font-mono); }

/* ── Main area ───────────────────────────────────────────── */
.main-area {
  margin-right: var(--sidebar-w);
  margin-left: 0;
  flex: 1;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ── Topbar ──────────────────────────────────────────────── */
.topbar {
  height: var(--topbar-h);
  position: sticky; top: 0; z-index: 50;
  background: rgba(5, 8, 20, 0.7);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 28px;
  transition: background 0.3s, border-color 0.3s;
}
[data-theme="light"] .topbar {
  background: rgba(255, 248, 220, 0.92);
  border-bottom-color: rgba(180, 130, 0, 0.25);
  box-shadow: 0 1px 12px rgba(180, 130, 0, 0.10);
}
.topbar-left { display: flex; align-items: center; gap: 12px; }
.topbar-title { font-size: 17px; font-weight: 600; color: var(--text-primary); }
.topbar-breadcrumb { font-size: 13px; color: var(--text-muted); }
.topbar-breadcrumb span { color: var(--text-secondary); }

.topbar-actions { display: flex; align-items: center; gap: 10px; }

/* ── Page content ────────────────────────────────────────── */
.page-content { padding: 28px; flex: 1; }

/* ══════════════════════════════════════════════════════════════
   GLASSMORPHISM COMPONENTS
══════════════════════════════════════════════════════════════ */

/* ── Glass card ──────────────────────────────────────────── */
.glass-card {
  background: var(--bg-card);
  backdrop-filter: blur(12px) saturate(150%);
  -webkit-backdrop-filter: blur(12px) saturate(150%);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  transition: all var(--transition);
}
.glass-card:hover {
  background: var(--bg-card-hover);
  border-color: var(--border-gold);
  box-shadow: var(--shadow-gold);
  transform: translateY(-2px);
}

/* ── Stat widget ─────────────────────────────────────────── */
/* ══════════════════════════════════════════════════════════════
   DASHBOARD — Sistema widget personalizzabili
══════════════════════════════════════════════════════════════ */

/* Griglia widget: colonne flessibili basate su unità di 1 colonna */
.db-widgets-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 24px;
  align-items: start;
}

/* Dimensioni widget */
.db-widget-sm  { grid-column: span 1; }
.db-widget-md  { grid-column: span 2; }
.db-widget-lg  { grid-column: span 4; }

/* Card base */
.db-widget-card {
  background: var(--bg-card);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  position: relative;
  overflow: hidden;
  transition: box-shadow var(--transition), border-color var(--transition), transform var(--transition);
  min-height: 110px;
}
.db-widget-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--gold-glow), transparent);
  opacity: 0;
  transition: opacity var(--transition);
}
.db-widget-card:hover::before { opacity: 1; }
.db-widget-card:hover {
  border-color: rgba(245,158,11,0.2);
  box-shadow: 0 4px 24px rgba(0,0,0,0.35), 0 0 16px rgba(245,158,11,0.06);
  transform: translateY(-2px);
}

/* Header del widget */
.db-widget-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}
.db-widget-title {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  line-height: 1.3;
  flex: 1;
}
.db-widget-actions {
  display: flex;
  gap: 2px;
  opacity: 0;
  transition: opacity .15s;
  flex-shrink: 0;
}
.db-widget-card:hover .db-widget-actions { opacity: 1; }

/* Body del widget */
.db-widget-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

/* Valore statistico scalare */
.db-stat-value {
  font-size: 36px;
  font-weight: 700;
  font-family: var(--font-mono);
  letter-spacing: -0.03em;
  line-height: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.db-stat-sub {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 5px;
  text-transform: uppercase;
  letter-spacing: .04em;
}

/* Label nei modali */
.db-modal-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: .04em;
}

/* ── Widget responsive ───────────────────────────────────── */
@media (max-width: 1100px) {
  .db-widgets-grid { grid-template-columns: repeat(3, 1fr); }
  .db-widget-lg    { grid-column: span 3; }
}
@media (max-width: 768px) {
  .db-widgets-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    margin-bottom: 16px;
  }
  .db-widget-sm  { grid-column: span 1; }
  .db-widget-md  { grid-column: span 2; }
  .db-widget-lg  { grid-column: span 2; }
  .db-widget-card { padding: 14px 14px; min-height: 90px; }
  .db-widget-actions { opacity: 1; } /* sempre visibili su mobile */
  .db-stat-value { font-size: clamp(22px, 6vw, 30px); }
  .db-widget-title { font-size: 11px; }
}
@media (max-width: 480px) {
  .db-widgets-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .db-widget-card { padding: 12px; }
  .db-stat-value { font-size: clamp(18px, 7vw, 26px); }
}

/* ── Vecchie classi mantenute per compatibilità CSS globale ── */
.stat-widget {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 22px 24px;
  display: flex; flex-direction: column; gap: 8px;
  transition: all var(--transition);
  position: relative;
  overflow: hidden;
}
.stat-icon {
  width: 44px; height: 44px;
  border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  font-size: 20px;
  margin-bottom: 4px;
}
.stat-value {
  font-size: 32px;
  font-weight: 700;
  line-height: 1;
  letter-spacing: -0.03em;
  font-family: var(--font-mono);
}
.stat-label {
  font-size: 13px;
  color: var(--text-secondary);
  font-weight: 500;
}
.stat-trend {
  font-size: 12px;
  font-family: var(--font-mono);
  margin-top: 4px;
}
.stat-trend.up   { color: #34d399; }
.stat-trend.down { color: #f87171; }

/* ── Dashboard grid ──────────────────────────────────────── */
.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
  margin-bottom: 28px;
}

.content-grid {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 20px;
}
@media (max-width: 1100px) { .content-grid { grid-template-columns: 1fr; } }

/* ── Chart placeholder ───────────────────────────────────── */
.chart-container {
  background: var(--bg-card);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  min-height: 280px;
  display: flex; flex-direction: column;
}
.chart-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 20px;
}
.chart-title { font-size: 15px; font-weight: 600; }
.chart-body {
  flex: 1;
  display: flex; align-items: center; justify-content: center;
  position: relative;
}

/* Animated bar chart placeholder */
.mock-bars {
  display: flex; align-items: flex-end; gap: 8px;
  height: 160px; width: 100%;
}
.mock-bar {
  flex: 1;
  border-radius: 4px 4px 0 0;
  background: linear-gradient(to top, var(--gold-600), var(--gold-400));
  opacity: 0.7;
  animation: bar-grow var(--dur, 1s) ease-out both;
  animation-delay: var(--delay, 0s);
  transform-origin: bottom;
}
@keyframes bar-grow {
  from { transform: scaleY(0); opacity: 0; }
  to   { transform: scaleY(1); opacity: 0.7; }
}

/* ══════════════════════════════════════════════════════════════
   BUTTONS
══════════════════════════════════════════════════════════════ */
.btn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 9px 18px;
  border-radius: var(--radius-sm);
  font-family: var(--font-sans);
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  text-decoration: none;
  transition: all var(--transition-fast);
  white-space: nowrap;
  user-select: none;
}
.btn:active { transform: scale(0.97); }

.btn-primary {
  background: linear-gradient(135deg, var(--gold-600), var(--gold-400));
  color: #000;
  border-color: var(--gold-300);
}
.btn-primary:hover {
  box-shadow: var(--shadow-gold);
  filter: brightness(1.1);
  transform: translateY(-1px);
}

.btn-secondary {
  background: var(--bg-card);
  color: var(--text-primary);
  border-color: var(--border);
}
.btn-secondary:hover {
  background: var(--bg-card-hover);
  border-color: var(--border-gold);
  box-shadow: var(--shadow-gold);
}

.btn-danger {
  background: rgba(239, 68, 68, 0.12);
  color: #f87171;
  border-color: rgba(239, 68, 68, 0.3);
}
.btn-danger:hover {
  background: rgba(239, 68, 68, 0.2);
  box-shadow: 0 0 16px rgba(239,68,68,0.25);
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border-color: transparent;
}
.btn-ghost:hover {
  background: var(--bg-card);
  color: var(--text-primary);
  border-color: var(--border);
}

.btn-sm { padding: 6px 12px; font-size: 12px; }
.btn-lg { padding: 12px 24px; font-size: 15px; }
.btn-icon { padding: 9px; }

/* ── Icon buttons ────────────────────────────────────────── */
.icon-btn {
  width: 36px; height: 36px;
  border-radius: var(--radius-sm);
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition-fast);
  font-size: 15px;
}
.icon-btn:hover {
  background: var(--bg-card-hover);
  border-color: var(--border-gold);
  color: var(--gold-400);
  box-shadow: var(--shadow-gold);
}

/* ══════════════════════════════════════════════════════════════
   FORMS & INPUTS
══════════════════════════════════════════════════════════════ */
.form-group { display: flex; flex-direction: column; gap: 6px; }

.form-label {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-secondary);
  font-family: var(--font-mono);
}

.form-input,
.form-textarea,
.form-select {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 14px;
  padding: 10px 14px;
  outline: none;
  transition: all var(--transition-fast);
  width: 100%;
}
.form-input::placeholder,
.form-textarea::placeholder { color: var(--text-muted); }
.form-input:focus,
.form-textarea:focus,
.form-select:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--gold-glow), var(--shadow-gold);
  background: rgba(245,158,11,0.04);
}
.form-textarea { resize: vertical; min-height: 100px; }
.form-select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%23888' viewBox='0 0 16 16'%3E%3Cpath d='M7.247 11.14L2.451 5.658C1.885 5.013 2.345 4 3.204 4h9.592a1 1 0 0 1 .753 1.659l-4.796 5.48a1 1 0 0 1-1.506 0z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
  cursor: pointer;
}
.form-select option { background: var(--bg-deep); color: var(--text-primary); }

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-row-3 { grid-template-columns: 1fr 1fr 1fr; }

/* ── Field builder row ───────────────────────────────────── */
.field-builder-row {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr auto;
  gap: 10px;
  align-items: end;
  padding: 14px 16px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  transition: border-color var(--transition-fast);
}
.field-builder-row:hover { border-color: var(--border-gold); }

/* ── Toggle switch ───────────────────────────────────────── */
.toggle {
  position: relative;
  width: 40px; height: 22px;
  flex-shrink: 0;
}
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
  position: absolute; inset: 0;
  background: var(--border);
  border-radius: 22px;
  cursor: pointer;
  transition: background var(--transition-fast);
}
.toggle-slider::before {
  content: '';
  position: absolute;
  width: 16px; height: 16px;
  left: 3px; top: 3px;
  background: white;
  border-radius: 50%;
  transition: transform var(--transition-fast);
}
.toggle input:checked + .toggle-slider { background: var(--gold); }
.toggle input:checked + .toggle-slider::before { transform: translateX(18px); }

/* ══════════════════════════════════════════════════════════════
   TABLES
══════════════════════════════════════════════════════════════ */
.table-container {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}
.table-toolbar {
  padding: 16px 20px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  border-bottom: 1px solid var(--border);
}
.table-search {
  display: flex; align-items: center; gap: 8px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  flex: 1; max-width: 320px;
  transition: border-color var(--transition-fast);
}
.table-search:focus-within {
  border-color: var(--border-gold);
  box-shadow: 0 0 12px var(--gold-glow);
}
.table-search input {
  background: transparent; border: none; outline: none;
  color: var(--text-primary); font-size: 13px; flex: 1;
}
.table-search input::placeholder { color: var(--text-muted); }

table { width: 100%; border-collapse: collapse; }
thead tr {
  border-bottom: 1px solid var(--border);
  background: rgba(255,255,255,0.02);
}
th {
  text-align: left;
  padding: 11px 20px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  font-family: var(--font-mono);
  white-space: nowrap;
}
td {
  padding: 13px 20px;
  font-size: 13.5px;
  color: var(--text-secondary);
  border-bottom: 1px solid rgba(255,255,255,0.04);
}
tbody tr { transition: background var(--transition-fast); }
tbody tr:hover { background: rgba(245,158,11,0.04); }
[data-theme="light"] tbody tr:hover { background: rgba(124,58,237,0.05); }
tbody tr:hover td { color: var(--text-primary); }
tbody tr:last-child td { border-bottom: none; }

.table-actions { display: flex; gap: 4px; }

/* ══════════════════════════════════════════════════════════════
   MODALS
══════════════════════════════════════════════════════════════ */
.modal-overlay {
  position: fixed; inset: 0; z-index: 1000;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  animation: overlay-in var(--transition) ease;
}
@keyframes overlay-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.modal {
  background: var(--bg-panel);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  width: 100%; max-width: 640px;
  max-height: 90vh;
  overflow: hidden;
  display: flex; flex-direction: column;
  box-shadow: var(--shadow-lg), 0 0 40px rgba(0,0,0,0.4);
  animation: modal-in 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}
@keyframes modal-in {
  from { transform: scale(0.92) translateY(20px); opacity: 0; }
  to   { transform: scale(1) translateY(0); opacity: 1; }
}

.modal-header {
  padding: 22px 28px 18px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  background: linear-gradient(135deg, rgba(245,158,11,0.05), transparent);
}
.modal-title { font-size: 17px; font-weight: 700; }
.modal-body { padding: 24px 28px; flex: 1; overflow-y: auto; }
.modal-body::-webkit-scrollbar { width: 4px; }
.modal-body::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }
.modal-footer {
  padding: 16px 28px;
  border-top: 1px solid var(--border);
  display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap;
  background: rgba(0,0,0,0.15);
}

/* ══════════════════════════════════════════════════════════════
   BADGES & TAGS
══════════════════════════════════════════════════════════════ */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 9px;
  border-radius: 20px;
  font-size: 11.5px;
  font-weight: 600;
  font-family: var(--font-mono);
  letter-spacing: 0.02em;
}
.badge-gold    { background: rgba(245,158,11,0.15); color: var(--gold-400); border: 1px solid rgba(245,158,11,0.3); }
[data-theme="light"] .badge-gold { background: rgba(124,58,237,0.12); color: #7c3aed; border-color: rgba(124,58,237,0.30); }
.badge-blue    { background: rgba(59,130,246,0.15); color: #60a5fa; border: 1px solid rgba(59,130,246,0.3); }
.badge-green   { background: rgba(52,211,153,0.15); color: #34d399; border: 1px solid rgba(52,211,153,0.3); }
.badge-red     { background: rgba(248,113,113,0.15); color: #f87171; border: 1px solid rgba(248,113,113,0.3); }
.badge-purple  { background: rgba(167,139,250,0.15); color: #a78bfa; border: 1px solid rgba(167,139,250,0.3); }

/* ── Field type badge ────────────────────────────────────── */
.type-badge {
  font-size: 11px;
  font-family: var(--font-mono);
  padding: 2px 8px;
  border-radius: var(--radius-sm);
  background: rgba(255,255,255,0.06);
  border: 1px solid var(--border);
  color: var(--text-secondary);
}

/* ══════════════════════════════════════════════════════════════
   PAGE HEADERS
══════════════════════════════════════════════════════════════ */
.page-header {
  display: flex; align-items: flex-start; justify-content: space-between;
  margin-bottom: 28px; gap: 16px;
}
.page-header-text h1 {
  font-size: 26px; font-weight: 700;
  letter-spacing: -0.03em;
  background: linear-gradient(135deg, var(--text-primary) 60%, var(--gold-400));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  margin-bottom: 4px;
}
.page-header-text p { font-size: 14px; color: var(--text-secondary); }

/* ══════════════════════════════════════════════════════════════
   TOAST NOTIFICATIONS
══════════════════════════════════════════════════════════════ */
#toast-container {
  position: fixed;
  bottom: 24px; right: 24px;
  z-index: 9999;
  display: flex; flex-direction: column; gap: 8px;
  pointer-events: none;
}
.toast {
  background: var(--bg-panel);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 18px;
  min-width: 280px; max-width: 420px;
  display: flex; align-items: flex-start; gap: 12px;
  box-shadow: var(--shadow-lg);
  pointer-events: all;
  animation: toast-in 0.3s cubic-bezier(0.34,1.56,0.64,1);
}
.toast.success { border-left: 3px solid #34d399; }
.toast.error   { border-left: 3px solid #f87171; }
.toast.info    { border-left: 3px solid var(--gold); }
.toast-icon { font-size: 16px; flex-shrink: 0; margin-top: 1px; }
.toast-title { font-size: 13.5px; font-weight: 600; margin-bottom: 2px; }
.toast-msg   { font-size: 12.5px; color: var(--text-secondary); }
@keyframes toast-in {
  from { transform: translateX(20px) scale(0.95); opacity: 0; }
  to   { transform: translateX(0) scale(1); opacity: 1; }
}

/* ══════════════════════════════════════════════════════════════
   AUTH / LOGIN PAGE
══════════════════════════════════════════════════════════════ */
.auth-page {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.auth-card {
  width: 100%; max-width: 420px;
  background: var(--bg-panel);
  backdrop-filter: blur(24px) saturate(200%);
  -webkit-backdrop-filter: blur(24px) saturate(200%);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 40px 36px;
  box-shadow: var(--shadow-lg), 0 0 60px rgba(245,158,11,0.08);
  animation: card-appear 0.5s cubic-bezier(0.34,1.56,0.64,1);
}
@keyframes card-appear {
  from { transform: translateY(40px) scale(0.95); opacity: 0; }
  to   { transform: translateY(0) scale(1); opacity: 1; }
}
.auth-logo {
  text-align: center; margin-bottom: 32px;
}
.auth-logo-mark {
  width: 64px; height: 64px;
  background: linear-gradient(135deg, var(--gold-600), var(--gold-300));
  border-radius: var(--radius);
  display: flex; align-items: center; justify-content: center;
  font-size: 28px; margin: 0 auto 14px;
  box-shadow: var(--shadow-gold);
}
.auth-logo-name {
  font-size: 24px; font-weight: 800;
  letter-spacing: -0.04em;
  background: linear-gradient(135deg, var(--gold-400), var(--gold-300));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}
.auth-logo-tagline { font-size: 13px; color: var(--text-muted); margin-top: 4px; }

.auth-form { display: flex; flex-direction: column; gap: 18px; }
.auth-divider { border: none; border-top: 1px solid var(--border); }

/* ══════════════════════════════════════════════════════════════
   EMPTY STATE
══════════════════════════════════════════════════════════════ */
.empty-state {
  text-align: center;
  padding: 60px 24px;
  color: var(--text-muted);
}
.empty-state-icon { font-size: 48px; margin-bottom: 16px; opacity: 0.4; }
.empty-state h3 { font-size: 17px; font-weight: 600; color: var(--text-secondary); margin-bottom: 8px; }
.empty-state p  { font-size: 14px; }

/* ══════════════════════════════════════════════════════════════
   LOADING STATES
══════════════════════════════════════════════════════════════ */
.skeleton {
  background: linear-gradient(
    90deg,
    rgba(255,255,255,0.04) 0%,
    rgba(255,255,255,0.08) 50%,
    rgba(255,255,255,0.04) 100%
  );
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: var(--radius-sm);
}
@keyframes shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.spinner {
  width: 20px; height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--gold);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ══════════════════════════════════════════════════════════════
   THEME TOGGLE
══════════════════════════════════════════════════════════════ */
.theme-toggle {
  width: 36px; height: 36px;
  border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  background: var(--bg-card);
  border: 1px solid var(--border);
  cursor: pointer;
  transition: all var(--transition-fast);
  font-size: 16px;
  color: var(--text-secondary);
}
.theme-toggle:hover {
  border-color: var(--border-gold);
  color: var(--gold-400);
  box-shadow: var(--shadow-gold);
}

/* ══════════════════════════════════════════════════════════════
   MODULE CARDS (Module Builder list)
══════════════════════════════════════════════════════════════ */
.module-card {
  background: var(--bg-card);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px 22px;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  transition: all var(--transition);
  cursor: pointer;
}
.module-card:hover {
  border-color: var(--border-gold);
  background: var(--bg-card-hover);
  box-shadow: var(--shadow-gold);
  transform: translateX(-4px);
}
.module-card-icon {
  width: 46px; height: 46px;
  border-radius: var(--radius-sm);
  background: linear-gradient(135deg, rgba(245,158,11,0.2), rgba(245,158,11,0.05));
  border: 1px solid var(--border-gold);
  display: flex; align-items: center; justify-content: center;
  font-size: 20px; flex-shrink: 0;
}
.module-card-info { flex: 1; }
.module-card-name { font-size: 15px; font-weight: 600; margin-bottom: 2px; }
.module-card-desc { font-size: 12.5px; color: var(--text-muted); }
.module-card-meta { display: flex; gap: 6px; margin-top: 6px; align-items: center; }

/* ══════════════════════════════════════════════════════════════
   SCROLLBAR GLOBAL
══════════════════════════════════════════════════════════════ */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.12); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.22); }

/* ══════════════════════════════════════════════════════════════
   UTILITY CLASSES
══════════════════════════════════════════════════════════════ */
.hidden    { display: none !important; }
.flex      { display: flex; }
.flex-col  { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: 8px; }
.gap-4 { gap: 16px; }
.mt-4  { margin-top: 16px; }
.mb-4  { margin-bottom: 16px; }
.text-gold    { color: var(--gold-400); }
.text-muted   { color: var(--text-muted); }
.text-sm      { font-size: 13px; }
.font-mono    { font-family: var(--font-mono); }
.text-center  { text-align: center; }
.w-full       { width: 100%; }
.divider { border: none; border-top: 1px solid var(--border); margin: 20px 0; }

/* ══════════════════════════════════════════════════════════════
   RESPONSIVE
══════════════════════════════════════════════════════════════ */
@media (max-width: 768px) {
  :root { --sidebar-w: 0px; }
  .sidebar { transform: translateX(260px); width: 260px; }
  .sidebar.open { transform: translateX(0); }
  .main-area { margin-right: 0; }
  .dashboard-grid { grid-template-columns: 1fr 1fr; }
  .form-row, .form-row-3 { grid-template-columns: 1fr; }
  .field-builder-row { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 480px) {
  .dashboard-grid { grid-template-columns: 1fr; }
  .page-content { padding: 12px; }
}

/* ── Column config item ──────────────────────────────────── */
.col-config-item { transition: background 0.15s, opacity 0.15s; }
.col-config-item:hover { border-color: var(--border-gold) !important; }

/* ── Mobile: card layout per tabelle record ──────────────── */
@media (max-width: 768px) {
  .records-table-wrap table { display: none; }
  .records-card-list { display: flex !important; flex-direction: column; padding: 12px; }

  .table-toolbar { flex-direction: column; align-items: stretch; gap: 10px; }
  .table-search  { max-width: 100%; }

  .page-header { flex-direction: column; align-items: flex-start; gap: 12px; }
  .page-header > div > .btn { flex: 1; }

  .module-card { flex-direction: column !important; align-items: flex-start !important; }
  .module-card > div:last-child { width: 100%; }
  .module-card > div:last-child > .btn { flex: 1; min-width: 70px; text-align: center; }

  .modal-overlay { padding: 0; align-items: flex-end; }
  .modal { border-radius: var(--radius-lg) var(--radius-lg) 0 0; max-height: 92vh; width: 100% !important; max-width: 100% !important; }

  .field-edit-row { grid-template-columns: 1fr 1fr !important; }
  .field-edit-row > div:first-child { grid-column: 1 / -1; }
}

/* ── Mobile sidebar theme ────────────────────────────────── */
@media (max-width: 900px) {
  :root:not([data-theme="light"]) .sidebar, [data-theme=""] .sidebar {
    background: rgba(5, 10, 25, 0.97) !important;
  }
  [data-theme="light"] .sidebar {
    background: rgba(235, 237, 255, 0.98) !important;
    border-left: 1px solid rgba(180, 130, 0, 0.25);
    border-right: none;
  }
}

/* ══════════════════════════════════════════════════════════════
   HAMBURGER MENU — Mobile sidebar overlay
══════════════════════════════════════════════════════════════ */
@media (max-width: 768px) {
  /* ── App shell: establish stacking context ── */
  #app-shell {
    position: relative;
  }

  .sidebar {
    transform: translateX(260px);
    width: 260px;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 300;
    position: fixed;
    top: 0; right: 0; left: auto;
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
  }
  .sidebar.open {
    transform: translateX(0);
    box-shadow: -8px 0 40px rgba(0,0,0,0.8);
    pointer-events: all !important;
  }
  /* All children of open sidebar must be interactive */
  .sidebar.open * {
    pointer-events: auto;
  }

  /* ── Overlay: sits between content and sidebar ── */
  #sidebar-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.65);
    z-index: 250;
    cursor: pointer;
    /* NO backdrop-filter here - causes stacking context issues */
  }

  .main-area {
    margin-right: 0 !important;
  }
  #sidebar-toggle {
    display: flex !important;
  }
  .topbar {
    padding: 0 16px;
  }
  .page-content {
    padding: 16px;
  }
  body:has(.sidebar.open) {
    overflow: hidden;
  }
}
/* ══════════════════════════════════════════════════════════════
   LIGHT THEME — Purple accent overrides
   In light mode all gold/amber accents become purple (#7c3aed)
══════════════════════════════════════════════════════════════ */

/* Purple palette tokens for light theme */
[data-theme="light"] {
  --accent:           #7c3aed;
  --accent-light:     #a78bfa;
  --accent-lighter:   #c4b5fd;
  --accent-bg:        rgba(124, 58, 237, 0.10);
  --accent-bg-hover:  rgba(124, 58, 237, 0.18);
  --accent-glow:      rgba(124, 58, 237, 0.30);
  --accent-border:    rgba(124, 58, 237, 0.40);
  --accent-border-focus: rgba(124, 58, 237, 0.70);

  /* Remap all gold tokens to purple so every var(--gold-*) becomes purple */
  --gold:      #7c3aed;
  --gold-300:  #c4b5fd;
  --gold-400:  #7c3aed;
  --gold-600:  #5b21b6;
  --gold-glow: rgba(124, 58, 237, 0.25);

  --text-gold:        #7c3aed;
  --border-gold:      rgba(124, 58, 237, 0.40);
  --border-focus:     rgba(124, 58, 237, 0.70);
  --shadow-gold:      0 0 20px rgba(124,58,237,0.25), 0 0 60px rgba(124,58,237,0.10);
}

/* Sidebar logo text & icon — purple gradient in light mode */
[data-theme="light"] .sidebar-logo-icon {
  background: linear-gradient(135deg, #5b21b6, #7c3aed);
  color: var(--bg-void);
  box-shadow: 0 0 16px rgba(124,58,237,0.35);
}
[data-theme="light"] .sidebar-logo-text {
  background: linear-gradient(135deg, #7c3aed, #a78bfa);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

/* Active nav item — purple */
[data-theme="light"] .nav-item.active {
  background: linear-gradient(135deg, rgba(124,58,237,0.15), rgba(124,58,237,0.05));
  color: #7c3aed;
  border-color: rgba(124,58,237,0.40);
}
[data-theme="light"] .nav-item.active .nav-icon { color: #7c3aed; }

/* Nav badge — purple */
[data-theme="light"] .nav-badge {
  background: rgba(124,58,237,0.12);
  color: #7c3aed;
  border-color: rgba(124,58,237,0.35);
}

/* User card hover */
[data-theme="light"] .user-card:hover {
  border-color: rgba(124,58,237,0.40);
  box-shadow: 0 0 16px rgba(124,58,237,0.20);
}
[data-theme="light"] .user-avatar {
  background: linear-gradient(135deg, #5b21b6, #3b82f6);
}

/* Glass card hover */
[data-theme="light"] .glass-card:hover {
  border-color: rgba(124,58,237,0.35);
  box-shadow: 0 0 20px rgba(124,58,237,0.20);
}

/* Stat widget hover top line */
[data-theme="light"] .stat-widget::before {
  background: linear-gradient(90deg, transparent, rgba(124,58,237,0.35), transparent);
}

/* Primary button — purple */
[data-theme="light"] .btn-primary {
  background: linear-gradient(135deg, #5b21b6, #7c3aed);
  color: #fff;
  border-color: #a78bfa;
}
[data-theme="light"] .btn-primary:hover {
  box-shadow: 0 0 20px rgba(124,58,237,0.40);
  filter: brightness(1.08);
}

/* Secondary button hover */
[data-theme="light"] .btn-secondary:hover {
  border-color: rgba(124,58,237,0.40);
  box-shadow: 0 0 12px rgba(124,58,237,0.20);
}

/* Icon button hover */
[data-theme="light"] .icon-btn:hover {
  border-color: rgba(124,58,237,0.40);
  color: #7c3aed;
  box-shadow: 0 0 12px rgba(124,58,237,0.20);
}

/* Theme toggle hover */
[data-theme="light"] .theme-toggle:hover {
  border-color: rgba(124,58,237,0.40);
  color: #7c3aed;
  box-shadow: 0 0 12px rgba(124,58,237,0.20);
}

/* Inputs focus — purple ring */
[data-theme="light"] .form-input:focus,
[data-theme="light"] .form-textarea:focus,
[data-theme="light"] .form-select:focus {
  border-color: rgba(124,58,237,0.70);
  box-shadow: 0 0 0 3px rgba(124,58,237,0.12);
  background: rgba(124,58,237,0.04);
}

/* Table search focus */
[data-theme="light"] .table-search:focus-within {
  border-color: rgba(124,58,237,0.40);
  box-shadow: 0 0 12px rgba(124,58,237,0.15);
}

/* Badge gold → purple in light mode */
[data-theme="light"] .badge-gold {
  background: rgba(124,58,237,0.12);
  color: #7c3aed;
  border: 1px solid rgba(124,58,237,0.30);
}
[data-theme="light"] .text-gold { color: #7c3aed; }

/* Module card icon */
[data-theme="light"] .module-card-icon {
  background: linear-gradient(135deg, rgba(124,58,237,0.18), rgba(124,58,237,0.05));
  border-color: rgba(124,58,237,0.35);
}
[data-theme="light"] .module-card:hover {
  border-color: rgba(124,58,237,0.40);
  box-shadow: 0 0 20px rgba(124,58,237,0.18);
}

/* Toggle checked — purple */
[data-theme="light"] .toggle input:checked + .toggle-slider { background: #7c3aed; }

/* Table row hover */
[data-theme="light"] tbody tr:hover { background: rgba(124,58,237,0.05); }

/* Auth card glow */
[data-theme="light"] .auth-card {
  box-shadow: var(--shadow-lg), 0 0 60px rgba(124,58,237,0.10);
}
[data-theme="light"] .auth-logo-mark {
  background: linear-gradient(135deg, #5b21b6, #a78bfa);
  box-shadow: 0 0 20px rgba(124,58,237,0.35);
}
[data-theme="light"] .auth-logo-name {
  background: linear-gradient(135deg, #7c3aed, #a78bfa);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

/* Page header h1 gradient */
[data-theme="light"] .page-header-text h1 {
  background: linear-gradient(135deg, var(--text-primary) 60%, #7c3aed);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

/* Mock bars chart */
[data-theme="light"] .mock-bar {
  background: linear-gradient(to top, #5b21b6, #a78bfa);
}

/* Spinner */
[data-theme="light"] .spinner {
  border-top-color: #7c3aed;
}

/* Toast info border */
[data-theme="light"] .toast.info {
  border-left-color: #7c3aed;
}

/* Topbar in light already themed — keep existing gold tones, just ensure toggle works */
[data-theme="light"] .topbar {
  background: rgba(248, 245, 255, 0.92);
  border-bottom-color: rgba(124, 58, 237, 0.20);
  box-shadow: 0 1px 12px rgba(124,58,237,0.08);
}

/* Nebula purple tint in light mode */
[data-theme="light"] #space-bg {
  background:
    radial-gradient(ellipse at 20% 50%, rgba(124,58,237,0.10) 0%, transparent 50%),
    radial-gradient(ellipse at 80% 20%, rgba(167,139,250,0.08) 0%, transparent 40%),
    radial-gradient(ellipse at 60% 80%, rgba(109,40,217,0.06) 0%, transparent 40%),
    var(--bg-deep);
}

/* ── Stelle viola per il tema chiaro ──────────────────────── */
[data-theme="light"] .stars-sm {
  background-image:
    radial-gradient(1px 1px at 15% 10%, rgba(10,5,30,0.55)  0%, transparent 100%),
    radial-gradient(1px 1px at 32% 78%, rgba(10,5,30,0.40)  0%, transparent 100%),
    radial-gradient(1px 1px at 47% 25%, rgba(10,5,30,0.60)  0%, transparent 100%),
    radial-gradient(1px 1px at 63% 55%, rgba(10,5,30,0.35)  0%, transparent 100%),
    radial-gradient(1px 1px at 78% 12%, rgba(10,5,30,0.50)  0%, transparent 100%),
    radial-gradient(1px 1px at 91% 68%, rgba(10,5,30,0.45)  0%, transparent 100%),
    radial-gradient(1px 1px at  5% 45%, rgba(10,5,30,0.40)  0%, transparent 100%),
    radial-gradient(1px 1px at 25% 90%, rgba(10,5,30,0.55)  0%, transparent 100%),
    radial-gradient(1px 1px at 55% 88%, rgba(10,5,30,0.35)  0%, transparent 100%),
    radial-gradient(1px 1px at 72% 35%, rgba(10,5,30,0.60)  0%, transparent 100%),
    radial-gradient(1px 1px at 88% 92%, rgba(10,5,30,0.45)  0%, transparent 100%),
    radial-gradient(1px 1px at 10% 62%, rgba(10,5,30,0.50)  0%, transparent 100%),
    radial-gradient(1px 1px at 39% 42%, rgba(10,5,30,0.40)  0%, transparent 100%),
    radial-gradient(1px 1px at 58% 18%, rgba(10,5,30,0.55)  0%, transparent 100%),
    radial-gradient(1px 1px at 83% 48%, rgba(10,5,30,0.60)  0%, transparent 100%),
    radial-gradient(1px 1px at 95% 28%, rgba(10,5,30,0.45)  0%, transparent 100%),
    radial-gradient(1px 1px at 20% 33%, rgba(10,5,30,0.50)  0%, transparent 100%),
    radial-gradient(1px 1px at 44% 70%, rgba(10,5,30,0.35)  0%, transparent 100%),
    radial-gradient(1px 1px at 67% 82%, rgba(10,5,30,0.45)  0%, transparent 100%),
    radial-gradient(1px 1px at 85%  5%, rgba(10,5,30,0.55)  0%, transparent 100%);
  background-size: 100% 100%;
}

[data-theme="light"] .stars-md {
  background-image:
    radial-gradient(1.5px 1.5px at 18% 22%, rgba(10,5,30,0.70)  0%, transparent 100%),
    radial-gradient(2px   2px   at 36% 61%, rgba(10,5,30,0.55)  0%, transparent 100%),
    radial-gradient(1.5px 1.5px at 52% 14%, rgba(10,5,30,0.65)  0%, transparent 100%),
    radial-gradient(2px   2px   at 71% 73%, rgba(10,5,30,0.60)  0%, transparent 100%),
    radial-gradient(1.5px 1.5px at 87% 38%, rgba(10,5,30,0.75)  0%, transparent 100%),
    radial-gradient(2px   2px   at  8% 85%, rgba(10,5,30,0.50)  0%, transparent 100%),
    radial-gradient(1.5px 1.5px at 42% 96%, rgba(10,5,30,0.60)  0%, transparent 100%),
    radial-gradient(2px   2px   at 60% 50%, rgba(10,5,30,0.65)  0%, transparent 100%),
    radial-gradient(1.5px 1.5px at 79% 19%, rgba(10,5,30,0.70)  0%, transparent 100%),
    radial-gradient(2px   2px   at 94% 77%, rgba(10,5,30,0.55)  0%, transparent 100%);
}

[data-theme="light"] .stars-lg {
  background-image:
    radial-gradient(3px   3px   at 22% 30%, rgba(10,5,30,0.90)  0%, transparent 100%),
    radial-gradient(2.5px 2.5px at 55% 65%, rgba(10,5,30,1.00)  0%, transparent 100%),
    radial-gradient(3px   3px   at 80% 15%, rgba(10,5,30,0.85)  0%, transparent 100%),
    radial-gradient(2.5px 2.5px at 12% 75%, rgba(10,5,30,0.80)  0%, transparent 100%),
    radial-gradient(3px   3px   at 68% 88%, rgba(10,5,30,0.95)  0%, transparent 100%);
}

/* ── Nebulose viola nel tema chiaro ───────────────────────── */
[data-theme="light"] .nebula-1 { background: #7c3aed; opacity: 0.09; }
[data-theme="light"] .nebula-2 { background: #8b5cf6; opacity: 0.07; }
[data-theme="light"] .nebula-3 { background: #6d28d9; opacity: 0.10; }

/* ── Riflessi viola aggiuntivi (light-only) ───────────────── */
[data-theme="light"] #space-bg::before {
  content: '';
  position: absolute;
  width: 500px; height: 500px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(124,58,237,0.12) 0%, transparent 70%);
  top: -100px; right: -80px;
  pointer-events: none;
  animation: nebula-pulse 10s ease-in-out infinite alternate;
}
[data-theme="light"] #space-bg::after {
  content: '';
  position: absolute;
  width: 380px; height: 380px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(167,139,250,0.10) 0%, transparent 70%);
  bottom: -60px; left: 10%;
  pointer-events: none;
  animation: nebula-pulse 13s ease-in-out infinite alternate-reverse;
}

/* Shooting star: visibile anche nel tema chiaro con colore viola */
[data-theme="light"] .shooting-star {
  background: linear-gradient(90deg, transparent, rgba(124,58,237,0.7), transparent);
}

/* Field builder hover */
[data-theme="light"] .field-builder-row:hover { border-color: rgba(124,58,237,0.40); }

/* ══════════════════════════════════════════════════════════════
   DARK THEME — Explicit gold accent reinforcement
   (already default, but spelled out for clarity & overrides)
══════════════════════════════════════════════════════════════ */
:root,
[data-theme=""],
[data-theme]:not([data-theme="light"]) {
  --accent:            var(--gold-400);
  --accent-light:      var(--gold-300);
  --accent-bg:         var(--gold-glow);
  --accent-border:     var(--border-gold);
  --accent-border-focus: var(--border-focus);
}

/* ── Mobile: layout globale ──────────────────────────────── */
@media (max-width: 768px) {
  .dashboard-grid {
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-bottom: 16px;
  }

  /* Stat widget compact */
  .stat-widget {
    padding: 14px;
    gap: 5px;
    overflow: hidden;
  }
  .stat-icon {
    width: 34px; height: 34px;
    font-size: 15px;
    margin-bottom: 2px;
  }
  .stat-value {
    font-size: clamp(18px, 5vw, 26px);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 100%;
  }
  .stat-label {
    font-size: 11px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  /* Content grid stacks vertically */
  .content-grid {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  /* Charts compact */
  .chart-container {
    padding: 16px;
    min-height: 220px;
  }
  .chart-header { margin-bottom: 12px; }
  .chart-title { font-size: 14px; }

  /* Mock bars shorter on mobile */
  .mock-bars { height: 120px; }

  /* Activity list more compact */
  #activity-list { max-height: 160px; }

  /* Page header stacks */
  .page-header {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    margin-bottom: 16px;
  }
  .page-header .btn,
  .page-header > .btn {
    width: 100%;
    max-width: 100%;
    justify-content: center;
    box-sizing: border-box;
    display: flex;
  }
  .page-header-text h1 { font-size: 22px; }
  .page-header-text p  { font-size: 13px; }

  /* Topbar tighter */
  .topbar-title { font-size: 15px; }

  /* Prevent any child from overflowing the viewport */
  .main-area,
  .page-content { overflow-x: hidden; max-width: 100vw; }

  /* Hide logout text label on mobile to save space */
  #logout-btn { display: none !important; }
}

@media (max-width: 480px) {
  .dashboard-grid {
    grid-template-columns: 1fr 1fr;
    gap: 10px;
  }

  /* Stat widget even more compact on tiny screens */
  .stat-widget {
    padding: 12px;
    gap: 4px;
    overflow: hidden;
  }
  .stat-icon {
    width: 30px; height: 30px;
    font-size: 14px;
    flex-shrink: 0;
    margin-bottom: 2px;
  }
  .stat-value {
    font-size: clamp(16px, 6vw, 22px);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 100%;
  }
  .stat-label {
    font-size: 10px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .page-content { padding: 12px; }
  .chart-container { padding: 14px; min-height: 180px; }

  /* Full-width modal on tiny screens */
  .modal-overlay { padding: 0; align-items: flex-end; }
  .modal {
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    max-height: 92vh;
    width: 100% !important;
    max-width: 100% !important;
  }
}

/* ============================================================
   NOVA CRM — Calendar Module
   Aggiungere in append a nova.css
   ============================================================ */

.cal-page {
  display: flex;
  flex-direction: column;
  height: calc(100vh - var(--topbar-h) - 56px);
  min-height: 0;
  gap: 0;
}

/* Toolbar superiore */
.cal-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding-bottom: 12px;
  flex-shrink: 0;
  flex-wrap: nowrap;
}
.cal-toolbar-left {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  flex: 1;
}
.cal-period-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

/* Navigazione prev/today/next */
.cal-nav-group {
  display: flex;
  align-items: center;
  gap: 2px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 3px;
  flex-shrink: 0;
}
.cal-nav-btn {
  width: 30px; height: 30px;
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 16px;
  cursor: pointer;
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  transition: all var(--transition-fast);
  line-height: 1;
}
.cal-nav-btn:hover { background: var(--bg-card-hover); color: var(--text-primary); }
.cal-today-btn {
  padding: 5px 10px;
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.06em;
  cursor: pointer;
  transition: all var(--transition-fast);
  flex-shrink: 0;
}
.cal-today-btn:hover {
  background: var(--bg-card-hover);
  color: var(--text-primary);
  border-color: var(--border-gold);
}

/* Selettore vista */
.cal-view-switcher {
  display: flex;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 3px;
  gap: 2px;
  flex-shrink: 0;
}
.cal-view-btn {
  padding: 5px 11px;
  background: none;
  border: none;
  color: var(--text-secondary);
  font-family: var(--font-sans);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  border-radius: 8px;
  transition: all var(--transition-fast);
  white-space: nowrap;
}
.cal-view-btn:hover { background: var(--bg-card-hover); color: var(--text-primary); }
.cal-view-btn.active {
  background: linear-gradient(135deg, rgba(245,158,11,0.2), rgba(245,158,11,0.08));
  color: var(--gold-400);
  font-weight: 700;
  border: 1px solid rgba(245,158,11,0.3);
}

/* ── Pulsante + mobile (FAB) ─────────────────────────────── */
.cal-fab {
  display: none; /* visibile solo mobile */
  position: fixed;
  bottom: 80px; /* sopra bottom bar */
  right: 18px;
  width: 52px; height: 52px;
  background: linear-gradient(135deg, var(--gold-600), var(--gold-400));
  color: var(--bg-void);
  border: none;
  border-radius: 50%;
  font-size: 24px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 4px 20px rgba(245,158,11,0.45);
  z-index: 200;
  align-items: center;
  justify-content: center;
  transition: transform var(--transition-fast), box-shadow var(--transition-fast);
}
.cal-fab:active { transform: scale(0.92); }

/* ══════════════════════════════════════════════════════════════
   LAYOUT BODY — calendario + sidebar
══════════════════════════════════════════════════════════════ */
.cal-body {
  display: flex;
  flex: 1;
  min-height: 0;
  gap: 16px;
}

/* Griglia principale (90% larghezza desktop) */
.cal-main {
  flex: 1;
  min-width: 0;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* Sidebar destra */
.cal-sidebar {
  width: 220px;
  flex-shrink: 0;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px 14px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  overflow-y: auto;
  overflow-x: hidden;
}
.cal-sidebar::-webkit-scrollbar { width: 3px; }
.cal-sidebar::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

/* Pulsante nuovo evento dentro sidebar desktop */
.cal-new-btn {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 14px;
  background: linear-gradient(135deg, var(--gold-600), var(--gold-400));
  color: var(--bg-void);
  border: none;
  border-radius: var(--radius);
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: all var(--transition-fast);
}
.cal-new-btn:hover {
  box-shadow: var(--shadow-gold);
  filter: brightness(1.1);
  transform: translateY(-1px);
}

/* ══════════════════════════════════════════════════════════════
   MINI CALENDARIO (sidebar desktop)
══════════════════════════════════════════════════════════════ */
.mini-cal { width: 100%; }
.mini-cal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}
.mini-cal-title {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-primary);
}
.mini-cal-nav { display: flex; gap: 2px; }
.mini-cal-nav button {
  width: 22px; height: 22px;
  background: none;
  border: 1px solid var(--border);
  border-radius: 5px;
  color: var(--text-secondary);
  font-size: 12px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: all var(--transition-fast);
}
.mini-cal-nav button:hover { background: var(--bg-card-hover); color: var(--text-primary); border-color: var(--border-gold); }
.mini-cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 1px;
}
.mini-cal-dow {
  text-align: center;
  font-size: 9px;
  font-weight: 700;
  color: var(--text-muted);
  padding: 3px 0;
  font-family: var(--font-mono);
  letter-spacing: 0.04em;
}
.mini-cal-day {
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  color: var(--text-secondary);
  border-radius: 50%;
  cursor: pointer;
  transition: all var(--transition-fast);
  font-family: var(--font-mono);
  position: relative;
}
.mini-cal-day:hover { background: var(--bg-card-hover); color: var(--text-primary); }
.mini-cal-day.today { background: rgba(245,158,11,0.15); color: var(--gold-400); font-weight: 700; border: 1px solid rgba(245,158,11,0.3); }
.mini-cal-day.selected { background: var(--gold-400); color: var(--bg-void); font-weight: 700; }
.mini-cal-day.other-month { opacity: 0.3; }
.mini-cal-day.has-events::after {
  content: '';
  position: absolute;
  bottom: 2px; left: 50%; transform: translateX(-50%);
  width: 3px; height: 3px;
  border-radius: 50%;
  background: var(--gold-400);
}

/* ── Filtri ──────────────────────────────────────────────── */
.cal-filters-title {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.12em;
  color: var(--text-muted);
  text-transform: uppercase;
  font-family: var(--font-mono);
  margin-bottom: 6px;
}
.cal-filter-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition-fast);
  user-select: none;
}
.cal-filter-item:hover { background: var(--bg-card-hover); }
.cal-filter-dot {
  width: 9px; height: 9px;
  border-radius: 50%;
  flex-shrink: 0;
  transition: all var(--transition-fast);
}
.cal-filter-label {
  font-size: 12px;
  color: var(--text-secondary);
  flex: 1;
  transition: color var(--transition-fast);
}
.cal-filter-item.active .cal-filter-label { color: var(--text-primary); font-weight: 500; }
.cal-filter-item.inactive .cal-filter-dot { opacity: 0.2; }
.cal-filter-item.inactive .cal-filter-label { opacity: 0.4; }

/* ══════════════════════════════════════════════════════════════
   VISTA SETTIMANA
══════════════════════════════════════════════════════════════ */
.cal-week-header {
  display: grid;
  grid-template-columns: 48px repeat(7, 1fr);
  border-bottom: 1px solid var(--border);
  background: rgba(0,0,0,0.15);
  flex-shrink: 0;
}
.cal-week-header-gutter { border-right: 1px solid var(--border); }
.cal-week-day-header {
  padding: 8px 4px;
  text-align: center;
  border-right: 1px solid var(--border);
  cursor: pointer;
  transition: background var(--transition-fast);
}
.cal-week-day-header:hover { background: var(--bg-card-hover); }
.cal-week-day-header:last-child { border-right: none; }
.cal-week-dow {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  font-family: var(--font-mono);
  text-transform: uppercase;
}
.cal-week-date {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-secondary);
  font-family: var(--font-mono);
  line-height: 1.2;
  margin-top: 2px;
}
.cal-week-day-header.today .cal-week-date {
  width: 30px; height: 30px;
  background: var(--gold-400);
  color: var(--bg-void);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  margin: 2px auto 0;
  font-size: 15px;
}
.cal-week-day-header.today .cal-week-dow { color: var(--gold-400); }

.cal-week-body {
  display: grid;
  grid-template-columns: 48px repeat(7, 1fr);
  flex: 1;
  overflow-y: auto;
  position: relative;
  -webkit-overflow-scrolling: touch;
}
.cal-week-body::-webkit-scrollbar { width: 3px; }
.cal-week-body::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.cal-time-gutter { border-right: 1px solid var(--border); position: relative; }
.cal-time-label {
  position: absolute;
  right: 6px;
  font-size: 9px;
  color: var(--text-muted);
  font-family: var(--font-mono);
  transform: translateY(-50%);
  white-space: nowrap;
}
.cal-day-col {
  border-right: 1px solid var(--border);
  position: relative;
  cursor: pointer;
  min-height: 1440px;
}
.cal-day-col:last-child { border-right: none; }
.cal-hour-line { position: absolute; left: 0; right: 0; border-top: 1px solid var(--border); opacity: 0.4; }
.cal-half-line { position: absolute; left: 0; right: 0; border-top: 1px dashed var(--border); opacity: 0.2; }
.cal-now-line {
  position: absolute; left: 0; right: 0;
  border-top: 2px solid var(--gold-400);
  z-index: 10; pointer-events: none;
}
.cal-now-line::before {
  content: '';
  position: absolute;
  left: -4px; top: -4px;
  width: 8px; height: 8px;
  background: var(--gold-400);
  border-radius: 50%;
}

/* ── Vista 3 giorni (mobile) ─────────────────────────────── */
.cal-week-header.days-3 { grid-template-columns: 40px repeat(3, 1fr); }
.cal-week-body.days-3   { grid-template-columns: 40px repeat(3, 1fr); }

/* ══════════════════════════════════════════════════════════════
   VISTA MESE
══════════════════════════════════════════════════════════════ */
.cal-month-header {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  border-bottom: 1px solid var(--border);
  background: rgba(0,0,0,0.15);
  flex-shrink: 0;
}
.cal-month-dow {
  padding: 8px 4px;
  text-align: center;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  font-family: var(--font-mono);
  text-transform: uppercase;
  border-right: 1px solid var(--border);
}
.cal-month-dow:last-child { border-right: none; }
.cal-month-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.cal-month-grid::-webkit-scrollbar { width: 3px; }
.cal-month-grid::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }
.cal-month-cell {
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  padding: 5px 4px;
  min-height: 90px;
  cursor: pointer;
  overflow: hidden;
  transition: background var(--transition-fast);
  -webkit-tap-highlight-color: transparent;
}
.cal-month-cell:hover { background: rgba(255,255,255,0.02); }
.cal-month-cell:nth-child(7n) { border-right: none; }
.cal-month-cell.other-month { opacity: 0.4; }
.cal-month-cell.today { background: rgba(245,158,11,0.04); }
.cal-month-cell.today .cal-cell-date {
  background: var(--gold-400); color: var(--bg-void);
  border-radius: 50%;
  width: 22px; height: 22px;
  display: flex; align-items: center; justify-content: center;
}
.cal-cell-date {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary);
  font-family: var(--font-mono);
  margin-bottom: 3px;
  line-height: 1;
}

/* ══════════════════════════════════════════════════════════════
   CHIP EVENTO
══════════════════════════════════════════════════════════════ */
.cal-event-chip {
  display: block;
  padding: 2px 5px;
  border-radius: 3px;
  font-size: 10px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
  margin-bottom: 2px;
  transition: filter var(--transition-fast);
  line-height: 1.5;
  border-left: 2px solid transparent;
  -webkit-tap-highlight-color: transparent;
}
.cal-event-chip:hover { filter: brightness(1.2); }
/* Su mobile mostra solo il dot colorato */
.cal-event-dot {
  display: none;
  width: 7px; height: 7px;
  border-radius: 50%;
  margin: 1px auto;
}

/* ══════════════════════════════════════════════════════════════
   BLOCCO EVENTO FLOTTANTE (settimana)
══════════════════════════════════════════════════════════════ */
.cal-event-block {
  position: absolute;
  left: 3px; right: 3px;
  border-radius: 5px;
  padding: 3px 6px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  overflow: hidden;
  z-index: 5;
  border-left: 3px solid transparent;
  transition: filter var(--transition-fast), box-shadow var(--transition-fast);
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
}
.cal-event-block:hover { filter: brightness(1.15); box-shadow: 0 4px 16px rgba(0,0,0,0.4); z-index: 10; }
.cal-event-block.dragging { opacity: 0.55; z-index: 100; cursor: grabbing; }
.cal-event-block-title { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; line-height: 1.4; }
.cal-event-block-time { font-size: 9px; opacity: 0.8; font-family: var(--font-mono); line-height: 1.4; }

/* ══════════════════════════════════════════════════════════════
   VISTA AGENDA
══════════════════════════════════════════════════════════════ */
.cal-agenda { flex: 1; overflow-y: auto; padding: 0; -webkit-overflow-scrolling: touch; }
.cal-agenda::-webkit-scrollbar { width: 3px; }
.cal-agenda::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }
.cal-agenda-day { padding: 0 14px 14px; }
.cal-agenda-day-header {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 10px 0 6px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 6px;
  position: sticky; top: 0;
  background: var(--bg-panel);
  z-index: 5;
}
.cal-agenda-day-date { font-size: 20px; font-weight: 700; color: var(--text-primary); font-family: var(--font-mono); line-height: 1; }
.cal-agenda-day-label { font-size: 10px; font-weight: 700; letter-spacing: 0.1em; color: var(--text-muted); text-transform: uppercase; font-family: var(--font-mono); }
.cal-agenda-day-header.today .cal-agenda-day-date { color: var(--gold-400); }
.cal-agenda-empty { font-size: 11px; color: var(--text-muted); padding: 6px 0; font-style: italic; }
.cal-agenda-event {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 9px 10px;
  border-radius: var(--radius);
  background: var(--bg-card);
  border: 1px solid var(--border);
  margin-bottom: 5px;
  cursor: pointer;
  transition: all var(--transition-fast);
  -webkit-tap-highlight-color: transparent;
}
.cal-agenda-event:hover { background: var(--bg-card-hover); border-color: var(--border-gold); transform: translateX(3px); }
.cal-agenda-event-color { width: 3px; border-radius: 2px; align-self: stretch; flex-shrink: 0; }
.cal-agenda-event-time { font-size: 10px; font-family: var(--font-mono); color: var(--text-muted); white-space: nowrap; min-width: 66px; padding-top: 1px; }
.cal-agenda-event-body { flex: 1; min-width: 0; }
.cal-agenda-event-title { font-size: 13px; font-weight: 600; color: var(--text-primary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cal-agenda-event-meta { font-size: 11px; color: var(--text-muted); margin-top: 1px; }
.cal-agenda-event-type { font-size: 10px; padding: 1px 7px; border-radius: 20px; font-weight: 600; align-self: flex-start; margin-top: 2px; white-space: nowrap; flex-shrink: 0; }

/* ── Drop zone ───────────────────────────────────────────── */
.cal-day-col.drag-over,
.cal-month-cell.drag-over {
  background: rgba(245,158,11,0.06) !important;
  outline: 2px dashed rgba(245,158,11,0.4);
  outline-offset: -2px;
}

/* ══════════════════════════════════════════════════════════════
   QUICK CREATE MODAL
══════════════════════════════════════════════════════════════ */
.cal-quick-modal {
  position: fixed;
  z-index: 1100;
  background: var(--bg-panel);
  border: 1px solid var(--border-gold);
  border-radius: var(--radius-lg);
  padding: 18px;
  width: 300px;
  box-shadow: var(--shadow-lg), var(--shadow-gold);
  animation: modal-in 0.22s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.cal-quick-title {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  text-transform: uppercase;
  font-family: var(--font-mono);
  margin-bottom: 10px;
}
.cal-type-picker { display: flex; gap: 5px; margin-bottom: 12px; flex-wrap: wrap; }
.cal-type-btn {
  padding: 4px 9px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid var(--border);
  background: none;
  color: var(--text-secondary);
  font-family: var(--font-sans);
  transition: all var(--transition-fast);
}
.cal-type-btn:hover { background: var(--bg-card-hover); }
.cal-type-btn.active { color: var(--bg) !important; font-weight: 700; }

/* ══════════════════════════════════════════════════════════════
   BOTTOM SHEET (mobile) — sostituisce la sidebar
══════════════════════════════════════════════════════════════ */
.cal-bottom-bar {
  display: none; /* nascosta su desktop */
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: var(--bg-panel);
  border-top: 1px solid var(--border);
  padding: 8px 0 max(8px, env(safe-area-inset-bottom));
  z-index: 210;
  backdrop-filter: blur(16px);
}
.cal-bottom-bar-items {
  display: flex;
  justify-content: space-around;
  align-items: center;
}
.cal-bottom-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 6px 16px;
  cursor: pointer;
  border: none;
  background: none;
  color: var(--text-muted);
  font-family: var(--font-sans);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.04em;
  transition: color var(--transition-fast);
  -webkit-tap-highlight-color: transparent;
}
.cal-bottom-item .cal-bottom-icon { font-size: 20px; line-height: 1; }
.cal-bottom-item.active { color: var(--gold-400); }
.cal-bottom-item:active { transform: scale(0.9); }

/* Drawer filtri dal basso (mobile) */
.cal-filters-drawer {
  display: none;
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: var(--bg-panel);
  border-top: 1px solid var(--border-gold);
  border-radius: 20px 20px 0 0;
  padding: 16px 20px max(20px, env(safe-area-inset-bottom));
  z-index: 300;
  box-shadow: 0 -8px 40px rgba(0,0,0,0.5);
  animation: drawer-up 0.28s cubic-bezier(0.34, 1.36, 0.64, 1);
}
.cal-filters-drawer.open { display: block; }
@keyframes drawer-up {
  from { transform: translateY(100%); }
  to   { transform: translateY(0); }
}
.cal-drawer-handle {
  width: 36px; height: 4px;
  background: var(--border);
  border-radius: 2px;
  margin: 0 auto 16px;
}
.cal-drawer-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 299;
}
.cal-drawer-overlay.open { display: block; }

/* ══════════════════════════════════════════════════════════════
   EMPTY STATE & SKELETON
══════════════════════════════════════════════════════════════ */
.cal-empty-state {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  height: 100%; gap: 10px; color: var(--text-muted); padding: 40px; text-align: center;
}
.cal-empty-state-icon { font-size: 36px; opacity: 0.35; }
.cal-empty-state-text { font-size: 12px; }
.cal-skeleton-event {
  height: 20px; border-radius: 3px; background: var(--bg-card-hover);
  margin-bottom: 2px; animation: skeleton-pulse 1.5s ease-in-out infinite;
}
@keyframes skeleton-pulse { 0%, 100% { opacity: 0.5; } 50% { opacity: 1; } }

/* ══════════════════════════════════════════════════════════════
   RESPONSIVE — TABLET  ≤ 900px
══════════════════════════════════════════════════════════════ */
@media (max-width: 900px) {
  .cal-page { height: calc(100vh - var(--topbar-h) - 60px); } /* spazio per cal-bottom-bar */
  .cal-sidebar { display: none; } /* nascosta, rimpiazzata da bottom bar */
  .cal-fab { display: flex; }
  .cal-bottom-bar { display: block; }

  .cal-toolbar { gap: 6px; }
  .cal-period-title { font-size: 14px; }
  .cal-view-switcher { display: none; } /* gestita da bottom bar */

  /* Settimana: mostra solo 3 giorni */
  .cal-week-header { grid-template-columns: 40px repeat(3, 1fr) !important; }
  .cal-week-body   { grid-template-columns: 40px repeat(3, 1fr) !important; }

  .cal-month-cell { min-height: 72px; }
  .cal-event-chip { display: none; } /* sostituito da dots su mobile */
  .cal-event-dot  { display: block; }
}

/* ══════════════════════════════════════════════════════════════
   RESPONSIVE — MOBILE  ≤ 480px
══════════════════════════════════════════════════════════════ */
@media (max-width: 480px) {
  .cal-page { height: calc(100vh - var(--topbar-h) - 40px - 64px); }
  .cal-toolbar { flex-wrap: wrap; }
  .cal-period-title { font-size: 13px; order: -1; width: 100%; }
  .cal-today-btn { font-size: 9px; padding: 4px 8px; }
  .cal-month-cell { min-height: 56px; padding: 3px 2px; }
  .cal-cell-date { font-size: 10px; }
  .cal-month-cell.today .cal-cell-date { width: 18px; height: 18px; font-size: 9px; }

  .cal-week-header { grid-template-columns: 32px repeat(3, 1fr) !important; }
  .cal-week-body   { grid-template-columns: 32px repeat(3, 1fr) !important; }
  .cal-time-label  { font-size: 8px; right: 3px; }
  .cal-week-date   { font-size: 15px; }

  .cal-agenda-event-time { min-width: 52px; font-size: 9px; }
  .cal-agenda-event-title { font-size: 12px; }
  .cal-agenda-event-type { display: none; }

  .cal-quick-modal { width: calc(100vw - 32px); left: 16px !important; right: 16px !important; }

  .cal-fab { bottom: 74px; width: 48px; height: 48px; font-size: 22px; }
}

/* Touch: rimuovi hover states che causano flickering */
@media (hover: none) {
  .cal-agenda-event:hover { transform: none; }
  .cal-event-chip:hover   { filter: none; }
  .cal-event-block:hover  { filter: none; box-shadow: none; z-index: 5; }
}
/* ══════════════════════════════════════════════════════════════
   SAFE AREA (notch iPhone, barra home Android/iOS)
══════════════════════════════════════════════════════════════ */
:root {
  --safe-top:    env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left:   env(safe-area-inset-left, 0px);
  --safe-right:  env(safe-area-inset-right, 0px);
}

/* Topbar: compensazione notch superiore in standalone PWA */
@media (display-mode: standalone) {
  .topbar {
    padding-top: max(12px, env(safe-area-inset-top));
    height: calc(var(--topbar-h) + env(safe-area-inset-top, 0px));
  }
  /* Sidebar: padding top per notch */
  .sidebar {
    padding-top: env(safe-area-inset-top, 0px);
  }
}

/* ══════════════════════════════════════════════════════════════
   BOTTOM NAVIGATION BAR (mobile)
══════════════════════════════════════════════════════════════ */
.app-bottom-nav {
  display: none; /* nascosta su desktop */
}

/* Quando il calendario è aperto (ha la sua bottom bar), nascondi la app bottom nav */
@media (max-width: 900px) {
  body:has(.cal-bottom-bar) .app-bottom-nav {
    display: none !important;
  }
}

@media (max-width: 768px) {
  .app-bottom-nav {
    display: flex;
    position: fixed;
    bottom: 0; left: 0; right: 0;
    height: calc(56px + env(safe-area-inset-bottom, 0px));
    padding-bottom: env(safe-area-inset-bottom, 0px);
    background: var(--bg-panel);
    border-top: 1px solid var(--border);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    z-index: 200;
    justify-content: space-around;
    align-items: flex-start;
    padding-top: 0;
  }

  /* Spazio sotto il contenuto per non essere coperto dalla bottom nav */
  .page-content {
    padding-bottom: calc(56px + env(safe-area-inset-bottom, 0px) + 16px) !important;
  }
  /* Il calendario gestisce il suo layout internamente — non serve padding extra */
  .page-content:has(.cal-page) {
    padding-bottom: 0 !important;
  }

  .app-bn-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    padding: 8px 4px 0;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-muted);
    font-family: var(--font-sans);
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.03em;
    -webkit-tap-highlight-color: transparent;
    transition: color 0.15s;
    min-height: 56px;
  }
  .app-bn-item:active { transform: scale(0.88); }
  .app-bn-item.active { color: var(--gold-400); }
  .app-bn-icon {
    font-size: 20px;
    line-height: 1;
    display: block;
  }
  .app-bn-item.active .app-bn-icon {
    filter: drop-shadow(0 0 6px var(--gold-400));
  }
  .app-bn-label { display: block; line-height: 1; }

}

/* ── Drawer "Altro" ──────────────────────────────────────── */
.app-bn-drawer {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: var(--bg-panel);
  border-top: 1px solid var(--border-gold);
  border-radius: 20px 20px 0 0;
  padding: 0 0 env(safe-area-inset-bottom, 16px);
  z-index: 400;
  transform: translateY(100%);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  max-height: 75vh;
  overflow-y: auto;
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
}
.app-bn-drawer.open { transform: translateY(0); }

.app-bn-drawer-handle {
  width: 40px; height: 4px;
  background: var(--border);
  border-radius: 2px;
  margin: 12px auto 4px;
}
.app-bn-drawer-title {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-muted);
  padding: 8px 20px 12px;
}
.app-bn-drawer-list {
  display: flex;
  flex-direction: column;
  padding: 0 12px 12px;
  gap: 2px;
}
.app-bn-drawer-item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 13px 14px;
  border: none;
  background: none;
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 14px;
  font-weight: 500;
  border-radius: var(--radius-md);
  cursor: pointer;
  text-align: left;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.1s;
  width: 100%;
}
.app-bn-drawer-item:active { background: var(--bg-hover); }
.app-bn-drawer-item.active { color: var(--gold-400); }
.app-bn-drawer-icon { font-size: 18px; width: 24px; text-align: center; flex-shrink: 0; }

/* In modalità PWA standalone */
@media (display-mode: standalone) {
  body { background-color: #0a0a0f; }
}

/* ── Profile page — aggiunto dalla patch PWA+Profilo ──────── */
#profile-avatar-ring:hover #profile-avatar-overlay { opacity: 1 !important; }
#profile-pwa-card ol { padding-left: 20px; line-height: 2; }
#profile-pwa-card li { color: var(--text-secondary); font-size: 14px; }
@media (display-mode: standalone) { #sidebar-pwa-btn { display: none !important; } }

/* ══════════════════════════════════════════════════════════════
   EMAIL MODULE
══════════════════════════════════════════════════════════════ */

/* ── Layout tre colonne ─────────────────────────────────── */
.email-layout {
  display: grid;
  grid-template-columns: 220px 340px 1fr;
  height: calc(100vh - 60px);
  overflow: hidden;
  gap: 0;
}

/* ── Sidebar cartelle ────────────────────────────────────── */
.email-sidebar {
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  padding: 12px 0;
  overflow-y: auto;
  background: var(--bg-sidebar);
}

.email-compose-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 12px 16px;
  padding: 10px 16px;
  background: linear-gradient(135deg, var(--gold-400) 0%, var(--gold-300) 100%);
  color: var(--bg-void);
  font-weight: 700;
  font-size: 13px;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: opacity 0.15s;
}
.email-compose-btn:hover { opacity: 0.85; }

.email-folders { flex: 1; }

.email-folder-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px 16px;
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 13px;
  cursor: pointer;
  transition: background 0.1s, color 0.1s;
  text-align: left;
}
.email-folder-item:hover { background: var(--bg-card-hover); color: var(--text-primary); }
.email-folder-item.active { color: var(--gold-400); background: var(--bg-card); font-weight: 600; }
.email-folder-icon { font-size: 15px; width: 22px; text-align: center; }

.email-accounts-section {
  border-top: 1px solid var(--border);
  padding: 12px 12px 8px;
}

.email-section-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  text-transform: uppercase;
  margin-bottom: 8px;
}

.email-account-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.1s;
  position: relative;
}
.email-account-item:hover { background: var(--bg-card-hover); }
.email-account-item.active { background: var(--bg-card); border: 1px solid var(--border-gold); }

.email-account-avatar {
  width: 28px; height: 28px;
  border-radius: 50%;
  background: var(--gold-400);
  color: var(--bg-void);
  font-weight: 700;
  font-size: 12px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.email-account-info { flex: 1; min-width: 0; }
.email-account-name  { font-size: 12px; font-weight: 600; color: var(--text-primary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.email-account-email { font-size: 10px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.email-account-disconnect {
  background: none; border: none; color: var(--text-muted);
  font-size: 11px; cursor: pointer; padding: 2px 4px;
  opacity: 0; transition: opacity 0.15s;
}
.email-account-item:hover .email-account-disconnect { opacity: 1; }

.email-connect-btn {
  display: flex; align-items: center; gap: 6px;
  width: 100%; padding: 8px 8px;
  background: var(--bg-card); border: 1px dashed var(--border);
  color: var(--text-secondary); font-size: 12px;
  border-radius: 6px; cursor: pointer; margin-top: 8px;
  transition: border-color 0.15s, color 0.15s;
}
.email-connect-btn:hover { border-color: var(--gold-400); color: var(--gold-400); }

/* ── Lista messaggi ──────────────────────────────────────── */
.email-list-panel {
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  overflow: hidden;
}

.email-list-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.email-search {
  flex: 1;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 13px;
  color: var(--text-primary);
  outline: none;
}
.email-search:focus { border-color: var(--gold-400); }

#email-messages-container {
  flex: 1;
  overflow-y: auto;
}

.email-msg-item {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.1s;
}
.email-msg-item:hover   { background: var(--bg-card-hover); }
.email-msg-item.selected{ background: rgba(245,158,11,0.08); border-left: 2px solid var(--gold-400); }
.email-msg-item.unread .email-msg-from,
.email-msg-item.unread .email-msg-subject { font-weight: 700; color: var(--text-primary); }

.email-msg-star {
  font-size: 16px; cursor: pointer; color: var(--text-muted);
  transition: color 0.1s; flex-shrink: 0; line-height: 1; padding-top: 2px;
}
.email-msg-star.starred { color: var(--gold-400); }
.email-msg-star:hover   { color: var(--gold-300); }

.email-msg-main { flex: 1; min-width: 0; }
.email-msg-top  { display: flex; align-items: center; justify-content: space-between; margin-bottom: 2px; }
.email-msg-from { font-size: 13px; color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 180px; }
.email-msg-date { font-size: 11px; color: var(--text-muted); flex-shrink: 0; }
.email-msg-subject { font-size: 13px; color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-bottom: 2px; }
.email-msg-snippet { font-size: 11px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.email-msg-attach  { font-size: 13px; flex-shrink: 0; }

.email-pagination {
  display: flex; align-items: center; justify-content: center; gap: 12px;
  padding: 10px; font-size: 12px; color: var(--text-muted);
  border-top: 1px solid var(--border);
}
.email-pagination button {
  background: var(--bg-card); border: 1px solid var(--border);
  color: var(--text-secondary); padding: 4px 10px; border-radius: 4px; cursor: pointer;
}
.email-pagination button:disabled { opacity: 0.4; cursor: default; }
.email-pagination button:not(:disabled):hover { border-color: var(--gold-400); color: var(--gold-400); }

/* ── Dettaglio messaggio ─────────────────────────────────── */
.email-detail-panel {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.email-detail-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  opacity: 0.5;
}

#email-detail-content {
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
}

.email-detail-header {
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.email-detail-subject {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 8px;
  line-height: 1.3;
}

.email-detail-labels { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 8px; }
.email-label {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 10px;
}

.email-detail-meta {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 4px;
}
.email-detail-from { font-size: 14px; font-weight: 600; color: var(--text-primary); }
.email-detail-from-addr { font-size: 12px; color: var(--text-muted); margin-left: 4px; }
.email-detail-date { font-size: 12px; color: var(--text-muted); flex-shrink: 0; }
.email-detail-to-line { font-size: 12px; color: var(--text-secondary); margin-bottom: 12px; }

.email-detail-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.email-btn-danger { color: #f87171 !important; border-color: rgba(248,113,113,0.3) !important; }
.email-btn-danger:hover { background: rgba(248,113,113,0.1) !important; }

/* ── Record collegato email ──────────────────────────────── */
.email-linked-record {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  padding: 8px 12px;
  margin-bottom: 10px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 12px;
}
.email-linked-label {
  color: var(--text-muted);
  font-size: 11px;
  white-space: nowrap;
}
.email-linked-value { flex: 1; }

/* ── Fix iframe body email ───────────────────────────────── */
.email-detail-body iframe {
  display: block;
  width: 100%;
  border: none;
  transition: height 0.15s ease;
}

/* ── Record collegato (email & calendario) ─────────────────── */
.email-linked-record {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  padding: 7px 10px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: 10px;
  font-size: 12px;
}
.email-linked-label {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
  flex-shrink: 0;
}
.email-linked-value { flex: 1; min-width: 0; }
.email-linked-record .form-input {
  font-size: 12px !important;
  padding: 4px 8px !important;
  height: 28px !important;
}

/* ── Record collegato email ──────────────────────────────── */
.email-linked-record {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  padding: 8px 12px;
  background: rgba(59,130,246,0.06);
  border: 1px solid rgba(59,130,246,0.2);
  border-radius: var(--radius-sm);
  margin-bottom: 12px;
  font-size: 12px;
}
.email-linked-label {
  color: var(--text-muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .4px;
  flex-shrink: 0;
}
.email-linked-value { flex: 1; min-width: 0; }
.email-linked-record .form-input {
  height: 28px;
  padding: 3px 8px;
  font-size: 12px;
}

.email-detail-body {
  flex: 1;
  overflow-y: auto;
  padding: 0;
}
.email-detail-body iframe { display: block; width: 100%; border: none; }

/* ── Compose modal ───────────────────────────────────────── */
.email-compose-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 1000;
  display: none;
  align-items: flex-end;
  justify-content: flex-end;
  padding: 20px;
}

.email-compose-modal {
  width: 520px;
  max-width: calc(100vw - 40px);
  max-height: 80vh;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 60px rgba(0,0,0,0.4);
}

.email-compose-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
}

.email-compose-body { flex: 1; overflow-y: auto; }

.email-compose-field {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  border-bottom: 1px solid var(--border);
}
.email-compose-field label {
  font-size: 12px;
  color: var(--text-muted);
  width: 40px;
  flex-shrink: 0;
}
.email-compose-field input {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-size: 13px;
}

.email-compose-editor {
  min-height: 200px;
  padding: 12px 16px;
  color: var(--text-primary);
  font-size: 14px;
  line-height: 1.6;
  outline: none;
}
.email-compose-editor:empty::before {
  content: attr(data-placeholder);
  color: var(--text-muted);
  pointer-events: none;
}

.email-compose-footer {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
}

.email-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  color: var(--text-muted);
  text-align: center;
  gap: 8px;
}

/* ── Responsive ──────────────────────────────────────────── */
/* ── EMAIL RESPONSIVE ────────────────────────────────────── */

/* Tablet: nascondi dettaglio, sidebar stretta */
@media (max-width: 960px) {
  .email-layout {
    grid-template-columns: 200px 1fr;
  }
  .email-detail-panel {
    display: none;
  }
  .email-detail-panel.mobile-open {
    display: flex;
    position: fixed;
    inset: 0;
    z-index: 300;
    background: var(--bg-space);
    flex-direction: column;
  }
}

/* Mobile: layout a schermata intera, navigazione a tab */
@media (max-width: 640px) {

  /* layout occupa tutto lo schermo sotto la topbar */
  .email-layout {
    display: block;
    height: calc(100vh - 60px);
    position: relative;
    overflow: hidden;
  }

  /* ── PANNELLI: scorrevoli orizzontalmente ── */
  .email-sidebar,
  .email-list-panel,
  .email-detail-panel {
    position: absolute;
    inset: 0 0 52px 0; /* 52px per la bottom tab bar */
    width: 100%;
    height: calc(100% - 0px);
    transition: transform 0.28s cubic-bezier(.4,0,.2,1);
    background: var(--bg-space);
    overflow-y: auto;
    display: flex;
    flex-direction: column;
  }

  /* Sidebar cartelle: slide da sinistra */
  .email-sidebar {
    transform: translateX(-100%);
    z-index: 10;
    border-right: none;
    padding-bottom: 12px;
  }
  .email-sidebar.visible {
    transform: translateX(0);
    box-shadow: 4px 0 24px rgba(0,0,0,.4);
  }

  /* Lista messaggi: pannello principale */
  .email-list-panel {
    transform: translateX(0);
    z-index: 5;
  }

  /* Dettaglio: slide da destra */
  .email-detail-panel {
    transform: translateX(100%);
    z-index: 20;
  }
  .email-detail-panel.mobile-open {
    display: flex;
    transform: translateX(0);
    box-shadow: -4px 0 24px rgba(0,0,0,.4);
  }

  /* ── TOPBAR EMAIL MOBILE ── */
  .email-mobile-topbar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    background: var(--bg-sidebar);
    position: sticky;
    top: 0;
    z-index: 2;
  }
  .email-mobile-topbar-title {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-primary);
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .email-mobile-back {
    background: none;
    border: none;
    color: var(--gold-400);
    font-size: 22px;
    cursor: pointer;
    padding: 0 4px;
    line-height: 1;
    flex-shrink: 0;
  }

  /* ── BOTTOM TAB BAR ── */
  .email-bottom-tabs {
    position: absolute;
    bottom: 0;
    left: 0; right: 0;
    height: 72px;
    display: flex;
    background: var(--bg-sidebar);
    border-top: 1px solid var(--border);
    z-index: 100;
  }
  .email-tab-btn {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 10px;
    cursor: pointer;
    transition: color 0.15s;
    -webkit-tap-highlight-color: transparent;
  }
  .email-tab-btn.active { color: var(--gold-400); }
  .email-tab-btn span:first-child { font-size: 20px; line-height: 1; }

  /* ── LISTA MESSAGGI MOBILE ── */
  .email-list-toolbar {
    padding: 8px 12px;
    position: sticky;
    top: 0;
    background: var(--bg-space);
    z-index: 1;
  }

  .email-msg-item {
    padding: 12px 14px;
  }
  .email-msg-from    { max-width: 55vw; font-size: 14px; }
  .email-msg-subject { font-size: 13px; }
  .email-msg-snippet { font-size: 12px; }
  .email-msg-date    { font-size: 11px; }

  /* ── DETTAGLIO MOBILE ── */
  .email-detail-header {
    padding: 14px 16px 12px;
  }
  .email-detail-subject { font-size: 16px; }
  .email-detail-actions {
    gap: 6px;
  }
  .email-detail-actions .btn {
    font-size: 12px;
    padding: 6px 10px;
  }
  .email-detail-body iframe {
    min-height: 300px;
  }

  /* ── SIDEBAR MOBILE ── */
  .email-sidebar .email-compose-btn {
    margin: 14px 14px 12px;
  }
  .email-folder-item {
    padding: 12px 18px;
    font-size: 14px;
  }
  .email-accounts-section {
    padding: 12px 14px;
  }

  /* ── COMPOSE MODAL MOBILE ── */
  .email-compose-overlay {
    padding: 0;
    align-items: flex-end;
  }
  .email-compose-modal {
    width: 100%;
    max-width: 100%;
    max-height: 90vh;
    border-radius: 16px 16px 0 0;
  }

  /* ── NASCONDI ELEMENTI DESKTOP ── */
  .email-list-panel .email-list-toolbar .icon-btn[id="email-sync-btn"] {
    display: flex;
  }
}

/* ── Animazione slideUp (bottom sheet mobile) ────────────── */
@keyframes slideUp {
  from { transform: translateY(100%); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}

/* ── Cal mobile move sheet ──────────────────────────────── */
#cal-mobile-move button:active {
  filter: brightness(1.2);
  transform: scale(0.97);
}
