/* Bridge: embed CrystalKB hub UI inside Tickets without hijacking app chrome */

body:has(.tickets-app),
body:has(.shell-auth) {
  background: var(--bg);
  color: var(--text);
}

body[data-theme="dark"] {
  --kb-text: #e8edf7;
  --kb-text-secondary: #b4c0d4;
  --kb-text-muted: #97a5bc;
  --kb-accent: #3b82f6;
  --kb-accent-soft: rgba(59, 130, 246, 0.16);
  --kb-border: #1e2533;
  --kb-bg: #151a24;
  --kb-bg-soft: #1c2331;
  --kb-danger: #f07178;
  --kb-shadow-menu: 0 12px 32px rgba(0, 0, 0, 0.35);
  --kb-shadow-modal: 0 24px 56px rgba(0, 0, 0, 0.45);
  --text: var(--kb-text);
  --text-soft: var(--kb-text-secondary);
  --panel: var(--kb-bg);
  --panel-strong: var(--kb-bg-soft);
  --line: var(--kb-border);
}

/* Legacy styles.css hardcodes dark-on-light tree colors (#33475b / #97a6b6). */
body[data-theme="dark"] .knowledge-sidebar .knowledge-tree-folder,
body[data-theme="dark"] .knowledge-sidebar .knowledge-tree-document,
body[data-theme="dark"] .knowledge-sidebar .knowledge-tree-label {
  color: #d7dfec;
}

body[data-theme="dark"] .knowledge-sidebar .knowledge-tree-folder.active,
body[data-theme="dark"] .knowledge-sidebar .knowledge-tree-document.active,
body[data-theme="dark"] .knowledge-sidebar .knowledge-tree-folder.active .knowledge-tree-label,
body[data-theme="dark"] .knowledge-sidebar .knowledge-tree-document.active .knowledge-tree-label {
  color: #9ec1ff;
}

body[data-theme="dark"] .knowledge-sidebar .knowledge-tree-icon,
body[data-theme="dark"] .knowledge-sidebar .knowledge-tree-toggle,
body[data-theme="dark"] .knowledge-sidebar .knowledge-storage-meta,
body[data-theme="dark"] .knowledge-sidebar .knowledge-storage-link,
body[data-theme="dark"] .knowledge-sidebar .knowledge-sidebar-footer-text {
  color: var(--kb-text-secondary);
}

/* Document/editor surfaces must follow theme tokens (kb.css hardcodes #fff). */
body[data-theme="dark"] .knowledge-document-body,
body[data-theme="dark"] .knowledge-document-content,
body[data-theme="dark"] .knowledge-editor-shell,
body[data-theme="dark"] .knowledge-editor-shell .tox .tox-edit-area__iframe {
  background: var(--kb-bg) !important;
  color: var(--kb-text);
  box-shadow: none;
}

body[data-theme="dark"] .knowledge-document-content,
body[data-theme="dark"] .knowledge-document-content p,
body[data-theme="dark"] .knowledge-document-content li,
body[data-theme="dark"] .knowledge-document-content h1,
body[data-theme="dark"] .knowledge-document-content h2,
body[data-theme="dark"] .knowledge-document-content h3,
body[data-theme="dark"] .knowledge-document-content h4,
body[data-theme="dark"] .knowledge-document-content td,
body[data-theme="dark"] .knowledge-document-content th,
body[data-theme="dark"] .knowledge-document-content blockquote,
body[data-theme="dark"] .knowledge-editor-textarea {
  color: var(--kb-text);
}

body[data-theme="dark"] .knowledge-document-content a,
body[data-theme="dark"] .knowledge-document-content .knowledge-inline-document-link {
  color: #7eb6ff;
}

body[data-theme="dark"] .knowledge-document-content th {
  background: var(--kb-bg-soft);
}

body[data-theme="dark"] .knowledge-document-content td,
body[data-theme="dark"] .knowledge-document-content th {
  border-color: var(--kb-border);
}

body[data-theme="dark"] .knowledge-document-content blockquote {
  border-left-color: #5b6b84;
  color: var(--kb-text-secondary);
}

body[data-theme="dark"] .knowledge-editor-shell .tox .tox-toolbar,
body[data-theme="dark"] .knowledge-editor-shell .tox .tox-toolbar__primary,
body[data-theme="dark"] .knowledge-editor-shell .tox .tox-editor-header {
  background: var(--kb-bg-soft) !important;
  box-shadow: none;
}

