:root {
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  background-color: #f5f6f8;
  color: #111827;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  padding: 0;
  background-color: #f5f6f8;
  overflow: hidden;
}

.visually-hidden {
  border: 0;
  clip: rect(0 0 0 0);
  height: 1px;
  margin: -1px;
  overflow: hidden;
  padding: 0;
  position: absolute;
  width: 1px;
}

a {
  color: inherit;
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

button {
  cursor: pointer;
  font: inherit;
}

.app-shell {
  display: flex;
  height: 100vh;
}

.sidebar {
  width: 320px;
  background: #ffffff;
  border-right: 1px solid rgba(15, 23, 42, 0.08);
  display: flex;
  flex-direction: column;
  height: 100%;
}

.sidebar-header {
  padding: 1.25rem;
  border-bottom: 1px solid rgba(15, 23, 42, 0.06);
  font-weight: 600;
  font-size: 1.1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.sidebar-links {
  display: flex;
  gap: 0.5rem;
}

.sidebar-metric {
  font-size: 0.85rem;
  color: #2563eb;
}

.sidebar-metric span {
  font-weight: 600;
}

.auth-block {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.auth-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.text-button {
  border: none;
  background: transparent;
  padding: 0;
  color: #2563eb;
  font-size: 0.85rem;
}

.muted {
  color: #6b7280;
  font-size: 0.8rem;
}

.filters {
  padding: 0 1.25rem 1rem;
  border-bottom: 1px solid rgba(15, 23, 42, 0.06);
}

.filters .filter-group {
  margin-bottom: 0.85rem;
}

.filters .filter-group:last-of-type {
  margin-bottom: 0;
}

.filters label {
  display: block;
  font-size: 0.8rem;
  margin-bottom: 0.35rem;
  text-transform: uppercase;
  color: #6b7280;
}

.filters select,
.filters input {
  width: 100%;
  padding: 0.4rem 0.6rem;
  border: 1px solid rgba(148, 163, 184, 0.6);
  border-radius: 0.35rem;
}

.ticket-list {
  flex: 1;
  overflow-y: auto;
}

.ticket-item {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid rgba(148, 163, 184, 0.2);
  transition: background 0.2s ease;
}

.ticket-item:hover,
.ticket-item.active {
  background: rgba(59, 130, 246, 0.08);
}

.ticket-item h3 {
  margin: 0;
  font-size: 1rem;
}

.ticket-item p {
  margin: 0.25rem 0 0;
  color: #4b5563;
  font-size: 0.85rem;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  background: rgba(37, 99, 235, 0.12);
  color: #1d4ed8;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  font-size: 0.75rem;
}

.badge--done {
  background: rgba(34, 197, 94, 0.18);
  color: #047857;
}

#ticket-placeholder,
.placeholder {
  padding: 1.5rem;
  color: #4b5563;
}

.main-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: #f5f6f8;
  height: 100%;
  overflow: hidden;
  min-height: 0;
}

#ticket-detail {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.main-header {
  padding: 1.5rem;
  border-bottom: 1px solid rgba(148, 163, 184, 0.2);
  background: #ffffff;
}

.main-header h2 {
  margin: 0;
}

.header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.75rem;
}

#ticket-status-toggle {
  white-space: nowrap;
}

.main-meta {
  display: flex;
  gap: 1.5rem;
  font-size: 0.85rem;
  color: #4b5563;
  flex-wrap: wrap;
}

.main-meta .meta-email {
  cursor: pointer;
  color: #2563eb;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.main-meta .meta-email:hover {
  text-decoration: underline;
}

.main-meta .meta-email:focus-visible {
  outline: 2px solid rgba(37, 99, 235, 0.4);
  outline-offset: 2px;
  border-radius: 0.25rem;
}

