/* =========================================================================
   The House of Nonni Ventura - Admin console
   Design system "enterprise": palette slate scura, accento ocean del brand,
   controlli form pienamente leggibili, tabelle/badge/card coerenti.
   Unica fonte di stile per tutto /admin (vedi views/layouts/admin.php).
   ========================================================================= */

:root {
  /* Superfici (dal più profondo al più elevato) */
  --a-bg:        #0b0e11;   /* sfondo app */
  --a-surface:   #14181d;   /* card, sidebar, topbar */
  --a-surface-2: #1b2026;   /* input, righe hover, elementi annidati */
  --a-surface-3: #232a31;   /* hover su superfici-2 */

  /* Bordi */
  --a-border:    #262d34;   /* bordo standard */
  --a-border-2:  #333c45;   /* bordo evidenziato / focus base */

  /* Testo */
  --a-text:      #e7ebee;   /* primario */
  --a-text-2:    #a2adb6;   /* secondario */
  --a-muted:     #6d7882;   /* etichette, hint, placeholder */

  /* Accento (ocean del brand) */
  --a-accent:    #3b9ed6;
  --a-accent-h:  #58b0e2;   /* hover */
  --a-accent-d:  #2b7cab;   /* pressed */
  --a-accent-soft: rgba(59,158,214,0.14);
  --a-on-accent: #06131c;   /* testo su accento */

  /* Semantici */
  --a-ok:        #40c463;
  --a-ok-bg:     rgba(64,196,99,0.12);
  --a-ok-bd:     rgba(64,196,99,0.30);
  --a-warn:      #d9a520;
  --a-warn-bg:   rgba(217,165,32,0.12);
  --a-warn-bd:   rgba(217,165,32,0.30);
  --a-danger:    #f0645a;
  --a-danger-bg: rgba(240,100,90,0.12);
  --a-danger-bd: rgba(240,100,90,0.32);

  --a-radius:    10px;
  --a-radius-sm: 7px;
  --a-shadow:    0 1px 2px rgba(0,0,0,0.4), 0 8px 24px -12px rgba(0,0,0,0.55);
  --a-font: 'Instrument Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --a-mono: ui-monospace, 'SF Mono', 'JetBrains Mono', 'Menlo', monospace;
}

* { box-sizing: border-box; }

body.adm-body {
  margin: 0;
  background: var(--a-bg);
  color: var(--a-text);
  font-family: var(--a-font);
  font-size: 14px;
  line-height: 1.5;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--a-accent); text-decoration: none; }
a:hover { color: var(--a-accent-h); }
code { font-family: var(--a-mono); font-size: .88em; background: var(--a-surface-2);
  border: 1px solid var(--a-border); border-radius: 4px; padding: 1px 5px; color: var(--a-text-2); }

/* ===================== Layout shell ===================== */
.adm-wrap { display: flex; min-height: 100dvh; }

.adm-sidebar {
  width: 236px; flex-shrink: 0;
  background: var(--a-surface);
  border-right: 1px solid var(--a-border);
  display: flex; flex-direction: column;
  padding: 18px 0 14px;
  position: sticky; top: 0; height: 100dvh; overflow-y: auto;
}
.adm-brand {
  display: flex; align-items: center; gap: 10px;
  padding: 2px 18px 16px;
  margin-bottom: 10px;
  border-bottom: 1px solid var(--a-border);
}
.adm-brand .mark {
  width: 30px; height: 30px; flex-shrink: 0;
  border-radius: 8px;
  background: linear-gradient(150deg, var(--a-accent), var(--a-accent-d));
  display: grid; place-items: center;
  color: var(--a-on-accent); font-weight: 700; font-size: 15px;
  font-family: var(--a-mono);
}
.adm-brand .txt { line-height: 1.2; }
.adm-brand .txt strong { display: block; font-size: 13px; font-weight: 600; color: var(--a-text); }
.adm-brand .txt span { font-size: 11px; color: var(--a-muted); }

.adm-navlabel {
  font-size: 10px; font-weight: 700; letter-spacing: .09em;
  text-transform: uppercase; color: var(--a-muted);
  padding: 14px 18px 6px;
}
.adm-sidebar a.adm-link {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 18px; margin: 1px 8px;
  color: var(--a-text-2); font-size: 13.5px; font-weight: 500;
  border-radius: var(--a-radius-sm);
  border-left: 2px solid transparent;
  transition: background .13s, color .13s;
}
.adm-sidebar a.adm-link .ic { width: 17px; text-align: center; opacity: .85; font-size: 14px; }
.adm-sidebar a.adm-link:hover { background: var(--a-surface-2); color: var(--a-text); }
.adm-sidebar a.adm-link.active {
  background: var(--a-accent-soft); color: var(--a-text);
  border-left-color: var(--a-accent);
}
.adm-sidebar .foot { margin-top: auto; padding: 10px 8px 0; border-top: 1px solid var(--a-border); }
.adm-sidebar .foot a { color: var(--a-muted); font-size: 12.5px; }
.adm-sidebar .foot a.danger:hover { color: var(--a-danger); background: var(--a-danger-bg); }

