/* Stile di Jarvis: tema scuro unico, font di sistema (San Francisco su iPhone), pensato per lo schermo del telefono. */

:root {
  --bg: #0b0f14;
  --surface: #131a22;
  --surface-2: #1a232e;
  --border: #233040;
  --text: #e6edf3;
  --muted: #8b98a8;
  --accent: #5cc8d6;
  --accent-soft: rgba(92, 200, 214, 0.18);
  --accent-ink: #062126;
  --danger: #ff8a7a;
  --ok: #7fd49b;
  --warn: #f2c46d;
  --radius: 14px;
  color-scheme: dark;
}

* { box-sizing: border-box; }

/* La pagina non scorre e non "rimbalza": scorrono solo i messaggi e l'elenco (iPhone, app installata) */
html, body { height: 100%; overflow: hidden; overscroll-behavior: none; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 17px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

/* ---------- Schermate semplici (login, setup): colonna centrata ---------- */

/* Margini per notch e barra Home quando l'app è a schermo intero */
main {
  height: 100%;
  overflow-y: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(env(safe-area-inset-top) + 24px) calc(env(safe-area-inset-right) + 20px)
           calc(env(safe-area-inset-bottom) + 24px) calc(env(safe-area-inset-left) + 20px);
}

section {
  width: 100%;
  max-width: 400px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

section[hidden], [hidden] { display: none !important; }

/* Il simbolo di Jarvis, come l'icona: anello pieno, anello esterno trasparente, punto al centro */
.mark {
  width: 56px;
  height: 56px;
  flex: none;
  border-radius: 50%;
  border: 3px solid var(--accent);
  box-shadow: 0 0 0 5px var(--accent-soft);
  background: radial-gradient(circle, var(--accent) 0 7px, transparent 8px);
  margin: 5px 5px 8px;
}

[data-view="loading"] { align-items: center; }
[data-view="loading"] .mark { animation: pulse 1.6s ease-in-out infinite; }

@keyframes pulse {
  50% { opacity: 0.45; }
}

h1 {
  margin: 0;
  font-size: 30px;
  line-height: 1.15;
  font-weight: 700;
  letter-spacing: -0.02em;
}

p { margin: 0; }

.lead { color: var(--muted); }

.hint {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  font-size: 15px;
}

.footnote { color: var(--muted); font-size: 13px; }

form { display: flex; flex-direction: column; gap: 10px; }

label { font-size: 15px; color: var(--muted); }

input, textarea {
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 13px 14px;
  width: 100%;
}

input:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: transparent; }

button, .button {
  font: inherit;
  font-weight: 600;
  color: inherit;
  border: 0;
  border-radius: var(--radius);
  padding: 15px 18px;
  min-height: 52px;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
  transition: transform 120ms ease-out, opacity 120ms ease-out, background-color 120ms ease-out;
}

button:active, .button:active { transform: scale(0.97); }
button:disabled { opacity: 0.45; cursor: default; }

.primary { background: var(--accent); color: var(--accent-ink); margin-top: 8px; }
.secondary { background: var(--surface); color: var(--text); border: 1px solid var(--border); }

.message { min-height: 1.5em; font-size: 15px; color: var(--muted); }
.message.error { color: var(--danger); }

/* ---------- Schermate a tutto schermo (chat, elenco) ---------- */

/* Altezza e posizione seguono l'area davvero visibile (app.ts → fitViewport), così con la tastiera aperta
   la barra di scrittura resta subito sopra la tastiera */
.screen {
  position: fixed;
  top: var(--app-top, 0px);
  left: 0;
  right: 0;
  height: var(--app-height, 100%);
  max-width: none;
  gap: 0;
  padding: 0 env(safe-area-inset-right) 0 env(safe-area-inset-left);
  background: var(--bg);
}

.topbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: calc(env(safe-area-inset-top) + 6px) 8px 6px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}

