/* ═══════════════════════════════════════
   LAYOUT — FrontFi
   Sidebar, Header, Navbar, Grid, Responsive
   ═══════════════════════════════════════ */

/* ═══ ADMIN LAYOUT ═══ */
.app { display: flex; min-height: 100vh; }

/* ═══ SIDEBAR ═══ */
.sidebar {
  width: var(--sidebar-w);
  background: var(--bg-2);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  position: fixed; top: 0; bottom: 0; left: 0;
  z-index: 100;
  transition: width .3s var(--ease), transform .3s var(--ease);
  overflow-y: auto; overflow-x: hidden;
}
/* Collapsed sidebar */
.sidebar.collapsed { width: var(--sidebar-collapsed-w); }
.sidebar.collapsed .sidebar-brand,
.sidebar.collapsed .nav-label,
.sidebar.collapsed .nav-badge,
.sidebar.collapsed .nav-tag,
.sidebar.collapsed .nav-section-label,
.sidebar.collapsed .sidebar-logout span { display: none; }
.sidebar.collapsed .nav-item { justify-content: center; padding: 9px; }
.sidebar.collapsed .sidebar-header { justify-content: center; padding: 20px 12px 16px; }
.sidebar.collapsed .sidebar-footer { justify-content: center; padding: 16px 12px; }
.sidebar.collapsed .sidebar-logout { width: auto; justify-content: center; gap: 0; }
.sidebar.collapsed + .sidebar-overlay + .main,
.sidebar.collapsed ~ .main { margin-left: var(--sidebar-collapsed-w); }
/* Sidebar light mode */
[data-theme="light"] .sidebar {
  background: #FFFFFF;
  border-right-color: #E2E8F0;
}
[data-theme="light"] .sidebar .nav-item { color: #64748B; }
[data-theme="light"] .sidebar .nav-item:hover { color: #1C2434; background: #F1F5F9; }
[data-theme="light"] .sidebar .nav-item.active { color: var(--accent); background: rgba(70,95,255,.08); }
[data-theme="light"] .sidebar .nav-item.active::before { background: var(--accent); }
[data-theme="light"] .sidebar .nav-section-label { color: #94A3B8; }
[data-theme="light"] .sidebar .sidebar-brand-name { color: #1C2434; }
[data-theme="light"] .sidebar .sidebar-brand-sub { color: #94A3B8; }
[data-theme="light"] .sidebar .sidebar-user-name { color: #1C2434; }
[data-theme="light"] .sidebar .sidebar-user-role { color: #94A3B8; }
[data-theme="light"] .sidebar .sidebar-footer { border-top-color: #E2E8F0; }
[data-theme="light"] .sidebar .sidebar-logo { box-shadow: none; }
[data-theme="light"] .sidebar .sidebar-logout { background: #F1F5F9; border-color: #E2E8F0; color: #64748B; }
[data-theme="light"] .sidebar .sidebar-header { border-bottom-color: rgba(255,255,255,.08); }

.sidebar-header {
  padding: 20px 20px 16px;
  display: flex; align-items: center; gap: 12px;
}
.sidebar-logo {
  width: 36px; height: 36px;
  background: var(--grad-brand);
  border-radius: var(--r-md);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.1rem; flex-shrink: 0;
  box-shadow: var(--shadow-glow);
}
.sidebar-brand { display: flex; flex-direction: column; }
.sidebar-brand-name { font-weight: 700; font-size: 1rem; letter-spacing: -.01em; }
.sidebar-brand-sub { font-size: .75rem; color: var(--text-tertiary); font-weight: 400; }

/* Navigation */
.sidebar-nav { padding: 12px; flex: 1; }
.nav-section { margin-bottom: 24px; }
.nav-section-label {
  padding: 0 12px; margin-bottom: 8px;
  font-size: .68rem; font-weight: 600;
  text-transform: uppercase; letter-spacing: .1em;
  color: var(--text-muted);
}
.nav-item {
  display: flex; align-items: center; gap: 12px;
  padding: 9px 12px; border-radius: var(--r-md);
  font-size: .9rem; font-weight: 500;
  color: var(--text-secondary);
  transition: all var(--duration) var(--ease);
  cursor: pointer; position: relative; margin-bottom: 2px;
}
.nav-item:hover { color: var(--text-primary); background: var(--bg-4); }
.nav-item.active { color: var(--text-primary); background: var(--accent-muted); }
.nav-item.active::before {
  content: ''; position: absolute; left: 0; top: 6px; bottom: 6px;
  width: 3px; border-radius: 0 2px 2px 0;
  background: var(--accent);
}
.nav-icon { width: 20px; height: 20px; display: flex; align-items: center; justify-content: center; font-size: 1.05rem; flex-shrink: 0; }
.nav-label { flex: 1; white-space: nowrap; }
.nav-badge {
  font-size: .65rem; font-weight: 700;
  padding: 2px 7px; border-radius: var(--r-full);
  background: var(--accent); color: #fff;
  min-width: 20px; text-align: center;
}
.nav-tag {
  font-size: .6rem; font-weight: 700;
  padding: 2px 6px; border-radius: var(--r-sm);
  background: var(--grad-brand); color: #fff;
  text-transform: uppercase; letter-spacing: .05em;
}

/* Sidebar footer */
.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--border);
  display: flex; align-items: center; gap: 12px;
}
.sidebar-avatar {
  width: 32px; height: 32px; border-radius: var(--r-full);
  background: var(--grad-brand);
  display: flex; align-items: center; justify-content: center;
  font-size: .85rem; font-weight: 700; flex-shrink: 0; color: #fff;
}
.sidebar-user-name { font-weight: 600; font-size: .85rem; }
.sidebar-user-role { font-size: .7rem; color: var(--text-tertiary); }
.sidebar-logout {
  margin-left: auto;
  width: 28px; height: 28px; border-radius: var(--r-sm);
  display: flex; align-items: center; justify-content: center;
  color: var(--text-tertiary); transition: all .2s; font-size: .9rem;
}
.sidebar-logout:hover { background: var(--error-muted); color: var(--error); }

/* ═══ MAIN CONTENT ═══ */
.main {
  margin-left: var(--sidebar-w);
  flex: 1; min-height: 100vh; min-width: 0;
  display: flex; flex-direction: column;
  overflow-x: hidden;
  transition: margin-left .3s var(--ease);
}

/* Topbar */
.topbar {
  height: 64px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center;
  padding: 0 32px;
  position: sticky; top: 0; z-index: 50;
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  background: rgba(12,12,15,.8);
}
[data-theme="light"] .topbar { background: rgba(255,255,255,.9); border-bottom-color: #E2E8F0; }
.topbar-left { display: flex; align-items: center; gap: 16px; flex: 1; }
.topbar-title { font-weight: 700; font-size: 1.1rem; letter-spacing: -.01em; }
.topbar-breadcrumb { display: flex; align-items: center; gap: 6px; font-size: .8rem; color: var(--text-tertiary); }
.topbar-breadcrumb span { color: var(--text-muted); }
.topbar-right { display: flex; align-items: center; gap: 8px; }
.topbar-btn {
  width: 36px; height: 36px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-secondary); transition: all .2s;
  font-size: 1rem; position: relative;
  border: 1px solid var(--border); background: var(--bg-3);
}
.topbar-btn:hover { background: var(--bg-4); color: var(--text-primary); border-color: var(--border-hover); }
.topbar-btn .dot {
  position: absolute; top: 6px; right: 6px;
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--error); border: 2px solid var(--bg-1);
}
.topbar-user {
  display: flex; align-items: center; gap: 10px;
  padding: 4px 12px 4px 4px; border-radius: var(--r-full);
  border: 1px solid var(--border); background: var(--bg-3);
  transition: all .2s; cursor: default;
}
.topbar-user:hover { border-color: var(--border-hover); }
.topbar-avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--grad-brand); display: flex; align-items: center;
  justify-content: center; font-size: .8rem; font-weight: 700; color: #fff;
  flex-shrink: 0;
}
.topbar-user-info { display: flex; flex-direction: column; }
.topbar-user-name { font-size: .82rem; font-weight: 600; line-height: 1.2; }
.topbar-user-role { font-size: .68rem; color: var(--text-tertiary); line-height: 1.2; }
.topbar-search {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 16px; background: var(--bg-3); border: 1px solid var(--border);
  border-radius: var(--r-lg); font-size: .85rem; color: var(--text-tertiary);
  transition: all .2s; cursor: pointer; min-width: 260px;
}
.topbar-search:hover { border-color: var(--border-hover); }
.topbar-search kbd {
  font-family: var(--font); font-size: .7rem;
  padding: 2px 6px; border-radius: var(--r-xs);
  background: var(--bg-5); color: var(--text-muted);
  border: 1px solid var(--border);
}

/* Content area */
.content { padding: 32px 40px; flex: 1; overflow-x: hidden; min-width: 0; }
@media (min-width: 1600px) { .content { padding: 32px 16%; } }
.content-section { display: none; }
.content-section.active { display: block; animation: fadeUp .4s var(--ease) both; }

/* ═══ LANDING NAVBAR ═══ */
.navbar {
  position: fixed; top: 0; left: 0; right: 0;
  z-index: 1000;
  transition: background .3s var(--ease), box-shadow .3s var(--ease);
  background: rgba(12,12,15,.75);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  padding-top: env(safe-area-inset-top, 0);
}
[data-theme="light"] .navbar {
  background: rgba(255,255,255,.75);
}
.navbar.scrolled {
  background: rgba(12,12,15,.92);
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 1px 3px rgba(0,0,0,.12);
}
[data-theme="light"] .navbar.scrolled {
  background: rgba(255,255,255,.92);
}
.navbar-inner {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  max-width: 100%; padding: 12px 32px;
}
.navbar-inner > .navbar-logo { justify-self: start; }
.navbar-inner > .navbar-links { justify-self: center; }
.navbar-inner > .navbar-actions { justify-self: end; }
/* Mobile/landscape phone: torna flex space-between così le azioni stanno a destra */
@media (max-width: 900px) {
  .navbar-inner {
    display: flex;
    justify-content: space-between;
  }
}
.navbar-logo {
  display: flex; align-items: center; gap: 12px;
  font-weight: 700; font-size: 1.65rem;
  letter-spacing: -.025em;
  color: var(--text-primary);
}
.navbar-logo-icon {
  width: 38px; height: 38px;
  background: var(--grad-brand);
  border-radius: var(--r-md);
  display: flex; align-items: center; justify-content: center;
  font-size: .9rem;
}
.navbar-links {
  display: flex; align-items: center; gap: 32px;
}
.navbar-links a {
  font-size: .95rem; font-weight: 500; color: var(--text-secondary);
  transition: color .2s;
}
.navbar-links a:hover { color: var(--text-primary); }
.navbar-actions { display: flex; align-items: center; gap: 10px; }
/* Uniforma l'altezza di TUTTI gli item: theme-toggle, i18n switcher,
   bottoni Accedi / Inizia Gratis → stessa altezza fissa 40px */
.navbar-actions > * {
  height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
}
.navbar-actions .theme-toggle {
  width: 40px;
  background: var(--bg-3); border: 1px solid var(--border);
  cursor: pointer; color: var(--text-secondary);
  border-radius: 50%;
}
.navbar-actions .theme-toggle:hover {
  background: var(--accent-muted); color: var(--accent);
  border-color: var(--accent); transform: rotate(15deg);
}
/* Bottoni Accedi / Inizia Gratis nella navbar: override padding per mantenere h 40 */
.navbar-actions .btn-sm {
  padding: 0 18px;
  font-size: .82rem;
  line-height: 1;
}
/* Mobile button: stessa altezza */
.navbar-actions .navbar-mobile-btn { height: 40px; width: 40px; border-radius: var(--r-md); }
.navbar-mobile-btn {
  display: none; width: 36px; height: 36px;
  border-radius: var(--r-md); border: 1px solid var(--border);
  align-items: center; justify-content: center; font-size: 1.2rem;
}

/* Mobile nav overlay */
.mobile-nav {
  display: none; position: fixed; inset: 0; z-index: 999;
  background: rgba(0,0,0,.8); backdrop-filter: blur(8px);
}
.mobile-nav.open { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 24px; }
.mobile-nav a {
  font-size: 1.2rem; font-weight: 600; color: #fff;
  padding: 12px 40px; border-radius: var(--r-md);
  transition: background .2s;
}
.mobile-nav a:hover { background: rgba(255,255,255,.1); }
.mobile-nav button { color: rgba(255,255,255,.5); }
.mobile-nav a.btn { border-radius: var(--r-full); font-size: .95rem; }
.mobile-nav a.btn-secondary { color: #fff; border-color: rgba(255,255,255,.3); background: transparent; }
.mobile-nav a.btn-secondary:hover { background: rgba(255,255,255,.1); }

/* ═══ CHART LAYOUTS ═══ */
.chart-grid { display: grid; grid-template-columns: 1fr; gap: 16px; margin-bottom: 20px; }
@media (min-width: 1100px) { .chart-grid { grid-template-columns: 1.6fr 1fr; gap: 20px; } }
.chart-bar-container { height: 220px; display: flex; align-items: flex-end; gap: 8px; padding: 8px 0; }
.chart-bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; }
.chart-bar {
  width: 100%; max-width: 32px; border-radius: 6px 6px 2px 2px;
  background: var(--accent); min-height: 3px;
  transition: all .3s var(--ease); position: relative;
  animation: barGrow .8s var(--ease) both;
}
.chart-bar:hover { opacity: .8; }
.chart-bar-val { font-size: .68rem; font-weight: 600; font-family: var(--font-mono); color: var(--text-secondary); }
.chart-bar-label { font-size: .68rem; color: var(--text-muted); }

/* Donut */
.donut-container { display: flex; align-items: center; gap: 28px; justify-content: center; flex-wrap: wrap; }
.donut-svg { width: 160px; height: 160px; transform: rotate(-90deg); }
.donut-svg circle { transition: stroke-dasharray 1s var(--ease), stroke-dashoffset 1s var(--ease); }
.donut-center { font-size: 1.3rem; font-weight: 800; font-family: var(--font-mono); }
.donut-legend { display: flex; flex-direction: column; gap: 10px; }
.donut-legend-item { display: flex; align-items: center; gap: 8px; font-size: .82rem; }
.donut-legend-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.donut-legend-val { font-weight: 700; font-family: var(--font-mono); margin-left: auto; }

/* ═══ RESPONSIVE ═══ */
@media (max-width: 1400px) {
  .chart-grid { grid-template-columns: 1fr; }
}
/* Sidebar overlay (mobile) */
.sidebar-overlay {
  display: none; position: fixed; inset: 0; z-index: 99;
  background: rgba(0,0,0,.5); backdrop-filter: blur(2px);
  opacity: 0; transition: opacity .3s var(--ease);
}
.sidebar-overlay.open { display: block; opacity: 1; }

@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); z-index: 200; }
  .sidebar.open { transform: translateX(0); }
  .main { margin-left: 0; }
  .topbar-search { display: none; }
  .content { padding: 20px 16px; }
  #menu-btn { display: flex !important; }
  .navbar-links { display: none; }
  .navbar-mobile-btn { display: flex; }
  .navbar-actions .btn { display: none; }
  .navbar-actions { gap: 6px; }
}
@media (max-width: 640px) {
  .container { padding: 0 16px; }
}