.main-meta .meta-email[data-copy-state="copied"]::after,
.main-meta .meta-email[data-copy-state="copy-error"]::after {
  margin-left: 0.35rem;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.main-meta .meta-email[data-copy-state="copied"]::after {
  content: 'Copied!';
  color: #059669;
}

.main-meta .meta-email[data-copy-state="copy-error"]::after {
  content: 'Copy failed';
  color: #dc2626;
}

.reader-container {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-height: 0;
  --reply-panel-height: clamp(260px, 40vh, 520px);
}

.content-area {
  flex: 1;
  padding: 1.5rem;
  overflow-y: auto;
  min-height: 0;
}

.reply-resize-handle {
  height: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: row-resize;
  touch-action: none;
}

.reply-resize-handle::before {
  content: '';
  width: 64px;
  height: 4px;
  border-radius: 999px;
  background: rgba(148, 163, 184, 0.7);
  transition: background-color 0.15s ease;
}

.reply-resize-handle:focus-visible::before,
.reply-resize-handle.is-dragging::before {
  background: #2563eb;
}

.reader-container.is-resizing {
  user-select: none;
  cursor: row-resize;
}

#thread {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.thread-message {
  background: #ffffff;
  border-radius: 0.75rem;
  padding: 1rem 1.25rem;
  margin-bottom: 0;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.05);
  max-width: min(85%, 1000px);
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  align-self: flex-start;
}

.thread-message .timestamp {
  color: #6b7280;
  font-size: 0.8rem;
  margin-bottom: 0.5rem;
}

.thread-message.inbound {
  border-left: 4px solid #0ea5e9;
  margin-right: auto;
}

.thread-message.outbound {
  margin-left: auto;
  align-self: flex-end;
  background: #dbeafe;
  border-right: 4px solid #2563eb;
}

.thread-message.outbound .timestamp {
  color: rgba(15, 23, 42, 0.6);
  text-align: right;
}

.thread-message.outbound .message-body,
.thread-message.outbound .message-body * {
  color: inherit;
}

.message-body > :first-child {
  margin-top: 0;
}

.message-body > :last-child {
  margin-bottom: 0;
}

@media (max-width: 900px) {
  .thread-message {
    max-width: 100%;
  }
}

.reply-panel {
  background: #ffffff;
  border-top: 1px solid rgba(148, 163, 184, 0.2);
  box-shadow: 0 -1px 2px rgba(15, 23, 42, 0.04);
  padding: 1.25rem 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  flex: 0 0 auto;
  height: var(--reply-panel-height);
  min-height: 220px;
  max-height: 80vh;
  overflow: auto;
}

.reply-panel textarea {
  width: 100%;
  min-height: 160px;
  border: 1px solid rgba(148, 163, 184, 0.6);
  border-radius: 0.5rem;
  padding: 0.75rem;
  resize: vertical;
  font: inherit;
  background: #ffffff;
}

#reply-ai-context {
  min-height: 110px;
}

.reply-field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.reply-field-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.reply-field label {
  font-weight: 600;
  color: #111827;
}

.speech-input-controls {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.speech-input-button {
  font-size: 0.8rem;
}

.speech-input-button[data-listening='true'] {
  color: #dc2626;
  font-weight: 600;
}

.speech-input-status[hidden] {
  display: none;
}

.speech-input-status {
  font-size: 0.75rem;
  line-height: 1.2;
  text-align: right;
}

.reply-field small {
  color: #6b7280;
}

.reply-training {
  border: 1px solid rgba(148, 163, 184, 0.45);
  border-radius: 0.65rem;
  padding: 0.75rem 0.9rem;
  background: #f8fafc;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.reply-training-checkbox {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 600;
  color: #111827;
}

.reply-training-checkbox input[type='checkbox'] {
  width: 1rem;
  height: 1rem;
}

.language-insights {
  border: 1px solid rgba(148, 163, 184, 0.45);
  border-radius: 0.65rem;
  background: #f8fafc;
  padding: 0.75rem 0.9rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.language-insights[hidden] {
  display: none;
}

.language-insights-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem;
}

.language-insights-header strong {
  display: block;
}

.language-insights-summary {
  margin: 0;
  color: #475569;
  font-size: 0.85rem;
}

.language-insights label {
  font-size: 0.72rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #6b7280;
}

#language-insights-translation {
  min-height: 110px;
  background: #f1f5f9;
  border-color: rgba(148, 163, 184, 0.7);
}

