:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --text: #1c2330;
  --muted: #5f6b7a;
  --border: #dde2e8;
  --accent: #2f5bd3;
  --accent-text: #ffffff;
  --ok: #1d7a46;
  --ok-bg: #e3f4ea;
  --warn: #8a5a00;
  --warn-bg: #fdf1d8;
  --bad: #b3261e;
  --bad-bg: #fbe6e4;
  --info-bg: #e7eefc;
  --quote-bg: #f3f4f7;
  --range-bg: #e4ebfb;
  --radius: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12151b;
    --surface: #1a1f27;
    --surface-2: #222833;
    --text: #e6e9ee;
    --muted: #9aa5b4;
    --border: #2e3642;
    --accent: #7c9cf5;
    --accent-text: #0d1220;
    --ok: #6fd39a;
    --ok-bg: #16301f;
    --warn: #f0c46a;
    --warn-bg: #33290f;
    --bad: #f28b82;
    --bad-bg: #3a1b19;
    --info-bg: #1c2740;
    --quote-bg: #20252e;
    --range-bg: #222f4d;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
h1, h2, h3 { margin: 0 0 .5rem; line-height: 1.25; }
h1 { font-size: 1.15rem; }
h2 { font-size: 1.05rem; }
h3 { font-size: .95rem; margin-top: 1.25rem; }
code, .mono { font-family: ui-monospace, "Cascadia Code", Consolas, monospace; font-size: .88em; }
a { color: var(--accent); }
.muted { color: var(--muted); }

