/* ============================================================
   DistroBot Admin Dashboard
   Dark professional theme with green accent
   ============================================================ */

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

:root {
  --bg-base: #0d0f11;
  --bg-panel: #141618;
  --bg-surface: #1a1d20;
  --bg-hover: #202428;
  --bg-active: #252a30;

  --border: #252a30;
  --border-mid: #2e343c;
  --border-light: #374048;

  --text-primary: #e8eaed;
  --text-secondary: #8f97a3;
  --text-muted: #5a6270;

  --accent: #22c55e;
  --accent-dim: #16a34a;
  --accent-glow: rgba(34,197,94,0.12);

  --warning: #f59e0b;
  --danger: #ef4444;
  --info: #3b82f6;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;

  --font: 'DM Sans', -apple-system, sans-serif;
  --mono: 'DM Mono', monospace;

  --sidebar-w: 220px;
  --header-h: 56px;
}

body {
  font-family: var(--font);
  background: var(--bg-base);
  color: var(--text-primary);
  min-height: 100vh;
  font-size: 14px;
  line-height: 1.5;
  overflow: hidden;
}

.hidden { display: none !important; }

/* ============================================================
   LOGIN
   ============================================================ */
.login-overlay {
  position: fixed; inset: 0;
  background: var(--bg-base);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000;
}

.login-card {
  background: var(--bg-panel);
  border: 1px solid var(--border-mid);
  border-radius: var(--radius-lg);
  padding: 40px;
  width: 380px;
  box-shadow: 0 32px 80px rgba(0,0,0,0.6);
}

.login-logo {
  display: flex; align-items: center; gap: 12px;
  margin-bottom: 6px;
}

.login-logo h1 {
  font-size: 22px;
  font-weight: 600;
  color: var(--text-primary);
}

.logo-tag {
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  background: var(--accent-glow);
  color: var(--accent);
  border: 1px solid rgba(34,197,94,0.3);
  border-radius: 4px;
  padding: 2px 6px;
  margin-left: 6px;
  vertical-align: middle;
}

.logo-icon {
  width: 36px; height: 36px;
  background: var(--accent);
  color: #0d0f11;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.logo-icon.sm { width: 28px; height: 28px; font-size: 11px; border-radius: 6px; }

.login-sub {
  color: var(--text-muted);
  font-size: 13px;
  margin-bottom: 28px;
}

.login-error {
  color: var(--danger);
  font-size: 13px;
  margin-bottom: 12px;
}

/* ============================================================
   FORMS / INPUTS
   ============================================================ */
.field-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 16px;
  flex: 1;
}

.field-row {
  display: flex;
  gap: 12px;
}

.field-group label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  letter-spacing: 0.02em;
}

input[type="text"],
input[type="password"],
input[type="number"],
input[type="search"],
select,
textarea {
  background: var(--bg-surface);
  border: 1px solid var(--border-mid);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 14px;
  padding: 10px 12px;
  width: 100%;
  transition: border-color 0.15s;
  outline: none;
}

input:focus, textarea:focus, select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

