/* Two looks, chosen in Impostazioni › Aspetto (saved in this browser):
   "instrument" (Strumentazione, the default) and "logbook" (Giornale di bordo).
   Every color of the app comes from these variables. */
:root, :root[data-theme="instrument"] {
  color-scheme: dark;
  --font-body: Barlow, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-display: "Barlow Condensed", Barlow, system-ui, sans-serif;
  --display-case: uppercase;
  --display-spacing: .04em;
  --ink: #e6edf2;
  --muted: #93a6b5;
  --line: #24323e;
  --bg: #0a1016;
  --card: #121b23;
  --field: #0f171e;
  --surface2: #1a2530;
  --sea: #0f171e;
  --header-ink: #e6edf2;
  --header-muted: #93a6b5;
  --accent: #39c6d6;
  --accent-ink: #061015;
  --bubble: #1d3442;
  --bubble-ink: #e6edf2;
  --brass: #39c6d6;
  --danger: #ff6b5e;
  --warn: #f5b24a;
  --warn-ink: #1a1203;
  --warn-bg: #2a2111;
  --warn-line: #5a4520;
  --ok: #3dba78;
  --note-bg: #13261d;
  --toast-bg: #e6edf2;
  --toast-ink: #0a1016;
  --toast-action: #0b6f7c;
  --radius: 10px;
}
:root[data-theme="logbook"] {
  color-scheme: light;
  --font-body: Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-display: Fraunces, Georgia, serif;
  --display-case: none;
  --display-spacing: 0;
  --ink: #1b2a36;
  --muted: #5b6874;
  --line: #e2d8c6;
  --bg: #f4efe6;
  --card: #fffdf8;
  --field: #fffdf8;
  --surface2: #ece4d6;
  --sea: #0e2233;
  --header-ink: #f4efe6;
  --header-muted: #c9d3dc;
  --accent: #0e2233;
  --accent-ink: #f4efe6;
  --bubble: #0e2233;
  --bubble-ink: #f4efe6;
  --brass: #b08d57;
  --danger: #b3261e;
  --warn: #a8650a;
  --warn-ink: #ffffff;
  --warn-bg: #fbf3e2;
  --warn-line: #e5c98f;
  --ok: #1f7a46;
  --note-bg: #eef3ea;
  --toast-bg: #0e2233;
  --toast-ink: #f4efe6;
  --toast-action: #e3c58f;
  --radius: 12px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { height: 100%; }
body {
  margin: 0;
  font: 16px/1.45 var(--font-body);
  color: var(--ink);
  background: var(--bg);
  overflow: hidden; /* la pagina non scorre: scorrono l'elenco e i moduli */
}

h1 { font-size: 1.4rem; margin: 0 0 .25rem; }
h2 { font-size: 1.05rem; margin: 0 0 .5rem; }
.muted { color: var(--muted); font-size: .9rem; }
.error { color: var(--danger); min-height: 1.2em; margin: .25rem 0 0; }

/* L'intestazione e le schede restano ferme: questo contenitore è alto quanto
   lo schermo e ogni scheda scorre per conto suo. */
.screen { height: 100%; height: 100dvh; display: flex; flex-direction: column; min-height: 0; }
#login { align-items: center; justify-content: center; padding: 1rem; overflow-y: auto; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: 1rem;
  display: flex;
  flex-direction: column;
  gap: .6rem;
}
.narrow { width: min(100%, 360px); }

label { display: flex; flex-direction: column; gap: .2rem; font-size: .85rem; color: var(--muted); flex: 1; }
input, textarea, select {
  font: inherit;
  color: var(--ink);
  padding: .55rem .65rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--field);
  width: 100%;
}
input:focus, textarea:focus, select:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

button, .button {
  font: inherit;
  padding: .55rem .9rem;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink);
  cursor: pointer;
  white-space: nowrap;
  text-align: center;
}
.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.link { border: none; background: none; color: var(--accent); padding: .3rem; }
.danger { color: var(--danger); }
button:disabled { opacity: .55; cursor: default; }

header {
  background: var(--sea);
  color: var(--header-ink);
  padding: .7rem 1rem;
  padding-top: calc(.7rem + env(safe-area-inset-top));
  display: flex;
  justify-content: space-between;
  align-items: center;
}
header .muted { color: var(--header-muted); margin-left: .5rem; }
header .link { color: var(--header-ink); }

nav { display: flex; background: var(--card); border-bottom: 1px solid var(--line); overflow-x: auto; scrollbar-width: none; }
nav button {
  flex: 1 0 auto;
  border: none;
  border-bottom: 3px solid transparent;
  border-radius: 0;
  background: none;
  padding: .7rem .2rem;
  color: var(--muted);
}
nav button.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }

