/* ===== Variables & Tokens ===== */
:root {
  --brand-primary: #1565c0;
  --brand-dark: #0d47a1;
  --brand-gradient: linear-gradient(135deg, var(--brand-primary), var(--brand-dark));
  --bot-bg: #e8e8e8;
  --bot-text: #333;
  --error-bg: #ffebee;
  --error-text: #c62828;

  /* Surfaces */
  --bg-body: #f5f5f5;
  --bg-card: #ffffff;
  --bg-hover: #f8f9fa;
  --bg-input: #ffffff;
  --border-color: #ddd;
  --border-light: #eee;

  /* Text */
  --text-primary: #333;
  --text-secondary: #555;
  --text-muted: #888;
  --text-on-brand: #ffffff;

  /* Typography scale */
  --heading-lg: 1.4rem;
  --heading-md: 1.1rem;
  --heading-sm: 0.95rem;
  --text-base: 0.9rem;
  --text-sm: 0.85rem;
  --text-xs: 0.75rem;

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

  /* Radii & shadows */
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-pill: 24px;
  --shadow-card: 0 1px 3px rgba(0,0,0,0.1);
  --shadow-modal: 0 4px 20px rgba(0,0,0,0.2);
  --shadow-fab: 0 2px 8px rgba(0,0,0,0.2);
}

/* ===== Dark mode ===== */
@media (prefers-color-scheme: dark) {
  :root {
    --bg-body: #1a1a1a;
    --bg-card: #2a2a2a;
    --bg-hover: #333;
    --bg-input: #333;
    --border-color: #444;
    --border-light: #3a3a3a;
    --text-primary: #e0e0e0;
    --text-secondary: #bbb;
    --text-muted: #888;
    --bot-bg: #3a3a3a;
    --bot-text: #e0e0e0;
    --error-bg: #4a1c1c;
    --error-text: #ef9a9a;
    --shadow-card: 0 1px 3px rgba(0,0,0,0.3);
    --shadow-modal: 0 4px 20px rgba(0,0,0,0.5);
  }
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg-body);
  color: var(--text-primary);
  height: 100vh;
  display: flex;
  flex-direction: column;
}

body.page-layout {
  display: block;
  height: auto;
}

/* ===== Utilities ===== */
.hidden { display: none !important; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.section-heading {
  font-size: var(--heading-sm);
  margin-bottom: var(--space-sm);
  margin-top: var(--space-md);
}

.section-heading:first-child { margin-top: 0; }

.table-mb { margin-bottom: var(--space-lg); }

/* ===== Focus & accessibility ===== */
:focus-visible {
  outline: 2px solid var(--brand-primary);
  outline-offset: 2px;
}

button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--brand-primary);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ===== Site header ===== */
.site-header {
  background: var(--brand-gradient);
  color: var(--text-on-brand);
  padding: var(--space-md) var(--space-lg);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-shrink: 0;
  gap: var(--space-md);
}

.site-header__brand {
  font-size: var(--heading-lg);
  font-weight: 600;
  white-space: nowrap;
}

.site-header__subtitle {
  font-size: var(--text-sm);
  opacity: 0.85;
}

.header-phone {
  color: white;
  text-decoration: none;
  font-weight: 600;
}

.header-phone:hover { text-decoration: underline; }

/* ===== Site nav (primary navigation links) ===== */
.site-nav {
  display: flex;
  gap: var(--space-xs);
  align-items: center;
  flex-wrap: wrap;
}

.site-nav a {
  color: rgba(255, 255, 255, 0.75);
  text-decoration: none;
  font-size: var(--text-sm);
  padding: var(--space-xs) var(--space-sm);
  border-radius: var(--radius-sm);
  transition: all 0.15s;
  white-space: nowrap;
}

.site-nav a:hover {
  color: white;
  background: rgba(255, 255, 255, 0.15);
}

.site-nav a[aria-current="page"] {
  color: white;
  background: rgba(255, 255, 255, 0.2);
  font-weight: 600;
}

.site-nav .nav-sep {
  color: rgba(255, 255, 255, 0.3);
  font-size: var(--text-xs);
  user-select: none;
}

/* Dark variant (for use outside gradient headers) */
.site-nav--dark a { color: var(--brand-primary); }
.site-nav--dark a:hover { color: var(--brand-dark); background: var(--bg-hover); }
.site-nav--dark .nav-sep { color: var(--text-muted); }

