:root {
  --bg: #f5f5f2;
  --surface: #ffffff;
  --text: #1c1c1a;
  --muted: #6b6b66;
  --faint: #9a9993;
  --line: #e4e3de;
  --accent: #2f5d50;
  --accent-ink: #ffffff;
  --ok: #2e7d4f;
  --ok-bg: #e7f3eb;
  --warn: #9a5b00;
  --warn-bg: #fcf0d9;
  --bad: #b8352a;
  --bad-bg: #fbe6e3;
  --radius: 14px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121211;
    --surface: #1c1c1a;
    --text: #ecebe6;
    --muted: #a3a29c;
    --faint: #75746f;
    --line: #2d2d2a;
    --accent: #86c1ac;
    --accent-ink: #0f1a16;
    --ok: #74c995;
    --ok-bg: #16291e;
    --warn: #eaa94a;
    --warn-bg: #2e2310;
    --bad: #f0806f;
    --bad-bg: #351b17;
  }
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  -webkit-font-smoothing: antialiased;
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
}
body.bare { padding-bottom: 0; }
a { color: inherit; }
h1 { font-size: 1.55rem; line-height: 1.2; margin: 0; letter-spacing: -0.015em; overflow-wrap: anywhere; }
h2 { font-size: 1rem; margin: 0 0 .6rem; display: flex; align-items: center; gap: 8px; }
p { margin: .4rem 0; }
code, .mono, .path { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: .85em; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.small { font-size: .875rem; }
.warn-text { color: var(--warn); }
.bad-text { color: var(--bad); }

/* ---- chrome ---- */
.wrap { max-width: 860px; margin: 0 auto; padding: 16px 16px 40px; }
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 650; text-decoration: none; }
.logo { width: 26px; height: 26px; fill: var(--accent); }
.logo path { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linecap: round; }
.topnav { display: none; gap: 4px; }
.topnav a { padding: 6px 12px; border-radius: 999px; text-decoration: none; color: var(--muted); }
.topnav a:hover { color: var(--text); }
.topnav a[aria-current] { background: var(--surface); color: var(--text); box-shadow: 0 0 0 1px var(--line); }
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 10;
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar a {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 8px 0 6px; font-size: 11px; font-weight: 550; color: var(--muted); text-decoration: none;
  -webkit-tap-highlight-color: transparent;
}
.tabbar a[aria-current] { color: var(--accent); }
.tabbar .ic { width: 24px; height: 24px; }
@media (min-width: 720px) {
  .topnav { display: flex; }
  .tabbar { display: none; }
  body { padding-bottom: 0; }
  .wrap { padding: 28px 24px 56px; }
}

.ic { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* ---- buttons ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 0 16px;
  border-radius: 11px; border: 1px solid var(--line);
  background: var(--surface); color: var(--text);
  font: inherit; font-weight: 580; text-decoration: none; white-space: nowrap;
  cursor: pointer; -webkit-tap-highlight-color: transparent;
  transition: border-color .15s, transform .05s;
}
.btn:hover { border-color: color-mix(in srgb, var(--text) 25%, var(--line)); }
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .6; cursor: progress; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger { color: var(--bad); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.sm { min-height: 36px; padding: 0 12px; font-size: .875rem; }
.btn.sm .ic { width: 17px; height: 17px; }
.btn.icon { width: 44px; padding: 0; }
.btn.block { width: 100%; }
.link { color: var(--accent); text-decoration: none; font-weight: 550; font-size: .9rem; }

/* ---- layout bits ---- */
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin: 4px 0 18px; }
.page-head .muted { margin: 4px 0 0; }
.back { display: inline-flex; align-items: center; gap: 2px; margin: 0 0 6px -4px; color: var(--muted); text-decoration: none; font-size: .9rem; }
.back .ic { width: 18px; height: 18px; }
.section { margin: 26px 0; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 8px; }
.section-head h2 { margin: 0; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.card.section { margin: 14px 0; }
.actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }
.actions.center { justify-content: center; flex-wrap: wrap; }
.wrap-actions { justify-content: flex-start; flex-wrap: wrap; }
.danger-zone { border-top: 1px solid var(--line); padding-top: 20px; }
.notes { white-space: pre-wrap; margin: 0; }
.tag { font-size: .7rem; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; padding: 2px 7px; border-radius: 6px; background: var(--line); color: var(--muted); vertical-align: middle; }

.flash {
  margin: 0 0 16px; padding: 10px 14px; border-radius: 11px;
  background: var(--surface); border: 1px solid var(--line); border-left: 4px solid var(--accent);
  animation: fadein .25s ease-out;
}
@keyframes fadein { from { opacity: 0; transform: translateY(-4px); } }

