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

:root {
  --bg: #0a0a0a;
  --card: #1a1a1a;
  --accent: #4CAF50;
  --accent-dim: #2e7d32;
  --text: #e0e0e0;
  --text-muted: #888;
  --danger: #e53935;
  --radius: 12px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  -webkit-text-size-adjust: 100%;
}

.screen { display: none; height: 100%; flex-direction: column; }
.screen.active { display: flex; }

/* ---- Login ---- */
.login-container {
  margin: auto;
  padding: 2rem;
  text-align: center;
  width: 100%;
  max-width: 360px;
}
.login-icon { font-size: 3rem; margin-bottom: 0.5rem; }
.login-container h1 { font-size: 1.6rem; font-weight: 600; margin-bottom: 0.25rem; }
.subtitle { color: var(--text-muted); margin-bottom: 2rem; font-size: 0.9rem; }
#login-form input {
  width: 100%;
  padding: 14px 16px;
  border: 1px solid #333;
  border-radius: var(--radius);
  background: var(--card);
  color: var(--text);
  font-size: 1rem;
  margin-bottom: 1rem;
  outline: none;
}
#login-form input:focus { border-color: var(--accent); }
#login-form button {
  width: 100%;
  padding: 14px;
  border: none;
  border-radius: var(--radius);
  background: var(--accent);
  color: #fff;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
}
#login-form button:active { background: var(--accent-dim); }
.error { color: var(--danger); margin-top: 0.75rem; font-size: 0.85rem; min-height: 1.2em; }

/* ---- Chat ---- */
.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  padding-top: calc(12px + env(safe-area-inset-top, 0px));
  background: var(--card);
  border-bottom: 1px solid #222;
}
.chat-header h2 { font-size: 1.1rem; font-weight: 600; }

.icon-btn {
  background: none;
  border: none;
  color: var(--text);
  font-size: 1.3rem;
  cursor: pointer;
  padding: 4px 8px;
}

.messages-container {
  flex: 1;
  overflow-y: auto;
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  -webkit-overflow-scrolling: touch;
}

.message {
  max-width: 80%;
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 0.95rem;
  line-height: 1.4;
  word-wrap: break-word;
}
.message .timestamp {
  display: block;
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-top: 4px;
}
.message.user {
  align-self: flex-end;
  background: var(--accent-dim);
  border-bottom-right-radius: 4px;
}
.message.system {
  align-self: flex-start;
  background: var(--card);
  border-bottom-left-radius: 4px;
}

.input-bar {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 12px;
  padding-bottom: calc(10px + var(--safe-bottom));
  background: var(--card);
  border-top: 1px solid #222;
  flex-wrap: wrap;
}
.input-bar textarea {
  flex: 1;
  padding: 12px 14px;
  border: 1px solid #333;
  border-radius: 24px;
  background: var(--bg);
  color: var(--text);
  font-size: 1rem;
  outline: none;
  resize: none;
  line-height: 1.4;
  max-height: calc(1.4em * 5 + 24px);
  overflow-y: auto;
  font-family: inherit;
}
.input-bar textarea:focus { border-color: var(--accent); }
.send-hint {
  width: 100%;
  text-align: center;
  font-size: 0.7rem;
  color: var(--text-muted);
  opacity: 0.5;
}
@media (max-width: 600px) {
  .send-hint { display: none; }
}

.mic-btn { opacity: 0.4; }
.send-btn { color: var(--accent); font-size: 1.5rem; }

/* ---- Settings ---- */
.settings-content { padding: 20px 16px; overflow-y: auto; flex: 1; }
.setting-item { margin-bottom: 24px; }
.setting-item label { display: block; font-weight: 600; margin-bottom: 8px; }
.setting-item input[type="number"] {
  width: 100px;
  padding: 10px;
  border: 1px solid #333;
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  font-size: 1rem;
}
.setting-desc { color: var(--text-muted); font-size: 0.85rem; line-height: 1.5; }
.danger-btn {
  padding: 12px 24px;
  border: 1px solid var(--danger);
  border-radius: var(--radius);
  background: transparent;
  color: var(--danger);
  font-size: 1rem;
  cursor: pointer;
}
.danger-btn:active { background: var(--danger); color: #fff; }

/* ---- Connection Status Dot (#20) ---- */
.header-left { display: flex; align-items: center; gap: 8px; }
.connection-dot {
  width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0;
  transition: background 0.3s;
}
.connection-dot.connected { background: #4CAF50; }
.connection-dot.reconnecting { background: #FFC107; }
.connection-dot.disconnected { background: #e53935; }

/* ---- Empty State (#21) ---- */
.empty-state {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  flex: 1; color: var(--text-muted); text-align: center; padding: 2rem;
}
.empty-icon { font-size: 3rem; margin-bottom: 1rem; }
.empty-sub { font-size: 0.85rem; margin-top: 0.5rem; }

/* ---- Error Toast (#19) ---- */
.error-toast {
  position: fixed; bottom: 80px; left: 50%; transform: translateX(-50%);
  background: var(--danger); color: #fff; padding: 10px 20px;
  border-radius: 8px; font-size: 0.85rem; opacity: 0;
  transition: opacity 0.3s; pointer-events: none; z-index: 1000;
}
.error-toast.visible { opacity: 1; }

/* ---- Loading States (#22) ---- */
.loading { opacity: 0.6; cursor: wait !important; }
#login-form button:disabled { background: var(--accent-dim); }
.send-btn:disabled { opacity: 0.4; }
