/* ═══════════════════════════════════════════════════════════════════════════
   IT Manager — App CSS
   Colori primari iniettati dinamicamente via JS (CSS custom properties)
   ═══════════════════════════════════════════════════════════════════════════ */
:root {
  --primary:       #1e3a8a;
  --primary-dark:  #162d6e;
  --accent:        #3b82f6;
  --accent-hover:  #2563eb;
  --bg:            #f1f5f9;
  --surface:       #ffffff;
  --surface2:      #f8fafc;
  --border:        #e2e8f0;
  --text:          #0f172a;
  --text-2:        #475569;
  --text-3:        #94a3b8;
  --danger:        #dc2626;
  --warning:       #d97706;
  --success:       #16a34a;
  --sidebar-w:     260px;
  --topbar-h:      56px;
  --radius:        10px;
  --shadow:        0 2px 12px rgba(0,0,0,.08);
  --shadow-md:     0 4px 24px rgba(0,0,0,.12);
}

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
}

/* ── Utility ─────────────────────────────────────────────────────────────── */
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); }
.w-full { width: 100%; }
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.gap-2 { gap: 8px; }
.mt-4 { margin-top: 16px; }
.text-sm { font-size: 12.5px; }
.text-muted { color: var(--text-2); }
.bold { font-weight: 600; }

/* ── Alerts ──────────────────────────────────────────────────────────────── */
.alert { padding: 10px 14px; border-radius: var(--radius); font-size: 13px; margin: 10px 0; }
.alert-err  { background: rgba(220,38,38,.1);  color: #b91c1c; border: 1px solid rgba(220,38,38,.3); }
.alert-ok   { background: rgba(22,163,74,.1);  color: #15803d; border: 1px solid rgba(22,163,74,.3); }
.alert-warn { background: rgba(217,119,6,.1);  color: #b45309; border: 1px solid rgba(217,119,6,.3); }
.alert-info { background: rgba(59,130,246,.1); color: #1d4ed8; border: 1px solid rgba(59,130,246,.3); }

/* ── Badge ───────────────────────────────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 18px; height: 18px; padding: 0 5px;
  font-size: 11px; font-weight: 700; border-radius: 999px;
  background: var(--danger); color: #fff; vertical-align: top;
}

/* ── Buttons ─────────────────────────────────────────────────────────────── */
.btn-primary {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px 18px; border-radius: var(--radius);
  background: var(--accent); color: #fff; font-weight: 600; font-size: 14px;
  border: none; cursor: pointer; transition: background .15s, transform .1s;
}
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:active { transform: scale(.97); }
.btn-primary:disabled { opacity: .55; cursor: not-allowed; }

.btn-ghost {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 16px; border-radius: var(--radius);
  background: transparent; color: var(--text-2); font-size: 14px; font-weight: 500;
  border: 1px solid var(--border); cursor: pointer; transition: background .15s;
}
.btn-ghost:hover { background: var(--surface2); }

.btn-danger {
  background: var(--danger); color: #fff; border: none;
  padding: 8px 14px; border-radius: var(--radius);
  font-weight: 600; cursor: pointer; font-size: 13px;
}
.btn-sm { padding: 6px 12px; font-size: 12.5px; }

/* ── Form fields ─────────────────────────────────────────────────────────── */
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 12.5px; color: var(--text-2); font-weight: 600; margin-bottom: 5px; }
.field input, .field select, .field textarea {
  width: 100%; padding: 10px 13px; border: 1px solid var(--border);
  border-radius: var(--radius); font-size: 14px; background: var(--surface);
  color: var(--text); transition: border-color .15s;
  font-family: inherit;
}
.field input:focus, .field select:focus { outline: none; border-color: var(--accent); }
.input-eye { position: relative; }
.input-eye input { padding-right: 40px; }
.eye-btn { position: absolute; right: 10px; top: 50%; transform: translateY(-50%); background: none; border: none; cursor: pointer; font-size: 16px; }

/* ── Tables ──────────────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; border-radius: var(--radius); border: 1px solid var(--border); }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
thead th { background: var(--surface2); padding: 10px 14px; text-align: left; font-weight: 600; color: var(--text-2); border-bottom: 1px solid var(--border); white-space: nowrap; }
tbody tr { border-bottom: 1px solid var(--border); transition: background .1s; }
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: var(--surface2); }
tbody td { padding: 10px 14px; vertical-align: middle; }
.td-actions { display: flex; gap: 6px; }

/* ── Cards / KPI ─────────────────────────────────────────────────────────── */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; margin-bottom: 24px; }
.kpi-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px;
  box-shadow: var(--shadow); text-align: center;
}
.kpi-value { font-size: 32px; font-weight: 700; color: var(--primary); line-height: 1.1; }
.kpi-label { font-size: 12.5px; color: var(--text-2); margin-top: 4px; }

.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px;
  box-shadow: var(--shadow); margin-bottom: 20px;
}
.card-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.card-title { font-size: 16px; font-weight: 700; color: var(--text); }

