/* =====================================================================
   Componenti riutilizzabili: card, stat, tabelle, bottoni, badge, form
   ===================================================================== */

/* Intestazione pagina */
.page-head {
  display: flex; flex-wrap: wrap; gap: var(--sp-3);
  align-items: flex-end; justify-content: space-between;
  margin-bottom: var(--sp-5);
}
.page-head__title { font-size: var(--fs-2xl); font-weight: 700; letter-spacing: -.4px; }
.page-head__sub { color: var(--text-muted); margin-top: 2px; }
.page-head__actions { display: flex; gap: var(--sp-2); flex-wrap: wrap; }

/* Griglie */
.grid { display: grid; gap: var(--sp-4); }
.grid--stats { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.grid--2 { grid-template-columns: 1fr; }
@media (min-width: 900px) { .grid--2 { grid-template-columns: 1.4fr 1fr; } }

/* Card */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow-sm);
}
.card__head {
  display: flex; align-items: center; justify-content: space-between;
  padding: var(--sp-4); border-bottom: 1px solid var(--border);
}
.card__title { font-weight: 600; }
.card__body { padding: var(--sp-4); }
.card__link { font-size: var(--fs-sm); color: var(--brand); font-weight: 600; }

/* Stat */
.stat { padding: var(--sp-4); }
.stat__head { display: flex; align-items: center; justify-content: space-between; margin-bottom: var(--sp-3); }
.stat__label { color: var(--text-muted); font-size: var(--fs-sm); font-weight: 500; }
.stat__icon {
  width: 34px; height: 34px; border-radius: 9px; display: grid; place-items: center;
  color: var(--brand); background: color-mix(in srgb, var(--brand) 14%, transparent);
}
.stat__value { font-size: var(--fs-2xl); font-weight: 700; letter-spacing: -.5px; }
.stat__meta { color: var(--text-faint); font-size: var(--fs-sm); margin-top: 2px; }

/* Tabelle */
.table-wrap { width: 100%; overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: var(--fs-sm); }
.table th, .table td { padding: 11px var(--sp-4); text-align: left; white-space: nowrap; }
.table thead th {
  color: var(--text-muted); font-weight: 600; font-size: var(--fs-xs);
  text-transform: uppercase; letter-spacing: .5px;
  border-bottom: 1px solid var(--border); background: var(--surface-2);
}
.table tbody tr { border-bottom: 1px solid var(--border); }
.table tbody tr:last-child { border-bottom: 0; }
.table tbody tr:hover { background: var(--surface-2); }
.table .col-actions { text-align: right; }

/* Bottoni */
.btn {
  display: inline-flex; align-items: center; gap: var(--sp-2);
  padding: 9px 14px; border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong); background: var(--surface);
  color: var(--text); font-weight: 600; font-size: var(--fs-sm);
  cursor: pointer; transition: background .15s, border-color .15s, transform .05s;
}
.btn:hover { background: var(--surface-2); color: var(--text); }
.btn:active { transform: translateY(1px); }
.btn--primary { background: var(--brand); border-color: var(--brand); color: var(--brand-contrast); }
.btn--primary:hover { background: var(--brand-600); color: var(--brand-contrast); }
.btn--danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn--sm { padding: 5px 10px; font-size: var(--fs-xs); }
.btn--ghost { border-color: transparent; background: transparent; }

