:root {
  --bg: #0a0a0a;
  --bg-2: #14141a;
  --bg-3: #1f1f28;
  --bg-4: #2a2a35;
  --text: #e8e8ed;
  --text-muted: #888;
  --text-dim: #5a5a65;
  --gold: #d4a574;
  --gold-dark: #b3895d;
  --green: #4ade80;
  --green-dark: #16a34a;
  --red: #ef4444;
  --blue: #60a5fa;
  --border: #26262f;
  --shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
}

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

html, body {
  height: 100%;
  font-family: 'Inter', system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

body {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

button { font-family: inherit; }
input, textarea { font-family: inherit; }

/* ===== Buttons ===== */
.btn {
  border: none;
  background: var(--bg-3);
  color: var(--text);
  padding: 10px 16px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  transition: background 0.15s, transform 0.05s, opacity 0.15s;
  white-space: nowrap;
}
.btn:hover { background: var(--bg-4); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary {
  background: var(--gold);
  color: #1a1a1a;
}
.btn-primary:hover { background: var(--gold-dark); }
.btn-secondary {
  background: transparent;
  border: 1px solid var(--border);
}
.btn-secondary:hover { background: var(--bg-3); }
.btn-ghost { background: transparent; color: var(--text-muted); }
.btn-ghost:hover { background: var(--bg-3); color: var(--text); }
.btn-sm { padding: 6px 12px; font-size: 13px; }

/* ===== Topbar ===== */
.topbar {
  height: 56px;
  background: var(--bg-2);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  flex-shrink: 0;
}
.topbar-brand {
  display: flex;
  align-items: baseline;
  gap: 8px;
}
.brand {
  font-weight: 600;
  color: var(--gold);
  font-size: 16px;
  letter-spacing: 0.3px;
}
.brand-divider { color: var(--text-dim); }
.brand-sub {
  color: var(--text-muted);
  font-size: 14px;
}
.topbar-user {
  display: flex;
  align-items: center;
  gap: 12px;
}
.user-name {
  color: var(--text-muted);
  font-size: 13px;
}

/* ===== Layout ===== */
.layout {
  flex: 1;
  display: flex;
  min-height: 0;
}

/* ===== Sidebar ===== */
.sidebar {
  width: 320px;
  background: var(--bg-2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}
.sidebar-header {
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.sidebar-header h2 {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
}
.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--green);
  opacity: 0.6;
}
.status-dot.loading { background: var(--gold); }

.inbox-list {
  flex: 1;
  overflow-y: auto;
}
.inbox-item {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.1s;
  display: flex;
  flex-direction: column;
  gap: 6px;
  position: relative;
}
.inbox-item:hover { background: var(--bg-3); }
.inbox-item.active {
  background: var(--bg-3);
  border-left: 3px solid var(--gold);
  padding-left: 15px;
}
.inbox-item.locked {
  opacity: 0.55;
  cursor: pointer;
}
.inbox-item.flash {
  animation: flashHighlight 1.4s ease-out;
}
@keyframes flashHighlight {
  0% { background: rgba(212, 165, 116, 0.25); }
  100% { background: transparent; }
}
.inbox-item-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}
.inbox-item-phone {
  font-weight: 600;
  font-size: 14px;
  color: var(--text);
}
.inbox-item-time {
  font-size: 11px;
  color: var(--text-dim);
  flex-shrink: 0;
}
.inbox-item-preview {
  font-size: 12.5px;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  line-height: 1.4;
}
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 10.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  width: fit-content;
}
.badge-free {
  background: rgba(239, 68, 68, 0.15);
  color: var(--red);
  border: 1px solid rgba(239, 68, 68, 0.3);
}
.badge-mine {
  background: rgba(74, 222, 128, 0.15);
  color: var(--green);
  border: 1px solid rgba(74, 222, 128, 0.3);
}
.badge-locked {
  background: var(--bg-3);
  color: var(--text-muted);
  border: 1px solid var(--border);
}

/* ===== Chat ===== */
.chat {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--bg);
}
.chat-empty {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}
.chat-empty-inner {
  text-align: center;
  color: var(--text-muted);
}
.chat-empty-icon {
  font-size: 48px;
  margin-bottom: 12px;
  opacity: 0.5;
}
.chat-active {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.chat-header {
  height: 60px;
  padding: 0 18px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--bg-2);
  flex-shrink: 0;
}
.back-btn {
  display: none;
  font-size: 18px;
  padding: 6px 10px;
}
.chat-header-info {
  flex: 1;
  min-width: 0;
}
.chat-header-phone {
  font-weight: 600;
  font-size: 15px;
  color: var(--text);
}
.chat-header-meta {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}
.chat-header-actions {
  display: flex;
  gap: 8px;
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.msg {
  display: flex;
  flex-direction: column;
  max-width: 75%;
}
.msg-user { align-self: flex-start; }
.msg-assistant { align-self: flex-start; }
.msg-human { align-self: flex-end; align-items: flex-end; }

.msg-author {
  font-size: 10.5px;
  color: var(--text-dim);
  margin-bottom: 3px;
  padding: 0 4px;
}
.bubble {
  padding: 10px 14px;
  border-radius: 14px;
  line-height: 1.45;
  font-size: 14px;
  word-wrap: break-word;
  white-space: pre-wrap;
}
.msg-user .bubble {
  background: var(--bg-3);
  color: var(--text);
  border-bottom-left-radius: 4px;
}
.msg-assistant .bubble {
  background: rgba(96, 165, 250, 0.12);
  color: var(--text);
  border: 1px solid rgba(96, 165, 250, 0.25);
  border-bottom-left-radius: 4px;
}
.msg-assistant .bubble::before {
  content: "🤖 ";
  opacity: 0.7;
}
.msg-human .bubble {
  background: var(--gold);
  color: #1a1a1a;
  border-bottom-right-radius: 4px;
}
.msg-time {
  font-size: 10.5px;
  color: var(--text-dim);
  margin-top: 4px;
  padding: 0 4px;
}

/* ===== Composer ===== */
.composer-wrap {
  position: relative;
  border-top: 1px solid var(--border);
  background: var(--bg-2);
  flex-shrink: 0;
}
.composer-overlay {
  position: absolute;
  inset: 0;
  background: rgba(20, 20, 26, 0.92);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 14px;
  z-index: 10;
  backdrop-filter: blur(2px);
}
.composer {
  display: flex;
  gap: 10px;
  padding: 12px 14px;
  align-items: flex-end;
}
.composer textarea {
  flex: 1;
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  padding: 10px 14px;
  font-size: 14px;
  resize: none;
  max-height: 140px;
  line-height: 1.45;
  outline: none;
  transition: border-color 0.15s;
}
.composer textarea:focus { border-color: var(--gold); }

/* ===== Auth (login) ===== */
.auth-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  overflow: auto;
}
.auth-container {
  width: 100%;
  max-width: 400px;
  padding: 20px;
}
.auth-card {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 36px 32px;
  box-shadow: var(--shadow);
}
.logo-wrap {
  text-align: center;
  margin-bottom: 8px;
}
.logo-wrap h1.brand {
  font-size: 22px;
}
.logo-wrap .brand-sub {
  display: block;
  font-size: 13px;
  margin-top: 4px;
}
.separator {
  width: 50px;
  height: 1px;
  background: var(--gold);
  opacity: 0.4;
  margin: 16px auto 28px;
}
.form-group { margin-bottom: 18px; }
.form-group label {
  display: block;
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 1.2px;
  margin-bottom: 7px;
  font-weight: 500;
}
.form-group input {
  width: 100%;
  padding: 12px 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  transition: border-color 0.15s;
  outline: none;
}
.form-group input:focus { border-color: var(--gold); }
.alert {
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 13px;
  margin-bottom: 16px;
}
.alert-error {
  background: rgba(239, 68, 68, 0.12);
  color: var(--red);
  border: 1px solid rgba(239, 68, 68, 0.3);
}
.auth-footer {
  text-align: center;
  margin-top: 18px;
  color: var(--text-dim);
  font-size: 12px;
}

.empty-state {
  padding: 30px 18px;
  color: var(--text-muted);
  font-size: 13px;
  text-align: center;
}

/* ===== Mobile ===== */
@media (max-width: 768px) {
  .sidebar { width: 100%; }
  .layout.has-active .sidebar { display: none; }
  .layout:not(.has-active) .chat { display: none; }
  .back-btn { display: inline-flex; }
  .topbar { padding: 0 14px; }
  .user-name { display: none; }
  .msg { max-width: 85%; }
}

/* ===== Scrollbar ===== */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--bg-4);
  border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover { background: #3a3a45; }
