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

:root {
  /* Palette CcV — verde bosco + rosso mattone */
  --green-50:  #f0f7f0;
  --green-100: #d4ebd4;
  --green-400: #4a8c4a;
  --green-600: #2d6a2d;
  --green-800: #1a3f1a;

  --red-50:  #fdf1f0;
  --red-100: #f9d4d1;
  --red-400: #c0392b;
  --red-600: #962d22;

  --amber-50:  #fdf6ec;
  --amber-100: #fae3b8;
  --amber-400: #d4821a;
  --amber-600: #a66214;

  --gray-0:   #ffffff;
  --gray-50:  #f8f8f7;
  --gray-100: #f0efed;
  --gray-200: #e2e0dc;
  --gray-300: #c8c5bf;
  --gray-400: #9e9b95;
  --gray-500: #6e6b65;
  --gray-600: #4a4845;
  --gray-700: #2e2c2a;
  --gray-800: #1c1a18;

  /* Semantici — light mode */
  --color-bg:         var(--gray-50);
  --color-surface:    var(--gray-0);
  --color-border:     var(--gray-200);
  --color-border-md:  var(--gray-300);
  --color-text:       var(--gray-800);
  --color-text-md:    var(--gray-600);
  --color-text-sm:    var(--gray-400);

  --color-positive:   var(--green-600);
  --color-negative:   var(--red-400);
  --color-warning:    var(--amber-400);

  /* Sidebar */
  --sidebar-w: 240px;
  --sidebar-bg: var(--gray-800);
  --sidebar-text: #c8c5bf;
  --sidebar-text-active: #ffffff;
  --sidebar-accent: var(--green-400);

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

  /* Spacing */
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;
}

/* ===== DARK MODE ===== */
[data-theme="dark"] {
  --gray-0:   #1e1c1a;
  --gray-50:  #161412;
  --gray-100: #2a2826;
  --gray-200: #3a3835;
  --gray-300: #4e4b48;
  --gray-400: #7a7774;
  --gray-500: #9e9b95;
  --gray-600: #c8c5bf;
  --gray-700: #e0deda;
  --gray-800: #f5f4f2;

  --color-bg:        #161412;
  --color-surface:   #1e1c1a;
  --color-border:    #3a3835;
  --color-border-md: #4e4b48;
  --color-text:      #f0efed;
  --color-text-md:   #c8c5bf;
  --color-text-sm:   #7a7774;

  --green-50:  #0f2010;
  --green-100: #1a3f1a;
  --red-50:    #2a1010;
  --red-100:   #4a1a1a;
  --amber-50:  #2a1e08;
  --amber-100: #4a3010;

  --sidebar-bg: #0e0d0c;
}
}

html, body {
  height: 100%;
  font-family: var(--font-body);
  font-size: 14px;
  color: var(--color-text);
  background: var(--color-bg);
  -webkit-font-smoothing: antialiased;
}

/* ===== UTILITY ===== */
.hidden { display: none !important; }
.sr-only { position:absolute;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0,0,0,0);border:0; }

/* ===== LOGIN SCREEN ===== */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--gray-800);
}

.login-card {
  background: var(--gray-0);
  border-radius: var(--radius-lg);
  padding: 2.5rem 2rem;
  width: 320px;
  text-align: center;
}

.login-logo { margin-bottom: 1.25rem; }

.logo-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 56px;
  height: 56px;
  background: var(--green-600);
  color: #fff;
  font-family: var(--font-mono);
  font-size: 16px;
  font-weight: 500;
  border-radius: var(--radius-md);
  letter-spacing: .04em;
}

.login-title {
  font-size: 22px;
  font-weight: 600;
  color: var(--gray-800);
  margin-bottom: 4px;
}

.login-sub {
  font-size: 13px;
  color: var(--color-text-sm);
  margin-bottom: 2rem;
}

.btn-google {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  padding: 10px 16px;
  background: var(--gray-0);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  font-size: 14px;
  font-weight: 500;
  color: var(--gray-700);
  cursor: pointer;
  transition: background .15s, border-color .15s;
}
.btn-google:hover { background: var(--gray-50); border-color: var(--gray-300); }

