/* SwissDigiGuard – lettura dati, mobile first */

:root {
  --ink: #14202B;
  --paper: #EEF2F5;
  --surface: #FFFFFF;
  --line: #D6DDE3;
  --muted: #5E6B78;
  --text: #14202B;
  --signal: #C8102E;
  --signal-press: #A50D26;
  --ok: #1E7A52;
  --ok-bg: #E4F3EB;
  --err-bg: #FBE7EA;
  --info-bg: #E6EDF4;
  --field: #F5F7F9;
  --mark-cut: var(--ink);
  --r: 12px;
  --tap: 48px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  body.app {
    --paper: #0E151C;
    --surface: #16202A;
    --line: #253240;
    --text: #E4EAF0;
    --muted: #93A1AE;
    --field: #1C2833;
    --signal: #E23347;
    --signal-press: #C4283B;
    --ok-bg: #173327;
    --err-bg: #3A1A20;
    --info-bg: #1B2835;
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  color: var(--text);
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; }
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid var(--signal); outline-offset: 2px; border-radius: 6px; }

.mark { width: 26px; height: 26px; color: #fff; flex: none; }
.mark .cut { fill: var(--mark-cut); }

/* ---------------------------------------------------------------- accesso */

body.auth { background: var(--ink); min-height: 100vh; min-height: 100dvh; }
.auth-wrap {
  min-height: 100vh; min-height: 100dvh;
  display: flex; flex-direction: column;
}
.auth-top {
  flex: 1 0 auto;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 14px;
  padding: calc(40px + env(safe-area-inset-top)) 24px 36px;
  color: #fff;
}
.mark-lg { width: 64px; height: 64px; }
.auth-app { font-size: 19px; font-weight: 600; letter-spacing: .01em; }

.sheet {
  background: var(--surface);
  border-radius: 24px 24px 0 0;
  padding: 28px 22px calc(24px + env(safe-area-inset-bottom));
  width: 100%;
}
.sheet h1 { margin: 0 0 6px; font-size: 26px; line-height: 1.2; font-weight: 700; letter-spacing: -.01em; }
.lead { margin: 0 0 22px; color: var(--muted); font-size: 15px; }
.lead strong { color: var(--text); font-weight: 600; }
.sheet-foot {
  margin-top: 22px; padding-top: 18px; border-top: 1px solid var(--line);
  text-align: center; font-size: 15px;
}
.sheet-foot a { color: var(--muted); text-underline-offset: 3px; }

@media (min-width: 640px) {
  .auth-wrap { justify-content: center; align-items: center; padding: 40px 16px; }
  .auth-top { flex: none; padding: 0 0 28px; }
  .sheet { max-width: 420px; border-radius: 24px; padding: 32px 30px 28px; }
}

/* ---------------------------------------------------------------- moduli */

.form { display: grid; gap: 16px; }
.field { display: grid; gap: 6px; }
.field > span { font-size: 14px; font-weight: 600; }
input, select, button { font: inherit; color: inherit; }
input[type="email"], input[type="password"], input[type="text"], input[type="search"], input[type="date"], select {
  width: 100%;
  min-height: var(--tap);
  padding: 10px 14px;
  font-size: 16px; /* evita lo zoom automatico su iPhone */
  background: var(--field);
  border: 1px solid var(--line);
  border-radius: 10px;
  appearance: none; -webkit-appearance: none;
}
select {
  padding-right: 36px;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 19px) 52%, calc(100% - 14px) 52%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}
input:focus, select:focus { border-color: var(--text); outline: none; box-shadow: 0 0 0 3px rgba(200, 16, 46, .18); }
.otp { text-align: center; font-size: 30px !important; letter-spacing: .35em; font-variant-numeric: tabular-nums; font-weight: 600; }

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 100%; min-height: var(--tap);
  padding: 12px 20px;
  background: var(--signal); color: #fff;
  border: 0; border-radius: 10px;
  font-weight: 600; font-size: 16px;
  text-decoration: none; cursor: pointer;
}
.btn:active { background: var(--signal-press); }
.btn-sm { width: auto; min-height: 44px; padding: 10px 16px; }