.topbar {
  display: flex; flex-wrap: wrap; gap: 1rem; align-items: center; justify-content: space-between;
  padding: 1rem clamp(1rem, 3vw, 2rem); background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { display: flex; gap: .75rem; align-items: center; }
.brand-mark { color: var(--accent); font-size: 1.4rem; }
.sub { margin: 0; color: var(--muted); font-size: .88rem; }
.status-chips { display: flex; flex-wrap: wrap; gap: .4rem; }

.tabs {
  display: flex; gap: .25rem; overflow-x: auto; padding: 0 clamp(1rem, 3vw, 2rem);
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.tabs button {
  border: 0; border-bottom: 2px solid transparent; border-radius: 0; background: none;
  padding: .75rem .9rem; color: var(--muted); font-weight: 500; white-space: nowrap;
}
.tabs button[aria-selected="true"] { color: var(--text); border-bottom-color: var(--accent); }

main { max-width: 1100px; margin: 0 auto; padding: 1.25rem clamp(1rem, 3vw, 2rem) 4rem; }

.card, fieldset.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1rem 1.1rem; margin: 0 0 1rem;
}
fieldset.card legend { font-weight: 600; padding: 0 .3rem; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 1rem; }
.grid-2.tight { gap: .75rem; }
.row { display: flex; flex-wrap: wrap; gap: .6rem; align-items: center; }
.row.between { justify-content: space-between; margin-bottom: .75rem; }

label { display: block; margin: 0 0 .75rem; font-size: .9rem; font-weight: 500; }
label.check, label.inline { display: flex; gap: .5rem; align-items: center; font-weight: 400; }
label .muted { font-weight: 400; font-size: .82rem; }
.help { display: block; font-weight: 400; font-size: .82rem; color: var(--muted); margin-top: .2rem; }
input, select, textarea {
  display: block; width: 100%; margin-top: .3rem; padding: .5rem .6rem;
  border: 1px solid var(--border); border-radius: 7px; background: var(--surface-2); color: var(--text); font: inherit;
}
label.check input, label.inline input { width: auto; margin: 0; }
label.inline input { width: 5rem; }
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

button {
  padding: .5rem .9rem; border: 1px solid var(--border); border-radius: 7px;
  background: var(--surface-2); color: var(--text); font: inherit; font-weight: 500; cursor: pointer;
}
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
button:disabled { opacity: .5; cursor: default; }
button.selected { outline: 2px solid var(--accent); }

.chip {
  display: inline-flex; align-items: center; gap: .3rem; padding: .15rem .55rem; border-radius: 999px;
  font-size: .8rem; font-weight: 600; background: var(--surface-2); border: 1px solid var(--border);
}
.chip.ok { background: var(--ok-bg); color: var(--ok); border-color: transparent; }
.chip.warn { background: var(--warn-bg); color: var(--warn); border-color: transparent; }
.chip.bad { background: var(--bad-bg); color: var(--bad); border-color: transparent; }
.chip.info { background: var(--info-bg); color: var(--accent); border-color: transparent; }

.notice { padding: .75rem 1rem; border-radius: var(--radius); margin-bottom: 1rem; }
.notice.bad { background: var(--bad-bg); color: var(--bad); }
.notice.ok { background: var(--ok-bg); color: var(--ok); }
.notice ul { margin: .3rem 0 0; padding-left: 1.2rem; }

.result { margin-top: 1rem; }
.result-head { display: flex; flex-wrap: wrap; gap: .25rem 1rem; justify-content: space-between; margin-bottom: .5rem; }
.result-head .who { font-weight: 600; }
.original { margin: .5rem 0 .75rem; }
.original summary { cursor: pointer; color: var(--muted); font-size: .9rem; }
.verdicts { display: grid; gap: .5rem; margin-bottom: .75rem; }
.verdict { display: flex; flex-wrap: wrap; gap: .5rem; align-items: baseline; }
.verdict .label { min-width: 7.5rem; font-weight: 600; font-size: .9rem; }
.reply-box { border: 1px solid var(--border); border-radius: var(--radius); padding: .75rem .9rem; background: var(--surface-2); }
.reply-tools { display: flex; gap: .5rem; justify-content: flex-end; margin-top: .4rem; }
.reply-tools button { padding: .2rem .6rem; font-size: .8rem; }
pre.raw { white-space: pre-wrap; word-break: break-word; margin: 0; }
.meta { display: flex; flex-wrap: wrap; gap: .4rem 1rem; margin-top: .75rem; color: var(--muted); font-size: .82rem; }
.rate { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; margin-top: .75rem; padding-top: .75rem; border-top: 1px solid var(--border); }
.rate input { flex: 1 1 220px; width: auto; margin: 0; }

.bbcode { overflow-wrap: anywhere; }
.bbcode blockquote { margin: .4rem 0; padding: .5rem .75rem; border-left: 3px solid var(--accent); background: var(--quote-bg); border-radius: 4px; }
.bbcode .q-author { font-size: .8rem; font-weight: 600; color: var(--muted); }
.bbcode .mention { color: var(--accent); font-weight: 600; }
.bbcode ul { margin: .3rem 0; }

.list-item { display: grid; grid-template-columns: 1fr auto; gap: .5rem 1rem; align-items: start; }
.list-item .excerpt { color: var(--muted); font-size: .9rem; }
.list-item .badges { display: flex; flex-wrap: wrap; gap: .3rem; justify-content: flex-end; }
.list-item details { grid-column: 1 / -1; }
.list-item details > summary { cursor: pointer; color: var(--accent); font-size: .88rem; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: .75rem; margin-bottom: 1rem; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .75rem 1rem; }
.stat .num { font-size: 1.6rem; font-weight: 700; }
.bar { height: 6px; border-radius: 3px; background: var(--bad-bg); overflow: hidden; margin-top: .4rem; }
.bar > span { display: block; height: 100%; background: var(--ok); }

table { width: 100%; border-collapse: collapse; font-size: .88rem; }
th, td { text-align: left; padding: .5rem .4rem; border-bottom: 1px solid var(--border); vertical-align: top; }
th { color: var(--muted); font-weight: 600; }
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }

.field-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 0 1rem; }
.sticky-actions { position: sticky; bottom: 0; padding: .75rem 0; background: var(--bg); border-top: 1px solid var(--border); }
.spinner::before { content: ""; display: inline-block; width: .9em; height: .9em; margin-right: .4rem; border: 2px solid var(--muted); border-top-color: transparent; border-radius: 50%; animation: spin .8s linear infinite; vertical-align: -2px; }
@keyframes spin { to { transform: rotate(360deg); } }
.empty { padding: 1rem; text-align: center; color: var(--muted); }