textarea { resize: vertical; min-height: 60px; }
select { cursor: pointer; appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%235a6270' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; padding-right: 32px; }

.search-input { max-width: 280px; }
.select-input { max-width: 200px; }

/* ============================================================
   BUTTONS
   ============================================================ */
button { cursor: pointer; font-family: var(--font); font-size: 14px; border: none; border-radius: var(--radius-sm); transition: all 0.15s; }

.btn-primary {
  background: var(--accent);
  color: #0d0f11;
  font-weight: 600;
  padding: 10px 20px;
}
.btn-primary:hover { background: #16a34a; }

.btn-full { width: 100%; }

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  padding: 8px 14px;
  border: 1px solid var(--border-mid);
}
.btn-ghost:hover { background: var(--bg-hover); color: var(--text-primary); border-color: var(--border-light); }

.btn-warning {
  background: rgba(245,158,11,0.12);
  color: var(--warning);
  border: 1px solid rgba(245,158,11,0.3);
  padding: 8px 14px;
  font-weight: 500;
}
.btn-warning:hover { background: rgba(245,158,11,0.2); }

.btn-danger {
  background: rgba(239,68,68,0.1);
  color: var(--danger);
  border: 1px solid rgba(239,68,68,0.25);
  padding: 6px 12px;
  font-size: 13px;
}
.btn-danger:hover { background: rgba(239,68,68,0.2); }

.btn-sm {
  padding: 5px 10px;
  font-size: 12px;
}

/* ============================================================
   APP LAYOUT
   ============================================================ */
.app {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ============================================================
   SIDEBAR
   ============================================================ */
.sidebar {
  width: var(--sidebar-w);
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 18px 16px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  font-size: 15px;
  color: var(--text-primary);
}

.sidebar-nav {
  flex: 1;
  padding: 10px 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 13.5px;
  font-weight: 400;
  background: transparent;
  text-align: left;
  width: 100%;
  transition: all 0.12s;
  position: relative;
}

.nav-item:hover { background: var(--bg-hover); color: var(--text-primary); }
.nav-item.active {
  background: var(--accent-glow);
  color: var(--accent);
  font-weight: 500;
  border-left: 2px solid var(--accent);
  padding-left: 8px;
}

.nav-icon {
  font-size: 15px;
  line-height: 1;
  opacity: 0.7;
}

.nav-badge {
  margin-left: auto;
  background: var(--bg-surface);
  color: var(--text-secondary);
  font-size: 11px;
  font-weight: 600;
  padding: 1px 7px;
  border-radius: 20px;
  font-family: var(--mono);
}
.nav-badge.urgent { background: rgba(239,68,68,0.15); color: var(--danger); }

.sidebar-footer {
  padding: 14px 16px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-muted);
}

.connection-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
  flex-shrink: 0;
  transition: background 0.3s;
}
.connection-dot.connected { background: var(--accent); box-shadow: 0 0 6px var(--accent); }
.connection-dot.disconnected { background: var(--danger); }

#conn-status { flex: 1; }
#logout-btn { padding: 4px 8px; font-size: 12px; }

/* ============================================================
   MAIN CONTENT
   ============================================================ */
.main-content {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.view {
  display: none;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}
.view.active { display: flex; }

.view-header {
  padding: 20px 28px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 16px;
  flex-shrink: 0;
}

.view-header h2 {
  font-size: 18px;
  font-weight: 600;
  color: var(--text-primary);
}

.view-sub {
  font-size: 13px;
  color: var(--text-muted);
  margin-left: 16px;
}

.view-subtitle {
  font-size: 12px;
  color: var(--text-muted);
  margin-left: auto;
}

.header-actions {
  margin-left: auto;
  display: flex;
  gap: 10px;
  align-items: center;
}

/* ============================================================
   STAT CARDS
   ============================================================ */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  padding: 20px 28px;
  flex-shrink: 0;
}

.stat-card {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 20px;
  transition: border-color 0.15s;
}
.stat-card:hover { border-color: var(--border-light); }
.stat-card.highlight { border-color: rgba(34,197,94,0.3); background: rgba(34,197,94,0.03); }
.stat-card.alert { border-color: rgba(239,68,68,0.25); background: rgba(239,68,68,0.03); }

.stat-label {
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 10px;
}

.stat-value {
  font-size: 28px;
  font-weight: 600;
  color: var(--text-primary);
  font-family: var(--mono);
  line-height: 1;
  margin-bottom: 8px;
}

.highlight .stat-value { color: var(--accent); }
.alert .stat-value { color: var(--danger); }

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

/* ============================================================
   PANELS
   ============================================================ */
.panel-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  padding: 0 28px 20px;
  flex: 1;
  overflow: hidden;
  min-height: 0;
}