.link-btn {
  background: none; border: 0; padding: 10px 0; cursor: pointer;
  color: var(--text); text-decoration: underline; text-underline-offset: 3px;
  font-size: 15px;
}
.form-inline { margin-top: 10px; text-align: center; }

.note { margin: 0 0 18px; padding: 12px 14px; border-radius: 10px; font-size: 15px; }
.note-ok { background: var(--ok-bg); }
.note-error { background: var(--err-bg); }
.note-info { background: var(--info-bg); }
.note-ok, .note-error, .note-info { border-left: 4px solid; }
.note-ok { border-color: var(--ok); }
.note-error { border-color: var(--signal); }
.note-info { border-color: var(--muted); }

/* ---------------------------------------------------------------- app */

.bar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: var(--ink); color: #fff;
}
.bar-brand { display: flex; align-items: center; gap: 10px; text-decoration: none; font-weight: 600; min-height: 44px; }
.bar-user { margin-left: auto; font-size: 13px; color: #A9B6C2; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.bar-out {
  flex: none; min-height: 36px; display: inline-flex; align-items: center;
  padding: 0 14px; border: 1px solid #3B4B5A; border-radius: 999px;
  font-size: 14px; text-decoration: none;
}
@media (max-width: 360px) { .bar-user { display: none; } .bar-out { margin-left: auto; } }

.wrap {
  max-width: 760px; margin: 0 auto;
  padding: 16px 14px calc(40px + env(safe-area-inset-bottom));
}
.page-title { margin: 0; font-size: 28px; line-height: 1.15; font-weight: 700; letter-spacing: -.015em; overflow-wrap: anywhere; }

.switch { display: flex; align-items: center; gap: 10px; margin: 2px 0 18px; }
.switch label { font-size: 14px; color: var(--muted); flex: none; }
.switch select { background-color: var(--surface); }
.switch-go { flex: none; min-height: var(--tap); padding: 0 14px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); }

.title-row { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.count { margin: 0; color: var(--muted); font-size: 14px; font-variant-numeric: tabular-nums; white-space: nowrap; }

.query { margin-bottom: 12px; }
.search { display: flex; gap: 8px; }
.search input { background-color: var(--surface); }

.panel { margin-top: 10px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); }
.panel > summary {
  list-style: none; cursor: pointer;
  display: flex; align-items: center; gap: 10px;
  min-height: var(--tap); padding: 0 16px;
  font-weight: 600; font-size: 15px;
}
.panel > summary::-webkit-details-marker { display: none; }
.panel > summary::after { content: ""; margin: -4px 4px 0 auto; width: 8px; height: 8px; border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted); transform: rotate(45deg); transition: transform .15s; }
.panel[open] > summary::after { margin-top: 4px; transform: rotate(225deg); }
.badge { background: var(--signal); color: #fff; font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 999px; }
.panel-body { padding: 4px 16px 16px; border-top: 1px solid var(--line); }

.frow { display: grid; grid-template-columns: 1fr 1fr auto; gap: 8px; padding: 12px 0; border-bottom: 1px dashed var(--line); }
.frow input { grid-column: 1 / 3; }
.frow-x {
  grid-row: 1; grid-column: 3;
  width: var(--tap); min-height: var(--tap);
  border: 1px solid var(--line); border-radius: 10px; background: var(--field);
  font-size: 22px; line-height: 1; cursor: pointer; color: var(--muted);
}
@media (min-width: 600px) {
  .frow { grid-template-columns: 1.2fr 1fr 1.4fr auto; }
  .frow input { grid-column: auto; }
  .frow-x { grid-column: 4; }
}
.sort { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 14px; }
.sort label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
.sort select { color: var(--text); }
.panel-actions { display: flex; align-items: center; justify-content: space-between; margin-top: 16px; }

.chips { list-style: none; margin: 0 0 14px; padding: 0; display: flex; flex-wrap: wrap; gap: 8px; }
.chips a {
  display: inline-flex; align-items: center; gap: 8px;
  min-height: 36px; padding: 4px 12px;
  background: var(--info-bg); border-radius: 999px;
  font-size: 14px; text-decoration: none; overflow-wrap: anywhere;
}
.chips a span { color: var(--muted); font-size: 18px; line-height: 1; }

/* righe dati: un unico foglio con separatori sottili */
.rows { list-style: none; margin: 0; padding: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; }
.rows > li + li { border-top: 1px solid var(--line); }
.row > summary {
  list-style: none; cursor: pointer;
  display: grid; gap: 2px;
  padding: 14px 44px 14px 16px;
  position: relative;
}
.row > summary::-webkit-details-marker { display: none; }
.row > summary::after {
  content: ""; position: absolute; right: 18px; top: 22px;
  width: 8px; height: 8px; border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted);
  transform: rotate(-45deg); transition: transform .15s;
}
.row[open] > summary::after { transform: rotate(45deg); }
.row[open] > summary { background: var(--field); }
.row-title { font-weight: 600; font-size: 16px; overflow-wrap: anywhere; }
.row-meta { font-size: 14px; color: var(--muted); overflow-wrap: anywhere; }
.row-meta .k { color: var(--muted); opacity: .8; }
.row-meta .k::after { content: ":"; }
.row-meta time, .row-meta .num { color: var(--text); }