/* ===== Tenant sub-nav ===== */
.tenant-nav {
  background: #222;
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 0 var(--space-md);
  height: 36px;
  overflow-x: auto;
  flex-shrink: 0;
}

.tenant-nav a {
  color: rgba(255, 255, 255, 0.6);
  text-decoration: none;
  font-size: 0.78rem;
  padding: var(--space-sm) var(--space-md);
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  white-space: nowrap;
  transition: all 0.15s;
}

.tenant-nav a:hover {
  color: white;
  background: rgba(255, 255, 255, 0.1);
}

.tenant-nav a.active {
  color: white;
  background: var(--brand-primary);
}

.tenant-nav .nav-admin {
  margin-left: auto;
  color: rgba(255, 255, 255, 0.4);
  font-size: 0.72rem;
}

.tenant-nav .nav-admin:hover {
  color: rgba(255, 255, 255, 0.8);
}

/* ===== Page header (below site-header, for page title) ===== */
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--space-lg);
}

.page-header h1 {
  font-size: var(--heading-lg);
  font-weight: 600;
}

/* ===== Site footer ===== */
.site-footer {
  background: #222;
  color: rgba(255, 255, 255, 0.5);
  text-align: center;
  padding: var(--space-md) var(--space-lg);
  font-size: var(--text-xs);
  flex-shrink: 0;
  margin-top: auto;
}

.site-footer a {
  color: rgba(255, 255, 255, 0.7);
  text-decoration: none;
}

.site-footer a:hover { color: white; }

/* ===== Container ===== */
.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: var(--space-lg);
}

/* ===== Stat cards ===== */
.stats-bar {
  display: flex;
  gap: var(--space-md);
  margin-bottom: var(--space-lg);
  flex-wrap: wrap;
}

.stat-card {
  background: var(--bg-card);
  border-radius: var(--radius-md);
  padding: var(--space-md) var(--space-lg);
  box-shadow: var(--shadow-card);
  text-align: center;
  min-width: 120px;
}

.stat-card .stat-value {
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--brand-primary);
}

.stat-card .stat-value--orange { color: #e65100; }
.stat-card .stat-value--green { color: #2e7d32; }

.stat-card .stat-label {
  font-size: var(--text-xs);
  color: var(--text-muted);
  text-transform: uppercase;
  margin-top: 2px;
}

/* ===== Tables ===== */
.table-responsive {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--bg-card);
  border-radius: var(--radius-md);
  overflow: hidden;
  box-shadow: var(--shadow-card);
}

.data-table th {
  background: var(--brand-gradient);
  color: var(--text-on-brand);
  padding: 10px var(--space-md);
  text-align: left;
  font-size: 0.8rem;
  text-transform: uppercase;
  white-space: nowrap;
}

.data-table td {
  padding: 10px var(--space-md);
  border-bottom: 1px solid var(--border-light);
  font-size: var(--text-sm);
  vertical-align: top;
}

.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: var(--bg-hover); }
.data-table .query-cell { max-width: 300px; }
.data-table .response-cell { max-width: 300px; color: var(--text-muted); font-size: 0.8rem; }
.data-table .time-cell { white-space: nowrap; font-size: 0.8rem; color: var(--text-muted); }

.table-empty {
  text-align: center;
  color: var(--text-muted);
  padding: var(--space-lg);
}

/* ===== Badges ===== */
.badge {
  display: inline-block;
  padding: 2px var(--space-sm);
  border-radius: 10px;
  font-size: var(--text-xs);
  font-weight: 600;
}

