:root {
  --bg: #fafaf9;
  --surface: #ffffff;
  --ink: #111111;
  --ink-2: #3a3a3a;
  --dim: #6b6b6b;
  --line: #e7e5e2;
  --field: #f2f1ee;
  --btn: #111111;
  --btn-hover: #333333;
  --btn-ink: #ffffff;
  --warn: #a14a00;
  --bad-bg: #fdecea;
  --bad-ink: #9b1c12;
  --t-nuovo: #b26b00;
  --t-registrato: #1f7a4d;
  --t-da_chiarire: #c0352b;
  --r: 14px;
  --r-sm: 10px;
  font-family: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI Variable Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e0e0f;
    --surface: #18181a;
    --ink: #f4f4f3;
    --ink-2: #d4d4d2;
    --dim: #a3a3a0;
    --line: #2b2b2e;
    --field: #1f1f22;
    --btn: #f4f4f3;
    --btn-hover: #d9d9d6;
    --btn-ink: #0e0e0f;
    --warn: #f0a24b;
    --bad-bg: #3a1714;
    --bad-ink: #ffc4bc;
    --t-nuovo: #f0b34b;
    --t-registrato: #5fd197;
    --t-da_chiarire: #ff8a7f;
  }
}

* { box-sizing: border-box; }
html { background: var(--bg); }
body { margin: 0; background: var(--bg); color: var(--ink); min-height: 100vh; display: flex; flex-direction: column; }
a { color: inherit; }
h1 { font-size: 1.75rem; line-height: 1.2; letter-spacing: -0.02em; font-weight: 650; margin: 0 0 24px; }
h2 { font-size: 1.0625rem; font-weight: 650; margin: 0 0 16px; }
p { margin: 0 0 16px; }

/* Struttura */
.page { width: 100%; max-width: 520px; margin: 0 auto; padding: 32px 16px 48px; flex: 1; }
.page.wide, .top-in.wide, .foot.wide { max-width: 1040px; }

.top { border-bottom: 1px solid var(--line); background: var(--bg); position: sticky; top: 0; z-index: 2; }
.top-in { max-width: 520px; margin: 0 auto; padding: 0 16px; height: 56px; display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.brand { font-weight: 700; letter-spacing: -0.01em; text-decoration: none; }
.brand.big { font-size: 1rem; color: var(--dim); margin-bottom: 8px; }
.top nav { display: flex; gap: 4px; overflow-x: auto; }
.top nav a {
  text-decoration: none; color: var(--dim); padding: 6px 10px; border-radius: 8px; font-size: 0.9375rem; white-space: nowrap;
}
.top nav a:hover { color: var(--ink); background: var(--field); }
.top nav a.on { color: var(--ink); background: var(--field); font-weight: 550; }

.foot {
  width: 100%; max-width: 520px; margin: 0 auto; padding: 24px 16px 32px;
  display: flex; flex-wrap: wrap; gap: 8px 20px; align-items: center; color: var(--dim); font-size: 0.875rem;
}
.foot span { margin-right: auto; }
.foot a { text-decoration: none; }
.foot a:hover, .textbtn:hover { color: var(--ink); text-decoration: underline; }
.foot form { margin: 0; }

.center { max-width: 380px; margin: 10vh auto 0; }

/* Testo */
.dim { color: var(--dim); }
.warn { color: var(--warn); }
.small { font-size: 0.875rem; }
.hint { color: var(--dim); font-size: 0.875rem; margin-top: 20px; }
.empty { color: var(--dim); padding: 48px 0; text-align: center; }
.empty a { color: var(--ink); }
.money { font-variant-numeric: tabular-nums; font-weight: 600; white-space: nowrap; }
.title-row { display: flex; align-items: baseline; justify-content: space-between; gap: 16px; margin-bottom: 24px; }
.title-row h1 { margin: 0; }

.notice { background: var(--field); color: var(--ink); padding: 12px 16px; border-radius: var(--r-sm); font-size: 0.9375rem; }
.notice.bad { background: var(--bad-bg); color: var(--bad-ink); }

/* Form */
.form { display: grid; gap: 20px; }
.field { display: grid; gap: 8px; }
.field > span { font-size: 0.875rem; font-weight: 550; color: var(--ink-2); }
.field em { font-style: normal; font-weight: 400; color: var(--dim); }
input[type=text], input[type=email], input[type=password], input[type=date], input[type=month], select {
  font: inherit; color: var(--ink); background: var(--field);
  border: 1px solid transparent; border-radius: var(--r-sm);
  height: 48px; padding: 0 14px; width: 100%; appearance: none; -webkit-appearance: none;
}
select {
  padding-right: 36px;
  background-image: linear-gradient(45deg, transparent 50%, var(--dim) 50%), linear-gradient(135deg, var(--dim) 50%, transparent 50%);
  background-position: calc(100% - 19px) 21px, calc(100% - 14px) 21px;
  background-size: 5px 5px; background-repeat: no-repeat;
}
input::placeholder { color: var(--dim); opacity: 0.8; }
input:hover, select:hover { border-color: var(--line); }
input:focus, select:focus { outline: none; border-color: var(--ink); background-color: var(--surface); }
:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }

