:root {
  --bg-dark: #090D16;
  --bg-card: #111827;
  --bg-card-subtle: #162032;
  --bg-card-hover: #1E293B;
  --border-subtle: rgba(255, 255, 255, 0.08);
  --border-focus: #06B6D4;
  --text-main: #F8FAFC;
  --text-muted: #94A3B8;
  --text-dim: #64748B;
  --primary: #0EA5E9;
  --primary-glow: rgba(14, 165, 233, 0.25);
  --accent-cyan: #06B6D4;
  --accent-green: #10B981;
  --accent-purple: #8B5CF6;
  --accent-orange: #F59E0B;
  --font-heading: 'Outfit', sans-serif;
  --font-body: 'Plus Jakarta Sans', sans-serif;
}

body.light-theme {
  --bg-dark: #F8FAFC;
  --bg-card: #FFFFFF;
  --bg-card-subtle: #F1F5F9;
  --bg-card-hover: #E2E8F0;
  --border-subtle: rgba(0, 0, 0, 0.08);
  --border-focus: #0EA5E9;
  --text-main: #0F172A;
  --text-muted: #64748B;
  --text-dim: #94A3B8;
  --primary: #0284C7;
  --primary-glow: rgba(2, 132, 199, 0.25);
  --accent-cyan: #0EA5E9;
  --accent-green: #059669;
}

/* Theme Toggle */
.theme-toggle {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  color: var(--text-muted);
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.3s ease;
}
.theme-toggle:hover {
  background: var(--bg-card-hover);
  color: var(--text-main);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}
.theme-toggle svg {
  width: 20px;
  height: 20px;
}
body:not(.light-theme) .icon-sun { display: block; }
body:not(.light-theme) .icon-moon { display: none; }
body.light-theme .icon-sun { display: none; }
body.light-theme .icon-moon { display: block; }

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

body {
  background-color: var(--bg-dark);
  color: var(--text-main);
  font-family: var(--font-body);
  overflow-x: hidden;
  height: 100vh;
}

/* Layout */
.app-layout {
  display: flex;
  height: 100vh;
  width: 100vw;
  overflow: hidden;
}

/* Sidebar */
.main-sidebar {
  width: 270px;
  min-width: 270px;
  background: #0D1322;
  border-right: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  padding: 24px 16px;
  user-select: none;
}

.brand-area {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 24px;
  padding-left: 8px;
}

.brand-logo-glow {
  width: 40px;
  height: 40px;
  background: linear-gradient(135deg, #0EA5E9, #06B6D4);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  box-shadow: 0 4px 16px var(--primary-glow);
}

.brand-icon {
  width: 24px;
  height: 24px;
}

.brand-title {
  font-family: var(--font-heading);
  font-size: 20px;
  font-weight: 800;
  letter-spacing: 1px;
  background: linear-gradient(90deg, #FFFFFF, #38BDF8);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  display: block;
}

.brand-subtitle {
  font-size: 11px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 600;
}

/* Tenant Card */
.tenant-card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  padding: 12px 14px;
  border-radius: 14px;
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 24px;
}

.tenant-avatar {
  width: 36px;
  height: 36px;
  background: linear-gradient(135deg, #10B981, #059669);
  color: white;
  font-weight: 800;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
}

.tenant-name {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-main);
  line-height: 1.2;
}

.tenant-badge {
  font-size: 10px;
  color: #34D399;
  text-transform: uppercase;
  font-weight: 600;
  margin-top: 2px;
}

/* Nav Menu */
.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
}

.nav-item {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-family: var(--font-body);
  font-size: 14px;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.2s ease;
  position: relative;
  text-align: left;
  width: 100%;
}

.nav-item:hover {
  background: var(--bg-card-hover);
  color: var(--text-main);
}

.nav-item.active {
  background: linear-gradient(90deg, rgba(14, 165, 233, 0.15), rgba(6, 182, 212, 0.05));
  color: #38BDF8;
  border: 1px solid rgba(14, 165, 233, 0.3);
  font-weight: 600;
}

.nav-badge {
  margin-left: auto;
  background: #0284C7;
  color: white;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 20px;
}

