/* ── Self-hosted fonts ─────────────────────────────────────────────
   Evita dipendenza da Google Fonts: CSP stretta, zero CDN esterne.
   File WOFF2 in ./fonts/ (vedi fonts/README.md per scaricarli).
   font-display: swap = testo visibile immediatamente con fallback. */
@font-face { font-family: 'Syne'; font-style: normal; font-weight: 400; font-display: swap; src: url('./fonts/Syne-400.woff2') format('woff2'); }
@font-face { font-family: 'Syne'; font-style: normal; font-weight: 600; font-display: swap; src: url('./fonts/Syne-600.woff2') format('woff2'); }
@font-face { font-family: 'Syne'; font-style: normal; font-weight: 700; font-display: swap; src: url('./fonts/Syne-700.woff2') format('woff2'); }
@font-face { font-family: 'Syne'; font-style: normal; font-weight: 800; font-display: swap; src: url('./fonts/Syne-800.woff2') format('woff2'); }
@font-face { font-family: 'JetBrains Mono'; font-style: normal; font-weight: 400; font-display: swap; src: url('./fonts/JetBrainsMono-400.woff2') format('woff2'); }
@font-face { font-family: 'JetBrains Mono'; font-style: normal; font-weight: 600; font-display: swap; src: url('./fonts/JetBrainsMono-600.woff2') format('woff2'); }
@font-face { font-family: 'JetBrains Mono'; font-style: normal; font-weight: 700; font-display: swap; src: url('./fonts/JetBrainsMono-700.woff2') format('woff2'); }

  /* ── Reset & Variables ─────────────────────────────────────────── */
  *, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

  :root {
    --bg:        #0a0c10;
    --bg2:       #111418;
    --bg3:       #1a1f27;
    --border:    #1e2530;
    --border2:   #2a3240;
    --text:      #e8ecf1;
    --text2:     #8b95a3;
    --text3:     #4a5568;
    --brand:     #F09000;
    --brand2:    #d07800;
    --ok:        #22c55e;
    --warn:      #eab308;
    --critical:  #ef4444;
    --info:      #3b82f6;
    --purple:    #8b5cf6;
    --font-mono: 'JetBrains Mono', monospace;
    --font-sans: 'Syne', sans-serif;
    --radius:    8px;
    --sidebar:   240px;
  }

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

  /* ── Layout ────────────────────────────────────────────────────── */
  .layout { display: flex; min-height: 100vh; }

  /* ── Sidebar ───────────────────────────────────────────────────── */
  .sidebar {
    width: var(--sidebar); min-width: var(--sidebar);
    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;
  }
  .sidebar-logo {
    padding: 20px 16px 16px;
    border-bottom: 1px solid var(--border);
  }
  .logo-text {
    font-size: 20px; font-weight: 800; color: var(--brand);
    letter-spacing: 2px;
  }
  .logo-sub {
    font-size: 9px; color: var(--text3); text-transform: uppercase;
    letter-spacing: 1.5px; margin-top: 2px;
    font-family: var(--font-mono);
  }
  .sidebar-nav { flex: 1; padding: 12px 0; overflow-y: auto; }
  .nav-section { font-size: 9px; color: var(--text3); text-transform: uppercase; letter-spacing: 1.5px; padding: 12px 16px 6px; font-family: var(--font-mono); }
  .nav-item {
    display: flex; align-items: center; gap: 10px;
    padding: 9px 16px; cursor: pointer;
    color: var(--text2); font-size: 13px; font-weight: 600;
    transition: all .15s; border-left: 3px solid transparent;
  }
  .nav-item:hover { background: var(--bg3); color: var(--text); }
  .nav-item.active { background: var(--bg3); color: var(--brand); border-left-color: var(--brand); }
  .nav-item .icon { font-size: 15px; width: 20px; text-align: center; }
  .sidebar-footer {
    padding: 12px 16px; border-top: 1px solid var(--border);
    font-size: 10px; color: var(--text3); font-family: var(--font-mono);
  }

  /* ── Main ──────────────────────────────────────────────────────── */
  .main { margin-left: var(--sidebar); flex: 1; display: flex; flex-direction: column; min-height: 100vh; }

  .topbar {
    background: var(--bg2); border-bottom: 1px solid var(--border);
    padding: 14px 24px; display: flex; align-items: center; justify-content: space-between;
    position: sticky; top: 0; z-index: 50;
  }
  .topbar-title { font-size: 16px; font-weight: 700; color: var(--text); }
  .topbar-right { display: flex; align-items: center; gap: 12px; }
  .btn {
    padding: 7px 14px; border-radius: var(--radius); border: none;
    font-family: var(--font-sans); font-size: 12px; font-weight: 700;
    cursor: pointer; transition: all .15s; display: inline-flex; align-items: center; gap: 6px;
  }
  .btn-brand { background: var(--brand); color: #000; }
  .btn-brand:hover { background: var(--brand2); }
  .btn-ghost { background: transparent; color: var(--text2); border: 1px solid var(--border2); }
  .btn-ghost:hover { background: var(--bg3); color: var(--text); }
  .btn-danger { background: #ef444420; color: var(--critical); border: 1px solid #ef444440; }
  .btn-danger:hover { background: #ef444430; }
  .btn-sm { padding: 4px 10px; font-size: 11px; }

  .content { padding: 24px; flex: 1; }

  /* ── Cards ─────────────────────────────────────────────────────── */
  .card {
    background: var(--bg2); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 20px;
  }
  .card-title { font-size: 11px; font-weight: 700; color: var(--text3); text-transform: uppercase; letter-spacing: 1px; margin-bottom: 16px; }

  /* ── Grid ──────────────────────────────────────────────────────── */
  .grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 24px; }
  .grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
  .grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }

  /* ── KPI ───────────────────────────────────────────────────────── */
  .kpi { background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 20px; }
  .kpi-value { font-size: 32px; font-weight: 800; font-family: var(--font-mono); line-height: 1; }
  .kpi-label { font-size: 10px; color: var(--text3); text-transform: uppercase; letter-spacing: 1px; margin-top: 6px; }
  .kpi-sub { font-size: 11px; color: var(--text2); margin-top: 4px; }

  /* ── Badge ─────────────────────────────────────────────────────── */
  .badge {
    display: inline-flex; align-items: center; gap: 4px;
    padding: 2px 8px; border-radius: 20px; font-size: 10px; font-weight: 700;
    font-family: var(--font-mono); text-transform: uppercase; letter-spacing: .5px;
  }
  .badge-ok      { background: #22c55e20; color: var(--ok); }
  .badge-warn    { background: #eab30820; color: var(--warn); }
  .badge-critical{ background: #ef444420; color: var(--critical); }
  .badge-info    { background: #3b82f620; color: var(--info); }
  .badge-brand   { background: #F0900020; color: var(--brand); }
  .badge-purple  { background: #8b5cf620; color: var(--purple); }
  .badge-gray    { background: #ffffff10; color: var(--text3); }

  /* ── Table ─────────────────────────────────────────────────────── */
  .table-wrap { overflow-x: auto; }
  table { width: 100%; border-collapse: collapse; font-size: 13px; }
  th { text-align: left; padding: 8px 12px; font-size: 10px; font-weight: 700; color: var(--text3); text-transform: uppercase; letter-spacing: .8px; border-bottom: 1px solid var(--border); }
  td { padding: 10px 12px; border-bottom: 1px solid var(--border)22; color: var(--text2); vertical-align: middle; }
  tr:last-child td { border-bottom: none; }
  tr:hover td { background: var(--bg3)88; }
  .mono { font-family: var(--font-mono); font-size: 11px; }

  /* ── Status dot ────────────────────────────────────────────────── */
  .dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
  .dot-ok       { background: var(--ok); box-shadow: 0 0 6px var(--ok); }
  .dot-warn     { background: var(--warn); box-shadow: 0 0 6px var(--warn); }
  .dot-critical { background: var(--critical); box-shadow: 0 0 6px var(--critical); }
  .dot-gray     { background: var(--text3); }

  /* ── Page sections ─────────────────────────────────────────────── */
  .page { display: none; }
  .page.active { display: block; }

  /* ── Modal ─────────────────────────────────────────────────────── */
  .modal-overlay {
    position: fixed; inset: 0; background: rgba(0,0,0,.7);
    backdrop-filter: blur(4px); z-index: 1000;
    display: none; align-items: center; justify-content: center; padding: 20px;
  }
  .modal-overlay.open { display: flex; }
  .modal {
    background: var(--bg2); border: 1px solid var(--border2);
    border-radius: 12px; width: 100%; max-width: 560px;
    max-height: 90vh; overflow-y: auto;
    box-shadow: 0 24px 64px rgba(0,0,0,.6);
  }
  .modal-header {
    padding: 20px 24px 16px; border-bottom: 1px solid var(--border);
    display: flex; align-items: center; justify-content: space-between;
  }
  .modal-title { font-size: 16px; font-weight: 700; }
  .modal-body { padding: 20px 24px; }
  .modal-footer { padding: 16px 24px; border-top: 1px solid var(--border); display: flex; gap: 8px; justify-content: flex-end; }
  .modal-close { background: none; border: none; color: var(--text3); cursor: pointer; font-size: 18px; }
  .modal-close:hover { color: var(--text); }

  /* ── Form ──────────────────────────────────────────────────────── */
  .form-group { margin-bottom: 16px; }
  .form-label { display: block; font-size: 11px; font-weight: 700; color: var(--text2); text-transform: uppercase; letter-spacing: .8px; margin-bottom: 6px; }
  .form-input, .form-textarea, .form-select {
    width: 100%; background: var(--bg3); border: 1px solid var(--border2);
    border-radius: var(--radius); padding: 9px 12px;
    color: var(--text); font-family: var(--font-sans); font-size: 13px;
    outline: none; transition: border-color .15s;
  }
  .form-input:focus, .form-textarea:focus, .form-select:focus { border-color: var(--brand); }
  .form-textarea { resize: vertical; min-height: 80px; font-family: var(--font-mono); font-size: 12px; }
  .form-hint { font-size: 11px; color: var(--text3); margin-top: 4px; }

  /* ── Alert ─────────────────────────────────────────────────────── */
  .alert { padding: 12px 16px; border-radius: var(--radius); font-size: 13px; margin-bottom: 16px; }
  .alert-ok       { background: #22c55e15; border: 1px solid #22c55e30; color: var(--ok); }
  .alert-critical { background: #ef444415; border: 1px solid #ef444430; color: var(--critical); }
  .alert-warn     { background: #eab30815; border: 1px solid #eab30830; color: var(--warn); }

  /* ── Changelog list ────────────────────────────────────────────── */
  .changelog-list { list-style: none; }
  .changelog-list li { padding: 5px 0; color: var(--text2); font-size: 13px; display: flex; gap: 8px; }
  .changelog-list li::before { content: '▸'; color: var(--brand); flex-shrink: 0; }

  /* ── Module tags ───────────────────────────────────────────────── */
  .module-tags { display: flex; flex-wrap: wrap; gap: 4px; }
  .module-tag { padding: 2px 8px; background: var(--bg3); border: 1px solid var(--border2); border-radius: 4px; font-size: 10px; font-family: var(--font-mono); color: var(--text2); }

  /* ── Loader ────────────────────────────────────────────────────── */
  .loader { text-align: center; padding: 40px; color: var(--text3); font-size: 13px; }
  .spinner { display: inline-block; width: 20px; height: 20px; border: 2px solid var(--border2); border-top-color: var(--brand); border-radius: 50%; animation: spin .8s linear infinite; margin-right: 8px; vertical-align: middle; }
  @keyframes spin { to { transform: rotate(360deg); } }

  /* ── Toast ─────────────────────────────────────────────────────── */
  #toast-container { position: fixed; bottom: 20px; right: 20px; z-index: 9999; display: flex; flex-direction: column; gap: 8px; }
  .toast {
    background: var(--bg2); border: 1px solid var(--border2);
    border-radius: var(--radius); padding: 12px 16px;
    font-size: 13px; min-width: 260px; max-width: 360px;
    box-shadow: 0 8px 24px rgba(0,0,0,.4);
    animation: slideIn .2s ease; display: flex; align-items: center; gap: 10px;
  }
  .toast-ok       { border-left: 3px solid var(--ok); }
  .toast-critical { border-left: 3px solid var(--critical); }
  .toast-warn     { border-left: 3px solid var(--warn); }
  @keyframes slideIn { from { transform: translateX(20px); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

  /* ── Login ─────────────────────────────────────────────────────── */
  #login-screen {
    position: fixed; inset: 0; background: var(--bg);
    display: flex; align-items: center; justify-content: center;
    z-index: 9000;
  }
  .login-box {
    background: var(--bg2); border: 1px solid var(--border);
    border-radius: 12px; padding: 40px; width: 100%; max-width: 380px;
    text-align: center;
  }
  .login-logo { font-size: 28px; font-weight: 800; color: var(--brand); letter-spacing: 3px; margin-bottom: 4px; }
  .login-sub { font-size: 11px; color: var(--text3); text-transform: uppercase; letter-spacing: 2px; margin-bottom: 32px; font-family: var(--font-mono); }
  .login-error { display: none; }

  /* ── Version card ──────────────────────────────────────────────── */
  .version-card {
    background: var(--bg2); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 16px 20px; margin-bottom: 12px;
    display: flex; align-items: center; gap: 16px;
  }
  .version-num { font-size: 18px; font-weight: 800; font-family: var(--font-mono); color: var(--text); min-width: 80px; }
  .version-info { flex: 1; }
  .version-date { font-size: 11px; color: var(--text3); font-family: var(--font-mono); }
  .version-actions { display: flex; gap: 8px; }

  /* ── Install card ──────────────────────────────────────────────── */
  .install-row { cursor: pointer; }
  .install-row:hover td { background: var(--bg3) !important; }

  /* ── Progress bar ──────────────────────────────────────────────── */
  .prog-bar { height: 4px; background: var(--border); border-radius: 2px; overflow: hidden; margin-top: 6px; }
  .prog-fill { height: 100%; border-radius: 2px; background: var(--brand); transition: width .3s; }

  /* ── Detail panel ──────────────────────────────────────────────── */
  .detail-header { display: flex; align-items: center; gap: 12px; margin-bottom: 24px; }
  .back-btn { background: none; border: none; color: var(--text3); cursor: pointer; font-size: 20px; }
  .back-btn:hover { color: var(--text); }

  /* ── Stats row ─────────────────────────────────────────────────── */
  .stats-row { display: flex; gap: 20px; flex-wrap: wrap; margin-top: 8px; }
  .stat { font-size: 12px; color: var(--text2); font-family: var(--font-mono); }
  .stat span { color: var(--text); font-weight: 700; }