/* intestazione: interruttore e contatori */
.topbar-right { display: flex; flex-wrap: wrap; gap: .6rem; align-items: center; }
.power { min-width: 7.5rem; font-weight: 700; border-radius: 999px; background: var(--surface-2); color: var(--muted); }
.power.on { background: var(--ok-bg); color: var(--ok); border-color: var(--ok); }
.warn-text { color: var(--warn); }
.badge { display: inline-block; min-width: 1.3rem; padding: 0 .35rem; margin-left: .25rem; border-radius: 999px; background: var(--bad); color: #fff; font-size: .72rem; font-weight: 700; text-align: center; line-height: 1.3rem; }
.badge.muted-badge { background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); }

/* azioni da approvare */
.action header { margin-bottom: .5rem; }
.action-context { display: grid; gap: .35rem; margin-bottom: .6rem; }
blockquote.excerpt { margin: 0; padding: .4rem .7rem; border-left: 3px solid var(--border); color: var(--muted); font-size: .9rem; }
.action-message .preview { border: 1px solid var(--border); border-radius: var(--radius); padding: .6rem .8rem; background: var(--surface-2); }
.action-buttons { margin-top: .6rem; }
.action.handled { opacity: .6; }

details.more { margin: 0 0 .75rem; }
details.more > summary { cursor: pointer; color: var(--accent); font-size: .9rem; margin-bottom: .5rem; }
.bool-help { margin: -.5rem 0 .75rem; }
.bbcode hr { border: 0; border-top: 1px solid var(--border); margin: .75rem 0; }

.accounts-field { grid-column: 1 / -1; margin-bottom: .75rem; }
.field-label { display: block; font-size: .9rem; font-weight: 500; margin-bottom: .3rem; }
.account-row { margin-bottom: .5rem; }
.account-row input { width: auto; flex: 1 1 14rem; margin: 0; }
.account-row input[type="number"] { flex: 0 1 9rem; }
.account-pick select { width: auto; margin: 0; padding: .4rem .5rem; }

/* filtro per periodo */
.period-bar { position: relative; margin: 0 0 1rem; }
.period-btn { display: inline-flex; align-items: center; gap: .4rem; max-width: 100%; background: var(--surface); text-align: left; }
.period-pop {
  position: absolute; top: calc(100% + .35rem); left: 0; z-index: 30; width: min(640px, calc(100vw - 2rem));
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: 0 12px 32px rgba(0, 0, 0, .2);
}
.period-body { display: grid; grid-template-columns: minmax(170px, 40%) 1fr; height: min(470px, 72vh); }
.period-body > * { min-height: 0; }
.period-presets { list-style: none; margin: 0; padding: .3rem 0; overflow-y: auto; border-right: 1px solid var(--border); }
.period-presets button { border: 0; border-radius: 0; background: none; font-weight: 400; text-align: left; }
.period-presets button:hover { background: var(--surface-2); }
.preset-row { display: flex; }
.preset-custom { border-bottom: 1px solid var(--border); margin-bottom: .3rem; padding-bottom: .3rem; }
.preset { flex: 1; padding: .6rem 1rem; }
.period-presets .preset[aria-pressed="true"] { background: var(--info-bg); color: var(--accent); }
.preset-more { padding: 0 .9rem; color: var(--muted); }
.preset-sub { display: grid; padding: 0 0 .3rem .75rem; }
.preset-sub button { padding: .45rem 1rem; font-size: .88rem; color: var(--muted); }
.preset-sub button[aria-pressed="true"] { color: var(--accent); }
.period-cal { display: flex; flex-direction: column; min-width: 0; }
.period-fields { display: flex; align-items: center; gap: .5rem; padding: 1rem 1rem .6rem; }
.period-field { position: relative; flex: 1; min-width: 0; margin: 0; }
.period-field span {
  position: absolute; top: -.55rem; left: .55rem; padding: 0 .25rem; background: var(--surface);
  color: var(--muted); font-size: .75rem; font-weight: 400; line-height: 1.1;
}
.period-field input { margin: 0; padding: .6rem .7rem; background: var(--surface); }
.period-field.active input { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.period-field.active span { color: var(--accent); }
.cal-head { display: grid; grid-template-columns: repeat(7, 1fr); padding: .4rem 1rem; text-align: center; color: var(--muted); font-size: .8rem; border-bottom: 1px solid var(--border); }
.cal-scroll { position: relative; flex: 1; overflow-y: auto; padding: 0 1rem .75rem; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); row-gap: 3px; padding-top: 1rem; }
.cal-month { display: flex; align-items: center; color: var(--muted); font-size: .85rem; font-weight: 600; }
.cal-month--row { grid-column: 1 / -1; padding-bottom: .3rem; }
.cal-cell { display: flex; justify-content: center; }
.cal-cell button { width: 2.2rem; height: 2.2rem; padding: 0; border: 0; border-radius: 50%; background: none; font-weight: 400; font-size: .88rem; }
.cal-cell button:hover:not(:disabled) { background: var(--surface-2); }
.cal-cell.in-range { background: var(--range-bg); }
.cal-cell.start { background: linear-gradient(to right, transparent 50%, var(--range-bg) 50%); }
.cal-cell.end { background: linear-gradient(to left, transparent 50%, var(--range-bg) 50%); }
.cal-cell.start.end { background: none; }
.cal-cell.today button { box-shadow: inset 0 0 0 1px var(--accent); color: var(--accent); }
.cal-cell.start button, .cal-cell.end button { background: var(--accent); color: var(--accent-text); }
.period-foot { display: flex; justify-content: flex-end; gap: .25rem; padding: .5rem .75rem; border-top: 1px solid var(--border); }
.period-foot button { border: 0; background: none; color: var(--accent); }
.period-foot button:hover { background: var(--info-bg); }
@media (max-width: 600px) {
  .period-body { grid-template-columns: 1fr; height: auto; }
  .period-presets { max-height: 28vh; border-right: 0; border-bottom: 1px solid var(--border); }
  .cal-scroll { max-height: 42vh; }
}
#log-summary { margin-bottom: .5rem; font-size: .88rem; }
#log-more-row { margin-top: .75rem; }

