/* SWS Tracker v3.1 — CSS base */
:root {
  --navy:      #1B4F72; --navy-dark: #0D2B45; --navy-light: #2471A3;
  --teal:      #117A65; --teal-light: #1ABC9C; --teal-bg: #E8F8F5;
  --bg:        #F4F6F8; --card:       #FFFFFF; --border: #D5D8DC;
  --text:      #1C2833; --muted:      #7F8C8D; --danger: #C0392B;
  --warn:      #D97706; --success:    #1A7A1A;
  --sidebar-w: 220px;
  --font: 'Inter', system-ui, -apple-system, sans-serif;
}

/* ---- Dark Mode ---- */
body.dark {
  --bg:     #0F1923;
  --card:   #1A2636;
  --border: #2C3E50;
  --text:   #E8EDF2;
  --muted:  #7F8C9A;
  --navy-dark: #071420;
  color-scheme: dark;
}
body.dark input[type=text], body.dark input[type=email],
body.dark input[type=password], body.dark input[type=time],
body.dark input[type=number], body.dark input[type=url],
body.dark select, body.dark textarea {
  background: #162130; color: var(--text); border-color: var(--border);
}
body.dark thead tr, body.dark th { background: #162130; }
body.dark tr:nth-child(even) td { background: #1E2D3D; }
body.dark tr:hover td { background: #223347 !important; }
body.dark .login-card { background: var(--card); }
body.dark .topbar { background: var(--card); }
body.dark .modal-box, body.dark .modal { background: var(--card); }
body.dark .raw-pre { background: #162130; }
body.dark .log-line:hover { background: #1E2D3D; }
body.dark .info-note { background: #162130; border-color: var(--border); color: var(--text); }
body.dark .admin-bar { background: #2C3E50; border-color: var(--border); }

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: var(--font); background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.5; transition: background .2s, color .2s; }

/* ---- Layout ---- */
.app { display: flex; height: 100vh; overflow: hidden; }
.sidebar { width: var(--sidebar-w); background: var(--navy-dark); color: #eee; display: flex; flex-direction: column; flex-shrink: 0; }
.main { flex: 1; min-width: 0; overflow-x: hidden; overflow-y: auto; display: flex; flex-direction: column; }

/* ---- Sidebar ---- */
.sidebar-logo { display: flex; align-items: center; gap: 10px; padding: 18px 16px 14px; border-bottom: 1px solid #1e3a52; }
.sidebar-logo svg { flex-shrink: 0; }
.sidebar-logo-text { font-size: 13px; font-weight: 700; color: #f0f0f0; line-height: 1.2; }
.sidebar-logo-sub { font-size: 10px; color: rgba(255,255,255,.4); }
nav a { display: flex; align-items: center; gap: 10px; padding: 10px 16px; color: rgba(255,255,255,.75); text-decoration: none; font-size: 13px; font-weight: 500; transition: background .15s, color .15s; border-radius: 0; }
nav a:hover { background: rgba(255,255,255,.08); color: #fff; }
nav a.active { background: rgba(255,255,255,.12); color: var(--teal-light); border-left: 3px solid var(--teal-light); }
nav a svg { width: 15px; height: 15px; flex-shrink: 0; }
nav .sidebar-nav-divider { height: 1px; margin: 10px 16px; background: rgba(255,255,255,.12); flex-shrink: 0; }
/* Menu occupa lo spazio verticale; log + versione restano in basso */
#sidebar-nav.sidebar-nav-scroll {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
}
#hb-log-panel {
  flex-shrink: 0;
  max-height: 180px;
  min-height: 48px;
  overflow-y: auto;
  background: #050e15;
  border-top: 1px solid rgba(255,255,255,.08);
  padding: 4px 8px;
}
.sidebar-footer { padding: 10px 14px; font-size: 10px; color: rgba(255,255,255,.3); border-top: 1px solid #1e3a52; flex-shrink: 0; }
.sidebar-section-label { padding: 8px 16px 4px; font-size: 10px; text-transform: uppercase; color: rgba(255,255,255,.3); letter-spacing: 1px; margin-top: 8px; }

/* Sidebar "Soon!" links (user area) */
nav a.sidebar-link--soon { color: rgba(255,255,255,.55) !important; }
nav a.sidebar-link--soon svg { opacity: .75; }
nav a.sidebar-link--soon:hover { color: rgba(255,255,255,.7) !important; }
.sidebar-soon-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-left: 6px;
  padding: 1px 6px;
  border-radius: 999px;
  font-size: 9px;
  font-weight: 800;
  letter-spacing: .4px;
  text-transform: uppercase;
  background: rgba(255,255,255,.10);
  color: rgba(255,255,255,.70);
}

/* ---- Topbar ---- */
.topbar { display: flex; align-items: center; justify-content: space-between; padding: 14px 24px; background: var(--card); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 10; }
.topbar h1 { font-size: 16px; font-weight: 700; color: var(--text); }
.topbar-sub { font-size: 12px; color: var(--muted); margin-top: 1px; }
.topbar-actions { display: flex; gap: 8px; align-items: center; }

/* ---- Buttons ---- */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 7px 14px; border-radius: 6px; font-size: 13px; font-weight: 500; cursor: pointer; border: none; transition: background .15s, opacity .15s; text-decoration: none; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary  { background: var(--navy); color: #fff; }
.btn-primary:hover  { background: var(--navy-light); }
.btn-success  { background: var(--teal); color: #fff; }
.btn-success:hover  { background: var(--teal-light); }
.btn-danger   { background: var(--danger); color: #fff; }
.btn-outline  { background: transparent; border: 1px solid var(--border); color: var(--text); }
.btn-outline:hover  { background: var(--bg); }
.btn-icon     { padding: 5px; background: transparent; border: none; cursor: pointer; color: var(--muted); border-radius: 4px; }
.btn-icon:hover { background: var(--bg); color: var(--text); }
.btn-sm       { padding: 4px 10px; font-size: 12px; }

/* ---- Cards / KPI ---- */
.content-area { padding: 24px; flex: 1; max-width: 1600px; }
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px,1fr)); gap: 14px; margin-bottom: 20px; }
.kpi-card { background: var(--card); border: 1px solid var(--border); border-radius: 8px; padding: 14px 16px; display: flex; align-items: center; gap: 12px; }
.kpi-icon { width: 36px; height: 36px; border-radius: 8px; background: var(--bg); display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.kpi-icon svg { width: 18px; height: 18px; }
.kpi-value { font-size: 22px; font-weight: 700; color: var(--text); line-height: 1; }
.kpi-label { font-size: 11px; color: var(--muted); margin-top: 2px; }

/* ---- Info bar ---- */
.info-bar { background: var(--card); border: 1px solid var(--border); border-radius: 8px; padding: 10px 16px; display: flex; align-items: center; gap: 12px; font-size: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.info-bar svg { width: 14px; height: 14px; flex-shrink: 0; color: var(--navy-light); }
.info-bar .sep { color: var(--border); }

/* ---- Table ---- */
.table-wrap { background: var(--card); border: 1px solid var(--border); border-radius: 8px; overflow: hidden; margin-bottom: 24px; }
.table-wrap .overflow-x { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
thead tr { background: #F0F3F6; }
th { padding: 10px 12px; text-align: left; font-size: 11px; font-weight: 600; color: var(--muted); white-space: nowrap; position: sticky; top: 0; background: #F0F3F6; border-bottom: 2px solid var(--border); }
td { padding: 9px 12px; border-bottom: 1px solid #EBF0F4; white-space: nowrap; vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tr:nth-child(even) td { background: #FAFBFC; }
tr:hover td { background: #EEF5FB !important; }

/* ---- Badges ---- */
.badge { display: inline-flex; align-items: center; gap: 3px; padding: 2px 8px; border-radius: 100px; font-size: 11px; font-weight: 600; }
.badge-ok      { background: #D5F5E3; color: var(--success); }
.badge-error   { background: #FADBD8; color: var(--danger); }
.badge-short   { background: #FDEBD0; color: #B7791F; margin-left: 6px; font-size: 10px; }
.badge-partial { background: #FEF3C7; color: var(--warn); }
.badge-null    { background: #EAECEE; color: var(--muted); }
.score-high { background: #D5F5E3; color: var(--success); }
.score-mid  { background: #FEF9E7; color: var(--warn); }
.score-low  { background: #FADBD8; color: var(--danger); }

/* ---- Modal ---- */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 100; display: flex; align-items: center; justify-content: center; }
.modal-overlay.hidden { display: none; }
.modal { background: var(--card); border-radius: 10px; width: 520px; max-width: 95vw; max-height: 90vh; overflow-y: auto; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 18px 20px 14px; border-bottom: 1px solid var(--border); }
.modal-header h2 { font-size: 15px; font-weight: 700; }
.modal-body { padding: 20px; display: flex; flex-direction: column; gap: 14px; }
.modal-footer { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; }

/* ---- Forms ---- */
.form-group { display: flex; flex-direction: column; gap: 5px; }
.form-group label { font-size: 12px; font-weight: 600; color: var(--text); }
.form-group small { font-size: 11px; color: var(--muted); }
input[type=text], input[type=email], input[type=password], input[type=time], input[type=number], input[type=url], select, textarea {
  width: 100%; padding: 8px 10px; border: 1px solid var(--border); border-radius: 6px;
  font-size: 13px; font-family: var(--font); color: var(--text); background: var(--card);
  transition: border-color .15s;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--navy-light); box-shadow: 0 0 0 2px rgba(36,113,163,.15); }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.toggle { display: flex; align-items: center; gap: 10px; cursor: pointer; }
.toggle input[type=checkbox] { width: 36px; height: 20px; accent-color: var(--teal); cursor: pointer; }

/* ---- Alerts ---- */
.alert { padding: 10px 14px; border-radius: 6px; font-size: 12px; display: flex; gap: 8px; align-items: flex-start; margin-bottom: 12px; }
.alert-info    { background: #EBF5FB; border: 1px solid #AED6F1; color: #1A5276; }
.alert-success { background: #EAFAF1; border: 1px solid #A9DFBF; color: #1E8449; }
.alert-error   { background: #FDEDEC; border: 1px solid #F1948A; color: #922B21; }
.alert-warn    { background: #FEF9E7; border: 1px solid #F9E79F; color: #7D6608; }

/* ---- Toast ---- */
#toast-container { position: fixed; bottom: 20px; right: 20px; z-index: 9999; display: flex; flex-direction: column; gap: 8px; pointer-events: none; }
.toast { padding: 12px 16px; border-radius: 8px; font-size: 13px; font-weight: 500; color: #fff; box-shadow: 0 4px 20px rgba(0,0,0,.25); pointer-events: all; max-width: 320px; animation: slideIn .25s ease; }
.toast-success { background: var(--teal); }
.toast-error   { background: var(--danger); }
.toast-info    { background: var(--navy); }
@keyframes slideIn { from { transform: translateX(30px); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* ---- Mono values ---- */
.mono { font-family: 'JetBrains Mono', 'Courier New', monospace; font-size: 12px; }
.trend-up { color: var(--success); }
.trend-dn { color: var(--danger); }

/* ---- HeartBeat dot ---- */
.hb-dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #4CAF50;
  box-shadow: 0 0 5px #4CAF50;
  flex-shrink: 0;
  transition: background .4s, box-shadow .4s;
  cursor: help;
}
.hb-pulse {
  animation: hb-pulse-anim 1s ease-in-out infinite;
}
@keyframes hb-pulse-anim {
  0%, 100% { transform: scale(1);   opacity: 1; }
  50%       { transform: scale(1.5); opacity: .7; }
}

/* ---- Loading spinner ---- */
.spinner { width: 18px; height: 18px; border: 2px solid rgba(255,255,255,.3); border-top-color: #fff; border-radius: 50%; animation: spin .6s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- Log/Activity ---- */
.log-line { font-family: 'JetBrains Mono', 'Courier New', monospace; font-size: 11px; padding: 4px 8px; border-bottom: 1px solid #F0F0F0; display: flex; gap: 8px; }
.log-line:hover { background: #F8FAFB; }
.log-ts { color: var(--muted); flex-shrink: 0; width: 130px; }
.log-level { flex-shrink: 0; width: 70px; font-weight: 700; }
.log-ctx { flex-shrink: 0; width: 80px; color: var(--navy-light); }
.log-msg { flex: 1; word-break: break-all; }
.log-DEBUG    { color: var(--muted); }
.log-INFO     { color: var(--navy-light); }
.log-WARNING  { color: var(--warn); }
.log-ERROR    { color: var(--danger); }
.log-CRITICAL { color: var(--danger); background: #FFF0F0; }

/* ---- Realtime activity ---- */
.activity-item { display: flex; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--border); align-items: flex-start; }
.activity-icon { width: 32px; height: 32px; border-radius: 50%; display: flex; align-items: center; justify-content: center; flex-shrink: 0; font-size: 14px; }
.activity-icon.ok     { background: var(--teal-bg); color: var(--teal); }
.activity-icon.error  { background: #FADBD8; color: var(--danger); }
.activity-icon.info   { background: #EBF5FB; color: var(--navy-light); }
.activity-icon.delay  { background: #FEF9E7; color: var(--warn); }
.activity-text { flex: 1; }
.activity-title { font-weight: 600; font-size: 13px; }
.activity-detail { font-size: 11px; color: var(--muted); margin-top: 2px; }
.activity-ts { font-size: 11px; color: var(--muted); flex-shrink: 0; }

/* ---- Login page ---- */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: var(--navy-dark); }
.login-card { background: var(--card); border-radius: 12px; padding: 36px 40px; width: 380px; max-width: 95vw; box-shadow: 0 20px 60px rgba(0,0,0,.4); }
.login-logo { display: flex; align-items: center; gap: 10px; margin-bottom: 28px; justify-content: center; }
.login-logo-text { font-size: 18px; font-weight: 700; color: var(--navy-dark); }
body.dark .login-logo-text { color: var(--text); }
.btn-google { background: #fff; color: #444; border: 1px solid var(--border); width: 100%; justify-content: center; padding: 10px; font-size: 14px; font-weight: 500; gap: 10px; }
.btn-google:hover { background: #F8F9FA; }
.divider { display: flex; align-items: center; gap: 10px; margin: 16px 0; color: var(--muted); font-size: 12px; }
.divider::before, .divider::after { content: ''; flex: 1; height: 1px; background: var(--border); }

/* ---- Accesso negato ---- */
.forbidden-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: var(--bg); }
.forbidden-card { background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 48px; text-align: center; max-width: 420px; }
.forbidden-icon { font-size: 48px; margin-bottom: 16px; }
.forbidden-title { font-size: 18px; font-weight: 700; margin-bottom: 8px; color: var(--danger); }
.forbidden-sub { font-size: 13px; color: var(--muted); margin-bottom: 24px; }

/* ---- Responsive ---- */
@media (max-width: 768px) {
  .sidebar { display: none; }
  .content-area { padding: 12px; }
  .kpi-grid { grid-template-columns: 1fr 1fr; }
  .form-row { grid-template-columns: 1fr; }
}

/* ============================================================
   Valuta inline — codice ISO a larghezza fissa dopo i numeri
   Uso: <span class="cur">EUR</span> dopo il valore numerico
   Garantisce allineamento decimali anche con valute diverse
   ============================================================ */
.cur {
  display: inline-block;
  min-width: 3ch;
  font-size: 10px;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  letter-spacing: .02em;
  margin-left: 3px;
  vertical-align: baseline;
  white-space: nowrap;
}
td .cur { margin-left: 4px; }

/* ---- Zainetto fiscale (strip su pagine portafoglio) ---- */
#user-minusvalenza-strip {
  margin-bottom: 14px;
}
.minusvalenza-strip-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
  padding: 12px 16px;
  border-radius: 8px;
  border: 1px solid rgba(17, 122, 101, 0.35);
  background: rgba(17, 122, 101, 0.06);
  border-left-width: 4px;
  border-left-color: var(--teal);
}
body.dark .minusvalenza-strip-inner {
  background: rgba(26, 188, 156, 0.08);
  border-color: rgba(126, 184, 224, 0.25);
}