body[data-theme="dark"] .knowledge-table tbody tr:hover td,
body[data-theme="dark"] .knowledge-grid-card:hover,
body[data-theme="dark"] .knowledge-obj-icon--folder {
  background: var(--kb-bg-soft);
}

body[data-theme="dark"] .knowledge-obj-icon--folder {
  color: var(--kb-accent);
}

body[data-theme="dark"] .knowledge-obj-icon--file {
  background: rgba(99, 102, 241, 0.18);
  color: #a5b4fc;
}

body[data-theme="dark"] .knowledge-empty-state,
body[data-theme="dark"] .knowledge-callout--info,
body[data-theme="dark"] .knowledge-callout--success,
body[data-theme="dark"] .knowledge-callout--danger,
body[data-theme="dark"] .knowledge-callout--warning {
  color: var(--kb-text);
}

body[data-theme="dark"] .knowledge-callout--info {
  background: rgba(59, 130, 246, 0.12);
  border-color: rgba(59, 130, 246, 0.28);
}

body[data-theme="dark"] .knowledge-callout--success {
  background: rgba(34, 197, 94, 0.12);
  border-color: rgba(34, 197, 94, 0.28);
}

body[data-theme="dark"] .knowledge-callout--danger {
  background: rgba(240, 113, 120, 0.12);
  border-color: rgba(240, 113, 120, 0.28);
}

body[data-theme="dark"] .knowledge-callout--warning {
  background: rgba(245, 158, 11, 0.12);
  border-color: rgba(245, 158, 11, 0.28);
}

.tickets-app .primary {
  border: 0;
  background: var(--accent);
  color: var(--on-accent);
}

.tickets-app .primary:hover {
  filter: brightness(1.05);
}

.tickets-app .secondary {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
}

.tickets-app .secondary:hover {
  background: var(--panel-strong);
}

.tickets-app .knowledge-layout .primary {
  background: var(--kb-accent);
  color: #fff;
}

.tickets-app .knowledge-layout .primary:hover {
  background: #0f68e8;
  filter: none;
}

.tickets-app .knowledge-layout .secondary {
  border: 1px solid var(--kb-border);
  background: var(--kb-bg);
  color: var(--kb-text);
}

.tickets-app .knowledge-layout .secondary:hover {
  background: var(--kb-bg-soft);
}

.support-app-panel .support-modal-body:has(.knowledge-layout) {
  padding: 0;
  overflow: hidden;
  display: block;
  align-content: stretch;
  gap: 0;
}

.support-app-panel .support-modal-body > .knowledge-layout {
  height: 100%;
  min-height: 0;
  border: 1px solid var(--kb-border);
  border-radius: var(--kb-radius-lg, 12px);
  overflow: hidden;
}

/* Neutralize legacy light-theme card borders from styles.css */
.tickets-app .knowledge-sidebar,
.tickets-app .knowledge-content {
  border: 0;
  border-radius: 0;
  box-shadow: none;
  background: var(--kb-bg);
}

.tickets-app .knowledge-sidebar {
  border-right: 1px solid var(--kb-border);
}

body[data-theme="dark"] .support-app-panel .support-modal-body > .knowledge-layout,
body[data-theme="dark"] .tickets-app .knowledge-sidebar,
body[data-theme="dark"] .tickets-app .knowledge-content,
body[data-theme="dark"] .tickets-app .knowledge-details,
body[data-theme="dark"] .tickets-app .knowledge-storage-card,
body[data-theme="dark"] .tickets-app .knowledge-panel-toggle {
  border-color: var(--kb-border);
}

body[data-theme="dark"] .tickets-app .knowledge-storage-bar {
  background: #222938;
}

.support-profile-overlay {
  background: rgba(15, 23, 42, 0.28);
  backdrop-filter: blur(5px);
}

.support-profile-modal {
  width: min(100%, 560px);
  max-height: 90vh;
  padding: 0;
  border-radius: 16px;
  overflow: hidden;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 0;
}

.support-profile-header {
  align-items: flex-start;
  padding: 20px 22px 14px;
  border-bottom: 1px solid var(--line);
}

.support-profile-header h3 {
  font-size: 20px;
  font-weight: 700;
}

.support-profile-subtitle {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 400;
}

.support-profile-close {
  border: 0;
  border-radius: 8px;
  background: var(--panel-strong);
  color: var(--muted);
}

.support-profile-form {
  min-height: 0;
  overflow: auto;
  padding: 18px 22px 22px;
  gap: 18px;
}

.support-profile-section {
  display: grid;
  gap: 12px;
}

.support-profile-section-title {
  margin: 0;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--muted);
}