.badge-active { background: #e8f5e9; color: #2e7d32; }
.badge-inactive { background: #fce4ec; color: #c62828; }
.badge-general { background: #e3f2fd; color: #1565c0; }
.badge-billing { background: #fff3e0; color: #e65100; }
.badge-appointment, .badge-appointments { background: #e8f5e9; color: #2e7d32; }
.badge-escalation { background: #fce4ec; color: #c62828; }
.badge-local { background: #f3e5f5; color: #7b1fa2; }
.badge-claude { background: #e0f2f1; color: #00695c; }
.badge-pending { background: #fff3e0; color: #e65100; }
.badge-confirmed { background: #e8f5e9; color: #2e7d32; }
.badge-cancelled { background: #fce4ec; color: #c62828; }
.badge-completed { background: #e3f2fd; color: #1565c0; }
.badge-phone { background: #ede7f6; color: #4527a0; }
.badge-chat { background: #e3f2fd; color: #1565c0; }
.badge-web { background: #e0f2f1; color: #00695c; }

@media (prefers-color-scheme: dark) {
  .badge-active { background: #1b5e20; color: #a5d6a7; }
  .badge-inactive { background: #4a1c1c; color: #ef9a9a; }
  .badge-general { background: #0d47a1; color: #90caf9; }
  .badge-billing { background: #4e2a00; color: #ffcc80; }
  .badge-appointment, .badge-appointments { background: #1b5e20; color: #a5d6a7; }
  .badge-escalation { background: #4a1c1c; color: #ef9a9a; }
  .badge-pending { background: #4e2a00; color: #ffcc80; }
  .badge-confirmed { background: #1b5e20; color: #a5d6a7; }
  .badge-cancelled { background: #4a1c1c; color: #ef9a9a; }
}

/* ===== Buttons ===== */
.btn {
  padding: 5px var(--space-md);
  border-radius: var(--radius-sm);
  border: none;
  font-size: 0.8rem;
  cursor: pointer;
  transition: opacity 0.15s;
  text-decoration: none;
  display: inline-block;
}

.btn:hover { opacity: 0.85; }
.btn-primary { background: var(--brand-primary); color: white; }
.btn-danger { background: #c62828; color: white; }
.btn-cancel { background: var(--border-color); color: var(--text-primary); }
.btn-sm { padding: 3px var(--space-sm); font-size: var(--text-xs); }

/* ===== Filters ===== */
.filter-bar {
  display: flex;
  gap: 10px;
  margin-bottom: var(--space-md);
  flex-wrap: wrap;
  align-items: center;
}

.filter-bar label {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--text-secondary);
}

.filter-bar select,
.filter-bar input,
.filter-bar button {
  padding: var(--space-sm) 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  font-size: var(--text-sm);
  background: var(--bg-input);
  color: var(--text-primary);
}

.filter-bar button {
  background: var(--brand-gradient);
  color: white;
  border: none;
  cursor: pointer;
}

/* ===== Pagination ===== */
.pagination {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin-top: var(--space-md);
  align-items: center;
}

.pagination button {
  padding: var(--space-sm) var(--space-md);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  background: var(--bg-card);
  color: var(--text-primary);
  cursor: pointer;
  font-size: var(--text-sm);
}

.pagination button:disabled { opacity: 0.4; cursor: not-allowed; }
.pagination button:not(:disabled):hover { background: var(--bg-hover); }
.pagination .page-info { font-size: var(--text-sm); color: var(--text-muted); }

/* ===== Action bar ===== */
.action-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--space-md);
}

/* ===== Login ===== */
.login-box {
  max-width: 360px;
  margin: 80px auto;
  background: var(--bg-card);
  border-radius: var(--radius-md);
  padding: var(--space-xl);
  box-shadow: var(--shadow-card);
  text-align: center;
}

.login-box h2 {
  margin-bottom: var(--space-lg);
  font-size: 1.2rem;
}

.login-box input {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  font-size: var(--heading-sm);
  margin-bottom: var(--space-md);
  outline: none;
  background: var(--bg-input);
  color: var(--text-primary);
}

.login-box input:focus { border-color: var(--brand-primary); }

.login-box button {
  width: 100%;
  padding: 10px;
  background: var(--brand-gradient);
  color: white;
  border: none;
  border-radius: var(--radius-md);
  font-size: var(--heading-sm);
  cursor: pointer;
}

.login-box .login-error {
  color: var(--error-text);
  font-size: var(--text-sm);
  margin-top: var(--space-sm);
}

/* ===== Tabs ===== */
.tabs {
  display: flex;
  gap: 0;
  margin-bottom: var(--space-lg);
  border-bottom: 2px solid var(--border-color);
  overflow-x: auto;
}

.tab-btn {
  padding: 10px var(--space-lg);
  border: none;
  background: none;
  cursor: pointer;
  font-size: var(--text-base);
  font-weight: 500;
  color: var(--text-muted);
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: all 0.15s;
  white-space: nowrap;
}

.tab-btn.active { color: var(--brand-primary); border-bottom-color: var(--brand-primary); }
.tab-btn:hover { color: var(--brand-dark); }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ===== Modal ===== */
.modal-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.modal-overlay.hidden { display: none; }

.modal {
  background: var(--bg-card);
  border-radius: var(--radius-md);
  padding: var(--space-lg);
  width: 90%;
  max-width: 500px;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: var(--shadow-modal);
}

.modal h3 { margin-bottom: var(--space-md); font-size: var(--heading-md); }

.form-group { margin-bottom: var(--space-md); }

.form-group label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: var(--space-xs);
}

.form-group label .required-mark { color: var(--error-text); }

.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: var(--space-sm) 10px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  font-size: var(--text-base);
  outline: none;
  background: var(--bg-input);
  color: var(--text-primary);
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  border-color: var(--brand-primary);
}

.form-group textarea { resize: vertical; min-height: 60px; }
.modal-actions { display: flex; gap: var(--space-sm); justify-content: flex-end; margin-top: var(--space-md); }

/* ===== Upload area ===== */
.upload-area {
  border: 2px dashed var(--border-color);
  border-radius: var(--radius-md);
  padding: var(--space-lg);
  text-align: center;
  margin-bottom: var(--space-md);
  background: var(--bg-card);
}

.upload-area input[type="file"] { margin-top: var(--space-sm); }
.upload-controls { justify-content: center; margin-top: var(--space-sm); margin-bottom: 0; }
.upload-area .upload-filename { font-size: var(--text-sm); color: var(--brand-primary); margin-top: var(--space-xs); }
.kb-summary { color: var(--text-muted); font-size: var(--text-sm); }

/* ===== Tenant selector ===== */
.tenant-selector {
  margin-bottom: var(--space-md);
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

.tenant-selector label {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--text-secondary);
}

.tenant-selector select {
  padding: var(--space-sm) 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  font-size: var(--text-sm);
  background: var(--bg-input);
  color: var(--text-primary);
}

/* ===== Skeleton loading ===== */
.skeleton-row {
  height: 40px;
  background: linear-gradient(90deg, var(--bg-hover) 25%, var(--border-light) 50%, var(--bg-hover) 75%);
  background-size: 200% 100%;
  animation: skeleton-shimmer 1.5s infinite;
  border-radius: var(--radius-sm);
  margin-bottom: var(--space-sm);
}

@keyframes skeleton-shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ===== App layout: chat + help panel ===== */
.app-layout {
  display: flex;
  flex: 1;
  width: 100%;
  overflow: hidden;
}

.chat-container {
  flex: 1;
  max-width: 800px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  height: 100%;
}

/* Chat page: site-header is used instead of a separate chat-header */

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

.message {
  max-width: 80%;
  padding: 10px 14px;
  border-radius: var(--radius-lg);
  line-height: 1.5;
  font-size: var(--heading-sm);
  word-wrap: break-word;
}

.message.bot {
  align-self: flex-start;
  background: var(--bot-bg);
  color: var(--bot-text);
  border-bottom-left-radius: var(--space-xs);
}

.message.user {
  align-self: flex-end;
  background: var(--brand-primary);
  color: white;
  border-bottom-right-radius: var(--space-xs);
}

.message.error {
  align-self: flex-start;
  background: var(--error-bg);
  color: var(--error-text);
  border-bottom-left-radius: var(--space-xs);
}

.message[role="alert"] { /* for screen readers */ }

.message.bot p { margin: 0 0 var(--space-sm) 0; }
.message.bot p:last-child { margin-bottom: 0; }
.message.bot ul, .message.bot ol { margin: var(--space-xs) 0 var(--space-sm) 20px; padding: 0; }
.message.bot li { margin-bottom: var(--space-xs); }
.message.bot strong { font-weight: 600; }
.message.bot h1, .message.bot h2, .message.bot h3 {
  font-size: 1rem;
  font-weight: 600;
  margin: var(--space-sm) 0 var(--space-xs) 0;
}
.message.bot code {
  background: rgba(0,0,0,0.06);
  padding: 1px var(--space-xs);
  border-radius: 3px;
  font-size: 0.9em;
}

.agent-tag {
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-top: var(--space-sm);
  font-style: italic;
}

/* Escalation actions */
.escalation-actions {
  display: flex;
  gap: var(--space-sm);
  margin-top: 10px;
  flex-wrap: wrap;
}

.escalation-btn {
  display: inline-block;
  padding: var(--space-sm) var(--space-md);
  border-radius: 20px;
  font-size: var(--text-sm);
  text-decoration: none;
  font-weight: 500;
  transition: opacity 0.2s;
}

.escalation-btn:hover { opacity: 0.85; }
.escalation-btn.call { background: #2e7d32; color: white; }
.escalation-btn.email { background: var(--brand-primary); color: white; }
.escalation-btn.schedule { background: #e65100; color: white; }

/* Chips */
.chips {
  padding: var(--space-sm) var(--space-md);
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-sm);
}

.chip {
  padding: var(--space-sm) var(--space-md);
  border-radius: var(--space-md);
  border: 1px solid var(--brand-primary);
  background: var(--bg-card);
  color: var(--brand-primary);
  font-size: var(--text-sm);
  cursor: pointer;
  transition: all 0.2s;
}

.chip:hover {
  background: var(--brand-primary);
  color: white;
}

/* Mic button */
.mic-btn {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 1px solid var(--border-color);
  background: var(--bg-card);
  font-size: 1.1rem;
  cursor: pointer;
  transition: all 0.2s;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.mic-btn:hover { border-color: var(--brand-primary); }

.mic-btn.recording {
  background: #c62828;
  border-color: #c62828;
  animation: mic-pulse 1.2s infinite;
}

@keyframes mic-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(198, 40, 40, 0.4); }
  50% { box-shadow: 0 0 0 8px rgba(198, 40, 40, 0); }
}

/* Input area */
.input-area {
  padding: var(--space-md);
  background: var(--bg-card);
  border-top: 1px solid var(--border-color);
  display: flex;
  gap: var(--space-sm);
}

.input-area input {
  flex: 1;
  padding: 10px 14px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-pill);
  font-size: var(--heading-sm);
  outline: none;
  background: var(--bg-input);
  color: var(--text-primary);
}

.input-area input:focus { border-color: var(--brand-primary); }

.input-area button#send-btn {
  padding: 10px 20px;
  background: var(--brand-gradient);
  color: white;
  border: none;
  border-radius: var(--radius-pill);
  font-size: var(--heading-sm);
  cursor: pointer;
  transition: opacity 0.2s;
}

.input-area button#send-btn:hover { opacity: 0.9; }
.input-area button#send-btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* Thinking animation */
.thinking {
  display: flex;
  gap: var(--space-xs);
  padding: var(--space-xs) 0;
}

.thinking span {
  width: 8px;
  height: 8px;
  background: #999;
  border-radius: 50%;
  animation: bounce 1.4s infinite ease-in-out;
}

.thinking span:nth-child(1) { animation-delay: -0.32s; }
.thinking span:nth-child(2) { animation-delay: -0.16s; }

@keyframes bounce {
  0%, 80%, 100% { transform: scale(0); }
  40% { transform: scale(1); }
}

/* ===== Help panel ===== */
.help-panel {
  width: 300px;
  background: var(--bg-card);
  border-left: 1px solid var(--border-color);
  overflow-y: auto;
  padding: 0;
  display: flex;
  flex-direction: column;
  transition: transform 0.3s ease;
}

.help-panel.hidden {
  transform: translateX(100%);
  position: absolute;
  right: 0;
  pointer-events: none;
}

.help-header {
  background: var(--brand-gradient);
  color: white;
  padding: var(--space-md);
  font-weight: 600;
  font-size: var(--heading-sm);
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  top: 0;
}

.help-toggle {
  background: none;
  border: none;
  color: white;
  font-size: 1.1rem;
  cursor: pointer;
  padding: 0 var(--space-xs);
  opacity: 0.8;
}

.help-toggle:hover { opacity: 1; }

.help-section {
  padding: var(--space-sm) var(--space-md);
  border-bottom: 1px solid var(--border-light);
}

.help-category {
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--brand-primary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: var(--space-sm);
  padding-top: var(--space-xs);
}

.help-query {
  display: block;
  width: 100%;
  text-align: left;
  padding: var(--space-sm) 10px;
  margin-bottom: var(--space-xs);
  background: var(--bg-hover);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  color: var(--text-primary);
  cursor: pointer;
  transition: all 0.15s;
  line-height: 1.3;
}

.help-query:hover {
  background: color-mix(in srgb, var(--brand-primary) 10%, white);
  border-color: var(--brand-primary);
  color: var(--brand-dark);
}

.help-query:active {
  background: var(--brand-primary);
  color: white;
}

/* Help FAB */
.help-fab {
  position: fixed;
  bottom: 20px;
  right: 20px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--brand-gradient);
  color: white;
  border: none;
  font-size: 1.2rem;
  font-weight: 700;
  cursor: pointer;
  box-shadow: var(--shadow-fab);
  display: none;
  z-index: 10;
}

.help-fab:hover { opacity: 0.9; }
.help-fab.visible { display: block; }

/* ===== FAQ page ===== */
.faq-page {
  max-width: 800px;
  margin: 0 auto;
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--bg-card);
}

/* FAQ page: site-header is used instead of a separate faq-header */

.faq-search {
  padding: var(--space-md);
  background: var(--bg-body);
  border-bottom: 1px solid var(--border-color);
}

.faq-search input {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-pill);
  font-size: var(--heading-sm);
  outline: none;
  background: var(--bg-input);
  color: var(--text-primary);
}

.faq-search input:focus { border-color: var(--brand-primary); }

.faq-content { flex: 1; padding: 0; }

.faq-section { border-bottom: 1px solid var(--border-light); }

.faq-category-header {
  background: var(--brand-primary);
  color: white;
  padding: 10px var(--space-md);
  font-size: var(--text-sm);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.faq-item { border-bottom: 1px solid var(--border-light); }
.faq-item:last-child { border-bottom: none; }

.faq-question {
  width: 100%;
  text-align: left;
  padding: 14px var(--space-md);
  background: var(--bg-card);
  border: none;
  font-size: var(--heading-sm);
  font-weight: 500;
  color: var(--text-primary);
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--space-md);
  transition: background 0.15s;
}

.faq-question:hover { background: var(--bg-hover); }

.faq-q-text { flex: 1; }

.faq-chevron {
  font-size: 0.7rem;
  color: var(--text-muted);
  transition: transform 0.2s;
  flex-shrink: 0;
}

.faq-item.open .faq-chevron { transform: rotate(180deg); }

.faq-answer {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.25s ease, padding 0.25s ease;
  padding: 0 var(--space-md);
  font-size: var(--text-base);
  line-height: 1.6;
  color: var(--text-secondary);
  background: var(--bg-hover);
}

.faq-item.open .faq-answer {
  max-height: 500px;
  padding: var(--space-md);
}

.faq-empty {
  padding: 40px var(--space-md);
  text-align: center;
  color: var(--text-muted);
  font-size: var(--heading-sm);
}

.faq-cta {
  padding: var(--space-lg) var(--space-md);
  text-align: center;
  background: var(--bg-body);
  border-top: 1px solid var(--border-color);
}

.faq-cta p {
  font-size: var(--heading-sm);
  color: var(--text-secondary);
  margin-bottom: var(--space-md);
}

.faq-cta-btn {
  display: inline-block;
  padding: 10px var(--space-lg);
  background: var(--brand-gradient);
  color: white;
  border-radius: var(--radius-pill);
  text-decoration: none;
  font-size: var(--heading-sm);
  transition: opacity 0.2s;
}

.faq-cta-btn:hover { opacity: 0.9; }

/* ===== Mobile ===== */
@media (max-width: 900px) {
  .help-panel {
    position: fixed;
    right: 0;
    top: 0;
    height: 100vh;
    z-index: 20;
    box-shadow: -2px 0 12px rgba(0,0,0,0.15);
  }

  .help-panel.hidden { transform: translateX(100%); }
  .message { max-width: 90%; }
}

@media (max-width: 768px) {
  .container { padding: var(--space-md); }

  .page-header {
    flex-direction: column;
    gap: var(--space-sm);
    align-items: flex-start;
  }

  .stats-bar { gap: var(--space-sm); }

  .stat-card {
    min-width: 90px;
    padding: var(--space-sm) var(--space-md);
  }

  .stat-card .stat-value { font-size: 1.2rem; }

  .filter-bar {
    flex-direction: column;
    align-items: stretch;
  }

  .filter-bar select,
  .filter-bar input {
    width: 100%;
  }

  .data-table td,
  .data-table th {
    padding: var(--space-sm);
    font-size: var(--text-xs);
  }

  .data-table .hide-mobile { display: none; }

  .tabs { overflow-x: auto; }
  .tab-btn { padding: var(--space-sm) var(--space-md); font-size: var(--text-sm); }

  .tenant-selector { flex-direction: column; align-items: flex-start; }

  .site-nav { flex-wrap: wrap; gap: var(--space-xs); }

  .chat-header h1, .faq-header h1 { font-size: 1.1rem; }
}
