/*
  style.css — BotDesk Shared Design System

  WHAT THIS FILE CONTAINS:
  1. CSS Custom Properties (design tokens / variables)
  2. Reset & base typography
  3. Layout: sidebar + app shell
  4. Components:
     - Buttons (primary, secondary, action variants)
     - Badges (bot, escalated, human, resolved)
     - Form inputs, labels, error states
     - Cards (conversation card)
     - Panels (conv-panel, chat-panel, info-panel)
     - Filter tabs
     - Message bubbles (contact, bot, agent)
     - Loading & empty states
  5. Page-specific: login page layout
  6. Utilities

  DESIGN TOKENS (match existing agent-inbox.html prototype):
  - Font: DM Sans (body text), DM Mono (timestamps, numbers)
  - Sidebar: dark (#1a1a2e), 64px wide
  - Accent: purple (#6c63ff)
  - Background: warm off-white (#f5f4f0)
  - Surface (cards): white (#ffffff)
  - Badge colours: bot=green, escalated=orange, human=purple, resolved=grey

  HOW TO USE:
  - All pages import this one file
  - Use CSS variables for colours — never hardcode hex values in component CSS
  - New components go in the appropriate section below
*/

/* ════════════════════════════════════════════════════
   1. CSS Custom Properties — Design Tokens
   ════════════════════════════════════════════════════ */
:root {
  /* Layout */
  --sidebar-width: 64px;

  /* Colours */
  --sidebar-bg: #1a1a2e;
  --sidebar-text: #9ca3af;
  --sidebar-text-active: #ffffff;
  --accent: #6c63ff;
  --accent-hover: #5a52e0;
  --bg: #f5f4f0;
  --surface: #ffffff;
  --border: #e5e7eb;
  --text-primary: #111827;
  --text-secondary: #6b7280;
  --text-muted: #9ca3af;

  /* Badge colours */
  --badge-bot-bg: #dcfce7;
  --badge-bot-text: #166534;
  --badge-escalated-bg: #ffedd5;
  --badge-escalated-text: #9a3412;
  --badge-human-bg: #f3e8ff;
  --badge-human-text: #6b21a8;
  --badge-resolved-bg: #f3f4f6;
  --badge-resolved-text: #4b5563;

  /* Typography */
  --font-body: 'DM Sans', sans-serif;
  --font-mono: 'DM Mono', monospace;

  /* Spacing */
  --space-xs: 4px;
  --space-sm: 8px;
  --space-md: 16px;
  --space-lg: 24px;
  --space-xl: 32px;

  /* Radius */
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-full: 9999px;

  /* Shadow */
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.07);
}

/* ════════════════════════════════════════════════════
   2. Reset & Base Typography
   ════════════════════════════════════════════════════ */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

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

/* ════════════════════════════════════════════════════
   3. App Shell Layout
   ════════════════════════════════════════════════════ */

/* Body in app shell mode (index.html) */
body:not(.login-page) {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* Sidebar */
.sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: var(--space-md) 0;
  gap: var(--space-md);
  z-index: 100;
}

.sidebar-logo {
  margin-bottom: var(--space-md);
}

.logo-icon {
  font-size: 18px;
  font-weight: 700;
  color: var(--accent);
  font-family: var(--font-mono);
  letter-spacing: -1px;
}

.sidebar-nav {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
  flex: 1;
  width: 100%;
  align-items: center;
}

.sidebar-bottom {
  width: 100%;
  display: flex;
  justify-content: center;
}

.nav-item {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  background: transparent;
  border: none;
  color: var(--sidebar-text);
  font-size: 18px;
  transition: background 0.15s, color 0.15s;
}

.nav-item:hover,
.nav-item.active {
  background: rgba(108, 99, 255, 0.15);
  color: var(--sidebar-text-active);
}

/* Main content area */
.app-main {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* ════════════════════════════════════════════════════
   4a. Inbox Layout (3 panels)
   ════════════════════════════════════════════════════ */
.inbox-layout {
  display: flex;
  height: 100%;
  overflow: hidden;
}

/* Left: Conversation list */
.conv-panel {
  width: 300px;
  min-width: 260px;
  border-right: 1px solid var(--border);
  background: var(--surface);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.conv-panel-header {
  padding: var(--space-md);
  border-bottom: 1px solid var(--border);
}

.panel-title {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: var(--space-sm);
}

.conv-search {
  width: 100%;
  padding: var(--space-sm) var(--space-md);
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  font-family: var(--font-body);
  font-size: 13px;
  background: var(--bg);
  outline: none;
}

.conv-search:focus {
  border-color: var(--accent);
}

/* Filter tabs */
.filter-tabs {
  display: flex;
  padding: var(--space-sm) var(--space-md);
  gap: var(--space-xs);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
}

.tab {
  padding: 4px 10px;
  border-radius: var(--radius-full);
  border: 1px solid var(--border);
  background: transparent;
  font-family: var(--font-body);
  font-size: 12px;
  cursor: pointer;
  color: var(--text-secondary);
  white-space: nowrap;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.tab.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

/* Conv list */
.conv-list {
  flex: 1;
  overflow-y: auto;
}

.conv-card {
  padding: var(--space-md);
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.1s;
}

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

.conv-card.active {
  background: #ede9fe; /* light accent */
  border-left: 3px solid var(--accent);
}

.conv-card-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: var(--space-xs);
}

.conv-name {
  font-weight: 600;
  font-size: 14px;
}

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

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

.conv-list-empty {
  padding: var(--space-xl);
  text-align: center;
  color: var(--text-muted);
}

/* Center: Chat panel */
.chat-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg);
}

