:root {
  --bg: #f6f5f1;
  --card: #ffffff;
  --ink: #1f2430;
  --muted: #6b7280;
  --line: #e4e2da;
  --brand: #2f5d50;
  --brand-ink: #ffffff;
  --warn: #b45309;
  --warn-bg: #fef3c7;
  --ok: #166534;
  --ok-bg: #dcfce7;
  --err: #b91c1c;
  --err-bg: #fee2e2;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15181d;
    --card: #1e232b;
    --ink: #e8eaee;
    --muted: #9aa3b0;
    --line: #2f3641;
    --brand: #6fb39f;
    --brand-ink: #0f1a16;
    --warn: #fbbf24;
    --warn-bg: #3a2f10;
    --ok: #86efac;
    --ok-bg: #12301f;
    --err: #fca5a5;
    --err-bg: #3b1616;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--brand); }
h1 { font-size: 1.6rem; margin: 0.4rem 0 0.6rem; }
h2 { font-size: 1.1rem; margin: 0 0 0.6rem; }
main { max-width: 900px; margin: 0 auto; padding: 1rem 16px 4rem; }

.top {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 10px 16px; background: var(--card); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 5;
}
.brand { font-weight: 700; font-size: 1.2rem; text-decoration: none; color: var(--brand); }
.top nav { display: flex; gap: 2px; flex-wrap: wrap; flex: 1; }
.top nav a { padding: 6px 10px; border-radius: 8px; text-decoration: none; color: var(--ink); }
.top nav a.on { background: var(--brand); color: var(--brand-ink); }
.logout { margin: 0; }

.card {
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  padding: 16px; margin: 0 0 16px;
}
.card.narrow { max-width: 420px; margin: 2rem auto; }
details.card > summary { font-weight: 600; cursor: pointer; }
details > summary { cursor: pointer; color: var(--brand); }
.warnbox { border-color: var(--warn); }
.lead { color: var(--muted); margin-top: 0; }
.muted, .meta { color: var(--muted); font-size: 0.92rem; }
.meta { display: block; }

.stack { display: flex; flex-direction: column; gap: 12px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.wrap { flex-wrap: wrap; }
.inline { display: inline; margin: 0; }
.top-gap { margin-top: 16px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.grid-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 16px; }
.grid-cards .card { margin: 0; }
.grid-cards { margin-bottom: 16px; }
@media (max-width: 560px) {
  .grid2, .grid3 { grid-template-columns: 1fr; }
}

label { display: flex; flex-direction: column; gap: 4px; font-size: 0.92rem; font-weight: 500; }
label.check { flex-direction: row; align-items: center; gap: 6px; font-weight: 400; }
input, select, textarea {
  font: inherit; color: var(--ink); background: var(--bg);
  border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; width: 100%; min-height: 44px;
}
input[type=checkbox], input[type=radio] { width: auto; min-height: 0; }
textarea { min-height: 70px; }
fieldset { border: 1px solid var(--line); border-radius: 8px; }
.row input, .row select { width: auto; flex: 1 1 160px; }

.btn {
  display: inline-block; font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
  background: var(--brand); color: var(--brand-ink); border: 1px solid var(--brand);
  border-radius: 10px; padding: 10px 16px; min-height: 44px;
}
.btn.ghost { background: transparent; color: var(--brand); }
.btn.small { padding: 6px 12px; min-height: 36px; font-size: 0.9rem; }
.btn.on { background: var(--brand); color: var(--brand-ink); }
.link { background: none; border: 0; color: var(--brand); cursor: pointer; font: inherit; padding: 6px 0; text-decoration: underline; }
.link.danger { color: var(--err); }

.flash { padding: 10px 14px; border-radius: 10px; margin: 0 0 12px; }
.flash.ok { background: var(--ok-bg); color: var(--ok); }
.flash.err { background: var(--err-bg); color: var(--err); }
.flash.warn { background: var(--warn-bg); color: var(--warn); }

.tag { display: inline-block; font-size: 0.78rem; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: var(--line); color: var(--ink); }
.tag.ok { background: var(--ok-bg); color: var(--ok); }
.tag.warn { background: var(--warn-bg); color: var(--warn); }

.list { display: flex; flex-direction: column; gap: 10px; }
.item {
  display: block; text-decoration: none; color: var(--ink);
  border: 1px solid var(--line); border-left-width: 5px; border-radius: 10px; padding: 10px 12px; background: var(--card);
}
.card .item { background: var(--bg); margin-bottom: 10px; }
a.item:hover { border-color: var(--brand); }
.prio1 { border-left-color: var(--err); }
.prio2 { border-left-color: var(--warn); }
.prio3 { border-left-color: var(--line); }
.st-done { opacity: 0.6; }
.st-waiting { border-left-color: var(--warn); }
.line { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.plain { list-style: none; padding: 0; margin: 0; }
.plain li { padding: 4px 0; }
.counts { display: flex; flex-wrap: wrap; gap: 6px 16px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; align-items: flex-start; }
.boxed { border: 1px solid var(--line); border-radius: 10px; padding: 12px; margin: 8px 0; background: var(--card); width: 100%; }
.inline-details { width: 100%; }

.amount { font-variant-numeric: tabular-nums; font-weight: 700; white-space: nowrap; }
.amount.red { color: var(--err); }
.accounts { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 10px; }
.acct { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; display: flex; flex-direction: column; }
.acct.low, .item.low { border-color: var(--err); background: var(--err-bg); }
.acct .amount { font-size: 1.25rem; }

.timeline { display: flex; flex-direction: column; gap: 8px; margin-bottom: 16px; }
.slot { display: grid; grid-template-columns: 64px 1fr; gap: 12px; background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
.slot .time { font-weight: 700; font-variant-numeric: tabular-nums; }
.slot.k-meal, .slot.k-sleep { background: transparent; border-style: dashed; }
.slot.k-event { border-left: 5px solid var(--brand); }
.slot.running { border-color: var(--ok); box-shadow: 0 0 0 2px var(--ok-bg); }

.review-item .choices { display: flex; flex-wrap: wrap; gap: 6px 16px; margin: 8px 0; }
.review-item .choices label { flex-direction: row; align-items: center; gap: 6px; font-weight: 400; }
.cond { display: none; margin-bottom: 8px; }
.cond.show { display: grid; }

.chat { max-height: 320px; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.bubble { max-width: 88%; padding: 8px 12px; border-radius: 14px; white-space: pre-wrap; }
.bubble.lucy { align-self: flex-start; background: var(--bg); border: 1px solid var(--line); }
.bubble.me { align-self: flex-end; background: var(--brand); color: var(--brand-ink); }
#v-input { flex: 3 1 220px; }
#v-mic.on { background: var(--err-bg); color: var(--err); border-color: var(--err); }
[hidden] { display: none !important; }

.fold > summary { font-size: 1.1rem; font-weight: 600; color: var(--ink); padding: 2px 0; }
.fold[open] > summary { margin-bottom: 12px; }

.btn.danger { background: transparent; color: var(--err); border-color: var(--err); }
.btn.danger:hover { background: var(--err-bg); }
.title-row h1 { margin-right: 8px; }
.cycle-row { display: flex; gap: 8px; align-items: stretch; }
.cycle-row > .item { flex: 1; min-width: 0; }
.cycle-row > form { display: flex; align-items: center; }

.days { border: 0; padding: 0; margin: 12px 0 0; }
.days legend { font-size: 0.92rem; font-weight: 500; padding: 0; margin-bottom: 6px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { position: relative; display: block; }
.chip input { position: absolute; opacity: 0; inset: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.chip > span { display: inline-flex; align-items: center; justify-content: center; min-width: 52px; min-height: 44px; padding: 0 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); font-weight: 600; }
.chip input:checked + span { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.chip input:focus-visible + span { outline: 2px solid var(--brand); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.daybox { display: flex; flex-direction: column; gap: 6px; align-items: stretch; min-width: 64px; }
.hoursbox { flex-direction: row; align-items: center; gap: 6px; font-weight: 400; }
.hoursbox input { width: 64px; min-height: 40px; padding: 6px 8px; }
.meta.red { color: var(--err); }
.amount.inc { color: var(--ok); }

.cand { display: flex; gap: 10px; align-items: flex-start; cursor: pointer; }
.cand > input[type=checkbox] { margin-top: 5px; width: 20px; height: 20px; flex: 0 0 auto; }
.candbody { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.groupitem { border-left-color: var(--brand); }
.card .item.cand, .card .item.groupitem { background: var(--bg); }

.daygrid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 6px; }
.daygrid .chip > span { min-width: 0; width: 100%; padding: 0 2px; }
.daylabel { font-size: 0.92rem; font-weight: 500; margin: 12px 0 6px; }
.hoursin { text-align: center; padding: 8px 2px; min-width: 0; }

.catblock { margin-top: 20px; }
.catblock h3 { font-size: 1rem; margin: 0 0 10px; }
.catrow { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; }
.catedit { display: flex; gap: 8px; align-items: center; flex: 1; margin: 0; }
.catedit input { flex: 1; min-width: 0; }

.table-wrap { overflow-x: auto; }
table.grid { width: 100%; border-collapse: collapse; font-size: 0.95rem; }
table.grid th, table.grid td { padding: 8px 6px; border-bottom: 1px solid var(--line); text-align: left; }
table.grid .num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }

.mbrow { border: 1px solid var(--line); border-radius: 10px; margin-bottom: 8px; background: var(--bg); }
.mbrow > details > summary { padding: 10px 12px; display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; list-style: none; }
.mbrow > details > summary::-webkit-details-marker { display: none; }
.mbrow > details[open] > summary { border-bottom: 1px solid var(--line); }
.mbrow > details > .boxed, .mbrow > details > .row, .mbrow > details > p { margin-left: 12px; margin-right: 12px; }
.mbrow > details > .row { margin-bottom: 12px; }
.mbrow:target, .mbrow.flash-target { border-color: var(--brand); box-shadow: 0 0 0 2px var(--ok-bg); }
.dot { display: inline-block; width: 12px; height: 12px; border-radius: 50%; background: var(--line); flex: 0 0 auto; }
.dot.ok { background: #16a34a; }
.dot.bad { background: var(--err); }
#mb-search { flex: 1 1 220px; }
.mbon { align-self: end; padding-bottom: 12px; }

/* passi e sottoprodotti */
ol.steps { list-style: none; padding: 0; margin: 0; }
ol.steps .item { border-left-color: var(--brand); }
ol.steps .item.st-done { border-left-color: var(--line); }
.warn-text { color: var(--warn); }
