:root {
  color-scheme: dark;
  --bg: oklch(11% 0.02 255);
  --surface: oklch(14% 0.02 255);
  --surface-2: oklch(15% 0.02 255);
  --sidebar: oklch(9% 0.02 255);
  --input: oklch(9% 0.015 255);
  --border: oklch(26% 0.02 255);
  --border-strong: oklch(32% 0.03 255);
  --text: oklch(95% 0.01 255);
  --text-2: oklch(72% 0.02 255);
  --muted: oklch(60% 0.02 255);
  --muted-2: oklch(55% 0.02 255);
  --accent: oklch(78% 0.15 215);
  --accent-dim: oklch(60% 0.15 215);
  --accent-deep: oklch(55% 0.13 215);
  --core: oklch(99% 0.005 100);
  --online: oklch(78% 0.16 150);
  --danger: oklch(62% 0.19 25);
  --font: "Space Grotesk", sans-serif;
  --mono: "JetBrains Mono", monospace;
  --glow: 0 4px 20px -4px oklch(78% 0.15 215 / 0.6);
  --glow-strong: 0 6px 26px -2px oklch(78% 0.15 215 / 0.8);
  --topbar-h: calc(58px + env(safe-area-inset-top, 0px));
  --kb-inset: 0px;
}

@keyframes sn-twinkle {
  0%, 100% { opacity: 0.15; }
  50% { opacity: 1; }
}

@keyframes sn-breathe {
  0%, 100% { transform: scale(1); opacity: 0.85; }
  50% { transform: scale(1.08); opacity: 1; }
}

@keyframes sn-ring {
  0% { transform: scale(0.9); opacity: 0.45; }
  100% { transform: scale(1.6); opacity: 0; }
}

@keyframes sn-pulse-dot {
  0%, 100% { box-shadow: 0 0 0 0 oklch(78% 0.16 150 / 0.6); }
  50% { box-shadow: 0 0 0 5px oklch(78% 0.16 150 / 0); }
}

@keyframes sheet-up {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

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

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  touch-action: pan-x pan-y;
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  overflow: hidden;
  position: fixed;
  inset: 0;
  width: 100%;
}

button, input, textarea, select { font: inherit; color: inherit; }

/* iOS zooma se gli input sono < 16px */
input, textarea, select { font-size: 16px; }

button { cursor: pointer; }

a { color: var(--accent); }
a:hover { color: oklch(88% 0.13 215); }

