/* ─── RESET + TOKENS ─────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg-0: #0b0f14;
  --bg-1: #11161d;
  --bg-2: #161c25;
  --bg-3: #1d242f;
  --bg-4: #252e3b;
  --border: #2a3340;
  --border-strong: #3a4554;

  --text: #e7ecf2;
  --text-mute: #8b95a3;
  --text-dim: #5a6573;

  --primary: #10b981;
  --primary-dim: #0d8d63;
  --primary-soft: rgba(16, 185, 129, 0.14);

  --green: #10b981;
  --yellow: #f59e0b;
  --red: #ef4444;
  --blue: #3b82f6;
  --purple: #8b5cf6;

  --radius: 10px;
  --radius-sm: 6px;
  --radius-lg: 14px;
  --shadow: 0 6px 20px rgba(0, 0, 0, 0.35);

  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Inter", "Segoe UI",
          Roboto, "Helvetica Neue", Arial, sans-serif;
}

html, body { height: 100%; }
body {
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg-0);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; }
input, textarea { font-family: inherit; }

.muted { color: var(--text-mute); }
.small { font-size: 12px; }

/* ─── BUTTONS ────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-2);
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  transition: all 0.15s ease;
  white-space: nowrap;
}
.btn:hover { background: var(--bg-3); border-color: var(--border-strong); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary {
  background: var(--primary);
  border-color: var(--primary);
  color: white;
}
.btn-primary:hover { background: var(--primary-dim); border-color: var(--primary-dim); }

.btn-ghost { background: transparent; }
.btn-ghost:hover { background: var(--bg-2); }

.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-block { width: 100%; }

.btn-danger { background: var(--red); border-color: var(--red); color: white; }
.btn-danger:hover { background: #dc2626; }

.btn-warning { background: var(--yellow); border-color: var(--yellow); color: #1a1200; }
.btn-warning:hover { background: #d97706; }

/* ─── ALERTS ─────────────────────────────────────────────────────────────── */
.alert {
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  font-size: 13px;
  margin-bottom: 12px;
}
.alert-error { background: rgba(239, 68, 68, 0.1); border-color: rgba(239, 68, 68, 0.4); color: #fca5a5; }
.alert-success { background: rgba(16, 185, 129, 0.1); border-color: rgba(16, 185, 129, 0.4); color: #6ee7b7; }

/* ─── LOGIN ──────────────────────────────────────────────────────────────── */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: radial-gradient(circle at 50% 0%, rgba(16, 185, 129, 0.08), transparent 60%), var(--bg-0);
}
.login-card {
  width: 100%;
  max-width: 400px;
  padding: 36px 32px;
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}
.login-logo {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 28px;
}
.login-logo h1 { font-size: 20px; font-weight: 700; }
.logo-mark {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--primary), #059669);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-weight: 800;
  font-size: 20px;
  box-shadow: 0 4px 12px rgba(16, 185, 129, 0.3);
}
.login-form { display: flex; flex-direction: column; gap: 14px; }
.login-form label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  color: var(--text-mute);
}
.login-form input {
  padding: 11px 13px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 14px;
  transition: border-color 0.15s ease;
}
.login-form input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}
.footer-note { text-align: center; margin-top: 24px; font-size: 12px; }

/* ─── APP LAYOUT ─────────────────────────────────────────────────────────── */
.app {
  display: grid;
  grid-template-columns: 240px 1fr;
  height: 100vh;
}

/* SIDEBAR */
.sidebar {
  background: var(--bg-1);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 16px 12px;
  gap: 18px;
  overflow-y: auto;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 8px;
}
.brand strong { display: block; font-size: 14px; font-weight: 700; }
.brand small { font-size: 11px; }

