/* ===== Reset & base ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; }
body { font-family: system-ui, -apple-system, "Segoe UI", sans-serif; background: #f0f4f8; color: #1a2a3a; min-height: 100vh; }
a { color: #2980b9; text-decoration: none; }
a:hover { text-decoration: underline; }

/* ===== Variabili colore ===== */
:root {
  --navy: #1e3a5f;
  --blue: #2980b9;
  --blue-light: #5dade2;
  --green: #27ae60;
  --orange: #e67e22;
  --red: #c0392b;
  --purple: #8e44ad;
  --gray: #7f8c8d;
  --bg: #f0f4f8;
  --surface: #ffffff;
  --border: #d1dce8;
  --sidebar-w: 220px;
}

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

/* ===== Sidebar ===== */
.sidebar {
  width: var(--sidebar-w);
  background: var(--navy);
  color: #c8dff5;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  overflow-y: auto;
}
.sidebar-brand {
  padding: 1.25rem 1rem;
  font-size: 1.1rem;
  font-weight: 700;
  color: #fff;
  border-bottom: 1px solid rgba(255,255,255,.1);
  letter-spacing: .02em;
}
.sidebar-brand small { display: block; font-size: .7rem; font-weight: 400; opacity: .7; margin-top: .15rem; }
.sidebar-nav { flex: 1; padding: .5rem 0; }
.sidebar-nav a {
  display: block;
  padding: .6rem 1.1rem;
  color: #c8dff5;
  font-size: .9rem;
  transition: background .15s;
  border-radius: 4px;
  margin: .1rem .4rem;
}
.sidebar-nav a:hover, .sidebar-nav a.active { background: rgba(255,255,255,.12); color: #fff; text-decoration: none; }
.sidebar-nav .nav-section { padding: .8rem 1.1rem .3rem; font-size: .7rem; text-transform: uppercase; letter-spacing: .08em; opacity: .5; }
.sidebar-footer { padding: .8rem 1rem; border-top: 1px solid rgba(255,255,255,.1); font-size: .8rem; }
.sidebar-footer a { color: #c8dff5; }

/* ===== Main content ===== */
.main { margin-left: var(--sidebar-w); flex: 1; display: flex; flex-direction: column; }
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: .75rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar h1 { font-size: 1.1rem; font-weight: 600; color: var(--navy); }
.content { padding: 1.5rem; flex: 1; }

/* ===== Pagine pubbliche (login, registrazione) ===== */
.public-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 1rem;
}
.public-card {
  background: var(--surface);
  border-radius: 10px;
  box-shadow: 0 4px 24px rgba(0,0,0,.12);
  padding: 2.5rem 2rem;
  width: 100%;
  max-width: 420px;
}
.public-card .logo {
  text-align: center;
  margin-bottom: 1.5rem;
}
.public-card .logo h1 { font-size: 1.8rem; color: var(--navy); font-weight: 800; }
.public-card .logo p  { font-size: .85rem; color: var(--gray); margin-top: .3rem; }

/* ===== Card ===== */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1.25rem;
  margin-bottom: 1rem;
}
.card-title { font-size: .95rem; font-weight: 600; margin-bottom: .9rem; color: var(--navy); }

/* ===== Form elements ===== */
.form-group { margin-bottom: .9rem; }
.form-group label { display: block; font-size: .82rem; font-weight: 600; margin-bottom: .3rem; color: #345; }
input[type=text], input[type=password], input[type=email], input[type=number],
input[type=tel], input[type=date], input[type=time], input[type=datetime-local], input[type=file], select, textarea {
  display: block; width: 100%;
  padding: .5rem .7rem;
  border: 1px solid var(--border);
  border-radius: 5px;
  font-size: .9rem;
  font-family: inherit;
  color: #1a2a3a;
  background: #fff;
  transition: border-color .15s;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--blue); box-shadow: 0 0 0 2px rgba(41,128,185,.2); }
textarea { resize: vertical; min-height: 80px; }

