/* GestiPC web app — layout condiviso tra browser e Telegram Mini App. */
:root {
  color-scheme: light;
  --bg: #f4f4f2;
  --surface: #fcfcfb;
  --surface-2: #efeeea;
  --border: #e0dfda;
  --text: #0b0b0b;
  --text-2: #52514e;
  --text-3: #7a7974;
  --accent: #2a78d6;
  --accent-text: #ffffff;
  --danger: #c62f2f;
  --grid: #e6e5e0;
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --radius: 12px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #111110;
    --surface: #1a1a19;
    --surface-2: #232321;
    --border: #2f2f2c;
    --text: #f0efec;
    --text-2: #c3c2b7;
    --text-3: #8f8e86;
    --accent: #3987e5;
    --danger: #e66767;
    --grid: #2c2c2a;
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111110;
  --surface: #1a1a19;
  --surface-2: #232321;
  --border: #2f2f2c;
  --text: #f0efec;
  --text-2: #c3c2b7;
  --text-3: #8f8e86;
  --accent: #3987e5;
  --danger: #e66767;
  --grid: #2c2c2a;
  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;
}
/* Dentro Telegram adottiamo i colori del tema del client. */
:root.tg {
  --bg: var(--tg-theme-secondary-bg-color, var(--bg));
  --surface: var(--tg-theme-section-bg-color, var(--tg-theme-bg-color, var(--surface)));
  --text: var(--tg-theme-text-color, var(--text));
  --text-2: var(--tg-theme-subtitle-text-color, var(--tg-theme-hint-color, var(--text-2)));
  --text-3: var(--tg-theme-hint-color, var(--text-3));
  --accent: var(--tg-theme-button-color, var(--accent));
  --accent-text: var(--tg-theme-button-text-color, var(--accent-text));
  --danger: var(--tg-theme-destructive-text-color, var(--danger));
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); }

.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 16px;
  padding: 10px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; font-size: 17px; color: var(--text); text-decoration: none; }
.nav { display: flex; gap: 4px; overflow-x: auto; flex: 1; scrollbar-width: none; }
.nav a {
  padding: 6px 10px; border-radius: 8px; white-space: nowrap;
  color: var(--text-2); text-decoration: none; font-size: 14px;
}
.nav a[aria-current="page"] { background: var(--surface-2); color: var(--text); font-weight: 600; }
.logout button {
  background: none; border: 0; color: var(--text-3); font: inherit; font-size: 14px; cursor: pointer;
}
:root.tg .topbar .brand, :root.tg .logout { display: none; }

main { max-width: 1040px; margin: 0 auto; padding: 16px 16px 48px; }
h1 { font-size: 22px; margin: 4px 0 4px; }
h2 { font-size: 16px; margin: 0 0 12px; }
.lead { color: var(--text-2); margin: 0 0 16px; }
.muted { color: var(--text-3); }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
}
:root.tg .card { border-color: transparent; }

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
:root.tg .tile { border-color: transparent; }
.tile .label { font-size: 13px; color: var(--text-2); }
.tile .value { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; margin-top: 2px; }
.tile .sub { font-size: 12px; color: var(--text-3); }

.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 16px; }
.chip {
  padding: 6px 12px; border-radius: 999px; font-size: 14px; text-decoration: none;
  background: var(--surface); color: var(--text-2); border: 1px solid var(--border);
}
.chip[aria-current="true"] { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.range { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; font-size: 14px; color: var(--text-2); }
.range input {
  font: inherit; padding: 5px 8px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text);
}
.btn {
  display: inline-block; font: inherit; font-size: 14px; font-weight: 600;
  padding: 7px 14px; border-radius: 8px; border: 0; cursor: pointer; text-decoration: none;
  background: var(--accent); color: var(--accent-text);
}
.btn.secondary { background: var(--surface-2); color: var(--text); }

.chart-box { position: relative; height: 280px; }
.legend { display: flex; flex-wrap: wrap; gap: 14px; font-size: 13px; color: var(--text-2); margin: -4px 0 10px; }
.legend span::before {
  content: ""; display: inline-block; width: 10px; height: 10px; border-radius: 3px;
  margin-right: 6px; vertical-align: -1px; background: var(--swatch);
}
.card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 8px 10px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { color: var(--text-2); font-weight: 600; font-size: 13px; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tbody tr:last-child td { border-bottom: 0; }

.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.list li:last-child { border-bottom: 0; }
.badge { display: inline-block; font-size: 12px; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--text-2); }
.empty { color: var(--text-3); text-align: center; padding: 24px 0; }

.center-page { min-height: 70vh; display: flex; align-items: center; justify-content: center; text-align: center; }
.center-page .card { max-width: 380px; width: 100%; }
.error-text { color: var(--danger); }

@media (max-width: 560px) {
  .chart-box { height: 240px; }
  .tile .value { font-size: 22px; }
}