.reply-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem;
}

.reply-actions {
  display: flex;
  gap: 0.75rem;
  justify-content: flex-end;
  flex-wrap: wrap;
}

.placeholder {
  padding: 1.5rem;
  color: #4b5563;
}

.button {
  background: #2563eb;
  color: #ffffff;
  border: none;
  border-radius: 0.5rem;
  padding: 0.6rem 1.2rem;
  font-weight: 600;
}

.button.secondary {
  background: #e5e7eb;
  color: #111827;
}

.button.danger {
  background: #dc2626;
  color: #ffffff;
}

.auth-gate {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(
    135deg,
    rgba(59, 130, 246, 0.08),
    rgba(14, 116, 144, 0.08)
  );
  padding: 2rem;
}

.auth-card {
  background: #ffffff;
  border-radius: 1rem;
  box-shadow: 0 20px 45px rgba(15, 23, 42, 0.12);
  max-width: 420px;
  width: 100%;
  padding: 2.5rem;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

/* Knowledge base layout */

.kb-layout {
  background: #f9fafb;
  color: #111827;
}

.kb-shell {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  height: 100vh;
  overflow: hidden;
}

.kb-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1.5rem;
  padding: 1.75rem 2rem 1.5rem;
  background: #ffffff;
  border-bottom: 1px solid #e5e7eb;
}

.kb-header h1 {
  margin: 0;
  font-size: 1.75rem;
}

.kb-subtitle {
  margin: 0.4rem 0 0;
  color: #6b7280;
}

.kb-header-actions {
  display: flex;
  gap: 0.75rem;
  align-items: center;
}

.kb-grid {
  display: flex;
  flex: 1;
  min-height: 0;
  height: 100%;
  overflow: hidden;
}

.kb-sidebar {
  width: 320px;
  max-width: 100%;
  border-right: 1px solid #e5e7eb;
  background: #ffffff;
  display: flex;
  flex-direction: column;
}