.hidden { display: none !important; }
[hidden] { display: none !important; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar-thumb {
  background: oklch(28% 0.02 255);
  border-radius: 4px;
}

/* —— Supernova emblem —— */
.sn-emblem {
  position: relative;
  pointer-events: none;
}

.sn-ring {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 1px solid oklch(78% 0.15 215 / 0.35);
  animation: sn-ring 3.2s ease-out infinite;
}

.sn-ring-delay {
  inset: 40px;
  border-color: oklch(78% 0.15 215 / 0.25);
  animation-delay: 1.1s;
}

.sn-core {
  position: absolute;
  inset: 38%;
  border-radius: 50%;
  background: radial-gradient(
    circle at 50% 50%,
    var(--core) 0%,
    var(--accent) 40%,
    oklch(55% 0.13 215 / 0.5) 68%,
    transparent 75%
  );
  filter: blur(1px);
  animation: sn-breathe 4s ease-in-out infinite;
  box-shadow:
    0 0 70px 10px oklch(55% 0.13 215 / 0.55),
    0 0 140px 40px oklch(78% 0.15 215 / 0.25);
}

.sn-core-lg {
  inset: 34%;
  filter: none;
  box-shadow: 0 0 60px 10px oklch(55% 0.13 215 / 0.5);
  animation-name: sn-breathe;
}

.sn-dot {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  flex-shrink: 0;
  background: radial-gradient(
    circle at 50% 50%,
    var(--core),
    var(--accent) 55%,
    oklch(55% 0.13 215 / 0.4) 78%,
    transparent 82%
  );
  box-shadow: 0 0 12px 2px oklch(78% 0.15 215 / 0.5);
}

.stars {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
}

.star {
  position: absolute;
  border-radius: 50%;
  background: oklch(95% 0.01 255);
  animation: sn-twinkle var(--dur, 3s) ease-in-out infinite;
  animation-delay: var(--delay, 0s);
}

/* —— Login —— */
.login-page {
  min-height: 100dvh;
  overflow: auto;
  background: var(--bg);
}

.login-shell {
  position: relative;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  overflow: hidden;
}

.login-emblem {
  position: absolute;
  left: 50%;
  top: 32%;
  transform: translate(-50%, -50%);
  width: min(340px, 78vw);
  height: min(340px, 78vw);
  z-index: 1;
}

.login-emblem .sn-core { inset: 38%; }

.login-card {
  position: relative;
  z-index: 2;
  width: min(380px, 88vw);
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 40px 32px 32px;
  margin-top: 120px;
  background: oklch(15% 0.02 255 / 0.72);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border: 1px solid oklch(35% 0.03 255 / 0.5);
  border-radius: 4px;
  box-shadow: 0 30px 80px -20px oklch(0% 0 0 / 0.7);
}

.login-heading { text-align: center; }

.login-heading h1 {
  margin: 0;
}

.login-heading p {
  margin: 10px 0 0;
  font-size: 13px;
  color: oklch(62% 0.02 255);
  font-family: var(--mono);
}

.login-card label {
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 12px;
  letter-spacing: 0.04em;
  color: oklch(65% 0.02 255);
  font-family: var(--mono);
  text-transform: uppercase;
}

.login-card input {
  padding: 12px 14px;
  border-radius: 3px;
  border: 1px solid var(--border-strong);
  background: var(--input);
  color: var(--text);
  font-size: 16px;
  font-family: var(--font);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.login-card input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px oklch(78% 0.15 215 / 0.18);
}

.login-card button[type="submit"] {
  margin-top: 6px;
  padding: 13px;
  border-radius: 3px;
  border: none;
  background: linear-gradient(180deg, var(--accent), var(--accent-dim));
  color: var(--bg);
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.03em;
  box-shadow: 0 4px 24px -4px oklch(78% 0.15 215 / 0.5);
  transition: transform 0.15s, box-shadow 0.15s, opacity 0.15s;
}

.login-card button[type="submit"]:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 32px -2px oklch(78% 0.15 215 / 0.75);
}

.login-card button[type="submit"]:disabled {
  opacity: 0.6;
  cursor: wait;
  transform: none;
}

#login-error {
  min-height: 14px;
  text-align: center;
  font-size: 12px;
  color: var(--danger);
  font-family: var(--mono);
}

/* —— App shell —— */
#app {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 100%;
  height: 100svh;
  overflow: hidden;
  background: var(--bg);
}

.scrim {
  position: fixed;
  inset: 0;
  z-index: 19;
  background: oklch(5% 0.01 255 / 0.55);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}

#sidebar {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  width: min(80vw, 300px);
  height: 100%;
  background: var(--sidebar);
  border-right: 1px solid oklch(26% 0.02 255 / 0.6);
  transform: translateX(-100%);
  transition: transform 0.28s ease;
}

#sidebar.open { transform: translateX(0); }

#sidebar > header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: max(18px, env(safe-area-inset-top)) 16px 14px;
  border-bottom: 1px solid oklch(26% 0.02 255 / 0.6);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand-mark {
  font-family: var(--font);
  font-weight: 600;
  letter-spacing: 0.08em;
  color: var(--text);
}

.brand-a {
  color: oklch(78% 0.15 215);
  text-shadow: 0 0 12px oklch(78% 0.15 215 / 0.45);
}

.brand-mark.login-title {
  display: block;
  font-size: 28px;
  font-weight: 600;
  letter-spacing: 0.12em;
}

.brand-mark.sidebar-title {
  font-size: 16px;
  letter-spacing: 0.1em;
}

.empty-brand {
  margin: 0;
  font-size: 28px;
  font-weight: 600;
  z-index: 2;
}

.empty-brand .brand-mark {
  font-size: inherit;
  letter-spacing: 0.12em;
}