.adm-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.adm-topbar {
  position: sticky; top: 0; z-index: 5;
  background: color-mix(in srgb, var(--a-surface) 88%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--a-border);
  padding: 12px 26px;
  display: flex; justify-content: space-between; align-items: center;
  font-size: 12.5px; color: var(--a-text-2);
}
.adm-topbar .who { display: flex; align-items: center; gap: 8px; }
.adm-topbar .who .avatar {
  width: 24px; height: 24px; border-radius: 50%;
  background: var(--a-surface-3); color: var(--a-text-2);
  display: grid; place-items: center; font-size: 11px; font-weight: 700;
}
.adm-content { padding: 26px; max-width: 1160px; width: 100%; }

/* ===================== Titoli pagina ===================== */
.adm-title { font-size: 21px; font-weight: 700; letter-spacing: -.01em; margin: 0 0 4px; color: var(--a-text); }
.adm-lede { font-size: 13.5px; color: var(--a-text-2); line-height: 1.55; margin: 0 0 22px; max-width: 78ch; }
.adm-hint { font-size: 12.5px; color: var(--a-muted); line-height: 1.55; margin: 0; }

/* ===================== Card ===================== */
.card {
  background: var(--a-surface);
  border: 1px solid var(--a-border);
  border-radius: var(--a-radius);
  padding: 22px;
  margin-bottom: 20px;
  box-shadow: var(--a-shadow);
}
.card > h2, .card-title {
  font-size: 15px; font-weight: 600; margin: 0 0 16px; color: var(--a-text);
  letter-spacing: -.005em;
}
.adm-section-head { margin-bottom: 16px; }
.adm-section-head h2 { font-size: 15px; font-weight: 600; margin: 0 0 5px; color: var(--a-text); }

/* ===================== Form ===================== */
.field { margin-bottom: 15px; }
.field:last-child { margin-bottom: 0; }
.field > label {
  display: block; font-size: 12px; font-weight: 600;
  color: var(--a-text-2); margin-bottom: 6px; letter-spacing: .005em;
}

.adm-content input:not([type=checkbox]):not([type=radio]):not([type=file]),
.adm-content select,
.adm-content textarea {
  width: 100%;
  background: var(--a-surface-2);
  border: 1px solid var(--a-border-2);
  border-radius: var(--a-radius-sm);
  padding: 9px 12px;
  color: var(--a-text);
  font-family: var(--a-font);
  font-size: 14px;
  line-height: 1.4;
  outline: none;
  transition: border-color .13s, box-shadow .13s, background .13s;
  -webkit-appearance: none; appearance: none;
}
.adm-content textarea { min-height: 68px; resize: vertical; }
.adm-content select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23a2adb6' d='M6 8.5 1.5 4h9z'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center;
  padding-right: 34px; cursor: pointer;
}
.adm-content input::placeholder,
.adm-content textarea::placeholder { color: var(--a-muted); opacity: 1; }

.adm-content input:not([type=checkbox]):not([type=radio]):not([type=file]):focus,
.adm-content select:focus,
.adm-content textarea:focus {
  border-color: var(--a-accent);
  box-shadow: 0 0 0 3px var(--a-accent-soft);
  background: var(--a-surface);
}

.adm-content input[type=file] {
  color: var(--a-text-2); font-size: 13px;
}
.adm-content input[type=file]::file-selector-button {
  background: var(--a-surface-2); color: var(--a-text);
  border: 1px solid var(--a-border-2); border-radius: var(--a-radius-sm);
  padding: 7px 13px; margin-right: 12px; cursor: pointer;
  font-family: var(--a-font); font-size: 13px; font-weight: 500;
}
.adm-content input[type=file]::file-selector-button:hover { background: var(--a-surface-3); }

.field-check { display: flex; align-items: center; gap: 8px; font-size: 13.5px; color: var(--a-text-2); }
.field-check input[type=checkbox] { width: 16px; height: 16px; accent-color: var(--a-accent); cursor: pointer; }

.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 640px){ .field-row { grid-template-columns: 1fr; } }

