/* ─── Reset & Base ──────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0f0f0f;
  --bg-card: #1a1a1a;
  --bg-sidebar: #141414;
  --bg-input: #222;
  --border: #2a2a2a;
  --text: #e8e8e8;
  --text-muted: #888;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --danger: #ef4444;
  --danger-hover: #dc2626;
  --warning: #f59e0b;
  --success: #22c55e;
  --badge-waiting: #f59e0b;
  --badge-active: #22c55e;
  --badge-closed: #6b7280;
  --badge-expired: #ef4444;
  --msg-user: #1e293b;
  --msg-operator: #1a2e1a;
  --msg-system: #2a2a2a;
  --radius: 8px;
  --radius-sm: 4px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

code { background: var(--bg-input); padding: 2px 6px; border-radius: 3px; font-size: 13px; }

/* ─── Navbar ───────────────────────────────────────────────────────────── */
.navbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  height: 56px;
  gap: 24px;
}
.navbar-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}
.navbar-logo { font-size: 20px; }
.navbar-title { font-weight: 700; font-size: 16px; color: var(--text); }
.navbar-links {
  display: flex;
  align-items: center;
  gap: 4px;
  flex: 1;
}
.nav-link {
  padding: 6px 14px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  color: var(--text-muted);
  transition: all 0.15s;
}
.nav-link:hover { color: var(--text); background: rgba(255,255,255,0.05); text-decoration: none; }
.nav-link.active { color: var(--text); background: rgba(255,255,255,0.08); }
.navbar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}
.nav-username { font-size: 14px; color: var(--text-muted); }

/* ─── Main Content ─────────────────────────────────────────────────────── */
.main-content {
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px;
}

/* ─── Buttons ──────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px 16px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  text-decoration: none;
  white-space: nowrap;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { background: var(--danger-hover); }
.btn-danger-ghost { background: transparent; color: var(--danger); border: 1px solid var(--danger); }
.btn-danger-ghost:hover { background: var(--danger); color: #fff; }
.btn-warning { background: var(--warning); color: #000; }
.btn-warning:hover:not(:disabled) { background: #d97706; }
.btn-outline { background: transparent; border: 1px solid var(--border); color: var(--text); }
.btn-outline:hover:not(:disabled) { border-color: var(--text-muted); background: var(--bg-card); text-decoration: none; }
.btn-ghost { background: transparent; color: var(--text-muted); }
.btn-ghost:hover { color: var(--text); }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-full { width: 100%; }
.mt-2 { margin-top: 8px; }
.mb-4 { margin-bottom: 24px; }

/* ─── Badges ───────────────────────────────────────────────────────────── */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.badge-waiting { background: var(--badge-waiting); color: #000; }
.badge-active { background: var(--badge-active); color: #000; }
.badge-closed { background: var(--badge-closed); color: #fff; }
.badge-expired { background: var(--badge-expired); color: #fff; }
.badge-superadmin { background: var(--primary); color: #fff; }
.badge-operator { background: var(--bg-input); color: var(--text-muted); border: 1px solid var(--border); }

/* ─── Page Header ──────────────────────────────────────────────────────── */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
}
.page-title { font-size: 24px; font-weight: 700; }
.page-actions { display: flex; align-items: center; gap: 12px; }
.total-count { font-size: 14px; color: var(--text-muted); }

/* ─── Filters ──────────────────────────────────────────────────────────── */
.filters-bar {
  margin-bottom: 20px;
}
.filters-form {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}
.status-tabs {
  display: flex;
  gap: 4px;
}
.status-tab {
  padding: 6px 14px;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: transparent;
  color: var(--text-muted);
  font-size: 13px;
  cursor: pointer;
  transition: all 0.15s;
  text-decoration: none;
}
.status-tab:hover { border-color: var(--text-muted); color: var(--text); text-decoration: none; }
.status-tab.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.search-box { flex-shrink: 0; }
.search-input {
  padding: 6px 14px;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: var(--bg-input);
  color: var(--text);
  font-size: 13px;
  width: 280px;
  outline: none;
}
.search-input:focus { border-color: var(--primary); }

/* ─── Table ────────────────────────────────────────────────────────────── */
.table-wrapper {
  overflow-x: auto;
}
.sessions-table {
  width: 100%;
  border-collapse: collapse;
}
.sessions-table th {
  text-align: left;
  padding: 10px 12px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 1px solid var(--border);
}
.sessions-table td {
  padding: 12px;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}
.sessions-table tr { transition: background 0.1s; }
.sessions-table tbody tr:hover { background: var(--bg-card); }
.session-row { cursor: pointer; }

.user-cell { display: flex; flex-direction: column; gap: 2px; }
.user-name { font-weight: 600; font-size: 14px; }
.user-sub { font-size: 12px; color: var(--text-muted); }
.operator-cell { font-size: 14px; }

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

/* Pagination */
.pagination {
  display: flex;
  justify-content: center;
  gap: 4px;
  margin-top: 20px;
}
.page-link {
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-muted);
  font-size: 13px;
  cursor: pointer;
  text-decoration: none;
}
.page-link.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.page-link:hover:not(.active) { border-color: var(--text-muted); text-decoration: none; }

/* Empty State */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 64px 24px;
  text-align: center;
}
.empty-icon { font-size: 48px; margin-bottom: 16px; }
.empty-text { font-size: 16px; color: var(--text-muted); }

/* ─── Cards ────────────────────────────────────────────────────────────── */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.card-header {
  padding: 14px 20px;
  font-weight: 600;
  font-size: 14px;
  border-bottom: 1px solid var(--border);
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.card-body { padding: 20px; }

/* ─── Forms ────────────────────────────────────────────────────────────── */
.add-form { display: flex; flex-direction: column; gap: 12px; }
.form-row {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  align-items: flex-end;
}
.form-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
  min-width: 140px;
}
.form-group-btn {
  flex: 0;
  min-width: auto;
  justify-content: flex-end;
}
.form-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.required { color: var(--danger); }
.form-input {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  color: var(--text);
  font-size: 14px;
  outline: none;
  font-family: inherit;
}
.form-input:focus { border-color: var(--primary); }

/* Alerts */
.alert {
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  font-size: 14px;
}
.alert-error { background: rgba(239,68,68,0.15); color: var(--danger); border: 1px solid rgba(239,68,68,0.3); }
.alert-success { background: rgba(34,197,94,0.15); color: var(--success); border: 1px solid rgba(34,197,94,0.3); }

/* ─── Session Page ─────────────────────────────────────────────────────── */
.session-layout {
  display: flex;
  height: calc(100vh - 56px);
}
.session-sidebar {
  width: 280px;
  min-width: 280px;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 16px;
  overflow-y: auto;
}
.sidebar-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}
.back-link { color: var(--text-muted); font-size: 14px; }
.back-link:hover { color: var(--text); text-decoration: none; }
.sidebar-title { font-size: 16px; font-weight: 700; }

.session-info { display: flex; flex-direction: column; gap: 12px; }
.info-row { display: flex; flex-direction: column; gap: 2px; }
.info-label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-muted); }
.info-value { font-size: 14px; }