.message .tag .brand-a {
  color: var(--accent);
  text-shadow: none;
}

#close-side {
  background: none;
  border: none;
  color: oklch(65% 0.02 255);
  padding: 4px;
  line-height: 1;
  display: grid;
  place-items: center;
}

#new-chat {
  margin: 14px 16px 6px;
  padding: 11px 14px;
  border-radius: 3px;
  border: 1px solid oklch(78% 0.15 215 / 0.4);
  background: oklch(78% 0.15 215 / 0.08);
  color: oklch(88% 0.1 215);
  font-size: 13px;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: background 0.15s, border-color 0.15s;
}

#new-chat:hover {
  background: oklch(78% 0.15 215 / 0.16);
  border-color: oklch(78% 0.15 215 / 0.7);
}

#conversation-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.conversation {
  display: flex;
  align-items: center;
  gap: 2px;
  border-radius: 4px;
  background: transparent;
}

.conversation.active {
  background: oklch(78% 0.15 215 / 0.1);
}

.conversation .conv-main {
  all: unset;
  box-sizing: border-box;
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 4px 10px 12px;
  cursor: pointer;
  font-size: 13px;
  color: var(--text-2);
  font-family: var(--font);
}

.conversation.active .conv-main { color: oklch(92% 0.01 255); }

.conversation .conv-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.conversation .conv-time {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--muted-2);
  flex-shrink: 0;
}

.conversation .conv-edit {
  flex: 1;
  min-width: 0;
  margin: 0 8px;
  padding: 8px 10px;
  background: var(--input);
  border: 1px solid oklch(78% 0.15 215 / 0.5);
  border-radius: 3px;
  color: var(--text);
  font-size: 13px;
  font-family: var(--font);
  outline: none;
}

.conversation .conv-delete {
  all: unset;
  box-sizing: border-box;
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  cursor: pointer;
  color: oklch(50% 0.02 255);
  font-size: 13px;
  margin-right: 6px;
}

.conversation .conv-delete:hover {
  color: var(--danger);
  background: oklch(62% 0.19 25 / 0.1);
}

#sidebar > footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-top: 1px solid oklch(26% 0.02 255 / 0.6);
}

.user-label {
  font-size: 13px;
  color: oklch(70% 0.02 255);
  font-family: var(--mono);
}

#logout {
  background: none;
  border: none;
  color: oklch(60% 0.02 255);
  font-size: 12px;
  font-family: var(--mono);
  padding: 0;
}

#logout:hover { color: var(--accent); }

/* —— Main —— */
main {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-width: 0;
  min-height: 0;
  position: relative;
  overflow: hidden;
}

.topbar {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  height: var(--topbar-h);
  padding: env(safe-area-inset-top, 0px) 12px 0;
  border-bottom: 1px solid oklch(26% 0.02 255 / 0.6);
  background: var(--bg);
  flex-shrink: 0;
  z-index: 15;
}

#open-side {
  background: none;
  border: none;
  color: oklch(80% 0.01 255);
  padding: 4px;
  line-height: 1;
  display: grid;
  place-items: center;
}

#title {
  flex: 1;
  min-width: 0;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 3px;
  color: var(--text);
  font-size: 16px;
  font-weight: 500;
  padding: 6px 8px;
  outline: none;
}

#title:hover { background: oklch(15% 0.02 255 / 0.5); }

#title:focus {
  border-color: var(--border-strong);
  background: var(--input);
}

#status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: var(--mono);
  font-size: 11px;
  color: oklch(70% 0.02 255);
  padding: 5px 10px;
  border: 1px solid var(--border);
  border-radius: 20px;
  flex-shrink: 1;
  min-width: 0;
  max-width: 130px;
  background: none;
}

#status-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--online);
  animation: sn-pulse-dot 2s infinite;
  flex-shrink: 0;
}

#status.offline .status-dot {
  background: var(--danger);
  animation: none;
}

#settings {
  background: none;
  border: 1px solid var(--border);
  color: oklch(80% 0.01 255);
  width: 32px;
  height: 32px;
  border-radius: 3px;
  flex-shrink: 0;
  display: grid;
  place-items: center;
  display: grid;
  place-items: center;
  padding: 0;
  transition: border-color 0.15s, color 0.15s;
}

