/* Prototipo dello spike: tema solo scuro, layout mobile. Nessuna risorsa di terzi, nessuno stile inline. */

:root {
  color-scheme: dark;
  --bg: #0f1115;
  --panel: #171a21;
  --panel2: #1e222b;
  --line: #2a2f3a;
  --text: #e6e8ee;
  --muted: #98a1b2;
  --accent: #5b9dff;
  --accent-text: #0b1220;
  --danger: #ff6b6b;
  --ok: #3ecf8e;
  --warn: #f0b429;
  --vv-h: 100dvh;
  --vv-top: 0px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
}

body {
  overflow: hidden;
}

/* Sonde di misura (invisibili): unità di altezza e area sicura. */
#probes {
  position: fixed;
  left: 0;
  top: 0;
  width: 0;
  height: 0;
  visibility: hidden;
  pointer-events: none;
}

.probe {
  position: fixed;
  left: 0;
  top: 0;
  width: 1px;
}

#probe-vh {
  height: 100vh;
}

#probe-dvh {
  height: 100dvh;
}

#probe-svh {
  height: 100svh;
}

#probe-lvh {
  height: 100lvh;
}

#probe-safe {
  height: 0;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

/* Contenitore principale. layout=css: 100vh con ripiego e 100dvh. layout=vv: segue l'area visibile (tastiera di iOS). */
#app {
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
}

.layout-vv #app {
  position: fixed;
  left: 0;
  right: 0;
  top: var(--vv-top);
  height: var(--vv-h);
}

.view {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.scroll {
  overflow-y: auto;
}

/* Accesso */
.card {
  width: 100%;
  max-width: 26rem;
  margin: auto;
  padding: calc(24px + env(safe-area-inset-top)) calc(20px + env(safe-area-inset-right)) calc(24px + env(safe-area-inset-bottom))
    calc(20px + env(safe-area-inset-left));
}

h1 {
  margin: 0 0 4px;
  font-size: 1.5rem;
}

h3 {
  margin: 16px 0 4px;
  font-size: 0.9rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.muted {
  color: var(--muted);
  margin: 0 0 16px;
}

label {
  display: block;
  margin: 12px 0 4px;
  color: var(--muted);
  font-size: 0.9rem;
}

input,
textarea {
  width: 100%;
  font: inherit;
  font-size: 16px; /* almeno 16px: evita lo zoom automatico su iOS */
  color: var(--text);
  background: var(--panel2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
}

input:focus,
textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: 0;
}

button {
  font: inherit;
  color: var(--text);
  background: var(--panel2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 14px;
  min-height: 44px;
  cursor: pointer;
}

button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
}

button.small {
  min-height: 36px;
  padding: 6px 10px;
  font-size: 0.85rem;
}

button.link {
  background: none;
  border: none;
  color: var(--accent);
  padding: 8px 0;
  min-height: 0;
}

.card form > button.primary {
  width: 100%;
  margin-top: 16px;
}

#btn-send {
  flex: none;
}

.error {
  color: var(--danger);
  min-height: 1.4em;
  margin: 8px 0 0;
}

/* Chat */
.bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: calc(8px + env(safe-area-inset-top)) calc(12px + env(safe-area-inset-right)) 8px calc(12px + env(safe-area-inset-left));
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

.spacer {
  flex: 1;
}

.conn {
  font-size: 0.85rem;
  color: var(--muted);
}

.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--muted);
}

.dot.ok {
  background: var(--ok);
}

.dot.warn {
  background: var(--warn);
}

.dot.bad {
  background: var(--danger);
}

#messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 12px calc(12px + env(safe-area-inset-right)) 12px calc(12px + env(safe-area-inset-left));
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.msg {
  max-width: 85%;
  align-self: flex-start;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 8px 12px;
}

.msg.mine {
  align-self: flex-end;
  background: #1b2a44;
  border-color: #2b4266;
}

.msg.pending {
  opacity: 0.6;
}

.msg.failed {
  border-color: var(--danger);
}

.msg .meta {
  font-size: 0.75rem;
  color: var(--muted);
}

.msg .body {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

#composer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 8px calc(12px + env(safe-area-inset-right)) calc(8px + env(safe-area-inset-bottom)) calc(12px + env(safe-area-inset-left));
  background: var(--panel);
  border-top: 1px solid var(--line);
}

#input {
  flex: 1;
  resize: none;
  max-height: 7.5em;
  line-height: 1.35;
}

/* Diagnostica */
#diag {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 10;
  overflow-y: auto;
  background: var(--bg);
  padding: calc(8px + env(safe-area-inset-top)) calc(12px + env(safe-area-inset-right)) calc(24px + env(safe-area-inset-bottom))
    calc(12px + env(safe-area-inset-left));
}

.diag-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.diag-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

#sessions-list .sess {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 6px;
  font-size: 0.8rem;
}

pre {
  margin: 0;
  padding: 8px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font: 12px/1.35 ui-monospace, Menlo, Consolas, monospace;
}