.side-nav { display: flex; flex-direction: column; gap: 2px; }
.side-nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 11px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  color: var(--text-mute);
  transition: all 0.15s ease;
}
.side-nav a:hover { background: var(--bg-2); color: var(--text); }
.side-nav a.active {
  background: var(--primary-soft);
  color: var(--text);
  font-weight: 500;
}
.side-nav .badge {
  margin-left: auto;
  background: var(--bg-3);
  padding: 2px 7px;
  border-radius: 10px;
  font-size: 11px;
  color: var(--text-mute);
}
.side-nav a.active .badge { background: var(--primary); color: white; }

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-dim);
  flex-shrink: 0;
}
.dot-green { background: var(--green); }
.dot-yellow { background: var(--yellow); }
.dot-red { background: var(--red); }
.dot-blue { background: var(--blue); }

.side-bottom { margin-top: auto; display: flex; flex-direction: column; gap: 8px; }
.user-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  background: var(--bg-2);
  border-radius: var(--radius-sm);
}
.avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), #059669);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-weight: 700;
  font-size: 13px;
}
.user-meta strong { display: block; font-size: 13px; }
.user-meta small { font-size: 11px; }

/* MAIN */
.main { display: flex; flex-direction: column; min-width: 0; }
.main.full { width: 100%; }

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 20px;
  background: var(--bg-1);
  border-bottom: 1px solid var(--border);
  min-height: 56px;
}
.topbar-title { font-size: 16px; font-weight: 600; flex: 1; }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 10px; }

.search {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  max-width: 420px;
}
.search input {
  flex: 1;
  padding: 8px 12px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 13px;
}
.search input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}

.instance-state {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 14px;
  font-size: 12px;
  color: var(--text-mute);
}

/* CONTENT */
.content { flex: 1; overflow: hidden; padding: 16px 20px; }
.content.split {
  display: grid;
  grid-template-columns: 380px 1fr;
  gap: 16px;
  padding: 16px 20px 20px;
  overflow: hidden;
}

/* CONTACTS PANE */
.contacts-pane {
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
}
.pane-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
}
.pane-header h2 { font-size: 14px; font-weight: 600; }

.contacts-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px;
}
.contact-row {
  display: flex;
  gap: 10px;
  padding: 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.15s ease;
}
.contact-row:hover { background: var(--bg-2); }
.contact-row.active { background: var(--primary-soft); }
.contact-row + .contact-row { margin-top: 2px; }

