/* ============================================================
   TrunkMasters SMS — Dark Theme
   ============================================================ */

:root {
  --bg: #111;
  --bg-surface: #1a1a1a;
  --bg-elevated: #222;
  --bg-hover: #2a2a2a;
  --text: #fff;
  --text-secondary: #999;
  --text-muted: #666;
  --accent: #0088ff;
  --accent-hover: #006cd6;
  --danger: #e53935;
  --success: #43a047;
  --warning: #fb8c00;
  --border: #333;
  --bubble-out: #0088ff;
  --bubble-in: #333;
  --radius: 8px;
  --radius-lg: 12px;
  --sidebar-w: 320px;
  --topbar-h: 52px;
  --input-bar-min: 60px;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
  --transition: .18s ease;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }

html, body {
  height: 100%;
  font-family: var(--font);
  font-size: 14px;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}

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

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

/* --- SCROLLBAR --- */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #444; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #555; }

/* ============================================================
   BUTTONS
   ============================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-elevated);
  color: var(--text);
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition);
  white-space: nowrap;
  line-height: 1.4;
}
.btn:hover { background: var(--bg-hover); }
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }

.btn-danger {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
}
.btn-danger:hover { opacity: .85; }

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

.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-block { width: 100%; }
.btn-icon { padding: 8px; min-width: 36px; }

/* ============================================================
   FORMS
   ============================================================ */
.form-group { margin-bottom: 14px; }
.form-group label {
  display: block;
  margin-bottom: 4px;
  font-size: 12px;
  color: var(--text-secondary);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .5px;
}
.form-group input,
.form-group textarea,
.form-group select {
  width: 100%;
  padding: 10px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  outline: none;
  transition: border-color var(--transition);
}
.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
  border-color: var(--accent);
}

.form-error {
  background: rgba(229,57,53,.15);
  color: var(--danger);
  padding: 8px 12px;
  border-radius: var(--radius);
  margin-bottom: 12px;
  font-size: 13px;
}

.form-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 18px;
}

/* ============================================================
   LOGIN SCREEN
   ============================================================ */
.login-screen {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  z-index: 9000;
}
.login-card {
  width: 100%;
  max-width: 380px;
  padding: 40px 32px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}
.login-logo {
  text-align: center;
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 28px;
  letter-spacing: -.5px;
}
.login-logo span { color: var(--accent); }

/* ============================================================
   TOP BAR
   ============================================================ */
.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  height: var(--topbar-h);
  padding: 0 16px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.topbar-title {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -.3px;
}
.topbar-title span { color: var(--accent); }
.topbar-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 10px;
}
.topbar-menu-btn {
  display: none;
  background: none;
  border: none;
  color: var(--text);
  cursor: pointer;
  padding: 4px;
}
.user-display {
  font-size: 12px;
  color: var(--text-secondary);
}

/* WS indicator */
.ws-indicator {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}
.ws-connected { background: var(--success); }
.ws-disconnected { background: var(--danger); }
.ws-connecting { background: var(--warning); animation: pulse 1s infinite; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .3; } }

/* ============================================================
   APP LAYOUT
   ============================================================ */
.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
}
.app-body {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* ============================================================
   SIDEBAR
   ============================================================ */
.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  display: flex;
  flex-direction: column;
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  overflow: hidden;
}
.sidebar-header { padding: 12px; }
.sidebar-nav {
  display: flex;
  border-bottom: 1px solid var(--border);
}
.sidebar-tab {
  flex: 1;
  padding: 10px;
  text-align: center;
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .5px;
  border-bottom: 2px solid transparent;
  transition: color var(--transition), border-color var(--transition);
}
.sidebar-tab:hover { color: var(--text); }
.sidebar-tab.active { color: var(--accent); border-bottom-color: var(--accent); }

.sidebar-search {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
}
.sidebar-search input {
  width: 100%;
  padding: 8px 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  outline: none;
  font-size: 13px;
}
.sidebar-search input:focus { border-color: var(--accent); }

.sidebar-content {
  flex: 1;
  overflow-y: auto;
}

/* ============================================================
   CONVERSATION LIST
   ============================================================ */
.conversation-list { list-style: none; }

.convo-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background var(--transition);
}
.convo-item:hover { background: var(--bg-hover); }
.convo-item.active { background: var(--bg-elevated); border-left: 3px solid var(--accent); }

.convo-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--bg-elevated);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 15px;
  color: var(--accent);
  flex-shrink: 0;
  text-transform: uppercase;
}

