/* ========== VARIABLES ========== */
:root {
  --bg-primary: #1a1d23;
  --bg-secondary: #22262e;
  --bg-tertiary: #2c313b;
  --bg-hover: #343a46;
  --text-primary: #e8eaed;
  --text-secondary: #9aa0ad;
  --text-muted: #6b7280;
  --accent: #5e9cea;
  --accent-bright: #7eb0f2;
  --accent-dim: #3d78c3;
  --border: #363b47;
  --border-glow: #4a5060;
  --green: #34d399;
  --red: #f87171;
  --orange: #f59e0b;
  --gold: #d4a843;
  --radius: 8px;
  --radius-lg: 12px;
  --font: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
}

/* ========== RESET ========== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: var(--font);
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  font-size: 14px;
}
button { font-family: inherit; }
input, textarea, select { font-family: inherit; }
a { color: var(--accent-bright); }

/* ========== LOGIN SCREEN ========== */
.login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 24px;
}
.login-card {
  text-align: center;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 48px 40px;
  max-width: 360px;
  width: 100%;
}
.login-logo { display: block; margin: 0 auto 16px; width: 56px; height: 56px; border-radius: 14px; }
.login-title { font-size: 1.8rem; font-weight: 700; margin-bottom: 4px; }
.login-subtitle { color: var(--text-muted); font-size: 0.9rem; margin-bottom: 32px; }
.google-btn {
  display: inline-flex; align-items: center; gap: 10px;
  background: #fff; color: #333; border: none;
  font-size: 0.92rem; font-weight: 600;
  padding: 12px 28px; border-radius: var(--radius);
  cursor: pointer; transition: box-shadow 0.2s;
}
.google-btn:hover { box-shadow: 0 2px 12px rgba(94,156,234,0.3); }
.login-error { color: var(--red); font-size: 0.8rem; margin-top: 16px; min-height: 1.2em; }