/* ===================== Bottoni ===================== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 9px 16px;
  background: var(--a-accent); color: var(--a-on-accent);
  border: 1px solid transparent; border-radius: var(--a-radius-sm);
  font-family: var(--a-font); font-weight: 600; font-size: 13.5px;
  cursor: pointer; text-decoration: none; white-space: nowrap;
  transition: background .13s, border-color .13s, color .13s, opacity .13s;
}
.btn:hover { background: var(--a-accent-h); color: var(--a-on-accent); }
.btn:active { background: var(--a-accent-d); }

.btn-secondary { background: var(--a-surface-2); color: var(--a-text); border-color: var(--a-border-2); }
.btn-secondary:hover { background: var(--a-surface-3); color: var(--a-text); }

.btn-ghost { background: transparent; color: var(--a-text-2); border-color: var(--a-border-2); }
.btn-ghost:hover { background: var(--a-surface-2); color: var(--a-text); }
.btn-ghost.active { background: var(--a-accent-soft); color: var(--a-text); border-color: var(--a-accent); }

.btn-danger { background: transparent; color: var(--a-danger); border-color: var(--a-danger-bd); }
.btn-danger:hover { background: var(--a-danger-bg); color: var(--a-danger); }

.btn-sm { padding: 6px 11px; font-size: 12.5px; }
.btn-block { width: 100%; }

/* Bottone-link testuale dentro le tabelle (Modifica / Elimina) */
.btn-link { background: none; border: 0; cursor: pointer; font-family: var(--a-font);
  font-size: 12.5px; font-weight: 600; color: var(--a-accent); padding: 4px 2px; }
.btn-link:hover { color: var(--a-accent-h); text-decoration: underline; }
.btn-link.danger { color: var(--a-danger); }
.btn-link.danger:hover { color: var(--a-danger); }

.btn-row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

