:root {
  --bg: #0c0f10;
  --panel: #141819;
  --panel-raised: #1b2021;
  --line: #2a3031;
  --text: #f2f4ef;
  --muted: #919b99;
  --accent: #c9f27b;
  --accent-dark: #91b64c;
  --danger: #ff8f82;
  --owner: #273321;
  --assistant: #171c1d;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background:
    radial-gradient(circle at 85% -10%, rgba(201, 242, 123, .12), transparent 35%),
    var(--bg);
  color: var(--text);
  overscroll-behavior: none;
}

button, input, textarea { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }

.app-shell {
  height: 100dvh;
  max-width: 780px;
  margin: 0 auto;
  display: grid;
  grid-template-rows: auto 1fr;
  border-inline: 1px solid rgba(255, 255, 255, .03);
  background: rgba(12, 15, 16, .86);
}

.topbar {
  min-height: 72px;
  padding: calc(10px + env(safe-area-inset-top, 0px)) 14px 10px;
  display: flex;
  align-items: center;
  gap: 11px;
  border-bottom: 1px solid var(--line);
  background: rgba(20, 24, 25, .9);
  backdrop-filter: blur(16px);
}

.brand-mark, .auth-icon {
  display: grid;
  place-items: center;
  color: #17200f;
  background: var(--accent);
  font-weight: 850;
  border-radius: 14px;
}
.brand-mark { width: 44px; height: 44px; font-size: 23px; }
.auth-icon { width: 68px; height: 68px; margin: 0 auto 18px; font-size: 34px; border-radius: 21px; }

.brand-copy { min-width: 0; flex: 1; }
.brand-copy h1 { margin: 0; font-size: 18px; letter-spacing: .01em; }
.brand-copy p { margin: 3px 0 0; color: var(--muted); font-size: 12px; }

.icon-button {
  border: 0;
  color: var(--muted);
  background: transparent;
  min-width: 40px;
  min-height: 40px;
  border-radius: 12px;
}
.icon-button:active { background: var(--panel-raised); }

.auth-panel { display: grid; place-items: center; padding: 24px; }
.auth-card {
  width: min(100%, 420px);
  padding: 30px 24px;
  border: 1px solid var(--line);
  border-radius: 24px;
  background: var(--panel);
  box-shadow: 0 24px 80px rgba(0, 0, 0, .35);
}
.auth-card h2 { text-align: center; margin: 0; }
.auth-card p { color: var(--muted); line-height: 1.5; text-align: center; }
.auth-card label { display: block; margin: 22px 0 8px; color: var(--muted); font-size: 13px; }
.auth-card input {
  width: 100%;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 13px;
  color: var(--text);
  background: #0f1213;
  outline: none;
}
.auth-card input:focus { border-color: var(--accent-dark); }

