:root {
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --primary-light: #eef2ff;
  --primary-border: #c7d2fe;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --bg-main: #0f172a;
  --bg-sidebar: #1e293b;
  --bg-card: #ffffff;
  --bg-app: #f8fafc;
  --text-main: #0f172a;
  --text-muted: #64748b;
  --text-light: #94a3b8;
  --border: #e2e8f0;
  --border-dark: #334155;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
  --shadow-lg: 0 10px 25px rgba(0,0,0,0.12);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

body {
  background-color: var(--bg-app);
  color: var(--text-main);
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* App Layout */
.app-container {
  display: flex;
  flex: 1;
  height: calc(100vh - 64px);
  height: calc(100dvh - 64px);
  overflow: hidden;
  position: relative;
}

/* Header Navbar */
.app-navbar {
  height: 64px;
  background: var(--bg-main);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  border-bottom: 1px solid var(--border-dark);
  z-index: 50;
  flex-shrink: 0;
}

.brand-logo {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 18px;
  font-weight: 700;
  color: #fff;
  text-decoration: none;
}

.brand-badge {
  background: linear-gradient(135deg, var(--primary), #818cf8);
  color: #fff;
  font-size: 11px;
  padding: 2px 7px;
  border-radius: 12px;
  font-weight: 600;
  letter-spacing: 0.5px;
}

.nav-center {
  display: flex;
  align-items: center;
  gap: 6px;
}

.nav-link {
  color: var(--text-light);
  text-decoration: none;
  padding: 8px 14px;
  border-radius: var(--radius-md);
  font-size: 13.5px;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 7px;
  transition: all 0.2s;
}

.nav-link:hover {
  color: #fff;
  background: rgba(255,255,255,0.08);
}

.nav-link.active {
  color: #fff;
  background: var(--primary);
}

.nav-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

/* Agent Presence Switcher */
.status-pill {
  display: flex;
  align-items: center;
  gap: 6px;
  background: #1e293b;
  padding: 6px 10px;
  border-radius: 20px;
  font-size: 12.5px;
  cursor: pointer;
  border: 1px solid var(--border-dark);
}

.agent-profile {
  display: flex;
  align-items: center;
  gap: 8px;
}

.agent-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 13px;
  flex-shrink: 0;
}

/* Mobile Bottom Navigation Bar */
.mobile-bottom-nav {
  display: none;
  height: 60px;
  background: var(--bg-main);
  border-top: 1px solid var(--border-dark);
  align-items: center;
  justify-content: space-around;
  z-index: 100;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
}

.mobile-nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--text-light);
  text-decoration: none;
  font-size: 10.5px;
  font-weight: 500;
  gap: 3px;
  flex: 1;
  height: 100%;
  transition: color 0.15s;
}

.mobile-nav-item.active {
  color: #818cf8;
}

.mobile-nav-item svg {
  width: 20px;
  height: 20px;
}

/* Inbox 3-Column Console */
.inbox-layout {
  display: flex;
  width: 100%;
  height: 100%;
  position: relative;
}

/* Left: Conversations List */
.inbox-sidebar {
  width: 340px;
  min-width: 300px;
  background: #ffffff;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  height: 100%;
  transition: transform 0.25s ease;
}

.inbox-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  padding: 6px 8px 0;
  background: #f8fafc;
  gap: 2px;
  overflow-x: auto;
  scrollbar-width: none;
}
.inbox-tabs::-webkit-scrollbar { display: none; }

.inbox-tab {
  flex: 1;
  min-width: max-content;
  text-align: center;
  padding: 10px 8px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
}

.inbox-tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

.tab-badge {
  background: #e2e8f0;
  color: var(--text-main);
  font-size: 10.5px;
  padding: 1px 6px;
  border-radius: 10px;
  font-weight: 700;
}
.inbox-tab.active .tab-badge {
  background: var(--primary-light);
  color: var(--primary);
}

.conv-list {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.conv-item {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.15s;
  position: relative;
}

.conv-item:hover {
  background: #f8fafc;
}

.conv-item.selected {
  background: var(--primary-light);
  border-left: 4px solid var(--primary);
}

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

.conv-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-main);
}

.conv-time {
  font-size: 11px;
  color: var(--text-light);
}

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

.conv-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 6px;
}

