/* Stile ispirato alla Okta Admin Console: Inter, canvas grigio, sidebar bianca, card bianche
   con angoli ampi e senza ombra, intestazioni di tabella grigie in maiuscoletto. */

@font-face { font-family: "Inter"; font-weight: 400; font-display: swap; src: url("/fonts/inter-400.woff2") format("woff2"); }
@font-face { font-family: "Inter"; font-weight: 500; font-display: swap; src: url("/fonts/inter-500.woff2") format("woff2"); }
@font-face { font-family: "Inter"; font-weight: 600; font-display: swap; src: url("/fonts/inter-600.woff2") format("woff2"); }
@font-face { font-family: "Inter"; font-weight: 700; font-display: swap; src: url("/fonts/inter-700.woff2") format("woff2"); }

:root {
  --bg: #f4f4f4;
  --surface: #ffffff;
  --surface-2: #f4f4f4;        /* intestazioni tabella, codice */
  --text: #1d1d21;
  --text-2: #272727;
  --muted: #6e6e78;
  --divider: #e1e1e1;
  --control-border: #8d8d8d;   /* input */
  --button-border: #cbcbcb;    /* bottoni secondari */
  --accent: #546be7;           /* bottone primario */
  --accent-hover: #4c64e1;
  --accent-text: #ffffff;
  --link: #1662dd;
  --nav-active-bg: #f2f3fd;
  --nav-active-text: #4c64e1;
  --focus: #546be7;
  --danger: #c1121f;
  --ok-bg: #defae7;
  --ok-text: #197f48;
  --warn-bg: #fdf1d3;
  --warn-text: #8a5b00;
  --del-bg: #fde6e6;
  --del-text: #b0201d;
  --neutral-bg: #ebebed;
  --super-bg: #ebefff;
  --super-text: #3a4fc9;
  --radius-card: 16px;
  --radius: 6px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121316;
    --surface: #1c1d21;
    --surface-2: #26272c;
    --text: #ececef;
    --text-2: #dcdce0;
    --muted: #9b9ba6;
    --divider: #2e2f35;
    --control-border: #5c5d66;
    --button-border: #43444c;
    --accent: #6f83ef;
    --accent-hover: #8194f1;
    --accent-text: #0e0f12;
    --link: #7fa6f5;
    --nav-active-bg: #262a45;
    --nav-active-text: #a3b1f7;
    --focus: #8194f1;
    --danger: #f28b8b;
    --ok-bg: #173523;
    --ok-text: #7fd59b;
    --warn-bg: #3a2d10;
    --warn-text: #f0c46a;
    --del-bg: #3d1a1a;
    --del-text: #f2a3a3;
    --neutral-bg: #2c2d33;
    --super-bg: #23284a;
    --super-text: #a3b1f7;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; } /* l'attributo hidden deve vincere su display: grid/flex */

body {
  margin: 0;
  font-family: Inter, -apple-system, system-ui, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { margin: 0; color: var(--text); }
h1 { font-size: 24px; font-weight: 600; letter-spacing: -0.01em; }
h2 { font-size: 18px; font-weight: 600; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; background: var(--surface-2); padding: 1px 6px; border-radius: 4px; }
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- Controlli ---------- */
button, input, select, a.button {
  font: inherit;
  color: var(--text-2);
}
input, select {
  background: var(--surface);
  border: 1px solid var(--control-border);
  border-radius: var(--radius);
  padding: 8px 10px;
  min-height: 40px;
}
input[type="checkbox"] { min-height: 0; width: 16px; height: 16px; accent-color: var(--accent); margin: 0; }
input:focus-visible, select:focus-visible, button:focus-visible, a.button:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 1px;
}
button, a.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 40px;
  padding: 8px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--button-border);
  background: var(--surface);
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  text-decoration: none;
}
button:hover, a.button:hover { background: var(--surface-2); text-decoration: none; }
button:disabled { opacity: 0.5; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
button.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
button.danger { color: var(--danger); }
button.text-btn, button.link {
  border: none;
  background: none;
  color: var(--link);
  min-height: 0;
  padding: 2px 4px;
}
button.text-btn:hover, button.link:hover { background: none; text-decoration: underline; }
.small-btn { min-height: 32px; padding: 4px 12px; }

/* ---------- Layout ---------- */
.app { display: grid; grid-template-columns: 280px minmax(0, 1fr); min-height: 100vh; }
.sidebar {
  background: var(--surface);
  padding: 20px 16px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 0 8px; }
.brand-mark {
  width: 28px; height: 28px; border-radius: 50%;
  background: conic-gradient(from 0deg, var(--accent), #1662dd, var(--accent));
  -webkit-mask: radial-gradient(circle, transparent 6px, #000 7px);
          mask: radial-gradient(circle, transparent 6px, #000 7px);
}
.brand-name { font-weight: 700; font-size: 18px; line-height: 1.1; }
.brand-sub { font-size: 12px; color: var(--muted); }
.console-title { font-size: 18px; font-weight: 500; color: var(--text-2); margin: 28px 8px 12px; }
#tabs { display: flex; flex-direction: column; gap: 2px; }
#tabs button {
  justify-content: flex-start;
  gap: 12px;
  border: none;
  background: none;
  padding: 10px 12px;
  min-height: 44px;
  font-weight: 400;
  color: var(--text-2);
  text-align: left;
}
#tabs button svg { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
#tabs button:hover { background: var(--surface-2); }
#tabs button.active { background: var(--nav-active-bg); color: var(--nav-active-text); font-weight: 600; }

.content { min-width: 0; }
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 32px 6px;
}
.who { display: flex; align-items: center; gap: 14px; text-align: right; }
.who-name { font-size: 13px; font-weight: 500; color: var(--text-2); }
.who-role { font-size: 12px; color: var(--muted); }
main { padding: 16px 32px 40px; max-width: 1600px; }
.tab { display: flex; flex-direction: column; gap: 20px; }

/* ---------- Card ---------- */
.card { background: var(--surface); border-radius: var(--radius-card); }
.card.narrow { max-width: 460px; }
.card-header {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--divider);
  flex-wrap: wrap;
}
.card-header > h2 { margin-right: auto; }
.card-body { padding: 16px 20px; }
.card-body.flush { padding: 8px 14px 14px; }
.intro { margin: 0 0 4px; }
.empty { padding: 8px 6px; margin: 0; }

/* ---------- Filtri ---------- */
.filters { display: flex; flex-wrap: wrap; gap: 24px; }
.filters fieldset { border: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 8px; min-width: 180px; }
.filters fieldset.grow { flex: 1; min-width: 220px; }
.filters legend {
  padding: 0;
  margin-bottom: 8px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 1.2px;
  text-transform: uppercase;
  color: var(--muted);
}
.filters label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--text-2); }
.checks { display: flex; flex-direction: column; gap: 6px; max-height: 150px; overflow: auto; }
.checks label { flex-direction: row; align-items: center; gap: 8px; }