.contact-avatar {
  width: 40px;
  height: 40px;
  flex-shrink: 0;
  border-radius: 50%;
  background: linear-gradient(135deg, #475569, #334155);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-weight: 600;
  font-size: 14px;
}
.contact-row.active .contact-avatar {
  background: linear-gradient(135deg, var(--primary), #059669);
}

.contact-info { flex: 1; min-width: 0; }
.contact-row-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.contact-name {
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.contact-row-mid { margin-top: 1px; }
.phone {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: block;
}
.contact-row-bot {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 6px;
}

/* CHIPS */
.chip {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 500;
  white-space: nowrap;
}
.chip-green { background: rgba(16, 185, 129, 0.15); color: #6ee7b7; }
.chip-yellow { background: rgba(245, 158, 11, 0.15); color: #fcd34d; }
.chip-red { background: rgba(239, 68, 68, 0.15); color: #fca5a5; }
.chip-blue { background: rgba(59, 130, 246, 0.15); color: #93c5fd; }
.chip-purple { background: rgba(139, 92, 246, 0.15); color: #c4b5fd; }
.chip-gray, .chip-mute { background: var(--bg-3); color: var(--text-mute); }

/* DETAIL PANE */
.detail-pane {
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
}

.empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 60px 20px;
  color: var(--text-mute);
}
.empty-icon { font-size: 48px; opacity: 0.5; margin-bottom: 12px; }
.empty-state h3 { font-size: 16px; font-weight: 600; color: var(--text); margin-bottom: 6px; }

.empty {
  padding: 40px 20px;
  text-align: center;
  color: var(--text-mute);
  font-size: 13px;
}

/* DETAIL HEADER */
.detail-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-1);
}
.detail-header .contact-avatar { width: 44px; height: 44px; font-size: 16px; }
.detail-header h3 { font-size: 15px; font-weight: 600; }
.detail-header .phone-link { font-size: 12px; color: var(--text-mute); }
.detail-header-actions { margin-left: auto; display: flex; gap: 6px; flex-wrap: wrap; }

/* DETAIL TABS */
.detail-tabs {
  display: flex;
  gap: 0;
  padding: 0 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-1);
}
.detail-tab {
  padding: 10px 14px;
  font-size: 13px;
  color: var(--text-mute);
  border-bottom: 2px solid transparent;
  cursor: pointer;
  background: none;
  border-left: none;
  border-right: none;
  border-top: none;
  transition: all 0.15s ease;
}
.detail-tab:hover { color: var(--text); }
.detail-tab.active {
  color: var(--text);
  border-bottom-color: var(--primary);
  font-weight: 500;
}

.detail-body {
  flex: 1;
  overflow-y: auto;
  background: var(--bg-0);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

/* INFO PANEL */
.info-panel { padding: 16px; display: flex; flex-direction: column; gap: 14px; }

.info-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
}
.info-cell {
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
}
.info-cell-label { font-size: 11px; color: var(--text-mute); text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 4px; }
.info-cell-value { font-size: 13px; font-weight: 500; }

.section-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-mute);
  text-transform: uppercase;
  letter-spacing: 0.6px;
  margin-bottom: 8px;
}

.action-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 8px;
}

.summary-box {
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-size: 13px;
  line-height: 1.6;
  color: var(--text);
  white-space: pre-wrap;
  max-height: 200px;
  overflow-y: auto;
}

/* CHAT */
.chat-pane {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  background:
    radial-gradient(circle at 25% 25%, rgba(16, 185, 129, 0.04) 0, transparent 50%),
    radial-gradient(circle at 75% 75%, rgba(59, 130, 246, 0.04) 0, transparent 50%),
    var(--bg-0);
}
.chat-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-1);
  font-size: 12px;
  color: var(--text-mute);
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.msg {
  max-width: 70%;
  padding: 8px 12px;
  border-radius: 10px;
  font-size: 13px;
  line-height: 1.45;
  word-wrap: break-word;
  position: relative;
}
.msg-incoming {
  align-self: flex-start;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}
.msg-outgoing {
  align-self: flex-end;
  background: var(--primary);
  color: white;
  border-bottom-right-radius: 4px;
}
.msg-time {
  display: block;
  font-size: 10px;
  margin-top: 4px;
  opacity: 0.7;
}
.msg-system {
  align-self: center;
  background: rgba(245, 158, 11, 0.12);
  color: #fcd34d;
  font-size: 11px;
  border-radius: 10px;
  padding: 4px 10px;
  border: 1px solid rgba(245, 158, 11, 0.3);
}

.chat-loading, .chat-empty {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-mute);
  font-size: 13px;
  padding: 30px;
}

.chat-input {
  display: flex;
  gap: 8px;
  padding: 10px 14px;
  background: var(--bg-1);
  border-top: 1px solid var(--border);
}
.chat-input textarea {
  flex: 1;
  padding: 9px 12px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 13px;
  resize: none;
  min-height: 38px;
  max-height: 120px;
  line-height: 1.4;
}
.chat-input textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}

/* ERROR PAGE */
.error-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: var(--bg-0);
}
.error-card {
  text-align: center;
  padding: 40px;
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}
.error-card h1 { font-size: 64px; font-weight: 800; color: var(--primary); margin-bottom: 8px; }
.error-card p { color: var(--text-mute); margin-bottom: 20px; }

/* SCROLLBARS */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: var(--bg-1); }
::-webkit-scrollbar-thumb { background: var(--bg-3); border-radius: 5px; border: 2px solid var(--bg-1); }
::-webkit-scrollbar-thumb:hover { background: var(--bg-4); }

/* RESPONSIVE */
@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .content.split { grid-template-columns: 1fr; }
  .detail-pane { display: none; }
  .detail-pane.mobile-open { display: flex; position: fixed; inset: 0; z-index: 100; border-radius: 0; }
}