/* ========== SYNC INDICATOR ========== */
.sync-indicator {
  display: flex; align-items: center; gap: 6px;
  justify-content: flex-end;
  padding: 6px 16px 0;
  max-width: 1200px; margin: 0 auto;
}
.sync-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--text-muted);
  transition: background 0.4s, box-shadow 0.4s;
}
.sync-indicator.synced .sync-dot { background: #3fb950; box-shadow: 0 0 6px rgba(63,185,80,0.5); }
.sync-indicator.error .sync-dot { background: #da3633; box-shadow: 0 0 6px rgba(218,54,51,0.4); }
.sync-label {
  font-size: 0.6rem; color: var(--text-muted);
  letter-spacing: 0.3px; text-transform: uppercase; font-weight: 600;
}
.sync-indicator.synced .sync-label { color: #3fb950; }
.sync-indicator.error .sync-label { color: #da3633; }

/* ========== HEADER ========== */
header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 24px; max-width: 1200px; margin: 0 auto; gap: 12px;
  flex-wrap: wrap;
}
.header-left { display: flex; align-items: center; gap: 14px; }
.logo { display: flex; align-items: center; gap: 8px; }
.logo-icon {
  width: 28px; height: 28px;
  display: flex; align-items: center; justify-content: center;
  color: #fff; background: var(--accent); border-radius: 7px;
  box-shadow: 0 2px 8px rgba(94,156,234,0.35);
}
.logo-icon svg { width: 18px; height: 18px; }
.logo-text { font-size: 1.3rem; font-weight: 700; letter-spacing: -0.5px; }
.header-right { display: flex; align-items: center; gap: 10px; }
.user-email { font-size: 0.78rem; color: var(--text-muted); }
.lang-toggle, .admin-link, .logout-btn {
  background: var(--bg-tertiary); border: 1px solid var(--border);
  color: var(--text-secondary);
  font-size: 0.72rem; font-weight: 600; letter-spacing: 0.3px;
  padding: 5px 10px; border-radius: 6px; cursor: pointer;
  transition: all 0.15s; text-decoration: none;
  display: inline-flex; align-items: center;
}
.lang-toggle:hover, .admin-link:hover, .logout-btn:hover {
  border-color: var(--accent); color: var(--text-primary);
}

/* ========== TABS ========== */
.tabs {
  display: flex; gap: 4px;
  background: var(--bg-secondary);
  padding: 3px; border-radius: 8px;
  border: 1px solid var(--border);
}
.tab {
  background: none; border: none; color: var(--text-secondary);
  font-size: 13px; font-weight: 500;
  padding: 6px 16px; border-radius: 6px;
  cursor: pointer; transition: all 0.15s;
}
.tab:hover { color: var(--text-primary); }
.tab.active { background: var(--accent); color: #fff; }

/* ========== VIEWS ========== */
.view { display: none; }
.view.active { display: block; }
.view-inner { padding: 24px; max-width: 1200px; margin: 0 auto; }

.sub-tabs { margin-top: 16px; }
.sub-view { display: none; margin-top: 18px; }
.sub-view.active { display: block; }

/* ========== DETAIL HEADER ========== */
.detail-header {
  padding-bottom: 4px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 4px;
}
.back-btn {
  display: inline-flex; align-items: center; gap: 4px;
  background: none; border: none; color: var(--text-muted);
  font-size: 0.82rem; font-weight: 600;
  padding: 4px 0; cursor: pointer;
  margin-bottom: 12px;
  transition: color 0.15s;
}
.back-btn:hover { color: var(--text-primary); }
.detail-title-row {
  display: flex; align-items: center; gap: 14px;
  margin-bottom: 12px;
}
.detail-avatar {
  width: 52px; height: 52px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 700; font-size: 1.15rem;
  flex-shrink: 0;
}
.detail-title { flex: 1; min-width: 0; }
.detail-title h2 {
  font-size: 1.4rem; font-weight: 700;
  margin-bottom: 2px;
}
.detail-meta { font-size: 0.8rem; color: var(--text-muted); }

.section-subtitle { font-size: 1.1rem; font-weight: 700; }

/* ========== SECTION HEADER ========== */
.section-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 20px; gap: 12px; flex-wrap: wrap;
}
.section-title { font-size: 1.4rem; font-weight: 700; }

/* ========== BUTTONS ========== */
.btn-primary {
  background: var(--accent); color: #fff; border: none;
  padding: 8px 16px; border-radius: 6px; cursor: pointer;
  font-weight: 600; font-size: 0.85rem;
  transition: background 0.15s;
}
.btn-primary:hover { background: var(--accent-bright); }
.btn-ghost {
  background: transparent; color: var(--text-secondary);
  border: 1px solid var(--border);
  padding: 8px 16px; border-radius: 6px; cursor: pointer;
  font-weight: 500; font-size: 0.85rem; transition: all 0.15s;
}
.btn-ghost:hover { color: var(--text-primary); border-color: var(--border-glow); }
.btn-danger {
  background: transparent; color: var(--red);
  border: 1px solid rgba(248,113,113,0.3);
  padding: 8px 16px; border-radius: 6px; cursor: pointer;
  font-weight: 500; font-size: 0.85rem; transition: all 0.15s;
}
.btn-danger:hover { background: rgba(248,113,113,0.1); }
.btn-link {
  color: var(--accent-bright); text-decoration: none;
  font-size: 0.8rem; padding: 4px 8px; border-radius: 4px;
  border: 1px solid var(--border);
}
.btn-link:hover { background: var(--bg-hover); }
.icon-btn {
  background: transparent; border: none; color: var(--text-muted);
  cursor: pointer; padding: 6px 8px; border-radius: 4px;
  font-size: 0.95rem; transition: all 0.15s;
}
.icon-btn:hover { background: var(--bg-hover); color: var(--text-primary); }

/* ========== ACCOUNT CARDS ========== */
.accounts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 14px;
}
.account-card {
  display: flex; align-items: center; gap: 14px;
  background: var(--bg-secondary);
  border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: 16px; cursor: pointer; transition: all 0.15s;
}
.account-card:hover { border-color: var(--border-glow); background: var(--bg-tertiary); }
.account-avatar {
  width: 44px; height: 44px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 700; font-size: 1rem;
  flex-shrink: 0;
}
.account-info { flex: 1; min-width: 0; }
.account-name { font-weight: 600; margin-bottom: 2px; }
.account-meta { font-size: 0.78rem; color: var(--text-muted); }
.account-stats { display: flex; gap: 6px; font-size: 0.75rem; color: var(--text-secondary); margin-top: 4px; flex-wrap: wrap; }
.account-chevron {
  color: var(--text-muted); font-size: 1.3rem;
  padding: 0 4px; transition: transform 0.15s, color 0.15s;
}
.account-card:hover .account-chevron,
.asset-card:hover .account-chevron { color: var(--text-primary); transform: translateX(2px); }

/* ========== ASSETS GRID ========== */
.assets-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(290px, 1fr));
  gap: 14px;
  margin-top: 14px;
}
.asset-card {
  display: flex; align-items: center; gap: 14px;
  background: var(--bg-secondary);
  border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: 16px; cursor: pointer; transition: all 0.15s;
}
.asset-card:hover { border-color: var(--border-glow); background: var(--bg-tertiary); }
.asset-icon {
  width: 52px; height: 52px; border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.6rem; flex-shrink: 0;
  background: var(--bg-tertiary); border: 1px solid var(--border);
}
.asset-icon-immobile { background: rgba(251,146,60,0.12); border-color: rgba(251,146,60,0.3); }
.asset-icon-mobile { background: rgba(168,85,247,0.12); border-color: rgba(168,85,247,0.3); }
.asset-icon-personale { background: rgba(94,156,234,0.12); border-color: rgba(94,156,234,0.3); }
.asset-icon-altro { background: var(--bg-tertiary); }
.asset-icon-lg { width: 64px; height: 64px; font-size: 2rem; border-radius: 14px; }
.asset-info { flex: 1; min-width: 0; }
.asset-name {
  font-weight: 600; font-size: 0.95rem;
  margin-bottom: 2px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.asset-meta { font-size: 0.77rem; color: var(--text-muted); }
.asset-stats { display: flex; gap: 6px; font-size: 0.75rem; color: var(--text-secondary); margin-top: 4px; flex-wrap: wrap; }

/* Asset detail view */
.asset-detail-header {
  display: flex; align-items: center; gap: 16px;
  padding: 14px 0 18px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 18px;
}
.asset-detail-info { flex: 1; min-width: 0; }
.asset-detail-title {
  font-size: 1.3rem; font-weight: 700;
  margin-bottom: 3px;
}

.asset-section {
  margin-bottom: 26px;
}
.asset-section-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 10px;
}
.asset-section-title {
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  font-weight: 700;
}