.primary-button, .secondary-button, .danger-button {
  width: 100%;
  min-height: 48px;
  margin-top: 14px;
  border-radius: 13px;
  border: 1px solid transparent;
  font-weight: 700;
}
.primary-button { background: var(--accent); color: #151b10; }
.secondary-button { color: var(--text); background: var(--panel-raised); border-color: var(--line); }
.danger-button { color: var(--danger); background: transparent; border-color: rgba(255, 143, 130, .35); }
.error-text { min-height: 20px; color: var(--danger) !important; font-size: 13px; }

.chat-panel { min-height: 0; display: grid; grid-template-rows: 1fr auto auto auto; }
.messages {
  overflow-y: auto;
  padding: 24px 16px 18px;
  scroll-behavior: smooth;
}
.empty-state { max-width: 440px; margin: 12vh auto 0; text-align: center; color: var(--muted); line-height: 1.55; }
.empty-state strong { display: block; color: var(--text); font-size: 22px; margin-bottom: 8px; }

.message { display: flex; margin: 10px 0; }
.message.owner { justify-content: flex-end; }
.bubble {
  max-width: min(88%, 620px);
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 17px 17px 17px 5px;
  background: var(--assistant);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  line-height: 1.48;
  font-size: 15px;
}
.owner .bubble {
  background: var(--owner);
  border-color: #3b5030;
  border-radius: 17px 17px 5px 17px;
}

.thinking { display: flex; align-items: center; gap: 5px; padding: 7px 19px 12px; color: var(--muted); }
.thinking span { width: 6px; height: 6px; border-radius: 50%; background: var(--accent); animation: pulse 1.15s infinite ease-in-out; }
.thinking span:nth-child(2) { animation-delay: .15s; }
.thinking span:nth-child(3) { animation-delay: .3s; }
.thinking em { margin-left: 5px; font-size: 12px; font-style: normal; }
@keyframes pulse { 0%, 60%, 100% { opacity: .25; transform: translateY(0); } 30% { opacity: 1; transform: translateY(-3px); } }

.voice-panel {
  display: flex;
  align-items: center;
  gap: 11px;
  margin: 0 12px 8px;
  padding: 11px 12px;
  border: 1px solid rgba(201, 242, 123, .28);
  border-radius: 16px;
  background: linear-gradient(100deg, rgba(201, 242, 123, .12), rgba(27, 32, 33, .96));
}
.voice-level { display: flex; align-items: center; justify-content: center; gap: 3px; width: 35px; height: 35px; }
.voice-level span { width: 3px; height: 9px; border-radius: 4px; background: var(--accent); animation: voice-wave .8s ease-in-out infinite alternate; }
.voice-level span:nth-child(2) { height: 19px; animation-delay: -.45s; }
.voice-level span:nth-child(3) { height: 14px; animation-delay: -.2s; }
.voice-level span:nth-child(4) { height: 7px; animation-delay: -.6s; }
@keyframes voice-wave { from { transform: scaleY(.45); opacity: .55; } to { transform: scaleY(1.15); opacity: 1; } }
.voice-panel.speaking .voice-level span { background: #8ecbff; }
.voice-panel.error { border-color: rgba(255, 143, 130, .45); background: rgba(255, 143, 130, .08); }
.voice-panel.error .voice-level span { animation: none; background: var(--danger); }
.voice-copy { min-width: 0; flex: 1; display: flex; flex-direction: column; gap: 3px; }
.voice-copy strong { font-size: 14px; }
.voice-copy span { color: var(--muted); font-size: 11px; line-height: 1.3; }
.voice-panel > button {
  flex: none;
  min-height: 34px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--text);
  background: var(--panel-raised);
  font-size: 11px;
  font-weight: 700;
}

.composer {
  display: grid;
  grid-template-columns: 46px 1fr 46px;
  align-items: end;
  gap: 9px;
  padding: 10px 12px calc(10px + var(--safe-bottom));
  border-top: 1px solid var(--line);
  background: rgba(20, 24, 25, .94);
}
.composer textarea {
  resize: none;
  max-height: 160px;
  min-height: 46px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 16px;
  outline: none;
  color: var(--text);
  background: #0f1213;
  line-height: 1.35;
}
.composer textarea:focus { border-color: #4b5f38; }
.composer > button {
  width: 46px;
  height: 46px;
  border: 0;
  border-radius: 15px;
  background: var(--accent);
  color: #15200e;
  font-size: 27px;
  font-weight: 750;
}
.composer > button:disabled { opacity: .35; }
.composer .voice-button {
  border: 1px solid var(--line);
  color: var(--text);
  background: var(--panel-raised);
  font-size: 20px;
}
.composer .voice-button.active {
  border-color: var(--accent-dark);
  color: #15200e;
  background: var(--accent);
  box-shadow: 0 0 0 5px rgba(201, 242, 123, .1);
}
.composer .voice-button.active span { display: inline-block; animation: mic-pulse 1.2s ease-in-out infinite; }
@keyframes mic-pulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.17); } }

dialog {
  width: min(calc(100% - 32px), 430px);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 20px;
  color: var(--text);
  background: var(--panel);
}
dialog::backdrop { background: rgba(0, 0, 0, .65); backdrop-filter: blur(4px); }
.dialog-head { display: flex; align-items: center; }
.dialog-head h2 { flex: 1; margin: 0; }
dialog p { color: var(--muted); line-height: 1.45; }
.settings-note { padding: 11px 12px; border-radius: 12px; background: rgba(201, 242, 123, .07); font-size: 13px; }
.settings-note strong { color: var(--text); }
.settings-label { display: block; margin: 18px 0 7px; color: var(--muted); font-size: 12px; font-weight: 700; }
.project-select {
  width: 100%; min-height: 46px; padding: 0 12px; border: 1px solid var(--line); border-radius: 12px;
  color: var(--text); background: var(--panel-raised); outline: none;
}
.project-select:focus { border-color: var(--accent-dark); }
.approval-card {
  max-width: min(94%, 650px); margin: 10px 0; padding: 13px; border: 1px solid rgba(255, 200, 105, .42);
  border-radius: 14px; background: rgba(255, 200, 105, .08);
}
.approval-card strong { display: block; margin-bottom: 6px; }
.approval-card code { display: block; max-height: 140px; overflow: auto; color: #f4d49a; white-space: pre-wrap; overflow-wrap: anywhere; }
.approval-actions { display: flex; gap: 8px; margin-top: 10px; }
.approval-actions button { min-height: 38px; padding: 0 13px; border-radius: 10px; border: 1px solid var(--line); font-weight: 700; }
.approval-accept { color: #15200e; background: var(--accent); }
.approval-decline { color: var(--danger); background: var(--panel-raised); }

.hidden { display: none !important; }

@media (min-width: 700px) {
  .messages { padding-inline: 34px; }
  .composer { padding-inline: 30px; }
}
