/* Diario Nash — mobile-first, tema scuro (si compila la sera, a luci basse).
   La stampa resta chiara: un report nero sprecherebbe inchiostro e sulla carta
   si legge peggio. Vedi @media print in fondo. */

:root {
  color-scheme: dark;
  --bg: #14161a;
  --card: #1d2026;
  --card-2: #23272e;
  --ink: #e9e7e4;
  --ink-soft: #9aa1ab;
  --line: #2f343c;
  --accent: #3fbf8f;
  --accent-soft: #172c25;
  --danger: #f87171;
  --danger-bg: #7f1d1d;
  --warn: #fbbf24;
  --radius: 14px;
  --tap: 52px;
  /* serie del grafico */
  --s-lick: #fb923c;
  --s-grass: #4ade80;
  --s-vomit: #f87171;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 17px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
}

.wrap {
  max-width: 780px;
  margin: 0 auto;
  padding: 12px 14px 40px;
}

h2 {
  font-size: 15px;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--ink-soft);
  margin: 0 0 12px;
  font-weight: 600;
}

a { color: var(--accent); }

/* ---------- nav ---------- */
.topnav {
  display: flex;
  background: #0e1014;
  position: sticky;
  top: 0;
  z-index: 20;
  padding-top: env(safe-area-inset-top);
}
.topnav a {
  flex: 1;
  text-align: center;
  padding: 14px 4px;
  color: #9aa1ab;
  text-decoration: none;
  font-size: 15px;
  font-weight: 500;
}
.topnav a.on { color: #fff; box-shadow: inset 0 -3px 0 var(--accent); }

.foot {
  text-align: center;
  color: var(--ink-soft);
  font-size: 12px;
  padding: 0 14px 26px;
}
.inline { display: inline; }
.linkish {
  background: none; border: 0; padding: 0;
  color: var(--accent); font-size: 12px; text-decoration: underline; cursor: pointer;
}

/* ---------- card ---------- */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
}

.empty, .hint-past { color: var(--ink-soft); font-size: 14px; }
.hint-past { text-align: center; margin: -4px 0 12px; }

