:root {
  --bg: #08090d;
  --panel: #12141a;
  --panel-2: #191c24;
  --line: rgba(255, 255, 255, 0.075);
  --text: #edeff5;
  --muted: #8a90a0;
  --gold: #e9c57e;
  --gold-2: #d3a558;
  --gold-soft: rgba(233, 197, 126, 0.14);
  --danger: #e0605e;
  --ok: #6fd39a;
  --radius: 20px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", -apple-system, BlinkMacSystemFont, "Inter", Roboto,
    "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(70% 45% at 50% -8%, rgba(233, 197, 126, 0.13), transparent 70%),
    radial-gradient(50% 35% at 90% 110%, rgba(88, 112, 190, 0.09), transparent 70%);
  z-index: 0;
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.app {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-height: 100dvh;
}

/* ── Barra superiore ─────────────────────────────────────── */

.topbar {
  position: relative;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(10px + var(--safe-t)) 16px 10px;
  background: rgba(8, 9, 13, 0.72);
  backdrop-filter: blur(18px) saturate(140%);
  -webkit-backdrop-filter: blur(18px) saturate(140%);
  border-bottom: 1px solid var(--line);
  flex: none;
}

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

.logo {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 13px;
  color: var(--gold);
  background: linear-gradient(160deg, rgba(233, 197, 126, 0.18), rgba(233, 197, 126, 0.04));
  border: 1px solid rgba(233, 197, 126, 0.24);
  box-shadow: 0 6px 18px -10px rgba(233, 197, 126, 0.7);
  flex: none;
}

.logo svg {
  width: 26px;
  height: 26px;
}

.brand-text {
  min-width: 0;
}

.brand h1 {
  margin: 0;
  font-size: 17px;
  font-weight: 650;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.brand p {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 1px 0 0;
  font-size: 11.5px;
  color: var(--muted);
  letter-spacing: 0.02em;
}

.dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--muted);
  box-shadow: 0 0 0 3px rgba(138, 144, 160, 0.12);
  transition: background 0.25s ease, box-shadow 0.25s ease;
}

.dot.online {
  background: var(--ok);
  box-shadow: 0 0 0 3px rgba(111, 211, 154, 0.16);
}

.dot.offline {
  background: var(--danger);
  box-shadow: 0 0 0 3px rgba(224, 96, 94, 0.16);
}

.actions {
  display: flex;
  align-items: center;
  gap: 4px;
  flex: none;
}

.icon-btn {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 12px;
  color: var(--muted);
  transition: color 0.2s ease, background 0.2s ease;
}

.icon-btn svg {
  width: 20px;
  height: 20px;
}

.icon-btn:hover,
.icon-btn:focus-visible {
  color: var(--text);
  background: rgba(255, 255, 255, 0.05);
}

.icon-btn.active {
  color: var(--gold);
  background: var(--gold-soft);
}

.icon-btn.muted {
  opacity: 0.55;
}

.icon-btn.muted #soundWave {
  display: none;
}

/* ── Menu a tendina ──────────────────────────────────────── */

.menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 12px;
  z-index: 60;
  min-width: 196px;
  padding: 6px;
  border-radius: 16px;
  background: #14161d;
  border: 1px solid var(--line);
  box-shadow: 0 24px 50px -20px rgba(0, 0, 0, 0.9);
  animation: pop 0.16s ease;
}

.menu button,
.menu a {
  display: block;
  width: 100%;
  padding: 11px 12px;
  border-radius: 11px;
  text-align: left;
  font-size: 14.5px;
  color: var(--text);
}

.menu a {
  text-decoration: none;
}

.menu button:hover,
.menu a:hover {
  background: rgba(255, 255, 255, 0.055);
}

.menu button.danger {
  color: #ff9b96;
}

.menu button[hidden] {
  display: none;
}

@keyframes pop {
  from {
    opacity: 0;
    transform: translateY(-4px) scale(0.98);
  }
}

/* ── Banner Hey Valet ────────────────────────────────────── */

.wake-banner {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 10px 12px 0;
  padding: 11px 12px;
  border-radius: 16px;
  background: linear-gradient(135deg, rgba(233, 197, 126, 0.16), rgba(233, 197, 126, 0.05));
  border: 1px solid rgba(233, 197, 126, 0.28);
  animation: pop 0.2s ease;
  flex: none;
}

.wake-copy {
  display: flex;
  flex-direction: column;
  min-width: 0;
  flex: 1;
}

.wake-copy strong {
  font-size: 13.5px;
  font-weight: 600;
  color: #f6e3bd;
}