.icon-btn {
  width: 38px; height: 38px; border-radius: var(--radius-sm);
  display: inline-grid; place-items: center; cursor: pointer;
  border: 1px solid transparent; background: transparent; color: var(--text-muted);
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

/* Badge / stati */
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 9px; border-radius: 999px; font-size: var(--fs-xs); font-weight: 600;
  background: var(--surface-2); color: var(--text-muted);
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge--success { color: var(--success); background: var(--success-bg); }
.badge--warning { color: var(--warning); background: var(--warning-bg); }
.badge--danger  { color: var(--danger);  background: var(--danger-bg); }
.badge--info    { color: var(--info);    background: var(--info-bg); }
.badge--muted   { color: var(--text-faint); }

/* Form */
.form { display: flex; flex-direction: column; gap: var(--sp-4); max-width: 560px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-weight: 600; font-size: var(--fs-sm); }
.field .hint { font-size: var(--fs-xs); color: var(--text-faint); }
.input, .select, .textarea {
  width: 100%; padding: 10px 12px; border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  transition: border-color .15s, box-shadow .15s;
}
.input:focus, .select:focus, .textarea:focus {
  outline: none; border-color: var(--brand);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 22%, transparent);
}
.field-row { display: flex; gap: var(--sp-3); flex-wrap: wrap; }
.field-row .field { flex: 1; min-width: 160px; }
.check { display: flex; align-items: center; gap: var(--sp-2); }
.check input { width: 16px; height: 16px; accent-color: var(--brand); }
.form__actions { display: flex; gap: var(--sp-2); }

/* Toolbar filtri */
.toolbar {
  display: flex; gap: var(--sp-2); flex-wrap: wrap; align-items: center;
  margin-bottom: var(--sp-4);
}
.toolbar .search { flex: 1; min-width: 200px; max-width: 360px; }

/* Flash */
.flash {
  padding: 11px var(--sp-4); border-radius: var(--radius-sm);
  margin-bottom: var(--sp-4); font-size: var(--fs-sm); font-weight: 500;
  border: 1px solid transparent;
}
.flash--success { color: var(--success); background: var(--success-bg); border-color: color-mix(in srgb, var(--success) 30%, transparent); }
.flash--error   { color: var(--danger);  background: var(--danger-bg);  border-color: color-mix(in srgb, var(--danger) 30%, transparent); }

/* Empty state */
.empty { text-align: center; padding: var(--sp-7) var(--sp-4); color: var(--text-muted); }
.empty__title { font-weight: 600; color: var(--text); margin-bottom: 4px; }

/* Lista media compatta */
.media-list { display: flex; flex-direction: column; }
.media-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--sp-3); padding: 10px 0; border-bottom: 1px solid var(--border);
}
.media-row:last-child { border-bottom: 0; }
.media-row__title { font-weight: 500; }
.media-row__meta { font-size: var(--fs-xs); color: var(--text-faint); }

.pill { font-size: var(--fs-xs); padding: 2px 8px; border-radius: 6px; background: var(--surface-2); color: var(--text-muted); }

/* Banner info (es. DB non configurato) */
.notice {
  display: flex; gap: var(--sp-3); align-items: flex-start;
  padding: var(--sp-4); border-radius: var(--radius);
  background: var(--info-bg); color: var(--info); margin-bottom: var(--sp-5);
  border: 1px solid color-mix(in srgb, var(--info) 25%, transparent);
}
.notice strong { color: var(--info); }
.notice .icon { margin-top: 2px; }

/* Cella con logo/thumbnail (es. canali stream) */
.cell-media { display: flex; align-items: center; gap: var(--sp-3); }
.cell-logo {
  width: 34px; height: 34px; flex: 0 0 34px; border-radius: 8px; object-fit: cover;
  background: var(--surface-2); border: 1px solid var(--border);
}
.cell-logo--ph {
  display: grid; place-items: center; color: var(--text-faint);
  font-weight: 700; font-size: var(--fs-sm);
}

/* Azioni multiple in riga tabella */
.row-actions { display: flex; gap: 6px; justify-content: flex-end; align-items: center; }
.row-actions form { display: inline; }

/* Form largo (es. bouquet con checklist) */
.form--wide { max-width: 920px; }