/* ===================== Tabelle ===================== */
.table-wrap { width: 100%; overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th {
  text-align: left; padding: 10px 14px;
  color: var(--a-muted); font-weight: 600; font-size: 11px;
  text-transform: uppercase; letter-spacing: .05em;
  border-bottom: 1px solid var(--a-border);
  background: var(--a-surface-2);
  position: sticky; top: 0;
}
.table td { padding: 11px 14px; border-bottom: 1px solid var(--a-border); color: var(--a-text-2); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover td { background: var(--a-surface-2); }
.table td strong, .table td .primary { color: var(--a-text); font-weight: 500; }
.table .num { font-family: var(--a-mono); font-variant-numeric: tabular-nums; }
.table .nowrap { white-space: nowrap; }
.table .empty { color: var(--a-muted); text-align: center; padding: 26px; }

/* Card senza padding quando contiene solo una tabella a tutta larghezza */
.card.card-table { padding: 0; overflow: hidden; }
.card.card-table .table th:first-child,
.card.card-table .table td:first-child { padding-left: 20px; }
.card.card-table .table th:last-child,
.card.card-table .table td:last-child { padding-right: 20px; }

/* ===================== Badge / pill di stato ===================== */
.pill {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 9px; border-radius: 999px;
  font-size: 11.5px; font-weight: 600; line-height: 1.4;
  border: 1px solid transparent; white-space: nowrap;
}
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.pill-new,
.pill-pending    { color: var(--a-warn);   background: var(--a-warn-bg);   border-color: var(--a-warn-bd); }
.pill-confirmed,
.pill-replied    { color: var(--a-ok);     background: var(--a-ok-bg);     border-color: var(--a-ok-bd); }
.pill-read,
.pill-archived,
.pill-unsubscribed { color: var(--a-muted); background: var(--a-surface-2); border-color: var(--a-border-2); }
.pill-danger     { color: var(--a-danger); background: var(--a-danger-bg); border-color: var(--a-danger-bd); }

.tag { display: inline-block; padding: 2px 7px; border-radius: 5px; font-family: var(--a-mono);
  font-size: 11px; background: var(--a-surface-2); border: 1px solid var(--a-border); color: var(--a-text-2); }

/* ===================== Statistiche ===================== */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 14px; margin-bottom: 20px; }
.stat-card { background: var(--a-surface); border: 1px solid var(--a-border); border-radius: var(--a-radius); padding: 16px 18px; box-shadow: var(--a-shadow); }
.stat-card .n { font-size: 26px; font-weight: 700; color: var(--a-text); line-height: 1.05; font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.stat-card .n.accent { color: var(--a-accent); }
.stat-card .l { font-size: 12px; color: var(--a-muted); margin-top: 6px; line-height: 1.4; }

/* Grafico a barre orizzontali (andamento) */
.bars { display: flex; flex-direction: column; gap: 9px; }
.bars .row { display: flex; align-items: center; gap: 12px; }
.bars .row .lab { width: 38px; font-size: 12px; color: var(--a-muted); flex-shrink: 0; }
.bars .row .track { flex: 1; background: var(--a-surface-2); border-radius: 5px; overflow: hidden; height: 20px; }
.bars .row .fill { height: 100%; background: linear-gradient(90deg, var(--a-accent-d), var(--a-accent)); border-radius: 5px; min-width: 3px; }
.bars .row .val { width: 28px; font-size: 12px; color: var(--a-text); text-align: right; flex-shrink: 0; font-variant-numeric: tabular-nums; }

/* ===================== Media grid ===================== */
.media-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 16px; }
.media-item { border: 1px solid var(--a-border); border-radius: var(--a-radius); overflow: hidden; background: var(--a-surface-2); }
.media-item img { width: 100%; height: 140px; object-fit: cover; display: block; background: var(--a-bg); }
.media-item .body { padding: 12px; }
.media-item .meta { font-size: 11px; color: var(--a-muted); margin-bottom: 10px; font-family: var(--a-mono); }
.media-item label { display: block; font-size: 11px; color: var(--a-muted); margin-bottom: 3px; }
.media-item .field { margin-bottom: 9px; }

/* ===================== Toolbar (filtri + azioni) ===================== */
.adm-toolbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.adm-filters { display: flex; gap: 8px; flex-wrap: wrap; }

/* ===================== Flash ===================== */
.adm-flash { border-radius: var(--a-radius-sm); padding: 11px 15px; font-size: 13px; margin-bottom: 18px; border: 1px solid; display: flex; gap: 9px; align-items: flex-start; }
.adm-flash.ok    { background: var(--a-ok-bg);     border-color: var(--a-ok-bd);     color: var(--a-ok); }
.adm-flash.error { background: var(--a-danger-bg); border-color: var(--a-danger-bd); color: var(--a-danger); }
.adm-error { background: var(--a-danger-bg); border: 1px solid var(--a-danger-bd); color: var(--a-danger); border-radius: var(--a-radius-sm); padding: 11px 15px; font-size: 13px; margin-bottom: 16px; }

/* ===================== Pagine auth (login / setup / 2FA) ===================== */
.adm-auth-wrap { min-height: 100dvh; display: flex; align-items: center; justify-content: center; padding: 24px; background:
  radial-gradient(1100px 500px at 50% -10%, rgba(59,158,214,0.10), transparent 70%), var(--a-bg); }
.adm-auth-box {
  background: var(--a-surface); border: 1px solid var(--a-border);
  border-radius: 14px; padding: 30px 32px; width: 100%; max-width: 400px;
  box-shadow: var(--a-shadow);
}
.adm-auth-brand { display: flex; align-items: center; gap: 11px; margin-bottom: 22px; }
.adm-auth-brand .mark { width: 34px; height: 34px; border-radius: 9px;
  background: linear-gradient(150deg, var(--a-accent), var(--a-accent-d));
  display: grid; place-items: center; color: var(--a-on-accent); font-weight: 700; font-family: var(--a-mono); }
.adm-auth-brand div strong { display: block; font-size: 14px; color: var(--a-text); }
.adm-auth-brand div span { font-size: 11.5px; color: var(--a-muted); }
.adm-auth-box h1 { font-size: 17px; font-weight: 600; margin: 0 0 18px; color: var(--a-text); }
.adm-auth-box .field label { color: var(--a-text-2); }
.adm-auth-box input:not([type=checkbox]) {
  width: 100%; background: var(--a-surface-2); border: 1px solid var(--a-border-2);
  border-radius: var(--a-radius-sm); padding: 10px 12px; color: var(--a-text);
  font-size: 14px; font-family: var(--a-font); outline: none;
  transition: border-color .13s, box-shadow .13s;
}
.adm-auth-box input:focus { border-color: var(--a-accent); box-shadow: 0 0 0 3px var(--a-accent-soft); }
.adm-auth-box button[type=submit]:not(.btn) {
  width: 100%; background: var(--a-accent); color: var(--a-on-accent); border: none;
  border-radius: var(--a-radius-sm); padding: 11px; font-weight: 600; font-size: 14px;
  cursor: pointer; margin-top: 6px; font-family: var(--a-font);
}
.adm-auth-box button[type=submit]:not(.btn):hover { background: var(--a-accent-h); }

/* Responsività: sidebar collassata su schermi stretti */
@media (max-width: 820px){
  .adm-sidebar { width: 62px; }
  .adm-brand .txt, .adm-navlabel, .adm-sidebar a.adm-link .lab, .adm-sidebar .foot a .lab { display: none; }
  .adm-sidebar a.adm-link { justify-content: center; padding: 10px; margin: 1px 8px; }
  .adm-brand { justify-content: center; padding: 2px 0 16px; }
  .adm-content { padding: 18px; }
}