.convo-info {
  flex: 1;
  min-width: 0;
}
.convo-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 2px;
}
.convo-name {
  font-weight: 600;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.convo-time {
  font-size: 11px;
  color: var(--text-muted);
  flex-shrink: 0;
  margin-left: 8px;
}
.convo-preview {
  font-size: 13px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.convo-badge {
  background: var(--accent);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  min-width: 20px;
  height: 20px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 6px;
  flex-shrink: 0;
}

/* ============================================================
   CONTACT LIST (sidebar)
   ============================================================ */
.contact-list { list-style: none; }

.contact-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background var(--transition);
}
.contact-item:hover { background: var(--bg-hover); }
.contact-item-info { flex: 1; min-width: 0; }
.contact-item-name { font-weight: 600; font-size: 14px; }
.contact-item-phone { font-size: 12px; color: var(--text-secondary); }
.contact-item-actions {
  display: flex;
  gap: 4px;
  opacity: 0;
  transition: opacity var(--transition);
}
.contact-item:hover .contact-item-actions { opacity: 1; }

/* ============================================================
   MAIN PANEL
   ============================================================ */
.main-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}

/* EMPTY STATE */
.empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  color: var(--text-muted);
}

/* ============================================================
   CHAT VIEW
   ============================================================ */
.chat-view {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.chat-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.chat-back-btn {
  display: none;
  background: none;
  border: none;
  color: var(--text);
  cursor: pointer;
  padding: 4px;
}
.chat-header-info h3 { font-size: 15px; font-weight: 600; }
.chat-subtitle { font-size: 12px; color: var(--text-secondary); }

/* Messages area */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
}
.load-more-wrap {
  text-align: center;
  padding: 8px 0 16px;
}

/* ============================================================
   MESSAGE BUBBLES
   ============================================================ */
.msg-group {
  margin-bottom: 16px;
}
.msg-date-separator {
  text-align: center;
  margin: 16px 0;
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .5px;
}
.msg-date-separator span {
  background: var(--bg);
  padding: 2px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
}

.msg-row {
  display: flex;
  margin-bottom: 3px;
}
.msg-row.outbound { justify-content: flex-end; }
.msg-row.inbound { justify-content: flex-start; }

.msg-bubble {
  max-width: 65%;
  padding: 9px 14px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.45;
  word-wrap: break-word;
  position: relative;
}
.msg-row.outbound .msg-bubble {
  background: var(--bubble-out);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.msg-row.inbound .msg-bubble {
  background: var(--bubble-in);
  color: var(--text);
  border-bottom-left-radius: 4px;
}

.msg-media { margin-bottom: 6px; }
.msg-media img {
  max-width: 240px;
  max-height: 200px;
  border-radius: var(--radius);
  cursor: pointer;
  display: block;
}
.msg-media-file {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  background: rgba(255,255,255,.1);
  border-radius: var(--radius);
  font-size: 12px;
  color: inherit;
  text-decoration: none;
}
.msg-media-file:hover { background: rgba(255,255,255,.2); text-decoration: none; }

.msg-meta {
  display: flex;
  align-items: center;
  gap: 4px;
  justify-content: flex-end;
  margin-top: 3px;
  font-size: 11px;
  color: rgba(255,255,255,.6);
}
.msg-row.inbound .msg-meta { color: var(--text-muted); }

/* Status icons */
.msg-status { font-size: 12px; line-height: 1; }
.msg-status.sent::after { content: '\2713'; }
.msg-status.delivered::after { content: '\2713\2713'; }
.msg-status.read::after { content: '\2713\2713'; color: #6cf; }
.msg-status.failed { color: var(--danger); }
.msg-status.failed::after { content: '\2717'; }
.msg-status.queued::after { content: '\23F3'; }
.msg-status.sending { opacity: .5; }
.msg-status.sending::after { content: '\2022'; }

/* Typing indicator */
.typing-indicator {
  display: flex;
  gap: 4px;
  padding: 8px 0;
  align-items: center;
}
.typing-indicator span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: typingDot 1.2s infinite;
}
.typing-indicator span:nth-child(2) { animation-delay: .2s; }
.typing-indicator span:nth-child(3) { animation-delay: .4s; }
@keyframes typingDot {
  0%, 60%, 100% { opacity: .3; transform: scale(.8); }
  30% { opacity: 1; transform: scale(1); }
}

/* ============================================================
   CHAT INPUT BAR
   ============================================================ */
.chat-input-bar {
  border-top: 1px solid var(--border);
  background: var(--bg-surface);
  flex-shrink: 0;
}
.chat-input-row {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  padding: 8px 12px;
}
.message-input {
  flex: 1;
  padding: 10px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 20px;
  color: var(--text);
  outline: none;
  resize: none;
  max-height: 120px;
  line-height: 1.4;
}
.message-input:focus { border-color: var(--accent); }

.from-number-wrap {
  flex-shrink: 0;
}
.from-number-select {
  padding: 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-secondary);
  font-size: 12px;
  outline: none;
  max-width: 140px;
}
.from-number-select:focus { border-color: var(--accent); }