.banner { padding: 12px 14px; border-radius: 12px; margin: 10px 0; background: var(--surface); border: 1px solid var(--line); }
.banner.ok { background: var(--ok-bg); border-color: transparent; color: var(--text); }
.banner.ok b { color: var(--ok); }
.banner.warn { background: var(--warn-bg); border-color: transparent; }
.banner.warn b { color: var(--warn); }
.banner.bad { background: var(--bad-bg); border-color: transparent; }
.banner.bad b { color: var(--bad); }
p.banner.bad { color: var(--bad); }

/* ---- stats ---- */
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
@media (min-width: 720px) { .stats { grid-template-columns: repeat(4, 1fr); } }
.stat {
  display: flex; flex-direction: column; gap: 2px; padding: 14px 16px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); text-decoration: none;
}
.stat b { font-size: 1.6rem; line-height: 1.1; font-weight: 680; letter-spacing: -0.02em; }
.stat span { color: var(--muted); font-size: .85rem; }
.stat.ok b { color: var(--ok); }
.stat.warn { background: var(--warn-bg); border-color: transparent; }
.stat.warn b { color: var(--warn); }
.stat.bad { background: var(--bad-bg); border-color: transparent; }
.stat.bad b { color: var(--bad); }

/* ---- lists ---- */
.list { list-style: none; margin: 0; padding: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.list > li + li { border-top: 1px solid var(--line); }
.list.plain { background: none; border: 0; border-radius: 0; margin: 8px 0 12px; }
.list.plain > li { padding: 10px 0; }
.row { display: flex; align-items: center; gap: 12px; padding: 12px 14px; text-decoration: none; min-height: 60px; -webkit-tap-highlight-color: transparent; }
.row:hover, a.item-main:hover { background: color-mix(in srgb, var(--text) 3%, transparent); }
.row > .ic { color: var(--faint); }
.row-main { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.row-title { font-weight: 600; overflow-wrap: anywhere; text-decoration: none; }
.row-sub { color: var(--muted); font-size: .85rem; overflow-wrap: anywhere; }
.row-sub.faint { color: var(--faint); }
.retired { opacity: .6; }

.item { display: flex; align-items: center; gap: 8px; padding: 10px 10px 10px 14px; }
.item-main { display: flex; flex-direction: column; gap: 1px; min-width: 0; flex: 1; text-decoration: none; border-radius: 8px; }
.item-actions { display: flex; gap: 6px; }
.item-actions .btn { border-color: transparent; background: transparent; }
.item-actions .btn:hover { border-color: var(--line); }

.pill {
  display: inline-flex; align-items: center; justify-content: center; flex: none;
  min-width: 38px; height: 26px; padding: 0 7px; border-radius: 999px;
  font-size: .8rem; font-weight: 700; font-variant-numeric: tabular-nums;
}
.pill.ok { background: var(--ok-bg); color: var(--ok); }
.pill.warn { background: var(--warn-bg); color: var(--warn); }
.pill.bad { background: var(--bad-bg); color: var(--bad); }
.row-title .pill { min-width: 32px; height: 22px; font-size: .75rem; margin-right: 4px; vertical-align: 1px; }

.kind-badge {
  flex: none; width: 52px; height: 40px; display: grid; place-items: center;
  border-radius: 10px; background: var(--bg); border: 1px solid var(--line);
  font-size: .68rem; font-weight: 700; color: var(--muted); text-align: center; line-height: 1.1; padding: 2px;
}

.path {
  display: block; width: fit-content; max-width: 100%; margin: 3px 0;
  padding: 3px 8px; border-radius: 6px; border: 0; background: var(--bg); color: var(--text);
  text-align: left; overflow-wrap: anywhere; cursor: copy;
}
.path.copied { background: var(--ok-bg); color: var(--ok); }
.path.copied::after { content: "  ✓ copiato"; font-family: system-ui, sans-serif; }

.usage { display: flex; align-items: center; gap: 8px; margin-top: 6px; }
.usage small { color: var(--muted); font-size: .78rem; white-space: nowrap; }
.usage.big { margin: -6px 0 14px; }
progress { flex: 1; max-width: 220px; height: 6px; border: 0; border-radius: 99px; background: var(--line); overflow: hidden; -webkit-appearance: none; appearance: none; }
.usage.big progress { max-width: none; height: 8px; }
progress::-webkit-progress-bar { background: var(--line); border-radius: 99px; }
progress::-webkit-progress-value { background: var(--accent); border-radius: 99px; }
progress::-moz-progress-bar { background: var(--accent); border-radius: 99px; }

.empty { text-align: center; padding: 32px 16px; color: var(--muted); background: var(--surface); border: 1px dashed var(--line); border-radius: var(--radius); }
.empty h1 { color: var(--text); margin-bottom: 8px; }
.empty .btn { margin-top: 8px; }
.empty.ok { display: flex; align-items: center; justify-content: center; gap: 8px; color: var(--ok); border-style: solid; background: var(--ok-bg); border-color: transparent; padding: 18px; }
.empty.ok p { margin: 0; }

/* ---- forms ---- */
.form { display: flex; flex-direction: column; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; margin: 0; border: 0; padding: 0; }
label, legend { font-size: .875rem; font-weight: 580; padding: 0; }
input, select, textarea {
  width: 100%; min-height: 44px; padding: 10px 12px;
  font: inherit; font-size: 16px; /* no iOS zoom */
  color: var(--text); background: var(--bg);
  border: 1px solid var(--line); border-radius: 10px;
  transition: border-color .15s, box-shadow .15s;
}
textarea { resize: vertical; min-height: 84px; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent); }
input[type="date"] { -webkit-appearance: none; appearance: none; }
input[type="checkbox"] { width: 20px; height: 20px; min-height: 0; padding: 0; margin: 0; accent-color: var(--accent); flex: none; }
.grid2 { display: grid; grid-template-columns: 1fr; gap: 14px; }
@media (min-width: 560px) { .grid2 { grid-template-columns: 1fr 1fr; } }

.checklist { display: flex; flex-direction: column; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; margin-bottom: 8px; }
.checklist.scroll { max-height: 46vh; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.check { display: flex; align-items: center; gap: 12px; padding: 11px 12px; font-weight: 500; cursor: pointer; background: var(--surface); -webkit-tap-highlight-color: transparent; }
.check + .check { border-top: 1px solid var(--line); }
.check span { display: flex; flex-direction: column; min-width: 0; overflow-wrap: anywhere; }
.check small { color: var(--muted); font-weight: 400; font-size: .8rem; }
.check:has(input:checked) { background: color-mix(in srgb, var(--accent) 9%, var(--surface)); }
.check.standalone { border: 1px solid var(--line); border-radius: 12px; }

.inline-form { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.inline-form input { flex: 1 1 200px; }

details.add { margin-top: 12px; padding: 0; }
details.add > summary {
  display: flex; align-items: center; gap: 8px; padding: 14px 16px; cursor: pointer;
  font-weight: 600; color: var(--accent); list-style: none; -webkit-tap-highlight-color: transparent;
}
details.add > summary::-webkit-details-marker { display: none; }
details.add[open] > summary { border-bottom: 1px solid var(--line); }
details.add > form { padding: 16px; }

/* ---- toolbar ---- */
.toolbar { display: flex; flex-direction: column; gap: 10px; margin-bottom: 14px; }
.toolbar-row { display: flex; gap: 8px; align-items: center; }
.toolbar-row select { width: auto; margin-left: auto; background: var(--surface); }
.search { position: relative; display: block; }
.search .ic { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--faint); pointer-events: none; }
.search input { padding-left: 40px; background: var(--surface); }
@media (min-width: 720px) {
  .toolbar { flex-direction: row; align-items: center; }
  .toolbar .search { flex: 1; }
}
.chip { display: inline-flex; align-items: center; gap: 8px; min-height: 44px; padding: 0 14px; border: 1px solid var(--line); border-radius: 999px; background: var(--surface); cursor: pointer; font-weight: 550; white-space: nowrap; }
.chip:has(input:checked) { border-color: var(--warn); background: var(--warn-bg); color: var(--warn); }
.chip input { accent-color: var(--warn); width: 18px; height: 18px; }

.kv { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.kv > span { display: flex; flex-direction: column; min-width: 0; overflow-wrap: anywhere; }

/* ---- auth ---- */
.auth { max-width: 380px; margin: 0 auto; padding-top: max(6vh, env(safe-area-inset-top)); }
.auth-brand { text-align: center; margin-bottom: 20px; }
.auth-brand .logo { width: 52px; height: 52px; }
.auth-brand h1 { margin-top: 8px; }
.auth .card { padding: 20px; display: flex; flex-direction: column; gap: 12px; }
.divider { display: flex; align-items: center; gap: 12px; color: var(--faint); font-size: .8rem; margin: 4px 0; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--line); }