/* ---------- barra data ---------- */
.datebar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 8px 0 14px;
}
.datenav {
  width: var(--tap);
  height: var(--tap);
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 30px;
  line-height: 1;
  text-decoration: none;
  color: var(--ink);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.datenav.off { opacity: .3; }
.datebox { flex: 1; text-align: center; }
.dateday { font-size: 28px; font-weight: 700; letter-spacing: -.02em; }
.datesub { font-size: 13px; color: var(--ink-soft); }

/* ---------- banner allarme ---------- */
.banner-allarme {
  position: sticky;
  top: 48px;
  z-index: 15;
  background: var(--danger);
  color: #fff;
  font-weight: 600;
  text-align: center;
  padding: 12px 14px;
  border-radius: 10px;
  margin-bottom: 12px;
}

/* ---------- dosi ---------- */
.dosegrid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}
.dose {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-height: 92px;
  padding: 12px 10px;
  text-align: left;
  background: var(--card-2);
  border: 2px solid var(--line);
  border-radius: var(--radius);
  font: inherit;
  color: var(--ink);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.dose.on { border-color: var(--accent); background: var(--accent-soft); }
.dose-time { font-size: 22px; font-weight: 700; letter-spacing: -.02em; }
.dose-name { font-size: 12px; color: var(--ink-soft); line-height: 1.25; }
.dose-dose { font-size: 12px; color: var(--ink-soft); }
.dose-state { margin-top: auto; font-size: 12px; font-weight: 600; color: var(--ink-soft); }
.dose.on .dose-state { color: var(--accent); }

.pending {
  margin: 12px 0 0;
  font-size: 13px;
  color: var(--warn);
  font-weight: 500;
}

/* ---------- stepper ---------- */
.stepper-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}
.stepper-row:last-of-type { border-bottom: 0; }
.stepper-row label { font-size: 15px; flex: 1; }
.stepper { display: flex; align-items: center; gap: 6px; flex: none; }
.step {
  width: var(--tap);
  height: var(--tap);
  font-size: 26px;
  line-height: 1;
  background: var(--card-2);
  border: 1px solid var(--line);
  border-radius: 12px;
  color: var(--ink);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.step:active { background: var(--accent-soft); }
.stepval {
  min-width: 44px;
  text-align: center;
  font-size: 26px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

/* ---------- campi ---------- */
.field { padding: 12px 0 0; }
.field.first { padding-top: 0; padding-bottom: 14px; border-bottom: 1px solid var(--line); }
.field > label {
  display: block;
  font-size: 13px;
  color: var(--ink-soft);
  margin-bottom: 6px;
}
.choices { display: flex; flex-wrap: wrap; gap: 8px; }
.choice {
  flex: 1 1 auto;
  min-width: 84px;
  min-height: 48px;
  padding: 10px 12px;
  background: var(--card-2);
  border: 2px solid var(--line);
  border-radius: 12px;
  font: inherit;
  font-size: 15px;
  color: var(--ink);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.choice.on { border-color: var(--accent); background: var(--accent-soft); font-weight: 600; }
.choices.skin .choice { min-width: 72px; font-size: 14px; }

/* I lambimenti sono il campo che si tocca ogni sera: 2×2 a tutta larghezza,
   bersagli grandi, niente riga spaiata. */
.choices.quattro { display: grid; grid-template-columns: repeat(2, 1fr); }
.choices.quattro .choice { min-width: 0; min-height: 56px; }

textarea, input[type="text"], input[type="date"], input[type="password"] {
  width: 100%;
  padding: 12px;
  font: inherit;
  color: var(--ink);
  background: var(--card-2);
  border: 1px solid var(--line);
  border-radius: 12px;
  resize: vertical;
}
textarea:focus, input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

.hidden { display: none !important; }

/* ---------- segnali di allarme ---------- */
.redflags summary {
  font-size: 15px;
  font-weight: 600;
  color: var(--danger);
  cursor: pointer;
  list-style: none;
}
.redflags summary::-webkit-details-marker { display: none; }
.redflags summary::before { content: "▸ "; }
.redflags[open] summary::before { content: "▾ "; }
.flaglist { margin-top: 12px; display: flex; flex-direction: column; gap: 2px; }
.flag {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 50px;
  padding: 4px 2px;
  font-size: 16px;
  cursor: pointer;
}
.flag input { width: 26px; height: 26px; accent-color: var(--danger); flex: none; }

/* ---------- indicatore salvato ---------- */
.salvato {
  position: fixed;
  left: 50%;
  bottom: 18px;
  transform: translate(-50%, 14px);
  background: #0e1014;
  color: #fff;
  padding: 9px 18px;
  border-radius: 999px;
  font-size: 14px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .18s, transform .18s;
  z-index: 30;
}
.salvato.visible { opacity: .95; transform: translate(-50%, 0); }
.salvato.errore { background: var(--danger); }

/* ---------- storico ---------- */
.storico-list { display: flex; flex-direction: column; gap: 8px; }
.giorno {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  background: var(--card);
  border: 1px solid var(--line);
  border-left: 4px solid var(--line);
  border-radius: 12px;
  text-decoration: none;
  color: inherit;
}
.giorno.vuoto { background: transparent; border-left-color: #3a4049; }
.giorno.vuoto .g-data { color: var(--ink-soft); }
.giorno.compilato { border-left-color: var(--accent); }
.giorno.oggi { box-shadow: 0 0 0 2px var(--accent-soft); }
.g-data { flex: 1; min-width: 0; }
.g-giorno { font-size: 16px; font-weight: 600; display: block; white-space: nowrap; }
.g-wd { font-size: 12px; color: var(--ink-soft); }
.g-wd .wd { text-transform: capitalize; }
.g-nums { display: flex; gap: 10px; font-variant-numeric: tabular-nums; }
.g-num { text-align: center; min-width: 34px; }
.g-num b { display: block; font-size: 18px; }
.g-num-txt { min-width: 62px; }
.g-num-txt b { font-size: 14px; font-weight: 600; }
.g-num span { font-size: 10px; color: var(--ink-soft); text-transform: uppercase; }
.g-dosi {
  flex: none;
  min-width: 46px;
  text-align: right;
  font-size: 14px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--accent);
}
.g-dosi.mancate { color: var(--warn); }
.g-dosi.nulle { color: var(--ink-soft); font-weight: 400; }
.g-flag { color: var(--danger); font-size: 15px; }
.legenda { font-size: 12px; color: var(--ink-soft); margin: 14px 0 0; text-align: center; }

/* ---------- report ---------- */
.report-head { text-align: center; margin: 6px 0 16px; }
.report-head h1 { font-size: 24px; margin: 0 0 4px; }
.report-head .periodo { font-size: 15px; color: var(--ink-soft); }
.report-nota {
  font-size: 12px;
  color: var(--ink-soft);
  text-align: center;
  border-top: 1px solid var(--line);
  margin-top: 22px;
  padding-top: 12px;
}

.presets { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.presets a {
  flex: 1 1 auto;
  text-align: center;
  min-height: 46px;
  padding: 12px 10px;
  background: var(--card-2);
  border: 2px solid var(--line);
  border-radius: 12px;
  text-decoration: none;
  color: var(--ink);
  font-size: 14px;
}
.presets a.on { border-color: var(--accent); background: var(--accent-soft); font-weight: 600; }
.range-form { display: flex; flex-wrap: wrap; gap: 8px; align-items: flex-end; }
.range-form .f { flex: 1 1 140px; }
.range-form label { display: block; font-size: 12px; color: var(--ink-soft); }
.btn {
  min-height: 46px;
  padding: 12px 18px;
  background: var(--accent);
  color: #fff;
  border: 0;
  border-radius: 12px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.btn.ghost { background: var(--card-2); color: var(--ink); border: 2px solid var(--line); }
.btn.small { min-height: 40px; padding: 8px 14px; font-size: 14px; }
.azioni { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.azioni .btn { flex: 1 1 auto; }

table.dati {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}
table.dati th, table.dati td {
  padding: 9px 8px;
  border-bottom: 1px solid var(--line);
  text-align: right;
}
table.dati th:first-child, table.dati td:first-child { text-align: left; }
table.dati thead th {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--ink-soft);
  font-weight: 600;
}
table.dati tbody tr:last-child td { border-bottom: 0; }
table.dati tr.sezione td { color: var(--ink-soft); font-size: 13px; border-bottom: 0; padding-bottom: 2px; }
table.dati td.sotto { padding-left: 18px; }
.tabella-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }

.chart-legend { display: flex; flex-wrap: wrap; gap: 14px; margin-top: 8px; font-size: 13px; }
.chart-legend span { display: flex; align-items: center; gap: 6px; }
.chart-legend i { width: 14px; height: 3px; border-radius: 2px; display: inline-block; }
.chart svg { width: 100%; height: auto; display: block; }

/* I colori del grafico stanno qui e non nell'SVG, così la stampa può usarne
   di più scuri senza toccare il codice che genera il grafico. */
.chart .griglia { stroke: var(--line); }
.chart .asse { fill: var(--ink-soft); }
.s-lambimenti    { stroke: var(--s-lick); fill: var(--s-lick); }
.s-grass_seeking { stroke: var(--s-grass); fill: var(--s-grass); }
.s-vomit_count   { stroke: var(--s-vomit); fill: var(--s-vomit); }
.chart polyline { fill: none; }
.chart circle { stroke: none; }
.chart-legend i.s-grass_seeking { background: var(--s-grass); }
.chart-legend i.s-vomit_count   { background: var(--s-vomit); }

.aderenza-big {
  font-size: 40px;
  font-weight: 700;
  letter-spacing: -.02em;
  line-height: 1;
}
.aderenza-sub { color: var(--ink-soft); font-size: 14px; margin-top: 4px; }
.lista { list-style: none; margin: 12px 0 0; padding: 0; font-size: 14px; }
.lista li { padding: 8px 0; border-bottom: 1px solid var(--line); }
.lista li:last-child { border-bottom: 0; }
.lista .data { font-weight: 600; margin-right: 6px; }
.lista .dett { color: var(--ink-soft); }
.lista .flagname { color: var(--danger); font-weight: 600; }
.nota-testo { white-space: pre-wrap; }

/* ---------- impostazioni ---------- */
.med { border-bottom: 1px solid var(--line); padding-bottom: 16px; margin-bottom: 16px; }
.med:last-child { border-bottom: 0; margin-bottom: 0; padding-bottom: 0; }
.med.inattivo { opacity: .6; }
.med h3 { margin: 0 0 8px; font-size: 18px; }
.med .row { display: flex; flex-wrap: wrap; gap: 8px; align-items: flex-end; }
.med .row .f { flex: 1 1 130px; }
.med .row label { display: block; font-size: 12px; color: var(--ink-soft); }
.slotrow { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 12px; }
.slotrow form { display: flex; gap: 6px; align-items: center; }
.slotrow input[type="text"] { width: 88px; text-align: center; font-size: 16px; }
.slot-off { text-decoration: line-through; color: var(--ink-soft); }

/* Orari dentro il form del "Salva": selettore ora nativo, un solo salvataggio. */
.orari-edit { margin-top: 12px; }
.orari-edit > label { display: block; font-size: 12px; color: var(--ink-soft); margin-bottom: 6px; }
.slotedit { display: flex; flex-wrap: wrap; gap: 8px; }
.slotedit .slot-inp.slot-off input { opacity: .5; text-decoration: line-through; }
input[type="time"] { font-size: 17px; padding: 10px 12px; min-height: 44px; }
.slotrow input[type="time"] { width: auto; }
.tag {
  display: inline-block;
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--card-2);
  color: var(--ink-soft);
  vertical-align: middle;
  margin-left: 6px;
}

/* ---------- login ---------- */
.login-box { max-width: 340px; margin: 60px auto; }
.login-box .btn { width: 100%; margin-top: 12px; }
.errore-msg { color: var(--danger); font-size: 14px; margin-top: 8px; }

/* ---------- desktop ---------- */
@media (min-width: 640px) {
  .dosegrid { grid-template-columns: repeat(4, 1fr); }
  .choices.quattro { grid-template-columns: repeat(4, 1fr); }
  .wrap { padding: 20px 20px 50px; }
}

/* ---------- stampa ----------
   Lo schermo è scuro, la carta no: qui si torna a nero-su-bianco, con colori
   del grafico più scuri per reggere la stampa. Ctrl+P deve dare un PDF
   presentabile al veterinario. */
@media print {
  @page { margin: 14mm; }
  :root {
    color-scheme: light;
    --bg: #fff;
    --card: #fff;
    --card-2: #fff;
    --ink: #000;
    --ink-soft: #444;
    --line: #bbb;
    --accent: #14584a;
    --accent-soft: #fff;
    --danger: #a11212;
    --warn: #8a5a00;
    --s-lick: #b4460c;
    --s-grass: #14703a;
    --s-vomit: #a11212;
  }
  html, body { background: #fff; color: #000; font-size: 11pt; }
  .no-print, .topnav, .foot, .presets, .range-form, .azioni, .salvato { display: none !important; }
  .wrap { max-width: none; padding: 0; }
  .card {
    background: #fff;
    border: 0;
    border-top: 1px solid #999;
    border-radius: 0;
    padding: 10px 0 0;
    margin: 0 0 14px;
    break-inside: avoid;
  }
  .card:first-of-type { border-top: 0; }
  h2 { color: #000; }
  table.dati th, table.dati td { border-bottom: 1px solid #ccc; }
  .chart { break-inside: avoid; }
  a { color: #000; text-decoration: none; }
  .report-head h1 { font-size: 18pt; }
}