/* --- Timbratura e notifiche --- */
.flash {
  padding: 12px 14px; border-radius: 10px; margin-bottom: 16px; font-size: 14px;
  background: var(--surface); border: 1px solid var(--border);
}
.flash.success { border-color: var(--series-3); }
.flash.error { border-color: var(--danger); color: var(--danger); }

.turno .turno-stato { font-size: 20px; font-weight: 700; display: flex; align-items: center; gap: 10px; }
.turno .muted { margin: 4px 0 14px; }
.turno .dot {
  width: 12px; height: 12px; border-radius: 50%; background: var(--series-3);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--series-3) 25%, transparent);
}
.btn.big { display: block; width: 100%; padding: 14px; font-size: 17px; border-radius: 12px; }
.btn.danger { background: var(--danger); color: #fff; }
.btn.link { background: none; color: var(--text-3); font-weight: 400; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.modal {
  width: min(440px, calc(100vw - 32px)); max-height: calc(100dvh - 32px); padding: 20px;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); color: var(--text);
}
.modal::backdrop { background: rgb(0 0 0 / 0.5); }
.modal h2 { margin-top: 0; }
.modal-actions { justify-content: flex-end; margin-top: 16px; }
.steps { margin: 8px 0 0; padding-left: 20px; }
.steps li { margin: 4px 0; }
#notifiche p { margin: 0 0 12px; }

/* --- Pagina iniziale --- */
.landing {
  min-height: 80vh; max-width: 360px; margin: 0 auto;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center;
}
.landing-logo { border-radius: 26px; margin-bottom: 16px; }
.landing h1 { font-size: 30px; margin: 0; }
.landing .lead { margin: 4px 0 28px; }
.landing .btn.big { display: flex; align-items: center; justify-content: center; gap: 10px; }
.btn.tg-login { background: #2aabee; color: #fff; }
.landing-hint { font-size: 13px; margin-top: 14px; }

/* --- Profilo: menu laterale + sezioni --- */
.profilo { display: grid; grid-template-columns: 230px minmax(0, 1fr); gap: 24px; align-items: start; }
.side-menu {
  position: sticky; top: 72px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 12px;
}
:root.tg .side-menu { border-color: transparent; }
.side-head { display: flex; align-items: center; gap: 10px; padding: 4px 6px 12px; border-bottom: 1px solid var(--border); margin-bottom: 8px; }
.side-name { font-weight: 600; }
.side-head .muted { font-size: 13px; }
.avatar {
  width: 40px; height: 40px; border-radius: 50%; flex: none;
  display: flex; align-items: center; justify-content: center;
  background: var(--accent); color: var(--accent-text); font-weight: 700;
}
.side-menu nav { display: flex; flex-direction: column; gap: 2px; }
.side-menu nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 10px; border-radius: 8px; text-decoration: none; color: var(--text-2);
}
.side-menu nav a:hover { background: var(--surface-2); }
.side-menu nav a[aria-current="page"] { background: var(--surface-2); color: var(--text); font-weight: 600; }
.side-icon { width: 20px; text-align: center; }
.profilo-content { min-width: 0; }
.profilo-content h1 { margin-top: 0; }

.fields { display: grid; grid-template-columns: max-content 1fr; gap: 10px 20px; margin: 0; }
.fields dt { color: var(--text-2); }
.fields dd { margin: 0; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: .02em; }
.nowrap { white-space: nowrap; }
.count { font-size: 13px; font-weight: 500; color: var(--text-3); margin-left: 4px; }
.badge.ok { background: color-mix(in srgb, var(--series-3) 18%, transparent); color: var(--text); }
.range select {
  font: inherit; padding: 5px 8px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text);
}

/* Telefono: il menu laterale diventa una barra di schede scorrevole. */
@media (max-width: 760px) {
  .profilo { grid-template-columns: minmax(0, 1fr); gap: 12px; }
  .side-menu { min-width: 0; position: static; padding: 0; background: none; border: 0; }
  .side-head { display: none; }
  .side-menu nav { flex-direction: row; overflow-x: auto; scrollbar-width: none; gap: 6px; }
  .side-menu nav a {
    flex: none; padding: 7px 12px; border-radius: 999px; font-size: 14px;
    background: var(--surface); border: 1px solid var(--border);
  }
  .side-menu nav a[aria-current="page"] { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
  .side-icon { width: auto; }
  .fields { grid-template-columns: 1fr; gap: 2px; }
  .fields dd { margin-bottom: 10px; }
}

/* --- Moduli --- */
.form .field { margin-bottom: 14px; }
.form label { display: block; font-size: 14px; font-weight: 600; margin-bottom: 6px; }
.form label .muted { font-weight: 400; }
.form input, .form select, .form textarea {
  width: 100%; font: inherit; padding: 10px 12px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--bg); color: var(--text);
}
.form textarea { resize: vertical; }
.form input:focus, .form select:focus, .form textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.form .has-error input, .form .has-error select { border-color: var(--danger); }
.field-error { color: var(--danger); font-size: 13px; margin-top: 4px; }
.entry-side { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; }
.edit-link { font-size: 13px; }
