/* ============================================================
   Orange Frog · Gestionale — design system
   Colori società: arancione racing su nero, neutri caldi.
   ============================================================ */

:root {
  /* Brand */
  --brand: #F97316;
  --brand-strong: #EA580C;
  --brand-deep: #C2410C;
  --brand-soft: rgba(249, 115, 22, 0.12);
  --brand-grad: linear-gradient(135deg, #F97316 0%, #EA580C 100%);

  /* Neri / neutri */
  --ink: #17171b;
  --side: #0c0c10;
  --side-text: #9d9da8;
  --side-text-active: #ffffff;

  /* Tema chiaro */
  --bg: #faf9f6;
  --surface: #ffffff;
  --surface-2: #f4f3ef;
  --border: #e8e6e1;
  --text: #1c1c22;
  --text-mut: #6e6d78;

  /* Semantici (separati dall'accento) */
  --ok: #16a34a;      --ok-soft: rgba(22, 163, 74, 0.12);
  --warn: #d97706;    --warn-soft: rgba(217, 119, 6, 0.14);
  --danger: #dc2626;  --danger-soft: rgba(220, 38, 38, 0.12);
  --info: #2563eb;    --info-soft: rgba(37, 99, 235, 0.12);

  /* Forma e ombre */
  --radius: 14px;
  --radius-sm: 9px;
  --shadow-sm: 0 1px 2px rgba(20, 20, 28, 0.05);
  --shadow-md: 0 6px 24px rgba(20, 20, 28, 0.08);

  /* Tipografia */
  --font-display: "Saira Condensed", "Arial Narrow", sans-serif;
  --font-body: "Archivo", system-ui, -apple-system, sans-serif;
  --font-mono: ui-monospace, "SF Mono", "Cascadia Mono", "Roboto Mono", monospace;

  --sidebar-w: 232px;
  --topbar-h: 64px;
}

:root.dark {
  --bg: #0f0f14;
  --surface: #17171d;
  --surface-2: #1e1e26;
  --border: #2a2a33;
  --text: #ececef;
  --text-mut: #9a9aa5;
  --side: #0a0a0e;
  --side-text: #8f8f9b;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 8px 30px rgba(0, 0, 0, 0.45);
  --brand-soft: rgba(249, 115, 22, 0.16);
}

/* ---------- Base ---------- */
* { box-sizing: border-box; }
/* L'attributo `hidden` deve sempre vincere sui `display` espliciti (es. #login/#shell grid),
   altrimenti login e dashboard restano entrambi visibili impilati. */
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4 { font-family: var(--font-display); font-weight: 600; margin: 0; text-wrap: balance; }
h1 { font-size: 28px; letter-spacing: 0.2px; }
h2 { font-size: 21px; letter-spacing: 0.2px; }
h3 { font-size: 17px; letter-spacing: 0.3px; }
p { margin: 0 0 10px; }
a { color: var(--brand-strong); text-decoration: none; }
a:hover { text-decoration: underline; }
code, .mono { font-family: var(--font-mono); font-size: 0.92em; }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; border-radius: 4px; }
::selection { background: var(--brand-soft); }
.num { font-variant-numeric: tabular-nums; }

