/* =====================================================
   CMS Closer Elisir Studio - Stile globale
   ===================================================== */

:root {
  --bg: #FAFAF7;
  --surface: #FFFFFF;
  --surface-2: #F4F2EC;
  --text: #1A1A1A;
  --text-muted: #6B6B6B;
  --text-faint: #9A9A95;
  --border: #E5E3DC;
  --border-strong: #C9C6BD;
  --accent: #C8553D;
  --accent-dark: #A33F2A;
  --success: #2D6A4F;
  --success-bg: #E8F3EC;
  --warning: #C7903F;
  --warning-bg: #FDF4E2;
  --danger: #B23A48;
  --danger-bg: #FBEAEA;
  --radius: 6px;
  --radius-lg: 10px;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.04);
  --shadow: 0 4px 16px rgba(0,0,0,0.06);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text); font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif; font-size: 14px; line-height: 1.5; }

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-dark); }

/* ========== Login page ========== */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; }
.login-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 40px; width: 100%; max-width: 400px; box-shadow: var(--shadow); }
.login-card h1 { font-size: 22px; margin: 0 0 4px; letter-spacing: -0.01em; }
.login-card .brand { color: var(--accent); font-size: 13px; font-weight: 500; letter-spacing: 0.08em; text-transform: uppercase; margin-bottom: 28px; }

/* ========== Layout app ========== */
.app { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.sidebar { background: var(--surface); border-right: 1px solid var(--border); padding: 24px 0; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.sidebar .brand { padding: 0 24px 24px; border-bottom: 1px solid var(--border); margin-bottom: 16px; }
.sidebar .brand-name { font-weight: 600; font-size: 15px; letter-spacing: -0.01em; }
.sidebar .brand-sub { font-size: 11px; color: var(--accent); letter-spacing: 0.08em; text-transform: uppercase; margin-top: 2px; }
.sidebar nav a { display: block; padding: 10px 24px; color: var(--text-muted); font-weight: 500; font-size: 14px; border-left: 3px solid transparent; }
.sidebar nav a:hover { background: var(--surface-2); color: var(--text); }
.sidebar nav a.active { color: var(--text); border-left-color: var(--accent); background: var(--surface-2); }
.sidebar .user-box { position: absolute; bottom: 0; left: 0; right: 0; padding: 16px 24px; border-top: 1px solid var(--border); background: var(--surface); }
.sidebar .user-name { font-weight: 500; font-size: 13px; }
.sidebar .user-role { font-size: 11px; color: var(--text-muted); margin-top: 2px; }
.sidebar .logout-btn { margin-top: 8px; font-size: 12px; color: var(--accent); background: none; border: none; padding: 0; cursor: pointer; }

.main { padding: 32px 40px; max-width: 1400px; }
.main h1 { font-size: 24px; font-weight: 600; letter-spacing: -0.01em; margin: 0 0 4px; }
.main .page-sub { color: var(--text-muted); margin-bottom: 28px; }

/* ========== Form ========== */
label { display: block; font-size: 12px; font-weight: 500; color: var(--text-muted); margin: 14px 0 6px; text-transform: uppercase; letter-spacing: 0.04em; }
input, select, textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--border-strong); border-radius: var(--radius);
  font-size: 14px; font-family: inherit; background: var(--surface); color: var(--text);
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(200,85,61,0.12); }
textarea { resize: vertical; min-height: 80px; }

button { cursor: pointer; font-family: inherit; }
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 9px 16px; border-radius: var(--radius); font-size: 13px; font-weight: 500; border: 1px solid var(--border-strong); background: var(--surface); color: var(--text); transition: all 0.12s; }
.btn:hover { border-color: var(--text); }
.btn-primary { background: var(--text); color: var(--surface); border-color: var(--text); }
.btn-primary:hover { background: var(--accent); border-color: var(--accent); }
.btn-accent { background: var(--accent); color: white; border-color: var(--accent); }
.btn-accent:hover { background: var(--accent-dark); border-color: var(--accent-dark); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--text-muted); }
.btn-ghost:hover { color: var(--danger); }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-full { width: 100%; justify-content: center; padding: 11px; }