main { flex: 1; display: flex; flex-direction: column; min-height: 0; }
section {
  flex: 1;
  padding: 1rem;
  max-width: 820px;
  width: 100%;
  margin: 0 auto;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.row { display: flex; gap: .5rem; align-items: flex-end; }
.row.end { justify-content: flex-end; }
.row > input, .row > select { flex: 1; }

/* Chat: scorre solo la lista dei messaggi, la casella resta in basso. */
#tab-chat { display: flex; flex-direction: column; padding-bottom: 0; overflow: hidden; }
#messages { flex: 1; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; gap: .5rem; padding-bottom: .75rem; }
.msg { max-width: 85%; padding: .55rem .75rem; border-radius: 14px; white-space: pre-wrap; overflow-wrap: anywhere; flex: 0 0 auto; }
.msg.user { align-self: flex-end; background: var(--bubble); color: var(--bubble-ink); border-bottom-right-radius: 4px; }
.msg.assistant { align-self: flex-start; background: var(--card); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.msg.pending { color: var(--muted); font-style: italic; }
.msg.failed { align-self: center; color: var(--danger); background: none; font-size: .9rem; }
.found { align-self: flex-start; display: flex; gap: .5rem; flex-wrap: wrap; max-width: 100%; flex: 0 0 auto; }
#chat-form {
  display: flex;
  gap: .5rem;
  padding: .6rem 0 calc(.6rem + env(safe-area-inset-bottom));
  align-items: flex-end;
}
#chat-send {
  background: var(--bg);
  display: flex;
  flex-direction: column;
  gap: .35rem;
}
#chat-text { resize: none; max-height: 200px; flex: 1 1 0; min-width: 0; width: auto; }
#chat-text::placeholder { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#chat-attach { flex: 0 0 auto; display: flex; align-items: center; padding: .55rem; color: var(--accent); }
#chat-hint { text-align: right; padding-right: .2rem; }
#tab-chat.dropping { outline: 2px dashed var(--accent); outline-offset: -6px; background: var(--surface2); }
.chips { display: flex; flex-wrap: wrap; gap: .35rem; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: .25rem;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: .15rem .3rem .15rem .6rem;
  font-size: .85rem;
}
.chip .link { padding: 0 .3rem; color: var(--muted); }
.msg .files { display: block; margin-top: .25rem; font-size: .85rem; opacity: .85; }

/* Inventory */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: .6rem; margin-top: .6rem; }
.item {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0;
  overflow: hidden;
  text-align: left;
  display: flex;
  flex-direction: column;
  white-space: normal;
}
.item img, .item .nophoto { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; background: var(--surface2); }
.item .body { padding: .5rem .6rem; display: flex; flex-direction: column; gap: .1rem; }
.item .name { font-weight: 600; }
.item .where { color: var(--accent); font-size: .85rem; }
.item .aka { color: var(--muted); font-size: .8rem; }
.found .item { width: 150px; }

/* Locations */
.tree, .plain { list-style: none; margin: .75rem 0 0; padding: 0; }
.tree ul { list-style: none; padding-left: 1.1rem; border-left: 2px solid var(--line); margin-left: .4rem; }
.tree li { padding: .25rem 0; }
.tree .count { color: var(--muted); font-size: .85rem; }
.plain li { display: flex; justify-content: space-between; gap: .5rem; padding: .3rem 0; border-bottom: 1px solid var(--line); }

/* Usage */
.bar { height: 10px; border-radius: 5px; background: var(--surface2); overflow: hidden; margin: .4rem 0; }
.bar > div { height: 100%; background: var(--accent); }
.bar.warn > div { background: var(--warn); }
.bar.over > div { background: var(--danger); }
table { border-collapse: collapse; width: 100%; font-size: .9rem; }
td, th { text-align: left; padding: .25rem .4rem .25rem 0; border-bottom: 1px solid var(--line); }
td.num, th.num { text-align: right; }

dialog { background: var(--card); color: var(--ink); border: none; border-radius: var(--radius); padding: 1rem; width: min(96vw, 480px); max-height: 92vh; }
dialog::backdrop { background: rgba(10, 25, 35, .5); }
dialog form { display: flex; flex-direction: column; gap: .55rem; }
dialog img { width: 100%; max-height: 220px; object-fit: contain; border-radius: 8px; background: var(--surface2); }

#toast {
  position: fixed;
  left: 50%;
  bottom: calc(1rem + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: var(--toast-bg);
  color: var(--toast-ink);
  padding: .55rem .9rem;
  border-radius: 8px;
  max-width: 90vw;
  z-index: 10;
}

@media (max-width: 520px) {
  #location-form { flex-wrap: wrap; }
  #location-form > * { flex: 1 1 100%; }
  #chat-form { gap: .4rem; }
  #chat-form .primary { padding: .55rem .7rem; }
  section { padding: .75rem; }
}

