/* ============================================================
   KemComm Assistenza — Design System
   Palette: Ardesia scura + Arancio tecnico + Bianco caldo
   ============================================================ */

:root {
  --bg:          #0f1117;
  --bg2:         #171b26;
  --bg3:         #1e2333;
  --border:      #2a2f45;
  --border-light:#353c56;
  --text:        #e8eaf0;
  --text-muted:  #7c8299;
  --text-dim:    #4a5068;
  --accent:      #f47b20;
  --accent-light:#ff9a4c;
  --accent-dark: #c85f10;
  --green:       #2ecc71;
  --red:         #e74c3c;
  --yellow:      #f1c40f;
  --blue:        #3498db;
  --font-body:   'Sora', sans-serif;
  --font-mono:   'DM Mono', monospace;
  --radius:      8px;
  --radius-lg:   14px;
  --shadow:      0 2px 12px rgba(0,0,0,.45);
  --shadow-lg:   0 8px 32px rgba(0,0,0,.6);
  --sidebar-w:   240px;
  --transition:  .18s ease;
}

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

html { font-size: 15px; scroll-behavior: smooth; }

body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  display: flex;
  min-height: 100vh;
  line-height: 1.6;
}

/* ============================================================
   SIDEBAR
   ============================================================ */
.sidebar {
  width: var(--sidebar-w);
  background: var(--bg2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
  overflow-y: auto;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 20px 18px;
  border-bottom: 1px solid var(--border);
}

.brand-icon {
  width: 38px; height: 38px;
  background: var(--accent);
  border-radius: 10px;
  display: grid; place-items: center;
  font-family: var(--font-mono);
  font-weight: 500;
  font-size: .85rem;
  color: #fff;
  flex-shrink: 0;
}

.brand-text { display: flex; flex-direction: column; }
.brand-name { font-weight: 700; font-size: .95rem; letter-spacing: -.01em; }
.brand-sub  { font-size: .72rem; color: var(--text-muted); font-family: var(--font-mono); }

.nav-items {
  list-style: none;
  padding: 12px 10px;
  flex: 1;
}

.nav-divider {
  height: 1px;
  background: var(--border);
  margin: 8px 8px;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: var(--radius);
  color: var(--text-muted);
  text-decoration: none;
  font-size: .875rem;
  font-weight: 500;
  transition: all var(--transition);
  white-space: nowrap;
}

.nav-link svg { width: 17px; height: 17px; flex-shrink: 0; }
.nav-link:hover { color: var(--text); background: var(--bg3); }
.nav-link.active { color: var(--accent); background: rgba(244,123,32,.12); }

.sidebar-footer {
  padding: 14px 16px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
}

.user-info { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; }

.user-avatar {
  width: 32px; height: 32px;
  background: var(--bg3);
  border: 1px solid var(--border-light);
  border-radius: 50%;
  display: grid; place-items: center;
  font-family: var(--font-mono);
  font-size: .75rem;
  flex-shrink: 0;
}

.user-meta { display: flex; flex-direction: column; min-width: 0; }
.user-name { font-size: .8rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role { font-size: .7rem; color: var(--text-muted); font-family: var(--font-mono); }

.btn-logout {
  color: var(--text-dim);
  transition: color var(--transition);
  flex-shrink: 0;
}
.btn-logout:hover { color: var(--red); }
.btn-logout svg { width: 18px; height: 18px; display: block; }

/* ============================================================
   MAIN CONTENT
   ============================================================ */
.main-content {
  margin-left: var(--sidebar-w);
  flex: 1;
  min-height: 100vh;
}

.page-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 32px 36px;
}

.page-header {
  display: flex;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 32px;
  flex-wrap: wrap;
}

.page-title {
  font-size: 1.6rem;
  font-weight: 700;
  letter-spacing: -.03em;
  flex: 1;
}

.page-subtitle {
  color: var(--text-muted);
  font-size: .9rem;
  margin-top: 4px;
}

.page-actions { display: flex; gap: 10px; align-items: center; }

/* ============================================================
   CARDS
   ============================================================ */
.card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
}

.card-title {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 20px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 20px; }

/* ============================================================
   STAT CARDS
   ============================================================ */
.stat-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px 24px;
  position: relative;
  overflow: hidden;
}

.stat-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: var(--accent);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}

.stat-label {
  font-size: .75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .08em;
  font-family: var(--font-mono);
  margin-bottom: 8px;
}

.stat-value {
  font-size: 2.2rem;
  font-weight: 700;
  font-family: var(--font-mono);
  letter-spacing: -.04em;
  line-height: 1;
}

.stat-sub {
  font-size: .78rem;
  color: var(--text-muted);
  margin-top: 6px;
}

/* ============================================================
   ORE GAUGE
   ============================================================ */
.ore-gauge {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px 24px;
}

.gauge-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.gauge-label { font-weight: 600; font-size: .9rem; }

.gauge-numbers {
  font-family: var(--font-mono);
  font-size: .85rem;
  color: var(--text-muted);
}

.gauge-numbers strong {
  color: var(--text);
  font-size: 1.1rem;
}

.gauge-track {
  height: 10px;
  background: var(--bg3);
  border-radius: 99px;
  overflow: hidden;
  margin-bottom: 8px;
}

.gauge-fill {
  height: 100%;
  border-radius: 99px;
  background: var(--accent);
  transition: width .5s ease;
}

