/* ============================================================
   Programma Espositori — Stylesheet principale
   ============================================================ */

:root {
  --primary:       #1565C0;
  --primary-light: #1E88E5;
  --primary-dark:  #0D47A1;
  --accent:        #00897B;
  --accent-light:  #26A69A;
  --danger:        #E53935;
  --warning:       #F4A900;
  --success:       #2E7D32;
  --bg:            #F5F7FA;
  --surface:       #FFFFFF;
  --border:        #DDE3EC;
  --text:          #1A2340;
  --text-muted:    #6B7A99;
  --sidebar-w:     240px;
  --header-h:      60px;
  --radius:        10px;
  --shadow:        0 2px 12px rgba(21,101,192,.08);
  --shadow-md:     0 4px 24px rgba(21,101,192,.13);
  --surface-2:     #F0F4F9;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

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

/* ── SIDEBAR ────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  background: var(--primary-dark);
  color: #fff;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
  transition: transform .25s;
}
.sidebar-logo {
  padding: 18px 20px 14px;
  border-bottom: 1px solid rgba(255,255,255,.12);
  display: flex; align-items: center; gap: 10px;
}
.sidebar-logo .logo-icon {
  width: 36px; height: 36px;
  background: var(--accent);
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px;
}
.sidebar-logo h1 { font-size: 13px; font-weight: 700; line-height: 1.3; }
.sidebar-logo span { font-size: 11px; opacity: .7; }

.sidebar-nav { flex: 1; padding: 12px 0; overflow-y: auto; }
.nav-section { margin-bottom: 4px; }
.nav-label {
  font-size: 10px; font-weight: 700; letter-spacing: .1em;
  color: rgba(255,255,255,.45);
  padding: 10px 20px 4px;
  text-transform: uppercase;
}
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 20px;
  color: rgba(255,255,255,.82);
  cursor: pointer;
  transition: background .15s, color .15s;
  font-size: 13.5px;
  text-decoration: none;
}
.nav-item:hover { background: rgba(255,255,255,.1); color: #fff; text-decoration: none; }
.nav-item.active { background: rgba(255,255,255,.16); color: #fff; font-weight: 600; }
.nav-item .icon { font-size: 18px; width: 22px; text-align: center; flex-shrink: 0; }
.nav-badge {
  margin-left: auto;
  background: var(--accent);
  color: #fff;
  font-size: 10px; font-weight: 700;
  padding: 1px 6px;
  border-radius: 999px;
}

.sidebar-user {
  padding: 14px 20px;
  border-top: 1px solid rgba(255,255,255,.12);
  display: flex; align-items: center; gap: 10px;
}
.sidebar-user .avatar {
  width: 34px; height: 34px;
  background: var(--accent);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 14px; flex-shrink: 0;
}
.sidebar-user .info { flex: 1; min-width: 0; }
.sidebar-user .name { font-size: 13px; font-weight: 600; color: #fff; }
.sidebar-user .role { font-size: 11px; color: rgba(255,255,255,.55); }

/* ── MAIN ───────────────────────────────────────────────── */
.main {
  margin-left: var(--sidebar-w);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

/* ── TOPBAR ─────────────────────────────────────────────── */
.topbar {
  height: var(--header-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center;
  padding: 0 24px;
  gap: 16px;
  position: sticky; top: 0; z-index: 50;
}
.topbar-title { font-size: 18px; font-weight: 700; flex: 1; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.btn-icon {
  width: 36px; height: 36px;
  border-radius: 50%;
  border: none;
  background: transparent;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px;
  color: var(--text-muted);
  transition: background .15s;
}
.btn-icon:hover { background: var(--bg); color: var(--text); }

/* ── PAGE CONTENT ───────────────────────────────────────── */
.page-content { flex: 1; padding: 24px; }

/* ── CARDS ──────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}
.card-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 16px;
}
.card-title { font-size: 15px; font-weight: 700; }
.card-subtitle { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

/* ── BUTTONS ────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 16px;
  border-radius: 8px;
  border: none;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, box-shadow .15s, transform .1s;
  font-family: inherit;
  text-decoration: none;
}
.btn:active { transform: scale(.97); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-light); color: #fff; text-decoration: none; }
.btn-accent { background: var(--accent); color: #fff; }
.btn-accent:hover { background: var(--accent-light); color: #fff; text-decoration: none; }
.btn-outline {
  background: transparent;
  color: var(--primary);
  border: 1.5px solid var(--primary);
}
.btn-outline:hover { background: #EEF4FF; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-sm { padding: 5px 11px; font-size: 12px; border-radius: 6px; }
.btn-ghost { background: transparent; color: var(--text-muted); border: none; }
.btn-ghost:hover { background: var(--bg); color: var(--text); }

/* ── BADGES ─────────────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 11px; font-weight: 700;
}
.badge-primary { background: #DBEAFE; color: var(--primary-dark); }
.badge-success { background: #DCFCE7; color: var(--success); }
.badge-warning { background: #FEF3C7; color: #92400E; }
.badge-danger  { background: #FEE2E2; color: var(--danger); }
.badge-neutral { background: var(--bg); color: var(--text-muted); border: 1px solid var(--border); }
.badge-accent  { background: #CCFBF1; color: #065F46; }
.badge-info    { background: #DBEAFE; color: #1E40AF; }

/* ── TABLES ─────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th {
  text-align: left;
  font-size: 11px; font-weight: 700;
  letter-spacing: .05em;
  color: var(--text-muted);
  text-transform: uppercase;
  padding: 10px 14px;
  border-bottom: 2px solid var(--border);
  background: var(--bg);
}
td {
  padding: 11px 14px;
  border-bottom: 1px solid var(--border);
  font-size: 13.5px;
  vertical-align: middle;
}
tr:last-child td { border-bottom: none; }
tr:hover td { background: #F8FAFF; }

/* ── FORMS ──────────────────────────────────────────────── */
.form-group { margin-bottom: 16px; }
.form-label { display: block; font-size: 12px; font-weight: 700; margin-bottom: 5px; color: var(--text-muted); }
.form-control {
  width: 100%;
  padding: 9px 12px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-size: 13.5px;
  color: var(--text);
  background: var(--surface);
  transition: border-color .15s;
  font-family: inherit;
}
.form-control:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(21,101,192,.1); }
select.form-control { cursor: pointer; }
textarea.form-control { resize: vertical; min-height: 80px; }
/* Alias: .input = .form-control */
.input {
  width: 100%;
  padding: 9px 12px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-size: 13.5px;
  color: var(--text);
  background: var(--surface);
  transition: border-color .15s;
  font-family: inherit;
}
.input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(21,101,192,.1); }
select.input { cursor: pointer; }
textarea.input { resize: vertical; min-height: 80px; }

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

/* ── GRID ───────────────────────────────────────────────── */
.stats-grid { display: grid; grid-template-columns: repeat(4,1fr); gap: 16px; margin-bottom: 24px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }

/* ── STAT CARD ──────────────────────────────────────────── */
.stat-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 20px;
  display: flex; align-items: flex-start; gap: 14px;
}
.stat-icon {
  width: 46px; height: 46px;
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 22px; flex-shrink: 0;
}
.stat-icon.blue  { background: #DBEAFE; }
.stat-icon.green { background: #DCFCE7; }
.stat-icon.amber { background: #FEF3C7; }
.stat-icon.teal  { background: #CCFBF1; }
.stat-icon.red   { background: #FEE2E2; }
.stat-value { font-size: 26px; font-weight: 800; line-height: 1; }
.stat-label { font-size: 12px; color: var(--text-muted); margin-top: 3px; }
.stat-delta { font-size: 11px; margin-top: 5px; font-weight: 600; }
.stat-delta.up   { color: var(--success); }
.stat-delta.down { color: var(--danger); }

/* ── AVATAR ─────────────────────────────────────────────── */
.avatar {
  width: 36px; height: 36px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 13px;
  flex-shrink: 0;
}
.avatar-sm { width: 28px; height: 28px; font-size: 11px; }
.avatar-lg { width: 52px; height: 52px; font-size: 20px; }
.av-blue  { background: #DBEAFE; color: var(--primary-dark); }
.av-green { background: #DCFCE7; color: var(--success); }
.av-teal  { background: #CCFBF1; color: #065F46; }
.av-amber { background: #FEF3C7; color: #92400E; }
.av-red   { background: #FEE2E2; color: var(--danger); }

/* ── ALERT ──────────────────────────────────────────────── */
.alert {
  padding: 12px 16px;
  border-radius: 8px;
  font-size: 13px;
  border-left: 4px solid;
  display: flex; align-items: flex-start; gap: 10px;
}
.alert-info    { background: #EFF6FF; border-color: var(--primary); color: var(--primary-dark); }
.alert-success { background: #F0FDF4; border-color: var(--success); color: var(--success); }
.alert-warning { background: #FFFBEB; border-color: var(--warning); color: #92400E; }
.alert-danger  { background: #FFF1F2; border-color: var(--danger); color: var(--danger); }
.alert-error   { background: #FFF1F2; border-color: var(--danger); color: var(--danger); }

/* ── TABS ───────────────────────────────────────────────── */
.tabs { display: flex; border-bottom: 2px solid var(--border); margin-bottom: 20px; gap: 2px; }
.tab {
  padding: 9px 18px;
  font-size: 13.5px; font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: color .15s, border-color .15s;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--primary); border-color: var(--primary); }

/* ── MODAL ──────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.45);
  display: flex; align-items: center; justify-content: center;
  z-index: 200;
  padding: 20px;
}
.modal {
  background: var(--surface);
  border-radius: 14px;
  box-shadow: var(--shadow-md);
  width: 100%; max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
}
.modal-header {
  padding: 18px 22px 14px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.modal-title { font-size: 16px; font-weight: 700; }
.modal-body { padding: 20px 22px; }
.modal-footer { padding: 14px 22px; border-top: 1px solid var(--border); display: flex; gap: 10px; justify-content: flex-end; }

/* ── TOGGLE ─────────────────────────────────────────────── */
.toggle-wrap { display: flex; align-items: center; gap: 10px; }
.toggle { position: relative; width: 42px; height: 22px; flex-shrink: 0; }
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
  position: absolute; inset: 0;
  background: #CBD5E1;
  border-radius: 99px;
  cursor: pointer;
  transition: background .2s;
}
.toggle-slider::before {
  content: '';
  position: absolute;
  width: 16px; height: 16px;
  background: #fff;
  border-radius: 50%;
  top: 3px; left: 3px;
  transition: transform .2s;
  box-shadow: 0 1px 3px rgba(0,0,0,.2);
}
.toggle input:checked + .toggle-slider { background: var(--primary); }
.toggle input:checked + .toggle-slider::before { transform: translateX(20px); }

/* ── PROGRESS ───────────────────────────────────────────── */
.progress { height: 8px; background: var(--bg); border-radius: 99px; overflow: hidden; margin-top: 6px; }
.progress-bar { height: 100%; border-radius: 99px; background: var(--primary); transition: width .4s; }
.progress-bar.green { background: var(--success); }
.progress-bar.amber { background: var(--warning); }
.progress-bar.red   { background: var(--danger); }

/* ── EMPTY STATE ────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 48px 20px;
  color: var(--text-muted);
}
.empty-state .icon { font-size: 48px; margin-bottom: 12px; opacity: .4; }
.empty-state h3 { font-size: 16px; font-weight: 700; color: var(--text); margin-bottom: 6px; }

/* ── ROLE CHIPS ─────────────────────────────────────────── */
.role-chip {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 11px; font-weight: 700;
}
.role-admin      { background: #EDE9FE; color: #5B21B6; }
.role-superadmin { background: #FCE7F3; color: #9D174D; }
.role-coord      { background: #DBEAFE; color: var(--primary-dark); }
.role-pub        { background: #DCFCE7; color: var(--success); }

/* ── MISC UTILITIES ─────────────────────────────────────── */
.flex { display: flex; }
.flex-col { display: flex; flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.gap-4 { gap: 16px; }
.mt-1 { margin-top: 4px; }
.mt-2 { margin-top: 8px; }
.mt-3 { margin-top: 12px; }
.mt-4 { margin-top: 16px; }
.mb-2 { margin-bottom: 8px; }
.mb-3 { margin-bottom: 12px; }
.mb-4 { margin-bottom: 16px; }
.mb-6 { margin-bottom: 24px; }
.text-sm { font-size: 12px; }
.text-muted { color: var(--text-muted); }
.font-bold { font-weight: 700; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ── AUTH LAYOUT ────────────────────────────────────────── */
body.auth-body {
  background: linear-gradient(135deg, var(--primary-dark) 0%, var(--primary) 60%, var(--accent) 100%);
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.auth-container {
  width: 100%;
  max-width: 440px;
}

.auth-brand {
  text-align: center;
  color: #fff;
  margin-bottom: 24px;
}
.auth-brand-icon {
  font-size: 48px;
  margin-bottom: 10px;
}
.auth-brand h1 {
  font-size: 22px;
  font-weight: 800;
  margin-bottom: 4px;
}
.auth-brand p {
  font-size: 13px;
  opacity: .8;
}

.auth-card {
  background: var(--surface);
  border-radius: 16px;
  padding: 28px 32px;
  box-shadow: 0 8px 40px rgba(0,0,0,.25);
}

.auth-title {
  font-size: 20px;
  font-weight: 800;
  margin-bottom: 20px;
  color: var(--text);
}

/* Setup wizard specifico */
.auth-container:has(.setup-header) {
  max-width: 540px;
}

.setup-section {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 16px;
  background: var(--bg);
}

.setup-section-title {
  font-size: 14px;
  font-weight: 700;
  margin-bottom: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.setup-step-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px; height: 22px;
  background: var(--primary);
  color: #fff;
  border-radius: 50%;
  font-size: 12px;
  font-weight: 800;
  flex-shrink: 0;
}

/* ── MOBILE SIDEBAR OVERLAY ─────────────────────────────── */
.sidebar-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,.4);
  z-index: 99;
}
.sidebar-overlay.show { display: block; }

/* ── RESPONSIVE ─────────────────────────────────────────── */
@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .main { margin-left: 0; }
  .stats-grid { grid-template-columns: repeat(2,1fr); }
  .form-row { grid-template-columns: 1fr; }
  .grid-2 { grid-template-columns: 1fr; }
}

@media (max-width: 600px) {
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .page-content { padding: 16px; }
  .auth-card { padding: 22px 18px; }
}

/* ── SIDEBAR TOGGLE — nascosto su desktop ───────────────── */
@media (min-width: 901px) {
  #sidebar-toggle { display: none; }
}

/* ── CALENDARIO ─────────────────────────────────────────── */
.cal-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal-day-header { text-align: center; font-size: 10px; font-weight: 700; color: var(--text-muted); padding: 4px; text-transform: uppercase; }
.cal-day {
  min-height: 80px;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 5px 6px;
  background: var(--surface);
  cursor: pointer;
  transition: background .1s;
}
.cal-day:hover { background: #F0F5FF; }
.cal-day.today { border-color: var(--primary); background: #EEF4FF; }
.cal-day.other-month { background: var(--bg); opacity: .5; }
.cal-day-num { font-size: 12px; font-weight: 700; margin-bottom: 3px; }
.cal-event {
  background: var(--primary);
  color: #fff;
  font-size: 9px;
  padding: 2px 4px;
  border-radius: 3px;
  margin-bottom: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cal-event.green  { background: var(--accent); }
.cal-event.amber  { background: var(--warning); color: var(--text); }
.cal-event.red    { background: var(--danger); }
.cal-event.purple { background: #7C3AED; }

@media (max-width: 900px) {
  .cal-day { min-height: 55px; }
}

/* ── DARK MODE ──────────────────────────────────────────── */
[data-theme="dark"] {
  --bg:        #0F172A;
  --surface:   #1E293B;
  --surface-2: #273349;
  --border:    #334155;
  --text:      #F1F5F9;
  --text-muted:#94A3B8;
}

[data-theme="dark"] body { background: var(--bg); color: var(--text); }

[data-theme="dark"] .sidebar { background: #0D2137; }

[data-theme="dark"] .topbar {
  background: var(--surface);
  border-bottom-color: var(--border);
}

[data-theme="dark"] .card { background: var(--surface); }

[data-theme="dark"] .form-control,
[data-theme="dark"] .input {
  background: var(--surface);
  border-color: var(--border);
  color: var(--text);
}

[data-theme="dark"] th { background: var(--surface-2); color: var(--text-muted); }
[data-theme="dark"] td { border-bottom-color: var(--border); }
[data-theme="dark"] tr:hover td { background: rgba(255,255,255,.04); }

[data-theme="dark"] .btn-outline {
  border-color: var(--primary-light);
  color: var(--primary-light);
}
[data-theme="dark"] .btn-outline:hover { background: rgba(21,101,192,.2); }
[data-theme="dark"] .btn-ghost { color: var(--text-muted); }
[data-theme="dark"] .btn-ghost:hover { background: rgba(255,255,255,.07); color: var(--text); }
[data-theme="dark"] .btn-icon { color: var(--text-muted); }
[data-theme="dark"] .btn-icon:hover { background: rgba(255,255,255,.07); color: var(--text); }

[data-theme="dark"] .alert-info    { background: #1e3a5f; border-color: var(--primary-light); color: #93C5FD; }
[data-theme="dark"] .alert-success { background: #1a3d2b; border-color: var(--success); color: #86EFAC; }
[data-theme="dark"] .alert-warning { background: #3d2f00; border-color: var(--warning); color: #FCD34D; }
[data-theme="dark"] .alert-danger,
[data-theme="dark"] .alert-error   { background: #3d1a1a; border-color: var(--danger); color: #FCA5A5; }

[data-theme="dark"] .badge-neutral { background: #2a3a4a; border-color: var(--border); }
[data-theme="dark"] .badge-info    { background: #1e3a5f; color: #93C5FD; }
[data-theme="dark"] .modal { background: var(--surface); }
[data-theme="dark"] .tabs { border-bottom-color: var(--border); }
[data-theme="dark"] .progress { background: var(--border); }
[data-theme="dark"] .setup-section { background: var(--surface-2); border-color: var(--border); }
[data-theme="dark"] .sidebar-overlay { background: rgba(0,0,0,.6); }