/* Lavori */
.works li { flex-direction: column; align-items: stretch; gap: .15rem; padding: .6rem 0; }
.works .head { display: flex; justify-content: space-between; gap: .5rem; font-weight: 600; }
.works .meta { color: var(--muted); font-size: .85rem; }
.works .line { display: flex; justify-content: space-between; align-items: center; gap: .5rem; }
label.check { flex-direction: row; align-items: center; gap: .5rem; }
label.check input { width: auto; }
#tab-items .row, #tab-work .row { flex-wrap: wrap; }

/* Plans */
.row.wrap { flex-wrap: wrap; align-items: center; }
.spacer { flex: 1; }
.chip.tab { cursor: pointer; padding: .3rem .8rem; font-size: .9rem; }
.chip.tab.active { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.plan-layout { display: grid; grid-template-columns: minmax(0, 1fr) minmax(240px, 320px); gap: .8rem; margin-top: .6rem; align-items: start; }
#tab-locations { max-width: 1100px; }
@media (max-width: 720px) { .plan-layout { grid-template-columns: 1fr; } }
.plan-view { text-align: center; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: .5rem; min-height: 120px; }
.plan-figure { position: relative; display: inline-block; line-height: 0; touch-action: manipulation; }
.plan-figure img { display: block; max-width: 100%; max-height: 78vh; width: auto; height: auto; user-select: none; -webkit-user-drag: none; }
.plan-view.mapping .plan-figure { cursor: crosshair; outline: 2px dashed var(--accent); outline-offset: 3px; }
.pin {
  position: absolute; transform: translate(-50%, -50%);
  min-width: 26px; height: 26px; padding: 0 .35rem; border-radius: 13px;
  background: var(--accent); color: #fff; border: 2px solid #fff;
  box-shadow: 0 1px 4px rgba(0,0,0,.35); font-size: .75rem; line-height: 22px; font-weight: 600;
  white-space: nowrap; cursor: pointer;
}
.pin.dim { background: #7d8f9c; }
.pin.hit { background: var(--danger); min-width: 30px; height: 30px; line-height: 26px; z-index: 2; animation: pulse 1.4s ease-in-out infinite; }
.pin.selected { background: var(--warn); z-index: 3; }
.pin.new { background: var(--warn); }
@keyframes pulse { 50% { box-shadow: 0 0 0 8px rgba(179, 38, 30, .2); } }
.side h3 { margin: 0 0 .4rem; }
.side .grid { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); }
.side ol, .side ul { padding-left: 1.2rem; margin: .4rem 0; }
.side li.current { font-weight: 700; color: var(--accent); }
.side li.done { color: var(--muted); }
.side .actions { display: flex; flex-wrap: wrap; gap: .4rem; margin-top: .6rem; }
.proposal { display: flex; gap: .8rem; align-items: center; margin-top: .6rem; }
.proposal img { width: 90px; height: 120px; object-fit: contain; background: #fff; border: 1px solid var(--line); border-radius: 6px; }
.found-plans { display: flex; gap: .6rem; flex-wrap: wrap; flex: 0 0 auto; align-self: flex-start; }
.found-plans .plan-figure img { max-height: 300px; }
.found-plans figure { margin: 0; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: .4rem; text-align: center; }
.found-plans figcaption { font-size: .8rem; color: var(--muted); line-height: 1.3; margin-top: .3rem; }
#items-plans { margin-top: .6rem; }
#location-list { margin-top: .8rem; }
#location-list summary { cursor: pointer; font-weight: 600; }
.row.wrap > label.button, .row.wrap > button { flex: 0 0 auto; }
.map-hint { position: sticky; top: 0; z-index: 5; margin: 0 0 .5rem; padding: .45rem .7rem; background: var(--warn-bg); border: 1px solid var(--warn-line); border-radius: 8px; line-height: 1.3; }
.danger-fill { background: var(--danger); border-color: var(--danger); color: #fff; }
.effects { margin: 0 0 .4rem; padding-left: 1.2rem; }
.effects li { margin: .2rem 0; }
#toast { display: flex; align-items: center; gap: .8rem; }
#toast-action { color: var(--toast-action); font-weight: 700; padding: 0; }
.pin.dot { min-width: 16px; width: 16px; height: 16px; padding: 0; border-radius: 8px; font-size: 0; line-height: 0; }
.pin.dot:hover, .pin.dot:focus-visible { transform: translate(-50%, -50%) scale(1.3); }
.labels-bar { margin: .5rem 0; }
.labels-bar .muted { flex: 1 1 260px; }
.label-toggle { display: inline-flex; flex: 0 0 auto; margin-right: .4rem; vertical-align: middle; }
.label-toggle input { width: 1.1rem; height: 1.1rem; margin: 0; }
.tree .go { color: var(--accent); cursor: pointer; text-decoration: underline dotted; }
#place-dialog { width: min(96vw, 720px); }
.place { display: flex; flex-direction: column; gap: .5rem; }
.place h2 { margin: 0; }
.plan-view.readonly .pin { pointer-events: none; }
.plan-view.readonly .plan-figure img { max-height: 68vh; pointer-events: none; }
#item-show-place { flex: 0 0 auto; }
#item-show-place:disabled { opacity: .45; }
#place-dialog img { width: auto; max-width: 100%; max-height: 68vh; object-fit: fill; border-radius: 0; background: none; }
.go-green { background: #1f8a4c; border-color: #1f8a4c; color: #fff; }
.go-green:hover:not(:disabled) { background: #187040; border-color: #187040; }
.go-green:disabled { background: var(--surface2); border-color: var(--line); color: var(--muted); opacity: 1; }
.work-photos { display: flex; gap: .3rem; flex-wrap: wrap; cursor: pointer; margin-top: .3rem; align-items: center; }
.work-photos img { width: 64px; height: 64px; object-fit: cover; border-radius: 6px; border: 1px solid var(--line); }
.work-photos .more { font-size: .85rem; color: var(--accent); font-weight: 600; padding: 0 .3rem; }
#gallery-dialog { width: min(96vw, 960px); }
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: .5rem; max-height: 70vh; overflow-y: auto; }
.gallery a { display: flex; flex-direction: column; gap: .2rem; color: var(--muted); font-size: .8rem; text-decoration: none; }
#gallery-dialog .gallery img { width: 100%; max-height: none; aspect-ratio: 1; object-fit: cover; border-radius: 6px; }
.gallery .tile { display: flex; flex-direction: column; gap: .2rem; font-size: .75rem; color: var(--muted); min-width: 0; }
.gallery .tile .line { display: flex; justify-content: space-between; gap: .3rem; align-items: center; }
.gallery .tile .line span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.gallery .tile .link { font-size: .75rem; padding: 0; }

/* Logbook */
#tab-log { max-width: 1200px; }
.grow { flex: 1; margin: 0; }
.log-status { margin: .3rem 0 .6rem; font-size: .9rem; }
.log-status.ok { color: var(--ok); }
.log-status.warn { color: var(--warn); }
.chips.quick { margin: .6rem 0; }
.chips.quick button { border-radius: 999px; padding: .3rem .8rem; font-size: .85rem; }
.instruments { margin-top: .6rem; }
.instruments summary { cursor: pointer; color: var(--accent); }
.exports { margin-top: .4rem; gap: 1rem; }
.table-wrap { overflow-x: auto; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); margin: .8rem 0; }
.logtable { font-size: .82rem; white-space: nowrap; }
.logtable th { position: sticky; top: 0; background: var(--surface2); padding: .35rem .5rem; }
.logtable td { padding: .3rem .5rem; vertical-align: top; }
.logtable td.text { white-space: normal; min-width: 220px; }
.logtable tr.event td { background: var(--warn-bg); }
.logtable .media a { margin-right: .3rem; }
.logtable .del { color: var(--muted); padding: 0 .2rem; }
.voyages li { cursor: pointer; flex-direction: column; align-items: flex-start; }
.voyages li .meta { color: var(--muted); font-size: .85rem; }
.section-title { font-size: 1.05rem; margin: 1rem 0 .3rem; }
.gallery .tile video, .gallery .tile audio { width: 100%; }
.space-row { margin-top: .6rem; }
.log-map { height: 380px; border-radius: var(--radius); border: 1px solid var(--line); margin: .8rem 0; }
.logtable tr.note td { background: var(--note-bg); }
.logtable tr.note td.text { font-style: italic; }
.logtable tr { cursor: pointer; }
.logtable .sources a { font-style: normal; font-size: .75rem; margin-right: .4rem; }
.stats-year { margin-bottom: .8rem; }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: .5rem; margin: .5rem 0; }
.tile-num { background: var(--surface2); border-radius: 8px; padding: .5rem .6rem; }
.tile-num strong { display: block; font-size: 1.25rem; }
.tile-num span { color: var(--muted); font-size: .8rem; }
.bars { display: flex; align-items: flex-end; gap: 4px; height: 90px; margin: .4rem 0 .2rem; }
.bars div { flex: 1; background: var(--accent); border-radius: 3px 3px 0 0; min-height: 1px; position: relative; }
.bars-labels { display: flex; gap: 4px; font-size: .7rem; color: var(--muted); }
.bars-labels span { flex: 1; text-align: center; }
#log-watch:empty, #log-sun:empty { display: none; }
.due li { align-items: center; }
.due .badge { font-size: .75rem; padding: .1rem .5rem; border-radius: 999px; color: #fff; flex: 0 0 auto; }
.due .overdue { background: var(--danger); } .due .soon { background: var(--warn); color: var(--warn-ink); } .due .ok { background: #1f8a4c; } .due .unknown { background: #7d8f9c; }
.due .what { flex: 1; display: flex; flex-direction: column; }
.due .what span { color: var(--muted); font-size: .85rem; }
#equipment-card summary { cursor: pointer; }
#equipment .what { display: flex; flex-direction: column; flex: 1; }

.equipment-row .what { display: flex; flex-direction: column; gap: .2rem; }
.equipment-actions { display: flex; flex-wrap: wrap; gap: .4rem; margin-top: .3rem; align-items: center; }
.equipment-actions button:not(.link) { padding: .45rem .8rem; }

.galley-actions { display: flex; flex-wrap: wrap; gap: .5rem; }
.galley li { align-items: flex-start; gap: .5rem; }
.galley .what { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.galley .what span { color: var(--muted); font-size: .85rem; }
.galley .keeping { font-style: italic; }
.galley .badge { font-size: .75rem; padding: .1rem .5rem; border-radius: 999px; color: #fff; flex: 0 0 auto; margin-top: .15rem; }
.galley .scaduto { background: var(--danger); } .galley .subito { background: var(--warn); color: var(--warn-ink); } .galley .presto { background: #b59a00; }
.galley .ok { background: #1f8a4c; } .galley .senza-data { background: #7d8f9c; }
.galley-buttons { display: flex; flex-direction: column; align-items: flex-end; gap: .2rem; }
#shopping li { align-items: center; }
#shopping .what { flex: 1; }

/* ---------------------------------------------------------------- voice */
#voice-button { flex: 0 0 auto; display: flex; align-items: center; padding: .55rem; color: var(--accent); }
#voice-button .stop-icon { display: none; }
#voice-button.recording { background: #c0392b; border-color: #c0392b; color: #fff; }
#voice-button.recording .mic-icon { display: none; }
#voice-button.recording .stop-icon { display: block; }
#voice-button.busy { opacity: .6; pointer-events: none; }
#chat-form.recording #chat-text { display: none; }
.voice-status { flex: 1 1 0; min-width: 0; display: flex; align-items: center; gap: .5rem; font-variant-numeric: tabular-nums; }
.voice-status::before { content: ""; width: .7rem; height: .7rem; border-radius: 50%; background: #c0392b; animation: voice-blink 1s infinite; }
.voice-status.working::before { background: var(--accent); }
@keyframes voice-blink { 50% { opacity: .2; } }
.voice-cancel { flex: 0 0 auto; padding: .55rem .7rem; }
#telegram-code { margin: .6rem 0; }
#telegram-code .code { font: 600 1.3rem/1.2 ui-monospace, monospace; letter-spacing: .05em; user-select: all; }
#telegram-code a.button { display: inline-block; text-decoration: none; }
#telegram-code p { margin: .4rem 0; }
#telegram-links[hidden] { display: none; }
#telegram-links li { display: flex; justify-content: space-between; align-items: center; gap: .5rem; }

/* ---------------------------------------------------------------- live voice (hands-free) */
#live-button { flex: 0 0 auto; display: flex; align-items: center; padding: .55rem; color: var(--accent); }
.live { position: fixed; inset: 0; z-index: 50; display: flex; flex-direction: column; gap: .8rem;
  padding: max(1rem, env(safe-area-inset-top)) 1rem max(1rem, env(safe-area-inset-bottom));
  background: #0e2a3d; color: #f2f6f9; }
.live[hidden] { display: none; }
.live-head { display: flex; justify-content: space-between; align-items: baseline; font-weight: 600; }
.live-clock { font-variant-numeric: tabular-nums; opacity: .85; }
.live-center { flex: 1 1 auto; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1rem; min-height: 12rem; }
.live-orb { --level: 0; width: 11rem; height: 11rem; border-radius: 50%; display: grid; place-items: center; text-align: center;
  font-size: 1.25rem; font-weight: 600; background: #1b4a69;
  box-shadow: 0 0 0 calc(var(--level) * 1.6rem) rgba(120, 190, 235, .25); transition: background .3s, box-shadow .08s; }
.live-orb[data-status="listening"] { background: #1f6f9e; }
.live-orb[data-status="thinking"], .live-orb[data-status="checking"] { background: #8a6d1f; animation: live-pulse 1.4s infinite; }
.live-orb[data-status="speaking"] { background: #2c8a5a; }
.live-orb[data-status="closed"] { background: #555; }
@keyframes live-pulse { 50% { opacity: .65; } }
.live-hint { margin: 0; opacity: .8; text-align: center; max-width: 22rem; }
.live-lines { list-style: none; margin: 0; padding: 0; max-height: 30vh; overflow-y: auto; display: flex; flex-direction: column; gap: .4rem; }
.live-lines li { padding: .45rem .7rem; border-radius: .6rem; background: rgba(255, 255, 255, .08); line-height: 1.35; }
.live-lines li.user { align-self: flex-end; background: rgba(120, 190, 235, .22); }
.live-lines li.partial { opacity: .75; }
.live-lines li:empty::before { content: '…'; }
.live-error { margin: 0; color: #ffb4a8; }
.live-controls { display: grid; grid-template-columns: 1fr 1fr; gap: .6rem; }
.live-controls .button { min-height: 3.2rem; font-size: 1.05rem; background: rgba(255, 255, 255, .12); color: #fff; border-color: rgba(255, 255, 255, .25); }
.live-controls .button[aria-pressed="true"] { background: #c0392b; border-color: #c0392b; }
.live-controls .danger-fill { background: #c0392b; border-color: #c0392b; }
.live-tool { margin: 0; padding: .45rem .8rem; border-radius: .6rem; background: rgba(255, 210, 120, .14); color: #ffe2a8; text-align: center; max-width: 24rem; }
.live-tool.done { background: rgba(120, 220, 160, .14); color: #bff0cf; }
.live-tool.failed { background: rgba(255, 140, 120, .16); color: #ffc4b8; }

/* ---------------------------------------------------------------- subscription */
.paused-screen { align-items: center; justify-content: center; padding: 1rem; background: var(--sea); }
.paused-screen .card { max-width: 26rem; text-align: center; }
.paused-screen .primary { width: 100%; padding: .9rem; font-size: 1.05rem; margin: .5rem 0; }
.billing-status { font-weight: 600; }
.billing-status.warn { color: var(--danger); }
.token-bar { display: flex; height: .7rem; border-radius: 999px; overflow: hidden; background: var(--line); margin: .4rem 0; }
.token-bar .month { background: var(--accent); }
.token-bar .topup { background: #2e8b57; }
.billing-actions { display: flex; flex-direction: column; gap: .5rem; margin-top: .75rem; }
label.waiver { flex-direction: row; gap: .5rem; align-items: flex-start; font-size: .85rem; }
label.waiver input { width: auto; margin-top: .15rem; flex: none; }
.billing-actions button { white-space: normal; text-align: center; }

/* paused: only the logbook, read only (export and print stay) */
.paused-screen .button { width: 100%; }
.readonly-bar { display: flex; align-items: center; justify-content: space-between; gap: .5rem; padding: .5rem .9rem;
  background: var(--warn-bg); border-bottom: 1px solid var(--warn-line); font-size: .9rem; }
body.readonly nav button:not([data-tab="log"]),
body.readonly #log-start, body.readonly #log-controls, body.readonly #log-close,
body.readonly #log-delete, body.readonly #log-table .del { display: none !important; }
body.readonly #log-table tr { cursor: default; }

/* ---------------------------------------------------------------- settings */
.header-actions { display: flex; align-items: center; gap: .6rem; }
.icon-button { background: none; border: none; color: var(--header-ink); padding: .25rem; display: grid; place-items: center; }
.icon-button.active { color: var(--accent); }
.settings-head { display: flex; flex-direction: column; gap: .2rem; margin: .2rem 0 .6rem; }
.settings-head .link { align-self: flex-start; padding: 0; }
.settings-head h2 { margin: 0; }
.settings-menu { list-style: none; padding: 0; overflow: hidden; }
.settings-menu li + li { border-top: 1px solid var(--line); }
.settings-menu button { width: 100%; display: flex; flex-direction: column; align-items: flex-start; gap: .1rem;
  background: none; border: none; border-radius: 0; padding: .75rem 1rem; text-align: left; color: var(--ink); }
.settings-menu button::after { content: '›'; position: absolute; right: 1.2rem; color: var(--muted); font-size: 1.3rem; }
.settings-menu li { position: relative; }
.settings-menu span { color: var(--muted); font-size: .85rem; }
.token-guide td { padding: .25rem .4rem .25rem 0; vertical-align: top; }
.token-guide td:last-child { white-space: nowrap; font-weight: 600; }
body.readonly #settings-open { display: none; }
/* the pane title already names the card: no second heading */
#billing-card > h2, #boat-form > h2, #agent-form > h2,
#tab-boat [data-pane="telegram"] > h2, #tab-boat [data-pane="manuals"] > h2, #tab-boat [data-pane="memory"] > h2 { display: none; }
nav button { padding-left: .55rem; padding-right: .55rem; }

/* connector: consent screen (connect.html) and «App collegate» */
main.connect { min-height: 100dvh; display: flex; align-items: center; justify-content: center; padding: 1rem; }
main.connect .narrow { width: min(100%, 420px); }
main.connect .ask { font-size: 1.05rem; margin-bottom: .3rem; }
main.connect .scopes { margin: 0 0 .6rem; padding-left: 1.2rem; }
main.connect .scopes li { margin: .3rem 0; }
main.connect .row { justify-content: flex-end; margin: .8rem 0 .4rem; }
#tab-boat [data-pane="apps"] > h2, #tab-boat [data-pane="look"] > h2 { display: none; }
#apps-list li { align-items: center; }
#apps-list li span small { display: block; color: var(--muted); }
.copy-url { display: flex; gap: .4rem; align-items: center; }
.copy-url code { flex: 1; overflow-wrap: anywhere; background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: .35rem .5rem; font-size: .85rem; }
/* public pages: connector guide, privacy, terms */
body.doc { overflow-y: auto; height: auto; }
main.doc { max-width: 760px; margin: 0 auto; padding: 1rem 1.2rem 3rem; line-height: 1.5; }
main.doc section { border-top: 1px solid var(--line); margin-top: 1.5rem; padding-top: .5rem; }
main.doc h1 { font-size: 1.5rem; } main.doc h2 { font-size: 1.1rem; margin-top: 1.2rem; }
main.doc code { background: var(--card); border: 1px solid var(--line); border-radius: 4px; padding: .1rem .3rem; }
.langs { font-size: .9rem; }

/* ---------------------------------------------------------------- look: type, header, bottom tabs */
h1, h2, .display { font-family: var(--font-display); text-transform: var(--display-case); letter-spacing: var(--display-spacing); }
h2 { font-weight: 600; }
a { color: var(--accent); }
:root[data-theme="logbook"] a { color: #7a5a2a; }
header strong#boat-title { font-family: var(--font-display); font-size: 1.35rem; text-transform: var(--display-case); letter-spacing: var(--display-spacing); display: block; line-height: 1.1; }
header #boat-sub { display: block; margin: .1rem 0 0; font-size: .82rem; }
header { border-bottom: 1px solid var(--line); }
:root[data-theme="logbook"] header { border-bottom: 2px solid var(--brass); }
#app > nav { order: 10; border-bottom: 0; border-top: 1px solid var(--line); background: var(--card);
  padding: .2rem .2rem calc(.2rem + env(safe-area-inset-bottom)); overflow-x: auto; }
#app > main { order: 5; }
#app > nav button { display: flex; flex-direction: column; align-items: center; gap: .15rem; min-height: 54px; flex: 1 0 58px;
  border-bottom: 0; border-top: 3px solid transparent; font-size: .7rem; padding: .3rem .2rem; }
#app > nav button svg { width: 22px; height: 22px; }
#app > nav button.active { border-top-color: var(--accent); border-bottom-color: transparent; }
:root[data-theme="instrument"] #app > nav button { text-transform: uppercase; letter-spacing: .05em; }
:root[data-theme="logbook"] #app > nav button.active { color: var(--accent); border-top-color: var(--brass); }
.msg.assistant { background: var(--card); }
:root[data-theme="instrument"] .tile-num strong { font-family: var(--font-display); font-size: 1.6rem; }

/* ---------------------------------------------------------------- splash and login */
.hero { display: flex; flex-direction: column; align-items: center; gap: .5rem; text-align: center; color: var(--ink); }
.hero .art { width: 220px; height: 220px; }
.hero .art .only-logbook { display: none; }
:root[data-theme="logbook"] .hero .art .only-logbook { display: inline; }
:root[data-theme="logbook"] .hero .art .only-instrument { display: none; }
.hero .kicker { margin: 0; font-size: .75rem; letter-spacing: .18em; text-transform: uppercase; color: var(--brass); }
.hero h1 { margin: 0; font-size: 2.2rem; line-height: 1.02; font-weight: 700; }
:root[data-theme="logbook"] .hero h1 { font-weight: 600; font-size: 2.3rem; }
.hero .tagline { margin: .2rem 0 0; max-width: 20rem; color: var(--muted); font-size: .98rem; line-height: 1.45; }
#splash { position: fixed; inset: 0; z-index: 100; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 1.5rem; background: var(--bg); transition: opacity .35s ease; }
#splash.gone { opacity: 0; pointer-events: none; }
:root[data-theme="logbook"] #splash { background: var(--sea); }
:root[data-theme="logbook"] #splash .hero, :root[data-theme="logbook"] #splash .hero h1 { color: #f4efe6; }
:root[data-theme="logbook"] #splash .tagline { color: #c9d3dc; }
.splash-bar { width: 140px; height: 3px; border-radius: 2px; background: var(--line); overflow: hidden; }
.splash-bar::after { content: ""; display: block; width: 40%; height: 100%; background: var(--accent); animation: splash-run 1.1s ease-in-out infinite; }
:root[data-theme="logbook"] .splash-bar { background: rgba(244, 239, 230, .2); }
:root[data-theme="logbook"] .splash-bar::after { background: var(--brass); }
@keyframes splash-run { 0% { transform: translateX(-100%); } 100% { transform: translateX(250%); } }
@media (prefers-reduced-motion: reduce) { .splash-bar::after { animation: none; } #splash { transition: none; } }
.dial-sweep { transform-origin: 140px 140px; animation: dial 6s ease-in-out infinite alternate; }
@keyframes dial { from { transform: rotate(-12deg); } to { transform: rotate(12deg); } }
@media (prefers-reduced-motion: reduce) { .dial-sweep { animation: none; } }
#login { justify-content: flex-start; gap: 1.2rem; padding: max(2rem, env(safe-area-inset-top)) 1.2rem 1.2rem; }
#login .hero .art { width: 170px; height: 170px; }
#login-form { gap: .8rem; padding: 1.2rem; }
#login-form input { min-height: 48px; font-size: 16px; }
#login-form .primary { min-height: 52px; font-size: 1.05rem; }
:root[data-theme="instrument"] #login-form .primary { font-family: var(--font-display); text-transform: uppercase; letter-spacing: .08em; font-size: 1.15rem; }
:root[data-theme="logbook"] #login { background: var(--sea); }
:root[data-theme="logbook"] #login .hero, :root[data-theme="logbook"] #login .hero h1 { color: #f4efe6; }
:root[data-theme="logbook"] #login .tagline { color: #c9d3dc; }
.legal { margin: auto 0 0; font-size: .75rem; color: var(--muted); text-align: center; }
.legal a { color: inherit; }
:root[data-theme="logbook"] #login .legal { color: #8fa0ae; }

/* ---------------------------------------------------------------- Impostazioni › Aspetto */
.themes { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .6rem; }
.theme-option { display: flex; flex-direction: column; gap: .4rem; padding: .5rem; border: 2px solid var(--line); border-radius: var(--radius);
  cursor: pointer; color: var(--ink); font-size: .9rem; }
.theme-option:has(input:checked) { border-color: var(--accent); }
:root[data-theme="logbook"] .theme-option:has(input:checked) { border-color: var(--brass); }
.theme-option input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.theme-option:focus-within { outline: 2px solid var(--accent); outline-offset: 2px; }
.theme-option strong { font-size: .95rem; }
.swatch { height: 76px; border-radius: 8px; display: flex; flex-direction: column; justify-content: space-between; padding: .45rem; }
.swatch.instrument { background: #0a1016; border: 1px solid #24323e; }
.swatch.logbook { background: #f4efe6; border: 1px solid #e2d8c6; }
.swatch .bar1 { height: 14px; border-radius: 3px; }
.swatch.instrument .bar1 { background: #121b23; border-left: 4px solid #39c6d6; }
.swatch.logbook .bar1 { background: #0e2233; border-bottom: 2px solid #b08d57; }
.swatch .dots { display: flex; gap: 4px; }
.swatch .dots span { width: 14px; height: 14px; border-radius: 7px; }
:root[data-theme="logbook"] .icon-button.active { color: var(--brass); }

/* ---------------------------------------------------------------- boat sheet gathered online */
#dossier h3 { font-family: var(--font-display); text-transform: var(--display-case); letter-spacing: var(--display-spacing);
  font-size: 1rem; margin: 1rem 0 .3rem; color: var(--brass); }
:root[data-theme="instrument"] #dossier h3 { color: var(--accent); }
.dossier-summary { margin: .2rem 0; font-size: 1rem; }
.dossier-fields { display: grid; grid-template-columns: minmax(7rem, 38%) 1fr; gap: .35rem .8rem; margin: 0; }
.dossier-fields dt { color: var(--muted); font-size: .88rem; }
.dossier-fields dd { margin: 0; font-weight: 500; }
.dossier-fields dd small { display: block; font-weight: 400; color: var(--muted); }
.refs { font-size: .75rem; white-space: nowrap; }
.refs a { margin-right: .15rem; text-decoration: none; }
.dossier-list, .dossier-sources { margin: 0; padding-left: 1.2rem; display: flex; flex-direction: column; gap: .3rem; }
.dossier-sources { font-size: .85rem; color: var(--muted); }
#dossier-card #boat-form > h2 { display: none; }
:root[data-theme="logbook"] #dossier h3 { color: #7a5a2a; }