/* ---------- Riepilogo ---------- */
.summary { gap: 14px; }
.stat { display: flex; flex-direction: column; margin-right: 8px; }
.stat-label { font-size: 16px; font-weight: 700; color: var(--link); line-height: 1.3; }
.stat-value { font-size: 32px; font-weight: 600; line-height: 1.15; color: var(--text); }
.summary a.button { margin-left: auto; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }

/* ---------- Badge ---------- */
.chip {
  display: inline-block;
  padding: 3px 8px;
  border-radius: var(--radius);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.4px;
  text-transform: uppercase;
  line-height: 1.3;
  background: var(--neutral-bg);
  color: var(--text-2);
  white-space: nowrap;
}
.st-ACTIVE, .imp-ok { background: var(--ok-bg); color: var(--ok-text); }
.st-DELETED, .st-DEPROVISIONED, .imp-error { background: var(--del-bg); color: var(--del-text); }
.st-SUSPENDED, .st-LOCKED_OUT, .st-PASSWORD_EXPIRED, .st-PROVISIONED, .st-STAGED, .st-RECOVERY, .imp-skipped, .imp-replaced {
  background: var(--warn-bg); color: var(--warn-text);
}
.chip.super { background: var(--super-bg); color: var(--super-text); }
.chip.dup { background: var(--neutral-bg); color: var(--muted); }

/* ---------- Tabelle ---------- */
.table-wrap { overflow-x: auto; }
table { border-collapse: separate; border-spacing: 0; width: 100%; }
th, td { text-align: left; white-space: nowrap; }
th {
  background: var(--surface-2);
  color: var(--muted);
  font-size: 10.6px;
  font-weight: 600;
  letter-spacing: 1.3px;
  text-transform: uppercase;
  padding: 12px;
  position: sticky;
  top: 0;
}
th:first-child { border-radius: 8px 0 0 8px; }
th:last-child { border-radius: 0 8px 8px 0; }
th[data-sort] { cursor: pointer; user-select: none; }
th[data-sort]:hover { color: var(--text-2); }
th[data-dir="asc"]::after { content: " ▲"; }
th[data-dir="desc"]::after { content: " ▼"; }
td { padding: 14px 12px; border-bottom: 1px solid var(--divider); color: var(--text-2); vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: color-mix(in srgb, var(--surface-2) 55%, transparent); }
td.num { text-align: right; font-variant-numeric: tabular-nums; }
tr.deleted td { color: var(--muted); }