/* Checklist raggruppata (selezione canali) */
.checklist {
  display: grid; gap: var(--sp-3);
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
}
.checklist__group { border: 1px solid var(--border); border-radius: var(--radius-sm); overflow: hidden; }
.checklist__head {
  display: flex; align-items: center; gap: var(--sp-2);
  padding: 9px var(--sp-3); background: var(--surface-2);
  font-weight: 600; font-size: var(--fs-sm); cursor: pointer;
}
.checklist__head .pill { margin-left: auto; }
.checklist__items { max-height: 210px; overflow-y: auto; padding: 6px var(--sp-3); }
.check-row { display: flex; align-items: center; gap: var(--sp-2); padding: 4px 0; font-size: var(--fs-sm); cursor: pointer; }
.check-row input, .checklist__head input { width: 16px; height: 16px; accent-color: var(--brand); }

/* Meter / barra di carico */
.meter { height: 8px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.meter__fill { height: 100%; border-radius: 999px; transition: width .3s; }
.meter__fill--ok { background: var(--success); }
.meter__fill--warning { background: var(--warning); }
.meter__fill--danger { background: var(--danger); }
.meter-row { display: flex; flex-direction: column; gap: 5px; }
.meter-row__label { display: flex; justify-content: space-between; font-size: var(--fs-xs); color: var(--text-muted); }

/* Griglia + card server */
.srv-grid { grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); }
.srv-card { padding: var(--sp-4); display: flex; flex-direction: column; gap: var(--sp-4); }
.srv-card__head { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--sp-3); }
.srv-card__name { font-weight: 700; font-size: var(--fs-lg); display: flex; align-items: center; gap: var(--sp-2); }
.srv-card__host { font-size: var(--fs-xs); color: var(--text-muted); margin-top: 3px; }
.srv-card__meters { display: flex; flex-direction: column; gap: var(--sp-3); }
.srv-card__foot { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-2); padding-top: var(--sp-3); border-top: 1px solid var(--border); }
.srv-card__bw { display: inline-flex; align-items: center; gap: 6px; font-size: var(--fs-sm); color: var(--text-muted); }
.srv-card__bw .icon { width: 15px; height: 15px; }

.pill--brand { background: color-mix(in srgb, var(--brand) 16%, transparent); color: var(--brand); font-weight: 700; }

/* Account box come link al profilo */
a.sidebar__account { text-decoration: none; color: inherit; cursor: pointer; transition: background .15s; }
a.sidebar__account:hover { background: var(--surface-2); }
a.sidebar__account.is-active { background: var(--surface-2); }

/* Thread ticket */
.thread { display: flex; flex-direction: column; gap: var(--sp-3); }
.thread__msg { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: var(--sp-3); background: var(--surface); }
.thread__msg--admin { background: var(--info-bg); border-color: color-mix(in srgb, var(--info) 22%, transparent); }
.thread__msg--reseller { background: var(--surface-2); }
.thread__head { display: flex; align-items: center; gap: var(--sp-2); font-size: var(--fs-sm); margin-bottom: 6px; }
.thread__time { margin-left: auto; color: var(--text-faint); font-size: var(--fs-xs); }
.thread__body { font-size: var(--fs-sm); color: var(--text); }

/* Utility colore testo */
.txt-ok { color: var(--success); }
.txt-warning { color: var(--warning); }
.txt-danger { color: var(--danger); }

/* Righe chiave-valore (dettagli) */
.kv { display: flex; justify-content: space-between; gap: var(--sp-3); padding: 9px 0; border-bottom: 1px solid var(--border); font-size: var(--fs-sm); }
.kv:last-child { border-bottom: 0; }
.kv > span { color: var(--text-muted); }
.kv > b { text-align: right; }
.inline-form { display: inline-flex; align-items: center; gap: 6px; }

/* Tabs */
.tabs { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: var(--sp-4); border-bottom: 1px solid var(--border); }
.tab {
  display: inline-flex; align-items: center; gap: var(--sp-2);
  padding: 9px 14px; font-size: var(--fs-sm); font-weight: 600; color: var(--text-muted);
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tab:hover { color: var(--text); }
.tab.is-active { color: var(--brand); border-bottom-color: var(--brand); }
.tab .pill { font-weight: 700; }