/* ========== Card e griglie ========== */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 20px; box-shadow: var(--shadow-sm); }
.card h2 { font-size: 16px; font-weight: 600; margin: 0 0 16px; letter-spacing: -0.005em; }
.card h3 { font-size: 14px; font-weight: 500; color: var(--text-muted); margin: 0 0 8px; text-transform: uppercase; letter-spacing: 0.04em; }

.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.grid-stat { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }

.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 18px; }
.stat-label { font-size: 11px; font-weight: 500; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.06em; }
.stat-value { font-size: 26px; font-weight: 600; margin-top: 6px; letter-spacing: -0.02em; }
.stat-sub { font-size: 12px; color: var(--text-faint); margin-top: 4px; }
.stat-accent { color: var(--accent); }
.stat-success { color: var(--success); }
.stat-warning { color: var(--warning); }

/* ========== Tabella ========== */
.table-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); overflow: hidden; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; padding: 11px 14px; font-weight: 500; font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; background: var(--surface-2); border-bottom: 1px solid var(--border); white-space: nowrap; }
td { padding: 12px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--surface-2); }
.table-empty { padding: 40px; text-align: center; color: var(--text-faint); font-size: 13px; }

/* ========== Badge stato ========== */
.badge { display: inline-block; padding: 3px 9px; border-radius: 999px; font-size: 11px; font-weight: 500; text-transform: uppercase; letter-spacing: 0.04em; }
.badge-da_chiamare { background: #ECEAE2; color: #4A4842; }
.badge-contattato { background: #E2EBF3; color: #1F4868; }
.badge-appuntamento { background: var(--warning-bg); color: var(--warning); }
.badge-chiuso { background: var(--success-bg); color: var(--success); }
.badge-perso { background: var(--danger-bg); color: var(--danger); }
.badge-attivo { background: var(--success-bg); color: var(--success); }
.badge-prova { background: var(--warning-bg); color: var(--warning); }
.badge-sospeso { background: var(--danger-bg); color: var(--danger); }
.badge-soglia { background: var(--accent); color: white; }

/* ========== Progress bar ========== */
.progress { background: var(--surface-2); border-radius: 999px; height: 10px; overflow: hidden; margin-top: 8px; }
.progress-bar { height: 100%; background: var(--accent); border-radius: 999px; transition: width 0.4s; }
.progress-bar.success { background: var(--success); }

/* ========== Toolbar ========== */
.toolbar { display: flex; gap: 12px; align-items: center; margin-bottom: 18px; flex-wrap: wrap; }
.toolbar select, .toolbar input { width: auto; min-width: 160px; }
.toolbar .spacer { flex: 1; }

/* ========== Modal ========== */
.modal-overlay { position: fixed; inset: 0; background: rgba(20,20,20,0.4); display: flex; align-items: center; justify-content: center; padding: 24px; z-index: 100; }
.modal { background: var(--surface); border-radius: var(--radius-lg); padding: 28px; max-width: 520px; width: 100%; max-height: 90vh; overflow-y: auto; box-shadow: 0 24px 64px rgba(0,0,0,0.18); }
.modal h2 { margin: 0 0 8px; font-size: 18px; font-weight: 600; letter-spacing: -0.01em; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 24px; }

/* ========== Alert ========== */
.alert { padding: 12px 16px; border-radius: var(--radius); font-size: 13px; margin-bottom: 16px; }
.alert-err { background: var(--danger-bg); color: var(--danger); }
.alert-ok { background: var(--success-bg); color: var(--success); }
.alert-warn { background: var(--warning-bg); color: #6E4F12; }

/* ========== Utility ========== */
.hidden { display: none !important; }
.muted { color: var(--text-muted); }
.right { text-align: right; }
.mono { font-family: "SF Mono", "Monaco", "Menlo", monospace; }
.nowrap { white-space: nowrap; }
.flex { display: flex; align-items: center; gap: 8px; }
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }
.mb-16 { margin-bottom: 16px; }
.actions-cell { display: flex; gap: 6px; justify-content: flex-end; }

/* ========== Responsive ========== */
@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; padding: 16px 0; }
  .sidebar .user-box { position: static; }
  .main { padding: 20px; }
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
}