/* Media preview in send bar */
.media-preview-bar {
  display: flex;
  gap: 8px;
  padding: 8px 12px;
  overflow-x: auto;
  border-bottom: 1px solid var(--border);
}
.media-preview-item {
  position: relative;
  width: 60px;
  height: 60px;
  border-radius: var(--radius);
  overflow: hidden;
  flex-shrink: 0;
  background: var(--bg-elevated);
  display: flex;
  align-items: center;
  justify-content: center;
}
.media-preview-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.media-preview-item .file-icon {
  font-size: 11px;
  color: var(--text-secondary);
  text-align: center;
  padding: 4px;
  word-break: break-all;
}
.media-preview-remove {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: rgba(0,0,0,.7);
  color: #fff;
  border: none;
  cursor: pointer;
  font-size: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

/* ============================================================
   MODALS
   ============================================================ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 5000;
  backdrop-filter: blur(4px);
}
.modal {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 440px;
  padding: 24px;
  max-height: 85vh;
  overflow-y: auto;
}
.modal-wide { max-width: 600px; }
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
}
.modal-header h3 { font-size: 18px; font-weight: 700; }
.modal-close {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 24px;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
}
.modal-close:hover { color: var(--text); }

/* ============================================================
   LIGHTBOX
   ============================================================ */
.lightbox-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.92);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 8000;
  cursor: zoom-out;
}
.lightbox-overlay img {
  max-width: 92vw;
  max-height: 92vh;
  border-radius: var(--radius);
  box-shadow: 0 8px 40px rgba(0,0,0,.5);
}
.lightbox-close {
  position: absolute;
  top: 16px;
  right: 20px;
  background: none;
  border: none;
  color: #fff;
  font-size: 32px;
  cursor: pointer;
}

/* ============================================================
   ADMIN PANEL
   ============================================================ */
.admin-panel {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
}
.admin-panel h2 { margin-bottom: 16px; }

.admin-tabs {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 20px;
}
.admin-tab {
  padding: 10px 20px;
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  font-weight: 600;
  font-size: 13px;
  border-bottom: 2px solid transparent;
  transition: color var(--transition), border-color var(--transition);
}
.admin-tab:hover { color: var(--text); }
.admin-tab.active { color: var(--accent); border-bottom-color: var(--accent); }

.admin-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
}

.admin-table {
  width: 100%;
  border-collapse: collapse;
}
.admin-table th,
.admin-table td {
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.admin-table th {
  font-weight: 700;
  color: var(--text-secondary);
  text-transform: uppercase;
  font-size: 11px;
  letter-spacing: .5px;
}
.admin-table tr:hover td { background: var(--bg-hover); }
.admin-table .actions { white-space: nowrap; }
.admin-table .actions .btn { margin-left: 4px; }

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
}
.badge-active { background: rgba(67,160,71,.2); color: var(--success); }
.badge-suspended { background: rgba(229,57,53,.2); color: var(--danger); }
.badge-inactive { background: rgba(102,102,102,.2); color: var(--text-muted); }

/* ============================================================
   DRAG & DROP
   ============================================================ */
.chat-messages.drag-over {
  outline: 2px dashed var(--accent);
  outline-offset: -4px;
  background: rgba(0,136,255,.05);
}

/* ============================================================
   RESPONSIVE (mobile < 768px)
   ============================================================ */
@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    top: var(--topbar-h);
    left: 0;
    bottom: 0;
    z-index: 2000;
    transform: translateX(-100%);
    transition: transform .25s ease;
  }
  .sidebar.open { transform: translateX(0); }
  .topbar-menu-btn { display: block; }
  .chat-back-btn { display: block; }

  .msg-bubble { max-width: 82%; }

  .from-number-select { max-width: 100px; font-size: 11px; }

  .admin-table { font-size: 12px; }
  .admin-table th, .admin-table td { padding: 6px 8px; }
}