.topbar-title {
  flex: 1;
  margin: 0;
  font-size: 17px;
  font-weight: 600;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.icon-button, .icon-button-spacer {
  flex: none;
  width: 44px;
  height: 44px;
  min-height: 44px;
  padding: 0;
  display: grid;
  place-items: center;
  background: transparent;
  border-radius: 12px;
}

.icon-button:active { background: var(--surface); }

svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* Messaggi */
.messages {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 16px 16px 8px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.empty {
  margin: auto 0;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 14px;
  padding-bottom: 12px;
}

.suggestions { display: flex; flex-wrap: wrap; gap: 8px; }

.chip {
  min-height: 40px;
  padding: 8px 14px;
  font-size: 15px;
  font-weight: 500;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
}

.turn-user {
  align-self: flex-end;
  max-width: 85%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 18px 18px 4px 18px;
  padding: 10px 14px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.turn-assistant {
  align-self: stretch;
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow-wrap: anywhere;
}

.activity { display: flex; flex-direction: column; gap: 4px; }

.activity-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  color: var(--muted);
}

.activity-item::before {
  content: "";
  flex: none;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  animation: pulse 1.2s ease-in-out infinite;
}

.activity-item.done::before { background: var(--ok); animation: none; }
.activity-item.failed::before { background: var(--danger); animation: none; }

.answer p, .answer ul, .answer ol, .answer pre { margin: 0 0 10px; }
.answer > :last-child { margin-bottom: 0; }
.answer ul, .answer ol { padding-left: 22px; }
.answer li { margin: 3px 0; }
.answer code {
  font: 14px/1.4 ui-monospace, "SF Mono", Menlo, monospace;
  background: var(--surface);
  border-radius: 6px;
  padding: 1px 5px;
}
.answer pre {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  overflow-x: auto;
}
.answer pre code { background: none; padding: 0; }
.answer a { color: var(--accent); }

.notice {
  font-size: 14px;
  color: var(--muted);
  background: var(--surface);
  border-radius: 10px;
  padding: 8px 12px;
}

.notice.error { color: var(--danger); }

.typing { display: flex; gap: 5px; padding: 6px 0; }
.typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--muted);
  animation: typing 1.2s ease-in-out infinite;
}
.typing span:nth-child(2) { animation-delay: 0.15s; }
.typing span:nth-child(3) { animation-delay: 0.3s; }

@keyframes typing {
  0%, 60%, 100% { opacity: 0.3; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-3px); }
}

.turn-meta { font-size: 12px; color: var(--muted); }

/* Barra di scrittura */
.composer {
  display: flex;
  flex-direction: row;
  align-items: flex-end;
  gap: 8px;
  padding: 8px 12px calc(env(safe-area-inset-bottom) + 8px);
  border-top: 1px solid var(--border);
  background: var(--bg);
}

.composer textarea {
  resize: none;
  overflow-y: hidden;
  max-height: 160px;
  min-height: 46px;
  line-height: 1.35;
  padding: 11px 14px;
  border-radius: 22px;
}

.send {
  flex: none;
  width: 46px;
  height: 46px;
  min-height: 46px;
  padding: 0;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-ink);
}

/* Elenco conversazioni */
.list-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px 16px calc(env(safe-area-inset-bottom) + 16px);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.conversation-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }

.conversation-item {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.conversation-open {
  flex: 1;
  min-width: 0;
  min-height: 56px;
  padding: 10px 4px 10px 14px;
  background: transparent;
  text-align: left;
  font-weight: 500;
  display: flex;
  flex-direction: column;
}

.conversation-open span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conversation-open small { color: var(--muted); font-size: 13px; font-weight: 400; }

.conversation-delete { color: var(--muted); }

.list-footer { margin-top: auto; padding-top: 24px; display: flex; flex-direction: column; gap: 12px; }

/* Cruscotto */
.home-body {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.recap-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.recap-label { font-size: 13px; color: var(--muted); }
.recap-summary { font-size: 17px; font-weight: 500; }
.recap-actions { display: flex; flex-wrap: wrap; gap: 8px; }

button.small { min-height: 40px; padding: 8px 14px; font-size: 15px; }

.status-list { display: flex; flex-direction: column; gap: 8px; }

.status-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.status-item {
  width: 100%;
  min-height: 60px;
  padding: 12px 14px;
  display: flex;
  align-items: center;
  gap: 12px;
  background: transparent;
  text-align: left;
  font-weight: 400;
}

.status-item:active { transform: none; background: var(--surface-2); }

.dot { flex: none; width: 10px; height: 10px; border-radius: 50%; background: var(--muted); }
.dot.ok { background: var(--ok); }
.dot.warn { background: var(--warn); }
.dot.error { background: var(--danger); }

.status-text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.status-text strong { font-size: 16px; font-weight: 600; }
.status-text span { font-size: 14px; color: var(--muted); }

.status-item svg { flex: none; width: 18px; height: 18px; color: var(--muted); transition: transform 150ms ease-out; }
.status-item[aria-expanded="true"] svg { transform: rotate(90deg); }

.status-details {
  padding: 0 14px 14px 36px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 14px;
}

.status-details .row { display: flex; justify-content: space-between; gap: 12px; }
.status-details .row span:last-child { color: var(--muted); text-align: right; }
.status-details .bad { color: var(--danger); }
.status-details .link { align-self: flex-start; margin-top: 8px; }

.ask-button {
  flex: 1;
  min-height: 46px;
  padding: 11px 16px;
  text-align: left;
  font-weight: 400;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 22px;
}

.settings-block { display: flex; flex-direction: column; gap: 8px; }
.settings-title { font-weight: 600; }

/* Sonda invisibile per leggere le zone riservate di iOS (usata da fitViewport in app.ts) */
.safe-probe {
  position: fixed;
  visibility: hidden;
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
}

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