.amount-in { display: flex; align-items: center; background: var(--field); border-radius: var(--r-sm); border: 1px solid transparent; padding-left: 16px; }
.amount-in:focus-within { border-color: var(--ink); background: var(--surface); }
.amount-in i { font-style: normal; font-size: 1.75rem; color: var(--dim); font-weight: 500; }
.amount-in input {
  height: 68px; font-size: 2rem; font-weight: 600; letter-spacing: -0.02em; font-variant-numeric: tabular-nums;
  background: transparent; border: 0; padding-left: 8px;
}
.amount-in input:focus { background: transparent; }

.check { display: flex; gap: 10px; align-items: center; font-size: 0.9375rem; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--ink); margin: 0; }

/* Selettore file */
.pick {
  position: relative; display: block; cursor: pointer;
  border: 1px solid var(--line); border-radius: var(--r); background: var(--surface);
  min-height: 168px; transition: border-color 0.15s;
}
.pick:hover { border-color: var(--ink); }
.pick:focus-within { outline: 2px solid var(--ink); outline-offset: 2px; }
.pick input { position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; height: 100%; }
.pick-empty { display: grid; justify-items: center; align-content: center; gap: 4px; min-height: 168px; padding: 24px; text-align: center; pointer-events: none; }
.pick-empty svg { margin-bottom: 8px; padding: 10px; width: 48px; height: 48px; border-radius: 50%; background: var(--field); }
.pick-empty span { color: var(--dim); font-size: 0.875rem; }
.pick-full { display: none; flex-wrap: wrap; gap: 10px; padding: 14px; align-items: center; pointer-events: none; }
.pick.has .pick-empty { display: none; }
.pick.has .pick-full { display: flex; }
.thumb { width: 120px; height: 160px; box-shadow: 0 0 0 1px var(--line); border-radius: 8px; overflow: hidden; background: var(--field); display: grid; place-items: center; }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb.doc { font-size: 0.75rem; font-weight: 700; color: var(--dim); letter-spacing: 0.04em; }
.pick-change { color: var(--dim); font-size: 0.875rem; flex-basis: 100%; }

/* Bottoni */
.btn {
  font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; text-align: center;
  display: inline-flex; align-items: center; justify-content: center;
  height: 52px; padding: 0 22px; border-radius: var(--r-sm); border: 1px solid var(--btn);
  background: var(--btn); color: var(--btn-ink); transition: background-color 0.15s, border-color 0.15s;
}
.form > .btn { width: 100%; }
.btn:hover { background: var(--btn-hover); border-color: var(--btn-hover); }
.btn:active { transform: translateY(1px); }
.btn:disabled { cursor: progress; }
.btn.ghost { background: transparent; color: var(--ink); border-color: var(--line); }
.btn.ghost:hover { border-color: var(--ink); background: var(--field); }
.btn.small { height: 40px; padding: 0 14px; font-size: 0.9375rem; }
.textbtn { font: inherit; background: none; border: 0; padding: 0; color: inherit; cursor: pointer; }

/* Elenchi */
.rows { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--line); }
.rows li { border-bottom: 1px solid var(--line); }
.row { display: flex; justify-content: space-between; gap: 16px; padding: 14px 4px; text-decoration: none; align-items: center; }
a.row:hover { background: var(--field); margin: 0 -12px; padding: 14px 16px; }
.row-main { display: grid; gap: 2px; min-width: 0; }
.row-title { font-weight: 550; overflow-wrap: anywhere; }
.row-sub { color: var(--dim); font-size: 0.875rem; overflow-wrap: anywhere; }
.row-side { display: grid; justify-items: end; gap: 4px; }
.row-actions { display: flex; gap: 16px; font-size: 0.875rem; color: var(--dim); white-space: nowrap; }
.row-actions form { margin: 0; }
.row.off .row-title { color: var(--dim); }
@media (max-width: 480px) {
  .row.static { flex-direction: column; align-items: flex-start; gap: 8px; }
}