.chat-panel-header {
  padding: var(--space-md) var(--space-lg);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

.chat-contact-name {
  font-size: 16px;
  font-weight: 600;
}

.chat-thread {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-lg);
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
}

.chat-empty-state {
  text-align: center;
  color: var(--text-muted);
  margin-top: var(--space-xl);
}

/* Message bubbles */
.message {
  display: flex;
  flex-direction: column;
  max-width: 70%;
}

.message.from-contact {
  align-self: flex-end;
}

.message.from-bot,
.message.from-agent {
  align-self: flex-start;
}

.message-bubble {
  padding: var(--space-sm) var(--space-md);
  border-radius: var(--radius-lg);
  font-size: 14px;
  line-height: 1.5;
}

.from-contact .message-bubble {
  background: var(--accent);
  color: #fff;
  border-bottom-right-radius: var(--radius-sm);
}

.from-bot .message-bubble {
  background: var(--surface);
  color: var(--text-primary);
  border-bottom-left-radius: var(--radius-sm);
  box-shadow: var(--shadow-sm);
}

.from-agent .message-bubble {
  background: #f3e8ff;
  color: var(--text-primary);
  border-bottom-left-radius: var(--radius-sm);
}

.message-meta {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-muted);
  margin-top: 2px;
}

.message-sender-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 2px;
}

/* Reply box */
.reply-box {
  padding: var(--space-md);
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  gap: var(--space-sm);
  align-items: flex-end;
}

.reply-input {
  flex: 1;
  padding: var(--space-sm) var(--space-md);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-family: var(--font-body);
  font-size: 14px;
  resize: none;
  outline: none;
  background: var(--bg);
}

.reply-input:focus {
  border-color: var(--accent);
}

.reply-input:disabled,
button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* Right: Info panel */
.info-panel {
  width: 240px;
  min-width: 220px;
  border-left: 1px solid var(--border);
  background: var(--surface);
  padding: var(--space-lg) var(--space-md);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: var(--space-lg);
}

.info-section {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
}

.info-section-title {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: var(--space-xs);
}

.info-field {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-primary);
}

.info-label {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: -4px;
  margin-bottom: var(--space-xs);
}

.refresh-status {
  font-size: 11px;
  color: var(--text-muted);
  font-family: var(--font-mono);
  margin-top: auto;
}

/* ════════════════════════════════════════════════════
   4b. Badges
   ════════════════════════════════════════════════════ */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: var(--radius-full);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.badge-bot {
  background: var(--badge-bot-bg);
  color: var(--badge-bot-text);
}

.badge-escalated {
  background: var(--badge-escalated-bg);
  color: var(--badge-escalated-text);
}

.badge-human {
  background: var(--badge-human-bg);
  color: var(--badge-human-text);
}

.badge-resolved {
  background: var(--badge-resolved-bg);
  color: var(--badge-resolved-text);
}

/* ════════════════════════════════════════════════════
   4c. Buttons
   ════════════════════════════════════════════════════ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-sm) var(--space-md);
  border-radius: var(--radius-md);
  border: none;
  font-family: var(--font-body);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, opacity 0.15s;
}

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

.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
}

.btn-full {
  width: 100%;
}

/* Action buttons in info panel */
.btn-action {
  width: 100%;
  font-size: 13px;
  padding: 8px 12px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text-primary);
}

.btn-action:hover:not(:disabled) {
  background: var(--border);
}

.btn-bot {
  border-color: var(--badge-bot-text);
  color: var(--badge-bot-text);
}

.btn-escalate {
  border-color: var(--badge-escalated-text);
  color: var(--badge-escalated-text);
}

.btn-resolve {
  border-color: var(--text-secondary);
  color: var(--text-secondary);
}

/* ════════════════════════════════════════════════════
   4d. Form Inputs (Login page)
   ════════════════════════════════════════════════════ */
.form-group {
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
}

.form-group label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
}

.form-group input {
  padding: var(--space-sm) var(--space-md);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-family: var(--font-body);
  font-size: 14px;
  background: var(--bg);
  outline: none;
  transition: border-color 0.15s;
}

.form-group input:focus {
  border-color: var(--accent);
}

.error-message {
  background: #fef2f2;
  color: #dc2626;
  padding: var(--space-sm) var(--space-md);
  border-radius: var(--radius-md);
  font-size: 13px;
  border: 1px solid #fecaca;
}

/* ════════════════════════════════════════════════════
   5. Login Page Layout
   ════════════════════════════════════════════════════ */
body.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: var(--bg);
}

.login-card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  padding: var(--space-xl);
  width: 100%;
  max-width: 400px;
  display: flex;
  flex-direction: column;
  gap: var(--space-lg);
}

.login-logo {
  text-align: center;
}

.logo-text {
  font-size: 28px;
  font-weight: 700;
  color: var(--accent);
  font-family: var(--font-mono);
  letter-spacing: -1px;
}

.login-subtitle {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: var(--space-xs);
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
}

/* ════════════════════════════════════════════════════
   6. Loading & Empty States
   ════════════════════════════════════════════════════ */
.loading-state {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text-muted);
  font-size: 14px;
}

/* ════════════════════════════════════════════════════
   7. Scrollbar Styling (optional — webkit only)
   ════════════════════════════════════════════════════ */
::-webkit-scrollbar {
  width: 4px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: var(--radius-full);
}
