:root {
  --bg: #ffffff;
  --bg-secondary: #fafbfa;
  --bg-tertiary: #f4f5f4;
  --bg-hover: #eef0ef;
  --surface: #ffffff;
  --border: #e6ebea;
  --text: #0a1e1a;
  --text-secondary: #5f7570;
  --text-muted: #94a5a0;
  --teal: #00C4A7;
  --teal-dark: #00a38b;
  --teal-darker: #007a68;
  --teal-light: #e6faf6;
  --teal-dim: rgba(0,196,167,0.1);
  --danger: #ef4444;
  --radius: 12px;
  --radius-sm: 8px;
  --radius-lg: 16px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: "SF Mono", "Fira Code", "Fira Mono", Menlo, Consolas, monospace;
  --transition: all 0.15s ease;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.06);
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html { height: 100%; -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--font);
  background: var(--bg-secondary);
  color: var(--text);
  height: 100%;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--teal-dark); text-decoration: none; }
a:hover { color: var(--teal-darker); }
input, textarea, button, select { font-family: inherit; font-size: inherit; }
button { cursor: pointer; border: none; background: none; color: inherit; }

.screen { height: 100dvh; display: flex; flex-direction: column; }

/* ─── Login ───────────────────────────────────── */
#login-screen {
  align-items: center;
  justify-content: center;
  background: var(--bg-secondary);
  padding: 24px;
}
.login-card {
  width: 380px;
  max-width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 40px 36px;
  box-shadow: var(--shadow-md);
}
.logo-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-bottom: 8px;
  color: var(--teal);
}
.logo { width: 36px; height: 36px; }
.logo-text { font-size: 1.4rem; font-weight: 700; letter-spacing: 0.06em; color: var(--teal-dark); }
.login-subtitle {
  text-align: center;
  color: var(--text-secondary);
  font-size: 0.9rem;
  margin-bottom: 24px;
}
.error-box {
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: var(--danger);
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
  margin-bottom: 16px;
}
#login-form { display: flex; flex-direction: column; gap: 12px; }
#login-form input {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 12px 14px;
  font-size: 0.95rem;
  outline: none;
  transition: var(--transition);
}
#login-form input:focus { border-color: var(--teal); box-shadow: 0 0 0 3px rgba(0,196,167,0.1); }
#login-form button {
  background: var(--teal);
  color: #fff;
  padding: 12px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 0.95rem;
  transition: var(--transition);
  margin-top: 4px;
}
#login-form button:hover { background: var(--teal-dark); }
#login-form button:disabled { opacity: 0.5; cursor: not-allowed; }
.login-footer {
  text-align: center;
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  font-size: 0.85rem;
  color: var(--text-muted);
}
.login-footer .dot { margin: 0 8px; }

/* ─── Chat Header ─────────────────────────────── */
#chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  box-shadow: var(--shadow-sm);
}
.header-left { display: flex; align-items: center; gap: 10px; }
.header-logo { width: 28px; height: 28px; color: var(--teal); }
.header-title { font-weight: 600; font-size: 1rem; letter-spacing: 0.04em; color: var(--teal-dark); }
.header-right { display: flex; gap: 4px; }
.header-btn {
  padding: 8px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  transition: var(--transition);
}
.header-btn:hover { background: var(--bg-tertiary); color: var(--text); }

/* ─── Messages ────────────────────────────────── */
#messages {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 24px 16px;
  scroll-behavior: smooth;
  background: var(--bg-secondary);
}
.welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text-muted);
  text-align: center;
  gap: 16px;
}
.welcome-logo { width: 64px; height: 64px; color: var(--teal); opacity: 0.25; }
.welcome h2 { font-size: 1.5rem; font-weight: 600; color: var(--text-secondary); }
.welcome p { font-size: 0.95rem; }