.pulse-dot {
  margin-left: auto;
  width: 8px;
  height: 8px;
  background-color: #10B981;
  border-radius: 50%;
  box-shadow: 0 0 8px #10B981;
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0% { transform: scale(0.95); opacity: 0.8; }
  50% { transform: scale(1.2); opacity: 1; }
  100% { transform: scale(0.95); opacity: 0.8; }
}

.sidebar-footer {
  margin-top: auto;
}

.engine-status-box {
  background: #080C14;
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
  padding: 12px;
}

.status-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}

.status-indicator {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #10B981;
}

.status-title {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-main);
}

.status-caption {
  font-size: 10px;
  color: var(--text-dim);
}

/* Main Content */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow-y: auto;
}

.app-header {
  height: 70px;
  min-height: 70px;
  padding: 0 32px;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(13, 19, 34, 0.6);
  backdrop-filter: blur(12px);
  position: sticky;
  top: 0;
  z-index: 10;
}

.page-title {
  font-family: var(--font-heading);
  font-size: 19px;
  font-weight: 700;
  color: var(--text-main);
}

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

.header-actions {
  display: flex;
  align-items: center;
  gap: 16px;
}

.connection-status {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-muted);
  background: var(--bg-card);
  padding: 6px 14px;
  border-radius: 20px;
  border: 1px solid var(--border-subtle);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.status-dot.green {
  background: #10B981;
  box-shadow: 0 0 8px #10B981;
}

.btn-outline {
  border: 1px solid var(--border-subtle);
  background: transparent;
  color: var(--text-muted);
  font-size: 13px;
  padding: 7px 14px;
  border-radius: 10px;
  cursor: pointer;
  text-decoration: none;
  transition: all 0.2s;
}

.btn-outline:hover {
  background: var(--bg-card-hover);
  color: var(--text-main);
  border-color: #38BDF8;
}

/* Tab Panes */
.tab-pane {
  display: none;
  flex: 1;
  overflow-y: auto;
}

.tab-pane.active {
  display: flex;
  flex-direction: column;
}

/* TAB 1: Inbox Layout */
.inbox-layout {
  display: flex;
  flex: 1;
  height: calc(100vh - 70px);
  overflow: hidden;
}

.chats-sidebar {
  width: 320px;
  min-width: 320px;
  border-right: 1px solid var(--border-subtle);
  background: #0A0F1D;
  display: flex;
  flex-direction: column;
}

.chats-search-box {
  padding: 16px;
  border-bottom: 1px solid var(--border-subtle);
}

.chats-search-box input {
  width: 100%;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  color: var(--text-main);
  padding: 10px 14px;
  border-radius: 10px;
  font-size: 13px;
  outline: none;
}

.chats-search-box input:focus {
  border-color: var(--primary);
}

.chats-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}

.chat-card {
  padding: 12px 14px;
  border-radius: 12px;
  background: transparent;
  cursor: pointer;
  transition: all 0.2s;
  border: 1px solid transparent;
  margin-bottom: 6px;
}

.chat-card:hover {
  background: var(--bg-card);
}

.chat-card.active {
  background: var(--bg-card);
  border-color: rgba(14, 165, 233, 0.4);
}

.chat-card-header {
  display: flex;
  justify-content: space-between;
  margin-bottom: 4px;
}

.chat-name {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-main);
}

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

.chat-card-preview {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 8px;
}

.chat-card-footer {
  display: flex;
  gap: 6px;
}

.badge {
  font-size: 10px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 6px;
  text-transform: uppercase;
}

