/* ------------------------------------------------------------------
   Riflesso — foglio di stile unico, nessuna dipendenza.
   Pensato per un telefono in mano: tocchi grandi, testo che non esce
   mai dallo schermo, barra di invio sempre sopra la tastiera.
------------------------------------------------------------------ */

:root {
  --bg: #131316;
  --bg-2: #1a1a1e;
  --surface: #1f1f24;
  --surface-2: #26262c;
  --line: #303038;
  --text: #ece9e6;
  --dim: #9b9691;
  --faint: #6e6a66;
  --me: #6d4232;
  --me-text: #f7efe9;
  --accent: #d97757;
  --bad: #e0685f;
  --ok: #5fbf7f;
  --code-bg: #0e0e11;
  --radius: 16px;
  --vh: 100vh;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none;
}

button, input, textarea, select { font: inherit; color: inherit; font-family: inherit; }
button { background: none; border: 0; cursor: pointer; }
.hidden { display: none !important; }

.screen {
  position: fixed;
  inset: 0;
  height: var(--vh);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ================= barra in alto ================= */

.bar {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: calc(var(--safe-top) + 8px) 6px 8px;
  background: var(--bg-2);
  border-bottom: 1px solid var(--line);
  flex: 0 0 auto;
  z-index: 5;
}
.bar-title {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 0 4px;
}
.bar-name {
  font-size: 17px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.bar-sub {
  font-size: 12px;
  color: var(--dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.icon {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  font-size: 21px;
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
}
.icon:active { background: var(--surface-2); }

.dot {
  display: inline-block;
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--bad);
  vertical-align: middle;
}
.dot.on { background: var(--ok); }

/* ================= accoppiamento ================= */

#pair { align-items: center; justify-content: center; padding: 24px; }
.pair-box { width: 100%; max-width: 340px; text-align: center; }
.pair-box h1 { margin: 0 0 4px; font-size: 30px; letter-spacing: -0.02em; }
.sub { margin: 0 0 22px; color: var(--dim); }
.hint { color: var(--faint); font-size: 14px; margin-bottom: 14px; }
.pin {
  width: 100%;
  padding: 16px;
  font-size: 30px;
  letter-spacing: 0.32em;
  text-align: center;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  color: var(--text);
}
.primary {
  width: 100%;
  margin-top: 14px;
  padding: 15px;
  border-radius: 14px;
  background: var(--accent);
  color: #24120b;
  font-weight: 600;
}
.primary:disabled { opacity: .5; }
.error { color: var(--bad); min-height: 22px; font-size: 14px; margin-top: 12px; }

/* ================= elenco chat ================= */

.searchwrap { padding: 8px 12px; background: var(--bg-2); border-bottom: 1px solid var(--line); }
.search {
  width: 100%;
  padding: 10px 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  -webkit-appearance: none;
}
.chatlist { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding-bottom: var(--safe-bottom); }

.chatrow {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 11px 14px;
  text-align: left;
  border-bottom: 1px solid var(--line);
}
.chatrow:active { background: var(--surface); }
.chatrow.closed { opacity: .58; }

.avatar {
  width: 44px; height: 44px;
  flex: 0 0 44px;
  border-radius: 50%;
  background: var(--surface-2);
  color: var(--dim);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  font-weight: 600;
  border: 1px solid var(--line);
}
.avatar[data-m^="Opus"] { background: #3a2a22; color: #e0a184; border-color: #4d372c; }
.avatar[data-m^="Sonnet"] { background: #22303a; color: #86bcd8; border-color: #2c414d; }
.avatar[data-m^="Haiku"] { background: #232f26; color: #8fce9f; border-color: #2d3f31; }

.chatrow-main { flex: 1; min-width: 0; }
.chatrow-top { display: flex; align-items: baseline; gap: 8px; }
.chatrow-title {
  flex: 1;
  min-width: 0;
  font-weight: 600;
  font-size: 16px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
/* Fuori dal titolo, cosi' non entra nel testo e non falsa il taglio con i
   puntini quando il titolo e' lungo. */
.star { color: var(--accent); flex: 0 0 auto; font-size: 13px; }
.chatrow-when { font-size: 12px; color: var(--faint); flex: 0 0 auto; }
.chatrow-bottom { display: flex; align-items: center; gap: 8px; margin-top: 2px; }
.chatrow-prev {
  flex: 1;
  min-width: 0;
  font-size: 14px;
  color: var(--dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.you { color: var(--faint); }
.chatrow-turns {
  flex: 0 0 auto;
  font-size: 11px;
  color: var(--faint);
  background: var(--surface-2);
  border-radius: 9px;
  padding: 1px 7px;
}
.livedot {
  display: inline-block;
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--ok);
  margin-right: 6px;
  animation: pulse 1.8s infinite;
}
@keyframes pulse { 50% { opacity: .35; } }

.empty { color: var(--faint); text-align: center; padding: 36px 20px; font-size: 15px; }

/* ================= la conversazione ================= */

.thread {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 10px 10px 4px;
}

.daysep {
  text-align: center;
  font-size: 12px;
  color: var(--faint);
  margin: 14px 0 10px;
  text-transform: lowercase;
}

.row { display: flex; margin: 5px 0; }
.row.me { justify-content: flex-end; }
.row.claude { justify-content: flex-start; }

.bubble {
  max-width: 86%;
  padding: 9px 13px;
  border-radius: var(--radius);
  word-wrap: break-word;
  overflow-wrap: anywhere;
  font-size: 15.5px;
}
.bubble.me { background: var(--me); color: var(--me-text); border-bottom-right-radius: 5px; }
/* Quando il contenuto e' lungo la bolla prende quasi tutta la larghezza:
   leggere una tabella dentro il 70% dello schermo e' una tortura. */
.bubble.claude {
  max-width: 96%;
  background: var(--surface);
  border: 1px solid var(--line);
  border-bottom-left-radius: 5px;
}
.bubble.img { padding: 5px; }
.bubble.img img { max-width: 100%; display: block; border-radius: 11px; }

/* --- markdown --- */
.bubble p { margin: 0 0 9px; }
.bubble p:last-child { margin-bottom: 0; }
.bubble h1, .bubble h2, .bubble h3, .bubble h4, .bubble h5, .bubble h6 {
  margin: 13px 0 7px; line-height: 1.3;
}
.bubble h1 { font-size: 20px; }
.bubble h2 { font-size: 18px; }
.bubble h3 { font-size: 16.5px; }
.bubble h4, .bubble h5, .bubble h6 { font-size: 15.5px; }
.bubble > :first-child { margin-top: 0; }
.bubble ul, .bubble ol { margin: 0 0 9px; padding-left: 21px; }
.bubble li { margin: 3px 0; }
.bubble .nested { margin: 3px 0; }
.bubble blockquote {
  margin: 9px 0;
  padding: 2px 0 2px 11px;
  border-left: 3px solid var(--line);
  color: var(--dim);
}
.bubble hr { border: 0; border-top: 1px solid var(--line); margin: 12px 0; }
.bubble a { color: #8fbcea; text-decoration: underline; }
.bubble code {
  background: rgba(255, 255, 255, .09);
  padding: 1px 5px;
  border-radius: 5px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: .87em;
}
.bubble.me code { background: rgba(0, 0, 0, .22); }

/* Le tabelle scorrono dentro il loro riquadro, non sfondano lo schermo. */
.tablewrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 9px 0;
  border: 1px solid var(--line);
  border-radius: 10px;
}
.tablewrap table { border-collapse: collapse; width: 100%; font-size: 14px; }
.tablewrap th, .tablewrap td {
  padding: 7px 11px;
  border-bottom: 1px solid var(--line);
  border-right: 1px solid var(--line);
  text-align: left;
  white-space: nowrap;
}
.tablewrap th { background: var(--surface-2); font-weight: 600; }
.tablewrap tr:last-child td { border-bottom: 0; }
.tablewrap th:last-child, .tablewrap td:last-child { border-right: 0; }

/* --- blocchi di codice --- */
.code {
  margin: 9px 0;
  border: 1px solid var(--line);
  border-radius: 11px;
  overflow: hidden;
  background: var(--code-bg);
}
.code-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 5px 6px 5px 11px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--line);
}
.code-lang { font-size: 11.5px; color: var(--dim); text-transform: lowercase; }
.copy {
  font-size: 12px;
  color: var(--dim);
  padding: 4px 10px;
  border-radius: 8px;
  background: var(--surface);
  border: 1px solid var(--line);
}
.copy:active { background: var(--line); }
.code pre {
  margin: 0;
  padding: 10px 12px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.code code {
  background: none;
  padding: 0;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12.5px;
  line-height: 1.5;
  white-space: pre;
  color: #d7d3ce;
}

/* --- strumenti: una riga sola --- */
.tool, .fold {
  margin: 4px 0;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--bg-2);
  overflow: hidden;
}
.tool.bad { border-color: #5b3230; }
.tool-head, .fold-head {
  display: flex;
  align-items: center;
  gap: 7px;
  width: 100%;
  padding: 7px 11px;
  text-align: left;
  font-size: 13.5px;
  color: var(--dim);
  min-width: 0;
}
.tool-ico { flex: 0 0 auto; opacity: .8; }
.tool-name { flex: 0 0 auto; color: var(--text); font-weight: 500; }
.tool-brief {
  flex: 1;
  min-width: 0;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  color: var(--faint);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.caret { flex: 0 0 auto; opacity: .55; transition: transform .15s; }
.tool-head.open .caret, .fold-head.open .caret { transform: rotate(180deg); }
.tool-body, .fold-body { padding: 0 9px 9px; font-size: 14px; }
.tool-body .code, .fold-body .code { margin-top: 8px; }
.tool-note { color: var(--faint); font-size: 12.5px; margin: 8px 0 0; }
.fold-head { color: var(--faint); }
.fold-body { color: var(--dim); }
.fold.think { background: transparent; border-style: dashed; }

.chip {
  margin: 6px auto;
  padding: 4px 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--faint);
  font-size: 12.5px;
  width: fit-content;
  max-width: 92%;
  text-align: center;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.chip.warn { color: var(--bad); border-color: #4d302e; }
/* Blocchi di servizio: ci sono, ma non chiedono attenzione. */
.chip.faint { opacity: .5; font-size: 11.5px; border-style: dashed; }

/* --- una fila di strumenti consecutivi, chiusa in una riga --- */
.toolgroup {
  margin: 4px 0;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--bg-2);
}
.toolgroup.bad { border-color: #5b3230; }
.toolgroup > .tool-head { border-radius: 11px; }
.toolgroup-body {
  padding: 0 7px 7px;
  /* Gli strumenti dentro il gruppo non ripetono la cornice del gruppo. */
  border-top: 1px solid var(--line);
  margin-top: -1px;
  padding-top: 7px;
}
.toolgroup-body .tool { background: var(--surface); }

.more-wrap { text-align: center; padding: 8px 0 12px; }
.more {
  padding: 8px 18px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--dim);
  font-size: 13.5px;
}

/* --- risposta in arrivo --- */
.live-row { flex-direction: column; align-items: flex-start; }
.live-row .bubble { max-width: 96%; }
.working {
  display: flex;
  align-items: center;
  gap: 9px;
  color: var(--faint);
  font-size: 13px;
  padding: 7px 4px 3px;
}
.spin {
  width: 12px; height: 12px;
  border: 2px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.note {
  padding: 9px 14px;
  font-size: 13.5px;
  color: var(--dim);
  background: var(--surface);
  border-top: 1px solid var(--line);
}
.note.bad { color: var(--bad); }

/* ================= barra di invio ================= */

.composer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 8px 10px calc(8px + var(--safe-bottom));
  background: var(--bg-2);
  border-top: 1px solid var(--line);
  flex: 0 0 auto;
}
.composer textarea {
  flex: 1;
  min-height: 42px;
  max-height: 132px;
  padding: 10px 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 21px;
  resize: none;
  overflow-y: auto;
  line-height: 1.35;
  -webkit-appearance: none;
}
.send, .stop {
  width: 42px; height: 42px;
  flex: 0 0 42px;
  border-radius: 50%;
  background: var(--accent);
  color: #24120b;
  font-size: 19px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}
.stop { background: var(--bad); color: #fff; font-size: 13px; }

/* ================= specchio ================= */

#stage {
  flex: 1;
  position: relative;
  background: #000;
  overflow: hidden;
  touch-action: none;
}
#screen { width: 100%; height: 100%; display: block; }
.overlay-msg {
  position: absolute;
  inset: auto 12px 12px;
  padding: 11px 14px;
  background: rgba(0, 0, 0, .82);
  border: 1px solid var(--line);
  border-radius: 12px;
  font-size: 13.5px;
  color: var(--dim);
  white-space: pre-line;
}
.tap-dot {
  position: absolute;
  width: 26px; height: 26px;
  margin: -13px 0 0 -13px;
  border: 2px solid var(--accent);
  border-radius: 50%;
  opacity: 0;
  pointer-events: none;
}
.tap-dot.flash { animation: tap .45s ease-out; }
@keyframes tap {
  from { opacity: .9; transform: scale(.45); }
  to { opacity: 0; transform: scale(1.5); }
}

#zoombar, #keys {
  display: flex;
  gap: 6px;
  padding: 7px 10px;
  background: var(--bg-2);
  border-top: 1px solid var(--line);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  flex: 0 0 auto;
}
#zoombar button, #keys button {
  flex: 0 0 auto;
  padding: 7px 13px;
  border-radius: 10px;
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--dim);
  font-size: 13.5px;
}
#zoombar button.active, #zoombar button[data-on="1"] {
  background: var(--accent);
  border-color: var(--accent);
  color: #24120b;
}

/* ================= pannelli ================= */

.backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .6);
  z-index: 20;
}
.sheet {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  max-height: 88vh;
  background: var(--bg-2);
  border-top: 1px solid var(--line);
  border-radius: 20px 20px 0 0;
  z-index: 21;
  display: flex;
  flex-direction: column;
}
.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 8px 12px 18px;
  border-bottom: 1px solid var(--line);
}
.sheet-head h2 { margin: 0; font-size: 17px; }
.sheet-body {
  overflow-y: auto;
  padding: 6px 18px calc(20px + var(--safe-bottom));
  -webkit-overflow-scrolling: touch;
}
.row.check, .sheet-body .row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 13px 0;
  border-bottom: 1px solid var(--line);
  margin: 0;
}
.sheet-body .row.col { flex-direction: column; align-items: stretch; border-bottom: 0; }
.row select {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 11px;
  max-width: 58%;
}
.row.check input { width: 22px; height: 22px; accent-color: var(--accent); }
.secondary, .danger {
  margin-top: 9px;
  padding: 13px;
  border-radius: 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--text);
}
.danger { color: var(--bad); border-color: #4d302e; }
.warn {
  margin: 12px 0;
  padding: 11px 13px;
  border-radius: 11px;
  background: #2e211f;
  border: 1px solid #4d302e;
  color: #eab5ad;
  font-size: 13.5px;
}
.fineprint { color: var(--faint); font-size: 12.5px; margin: 16px 0 0; line-height: 1.5; }
.fineprint code { background: var(--surface); padding: 1px 5px; border-radius: 5px; }
.diag {
  margin-top: 14px;
  padding: 11px;
  background: var(--code-bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11.5px;
  color: var(--faint);
  white-space: pre-wrap;
}

/* Niente zoom: la pizzicata e il doppio tocco non ingrandiscono piu' la pagina.
   `pan-x pan-y` lascia intatto lo scorrimento, toglie solo l'ingrandimento. */
html, body { touch-action: pan-x pan-y; }

/* Scelta del modello: righe grandi, si toccano col pollice. */
.bar-sub.tappable { text-decoration: underline; text-underline-offset: 3px; cursor: pointer; }
.modellist { display: flex; flex-direction: column; gap: 2px; }
.modelrow {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 12px; border-radius: 12px; background: transparent;
  border: 0; width: 100%; font: inherit; color: inherit; text-align: left;
}
.modelrow:active { background: rgba(127,127,127,.18); }
.modelrow[aria-current="true"] { background: rgba(127,127,127,.12); font-weight: 600; }
.modelrow .tick { opacity: .9; }

/* Il modello e' un pulsante, non una scritta: si deve vedere che si tocca. */
.modelchip {
  flex: 0 0 auto;
  padding: 6px 10px;
  margin-right: 4px;
  border-radius: 999px;
  border: 1px solid rgba(127,127,127,.35);
  background: transparent;
  color: inherit;
  font: inherit;
  font-size: .82rem;
  line-height: 1;
  white-space: nowrap;
}
.modelchip:active { background: rgba(127,127,127,.2); }

.sheet-sub { margin: 18px 0 6px; font-size: .95rem; opacity: .75; font-weight: 600; }

/* «Sta lavorando»: la stessa riga che mostra il Mac — tempo, token, strumento. */
.working {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 14px; font-size: .82rem; color: var(--dim);
  border-top: 1px solid rgba(127,127,127,.15);
}
.working .spin { display: inline-block; animation: gira 1.6s linear infinite; }
@keyframes gira { to { transform: rotate(360deg); } }