.wake-copy span {
  font-size: 11.5px;
  color: rgba(246, 227, 189, 0.62);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.wake-stop {
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 12.5px;
  font-weight: 600;
  color: #f6e3bd;
  border: 1px solid rgba(246, 227, 189, 0.35);
  flex: none;
}

.wave {
  display: flex;
  align-items: center;
  gap: 2.5px;
  height: 20px;
  flex: none;
}

.wave i {
  display: block;
  width: 3px;
  border-radius: 3px;
  background: var(--gold);
  animation: bar 1s ease-in-out infinite;
}

.wave i:nth-child(1) {
  height: 7px;
  animation-delay: -0.2s;
}
.wave i:nth-child(2) {
  height: 16px;
  animation-delay: -0.05s;
}
.wave i:nth-child(3) {
  height: 11px;
  animation-delay: -0.35s;
}
.wave i:nth-child(4) {
  height: 5px;
  animation-delay: -0.1s;
}

@keyframes bar {
  0%,
  100% {
    transform: scaleY(0.45);
    opacity: 0.65;
  }
  50% {
    transform: scaleY(1);
    opacity: 1;
  }
}

/* ── Chat ────────────────────────────────────────────────── */

.chat {
  flex: 1 1 auto;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 18px 14px 8px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.14) transparent;
}

.chat > * {
  width: 100%;
  max-width: 780px;
  margin-inline: auto;
}

.chat::-webkit-scrollbar {
  width: 6px;
}

.chat::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.12);
  border-radius: 6px;
}

.empty {
  margin: auto;
  padding: 24px 8px 30px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.empty-logo {
  width: 74px;
  height: 74px;
  display: grid;
  place-items: center;
  color: var(--gold);
  border-radius: 26px;
  margin-bottom: 8px;
  background: radial-gradient(circle at 50% 20%, rgba(233, 197, 126, 0.2), rgba(233, 197, 126, 0.03));
  border: 1px solid rgba(233, 197, 126, 0.2);
  box-shadow: 0 24px 50px -28px rgba(233, 197, 126, 0.8);
}

.empty-logo svg {
  width: 44px;
  height: 44px;
}

.empty h2 {
  margin: 0;
  font-size: 23px;
  font-weight: 500;
  letter-spacing: -0.01em;
}

.empty p {
  margin: 0;
  max-width: 330px;
  font-size: 13.5px;
  color: var(--muted);
}

.chips {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin-top: 18px;
}

.chips button {
  padding: 9px 14px;
  border-radius: 999px;
  font-size: 13px;
  color: #d6d9e2;
  background: rgba(255, 255, 255, 0.035);
  border: 1px solid var(--line);
  transition: border-color 0.2s ease, color 0.2s ease, background 0.2s ease;
}

.chips button:hover {
  color: var(--gold);
  border-color: rgba(233, 197, 126, 0.4);
  background: var(--gold-soft);
}

.msg {
  display: flex;
  gap: 9px;
  align-items: flex-end;
  animation: rise 0.24s ease both;
}

.msg.user {
  justify-content: flex-end;
}

.avatar {
  width: 26px;
  height: 26px;
  border-radius: 9px;
  flex: none;
  display: grid;
  place-items: center;
  font-size: 11px;
  font-weight: 700;
  color: var(--gold);
  background: rgba(233, 197, 126, 0.12);
  border: 1px solid rgba(233, 197, 126, 0.2);
  margin-bottom: 2px;
}

.bubble {
  max-width: min(86%, 620px);
  padding: 11px 14px;
  border-radius: 18px 18px 18px 7px;
  background: var(--panel);
  border: 1px solid var(--line);
  font-size: 15px;
  line-height: 1.55;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.bubble strong {
  color: #fff;
  font-weight: 650;
}

.bubble em {
  color: #aab0c0;
}

.bubble code {
  padding: 1px 5px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.08);
  font-size: 0.92em;
}

.msg.user .bubble {
  border-radius: 18px 18px 7px 18px;
  background: linear-gradient(150deg, #f1d79f, #d9ad61);
  border-color: rgba(255, 255, 255, 0.16);
  color: #1a160d;
  font-weight: 500;
}

.msg.user .bubble strong,
.msg.user .bubble em {
  color: #1a160d;
}

.msg.user .bubble code {
  background: rgba(0, 0, 0, 0.12);
}

.msg.error .bubble {
  border-color: rgba(224, 96, 94, 0.4);
  color: #ffb3af;
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(7px);
  }
}

.typing {
  display: flex;
  gap: 9px;
  align-items: flex-end;
}

.typing .bubble {
  display: flex;
  gap: 4px;
  padding: 14px 16px;
}

.typing i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--muted);
  animation: blink 1.3s infinite ease-in-out;
}

.typing i:nth-child(2) {
  animation-delay: 0.16s;
}
.typing i:nth-child(3) {
  animation-delay: 0.32s;
}

@keyframes blink {
  0%,
  80%,
  100% {
    opacity: 0.25;
    transform: translateY(0);
  }
  40% {
    opacity: 1;
    transform: translateY(-3px);
  }
}

/* ── Registrazione ───────────────────────────────────────── */

