/* HS AMIATA SCADENZE — temi light/dark via variabili CSS + attributo data-theme */
:root {
  --bg: #f5f6f8; --surface: #ffffff; --text: #1a1d21; --muted: #6b7280;
  --border: #e1e4e8; --row-hover: #eef3ff; --zebra: #fafbfc;
  --accent: #1f6feb; --accent-text: #ffffff; --header: #eef1f5;
  --scaduto-bg: #fdecec; --scaduto-bd: #f1b5b5;
  --arrivo-bg: #fff6e5; --arrivo-bd: #f0cd7e;
  --shadow: 0 1px 3px rgba(0, 0, 0, .12);
}
[data-theme="dark"] {
  --bg: #0d1117; --surface: #161b22; --text: #e6edf3; --muted: #9aa4b2;
  --border: #30363d; --row-hover: #1b2333; --zebra: #12161d;
  --accent: #388bfd; --accent-text: #ffffff; --header: #1c2128;
  --scaduto-bg: #3a1d1d; --scaduto-bd: #6b3030;
  --arrivo-bg: #362e16; --arrivo-bd: #6b572a;
  --shadow: 0 1px 3px rgba(0, 0, 0, .5);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, sans-serif;
}

/* ---- topbar ---- */
.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px; background: var(--surface);
  border-bottom: 1px solid var(--border); box-shadow: var(--shadow);
  position: sticky; top: 0; z-index: 20;
}
.brand { font-weight: 700; letter-spacing: .3px; font-size: 16px; }
.spacer { flex: 1; }
.count { color: var(--muted); font-variant-numeric: tabular-nums; }
.user { color: var(--muted); }
.logout-form { margin: 0; }

.btn {
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px;
  padding: 6px 12px; cursor: pointer; font-size: 13px;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.btn.primary:hover { filter: brightness(1.05); }

/* ---- login ---- */
.login-wrap { display: flex; justify-content: center; padding: 8vh 16px; }
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; box-shadow: var(--shadow); padding: 24px;
}
.login-card { width: 320px; max-width: 100%; }
.login-card h2 { margin: 0 0 16px; }
.login-card label { display: block; margin-bottom: 12px; color: var(--muted); font-size: 13px; }
.login-card input {
  display: block; width: 100%; margin-top: 4px; padding: 9px 10px;
  border: 1px solid var(--border); border-radius: 8px;
  background: var(--bg); color: var(--text); font-size: 14px;
}
.login-card .btn.primary { width: 100%; margin-top: 4px; padding: 10px; }
.hint { color: var(--muted); font-size: 12px; margin: 12px 0 0; }
.error {
  background: var(--scaduto-bg); border: 1px solid var(--scaduto-bd);
  color: var(--text); padding: 8px 10px; border-radius: 8px; margin: 0 0 14px; font-size: 13px;
}

/* ---- table ---- */
/* Niente overflow (ne' qui ne' su <table>): creerebbe un contenitore di scorrimento
   che fa risolvere le th sticky contro se stesso anziche' contro il viewport,
   spostando intestazione/filtri sopra alle righe (vedi §filtri sticky). */
.table-wrap { padding: 16px; }
table {
  border-collapse: collapse; width: 100%; background: var(--surface);
  border: 1px solid var(--border); border-radius: 10px;
}
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); }
thead th { background: var(--header); position: sticky; top: 53px; z-index: 10; }
.head-row th.sortable { cursor: pointer; user-select: none; white-space: nowrap; }
.head-row th.sortable:hover { color: var(--accent); }
.head-row th.sort-asc::after { content: " ▲"; color: var(--accent); }
.head-row th.sort-desc::after { content: " ▼"; color: var(--accent); }
.filter-row th { top: 91px; padding: 4px 6px; background: var(--header); }
.filter-row input {
  width: 100%; min-width: 80px; padding: 5px 22px 5px 7px;   /* spazio a dx per la × */
  border: 1px solid var(--border); border-radius: 6px;
  background: var(--bg); color: var(--text); font-size: 12px;
}
/* pulsante "cancella" dentro ogni filtro (creato in app.js) */
.filter-cell { position: relative; display: block; }
.filter-clear {
  position: absolute; right: 4px; top: 50%; transform: translateY(-50%);
  display: none; border: none; background: transparent; cursor: pointer;
  color: var(--muted); font-size: 16px; line-height: 1; padding: 0 3px;
}
.filter-cell.has-value .filter-clear { display: block; }
.filter-clear:hover { color: var(--accent); }
tbody tr:nth-child(even) { background: var(--zebra); }
tbody tr:hover { background: var(--row-hover); }
tbody td { font-variant-numeric: tabular-nums; }
.empty { text-align: center; color: var(--muted); padding: 24px; }

/* evidenziazione righe */
tbody tr.scaduto { background: var(--scaduto-bg); }
tbody tr.scaduto:hover { background: var(--scaduto-bg); filter: brightness(1.03); }
tbody tr.in-arrivo { background: var(--arrivo-bg); }
tbody tr.in-arrivo:hover { background: var(--arrivo-bg); filter: brightness(1.03); }

/* password cell */
td.pw { white-space: nowrap; }
td.pw .pw-val { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
td.pw .pw-val.shown { user-select: all; }
.icon {
  background: transparent; border: none; cursor: pointer; font-size: 14px;
  padding: 0 4px; color: var(--muted);
}
.icon:hover { color: var(--accent); }
.icon.flash { color: var(--accent); }

/* colonne extra: nascoste finche' non si attiva il toggle */
.col-extra { display: none; }
body.show-extra .col-extra { display: table-cell; }