#settings:hover {
  border-color: oklch(78% 0.15 215 / 0.5);
  color: oklch(88% 0.1 215);
}

#empty {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  position: relative;
  overflow: hidden;
  text-align: center;
  padding: 24px;
}

#empty p {
  margin: 0;
  font-size: 14px;
  color: var(--muted);
  z-index: 2;
  max-width: 280px;
}

#messages {
  flex: 1;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 24px 0;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.message {
  display: flex;
  padding: 0 20px;
}

.message.user { justify-content: flex-end; }
.message.assistant { justify-content: flex-start; }

.message .bubble {
  max-width: min(560px, 78%);
  padding: 12px 16px;
  border-radius: 8px;
}

.message.user .bubble {
  background: oklch(30% 0.06 220);
  border: 1px solid oklch(45% 0.08 220 / 0.5);
  color: var(--text);
}

.message.assistant .bubble {
  background: oklch(16% 0.015 255);
  border: 1px solid var(--border);
  color: oklch(92% 0.01 255);
}

.message .tag {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.04em;
  color: var(--accent);
  margin-bottom: 6px;
  text-transform: uppercase;
}

@keyframes thinking-dots {
  0%, 20% { opacity: 0.25; }
  50% { opacity: 1; }
  100% { opacity: 0.25; }
}

.message .thinking {
  margin: 0 0 12px;
  border: 1px solid oklch(78% 0.15 215 / 0.35);
  border-radius: 8px;
  background: linear-gradient(180deg, oklch(14% 0.02 215 / 0.9), oklch(11% 0.015 255 / 0.9));
  overflow: hidden;
  opacity: 1;
  transform: translateY(0);
  transition: opacity 220ms ease, transform 220ms ease, max-height 220ms ease;
  max-height: 220px;
}

.message .thinking.thinking-live {
  box-shadow: inset 0 0 0 1px oklch(78% 0.15 215 / 0.12);
}

.message .thinking.thinking-out {
  opacity: 0;
  transform: translateY(-6px);
  max-height: 0;
  margin: 0;
  border-width: 0;
  pointer-events: none;
}

.message .thinking-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 12px;
  border-bottom: 1px solid oklch(78% 0.15 215 / 0.18);
}

.message .thinking-label {
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
}

.message .thinking-dots::after {
  content: "•••";
  letter-spacing: 0.15em;
  color: oklch(70% 0.08 215);
  animation: thinking-dots 1.1s ease-in-out infinite;
}

.message .thinking-body {
  padding: 10px 12px 12px;
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.55;
  color: oklch(68% 0.02 255);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  max-height: 160px;
  overflow-y: auto;
}

.message .thinking-body:empty::after {
  content: "sta elaborando…";
  color: oklch(55% 0.02 255);
  font-style: italic;
}

.message .content {
  font-size: 14.5px;
  line-height: 1.55;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.message .time {
  font-family: var(--mono);
  font-size: 10px;
  color: oklch(50% 0.02 255);
  margin-top: 8px;
  text-align: right;
}

#composer {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 12px 14px max(12px, env(safe-area-inset-bottom), var(--kb-inset));
  border-top: 1px solid oklch(26% 0.02 255 / 0.6);
  flex-shrink: 0;
  background: var(--bg);
  z-index: 14;
  transition: padding-bottom 160ms ease-out;
}

body.kb-open #composer {
  padding-bottom: max(10px, var(--kb-inset));
}

#composer textarea {
  flex: 1;
  resize: none;
  background: var(--surface-2);
  border: 1px solid oklch(28% 0.02 255);
  border-radius: 6px;
  color: var(--text);
  font-size: 16px;
  font-family: var(--font);
  padding: 12px 14px;
  max-height: 160px;
  outline: none;
  line-height: 1.4;
  transition: border-color 0.15s, box-shadow 0.15s;
}

#composer textarea:focus {
  border-color: oklch(78% 0.15 215 / 0.6);
  box-shadow: 0 0 0 3px oklch(78% 0.15 215 / 0.15);
}