/* ── Status chips ────────────────────────────────────────────────────────── */
.chip { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 11.5px; font-weight: 600; }
.chip-ok      { background: rgba(22,163,74,.12);  color: #15803d; }
.chip-danger  { background: rgba(220,38,38,.12);  color: #b91c1c; }
.chip-warning { background: rgba(217,119,6,.12);  color: #b45309; }
.chip-neutral { background: rgba(148,163,184,.15); color: var(--text-2); }

/* ── Progress bar ────────────────────────────────────────────────────────── */
.progress { height: 8px; background: var(--border); border-radius: 4px; overflow: hidden; margin-top: 4px; }
.progress-bar { height: 100%; border-radius: 4px; background: var(--accent); transition: width .4s ease; }
.progress-bar.warn { background: var(--warning); }
.progress-bar.danger { background: var(--danger); }

/* ── Login page ──────────────────────────────────────────────────────────── */
.page-full {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, var(--primary) 0%, #0f172a 100%);
}
.login-wrap { width: 100%; max-width: 420px; padding: 24px; }
.login-card {
  background: var(--surface); border-radius: 18px;
  padding: 36px 32px; box-shadow: var(--shadow-md);
}
.login-logo { max-width: 200px; width: 70%; margin: 0 auto 8px; display: block; }
.login-company { text-align: center; font-size: 12px; color: var(--text-3); margin: 0 0 20px; }
.login-title { font-size: 20px; font-weight: 700; margin: 0 0 20px; text-align: center; color: var(--text); }
.login-footer { margin-top: 20px; text-align: center; font-size: 12px; color: var(--text-3); display: flex; justify-content: center; gap: 16px; }
.link-sm { color: var(--accent); text-decoration: none; font-size: 12px; }
.link-sm:hover { text-decoration: underline; }

/* ── Sidebar ─────────────────────────────────────────────────────────────── */
#page-app { display: flex; height: 100vh; overflow: hidden; }
.sidebar {
  width: var(--sidebar-w); background: var(--primary);
  display: flex; flex-direction: column; flex-shrink: 0;
  overflow-y: auto; transition: transform .2s ease;
  z-index: 100;
}
.sidebar-brand {
  display: flex; align-items: center; justify-content: center;
  padding: 16px 12px; border-bottom: 1px solid rgba(255,255,255,.1);
}
.sb-logo { width: 160px; height: auto; object-fit: contain; filter: brightness(0) invert(1); }

.sidebar-nav { flex: 1; padding: 12px 0; }
.nav-section { padding: 12px 16px 4px; font-size: 10.5px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: rgba(255,255,255,.4); }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 16px; color: rgba(255,255,255,.7);
  text-decoration: none; font-size: 13.5px; font-weight: 500;
  border-radius: 0; transition: background .1s, color .1s;
  cursor: pointer;
}
.nav-item:hover { background: rgba(255,255,255,.08); color: #fff; }
.nav-item.active { background: rgba(255,255,255,.15); color: #fff; font-weight: 600; }
.nav-icon { font-size: 14px; width: 18px; text-align: center; }

.sidebar-user {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 16px; border-top: 1px solid rgba(255,255,255,.1);
}
.su-avatar {
  width: 34px; height: 34px; border-radius: 50%;
  background: rgba(255,255,255,.25); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 13px; flex-shrink: 0;
}
.su-info { flex: 1; overflow: hidden; }
.su-name { font-size: 13px; font-weight: 600; color: #fff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.su-role { font-size: 11px; color: rgba(255,255,255,.5); text-transform: capitalize; }
.su-logout { background: none; border: none; color: rgba(255,255,255,.5); font-size: 18px; cursor: pointer; padding: 4px; border-radius: 6px; flex-shrink: 0; }
.su-logout:hover { color: #fff; background: rgba(255,255,255,.1); }

/* ── Main area ───────────────────────────────────────────────────────────── */
.main-area { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.topbar {
  height: var(--topbar-h); background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 20px; flex-shrink: 0;
  box-shadow: 0 1px 4px rgba(0,0,0,.05);
}
.topbar-left, .topbar-right { display: flex; align-items: center; gap: 12px; }
.hamburger { background: none; border: none; font-size: 20px; cursor: pointer; color: var(--text-2); display: none; }
#tenant-select { border: 1px solid var(--border); border-radius: var(--radius); padding: 6px 10px; font-size: 13.5px; background: var(--surface2); }
.topbar-user { font-size: 13px; color: var(--text-2); font-weight: 500; }
.alert-bell { cursor: pointer; font-size: 18px; position: relative; }
.content { flex: 1; overflow-y: auto; padding: 24px; }

/* ── Page header ─────────────────────────────────────────────────────────── */
.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; }
.page-title { font-size: 22px; font-weight: 700; color: var(--text); margin: 0; }
.page-sub { font-size: 13.5px; color: var(--text-2); margin: 2px 0 0; }

/* ── Search bar ──────────────────────────────────────────────────────────── */
.search-bar { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; }
.search-bar input, .search-bar select { flex: 1; min-width: 160px; }

/* ── Modal ───────────────────────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.5);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000; padding: 20px; backdrop-filter: blur(3px);
}
.modal { background: var(--surface); border-radius: 16px; width: 100%; max-width: 480px; box-shadow: var(--shadow-md); }
.modal-lg { max-width: 680px; }
.modal-xl { max-width: 900px; }
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 18px 20px; border-bottom: 1px solid var(--border); }
.modal-header h3 { margin: 0; font-size: 17px; font-weight: 700; }
.modal-close { background: none; border: none; font-size: 18px; cursor: pointer; color: var(--text-2); }
.modal-body { padding: 20px; max-height: 60vh; overflow-y: auto; }
.modal-footer { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; }

/* ── Tabs ────────────────────────────────────────────────────────────────── */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; }
.tab-btn { background: none; border: none; padding: 9px 14px; font-size: 13.5px; font-weight: 600; color: var(--text-2); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); }
.tab-content { display: none; }

/* ── Form ────────────────────────────────────────────────────────────────── */
.form-row { margin-bottom: 14px; }
.form-label { display: block; font-size: 12.5px; font-weight: 600; color: var(--text-2); margin-bottom: 5px; text-transform: uppercase; letter-spacing: .4px; }
.form-input { width: 100%; padding: 9px 12px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg); color: var(--text-1); font-size: 13.5px; box-sizing: border-box; transition: border-color .15s; }
.form-input:focus { outline: none; border-color: var(--accent); }
select.form-input { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%2394a3b8' d='M1 1l5 5 5-5'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 10px center; padding-right: 28px; }

/* ── Modal overlay ───────────────────────────────────────────────────────── */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 1000; display: flex; align-items: center; justify-content: center; padding: 20px; }
.modal-overlay .modal { background: var(--surface); border-radius: 16px; width: 100%; max-width: 520px; box-shadow: var(--shadow-md); }
.modal-overlay .modal-header { display: flex; align-items: center; justify-content: space-between; padding: 18px 20px; border-bottom: 1px solid var(--border); }
.modal-overlay .modal-title { font-size: 16px; font-weight: 700; }
.modal-overlay .modal-close { background: none; border: none; font-size: 20px; cursor: pointer; color: var(--text-2); line-height: 1; }

/* ── Extra chips ─────────────────────────────────────────────────────────── */
.chip-ok  { background: rgba(22,163,74,.12);  color: #15803d; }
.chip-err { background: rgba(220,38,38,.12);  color: #b91c1c; }

/* ── Loader ──────────────────────────────────────────────────────────────── */
.loader { display: flex; align-items: center; justify-content: center; padding: 40px; color: var(--text-3); font-size: 13px; gap: 8px; }
.spinner { width: 20px; height: 20px; border: 3px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Responsive ──────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .sidebar { position: fixed; top: 0; left: 0; height: 100vh; transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .hamburger { display: block; }
  .kpi-grid { grid-template-columns: 1fr 1fr; }
  .content { padding: 16px; }
}