.kb-sidebar-controls {
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.kb-sidebar-controls label {
  font-size: 0.85rem;
  font-weight: 600;
  color: #374151;
}

.kb-sidebar-controls input,
.kb-sidebar-controls select {
  width: 100%;
  padding: 0.5rem 0.6rem;
  border: 1px solid #d1d5db;
  border-radius: 0.5rem;
  background: #f9fafb;
}

.kb-doc-list {
  flex: 1;
  overflow-y: auto;
  padding: 0 0 0.75rem;
}

.kb-doc-item {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.25rem;
  width: 100%;
  padding: 0.9rem 1.25rem;
  border: none;
  background: transparent;
  cursor: pointer;
  text-align: left;
  border-bottom: 1px solid #f3f4f6;
  transition: background 0.15s ease;
}

.kb-doc-item:hover {
  background: #f9fafb;
}

.kb-doc-item.active {
  background: #e0ecff;
}

.kb-doc-title {
  font-weight: 600;
}

.kb-doc-meta {
  font-size: 0.78rem;
  color: #6b7280;
}

.kb-doc-empty {
  padding: 1rem 1.25rem;
  color: #6b7280;
}

.kb-editor {
  flex: 1;
  min-width: 0;
  padding: 1.75rem 2rem 2rem;
  overflow-y: auto;
}

.kb-live-feed {
  border: 1px solid rgba(148, 163, 184, 0.3);
  border-radius: 0.9rem;
  padding: 1rem 1.25rem;
  background: #f8fafc;
}

.kb-live-feed-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.kb-live-feed-head h2 {
  margin: 0;
  font-size: 1rem;
}

.kb-live-feed-list {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.kb-live-feed-item {
  border: 1px solid rgba(148, 163, 184, 0.4);
  border-radius: 0.65rem;
  padding: 0.6rem 0.75rem;
  text-align: left;
  background: #fff;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  cursor: pointer;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.kb-live-feed-item:hover {
  border-color: #2563eb;
  box-shadow: 0 2px 4px rgba(37, 99, 235, 0.12);
}

.kb-live-feed-item strong {
  font-size: 0.95rem;
  color: #111827;
}

.kb-live-feed-meta {
  font-size: 0.8rem;
  color: #6b7280;
}

.kb-live-feed-empty {
  margin: 0;
}

.kb-empty {
  color: #6b7280;
}

.kb-form {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.kb-form-row {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.kb-form-row input,
.kb-form-row textarea,
.kb-form-row select {
  border: 1px solid #d1d5db;
  border-radius: 0.6rem;
  padding: 0.6rem 0.75rem;
  font-size: 0.95rem;
  background: #ffffff;
}

.kb-two-col {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
}

.kb-two-col .kb-form-row {
  flex: 1 1 180px;
}

.kb-preview {
  border: 1px solid #e5e7eb;
  border-radius: 0.75rem;
  background: #ffffff;
  padding: 1rem;
}

.kb-preview h2 {
  margin: 0 0 0.9rem;
  font-size: 1rem;
}

.kb-preview.kb-live {
  background: #f8fafc;
  border-style: dashed;
}

.kb-live-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.kb-live-pane {
  background: #fff;
  border-radius: 0.65rem;
  padding: 0.75rem 1rem;
  box-shadow: inset 0 1px 0 rgba(15, 23, 42, 0.04);
}

.kb-preview-pane {
  min-height: 160px;
  color: #1f2937;
  font-size: 0.95rem;
  line-height: 1.55;
}

.kb-form-actions {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.kb-form-status {
  min-height: 1.25rem;
  font-size: 0.9rem;
}

.kb-form-status[data-variant='success'] {
  color: #047857;
}

.kb-form-status[data-variant='error'] {
  color: #b91c1c;
}

.kb-form-status[data-variant='info'] {
  color: #2563eb;
}

.kb-button-row {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.kb-button-row .button {
  min-width: 160px;
}

.auth-card h1 {
  margin: 0;
  font-size: 1.75rem;
}

.auth-subtitle {
  margin: 0;
  color: #4b5563;
  font-size: 0.95rem;
}

.auth-alert {
  background: rgba(220, 38, 38, 0.08);
  color: #b91c1c;
  padding: 0.75rem 1rem;
  border-radius: 0.75rem;
  font-size: 0.9rem;
}

.auth-meta {
  margin: 0;
  color: #6b7280;
  font-size: 0.8rem;
}

/* AI support channel */

.ai-layout {
  background: #f5f6f8;
  min-height: 100vh;
  overflow: hidden;
}

.ai-shell {
  height: 100vh;
  display: flex;
  flex-direction: column;
  max-width: 1200px;
  margin: 0 auto;
  padding: 1.5rem;
  box-sizing: border-box;
}

.ai-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1.5rem;
  margin-bottom: 1.25rem;
}

.ai-subtitle {
  margin: 0.35rem 0 0;
  color: #4b5563;
}

.ai-header-actions {
  display: flex;
  gap: 0.75rem;
  align-items: center;
}

.ai-panels {
  flex: 1;
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 1.25rem;
  min-height: 0;
}

.ai-conversation-panel,
.ai-task-panel {
  background: #ffffff;
  border-radius: 1rem;
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  min-height: 0;
  box-shadow: 0 10px 30px -20px rgba(15, 23, 42, 0.35);
}

.ai-panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.75rem;
}

.ai-status {
  font-size: 0.85rem;
}

.ai-conversation {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding-right: 0.5rem;
}

.ai-empty {
  border: 1px dashed rgba(148, 163, 184, 0.5);
  padding: 1rem;
  border-radius: 0.85rem;
  color: #6b7280;
  text-align: center;
}

.ai-message {
  border-radius: 0.85rem;
  padding: 0.85rem 1rem;
  background: rgba(37, 99, 235, 0.08);
}

.ai-message-user {
  background: #dbeafe;
}

.ai-message-team_leader {
  background: #ecfdf5;
}

.ai-message-header {
  display: flex;
  justify-content: space-between;
  font-size: 0.75rem;
  color: #6b7280;
  margin-bottom: 0.35rem;
}

.ai-message-body {
  margin: 0;
  white-space: pre-wrap;
  font-size: 0.95rem;
  line-height: 1.4;
}

.ai-input {
  margin-top: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.ai-input textarea {
  width: 100%;
  resize: vertical;
  min-height: 90px;
  border-radius: 0.85rem;
  border: 1px solid rgba(148, 163, 184, 0.6);
  padding: 0.85rem;
  font-size: 1rem;
  line-height: 1.4;
}

.ai-input-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.ai-task-log {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  padding-right: 0.5rem;
}

.ai-task {
  border: 1px solid rgba(148, 163, 184, 0.25);
  border-radius: 0.85rem;
  padding: 0.85rem 1rem;
  background: rgba(249, 250, 251, 0.85);
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.ai-task-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.ai-task-title {
  font-weight: 600;
}

.ai-task-status {
  font-size: 0.7rem;
  padding: 0.2rem 0.45rem;
  border-radius: 999px;
  background: rgba(34, 197, 94, 0.15);
  color: #047857;
}

.ai-task-status.status-failed,
.ai-task-status.status-blocked {
  background: rgba(248, 113, 113, 0.15);
  color: #b91c1c;
}

.ai-task-status.status-needs_human {
  background: rgba(245, 158, 11, 0.18);
  color: #b45309;
}

.ai-task-meta {
  font-size: 0.75rem;
  color: #6b7280;
}

.ai-task-details {
  display: grid;
  gap: 0.35rem;
  font-size: 0.85rem;
}

.ai-json {
  background: rgba(148, 163, 184, 0.12);
  border-radius: 0.6rem;
  padding: 0.5rem 0.75rem;
}

.ai-json summary {
  font-weight: 600;
  cursor: pointer;
}

.ai-json pre {
  margin: 0.5rem 0 0;
  font-size: 0.8rem;
  line-height: 1.4;
  white-space: pre-wrap;
  word-break: break-word;
}

.ai-debug-panel {
  margin-top: 1rem;
  border: 1px solid rgba(148, 163, 184, 0.35);
  border-radius: 0.85rem;
  padding: 0.75rem 1rem;
  background: rgba(249, 250, 251, 0.85);
}

.ai-debug-panel summary {
  font-weight: 600;
  cursor: pointer;
}

.ai-debug-log {
  margin-top: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  max-height: min(420px, 50vh);
  overflow-y: auto;
  padding-right: 0.5rem;
}

.ai-debug-entry {
  border: 1px solid rgba(148, 163, 184, 0.25);
  border-radius: 0.75rem;
  padding: 0.75rem 0.9rem;
  background: rgba(243, 244, 246, 0.7);
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.ai-debug-entry-header {
  display: flex;
  justify-content: space-between;
  font-size: 0.75rem;
  color: #6b7280;
}

.ai-debug-entry-status {
  font-weight: 600;
  font-size: 0.75rem;
  color: #047857;
}

.ai-debug-entry-status.status-error {
  color: #b91c1c;
}

@media (max-width: 1080px) {
  .ai-panels {
    grid-template-columns: 1fr;
  }

  .ai-task-panel {
    max-height: 320px;
  }
}
