/* Dashboard di Burraco Insieme: fondo chiaro caldo, pannelli bianchi,
   verde del panno come unico accento. */
:root {
  color-scheme: light;
  --bg: #f5f5f2;
  --panel: #ffffff;
  --ink: #1b2420;
  --muted: #5d6762;
  --faint: #8a938e;
  --line: #e4e6e1;
  --accent: #0c7d40;
  --accent-dark: #075a2e;
  --accent-soft: #e5f2ea;
  --danger: #b3121b;
  --danger-soft: #fbe9ea;
  --radius: 14px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font-size: 15px; line-height: 1.45; }
a { color: var(--accent); }
a:hover { color: var(--accent-dark); }
code { font-size: 0.9em; background: #eef0ec; padding: 1px 6px; border-radius: 5px; }
h1 { font-size: 1.85rem; letter-spacing: -0.01em; margin: 0.15rem 0 0.4rem; }
h2 { font-size: 1.08rem; margin: 0 0 0.25rem; }
h3 { font-size: 0.95rem; margin: 1.1rem 0 0.4rem; }
small { display: block; color: var(--muted); font-size: 0.85rem; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.muted { color: var(--muted); }
.icon { flex: none; }

/* Barra laterale */
.shell { display: flex; min-height: 100vh; }
.side {
  width: 258px; flex: none; background: #fbfbf9; border-right: 1px solid var(--line);
  display: flex; flex-direction: column; padding: 22px 14px 16px; position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--ink); text-decoration: none; padding: 0 8px 26px; }
.brand img { border-radius: 9px; }
.brand strong { display: block; font-size: 1rem; }
.brand small { font-size: 0.8rem; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 9px; color: var(--ink); text-decoration: none; font-weight: 500; }
.nav a:hover { background: #eef1ec; }
.nav a[aria-current="page"] { background: var(--accent-soft); color: var(--accent-dark); font-weight: 600; }
.group { margin: 18px 12px 6px; font-size: 0.72rem; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--faint); }
.account { margin-top: auto; padding: 14px 8px 0; border-top: 1px solid var(--line); display: flex; align-items: center; gap: 10px; }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--ink); color: #fff; display: grid; place-items: center; font-weight: 700; flex: none; }
.account .who { flex: 1; min-width: 0; }
.account .mail { display: block; font-weight: 600; font-size: 0.85rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account small { font-size: 0.78rem; }
.icon-button { background: none; color: var(--muted); padding: 6px; min-height: 0; border-radius: 8px; display: grid; place-items: center; }
.icon-button:hover { background: #eef1ec; color: var(--ink); }

main { flex: 1; min-width: 0; padding: 40px 48px 56px; max-width: 1640px; }

/* Testata delle pagine */
.head { margin-bottom: 26px; }
.head.with-tools { display: flex; justify-content: space-between; align-items: flex-end; gap: 20px; flex-wrap: wrap; }
.eyebrow { margin: 0; text-transform: uppercase; letter-spacing: 0.1em; font-size: 0.74rem; font-weight: 600; color: var(--muted); }
.eyebrow a { color: var(--muted); }
.lede { margin: 0; color: var(--muted); max-width: 64ch; font-size: 1rem; }
.sub { margin: 0 0 12px; color: var(--muted); }

/* Pannelli e riquadri */
section { margin-bottom: 22px; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 22px 24px; }
.panel.flush { padding: 0; overflow: hidden; }
.panel .pad { padding: 18px 20px 6px; }
.panel-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.two { display: grid; grid-template-columns: repeat(auto-fit, minmax(380px, 1fr)); gap: 22px; }
.two section { margin: 0; }

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 16px; margin-bottom: 22px; }
.tile { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; display: flex; flex-direction: column; min-height: 132px; }
.tile .label { font-weight: 600; font-size: 0.92rem; }
.tile .value { font-size: 2rem; font-weight: 700; font-variant-numeric: tabular-nums; margin: 2px 0 6px; }
.tile .value.small { font-size: 1.05rem; margin-top: 8px; }
.tile .note { color: var(--muted); font-size: 0.85rem; }

.segmented { display: inline-flex; background: #ecede8; border-radius: 10px; padding: 3px; gap: 2px; }
.segmented a { padding: 7px 13px; border-radius: 8px; text-decoration: none; color: var(--muted); font-weight: 500; font-size: 0.9rem; }
.segmented a[aria-current="true"] { background: var(--panel); color: var(--ink); font-weight: 600; box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08); }

/* Grafici */
.charts { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 32px; margin-top: 18px; }
.chart { margin: 0; }
.chart figcaption { display: flex; justify-content: space-between; align-items: baseline; font-weight: 600; margin-bottom: 8px; }
.chart figcaption strong { font-size: 1.3rem; }
.plot { position: relative; padding-left: 28px; height: 140px; }
.axis { position: absolute; left: 0; font-size: 0.72rem; color: var(--faint); }
.axis.top { top: -6px; }
.axis.bottom { bottom: -6px; }
.bars {
  height: 100%; display: flex; align-items: flex-end; gap: 3px;
  border-bottom: 1px solid #cfd4cf; background-image: linear-gradient(to bottom, #e4e6e1 1px, transparent 1px);
  background-size: 100% 100%;
}
.bar { flex: 1; min-width: 2px; max-width: 14px; background: #1f6f4a; border-radius: 2px 2px 0 0; }
.dates { display: flex; justify-content: space-between; padding-left: 28px; margin-top: 8px; font-size: 0.78rem; color: var(--muted); }
.as-table { margin-top: 18px; }
.as-table summary { cursor: pointer; color: var(--muted); }

/* Classifiche */
.ranking { list-style: none; margin: 0; padding: 0; }
.ranking li { display: flex; align-items: center; gap: 16px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.ranking li:last-child { border-bottom: none; }
.ranking .pos { color: var(--faint); width: 18px; text-align: right; font-variant-numeric: tabular-nums; }
.ranking .who { flex: 1; min-width: 0; }
.ranking .who a { font-weight: 600; }
.ranking strong { font-variant-numeric: tabular-nums; }
.ranking .empty { color: var(--muted); }

/* Tabelle */
.toolbar { display: flex; align-items: center; gap: 12px; padding: 14px 20px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.search { display: flex; align-items: center; gap: 8px; border: 1px solid #cfd4cf; border-radius: 10px; padding: 0 12px; flex: 0 1 400px; color: var(--faint); background: #fff; }
.search input { border: none; padding: 10px 0; flex: 1; min-height: 42px; }
.search input:focus-visible { outline: none; }
.search:focus-within { outline: 3px solid #f0a500; outline-offset: 2px; }
.count { margin-left: auto; color: var(--muted); font-variant-numeric: tabular-nums; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 14px 20px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { font-size: 0.74rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); font-weight: 600; background: #fafaf8; }
th a { color: inherit; text-decoration: none; display: inline-flex; align-items: center; gap: 6px; }
th a:hover { color: var(--ink); }
.sort::after { content: "↕"; color: var(--faint); }
.sort.asc::after { content: "↑"; color: var(--ink); }
.sort.desc::after { content: "↓"; color: var(--ink); }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #fbfbf9; }
td .name { font-weight: 600; color: var(--ink); text-decoration: none; }
td .name:hover { text-decoration: underline; }
td small { margin-top: 2px; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.empty { color: var(--muted); text-align: center; padding: 28px; white-space: normal; }
.pager { display: flex; gap: 18px; }

.pill { display: inline-block; padding: 3px 10px; border-radius: 999px; background: #eef0ec; font-size: 0.8rem; font-weight: 600; color: var(--muted); }
.pill.on, .status-programmato { background: var(--accent-soft); color: var(--accent-dark); }
.pill.off, .status-annullato { background: var(--danger-soft); color: var(--danger); }
.status-concluso { background: #ecebf6; color: #3d2f8f; }

/* Feature flag */
.list details { border-bottom: 1px solid var(--line); }
.list details:last-child { border-bottom: none; }
.list summary { display: flex; align-items: center; gap: 18px; padding: 18px 22px; cursor: pointer; list-style: none; }
.list summary::-webkit-details-marker { display: none; }
.list summary:hover { background: #fbfbf9; }
.what { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.what span { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
details[open] .what span { white-space: normal; }
.scope { color: var(--muted); font-size: 0.9rem; }
.chev { color: var(--muted); display: grid; transition: transform 0.15s; }
details[open] .chev { transform: rotate(180deg); }
.body { padding: 0 22px 20px; }
.history { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.history li { display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap; }
.history .when { color: var(--muted); font-variant-numeric: tabular-nums; }
.history q { color: var(--muted); }

/* Moduli e pulsanti */
button, .button {
  font: inherit; font-weight: 600; border: none; border-radius: 10px; padding: 10px 18px; cursor: pointer;
  background: var(--accent); color: #fff; text-decoration: none; display: inline-block; min-height: 44px;
}
button:hover, .button:hover { background: var(--accent-dark); color: #fff; }
button.danger { background: var(--danger); }
input, select, textarea { font: inherit; padding: 10px 12px; border: 1px solid #cfd4cf; border-radius: 10px; background: #fff; color: var(--ink); min-height: 44px; }
:focus-visible { outline: 3px solid #f0a500; outline-offset: 2px; }
.inline { display: flex; gap: 8px; flex-wrap: wrap; max-width: 640px; }
.inline input { flex: 1 1 220px; }
.form { display: grid; gap: 6px; max-width: 600px; }
.form label { font-weight: 600; margin-top: 10px; }
.actions { display: flex; gap: 14px; align-items: center; margin-top: 16px; }
.banner { background: #fff7e0; border: 1px solid #f0d27a; border-radius: 10px; padding: 12px 16px; }
.banner.error { background: var(--danger-soft); border-color: #f0b5b8; color: var(--danger); }
.banner ul { margin: 0; padding-left: 18px; }

/* Accesso */
.login { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 18px; padding: 34px; max-width: 420px; width: 100%; display: flex; flex-direction: column; gap: 16px; }
.card h1 { margin: 0; }
.card .lede { margin: 0; }
.dev { display: flex; flex-direction: column; gap: 6px; border-top: 1px solid var(--line); padding-top: 16px; }

@media (max-width: 860px) {
  .shell { flex-direction: column; }
  .side { width: auto; height: auto; position: static; flex-direction: row; flex-wrap: wrap; align-items: center; gap: 8px 12px; border-right: none; border-bottom: 1px solid var(--line); padding: 12px 16px; }
  .brand { padding: 0; }
  .nav { flex-direction: row; flex-wrap: wrap; order: 3; width: 100%; }
  .nav a { padding: 8px 10px; }
  .group { display: none; }
  .account { margin: 0 0 0 auto; border: none; padding: 0; }
  .account .who { display: none; }
  main { padding: 22px 16px 40px; }
  .two { grid-template-columns: 1fr; }
  .scope { display: none; }
  .what span { white-space: normal; }
}

@media (prefers-reduced-motion: reduce) { .chev { transition: none; } }

/* Regole */
.rules td { white-space: normal; vertical-align: top; }
.rules td:first-child { max-width: 560px; }
.rules tr.differs td:last-child { font-weight: 600; }
.values { margin: 0; display: flex; flex-direction: column; }
.values div { display: flex; justify-content: space-between; gap: 16px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.values div:last-child { border-bottom: none; }
.values dt { font-weight: 600; flex: none; }
.values dd { margin: 0; color: var(--muted); text-align: right; }