.gauge-fill.warn  { background: var(--yellow); }
.gauge-fill.danger { background: var(--red); }

.gauge-meta {
  display: flex;
  justify-content: space-between;
  font-size: .75rem;
  color: var(--text-muted);
  font-family: var(--font-mono);
}

/* ============================================================
   TABLE
   ============================================================ */
.table-wrap { overflow-x: auto; border-radius: var(--radius-lg); }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: .875rem;
}

thead th {
  background: var(--bg3);
  color: var(--text-muted);
  font-size: .72rem;
  font-family: var(--font-mono);
  text-transform: uppercase;
  letter-spacing: .08em;
  padding: 10px 14px;
  text-align: left;
  white-space: nowrap;
}

tbody tr {
  border-bottom: 1px solid var(--border);
  transition: background var(--transition);
}

tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: rgba(255,255,255,.02); }

tbody td {
  padding: 12px 14px;
  vertical-align: middle;
}

.td-mono { font-family: var(--font-mono); }
.td-dim  { color: var(--text-muted); font-size: .82rem; }

/* ============================================================
   BADGES
   ============================================================ */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: 99px;
  font-size: .72rem;
  font-family: var(--font-mono);
  font-weight: 500;
  white-space: nowrap;
}

.badge-ticket     { background: rgba(52,152,219,.15);  color: #5dade2; }
.badge-telefonata { background: rgba(46,204,113,.15);  color: #58d68d; }
.badge-sopralluogo{ background: rgba(155,89,182,.15);  color: #a569bd; }
.badge-altro      { background: rgba(127,140,141,.15); color: #95a5a6; }
.badge-attivo     { background: rgba(46,204,113,.15);  color: #2ecc71; }
.badge-scaduto    { background: rgba(231,76,60,.15);   color: #e74c3c; }
.badge-sospeso    { background: rgba(241,196,15,.15);  color: #f1c40f; }

/* ============================================================
   FORMS
   ============================================================ */
.form-group { margin-bottom: 18px; }

label {
  display: block;
  font-size: .8rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .06em;
  margin-bottom: 6px;
  font-family: var(--font-mono);
}

input, select, textarea {
  width: 100%;
  background: var(--bg3);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius);
  padding: 10px 14px;
  font-family: var(--font-body);
  font-size: .9rem;
  transition: border-color var(--transition);
  outline: none;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
}

select option { background: var(--bg2); }
textarea { resize: vertical; min-height: 90px; }

input[type="range"] {
  padding: 0;
  accent-color: var(--accent);
  cursor: pointer;
}

/* ============================================================
   BUTTONS
   ============================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 10px 18px;
  border-radius: var(--radius);
  font-family: var(--font-body);
  font-size: .875rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  text-decoration: none;
  transition: all var(--transition);
  white-space: nowrap;
}

.btn svg { width: 16px; height: 16px; }

.btn-primary {
  background: var(--accent);
  color: #fff;
}
.btn-primary:hover { background: var(--accent-light); }

.btn-secondary {
  background: var(--bg3);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-secondary:hover { border-color: var(--border-light); }

.btn-danger { background: rgba(231,76,60,.15); color: var(--red); border: 1px solid rgba(231,76,60,.3); }
.btn-danger:hover { background: rgba(231,76,60,.25); }

.btn-sm { padding: 6px 12px; font-size: .8rem; }

/* ============================================================
   ALERTS
   ============================================================ */
.alert {
  padding: 13px 18px;
  border-radius: var(--radius);
  margin-bottom: 20px;
  font-size: .9rem;
  border-left: 4px solid;
}

.alert-success { background: rgba(46,204,113,.1); border-color: var(--green); }
.alert-error   { background: rgba(231,76,60,.1);  border-color: var(--red); }
.alert-info    { background: rgba(52,152,219,.1);  border-color: var(--blue); }
.alert-warning { background: rgba(241,196,15,.1);  border-color: var(--yellow); }

/* ============================================================
   LOGIN PAGE
   ============================================================ */
body.page-login {
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}

.login-box {
  width: 100%;
  max-width: 400px;
  padding: 20px;
}

.login-logo {
  text-align: center;
  margin-bottom: 32px;
}

.login-logo .brand-icon {
  width: 52px; height: 52px;
  font-size: 1.1rem;
  margin: 0 auto 12px;
}

.login-logo h1 { font-size: 1.4rem; font-weight: 700; }
.login-logo p  { color: var(--text-muted); font-size: .85rem; margin-top: 4px; }

.login-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 32px;
}

/* ============================================================
   MISC
   ============================================================ */
.divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 24px 0;
}

.text-muted { color: var(--text-muted); }
.text-accent { color: var(--accent); }
.text-mono { font-family: var(--font-mono); }
.text-sm { font-size: .85rem; }

.flex { display: flex; }
.flex-between { display: flex; align-items: center; justify-content: space-between; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.mb-4 { margin-bottom: 16px; }
.mb-6 { margin-bottom: 24px; }
.mt-4 { margin-top: 16px; }

.spinner {
  width: 20px; height: 20px;
  border: 2px solid var(--border-light);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  display: inline-block;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* Responsive */
@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .main-content { margin-left: 0; }
  .grid-4 { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 600px) {
  .page-inner { padding: 20px 16px; }
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
}