.login-note {
  margin-top: 1rem;
  font-size: 12px;
  color: var(--color-text-sm);
}

/* ===== APP SHELL ===== */
.app-shell {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ===== SIDEBAR ===== */
.sidebar {
  width: var(--sidebar-w);
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow-y: auto;
  overflow-x: hidden;
}

.sidebar-header {
  padding: 1.25rem 1rem 1rem;
  border-bottom: 1px solid rgba(255,255,255,.06);
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo-mark-sm {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  background: var(--green-600);
  color: #fff;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 500;
  border-radius: var(--radius-sm);
  flex-shrink: 0;
}

.sidebar-title {
  font-size: 14px;
  font-weight: 500;
  color: var(--sidebar-text-active);
  letter-spacing: .01em;
}

/* SALDO WIDGET */
.saldo-widget {
  margin: 1rem;
  padding: 1rem;
  background: rgba(255,255,255,.05);
  border: 1px solid rgba(255,255,255,.08);
  border-radius: var(--radius-md);
}

.saldo-label {
  font-size: 11px;
  color: var(--sidebar-text);
  text-transform: uppercase;
  letter-spacing: .06em;
  margin-bottom: 6px;
}

.saldo-value {
  font-family: var(--font-mono);
  font-size: 22px;
  font-weight: 500;
  color: #fff;
  margin-bottom: 10px;
}
.saldo-value.positive { color: #6dbf6d; }
.saldo-value.negative { color: #e07070; }

.saldo-bar {
  height: 3px;
  background: rgba(255,255,255,.1);
  border-radius: 2px;
  margin-bottom: 8px;
  overflow: hidden;
}
.saldo-bar-fill {
  height: 100%;
  background: var(--green-400);
  border-radius: 2px;
  transition: width .4s ease;
}

.saldo-detail {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  font-family: var(--font-mono);
}
.saldo-in  { color: #6dbf6d; }
.saldo-out { color: #e07070; }

/* SIDEBAR ALERTS */
.sidebar-alerts {
  padding: 0 .75rem;
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 4px;
}

.sidebar-alert {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 7px 9px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  cursor: pointer;
  transition: opacity .15s;
}
.sidebar-alert:hover { opacity: .85; }
.sidebar-alert.red    { background: rgba(192,57,43,.18); color: #f4a0a0; }
.sidebar-alert.amber  { background: rgba(212,130,26,.18); color: #f4c97a; }
.sidebar-alert i { font-size: 14px; flex-shrink: 0; }

/* SIDEBAR NAV */
.sidebar-nav {
  flex: 1;
  padding: .5rem .75rem;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  color: var(--sidebar-text);
  text-decoration: none;
  font-size: 13px;
  font-weight: 400;
  transition: background .12s, color .12s;
  position: relative;
}
.nav-item:hover  { background: rgba(255,255,255,.06); color: var(--sidebar-text-active); }
.nav-item.active { background: rgba(255,255,255,.1); color: var(--sidebar-text-active); font-weight: 500; }
.nav-item.active::before {
  content: '';
  position: absolute;
  left: 0; top: 6px; bottom: 6px;
  width: 3px;
  background: var(--sidebar-accent);
  border-radius: 0 2px 2px 0;
}
.nav-item i { font-size: 17px; flex-shrink: 0; }

.nav-badge {
  margin-left: auto;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  font-size: 10px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
}
.nav-badge:empty { display: none; }
.nav-badge-red   { background: rgba(192,57,43,.35); color: #f4a0a0; }
.nav-badge-amber { background: rgba(212,130,26,.35); color: #f4c97a; }
.nav-badge-green { background: rgba(74,140,74,.35); color: #6dbf6d; }

/* SIDEBAR FOOTER */
.sidebar-footer {
  padding: .75rem 1rem;
  border-top: 1px solid rgba(255,255,255,.06);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.anno-select {
  width: 100%;
  background: rgba(255,255,255,.07);
  border: 1px solid rgba(255,255,255,.1);
  border-radius: var(--radius-sm);
  color: var(--sidebar-text);
  font-size: 12px;
  padding: 5px 8px;
  cursor: pointer;
}
.anno-select option { background: var(--gray-700); color: #fff; }

.user-chip {
  display: flex;
  align-items: center;
  gap: 8px;
}

.user-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--green-600);
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  overflow: hidden;
}
.user-avatar img { width: 100%; height: 100%; object-fit: cover; }

.user-name {
  font-size: 12px;
  color: var(--sidebar-text);
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.btn-logout {
  background: none;
  border: none;
  color: var(--gray-500);
  cursor: pointer;
  padding: 4px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  transition: color .15s;
  font-size: 16px;
}
.btn-logout:hover { color: #e07070; }

/* ===== MAIN CONTENT ===== */
.main-content {
  flex: 1;
  overflow-y: auto;
  background: var(--color-bg);
}

.page { display: none; min-height: 100vh; }
.page.active { display: block; }

/* PAGE HEADER */
.page-header {
  padding: 1.75rem 2rem 1.25rem;
  border-bottom: 1px solid var(--color-border);
  background: var(--color-surface);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  position: sticky;
  top: 0;
  z-index: 10;
}

.page-title { font-size: 18px; font-weight: 600; color: var(--gray-800); }
.page-subtitle { font-size: 13px; color: var(--color-text-sm); margin-top: 2px; }

.page-actions { display: flex; gap: 8px; align-items: center; flex-shrink: 0; }

.page-body { padding: 1.5rem 2rem; }

/* ===== STAT CARDS ===== */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 1.5rem;
}

.stat-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 1rem 1.125rem;
}
.stat-card-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--color-text-sm);
  margin-bottom: 6px;
}
.stat-card-value {
  font-family: var(--font-mono);
  font-size: 20px;
  font-weight: 500;
  color: var(--gray-800);
}
.stat-card-value.positive { color: var(--green-600); }
.stat-card-value.negative { color: var(--red-400); }
.stat-card-value.warning  { color: var(--amber-400); }
.stat-card-sub {
  font-size: 12px;
  color: var(--color-text-sm);
  margin-top: 4px;
}

/* ===== TABLE ===== */
.table-wrap {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.table-toolbar {
  padding: .75rem 1rem;
  border-bottom: 1px solid var(--color-border);
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
thead th {
  text-align: left;
  padding: 9px 1rem;
  font-size: 11px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--color-text-sm);
  border-bottom: 1px solid var(--color-border);
  background: var(--gray-50);
  white-space: nowrap;
}
tbody tr {
  border-bottom: 1px solid var(--color-border);
  transition: background .1s;
  cursor: pointer;
}
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: var(--gray-50); }
tbody td {
  padding: 10px 1rem;
  color: var(--color-text);
  vertical-align: middle;
}
.td-mono { font-family: var(--font-mono); }
.td-muted { color: var(--color-text-sm); }
.td-amount-pos { font-family: var(--font-mono); font-weight: 500; color: var(--green-600); }
.td-amount-neg { font-family: var(--font-mono); font-weight: 500; color: var(--red-400); }
.td-amount-warn { font-family: var(--font-mono); font-weight: 500; color: var(--amber-400); }

.table-empty {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--color-text-sm);
  font-size: 13px;
}
.table-empty i { font-size: 32px; display: block; margin-bottom: .5rem; opacity: .4; }

/* TABLE FOOTER */
.table-footer {
  padding: .625rem 1rem;
  border-top: 1px solid var(--color-border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
  color: var(--color-text-sm);
  background: var(--gray-50);
}

/* ===== BADGES ===== */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 500;
  white-space: nowrap;
}
.badge-green  { background: var(--green-50);  color: var(--green-800); }
.badge-red    { background: var(--red-50);    color: var(--red-600); }
.badge-amber  { background: var(--amber-50);  color: var(--amber-600); }
.badge-gray   { background: var(--gray-100);  color: var(--gray-600); }
.badge-teal   { background: #e8f7f5; color: #1a6b5e; }
.badge-purple { background: #f0eeff; color: #4a3ab0; }
.badge-blue   { background: #e8f1fb; color: #1a4e8a; }

/* ===== STATUS DOTS ===== */
.dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
}
.dot-green { background: var(--green-400); }
.dot-red   { background: var(--red-400); }
.dot-amber { background: var(--amber-400); }
.dot-gray  { background: var(--gray-300); }

/* ===== BUTTONS ===== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: var(--radius-md);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background .12s, border-color .12s, opacity .12s;
  border: 1px solid transparent;
  white-space: nowrap;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn i { font-size: 15px; }

.btn-primary   { background: var(--green-600); color: #fff; border-color: var(--green-600); }
.btn-primary:hover { background: var(--green-800); border-color: var(--green-800); }

.btn-danger    { background: var(--red-400); color: #fff; border-color: var(--red-400); }
.btn-danger:hover { background: var(--red-600); border-color: var(--red-600); }

.btn-outline   { background: transparent; color: var(--gray-700); border-color: var(--color-border-md); }
.btn-outline:hover { background: var(--gray-50); border-color: var(--gray-300); }

.btn-ghost     { background: transparent; color: var(--gray-600); border-color: transparent; }
.btn-ghost:hover { background: var(--gray-100); }

.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-sm i { font-size: 13px; }

/* ===== ALERT BAR ===== */
.alert-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: var(--radius-md);
  font-size: 13px;
  margin-bottom: 1rem;
}
.alert-bar i { font-size: 16px; flex-shrink: 0; }
.alert-bar a { font-weight: 500; text-decoration: underline; cursor: pointer; }
.alert-bar.red   { background: var(--red-50);   border: 1px solid var(--red-100);   color: var(--red-600); }
.alert-bar.amber { background: var(--amber-50); border: 1px solid var(--amber-100); color: var(--amber-600); }
.alert-bar.green { background: var(--green-50); border: 1px solid var(--green-100); color: var(--green-600); }

/* ===== FORMS ===== */
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}
.form-grid.thirds { grid-template-columns: 1fr 1fr 1fr; }
.form-grid.full   { grid-template-columns: 1fr; }

.form-group {
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.form-group.span-2 { grid-column: span 2; }
.form-group.span-3 { grid-column: span 3; }

label {
  font-size: 12px;
  font-weight: 500;
  color: var(--color-text-md);
}

input[type="text"],
input[type="number"],
input[type="date"],
input[type="email"],
input[type="url"],
select,
textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-family: var(--font-body);
  color: var(--color-text);
  background: var(--color-surface);
  transition: border-color .15s;
  outline: none;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--green-400);
  box-shadow: 0 0 0 3px rgba(74,140,74,.12);
}
input.error, select.error { border-color: var(--red-400); }
textarea { resize: vertical; min-height: 80px; }
.form-hint { font-size: 11px; color: var(--color-text-sm); }
.form-error { font-size: 11px; color: var(--red-400); }

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 1.25rem;
  padding-top: 1rem;
  border-top: 1px solid var(--color-border);
}

/* ===== MODAL ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.modal {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 720px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 8px 32px rgba(0,0,0,.18);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.25rem 1.5rem 1rem;
  border-bottom: 1px solid var(--color-border);
  position: sticky;
  top: 0;
  background: var(--color-surface);
  z-index: 1;
}
.modal-title { font-size: 16px; font-weight: 600; }
.modal-close {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--color-text-sm);
  font-size: 18px;
  padding: 4px;
  border-radius: var(--radius-sm);
  display: flex;
  transition: background .12s;
}
.modal-close:hover { background: var(--gray-100); }
.modal-body { padding: 1.25rem 1.5rem 1.5rem; }

/* ===== SCADENZIARIO CARDS ===== */
.scad-section-title {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--color-text-sm);
  margin: 1.25rem 0 .5rem;
  display: flex;
  align-items: center;
  gap: 6px;
}
.scad-section-title i { font-size: 13px; }

.scad-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: .875rem 1rem;
  margin-bottom: 6px;
  display: flex;
  gap: 12px;
  align-items: flex-start;
  cursor: pointer;
  transition: border-color .12s, box-shadow .12s;
}
.scad-card:hover { border-color: var(--gray-300); }
.scad-card.urgente { border-left: 3px solid var(--red-400); }
.scad-card.avviso  { border-left: 3px solid var(--amber-400); }
.scad-card.ok      { border-left: 3px solid var(--green-400); }
.scad-card.fatto   { opacity: .55; }

.scad-check {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 1.5px solid var(--color-border-md);
  flex-shrink: 0;
  margin-top: 1px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .15s, border-color .15s;
  cursor: pointer;
}
.scad-check:hover { border-color: var(--green-400); background: var(--green-50); }
.scad-check.done  { background: var(--green-50); border-color: var(--green-400); color: var(--green-600); }
.scad-check.done i { font-size: 12px; }

.scad-body { flex: 1; min-width: 0; }
.scad-title { font-size: 13px; font-weight: 500; margin-bottom: 4px; }
.scad-meta { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 12px; color: var(--color-text-sm); }

.scad-amount { font-family: var(--font-mono); font-size: 13px; font-weight: 500; flex-shrink: 0; text-align: right; }

.countdown { font-weight: 500; }
.countdown.red   { color: var(--red-400); }
.countdown.amber { color: var(--amber-400); }
.countdown.green { color: var(--green-600); }

.pill-ricorrenza {
  font-size: 10px;
  padding: 1px 7px;
  border-radius: 10px;
  background: var(--gray-100);
  color: var(--gray-500);
  border: 1px solid var(--color-border);
}

/* ===== DASHBOARD ===== */
.dash-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.25rem;
  margin-top: 1.25rem;
}
.dash-panel {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  overflow: hidden;
}
.dash-panel-header {
  padding: .875rem 1rem;
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 13px;
  font-weight: 500;
}
.dash-panel-body { padding: 0; }

/* ===== TOAST ===== */
.toast-container {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}
.toast {
  background: var(--gray-800);
  color: #fff;
  padding: 10px 14px;
  border-radius: var(--radius-md);
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 8px;
  pointer-events: all;
  animation: toast-in .2s ease;
  max-width: 320px;
}
.toast.success { background: var(--green-600); }
.toast.error   { background: var(--red-400); }
.toast.warning { background: var(--amber-400); color: var(--gray-800); }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ===== LOADING ===== */
.loading-spinner {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 3rem;
  color: var(--color-text-sm);
  gap: 10px;
  font-size: 13px;
}
.loading-spinner::before {
  content: '';
  width: 18px;
  height: 18px;
  border: 2px solid var(--color-border);
  border-top-color: var(--green-400);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== RESPONSIVE TABLET ===== */
@media (max-width: 768px) {
  .sidebar { width: 200px; }
  .page-body { padding: 1rem; }
  .form-grid { grid-template-columns: 1fr; }
  .form-grid.thirds { grid-template-columns: 1fr; }
  .form-group.span-2 { grid-column: span 1; }
  .dash-grid { grid-template-columns: 1fr; }
}

/* ===== RESPONSIVE MOBILE ===== */
@media (max-width: 600px) {

  /* Sidebar → navbar in basso */
  .sidebar {
    position: fixed;
    bottom: 0; left: 0; right: 0;
    width: 100%;
    height: auto;
    flex-direction: row;
    z-index: 50;
    border-top: 1px solid rgba(255,255,255,.1);
    overflow: visible;
  }

  .sidebar-header,
  .sidebar-alerts,
  .sidebar-footer,
  .saldo-widget { display: none; }

  .sidebar-nav {
    flex-direction: row;
    padding: 0;
    gap: 0;
    width: 100%;
    justify-content: space-around;
  }

  .nav-item {
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0;
    padding: 10px 2px;
    flex: 1;
    border-radius: 0;
    min-width: 0;
  }
  .nav-item::before { display: none; }
  .nav-item i { font-size: 22px; }
  .nav-item span { display: none; }
  .nav-badge {
    position: absolute;
    top: 5px;
    right: calc(50% - 16px);
    min-width: 16px;
    height: 16px;
    font-size: 9px;
  }
  .nav-item { position: relative; }

  /* Main content — spazio per navbar in basso */
  .main-content {
    padding-bottom: 70px;
  }

  /* Saldo mobile — banner in cima alla dashboard */
  .mobile-saldo-banner {
    display: flex !important;
    background: var(--gray-800);
    color: #fff;
    padding: .875rem 1rem;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
  }
  .mobile-saldo-banner .saldo-val {
    font-family: var(--font-mono);
    font-size: 20px;
    font-weight: 500;
  }
  .mobile-saldo-banner .saldo-val.positive { color: #6dbf6d; }
  .mobile-saldo-banner .saldo-val.negative { color: #e07070; }
  .mobile-saldo-banner .saldo-sub {
    font-size: 11px;
    color: rgba(255,255,255,.5);
    margin-top: 2px;
  }
  .mobile-saldo-banner .saldo-detail {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 2px;
    font-size: 11px;
    font-family: var(--font-mono);
  }

  /* Page header compatto */
  .page-header {
    padding: .875rem 1rem;
    flex-wrap: wrap;
    gap: .5rem;
    position: sticky;
    top: 0;
    z-index: 10;
  }
  .page-title { font-size: 16px; }
  .page-subtitle { font-size: 12px; }
  .page-actions { width: 100%; justify-content: flex-end; }
  .page-body { padding: .75rem; }

  /* Stat grid 2x2 */
  .stat-grid {
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-bottom: 1rem;
  }
  .stat-card { padding: .75rem; }
  .stat-card-value { font-size: 16px; }
  .stat-card-label { font-size: 10px; }

  /* Tabelle → card verticali */
  .table-wrap { border-radius: var(--radius-md); overflow: hidden; }
  .table-toolbar { flex-wrap: wrap; gap: 6px; }
  .table-toolbar select,
  .table-toolbar input { font-size: 14px; min-width: 0; flex: 1 1 120px; }

  table thead { display: none; }
  table, table tbody, table tr, table td { display: block; width: 100%; }

  table tbody tr {
    border: none;
    border-bottom: 1px solid var(--color-border);
    padding: .75rem 1rem;
    display: flex;
    flex-direction: column;
    gap: 5px;
  }
  table tbody tr:last-child { border-bottom: none; }

  table tbody td {
    padding: 0;
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
  }

  /* Prima cella = titolo riga */
  table tbody td:first-child {
    font-weight: 500;
    font-size: 14px;
    color: var(--color-text);
  }

  /* Nascondi celle vuote o secondarie */
  table tbody td:empty { display: none; }

  /* Riga azioni — allinea a destra */
  table tbody td:last-child {
    justify-content: flex-end;
    margin-top: 4px;
  }

  /* Importi più grandi e leggibili */
  .td-amount-pos, .td-amount-neg, .td-amount-warn {
    font-size: 14px;
    font-weight: 600;
  }

  /* Alert bar */
  .alert-bar { font-size: 12px; padding: 8px 10px; }

  /* Dashboard grid */
  .dash-grid { grid-template-columns: 1fr; gap: .75rem; }

  /* Form mobile */
  .form-grid,
  .form-grid.thirds { grid-template-columns: 1fr; }
  .form-group.span-2,
  .form-group.span-3 { grid-column: span 1; }

  input[type="text"],
  input[type="number"],
  input[type="date"],
  input[type="email"],
  input[type="url"],
  select,
  textarea {
    font-size: 16px; /* evita zoom automatico iOS */
    padding: 10px 12px;
  }

  .btn { padding: 9px 14px; font-size: 14px; }
  .btn-sm { padding: 7px 12px; font-size: 13px; }

  /* Modal fullscreen su mobile */
  .modal-overlay { padding: 0; align-items: flex-end; }
  .modal {
    max-width: 100%;
    max-height: 95vh;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  }
  .modal-header { padding: 1rem 1.25rem .875rem; }
  .modal-body { padding: 1rem 1.25rem 1.5rem; }

  /* Scadenziario card */
  .scad-card { padding: .75rem; }
  .scad-title { font-size: 13px; }
  .scad-meta { font-size: 11px; }

  /* Toast */
  .toast-container { bottom: 80px; right: .75rem; left: .75rem; }
  .toast { max-width: 100%; }

  /* Login */
  .login-card { width: calc(100% - 2rem); padding: 2rem 1.5rem; }
}

/* Banner saldo mobile — nascosto su desktop */
.mobile-saldo-banner { display: none; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