.msg-row { display: flex; gap: 12px; margin-bottom: 20px; max-width: 760px; margin-left: auto; margin-right: auto; }
.msg-row.user { justify-content: flex-end; }
.msg-avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  font-weight: 600;
}
.msg-row.assistant .msg-avatar { background: var(--teal-light); color: var(--teal-dark); }
.msg-bubble {
  padding: 14px 18px;
  border-radius: var(--radius-lg);
  line-height: 1.65;
  font-size: 0.95rem;
  max-width: 85%;
  word-wrap: break-word;
  overflow-wrap: break-word;
}
.msg-row.assistant .msg-bubble {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}
.msg-row.user .msg-bubble {
  background: #ffffff;
  color: var(--text);
  border: 2px solid var(--teal);
  box-shadow: var(--shadow-sm);
}
.msg-row.user .msg-bubble strong { color: var(--text); }
.msg-bubble img {
  max-width: 100%;
  max-height: 300px;
  border-radius: var(--radius-sm);
  margin: 8px 0;
}
.msg-bubble pre {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px;
  overflow-x: auto;
  font-family: var(--mono);
  font-size: 0.88rem;
  margin: 10px 0;
  line-height: 1.5;
}
.msg-bubble code {
  font-family: var(--mono);
  font-size: 0.88rem;
  background: var(--bg-tertiary);
  padding: 2px 6px;
  border-radius: 4px;
  color: var(--teal-darker);
}
.msg-row.user .msg-bubble code { background: var(--bg-tertiary); color: var(--teal-darker); }
.msg-row.user .msg-bubble pre { background: var(--bg-tertiary); border-color: var(--border); color: var(--text); }
.msg-bubble pre code { background: none; padding: 0; color: inherit; }
.msg-bubble p { margin-bottom: 8px; }
.msg-bubble p:last-child { margin-bottom: 0; }
.msg-bubble ul, .msg-bubble ol { margin: 8px 0; padding-left: 20px; }
.msg-bubble li { margin-bottom: 4px; }
.msg-bubble strong { color: var(--text); font-weight: 600; }
.msg-bubble h1,.msg-bubble h2,.msg-bubble h3 {
  color: var(--text);
  margin: 16px 0 8px;
  font-size: 1.05rem;
}
.typing-indicator { display: inline-flex; gap: 4px; padding: 4px 0; }
.typing-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--teal);
  opacity: 0.4;
  animation: blink 1.4s infinite both;
}
.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink {
  0%,80%,100% { opacity: 0.3; transform: scale(0.9); }
  40% { opacity: 1; transform: scale(1); }
}

/* ─── Status Bar ──────────────────────────────── */
#status-bar {
  padding: 10px 16px;
  text-align: center;
  font-size: 0.85rem;
  background: #fef2f2;
  border-top: 1px solid #fecaca;
  color: var(--danger);
  flex-shrink: 0;
}

/* ─── Input Area ──────────────────────────────── */
#input-area {
  padding: 12px 16px;
  padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  background: var(--surface);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
.input-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  max-width: 760px;
  margin: 0 auto;
}
.input-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  cursor: pointer;
  transition: var(--transition);
  flex-shrink: 0;
}
.input-btn:hover { background: var(--bg-tertiary); color: var(--text-secondary); }
.input-wrapper {
  flex: 1;
  position: relative;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: var(--transition);
}
.input-wrapper:focus-within { border-color: var(--teal); box-shadow: 0 0 0 3px rgba(0,196,167,0.08); }
#msg-input {
  width: 100%;
  background: none;
  border: none;
  color: var(--text);
  padding: 10px 14px;
  font-size: 0.95rem;
  resize: none;
  outline: none;
  max-height: 150px;
  line-height: 1.5;
}
#msg-input::placeholder { color: var(--text-muted); }
#image-preview {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border-top: 1px solid var(--border);
}
#preview-img { height: 60px; border-radius: 6px; object-fit: cover; }
#btn-remove-image { color: var(--text-muted); font-size: 1.2rem; padding: 4px 8px; }
.send-btn {
  width: 40px; height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--teal);
  color: #fff;
  transition: var(--transition);
  flex-shrink: 0;
  box-shadow: 0 2px 8px rgba(0,196,167,0.25);
}
.send-btn:hover { background: var(--teal-dark); box-shadow: 0 4px 12px rgba(0,196,167,0.35); }
.send-btn:disabled { background: var(--bg-tertiary); color: var(--text-muted); box-shadow: none; cursor: not-allowed; }
.input-footer {
  text-align: center;
  padding-top: 6px;
  font-size: 0.75rem;
  color: var(--text-muted);
  max-width: 760px;
  margin: 0 auto;
}

/* ─── Offline Overlay ─────────────────────────── */
#offline-overlay {
  position: fixed;
  inset: 0;
  background: rgba(255,255,255,0.85);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.offline-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px 32px;
  color: var(--text-secondary);
  font-size: 0.95rem;
  box-shadow: var(--shadow-md);
}

/* ─── Desktop ─────────────────────────────────── */
@media (min-width: 768px) {
  #messages { padding: 32px 24px; }
  .msg-bubble { max-width: 75%; }
  #input-area { padding: 16px 24px; }
  .login-card { padding: 48px 44px; }
}

/* ─── Voice-Modus ────────────────────────── */
#btn-voice.active {
  background: rgba(0, 196, 167, 0.15);
  color: #00C4A7;
}
#btn-voice.recording {
  background: #00C4A7;
  color: #fff;
  animation: pulse 1.2s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.55; }
}
.msg.user .voice-interim {
  opacity: 0.55;
  font-style: italic;
}

#btn-speaker.active {
  background: rgba(0, 196, 167, 0.15);
  color: #00C4A7;
}