/* ===== Buttons ===== */
.btn {
  display: inline-block;
  padding: .5rem 1.1rem;
  border-radius: 5px;
  border: none;
  cursor: pointer;
  font-size: .88rem;
  font-family: inherit;
  font-weight: 600;
  transition: opacity .15s, background .15s;
  line-height: 1.4;
}
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary   { background: var(--blue);   color: #fff; }
.btn-primary:hover   { background: #1f6fa0; }
.btn-success   { background: var(--green);  color: #fff; }
.btn-success:hover   { background: #1e8449; }
.btn-danger    { background: var(--red);    color: #fff; }
.btn-danger:hover    { background: #a93226; }
.btn-warning   { background: var(--orange); color: #fff; }
.btn-warning:hover   { background: #ca6f1e; }
.btn-ghost     { background: transparent; border: 1px solid var(--border); color: #345; }
.btn-ghost:hover     { background: var(--bg); }
.btn-sm        { padding: .3rem .7rem; font-size: .8rem; }
.btn-full      { display: block; width: 100%; text-align: center; }

/* ===== Toolbar ===== */
.toolbar { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; margin-bottom: 1rem; }

/* ===== Tabella ===== */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .88rem; }
th { background: #eaf0f7; color: #345; font-weight: 600; padding: .55rem .75rem; text-align: left; border-bottom: 2px solid var(--border); white-space: nowrap; }
td { padding: .5rem .75rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: #f7fbff; }

/* ===== Badge stato ===== */
.badge {
  display: inline-block;
  padding: .18rem .55rem;
  border-radius: 20px;
  font-size: .75rem;
  font-weight: 600;
  white-space: nowrap;
}
.badge-green  { background: #d5f5e3; color: #1e8449; }
.badge-blue   { background: #d6eaf8; color: #1f6fa0; }
.badge-orange { background: #fdebd0; color: #ca6f1e; }
.badge-red    { background: #fad7d7; color: #a93226; }
.badge-purple { background: #e8d5f5; color: #7d3c98; }
.badge-gray   { background: #eaecee; color: #566573; }

/* ===== Alert ===== */
.alert { padding: .75rem 1rem; border-radius: 6px; font-size: .88rem; margin-bottom: 1rem; }
.alert-error   { background: #fad7d7; color: #922b21; border: 1px solid #f1948a; }
.alert-success { background: #d5f5e3; color: #1e8449; border: 1px solid #82e0aa; }
.alert-info    { background: #d6eaf8; color: #1a5276; border: 1px solid #85c1e9; }
.alert-warning { background: #fdebd0; color: #935116; border: 1px solid #f0b27a; }

/* ===== Toast ===== */
.toast {
  position: fixed;
  bottom: 1.5rem; right: 1.5rem;
  padding: .7rem 1.2rem;
  border-radius: 7px;
  font-size: .88rem;
  font-weight: 600;
  color: #fff;
  z-index: 9999;
  animation: slideIn .2s ease;
  box-shadow: 0 4px 12px rgba(0,0,0,.2);
}
.toast-info    { background: var(--blue); }
.toast-success { background: var(--green); }
.toast-error   { background: var(--red); }
@keyframes slideIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

/* ===== Modal ===== */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.45);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000;
}
.modal-backdrop.hidden { display: none; }
.modal {
  background: var(--surface);
  border-radius: 10px;
  padding: 1.75rem;
  width: 100%; max-width: 500px;
  max-height: 90vh; overflow-y: auto;
  box-shadow: 0 8px 40px rgba(0,0,0,.2);
}
.modal-title { font-size: 1rem; font-weight: 700; margin-bottom: 1.1rem; color: var(--navy); }
.modal-footer { margin-top: 1.2rem; display: flex; gap: .5rem; justify-content: flex-end; }

/* ===== Stat cards (dashboard) ===== */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 1rem; margin-bottom: 1.5rem; }
.stat-card { background: var(--surface); border-radius: 8px; border: 1px solid var(--border); padding: 1.1rem 1.2rem; }
.stat-card .stat-label { font-size: .78rem; color: var(--gray); font-weight: 600; text-transform: uppercase; letter-spacing: .05em; }
.stat-card .stat-value { font-size: 1.8rem; font-weight: 700; color: var(--navy); margin-top: .2rem; }
.stat-card .stat-sub   { font-size: .78rem; color: var(--gray); margin-top: .2rem; }

/* ===== Gara card (calendario) ===== */
.gara-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 1rem; }
.gara-card { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 1.1rem; display: flex; flex-direction: column; gap: .4rem; }
.gara-card .gara-title { font-size: 1rem; font-weight: 700; color: var(--navy); }
.gara-card .gara-meta  { font-size: .82rem; color: var(--gray); }
.gara-card .gara-desc  { font-size: .85rem; color: #444; }
.gara-card .gara-footer { margin-top: .5rem; display: flex; gap: .4rem; flex-wrap: wrap; align-items: center; }

/* ===== Checkbox list (selezione atleti) ===== */
.check-list { border: 1px solid var(--border); border-radius: 6px; max-height: 260px; overflow-y: auto; }
.check-list label { display: flex; align-items: center; gap: .6rem; padding: .5rem .75rem; cursor: pointer; border-bottom: 1px solid var(--border); font-size: .88rem; }
.check-list label:last-child { border-bottom: none; }
.check-list label:hover { background: var(--bg); }
.check-list input[type=checkbox] { width: auto; }

/* ===== Tabs ===== */
.tabs { display: flex; border-bottom: 2px solid var(--border); margin-bottom: 1.2rem; gap: .1rem; }
.tab-btn { background: none; border: none; padding: .55rem 1rem; font-size: .88rem; font-weight: 600; color: var(--gray); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -2px; }
.tab-btn.active { color: var(--blue); border-bottom-color: var(--blue); }
.tab-panel.hidden { display: none; }

/* ===== Utilities ===== */
.flex { display: flex; }
.gap-sm { gap: .5rem; }
.gap-md { gap: 1rem; }
.mt-1 { margin-top: .5rem; }
.mt-2 { margin-top: 1rem; }
.text-sm { font-size: .82rem; }
.text-gray { color: var(--gray); }
.text-right { text-align: right; }
.hidden { display: none !important; }
.w-full { width: 100%; }
.empty-state { text-align: center; padding: 2.5rem; color: var(--gray); font-size: .9rem; }

/* ===== Spinner ===== */
@keyframes spin { to { transform: rotate(360deg); } }
.spinner {
  display: inline-block;
  width: 1em; height: 1em;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin .7s linear infinite;
  vertical-align: middle;
  margin-right: .4em;
  flex-shrink: 0;
}

/* ===== Guida ===== */
.guida-page { max-width: 760px; margin: 0 auto; padding: 1.5rem; font-size: 1.05rem; line-height: 1.6; }
.guida-page h1 { color: var(--navy); font-size: 1.6rem; margin-bottom: .3rem; }
.guida-page .guida-intro { color: var(--gray); margin-bottom: 1.3rem; }
.guida-search { width: 100%; padding: .7rem .9rem; font-size: 1.05rem; border: 1px solid var(--border); border-radius: 6px; margin-bottom: 1.5rem; }
.guida-toc { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 1rem 1.2rem; margin-bottom: 1.5rem; }
.guida-toc-title { font-weight: 700; color: var(--navy); margin-bottom: .5rem; }
.guida-toc ul { margin: 0; padding-left: 1.2rem; }
.guida-toc li { margin-bottom: .25rem; }
.guida-section { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 1.3rem 1.4rem; margin-bottom: 1.2rem; scroll-margin-top: 1rem; }
.guida-section h2 { color: var(--navy); font-size: 1.2rem; margin-bottom: .6rem; }
.guida-section ol, .guida-section ul { padding-left: 1.4rem; margin: .5rem 0; }
.guida-section li { margin-bottom: .4rem; }
.guida-section.hidden { display: none; }
.guida-back { display: inline-block; margin-bottom: 1rem; }
.guida-fallback { margin-top: .5rem; font-size: .92rem; }
.guida-help-link {
  display: inline-flex; align-items: center; justify-content: center;
  width: 1.6rem; height: 1.6rem; border-radius: 50%;
  background: var(--blue); color: #fff; font-weight: 700; font-size: .85rem;
  text-decoration: none; vertical-align: middle;
}
.guida-help-link:hover { background: #1f6fa0; }

/* Barra dell'ingresso del Dev in un'utenza (ADR 0009) */
.imp-bar { background: var(--orange); color: #fff; padding: .55rem 1.5rem; display: flex; align-items: center; gap: 1rem; font-size: .88rem; position: sticky; top: 0; z-index: 50; }
.imp-bar b { font-weight: 700; }
.imp-bar .btn { background: #fff; color: #a04000; margin-left: auto; white-space: nowrap; }