/* ---------- Layout ---------- */
#shell { display: grid; grid-template-columns: var(--sidebar-w) 1fr; min-height: 100vh; animation: shell-in 240ms ease-out; }
@keyframes shell-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { #shell { animation: none; } }

.sidebar {
  background: var(--side);
  color: var(--side-text);
  display: flex;
  flex-direction: column;
  padding: 18px 14px;
  gap: 18px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.brand { display: flex; align-items: center; gap: 10px; padding: 4px 6px; }
.brand-mark {
  width: 40px; height: 40px; flex: none;
  display: grid; place-items: center;
  border-radius: 11px;
  background: var(--brand-grad);
  color: #fff;
  font-family: var(--font-display); font-weight: 700; font-size: 17px; letter-spacing: 0.5px;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.05; }
.brand-text strong { color: #fff; font-family: var(--font-display); font-weight: 700; font-size: 15px; letter-spacing: 1.2px; }
.brand-text small { font-size: 11px; color: var(--side-text); letter-spacing: 0.2px; }

.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-label {
  font-size: 11px; text-transform: uppercase; letter-spacing: 1.4px;
  color: #5c5c68; padding: 10px 10px 4px; font-weight: 600;
}
.nav a {
  display: flex; align-items: center; gap: 11px;
  padding: 9px 10px; border-radius: var(--radius-sm);
  color: var(--side-text); font-weight: 500; font-size: 14px;
  border-left: 3px solid transparent;
  transition: background 0.15s, color 0.15s;
}
.nav a svg { width: 18px; height: 18px; flex: none; }
.nav a:hover { background: rgba(255, 255, 255, 0.05); color: #fff; text-decoration: none; }
.nav a.active { background: var(--brand-soft); color: #fff; border-left-color: var(--brand); }
.nav a .badge-count {
  margin-left: auto; font-size: 11px; font-weight: 600;
  background: var(--brand); color: #fff; border-radius: 20px;
  padding: 1px 7px; font-variant-numeric: tabular-nums;
}

.sidebar-foot { margin-top: auto; display: flex; flex-direction: column; gap: 10px; padding-top: 12px; border-top: 1px solid rgba(255,255,255,0.07); }
.user-chip { display: flex; align-items: center; gap: 9px; padding: 6px 8px; }
.user-avatar {
  width: 32px; height: 32px; flex: none; border-radius: 50%;
  background: var(--brand-grad); color: #fff;
  display: grid; place-items: center; font-weight: 700; font-size: 13px;
}
.user-chip .u-name { color: #fff; font-weight: 600; font-size: 13px; line-height: 1.1; }
.user-chip .u-role { color: var(--side-text); font-size: 11px; text-transform: capitalize; }
.user-chip .u-block { display: flex; flex-direction: column; line-height: 1.15; min-width: 0; }
.user-chip .u-block .u-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.main { display: flex; flex-direction: column; min-width: 0; }

.topbar {
  height: var(--topbar-h); display: flex; align-items: center; justify-content: space-between;
  padding: 0 28px; border-bottom: 1px solid var(--border); background: var(--surface);
  position: sticky; top: 0; z-index: 20;
}
.page-title { font-size: 24px; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }

.content { padding: 26px 28px 60px; width: 100%; }

/* Dashboard a pagina intera: riempie l'altezza e affianca le sezioni basse
   (scadenze + movimenti/comunicazioni). Il contenuto è a larghezza piena ovunque. */
#main.wide { min-height: calc(100vh - var(--topbar-h)); }
.dash-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; align-items: start; }
@media (max-width: 900px) { .dash-2 { grid-template-columns: 1fr; } }

/* ---------- Card ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow-sm);
  padding: 20px;
}
.card + .card { margin-top: 18px; }
.card-header { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-bottom: 16px; }
.card-title { font-size: 17px; display: flex; align-items: center; gap: 8px; }

.grid { display: grid; gap: 18px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 980px) { .grid-4 { grid-template-columns: repeat(2, minmax(0,1fr)); } .grid-3 { grid-template-columns: repeat(2, minmax(0,1fr)); } }
@media (max-width: 640px) { .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; } }

/* ---------- Stat tiles ---------- */
.stat {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow-sm);
  position: relative; overflow: hidden;
}
.stat::after {
  content: ""; position: absolute; inset: auto 0 0 0; height: 3px;
  background: var(--brand-grad); opacity: 0.9;
}
.stat .stat-label { font-size: 12px; text-transform: uppercase; letter-spacing: 1.1px; color: var(--text-mut); font-weight: 600; }
.stat .stat-value { font-family: var(--font-display); font-size: 34px; font-weight: 700; line-height: 1.1; margin-top: 4px; font-variant-numeric: tabular-nums; }
.stat .stat-sub { font-size: 12.5px; color: var(--text-mut); margin-top: 2px; }
.stat.warn .stat-value { color: var(--warn); }
.stat.danger .stat-value { color: var(--danger); }
.stat.ok .stat-value { color: var(--ok); }

/* ---------- Tabelle ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
table.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
.tbl th {
  text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.9px;
  color: var(--text-mut); font-weight: 600; padding: 11px 14px;
  border-bottom: 1px solid var(--border); background: var(--surface-2); white-space: nowrap;
}
.tbl td { padding: 11px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.tbl tbody tr:last-child td { border-bottom: none; }
.tbl tbody tr:hover { background: var(--brand-soft); }
.tbl .row-click { cursor: pointer; }
.tbl .strong { font-weight: 600; }
.tbl .mut { color: var(--text-mut); font-size: 13px; }

/* ---------- Badge / pill ---------- */
.pill {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; font-weight: 600; border-radius: 20px; padding: 3px 10px;
  white-space: nowrap;
}
.pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; opacity: 0.85; }
.pill.ok    { background: var(--ok-soft);    color: var(--ok); }
.pill.warn  { background: var(--warn-soft);  color: var(--warn); }
.pill.danger{ background: var(--danger-soft); color: var(--danger); }
.pill.info  { background: var(--info-soft);  color: var(--info); }
.pill.neutral { background: var(--surface-2); color: var(--text-mut); }
.pill.neutral::before { display: none; }
.pill.brand { background: var(--brand-soft); color: var(--brand-deep); }
:root.dark .pill.brand { color: var(--brand); }

/* Semaforini della dashboard (certificato medico, iscrizione stagione). */
.semaforo {
  display: inline-block; width: 11px; height: 11px; border-radius: 50%;
  vertical-align: -1px; cursor: help;
}
.semaforo.ok      { background: var(--ok); }
.semaforo.warn    { background: var(--warn); }
.semaforo.danger  { background: var(--danger); }
.semaforo.neutral { background: var(--text-mut); }
.semaforo-label { font-size: 12px; color: var(--text-mut); }

/* ---------- Bottoni ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font-family: var(--font-body); font-size: 14px; font-weight: 600;
  padding: 9px 16px; border-radius: var(--radius-sm); border: 1px solid transparent;
  cursor: pointer; transition: background 0.15s, border-color 0.15s, transform 0.05s;
  white-space: nowrap;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn svg { width: 16px; height: 16px; }
.btn-primary { background: var(--brand-grad); color: #fff; box-shadow: var(--shadow-sm); }
.btn-primary:hover { filter: brightness(1.06); }
.btn-ghost { background: transparent; color: var(--text); border-color: var(--border); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-danger { background: var(--danger-soft); color: var(--danger); }
.btn-danger:hover { background: rgba(220, 38, 38, 0.2); }
.btn-sm { padding: 6px 11px; font-size: 13px; }
.btn-block { width: 100%; }
.icon-btn {
  display: inline-grid; place-items: center; width: 36px; height: 36px;
  border-radius: var(--radius-sm); border: 1px solid var(--border);
  background: var(--surface); color: var(--text-mut); cursor: pointer;
}
.icon-btn:hover { color: var(--brand-strong); border-color: var(--brand); }
.icon-btn svg { width: 18px; height: 18px; }
.icon-btn.ghost { background: transparent; border-color: transparent; }

/* ---------- Form ---------- */
.form-grid { display: grid; gap: 14px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form-grid .full { grid-column: 1 / -1; }
@media (max-width: 640px) { .form-grid { grid-template-columns: 1fr; } }
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 12.5px; font-weight: 600; color: var(--text-mut); }
.field input, .field select, .field textarea {
  font-family: var(--font-body); font-size: 14px; color: var(--text);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 9px 12px; transition: border-color 0.15s, box-shadow 0.15s;
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft);
}
.field input[readonly] { background: var(--surface-2); color: var(--text-mut); }
.field .hint { font-size: 12px; color: var(--text-mut); }
.form-actions { display: flex; gap: 10px; margin-top: 6px; }

/* ---------- Login ---------- */
#login {
  min-height: 100vh; display: grid; place-items: center;
  background:
    radial-gradient(900px 500px at 85% -10%, rgba(249, 115, 22, 0.22), transparent 60%),
    radial-gradient(700px 500px at -10% 110%, rgba(249, 115, 22, 0.12), transparent 55%),
    #0b0b0e;
  padding: 24px;
}
.login-card {
  width: 100%; max-width: 400px;
  background: #121218; border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 20px; padding: 34px 30px; box-shadow: 0 24px 70px rgba(0, 0, 0, 0.55);
}
.login-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 26px; }
.login-brand .brand-mark { width: 48px; height: 48px; border-radius: 13px; font-size: 20px; }
.login-brand strong { font-family: var(--font-display); font-size: 21px; letter-spacing: 2px; color: #fff; display: block; }
.login-brand small { color: #9d9da8; font-size: 12px; letter-spacing: 0.4px; }
.login-card h1 { color: #fff; font-size: 24px; margin-bottom: 4px; }
.login-card .login-sub { color: #9d9da8; font-size: 13.5px; margin-bottom: 22px; }
.login-card .field label { color: #b9b9c3; }
.login-card .field input {
  background: #1a1a22; border-color: rgba(255, 255, 255, 0.12); color: #fff; padding: 11px 13px;
}
.login-card .field input::placeholder { color: #666672; }
.login-error {
  background: var(--danger-soft); color: #fca5a5; border: 1px solid rgba(220, 38, 38, 0.3);
  border-radius: var(--radius-sm); padding: 9px 12px; font-size: 13px; margin-bottom: 14px; display: none;
}
.login-foot { margin-top: 18px; text-align: center; color: #6d6d78; font-size: 12.5px; }

/* ---------- Modal ---------- */
#modal-root { position: fixed; inset: 0; z-index: 60; display: none; align-items: center; justify-content: center; padding: 20px; }
#modal-root.open { display: flex; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(8, 8, 12, 0.55); backdrop-filter: blur(2px); }
.modal {
  position: relative; width: 100%; max-width: 520px; max-height: 90vh; overflow-y: auto;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow-md); padding: 24px;
}
.modal h2 { margin-bottom: 16px; }
.modal-close { position: absolute; top: 14px; right: 14px; }

/* ---------- Toast ---------- */
#toast-root { position: fixed; bottom: 20px; right: 20px; z-index: 80; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: var(--ink); color: #fff; border-radius: var(--radius-sm);
  padding: 12px 16px; font-size: 13.5px; box-shadow: var(--shadow-md);
  display: flex; align-items: center; gap: 9px; animation: toast-in 0.2s ease-out;
  max-width: 340px;
}
.toast.ok::before { content: ""; width: 9px; height: 9px; border-radius: 50%; background: var(--ok); }
.toast.error::before { content: ""; width: 9px; height: 9px; border-radius: 50%; background: var(--danger); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ---------- Wizard import ---------- */
.steps { display: flex; gap: 8px; margin-bottom: 22px; }
.step {
  flex: 1; display: flex; align-items: center; gap: 9px;
  padding: 10px 14px; border-radius: var(--radius-sm); border: 1px solid var(--border);
  background: var(--surface); color: var(--text-mut); font-size: 13.5px; font-weight: 600;
}
.step .step-n { width: 22px; height: 22px; border-radius: 50%; background: var(--surface-2); display: grid; place-items: center; font-size: 12px; font-variant-numeric: tabular-nums; }
.step.active { border-color: var(--brand); color: var(--brand-deep); }
.step.active .step-n { background: var(--brand-grad); color: #fff; }
.step.done { border-color: var(--ok); color: var(--ok); }
.step.done .step-n { background: var(--ok); color: #fff; }
:root.dark .step.active { color: var(--brand); }

.mapping-row {
  display: grid; grid-template-columns: 1fr auto 1fr; gap: 12px; align-items: center;
  padding: 9px 4px; border-bottom: 1px solid var(--border); font-size: 14px;
}
.mapping-row:last-child { border-bottom: none; }
.mapping-arrow { color: var(--text-mut); font-size: 16px; }
.mapping-row select { max-width: 100%; }
.preview-table { font-size: 13px; }

.dropzone {
  border: 2px dashed var(--border); border-radius: var(--radius);
  padding: 34px 20px; text-align: center; cursor: pointer; transition: border-color 0.15s, background 0.15s;
  background: var(--surface);
}
.dropzone:hover, .dropzone.dragover { border-color: var(--brand); background: var(--brand-soft); }
.dropzone .dz-icon { font-size: 30px; }
.dropzone p { margin: 8px 0 0; color: var(--text-mut); font-size: 13.5px; }
.dropzone strong { color: var(--text); }

/* ---------- Dettaglio atleta ---------- */
.kv-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 14px; }
.kv { display: flex; flex-direction: column; gap: 2px; }
.kv .k { font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.9px; color: var(--text-mut); font-weight: 600; }
.kv .v { font-size: 14.5px; font-weight: 500; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 18px; }
.tabs button {
  background: none; border: none; padding: 10px 14px; font-family: var(--font-body);
  font-size: 14px; font-weight: 600; color: var(--text-mut); cursor: pointer;
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tabs button.active { color: var(--brand-deep); border-bottom-color: var(--brand); }
:root.dark .tabs button.active { color: var(--brand); }

/* ---------- Varie ---------- */
.empty { text-align: center; color: var(--text-mut); padding: 34px 16px; font-size: 14px; }
.empty .empty-icon { font-size: 28px; margin-bottom: 6px; }
.muted { color: var(--text-mut); }
.row-tools { display: flex; gap: 8px; align-items: center; }
.flex { display: flex; align-items: center; gap: 10px; }
.spacer { flex: 1; }
.skeleton { background: var(--surface-2); border-radius: 8px; animation: pulse 1.2s infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.45; } }
.search-input { max-width: 260px; }
@media (max-width: 720px) {
  #shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; z-index: 40; width: var(--sidebar-w); transform: translateX(-100%); transition: transform 0.2s; }
  .sidebar.open { transform: none; }
  .content, .topbar { padding-left: 16px; padding-right: 16px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001s !important; transition-duration: 0.001s !important; }
}

/* ---------- Extra ---------- */
.modal-wide { max-width: 760px; }
.notice { border-radius: var(--radius-sm); padding: 10px 14px; font-size: 13.5px; border: 1px solid; }
.notice.warn { background: var(--warn-soft); border-color: rgba(217, 119, 6, 0.3); color: var(--warn); }
.tbl select, .field-select {
  font-family: var(--font-body); font-size: 13px; color: var(--text);
  background: var(--surface); border: 1px solid var(--border); border-radius: 6px; padding: 6px 8px;
  max-width: 100%;
}
.tbl select:focus, .field-select:focus { outline: none; border-color: var(--brand); }