.btn-sm { padding: 5px 12px; font-size: 0.78rem; }

/* ========== FILTER ROWS ========== */
.filter-row {
  display: flex; align-items: center; gap: 10px;
  margin-bottom: 10px; flex-wrap: wrap;
}
.filter-label {
  font-size: 0.7rem; color: var(--text-muted);
  font-weight: 700; text-transform: uppercase; letter-spacing: 0.4px;
  width: 46px; flex-shrink: 0;
}
.filter-group {
  display: flex; gap: 6px; flex-wrap: wrap;
}
.filter-btn {
  background: var(--bg-secondary); color: var(--text-secondary);
  border: 1px solid var(--border);
  padding: 5px 12px; border-radius: 6px;
  font-size: 0.78rem; cursor: pointer; transition: all 0.15s;
  display: inline-flex; align-items: center; gap: 4px;
}
.filter-btn:hover { color: var(--text-primary); }
.filter-btn.active { background: var(--accent); color: #fff; border-color: var(--accent); }

.utenze-hint { color: var(--text-muted); font-size: 0.9rem; margin: 16px 0; }

.utenze-table-wrap {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow-x: auto;
}
.utenze-table {
  width: 100%; border-collapse: collapse;
  font-size: 0.82rem; min-width: 1000px;
}
.utenze-table thead th {
  text-align: left; padding: 10px 12px;
  color: var(--text-muted); font-weight: 600;
  font-size: 0.72rem; letter-spacing: 0.4px; text-transform: uppercase;
  border-bottom: 1px solid var(--border);
  background: var(--bg-tertiary);
}
.utenze-table th.num, .utenze-table td.num { text-align: right; }
.utenze-table tbody td {
  padding: 10px 12px; vertical-align: top;
  border-bottom: 1px solid var(--border);
}
.utenze-table tbody tr:last-child td { border-bottom: none; }
.utenze-table tbody tr:hover { background: var(--bg-tertiary); }
.cell-name { display: flex; align-items: center; gap: 8px; }
.cell-icon {
  width: 28px; height: 28px; border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 0.95rem; flex-shrink: 0;
}
.subtle { color: var(--text-muted); font-size: 0.72rem; margin-top: 2px; }
.actions-cell { width: 40px; text-align: right; }

/* ========== PILLS ========== */
.pill {
  display: inline-block;
  padding: 2px 8px; border-radius: 999px;
  font-size: 0.7rem; font-weight: 600;
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  border: 1px solid var(--border);
  white-space: nowrap;
}
.pill-stato-attiva { background: rgba(52,211,153,0.15); color: var(--green); border-color: rgba(52,211,153,0.3); }
.pill-stato-sospesa { background: rgba(245,158,11,0.15); color: var(--orange); border-color: rgba(245,158,11,0.3); }
.pill-stato-chiusa { background: rgba(107,114,128,0.2); color: var(--text-muted); }

.pill-cat-bolletta { background: rgba(94,156,234,0.15); color: #7eb0f2; border-color: rgba(94,156,234,0.3); }
.pill-cat-condominio { background: rgba(20,184,166,0.15); color: #5eead4; border-color: rgba(20,184,166,0.3); }
.pill-cat-assicurazione { background: rgba(168,85,247,0.15); color: #c084fc; border-color: rgba(168,85,247,0.3); }
.pill-cat-tassa-rifiuti { background: rgba(52,211,153,0.15); color: var(--green); border-color: rgba(52,211,153,0.3); }
.pill-cat-tassa-territoriale { background: rgba(251,146,60,0.15); color: #fdba74; border-color: rgba(251,146,60,0.3); }
.pill-cat-irpef { background: rgba(248,113,113,0.15); color: var(--red); border-color: rgba(248,113,113,0.3); }
.pill-cat-canone { background: rgba(236,72,153,0.15); color: #f472b6; border-color: rgba(236,72,153,0.3); }
.pill-cat-mutuo { background: rgba(14,165,233,0.15); color: #7dd3fc; border-color: rgba(14,165,233,0.3); }
.pill-cat-altro { background: var(--bg-tertiary); }

/* ========== EMPTY STATE ========== */
.empty-state {
  color: var(--text-muted); text-align: center;
  padding: 40px 20px; font-size: 0.9rem;
}

/* ========== DOCUMENTI CARDS ========== */
.doc-list {
  display: flex; flex-direction: column; gap: 8px;
}
.doc-card {
  display: flex; align-items: flex-start; gap: 12px;
  background: var(--bg-secondary); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 12px 14px;
}
.doc-icon { font-size: 1.4rem; line-height: 1; padding-top: 2px; }
.doc-info { flex: 1; min-width: 0; }
.doc-name { font-weight: 600; margin-bottom: 3px; }
.doc-meta {
  display: flex; gap: 8px; flex-wrap: wrap;
  font-size: 0.72rem; color: var(--text-muted);
}
.doc-note { font-size: 0.8rem; color: var(--text-secondary); margin-top: 6px; }
.doc-actions { display: flex; gap: 6px; align-items: center; }

/* ========== DOCUMENTI FOLDERS (grouped by utenza → year) ========== */
.doc-folder {
  background: var(--bg-secondary); border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 10px;
  overflow: hidden;
}
.doc-folder-head {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 14px; cursor: pointer;
  list-style: none;
  user-select: none;
}
.doc-folder-head::-webkit-details-marker { display: none; }
.doc-folder-head::before {
  content: '▸';
  color: var(--text-muted);
  font-size: 0.8rem;
  transition: transform 0.15s;
  width: 12px;
}
.doc-folder[open] .doc-folder-head::before { transform: rotate(90deg); }
.doc-folder-name { flex: 1; font-weight: 600; }
.doc-folder-count {
  background: var(--bg-tertiary); color: var(--text-muted);
  font-size: 0.72rem; font-weight: 600;
  padding: 2px 8px; border-radius: 999px;
}
.doc-folder-body {
  padding: 4px 14px 14px; display: flex; flex-direction: column; gap: 12px;
}
.doc-year-group { display: flex; flex-direction: column; gap: 6px; }
.doc-year-label {
  font-size: 0.72rem; font-weight: 600;
  color: var(--text-muted); text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* ========== QUICK-DOC MODAL ========== */
.quick-doc-context {
  display: flex; align-items: center; gap: 12px;
  background: var(--bg-tertiary); border-radius: var(--radius);
  padding: 10px 12px; margin-bottom: 14px;
}
.quick-doc-utenza { font-weight: 600; }
.quick-doc-date { font-size: 0.78rem; color: var(--text-muted); }
.quick-actions {
  display: flex; flex-direction: column; gap: 8px;
  margin: 8px 0 4px;
}
.quick-action-btn {
  width: 100%; text-align: left;
  padding: 12px 14px; font-size: 0.95rem;
}
.modal.modal-sm { max-width: 380px; }

/* ========== MODAL ========== */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex; align-items: center; justify-content: center;
  padding: 20px; z-index: 100;
  overflow-y: auto;
}
.modal {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px; width: 100%; max-width: 520px;
  max-height: 90vh; overflow-y: auto;
}
.modal-wide { max-width: 780px; }
.modal-title { font-size: 1.1rem; font-weight: 700; margin-bottom: 18px; }
.form-grid {
  display: grid; grid-template-columns: 1fr 1fr;
  gap: 12px 14px;
}
.form-field { display: flex; flex-direction: column; gap: 4px; }
.form-field > span {
  font-size: 0.72rem; color: var(--text-muted);
  font-weight: 600; letter-spacing: 0.3px; text-transform: uppercase;
}
.form-field input, .form-field select, .form-field textarea {
  background: var(--bg-primary);
  border: 1px solid var(--border);
  color: var(--text-primary);
  padding: 8px 10px; border-radius: 6px;
  font-size: 0.88rem;
  outline: none;
  transition: border-color 0.15s;
}
.form-field input:focus, .form-field select:focus, .form-field textarea:focus {
  border-color: var(--accent);
}
.form-field input[type=color] { height: 36px; padding: 2px; cursor: pointer; }
.form-field-full { grid-column: 1 / -1; }
.form-section {
  grid-column: 1 / -1;
  margin-top: 6px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}
.form-section h4 {
  font-size: 0.78rem; font-weight: 700; color: var(--text-secondary);
  text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 4px;
}
.checkbox-field {
  display: flex; align-items: center; gap: 8px;
  cursor: pointer;
}
.checkbox-field input { width: 16px; height: 16px; accent-color: var(--accent); }
.checkbox-field span { font-size: 0.88rem; color: var(--text-primary); }
.modal-actions {
  display: flex; justify-content: space-between; align-items: center;
  margin-top: 20px; gap: 8px;
}
.modal-actions > div { display: flex; gap: 8px; }

/* ========== CALENDAR ========== */
.cal-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 14px;
}
.cal-nav { display: flex; align-items: center; gap: 10px; }
.cal-title { font-size: 1.1rem; font-weight: 700; min-width: 160px; text-align: center; }
.cal-btn {
  background: var(--bg-secondary); border: 1px solid var(--border);
  color: var(--text-primary);
  padding: 6px 12px; border-radius: 6px; cursor: pointer;
  font-size: 0.88rem; transition: all 0.15s;
}
.cal-btn:hover { background: var(--bg-hover); border-color: var(--border-glow); }
.cal-today-btn { font-weight: 600; }
.cal-legend {
  display: flex; gap: 14px;
  font-size: 0.75rem; color: var(--text-secondary);
  margin-bottom: 12px; flex-wrap: wrap;
}
.cal-legend span { display: flex; align-items: center; gap: 5px; }
.cal-dot {
  width: 9px; height: 9px; border-radius: 2px;
}
.cal-dot.check { background: var(--accent); }
.cal-dot.scadenza { background: var(--red); }
.cal-dot.done { background: var(--green); }

.cal-grid {
  display: grid; grid-template-columns: repeat(7, 1fr);
  gap: 4px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 6px;
}
.cal-day-header {
  text-align: center; padding: 8px 4px;
  font-size: 0.7rem; color: var(--text-muted);
  font-weight: 700; text-transform: uppercase; letter-spacing: 0.3px;
}
.cal-day {
  background: var(--bg-primary);
  min-height: 96px;
  padding: 6px;
  border-radius: 6px;
  display: flex; flex-direction: column; gap: 4px;
}
.cal-day-empty { background: transparent; min-height: 0; }
.cal-day-today { outline: 2px solid var(--accent); outline-offset: -2px; }
.cal-day-num {
  font-size: 0.78rem; font-weight: 600; color: var(--text-secondary);
}
.cal-day-today .cal-day-num { color: var(--accent-bright); }
.cal-events { display: flex; flex-direction: column; gap: 3px; overflow: hidden; }
.cal-event {
  display: flex; align-items: center; gap: 4px;
  background: var(--bg-tertiary); border: 1px solid var(--border);
  border-left: 3px solid var(--ev-color, var(--accent));
  border-radius: 4px;
  padding: 3px 5px; cursor: pointer;
  font-size: 0.7rem; color: var(--text-primary);
  overflow: hidden;
  transition: background 0.15s;
}
.cal-event:hover { background: var(--bg-hover); }
.cal-event-icon { font-size: 0.85rem; flex-shrink: 0; }
.cal-event-name {
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.cal-event-done { opacity: 0.55; text-decoration: line-through; }
.cal-event-check { border-left-color: var(--accent); }
.cal-event-scadenza { border-left-color: var(--red); }

/* ========== RESPONSIVE ========== */
@media (max-width: 780px) {
  .form-grid { grid-template-columns: 1fr; }
  .cal-day { min-height: 72px; }
  .section-header { align-items: flex-start; }
  header { padding: 12px 16px; }
  .view-inner { padding: 16px; }
  .utenze-table { min-width: 800px; }
}

@media (max-width: 640px) {
  /* iOS Safari zooms on focus when input font-size < 16px. Force 16px on form fields. */
  .form-field input,
  .form-field select,
  .form-field textarea {
    font-size: 16px;
  }
  /* Hide verbose user email on phones — still visible in profile / browser identity */
  .user-email { display: none; }
  .header-right { gap: 6px; }
  .lang-toggle, .admin-link, .logout-btn { padding: 5px 8px; font-size: 0.7rem; }
  /* Detail header: stack title + edit button cleanly */
  .detail-title-row { flex-wrap: wrap; gap: 10px; }
  .detail-title { flex: 1 0 calc(100% - 70px); }
  .detail-avatar { width: 44px; height: 44px; font-size: 1rem; }
  .detail-title h2 { font-size: 1.15rem; }
  /* Hide "Tipo"/"Stato" label, make filter buttons smaller */
  .filter-label { display: none; }
  .filter-row { gap: 6px; }
  .filter-btn { padding: 6px 10px; font-size: 0.75rem; }
  /* Sub-tabs: allow horizontal scroll if needed */
  .sub-tabs { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .sub-tabs .tab { white-space: nowrap; flex-shrink: 0; padding: 6px 14px; }
  /* Asset / account card chevron tighter */
  .asset-card, .account-card { padding: 14px 12px; gap: 12px; }
  .account-avatar, .asset-icon { width: 44px; height: 44px; font-size: 1.3rem; }
  .asset-icon-lg { width: 52px; height: 52px; font-size: 1.6rem; }
  /* Section header: title + button on the same row, button shrinks */
  .section-title { font-size: 1.2rem; }
  .section-subtitle { font-size: 1rem; }
  /* Asset section heading: reduce vertical space */
  .asset-section { margin-bottom: 18px; }
  /* Modal: full width, less padding */
  .modal-overlay { padding: 12px; }
  .modal { padding: 18px; }
  .modal-title { font-size: 1rem; margin-bottom: 14px; }
  /* Buttons: bigger tap target */
  .btn-primary, .btn-ghost, .btn-danger { padding: 9px 14px; }
  .icon-btn { padding: 8px 10px; font-size: 1rem; }
}

@media (max-width: 540px) {
  .cal-day-header { font-size: 0.6rem; padding: 4px 2px; }
  .cal-day { min-height: 62px; padding: 3px; }
  .cal-event-name { display: none; }
  .cal-event { padding: 2px 3px; }
  .cal-title { font-size: 1rem; min-width: 100px; }
  .cal-btn { padding: 5px 9px; font-size: 0.8rem; }
}

@media (max-width: 380px) {
  /* Tiny phones: collapse account/asset grids to a single column with full bleed */
  .accounts-grid, .assets-grid { grid-template-columns: 1fr; }
  .view-inner { padding: 12px; }
  header { padding: 10px 12px; }
  .logo-text { font-size: 1.1rem; }
  /* Section header stacks vertically (title above button) */
  .section-header { flex-direction: column; align-items: stretch; }
  .section-header .btn-primary { width: 100%; }
}
