:root {
  --bg: #16181D; --header: #1E2128; --card: #242830; --card-hover: #2C313B; --input: #2A2F38;
  --border: #363C48; --text: #E8EAED; --muted: #8B93A1; --alert: #FF5A5F; --amber: #F5B342; --ok: #3CC87A;
  --loc0: #4C8DFF; --loc1: #B07CFF; --loc2: #22C3A6;
  --zoom: 1;
  --safe-b: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); }
body {
  font: calc(15px * var(--zoom)) / 1.35 "Segoe UI", Roboto, system-ui, sans-serif;
  overscroll-behavior-y: contain;
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; padding: 0; }
input, select { font: inherit; color: var(--text); }
svg { width: 1.3em; height: 1.3em; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.muted { color: var(--muted); }
.error { color: var(--alert); min-height: 1.3em; margin: .4em 0 0; }

/* abbinamento */
.pair { max-width: 380px; margin: 0 auto; padding: 12vh 24px 24px; text-align: center; }
.pair-logo { width: 72px; height: 72px; border-radius: 18px; }
.pair h1 { margin: .4em 0 .3em; font-size: 1.5em; }
.pair form { display: grid; gap: 12px; margin-top: 24px; }
.pair input { background: var(--input); border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; text-align: center; outline: none; }
.pair input:focus { border-color: var(--loc0); }
#pairCode { font-size: 1.8em; letter-spacing: .25em; font-variant-numeric: tabular-nums; }
.btn { border-radius: 10px; padding: 12px 16px; background: var(--input); font-weight: 600; }
.btn.primary { background: var(--loc0); color: #fff; }
.btn.danger { color: var(--alert); }
.btn:disabled { opacity: .5; }

/* board */
#boardView { display: flex; flex-direction: column; height: 100%; }
.top { background: var(--header); padding: 12px 12px 8px; border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 2; }
.add { display: flex; gap: 8px; }
.add input {
  flex: 1; min-width: 0; background: var(--input); border: 1.5px solid var(--border); border-radius: 10px;
  padding: 11px 13px; outline: none; font-size: 1.07em;
}
.add input:focus { border-color: var(--locc, var(--loc0)); }
.add-btn { width: 46px; border-radius: 10px; background: var(--locc, var(--loc0)); color: #fff; display: grid; place-items: center; }
.loc { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-top: 8px; }
.loc button { border-radius: 8px; padding: 7px 4px; background: var(--input); color: var(--muted); font-size: .9em; font-weight: 600; }
.loc button.on[data-loc="0"] { background: color-mix(in srgb, var(--loc0) 28%, var(--input)); color: var(--text); box-shadow: inset 0 0 0 1.5px var(--loc0); }
.loc button.on[data-loc="1"] { background: color-mix(in srgb, var(--loc1) 28%, var(--input)); color: var(--text); box-shadow: inset 0 0 0 1.5px var(--loc1); }
.loc button.on[data-loc="2"] { background: color-mix(in srgb, var(--loc2) 28%, var(--input)); color: var(--text); box-shadow: inset 0 0 0 1.5px var(--loc2); }
.hint { margin: 7px 2px 0; color: var(--muted); font-size: .78em; }

.list { flex: 1; overflow-y: auto; padding: 12px 12px 4px; }
.empty { color: var(--muted); text-align: center; padding: 40px 24px; }

.card {
  position: relative; display: flex; align-items: center; gap: 10px; background: var(--card); border-radius: 12px;
  padding: 12px 10px 12px 16px; margin-bottom: 8px; overflow: hidden; user-select: none;
}
.card:active { background: var(--card-hover); }
.card::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--c); }
.card .prog { position: absolute; left: 0; bottom: 0; height: 2px; background: var(--c); opacity: .55; }
.card.alert .prog { background: var(--alert); opacity: .8; }
.card .body { flex: 1; min-width: 0; }
.card .title { font-weight: 600; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow-wrap: anywhere; }
.card .title .flag { color: var(--amber); margin-right: 4px; }
.card .sub { color: var(--muted); font-size: .84em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
.card.alert .sub { color: var(--alert); }
.card .right { display: flex; flex-direction: column; align-items: flex-end; gap: 5px; }
.card .timer { font-weight: 600; font-size: 1.25em; font-variant-numeric: tabular-nums; }
.card.alert .timer { color: var(--alert); }
.pill { border-radius: 12px; padding: 3px 10px; background: color-mix(in srgb, var(--alert) 20%, transparent); color: var(--alert); font-size: .78em; font-weight: 600; white-space: nowrap; }
.done-btn {
  width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; flex: none;
  background: var(--input); color: var(--muted);
}
.done-btn:active { background: var(--ok); color: #fff; }

.bottom {
  display: flex; align-items: center; gap: 12px; background: var(--header); border-top: 1px solid var(--border);
  padding: 10px 14px calc(10px + var(--safe-b)); font-size: .86em;
}
.status .al { color: var(--alert); }
.spacer { flex: 1; }
.link { color: var(--muted); font-weight: 600; padding: 4px 2px; }
.icon-btn { color: var(--muted); display: grid; place-items: center; padding: 4px; }
.sync-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--muted); padding: 0; }
.sync-dot.ok { background: var(--ok); }
.sync-dot.busy { background: var(--amber); }
.sync-dot.err { background: var(--alert); }

/* pannello inferiore */
.sheet-back { position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 10; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 11; max-height: 86vh; overflow-y: auto;
  background: var(--header); border-radius: 16px 16px 0 0; padding: 6px 0 calc(12px + var(--safe-b));
  max-width: 640px; margin: 0 auto; animation: up .18s ease-out;
}
@keyframes up { from { transform: translateY(30px); opacity: 0; } }
.sheet-grip { width: 40px; height: 4px; border-radius: 2px; background: var(--border); margin: 4px auto 8px; }
.sheet h2 { font-size: 1em; margin: 6px 18px 10px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sheet h3 { font-size: .8em; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 16px 18px 6px; }
.sheet .item { display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; padding: 13px 18px; }
.sheet .item:active { background: var(--card); }
.sheet .item .chk { margin-left: auto; color: var(--loc0); }
.sheet .item.danger { color: var(--alert); }
.sheet .chips { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 18px 8px; }
.sheet .chip { border-radius: 16px; padding: 7px 13px; background: var(--input); font-size: .9em; }
.sheet .chip.on { background: var(--loc0); color: #fff; }
.sheet .row { padding: 6px 18px; }
.sheet .note { color: var(--muted); font-size: .84em; padding: 4px 18px 8px; }
.sheet input.field { width: 100%; background: var(--input); border: 1px solid var(--border); border-radius: 10px; padding: 11px 13px; outline: none; }
.hist-day { display: flex; align-items: baseline; justify-content: space-between; margin: 16px 18px 4px; }
.hist-day h3 { margin: 0; }
.hist-item { display: block; width: 100%; text-align: left; padding: 9px 18px; }
.hist-item:active { background: var(--card); }
.hist-item .t { font-weight: 600; }
.hist-item .m { color: var(--muted); font-size: .84em; }

.toast {
  position: fixed; left: 50%; bottom: calc(70px + var(--safe-b)); transform: translateX(-50%); z-index: 20;
  background: var(--input); border: 1px solid var(--border); border-radius: 10px; padding: 10px 16px; max-width: 90vw;
  box-shadow: 0 6px 20px rgba(0,0,0,.4);
}
.toast button { color: var(--loc0); font-weight: 600; margin-left: 12px; }

@media (min-width: 700px) {
  #boardView { max-width: 720px; margin: 0 auto; border-left: 1px solid var(--border); border-right: 1px solid var(--border); }
}