.rec-bar {
  display: flex;
  align-items: center;
  gap: 9px;
  max-width: 780px;
  width: calc(100% - 28px);
  margin: 0 auto 4px;
  padding: 9px 14px;
  border-radius: 999px;
  font-size: 12.5px;
  color: #ffc9c6;
  background: rgba(224, 96, 94, 0.1);
  border: 1px solid rgba(224, 96, 94, 0.28);
  animation: pop 0.18s ease;
  flex: none;
}

.rec-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--danger);
  animation: pulse 1.2s infinite;
  flex: none;
}

.rec-hint {
  color: rgba(255, 201, 198, 0.6);
  margin-left: auto;
}

#recTime {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}

@keyframes pulse {
  0%,
  100% {
    opacity: 1;
    box-shadow: 0 0 0 0 rgba(224, 96, 94, 0.5);
  }
  50% {
    opacity: 0.7;
    box-shadow: 0 0 0 6px rgba(224, 96, 94, 0);
  }
}

/* ── Composer ────────────────────────────────────────────── */

.composer {
  flex: none;
  padding: 6px 12px calc(10px + var(--safe-b));
  background: linear-gradient(to top, rgba(8, 9, 13, 0.96) 55%, rgba(8, 9, 13, 0));
}

.input-row {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  max-width: 780px;
  margin: 0 auto;
  padding: 5px;
  border-radius: 26px;
  background: rgba(20, 22, 29, 0.92);
  border: 1px solid var(--line);
  box-shadow: 0 18px 40px -26px rgba(0, 0, 0, 0.95);
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.input-row:focus-within {
  border-color: rgba(233, 197, 126, 0.35);
  box-shadow: 0 0 0 3px rgba(233, 197, 126, 0.08), 0 18px 40px -26px rgba(0, 0, 0, 0.95);
}

#input {
  flex: 1;
  min-width: 0;
  max-height: 132px;
  padding: 11px 4px;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 16px;
  line-height: 1.4;
  resize: none;
}

#input::placeholder {
  color: #6e7484;
}

.mic,
.send {
  position: relative;
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  flex: none;
  transition: transform 0.15s ease, background 0.2s ease, color 0.2s ease;
}

.mic {
  color: #b9bfcd;
  background: rgba(255, 255, 255, 0.05);
}

.mic svg,
.send svg {
  width: 21px;
  height: 21px;
}

.mic:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.09);
}

.mic:active,
.send:active {
  transform: scale(0.94);
}

.mic.recording {
  color: #fff;
  background: var(--danger);
}

.mic-halo {
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  border: 1.5px solid transparent;
  pointer-events: none;
}

.mic.recording .mic-halo {
  border-color: rgba(224, 96, 94, 0.55);
  animation: halo 1.6s ease-out infinite;
}

@keyframes halo {
  0% {
    transform: scale(0.85);
    opacity: 0.9;
  }
  100% {
    transform: scale(1.3);
    opacity: 0;
  }
}

.send {
  color: #1a160d;
  background: linear-gradient(150deg, #f1d79f, #d9ad61);
}

.send:disabled {
  color: #6a6f7c;
  background: rgba(255, 255, 255, 0.06);
  cursor: default;
}

/* ── Toast / errore ──────────────────────────────────────── */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(96px + var(--safe-b));
  transform: translateX(-50%);
  z-index: 60;
  max-width: min(90vw, 420px);
  padding: 11px 16px;
  border-radius: 14px;
  font-size: 13.5px;
  text-align: center;
  color: #f4e6c8;
  background: rgba(32, 27, 18, 0.96);
  border: 1px solid rgba(233, 197, 126, 0.3);
  box-shadow: 0 20px 44px -18px rgba(0, 0, 0, 0.9);
  animation: rise 0.2s ease;
}

.fatal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 24px;
  background: var(--bg);
}

.fatal-card {
  max-width: 380px;
  padding: 26px;
  border-radius: 22px;
  background: var(--panel);
  border: 1px solid var(--line);
}

.fatal-card h2 {
  margin: 0 0 8px;
  font-size: 19px;
}

.fatal-card p {
  margin: 0;
  font-size: 14px;
  color: var(--muted);
}

.fatal-hint {
  margin-top: 12px !important;
  color: var(--gold) !important;
}

.fatal-form {
  display: flex;
  gap: 8px;
  margin-top: 16px;
}

.fatal-form input {
  flex: 1;
  min-width: 0;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}

.fatal-form input:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 1px;
}

.fatal-form button {
  padding: 10px 16px;
  border-radius: 12px;
  border: 1px solid rgba(233, 197, 126, 0.35);
  background: rgba(233, 197, 126, 0.12);
  color: var(--gold);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

.fatal-error {
  margin-top: 12px !important;
  color: #f08a8a !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;
}

.fatal-card code {
  color: var(--gold);
  font-size: 12.5px;
  overflow-wrap: anywhere;
}

@media (min-width: 720px) {
  .chat {
    padding-top: 26px;
  }
  .bubble {
    font-size: 15.5px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}
