:root {
  --bg: #f5f7fa;
  --card: #fff;
  --primary: #1a5fb4;
  --primary-dark: #0d4a8f;
  --text: #1e1e1e;
  --muted: #5e6c84;
  --border: #dfe3eb;
  --bot-bg: #eef3fb;
  --user-bg: #d4edda;
  --error: #c0392b;
  --warning: #f39c12;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100dvh;
  overflow: hidden;
}

.screen {
  height: 100dvh;
  display: flex;
  flex-direction: column;
}

.hidden { display: none !important; }

.auth-card {
  max-width: 400px;
  margin: auto;
  padding: 24px;
  background: var(--card);
  border-radius: 12px;
  box-shadow: 0 4px 24px rgba(0,0,0,.08);
}

.auth-card h1 { margin: 0 0 4px; font-size: 1.4rem; }
.subtitle { color: var(--muted); margin: 0 0 20px; font-size: 0.9rem; }

label {
  display: block;
  margin-bottom: 12px;
  font-size: 0.85rem;
  color: var(--muted);
}

input[type="text"],
input[type="password"],
input[type="number"] {
  display: block;
  width: 100%;
  margin-top: 4px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 1rem;
}

.btn {
  border: none;
  border-radius: 8px;
  padding: 10px 16px;
  font-size: 1rem;
  cursor: pointer;
  background: #e8ecf1;
  color: var(--text);
}

.btn.primary {
  background: var(--primary);
  color: #fff;
}

.auth-card .btn.primary {
  width: 100%;
}

.composer .btn.primary {
  width: auto;
  flex-shrink: 0;
  min-width: 44px;
  padding: 10px 14px;
}

.btn.primary:active { background: var(--primary-dark); }
.btn.small { padding: 6px 12px; font-size: 0.85rem; }
.btn.icon { padding: 8px 12px; font-size: 1.1rem; }

.error { color: var(--error); font-size: 0.9rem; margin-top: 12px; }

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 16px;
  background: var(--primary);
  color: #fff;
}

.warning-banner {
  background: #fff3cd;
  color: #856404;
  padding: 10px 16px;
  font-size: 0.9rem;
  border-bottom: 1px solid #ffeeba;
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.msg {
  max-width: 92%;
  padding: 10px 14px;
  border-radius: 12px;
  line-height: 1.45;
  word-break: break-word;
}

.msg.bot { align-self: flex-start; background: var(--bot-bg); }
.msg.user { align-self: flex-end; background: var(--user-bg); }
.msg.system { align-self: center; background: #eee; font-size: 0.85rem; color: var(--muted); }

.msg b, .msg strong { font-weight: 600; }

.msg a {
  color: var(--primary);
  text-decoration: underline;
  word-break: break-all;
}

.msg a[href^="tel:"] {
  text-decoration: none;
  font-weight: 500;
}

.inline-buttons {
  padding: 0 12px 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.inline-buttons .row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.inline-buttons button {
  flex: 1;
  min-width: 80px;
  padding: 10px;
  border: 1px solid var(--primary);
  background: #fff;
  color: var(--primary);
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.9rem;
}

.inline-buttons button:active {
  background: var(--primary);
  color: #fff;
}

.composer {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  background: var(--card);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.composer-form {
  display: flex;
  flex: 1;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.composer-tools { display: flex; gap: 4px; flex-shrink: 0; }

.reply-keyboard {
  padding: 8px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  background: var(--card);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.reply-keyboard.main-menu {
  background: #f0f4f8;
}

.reply-keyboard .row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.reply-keyboard button {
  flex: 1;
  min-width: calc(50% - 6px);
  padding: 12px 8px;
  border: 1px solid var(--primary);
  background: #fff;
  color: var(--primary);
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.9rem;
  touch-action: manipulation;
}

.reply-keyboard button:active {
  background: var(--primary);
  color: #fff;
}

.main-menu button {
  font-weight: 500;
}

#message-input {
  flex: 1;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 20px;
  font-size: 1rem;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.modal-content {
  background: var(--card);
  padding: 20px;
  border-radius: 12px;
  max-width: 96vw;
  width: 400px;
}

#qr-video {
  width: 100%;
  border-radius: 8px;
  background: #000;
}

#qr-status { font-size: 0.9rem; color: var(--muted); }

@media (max-width: 480px) {
  .auth-card { margin: 16px; }
}