/* coda di moderazione e segnalazioni */
.mod-item { border-top: 1px solid var(--border); padding: .9rem 0; }
.mod-item:first-child { border-top: 0; padding-top: .2rem; }
.mod-item.handled { opacity: .6; }
.mod-text {
  white-space: pre-wrap; overflow-wrap: anywhere; max-height: 14rem; overflow-y: auto; margin: .5rem 0;
  padding: .5rem .7rem; background: var(--surface-2); border-radius: 7px; font-size: .92rem;
}
.mod-extras { display: grid; gap: .4rem; margin-top: .5rem; }
.mod-extras label { margin: 0; }
.mod-detail { margin-top: .5rem; }
.mod-detail > summary { cursor: pointer; color: var(--accent); font-size: .9rem; }
.mod-section h4 { margin: .75rem 0 .3rem; font-size: .9rem; }
.mod-msg { border-left: 3px solid var(--border); padding-left: .7rem; margin: .5rem 0; }
.mod-form { margin-top: .75rem; padding-top: .75rem; border-top: 1px dashed var(--border); }
.mod-form > input { margin: 0 0 .75rem; }
fieldset.forum-radio { border: 0; padding: 0; margin: 0 0 .75rem; }
fieldset.forum-radio legend { padding: 0; margin-bottom: .3rem; font-size: .9rem; font-weight: 500; }
fieldset.forum-radio label.check { margin-bottom: .35rem; }
button.danger { color: var(--bad); border-color: var(--bad); }

/* accesso */
.logout { display: flex; gap: .5rem; align-items: center; margin: 0; }
.logout span { font-size: .88rem; }
.login { display: grid; place-items: center; min-height: 100vh; padding: 1rem; }
.login-card { width: min(380px, 100%); padding: 1.5rem; }
.login-brand { display: flex; gap: .75rem; align-items: center; margin-bottom: 1.25rem; }
.login-brand h1 { margin: 0; }
.login-card button[type="submit"] { width: 100%; margin-top: .25rem; }
.login-card pre { padding: .6rem .75rem; background: var(--surface-2); border-radius: 7px; overflow-x: auto; }