.pager { display: flex; align-items: center; justify-content: flex-end; gap: 12px; padding: 12px 6px 2px; }

/* ---------- Form e varie ---------- */
.toolbar { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.inline-form { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.stack-form { display: flex; flex-direction: column; gap: 14px; }
.stack-form label, .login-card label, .tenant-form label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 500; color: var(--text-2); }
label.check { flex-direction: row !important; align-items: center; gap: 8px; }
.actions { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; min-width: 260px; }
.actions button { min-height: 32px; padding: 4px 12px; }
.actions input { width: 160px; min-height: 32px; padding: 4px 8px; }

.muted { color: var(--muted); }
.hint { color: var(--muted); font-size: 12px; }
.small { font-size: 12px; white-space: normal; max-width: 320px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }
.error { color: var(--danger); }
.notice { color: var(--ok-text); }
#import-result p { margin: 12px 0 0; }

/* ---------- Wizard tenant ---------- */
.wizard { border: 1px solid var(--divider); border-radius: 12px; padding: 18px 20px; margin: 14px 0 6px; }
.steps { display: flex; gap: 8px; list-style: none; padding: 0; margin: 0 0 18px; flex-wrap: wrap; }
.steps li { display: flex; align-items: center; gap: 8px; padding: 6px 14px 6px 6px; border-radius: 999px; background: var(--surface-2); color: var(--muted); font-size: 13px; font-weight: 500; }
.steps li span { display: grid; place-items: center; width: 22px; height: 22px; border-radius: 50%; background: var(--surface); font-size: 12px; font-weight: 700; }
.steps li.active { background: var(--nav-active-bg); color: var(--nav-active-text); font-weight: 600; }
.steps li.active span { background: var(--accent); color: var(--accent-text); }
.steps li.done { background: var(--ok-bg); color: var(--ok-text); }
.tenant-form { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 14px 18px; align-items: end; }
.tenant-form label.check { padding-bottom: 10px; }
.tenant-form .form-actions { display: flex; gap: 8px; }
.tenant-form .hint, .tenant-form .error { grid-column: 1 / -1; margin: 0; }
.instructions { grid-column: 1 / -1; }
.instructions p { margin: 0 0 8px; }
.instructions ol { margin: 4px 0 0; padding-left: 20px; line-height: 1.9; }
.instructions code { word-break: break-all; }

/* ---------- Login / pagine semplici ---------- */
.login-body { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.login-card { background: var(--surface); border-radius: var(--radius-card); padding: 32px; width: 100%; max-width: 380px; }
.login-card h1 { font-size: 22px; margin-bottom: 20px; }
.login-card form { display: flex; flex-direction: column; gap: 14px; }
.login-card button.primary { margin-top: 6px; }

/* ---------- Mobile ---------- */
@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; padding: 12px 16px; }
  .console-title { display: none; }
  #tabs { flex-direction: row; overflow-x: auto; margin-top: 10px; }
  #tabs button { min-height: 36px; padding: 6px 10px; }
  #tabs button svg { display: none; }
  .topbar { padding: 14px 16px 0; }
  main { padding: 12px 16px 32px; }
  .card-body.flush { padding: 6px 8px 10px; }
}

/* ---------- Console ---------- */
h3 { font-size: 15px; font-weight: 600; }
.panel-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 28px; }
.panel-grid h3 { margin: 0; }
.panel-msg { margin: 0; padding: 0 20px 16px; }
.danger-zone { border-left: 3px solid var(--del-bg); padding-left: 16px; }
a.button.primary-link { background: var(--accent); border-color: var(--accent); color: var(--accent-text); min-height: 32px; padding: 4px 12px; }
a.button.primary-link:hover { background: var(--accent-hover); }
.alert-row { margin: 0 0 10px; }

/* ---------- Login SSO ---------- */
.login-card .login-btn { width: 100%; min-height: 44px; margin: 8px 0 4px; }
.login-card p { margin: 0 0 8px; }
.admins-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.admins-list li { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