.panel {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.panel-header {
  padding: 14px 18px;
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.activity-feed, .live-feed {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}

.feed-item {
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  margin-bottom: 4px;
  border-left: 2px solid transparent;
  transition: background 0.1s;
}
.feed-item:hover { background: var(--bg-hover); }
.feed-item.inbound { border-left-color: var(--accent); }
.feed-item.outbound { border-left-color: var(--border-light); }

.feed-meta {
  display: flex;
  justify-content: space-between;
  margin-bottom: 4px;
}

.feed-phone {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-primary);
  font-family: var(--mono);
}

.feed-time {
  font-size: 11px;
  color: var(--text-muted);
  font-family: var(--mono);
}

.feed-body {
  font-size: 13px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ============================================================
   TABLES
   ============================================================ */
.table-wrap {
  flex: 1;
  overflow: auto;
  padding: 0 28px 20px;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}

.data-table th {
  text-align: left;
  padding: 10px 14px;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--bg-base);
  z-index: 1;
}

.data-table td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  color: var(--text-secondary);
  vertical-align: middle;
}

.data-table tr:hover td { background: var(--bg-hover); }

.data-table td:first-child { color: var(--text-primary); font-weight: 500; }

/* Status badges */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.badge-pending { background: rgba(245,158,11,0.12); color: var(--warning); }
.badge-confirmed { background: rgba(59,130,246,0.12); color: var(--info); }
.badge-paid { background: rgba(34,197,94,0.12); color: var(--accent); }
.badge-processing { background: rgba(168,85,247,0.12); color: #a855f7; }
.badge-shipped { background: rgba(6,182,212,0.12); color: #06b6d4; }
.badge-delivered { background: rgba(34,197,94,0.18); color: #4ade80; }
.badge-cancelled { background: rgba(239,68,68,0.1); color: var(--danger); }
.badge-open { background: rgba(239,68,68,0.1); color: var(--danger); }
.badge-resolved { background: rgba(34,197,94,0.12); color: var(--accent); }
.badge-registered { background: var(--accent-glow); color: var(--accent); }
.badge-unregistered { background: var(--bg-surface); color: var(--text-muted); }

/* ============================================================
   CONVERSATIONS
   ============================================================ */
.convo-layout {
  display: flex;
  flex: 1;
  overflow: hidden;
  min-height: 0;
}

.convo-sidebar {
  width: 300px;
  border-right: 1px solid var(--border);
  overflow-y: auto;
  flex-shrink: 0;
}

.convo-thread {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.1s;
}
.convo-thread:hover, .convo-thread.active { background: var(--bg-hover); }
.convo-thread.active { border-left: 2px solid var(--accent); padding-left: 14px; }

.thread-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 4px;
}

.thread-name {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
}

.thread-time {
  font-size: 11px;
  color: var(--text-muted);
  font-family: var(--mono);
}

.thread-phone {
  font-size: 12px;
  color: var(--text-muted);
  font-family: var(--mono);
  margin-bottom: 4px;
}

.thread-preview {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.convo-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.chat-header {
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  background: var(--bg-panel);
}

.chat-customer-info {
  display: flex;
  align-items: center;
  gap: 12px;
}

.chat-avatar {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: var(--accent-glow);
  border: 1px solid rgba(34,197,94,0.3);
  color: var(--accent);
  font-weight: 600;
  font-size: 14px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}

.chat-name { font-weight: 500; font-size: 14px; }
.chat-phone { font-size: 12px; color: var(--text-muted); font-family: var(--mono); }

.chat-actions { display: flex; gap: 8px; }

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

.chat-empty {
  color: var(--text-muted);
  text-align: center;
  margin: auto;
  font-size: 13px;
}

.msg-bubble {
  max-width: 68%;
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 13.5px;
  line-height: 1.55;
  position: relative;
}

.msg-inbound {
  background: var(--bg-panel);
  border: 1px solid var(--border-mid);
  align-self: flex-start;
  border-radius: 4px 12px 12px 12px;
}

.msg-outbound {
  background: rgba(34,197,94,0.1);
  border: 1px solid rgba(34,197,94,0.2);
  align-self: flex-end;
  border-radius: 12px 4px 12px 12px;
  color: var(--text-primary);
}

.msg-outbound.admin-msg {
  background: rgba(245,158,11,0.1);
  border-color: rgba(245,158,11,0.25);
}

.msg-time {
  font-size: 10px;
  color: var(--text-muted);
  margin-top: 4px;
  font-family: var(--mono);
}

.msg-label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.chat-input-area {
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 10px;
  align-items: flex-end;
  background: var(--bg-panel);
  flex-shrink: 0;
}

.chat-input-area textarea {
  flex: 1;
}

/* ============================================================
   PAYMENTS GRID
   ============================================================ */
.payments-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 16px;
  padding: 20px 28px;
  overflow-y: auto;
  flex: 1;
}

.payment-card {
  background: var(--bg-panel);
  border: 1px solid var(--border-mid);
  border-radius: var(--radius-md);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  transition: border-color 0.15s;
}
.payment-card:hover { border-color: var(--border-light); }

.payment-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}

.payment-invoice {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  font-family: var(--mono);
}

.payment-amount {
  font-size: 22px;
  font-weight: 700;
  color: var(--accent);
  font-family: var(--mono);
}

.payment-currency {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 400;
}

.payment-detail {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.payment-row {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  color: var(--text-secondary);
}
.payment-row span:last-child { color: var(--text-primary); font-weight: 500; }

.payment-card-footer {
  padding-top: 4px;
  border-top: 1px solid var(--border);
}

.btn-mark-paid {
  width: 100%;
  padding: 10px;
  background: var(--accent);
  color: #0d0f11;
  font-weight: 600;
  border-radius: var(--radius-sm);
  font-size: 13px;
  transition: background 0.15s;
}
.btn-mark-paid:hover { background: var(--accent-dim); }
.btn-mark-paid:disabled { opacity: 0.5; cursor: not-allowed; background: var(--bg-surface); color: var(--text-muted); }

/* ============================================================
   ISSUES
   ============================================================ */
.issues-list {
  flex: 1;
  overflow-y: auto;
  padding: 20px 28px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.issue-card {
  background: var(--bg-panel);
  border: 1px solid var(--border-mid);
  border-left: 3px solid var(--danger);
  border-radius: var(--radius-md);
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.issue-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}

.issue-customer {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
}

.issue-phone {
  font-size: 12px;
  color: var(--text-muted);
  font-family: var(--mono);
}

.issue-question {
  font-size: 14px;
  color: var(--text-secondary);
  background: var(--bg-surface);
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  border-left: 2px solid var(--danger);
  font-style: italic;
}

.issue-footer {
  display: flex;
  gap: 10px;
  align-items: center;
}

.issue-time {
  font-size: 12px;
  color: var(--text-muted);
  font-family: var(--mono);
  flex: 1;
}

/* ============================================================
   MODAL
   ============================================================ */
.modal {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.7);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
}

.modal-content {
  background: var(--bg-panel);
  border: 1px solid var(--border-mid);
  border-radius: var(--radius-lg);
  width: 520px;
  max-width: 95vw;
  box-shadow: 0 32px 80px rgba(0,0,0,0.7);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
}

.modal-header h3 {
  font-size: 16px;
  font-weight: 600;
}

.modal-close {
  background: transparent;
  color: var(--text-muted);
  font-size: 16px;
  padding: 4px 8px;
  border-radius: 4px;
}
.modal-close:hover { background: var(--bg-hover); color: var(--text-primary); }

.modal-body { padding: 20px 24px; }

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 16px 24px;
  border-top: 1px solid var(--border);
}

/* ============================================================
   SCROLLBARS
   ============================================================ */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-light); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ============================================================
   TOAST NOTIFICATIONS
   ============================================================ */
#toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 9999;
}

.toast {
  background: var(--bg-panel);
  border: 1px solid var(--border-mid);
  border-radius: var(--radius-md);
  padding: 12px 18px;
  font-size: 13px;
  color: var(--text-primary);
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
  animation: slideIn 0.2s ease;
  min-width: 250px;
  max-width: 360px;
}

.toast.success { border-left: 3px solid var(--accent); }
.toast.error { border-left: 3px solid var(--danger); }
.toast.info { border-left: 3px solid var(--info); }

@keyframes slideIn {
  from { opacity: 0; transform: translateX(20px); }
  to { opacity: 1; transform: translateX(0); }
}