.conv-badge {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 6px;
  font-weight: 500;
}
.badge-unassigned { background: #fef3c7; color: #b45309; }
.badge-active { background: #d1fae5; color: #047857; }
.badge-closed { background: #f1f5f9; color: #64748b; }

/* Center: Active Chat Stream */
.inbox-chat {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: #ffffff;
  border-right: 1px solid var(--border);
  height: 100%;
}

.chat-header {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: #ffffff;
  flex-shrink: 0;
}

.chat-user-info h3 {
  font-size: 15px;
  font-weight: 600;
}

.chat-user-info p {
  font-size: 11.5px;
  color: var(--text-muted);
}

.chat-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.btn {
  padding: 7px 14px;
  border-radius: var(--radius-md);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  border: 1px solid transparent;
  transition: all 0.2s;
  text-decoration: none;
  white-space: nowrap;
}

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

.btn-outline { background: #fff; border-color: var(--border); color: var(--text-main); }
.btn-outline:hover { background: #f8fafc; border-color: #cbd5e1; }

.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { opacity: 0.9; }

.btn-danger { background: #fee2e2; color: var(--danger); border-color: #fecaca; }
.btn-danger:hover { background: #fca5a5; }

.chat-stream {
  flex: 1;
  padding: 16px;
  overflow-y: auto;
  background: #f8fafc;
  display: flex;
  flex-direction: column;
  gap: 12px;
  -webkit-overflow-scrolling: touch;
}

.chat-bubble-agent {
  align-self: flex-end;
  background: var(--primary);
  color: #fff;
  padding: 10px 15px;
  border-radius: 14px;
  border-bottom-right-radius: 3px;
  max-width: 82%;
  font-size: 13.5px;
  line-height: 1.45;
  box-shadow: var(--shadow-sm);
  word-break: break-word;
}

.chat-bubble-visitor {
  align-self: flex-start;
  background: #ffffff;
  color: var(--text-main);
  border: 1px solid var(--border);
  padding: 10px 15px;
  border-radius: 14px;
  border-bottom-left-radius: 3px;
  max-width: 82%;
  font-size: 13.5px;
  line-height: 1.45;
  box-shadow: var(--shadow-sm);
  word-break: break-word;
}

.chat-bubble-system {
  align-self: center;
  background: #e2e8f0;
  color: var(--text-muted);
  padding: 5px 12px;
  border-radius: 20px;
  font-size: 11.5px;
  text-align: center;
  max-width: 90%;
}

.chat-composer {
  padding: 10px 14px;
  border-top: 1px solid var(--border);
  background: #ffffff;
  display: flex;
  gap: 8px;
  align-items: center;
  flex-shrink: 0;
}

.composer-input {
  flex: 1;
  padding: 9px 14px;
  border: 1px solid var(--border);
  border-radius: 22px;
  font-size: 13.5px;
  outline: none;
  background: #f8fafc;
}

.composer-input:focus {
  border-color: var(--primary);
  background: #fff;
}

/* Right: Visitor Meta Details */
.inbox-meta {
  width: 270px;
  min-width: 250px;
  background: #ffffff;
  padding: 18px;
  overflow-y: auto;
}

.meta-section {
  margin-bottom: 18px;
}

.meta-title {
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 700;
  color: var(--text-light);
  margin-bottom: 10px;
}

.meta-row {
  display: flex;
  flex-direction: column;
  margin-bottom: 8px;
}

.meta-label {
  font-size: 10.5px;
  color: var(--text-muted);
}

.meta-value {
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text-main);
  word-break: break-all;
}

/* Table Responsive Styles */
.table-responsive {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* Modal */
.modal-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.6);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  backdrop-filter: blur(3px);
  padding: 16px;
}

.modal-card {
  background: #fff;
  border-radius: var(--radius-lg);
  width: 460px;
  max-width: 100%;
  padding: 22px;
  box-shadow: var(--shadow-lg);
}

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

.form-group {
  margin-bottom: 14px;
}

.form-label {
  display: block;
  font-size: 12.5px;
  font-weight: 600;
  margin-bottom: 5px;
  color: var(--text-main);
}

.form-control {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-size: 13.5px;
  outline: none;
}

.form-control:focus {
  border-color: var(--primary);
}

/* ========================================================
   📱 Mobile Responsive Rules (Screens <= 860px)
   ======================================================== */
@media (max-width: 860px) {
  body {
    padding-bottom: 60px; /* Space for bottom nav */
  }

  .app-container {
    height: calc(100vh - 56px - 60px);
    height: calc(100dvh - 56px - 60px);
  }

  .app-navbar {
    height: 56px;
    padding: 0 14px;
  }

  .nav-center {
    display: none; /* Hidden on mobile; using bottom nav */
  }

  .mobile-bottom-nav {
    display: flex;
  }

  .agent-profile {
    display: none; /* Hide name text to save space */
  }

  .brand-badge {
    display: none;
  }

  /* Inbox on Mobile */
  .inbox-meta {
    display: none; /* Hide side panel on mobile */
  }

  .inbox-sidebar {
    width: 100%;
    min-width: 100%;
    border-right: none;
  }

  .inbox-chat {
    width: 100%;
    min-width: 100%;
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    z-index: 10;
  }

  .inbox-chat.mobile-hidden {
    display: none !important;
  }

  .inbox-sidebar.mobile-hidden {
    display: none !important;
  }

  #mobile-back-btn {
    display: inline-flex !important;
  }

  .chat-header {
    padding: 8px 12px;
  }

  .chat-composer {
    padding: 8px 10px;
  }

  .chat-bubble-agent, .chat-bubble-visitor {
    max-width: 88%;
  }

  /* Page Containers on Mobile */
  .page-container {
    padding: 16px !important;
  }
}