.fields { margin: 0; padding: 4px 16px 16px; background: var(--field); }
.fields > div { padding: 10px 0; border-top: 1px solid var(--line); }
.fields dt { font-size: 12.5px; color: var(--muted); margin-bottom: 2px; }
.fields dd { margin: 0; font-size: 15px; overflow-wrap: anywhere; white-space: normal; }
.fields a { color: var(--signal); }

.num, time { font-variant-numeric: tabular-nums; }
.nil { color: var(--muted); }

.pager { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 16px; font-size: 15px; }
.pager a, .pager .off {
  min-height: var(--tap); display: inline-flex; align-items: center;
  padding: 0 14px; border-radius: 10px;
  background: var(--surface); border: 1px solid var(--line); text-decoration: none;
}
.pager .off { opacity: .4; }
.pager-pos { color: var(--muted); font-size: 14px; text-align: center; font-variant-numeric: tabular-nums; }

.tables { list-style: none; margin: 16px 0 0; padding: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; }
.tables li + li { border-top: 1px solid var(--line); }
.tables a { display: flex; align-items: center; gap: 12px; min-height: 56px; padding: 10px 16px; text-decoration: none; }
.tables-name { font-weight: 600; }
.tables-count { margin-left: auto; color: var(--muted); font-size: 14px; font-variant-numeric: tabular-nums; }
.tables a::after { content: ""; width: 8px; height: 8px; border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted); transform: rotate(-45deg); flex: none; }

.empty { padding: 32px 16px; text-align: center; color: var(--muted); background: var(--surface); border: 1px dashed var(--line); border-radius: var(--r); }
.empty p { margin: 0 0 6px; }

/* diagnostica */
.check { list-style: none; margin: 0 0 18px; padding: 0; font-size: 15px; }
.check li { padding: 10px 0; border-bottom: 1px solid var(--line); display: grid; gap: 2px; }
.check b.ok { color: var(--ok); }
.check b.ko { color: var(--signal); }
.check small { color: var(--muted); overflow-wrap: anywhere; }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}

/* immagini e dati tecnici */
.photo { display: block; max-width: 100%; max-height: 70vh; height: auto; margin-top: 4px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); }
.json {
  margin: 4px 0 0; padding: 12px; max-height: 360px; overflow: auto;
  background: var(--surface); border: 1px solid var(--line); border-radius: 10px;
  font: 12.5px/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  white-space: pre-wrap; word-break: break-word;
}