.icon {
  display: inline-block;
  vertical-align: middle;
  flex-shrink: 0;
  width: 20px;
  height: 20px;
}

.icon-sm {
  width: 16px;
  height: 16px;
}

button .icon {
  pointer-events: none;
}

#img-btn {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 1px solid oklch(28% 0.02 255);
  background: var(--surface-2);
  color: var(--text);
  display: grid;
  place-items: center;
  flex-shrink: 0;
  transition: border-color 0.15s, opacity 0.15s;
}

#img-btn:hover { border-color: oklch(78% 0.15 215 / 0.55); }
#img-btn:disabled { opacity: 0.45; }

#send {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: none;
  background: linear-gradient(180deg, var(--accent), var(--accent-dim));
  color: var(--bg);
  display: grid;
  place-items: center;
  flex-shrink: 0;
  box-shadow: var(--glow);
  transition: box-shadow 0.15s, opacity 0.15s;
}

.sheet-note {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
}

.actions .ghost {
  background: transparent;
  border: 1px solid oklch(28% 0.02 255);
  color: var(--text);
}

.message .gen-image {
  margin: 0 0 10px;
  padding: 0;
}

.message .gen-image img {
  display: block;
  width: 100%;
  max-width: 420px;
  border-radius: 10px;
  border: 1px solid oklch(28% 0.02 255);
  background: #0b0d12;
}

.img-timer {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  margin-top: 2px;
  padding: 8px 12px;
  border: 1px solid oklch(28% 0.02 255);
  border-radius: 999px;
  background: oklch(18% 0.02 255 / 0.75);
  font-family: var(--mono, "JetBrains Mono", ui-monospace, monospace);
  font-size: 12px;
  letter-spacing: 0.02em;
}

.img-timer:not(.done) .img-timer-clock {
  color: oklch(88% 0.12 215);
  animation: img-timer-pulse 1.2s ease-in-out infinite;
}

.img-timer.done .img-timer-clock {
  color: oklch(82% 0.12 150);
}

.img-timer.done.error .img-timer-clock {
  color: var(--danger);
}

.img-timer-label {
  color: var(--muted);
  font-family: var(--font);
  letter-spacing: 0;
}

.img-timer-clock {
  min-width: 3.4em;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}

.img-meta {
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
}

@keyframes img-timer-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.45; }
}

#send:hover { box-shadow: var(--glow-strong); }
#send:disabled { opacity: 0.5; cursor: wait; }

/* —— Bottom sheet —— */
.sheet-overlay {
  position: fixed;
  inset: 0;
  z-index: 30;
  background: oklch(5% 0.01 255 / 0.7);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.sheet {
  width: 100%;
  max-width: 520px;
  max-height: min(92dvh, 720px);
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid oklch(30% 0.03 255 / 0.6);
  border-bottom: none;
  border-radius: 16px 16px 0 0;
  padding: 20px 20px max(20px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 16px;
  box-shadow: 0 -20px 60px -20px oklch(0% 0 0 / 0.8);
  animation: sheet-up 0.28s ease;
}

.sheet-handle {
  width: 36px;
  height: 4px;
  border-radius: 2px;
  background: oklch(30% 0.02 255);
  margin: -8px auto 0;
}

.sheet > header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.sheet > header h2 {
  margin: 0;
  font-size: 17px;
  font-weight: 600;
}

#close-modal,
#close-img-modal {
  background: none;
  border: none;
  color: oklch(65% 0.02 255);
  padding: 4px;
  line-height: 1;
  display: grid;
  place-items: center;
}

.sheet-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.field-label {
  display: flex;
  flex-direction: column;
  gap: 7px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: oklch(65% 0.02 255);
  font-family: var(--mono);
}

.model-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 240px;
  overflow-y: auto;
}

.model-row {
  all: unset;
  box-sizing: border-box;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 5px;
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--input);
  color: oklch(92% 0.01 255);
  font-family: var(--font);
}

.model-row.active {
  border-color: oklch(78% 0.15 215 / 0.6);
  background: oklch(78% 0.15 215 / 0.1);
}