.session-actions { margin-top: 24px; display: flex; flex-direction: column; gap: 0; }
.capture-notice, .waiting-notice, .closed-notice { text-align: center; }

/* ─── Chat ─────────────────────────────────────────────────────────────── */
.chat-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 24px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.message {
  max-width: 70%;
  padding: 10px 14px;
  border-radius: var(--radius);
  word-wrap: break-word;
}
.message-user {
  align-self: flex-start;
  background: var(--msg-user);
}
.message-operator {
  align-self: flex-end;
  background: var(--msg-operator);
}
.message-system {
  align-self: center;
  background: var(--msg-system);
  max-width: 90%;
  font-size: 12px;
  color: var(--text-muted);
  text-align: center;
}
.message-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 4px;
}
.message-sender { font-size: 12px; font-weight: 600; color: var(--primary); }
.message-system .message-sender { color: var(--text-muted); }
.message-time { font-size: 11px; color: var(--text-muted); white-space: nowrap; }
.message-text { font-size: 14px; white-space: pre-wrap; }
.message-caption { font-size: 13px; margin-top: 4px; color: var(--text-muted); }

.message-media { margin-top: 4px; }
.media-img {
  max-width: 100%;
  max-height: 300px;
  border-radius: var(--radius-sm);
  cursor: pointer;
}
.media-audio { width: 100%; max-width: 300px; }
.media-video { max-width: 100%; max-height: 300px; border-radius: var(--radius-sm); }
.media-videonote {
  width: 200px; height: 200px;
  border-radius: 50%;
  object-fit: cover;
}
.file-link {
  display: inline-block;
  padding: 6px 12px;
  background: var(--bg-input);
  border-radius: var(--radius-sm);
  font-size: 13px;
}

/* Input */
.chat-input-area {
  border-top: 1px solid var(--border);
  padding: 12px 24px;
  background: var(--bg-card);
}
.text-form { display: flex; gap: 8px; }
.message-textarea {
  flex: 1;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-input);
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  resize: none;
  outline: none;
  max-height: 120px;
}
.message-textarea:focus { border-color: var(--primary); }
.send-btn { padding: 10px 20px; align-self: flex-end; }

.media-form-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
}
.file-label { cursor: pointer; }
.file-preview {
  display: flex;
  align-items: center;
  gap: 8px;
}
.file-name-text {
  font-size: 13px;
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.select-sm {
  padding: 4px 8px;
  background: var(--bg-input);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 12px;
}

.chat-readonly-notice {
  padding: 16px 24px;
  text-align: center;
  color: var(--text-muted);
  font-size: 14px;
  border-top: 1px solid var(--border);
  background: var(--bg-card);
}

.send-error {
  color: var(--danger);
  font-size: 12px;
  margin-top: 4px;
}

/* ─── Login ────────────────────────────────────────────────────────────── */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 24px;
}
.login-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 48px;
  text-align: center;
  max-width: 400px;
  width: 100%;
}
.login-title { font-size: 24px; font-weight: 700; margin-bottom: 8px; }
.login-subtitle { color: var(--text-muted); margin-bottom: 32px; }
.login-error { color: var(--danger); margin-bottom: 16px; font-size: 14px; }

/* ─── Lightbox ─────────────────────────────────────────────────────────── */
.lightbox {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.9);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  cursor: pointer;
}
.lightbox img { max-width: 90vw; max-height: 90vh; border-radius: 4px; }

/* Status overlay */
.status-overlay {
  position: fixed;
  bottom: 24px;
  right: 24px;
  padding: 12px 20px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  z-index: 100;
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}

/* ─── Operators Page ───────────────────────────────────────────────────── */
.operators-page { max-width: 800px; margin: 0 auto; padding: 24px; }

/* ─── Responsive ───────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .session-layout { flex-direction: column; }
  .session-sidebar {
    width: 100%;
    min-width: 100%;
    border-right: none;
    border-bottom: 1px solid var(--border);
    max-height: 200px;
    overflow-y: auto;
  }
  .message { max-width: 90%; }
  .main-content { padding: 12px; }
  .navbar { padding: 0 16px; }
  .filters-form { flex-direction: column; align-items: stretch; }
  .status-tabs { flex-wrap: wrap; }
  .search-input { width: 100%; }
  .form-row { flex-direction: column; }
  .form-group { min-width: 100%; }
}