.tag { display: inline-flex; align-items: center; gap: 6px; font-size: 0.8125rem; font-weight: 500; color: var(--dim); white-space: nowrap; }
.tag::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.row-title .tag { margin-left: 6px; }
.row-title .tag::before { display: none; }
.t-nuovo { color: var(--t-nuovo); }
.t-registrato { color: var(--t-registrato); }
.t-da_chiarire { color: var(--t-da_chiarire); }

/* Dettaglio */
.back { display: inline-block; color: var(--dim); text-decoration: none; font-size: 0.9375rem; margin-bottom: 24px; }
.back::before { content: "\2190\00a0"; }
.back:hover { color: var(--ink); }
.hero { margin-bottom: 24px; }
.hero h1 { font-size: 1.25rem; font-weight: 550; margin: 4px 0 4px; letter-spacing: -0.01em; overflow-wrap: anywhere; }
.hero p.dim { margin-bottom: 10px; }
.huge { font-size: 2.75rem; letter-spacing: -0.03em; line-height: 1.1; margin: 0; font-weight: 650; }

.files { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; margin-bottom: 32px; }
.file { border-radius: var(--r-sm); overflow: hidden; background: var(--field); text-decoration: none; border: 1px solid var(--line); }
.file:hover { border-color: var(--ink); }
.file.img { aspect-ratio: 3 / 4; }
.file.img img { width: 100%; height: 100%; object-fit: cover; display: block; }
.file.doc { display: grid; align-content: end; gap: 2px; padding: 14px; aspect-ratio: 3 / 4; font-size: 0.875rem; overflow-wrap: anywhere; }

.meta { margin: 0 0 32px; border-top: 1px solid var(--line); }
.meta > div { display: grid; grid-template-columns: 140px 1fr; gap: 16px; padding: 12px 0; border-bottom: 1px solid var(--line); font-size: 0.9375rem; }
.meta dt { color: var(--dim); }
.meta dd { margin: 0; overflow-wrap: anywhere; }
@media (max-width: 420px) { .meta > div { grid-template-columns: 1fr; gap: 2px; } }

.thread { margin-bottom: 32px; }
.msgs { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.msg { background: var(--field); border-radius: var(--r-sm); padding: 12px 16px; }
.msg.reply { background: var(--surface); border: 1px solid var(--line); }
.msg p { margin: 0; }
.msg .msg-head { font-size: 0.875rem; margin-bottom: 4px; }
.msg-body { white-space: pre-wrap; overflow-wrap: anywhere; font-size: 0.9375rem; }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 24px; margin-top: 32px; }
.resend { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; margin-top: 16px; font-size: 0.875rem; }

.seg { display: flex; gap: 4px; padding: 4px; background: var(--field); border-radius: var(--r-sm); }
.seg label { flex: 1; cursor: pointer; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span { display: block; text-align: center; padding: 10px 6px; border-radius: 7px; font-size: 0.875rem; font-weight: 550; color: var(--dim); }
.seg label:hover span { color: var(--ink); }
.seg input:checked + span { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgb(0 0 0 / 0.08), 0 0 0 1px var(--line); }
.seg input:focus-visible + span { outline: 2px solid var(--ink); }

/* Archivio */
.tabs { display: flex; gap: 4px; margin-bottom: 16px; overflow-x: auto; border-bottom: 1px solid var(--line); }
.tabs a { text-decoration: none; color: var(--dim); padding: 10px 12px; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; font-size: 0.9375rem; }
.tabs a:hover { color: var(--ink); }
.tabs a.on { color: var(--ink); border-bottom-color: var(--ink); font-weight: 550; }
.tabs b { font-weight: 600; font-variant-numeric: tabular-nums; margin-left: 2px; }

.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 20px; }
.filters input, .filters select { height: 40px; width: auto; min-width: 170px; font-size: 0.9375rem; }
.filters select { background-position: calc(100% - 19px) 17px, calc(100% - 14px) 17px; }
.filters a { font-size: 0.9375rem; margin-left: 4px; }
.sum { display: flex; justify-content: space-between; align-items: baseline; font-size: 0.9375rem; margin-bottom: 8px; }
.sum .money { font-size: 1.125rem; }

.table { overflow-x: auto; border-top: 1px solid var(--line); }
table { width: 100%; border-collapse: collapse; font-size: 0.9375rem; }
th { text-align: left; font-weight: 500; color: var(--dim); font-size: 0.8125rem; padding: 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 14px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th:first-child, td:first-child { padding-left: 4px; }
th:last-child, td:last-child { padding-right: 4px; }
tbody tr { cursor: pointer; }
tbody tr:hover td { background: var(--field); }
td a { text-decoration: none; font-weight: 500; }
td a:hover { text-decoration: underline; }
.r { text-align: right; }
.nowrap { white-space: nowrap; }