.model-row:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.model-dot {
  flex-shrink: 0;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid oklch(40% 0.02 255);
  background: transparent;
}

.model-row.active .model-dot {
  border-color: var(--accent);
  background: radial-gradient(circle, var(--core), var(--accent));
  box-shadow: 0 0 8px 1px oklch(78% 0.15 215 / 0.6);
}

.model-meta {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
  text-align: left;
}

.model-meta strong {
  font-size: 13.5px;
  font-weight: 500;
}

.model-meta span {
  font-family: var(--mono);
  font-size: 10.5px;
  color: oklch(58% 0.02 255);
}

#system-prompt {
  padding: 10px 12px;
  border-radius: 3px;
  border: 1px solid oklch(30% 0.03 255);
  background: var(--input);
  color: oklch(90% 0.01 255);
  font-size: 13px;
  font-family: var(--mono);
  resize: vertical;
  line-height: 1.5;
  outline: none;
  width: 100%;
}

#system-prompt:focus {
  border-color: oklch(78% 0.15 215 / 0.6);
  box-shadow: 0 0 0 3px oklch(78% 0.15 215 / 0.15);
}

.actions {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-top: 6px;
}

.actions button {
  padding: 10px 20px;
  border-radius: 3px;
  font-size: 13px;
  font-weight: 600;
  border: none;
}

.actions .danger {
  border: 1px solid oklch(62% 0.19 25 / 0.5);
  background: oklch(62% 0.19 25 / 0.08);
  color: oklch(72% 0.17 25);
  font-weight: 500;
}

.actions .danger:hover:not(:disabled) {
  background: oklch(62% 0.19 25 / 0.16);
}

.actions .danger:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

#save {
  background: linear-gradient(180deg, var(--accent), var(--accent-dim));
  color: var(--bg);
}

.toast {
  position: fixed;
  right: 18px;
  bottom: max(18px, env(safe-area-inset-bottom));
  z-index: 40;
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: oklch(16% 0.02 255);
  font-size: 13px;
  box-shadow: 0 12px 40px -12px oklch(0% 0 0 / 0.6);
  max-width: min(320px, calc(100vw - 36px));
}

@media (min-width: 900px) {
  #status { max-width: 180px; }
}

/* ============================================================================
   Pagina "Immagini" (/images) — generazione dedicata, separata dalla chat
   ========================================================================== */
#nav-images {
  margin: 0 16px 6px;
  padding: 10px 14px;
  border-radius: 3px;
  border: 1px solid var(--border);
  background: var(--input);
  color: var(--text-2);
  font-size: 13px;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}

#nav-images:hover {
  background: oklch(78% 0.15 215 / 0.1);
  border-color: oklch(78% 0.15 215 / 0.5);
  color: oklch(88% 0.1 215);
}

.ig-back {
  background: none;
  border: none;
  color: oklch(80% 0.01 255);
  padding: 4px;
  line-height: 1;
  display: grid;
  place-items: center;
  border-radius: 4px;
}

.ig-back:hover { background: oklch(15% 0.02 255 / 0.6); }