.badge-primary { background: rgba(14, 165, 233, 0.2); color: #38BDF8; }
.badge-bot { background: rgba(16, 185, 129, 0.2); color: #34D399; }
.badge-human { background: rgba(245, 158, 11, 0.2); color: #FBBF24; }
.badge-purple { background: rgba(139, 92, 246, 0.2); color: #C084FC; }
.badge-orange { background: rgba(249, 115, 22, 0.2); color: #FB923C; }
.badge-success { background: #065F46; color: #34D399; font-size: 12px; padding: 6px 14px; border-radius: 20px; }

/* Active Chat Window */
.chat-window {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: #0B101E;
}

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

.chat-contact-meta {
  display: flex;
  align-items: center;
  gap: 14px;
}

.contact-avatar {
  width: 42px;
  height: 42px;
  background: linear-gradient(135deg, #0284C7, #0369A1);
  color: white;
  font-weight: 700;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
}

.contact-name {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-main);
}

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

.highlight-dept {
  color: #38BDF8;
}

.btn-toggle-bot {
  background: #111827;
  border: 1px solid rgba(16, 185, 129, 0.4);
  color: #34D399;
  padding: 8px 16px;
  border-radius: 10px;
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: all 0.2s;
}

.btn-toggle-bot.human-mode {
  border-color: rgba(245, 158, 11, 0.6);
  color: #FBBF24;
  background: rgba(245, 158, 11, 0.1);
}

/* Quick Scenarios Bar */
.quick-scenarios-bar {
  background: #0F172A;
  padding: 10px 20px;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  gap: 8px;
  overflow-x: auto;
}

.scenarios-label {
  font-size: 11px;
  font-weight: 700;
  color: #94A3B8;
  white-space: nowrap;
}

.quick-btn {
  background: var(--bg-card);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: var(--text-main);
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.2s;
}

.quick-btn:hover {
  background: #1E293B;
  border-color: #38BDF8;
  color: #38BDF8;
}

/* Messages Stream */
.messages-stream {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.msg-row {
  display: flex;
  flex-direction: column;
  max-width: 75%;
}

.msg-row.user {
  align-self: flex-end;
}

.msg-row.bot {
  align-self: flex-start;
}

.msg-sender {
  font-size: 11px;
  font-weight: 600;
  margin-bottom: 4px;
  color: var(--text-dim);
}

.msg-row.user .msg-sender {
  text-align: right;
  color: #38BDF8;
}

.msg-bubble {
  padding: 14px 18px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
}

.msg-row.user .msg-bubble {
  background: #0284C7;
  color: white;
  border-bottom-right-radius: 4px;
}

.msg-row.bot .msg-bubble {
  background: #162032;
  color: var(--text-main);
  border: 1px solid var(--border-subtle);
  border-bottom-left-radius: 4px;
}

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

.msg-row.user .msg-time {
  text-align: right;
}

/* Chat Input Bar */
.chat-input-bar {
  padding: 16px 24px;
  background: #0E1526;
  border-top: 1px solid var(--border-subtle);
  display: flex;
  gap: 12px;
}

.chat-input-bar input {
  flex: 1;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  color: var(--text-main);
  padding: 12px 18px;
  border-radius: 12px;
  font-size: 14px;
  outline: none;
  font-family: var(--font-body);
}

.chat-input-bar input:focus {
  border-color: #0EA5E9;
  box-shadow: 0 0 10px rgba(14, 165, 233, 0.2);
}

.btn-send {
  background: linear-gradient(135deg, #0EA5E9, #0284C7);
  border: none;
  color: white;
  padding: 0 24px;
  border-radius: 12px;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: all 0.2s;
}

.btn-send:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(14, 165, 233, 0.4);
}

/* TAB 2: Catalog Grid */
.catalog-header {
  padding: 32px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--border-subtle);
}

.catalog-header h2 {
  font-family: var(--font-heading);
  font-size: 22px;
  margin-bottom: 4px;
}

.catalog-header p {
  color: var(--text-muted);
  font-size: 14px;
}

.products-grid {
  padding: 32px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 24px;
}

.product-card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: 18px;
  overflow: hidden;
  transition: all 0.3s;
  display: flex;
  flex-direction: column;
}

.product-card:hover {
  transform: translateY(-4px);
  border-color: rgba(14, 165, 233, 0.4);
  box-shadow: 0 12px 24px rgba(0, 0, 0, 0.4);
}

.product-image-container {
  height: 200px;
  background: #182235;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  position: relative;
}

.product-img {
  max-width: 90%;
  max-height: 90%;
  object-fit: contain;
}

.product-body {
  padding: 20px;
  flex: 1;
  display: flex;
  flex-direction: column;
}

.product-category {
  font-size: 11px;
  color: #38BDF8;
  text-transform: uppercase;
  font-weight: 700;
  letter-spacing: 0.5px;
  margin-bottom: 6px;
}

.product-name {
  font-size: 17px;
  font-weight: 700;
  color: var(--text-main);
  margin-bottom: 8px;
  line-height: 1.3;
}

.product-price {
  font-size: 20px;
  font-weight: 800;
  color: #34D399;
  margin-bottom: 12px;
}

.product-specs {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.6;
  margin-bottom: 16px;
  flex: 1;
}

.spec-line {
  margin-bottom: 4px;
}

.spec-line b {
  color: var(--text-main);
}

/* TAB 3: Routing Matrix */
.routing-grid {
  padding: 32px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 24px;
}

.routing-card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: 18px;
  padding: 24px;
  position: relative;
}

.routing-icon {
  width: 48px;
  height: 48px;
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  margin-bottom: 16px;
}

.routing-icon.blue { background: rgba(14, 165, 233, 0.15); color: #38BDF8; }
.routing-icon.purple { background: rgba(139, 92, 246, 0.15); color: #C084FC; }
.routing-icon.orange { background: rgba(249, 115, 22, 0.15); color: #FB923C; }

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

.routing-header h3 {
  font-size: 17px;
  font-weight: 700;
}

.routing-desc {
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.5;
  margin-bottom: 20px;
}

.routing-phone {
  background: #090E1A;
  padding: 12px 16px;
  border-radius: 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
  margin-bottom: 14px;
  border: 1px solid var(--border-subtle);
}

.routing-phone b {
  color: #38BDF8;
}

.routing-action-preview {
  font-size: 12px;
  color: var(--text-dim);
  line-height: 1.4;
}

/* TAB 4: Crawler */
.crawler-box {
  padding: 32px;
  max-width: 900px;
}

.crawler-form {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: 18px;
  padding: 28px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  margin-bottom: 30px;
}

.input-group label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--text-main);
}

.input-group input {
  width: 100%;
  background: #090E1A;
  border: 1px solid var(--border-subtle);
  color: var(--text-main);
  padding: 12px 16px;
  border-radius: 10px;
  font-size: 14px;
  outline: none;
}

.input-group input:focus {
  border-color: #0EA5E9;
}

.btn-primary {
  background: linear-gradient(135deg, #0EA5E9, #0284C7);
  border: none;
  color: white;
  padding: 14px 24px;
  border-radius: 12px;
  font-weight: 700;
  font-size: 15px;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: all 0.2s;
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 20px rgba(14, 165, 233, 0.4);
}

.crawler-result-area {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: 18px;
  padding: 28px;
}

.crawler-result-title {
  font-size: 20px;
  font-weight: 700;
  color: #38BDF8;
  margin-bottom: 16px;
}

.diagnosis-box {
  background: #0A0F1D;
  border: 1px solid rgba(245, 158, 11, 0.3);
  padding: 18px;
  border-radius: 12px;
  margin: 18px 0;
}

.diagnosis-title {
  color: #FBBF24;
  font-weight: 700;
  margin-bottom: 10px;
  font-size: 14px;
}

.diagnosis-list {
  padding-left: 20px;
  font-size: 13px;
  line-height: 1.8;
  color: var(--text-main);
}

/* TAB 5: QR Management */
.qr-management-card {
  padding: 40px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 40px;
  max-width: 1100px;
}

.qr-info-side h2 {
  font-family: var(--font-heading);
  font-size: 24px;
  margin-bottom: 12px;
}

.qr-info-side p {
  color: var(--text-muted);
  line-height: 1.6;
  margin-bottom: 20px;
}

.qr-steps {
  padding-left: 20px;
  line-height: 2;
  font-size: 14px;
  color: var(--text-main);
  margin-bottom: 24px;
}

.qr-specs {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.spec-chip {
  background: rgba(16, 185, 129, 0.1);
  color: #34D399;
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  border: 1px solid rgba(16, 185, 129, 0.2);
}

.qr-display-side {
  display: flex;
  align-items: center;
  justify-content: center;
}

.qr-frame-box {
  width: 100%;
  height: 480px;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: 20px;
  overflow: hidden;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.5);
}

.qr-iframe {
  width: 100%;
  height: 100%;
  border: none;
}
