:root {
  --bg: #0b0f14;
  --surface: #141a22;
  --surface-2: #1c2430;
  --line: #263142;
  --text: #e7edf5;
  --muted: #8b98aa;
  --accent: #4cc2ff;
  --accent-ink: #04121c;
  --danger: #ff5d5d;
  --radius: 18px;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
}

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

/* Yuqori panel */
.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + 8px) 12px 8px;
  border-bottom: 1px solid var(--line);
  background: var(--bg);
}

.top h1 {
  margin: 0;
  font-size: 17px;
  font-weight: 600;
  letter-spacing: 0.04em;
}

.icon-btn {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--text);
  cursor: pointer;
}

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

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

.voice-pill {
  min-width: 84px;
  height: 32px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
  color: var(--accent);
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

.voice-pill:active { background: var(--surface-2); }

#pushToggle { color: var(--muted); }
#pushToggle[aria-pressed="true"] { color: var(--accent); }

#speakToggle .off { display: none; }
#speakToggle[aria-pressed="false"] .on { display: none; }
#speakToggle[aria-pressed="false"] .off { display: block; color: var(--muted); }

/* Xabarlar */
#messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 16px 8px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  -webkit-overflow-scrolling: touch;
}

.msg {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: var(--radius);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.msg.user {
  align-self: flex-end;
  background: var(--accent);
  color: var(--accent-ink);
  border-bottom-right-radius: 6px;
}

.msg.assistant {
  align-self: flex-start;
  background: var(--surface);
  border: 1px solid var(--line);
  border-bottom-left-radius: 6px;
}

.msg.error {
  align-self: center;
  background: transparent;
  color: var(--danger);
  font-size: 14px;
  text-align: center;
}

.msg.pending { color: var(--muted); }
.msg.pending::after {
  content: "…";
  animation: blink 1s steps(2) infinite;
}

.empty {
  margin: auto;
  color: var(--muted);
  text-align: center;
  font-size: 15px;
}

/* Pastki panel */
.composer {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 8px 12px calc(env(safe-area-inset-bottom) + 10px);
  border-top: 1px solid var(--line);
  background: var(--bg);
}

#form {
  flex: 1;
  display: flex;
  align-items: flex-end;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 24px;
  padding: 4px 4px 4px 14px;
}

#input {
  flex: 1;
  max-height: 140px;
  padding: 9px 0;
  border: 0;
  outline: 0;
  resize: none;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 16px; /* 16px dan kichik bo'lsa iOS sahifani kattalashtiradi */
}

.send { color: var(--accent); }
.send:disabled { color: var(--muted); }

.mic {
  display: grid;
  place-items: center;
  flex: none;
  width: 52px;
  height: 52px;
  border: 0;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-ink);
  cursor: pointer;
  touch-action: manipulation;
}

.mic svg { width: 24px; height: 24px; }
.mic.recording { background: var(--danger); color: #fff; animation: pulse 1.2s ease-in-out infinite; }
.mic:disabled { opacity: 0.5; }

/* Ulanish oynasi */
dialog {
  width: min(92vw, 380px);
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
}

dialog::backdrop { background: rgb(0 0 0 / 0.7); }
dialog h2 { margin: 0 0 6px; font-size: 19px; }
dialog p { margin: 0 0 14px; color: var(--muted); font-size: 14px; }
dialog code { color: var(--text); }

dialog input {
  width: 100%;
  margin-bottom: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 16px;
}

.primary {
  width: 100%;
  padding: 12px;
  border: 0;
  border-radius: 12px;
  background: var(--accent);
  color: var(--accent-ink);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

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

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgb(255 93 93 / 0.5); }
  50% { box-shadow: 0 0 0 10px rgb(255 93 93 / 0); }
}

@keyframes blink { 50% { opacity: 0; } }

@media (prefers-reduced-motion: reduce) {
  .mic.recording, .msg.pending::after { animation: none; }
}