.ig-heading {
  flex: 1;
  min-width: 0;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.04em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ig-app main {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.ig-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 16px clamp(14px, 4vw, 28px) calc(40px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 22px;
  max-width: 760px;
  width: 100%;
  margin: 0 auto;
}

.ig-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.ig-panel-title {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.ig-unavailable {
  padding: 12px 14px;
  border-radius: 6px;
  border: 1px solid oklch(62% 0.19 25 / 0.4);
  background: oklch(62% 0.19 25 / 0.08);
  color: oklch(78% 0.14 25);
  font-size: 13px;
  line-height: 1.45;
}

.ig-fields {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.ig-fields textarea,
.ig-fields input[type="text"],
.ig-fields select {
  padding: 10px 12px;
  border-radius: 5px;
  border: 1px solid oklch(30% 0.03 255);
  background: var(--input);
  color: oklch(92% 0.01 255);
  font-size: 14px;
  font-family: var(--mono);
  outline: none;
  width: 100%;
}

.ig-fields textarea { resize: vertical; line-height: 1.5; }

.ig-fields textarea:focus,
.ig-fields input[type="text"]:focus,
.ig-fields select:focus {
  border-color: oklch(78% 0.15 215 / 0.6);
  box-shadow: 0 0 0 3px oklch(78% 0.15 215 / 0.15);
}

.ig-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.ig-range-val {
  font-family: var(--mono);
  color: var(--accent);
  text-transform: none;
  letter-spacing: 0;
}

.ig-fields input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

.ig-cpu-hint {
  margin: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-radius: 6px;
  background: oklch(78% 0.15 215 / 0.07);
  border: 1px solid oklch(78% 0.15 215 / 0.2);
  color: var(--text-2);
  font-size: 12.5px;
  line-height: 1.4;
}

#ig-generate {
  padding: 12px 20px;
  border-radius: 6px;
  border: none;
  font-size: 14px;
  font-weight: 600;
  background: linear-gradient(180deg, var(--accent), var(--accent-dim));
  color: var(--bg);
  box-shadow: var(--glow);
  transition: box-shadow 0.15s, opacity 0.15s;
}

#ig-generate:hover:not(:disabled) { box-shadow: var(--glow-strong); }
#ig-generate:disabled { opacity: 0.5; cursor: wait; }

.ig-result {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  align-items: flex-start;
}

.ig-timer {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  border: 1px solid oklch(28% 0.02 255);
  border-radius: 999px;
  background: oklch(18% 0.02 255 / 0.75);
  font-family: var(--mono);
  font-size: 12px;
}

.ig-timer:not(.done) .ig-timer-clock {
  color: oklch(88% 0.12 215);
  animation: img-timer-pulse 1.2s ease-in-out infinite;
}

.ig-timer.done .ig-timer-clock { color: oklch(82% 0.12 150); }
.ig-timer.done.error .ig-timer-clock { color: var(--danger); }

.ig-timer-label { color: var(--muted); font-family: var(--font); }

.ig-timer-clock {
  min-width: 3.4em;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}

.ig-preview {
  margin: 0;
  width: 100%;
}

.ig-preview img {
  display: block;
  width: 100%;
  max-width: 512px;
  border-radius: 10px;
  border: 1px solid oklch(28% 0.02 255);
  background: #0b0d12;
}

.ig-params {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 8px 18px;
  width: 100%;
}

.ig-param { display: flex; flex-direction: column; gap: 2px; }

.ig-param-k {
  font-family: var(--mono);
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.ig-param-v { font-size: 13.5px; font-weight: 500; }

.ig-result-actions { display: flex; gap: 10px; }

.ig-result-actions .ghost {
  padding: 9px 18px;
  border-radius: 6px;
  border: 1px solid oklch(28% 0.02 255);
  background: transparent;
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  text-decoration: none;
}

.ig-result-actions .ghost:hover { background: oklch(18% 0.02 255 / 0.7); }

.ig-history-wrap { display: flex; flex-direction: column; gap: 12px; }

.ig-history {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 12px;
}

.ig-card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.ig-card-thumb {
  all: unset;
  cursor: pointer;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--border);
  aspect-ratio: 1 / 1;
  background: #0b0d12;
}

.ig-card-thumb img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.ig-card-thumb:hover { border-color: oklch(78% 0.15 215 / 0.6); }

.ig-card-caption {
  font-size: 11.5px;
  color: var(--muted);
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.ig-card-del {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: none;
  background: oklch(10% 0.01 255 / 0.75);
  color: oklch(85% 0.01 255);
  font-size: 12px;
  line-height: 1;
  display: grid;
  place-items: center;
  opacity: 0;
  transition: opacity 0.15s, background 0.15s;
}

.ig-card:hover .ig-card-del { opacity: 1; }
.ig-card-del:hover { background: oklch(62% 0.19 25 / 0.8); color: #fff; }

.ig-history-empty { color: var(--muted); font-size: 13px; margin: 0; }

#ig-status.offline .status-dot { background: var(--danger); }

@media (max-width: 480px) {
  .ig-grid { grid-template-columns: 1fr; }
  .ig-card-del { opacity: 1; }
}
