:root {
  --blue: #1e5bd7;
  --bg: #f5f7fb;
  --card: #fff;
  --line: #dde4ef;
  --text: #12243a;
  --muted: #6a7891;
  --sidebar-width: 280px;
  --workspace-left-width: 62%;
  --right-ki-assistant-width: 50%;
  
  /* Semantic Tokens */
  --color-primary: #1e5bd7;
  --color-primary-hover: #184fc1;
  --color-primary-light: #edf3ff;
  --color-success: #0a7c3f;
  --color-success-bg: #e7f6ec;
  --color-danger: #b42323;
  --color-danger-bg: #fff2f2;
  --color-warning: #9a5a00;
  --color-warning-bg: #fff8e8;
  --color-text: #12243a;
  --color-muted: #6a7891;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
}

:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
  border-radius: 4px;
}

/* ---------------------------------
   Shared Components
--------------------------------- */
.error { color: #b20000; }
.success { color: #116b2e; }
a { color: var(--blue); text-decoration: none; }

button {
  border: 0;
  border-radius: 6px;
  background: var(--blue);
  color: #fff;
  font-weight: 700;
  cursor: pointer;
}

input, select, textarea {
  border: 1px solid #ccd4e2;
  border-radius: 6px;
  padding: 10px;
  box-sizing: border-box;
}

/* ---------------------------------
   Auth Pages (Login / Register)
--------------------------------- */
body.auth-page {
  background: #f3f6fb;
  color: initial;
}

.auth-page .card {
  width: 360px;
  margin: 80px auto;
  background: #fff;
  border-radius: 10px;
  padding: 24px;
  box-shadow: 0 10px 30px rgba(0,0,0,.08);
}
.auth-page.register-page .card {
  width: 400px;
  margin: 60px auto;
}
.auth-page h1 { margin: 0 0 16px; font-size: 22px; }
.auth-copy { margin: 0 0 14px; font-size: 14px; line-height: 1.5; color: #56657a; }
.auth-page label { display: block; margin: 12px 0 6px; font-size: 14px; color: #334; }
.auth-page input { width: 100%; }
.auth-page button { width: 100%; margin-top: 16px; padding: 10px; }
.auth-page .error,
.auth-page .success { font-size: 13px; margin-top: 10px; }
.auth-page a { font-size: 14px; }

/* ---------------------------------
   Chat Detail Page
--------------------------------- */
body.chat-page {
  color: #122;
}
.chat-page header { display: flex; align-items: center; justify-content: space-between; padding: 16px 24px; background: #fff; border-bottom: 1px solid var(--line); }
.chat-page .layout { max-width: 1100px; margin: 20px auto; display: grid; grid-template-columns: 1fr 320px; gap: 16px; }
.chat-page .panel { background: #fff; border: 1px solid var(--line); border-radius: 10px; }
.chat-page .messages { padding: 16px; height: 560px; overflow-y: auto; }
.chat-page .message { margin-bottom: 12px; padding: 12px 16px; border-radius: 12px; line-height: 1.4; font-size: 14px; display: flex; flex-direction: column; gap: 4px; box-shadow: 0 1px 2px rgba(0,0,0,.05); max-width: 80%; }
.chat-page .external { 
  background: #fff; border: 1px solid #d9e8ff; 
  border-left: 3px solid #1e5bd7;
}
.chat-page .ai { 
  background: #f8f9fa; border: 1px solid #e8edf5;
  border-left: 3px solid #a9b4c2;
}
.chat-page .internal { 
  background: #5145cd; color: #fff; margin-left: auto;
}
.msg-sender { font-size: 11px; font-weight: 600; opacity: 0.7; margin-bottom: 2px; }

/* Toast */
.toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  padding: 12px 24px;
  border-radius: 8px;
  color: #fff;
  font-weight: 500;
  z-index: 9999;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  animation: slideIn 0.3s ease-out forwards;
}
.toast-error { background: var(--color-danger); }
.toast-success { background: var(--color-success); }
.toast-info { background: var(--color-primary); }
@keyframes slideIn {
  from { transform: translateY(100%); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}
.chat-page .composer { display: flex; flex-direction: column; gap: 12px; border-top: none; padding: 12px; background: var(--card); }
.chat-page .composer input { width: 100%; min-height: 56px; border: 1px solid #5145cd; border-radius: 12px; padding: 12px 16px; font-family: inherit; line-height: 1.4; outline: none; box-sizing: border-box; }
.chat-page .composer input:focus { box-shadow: 0 0 0 2px rgba(81, 69, 205, 0.2); }
.chat-page button { border-radius: 12px; padding: 12px 16px; background: #a49df5; color: #fff; font-weight: 700; width: 100%; transition: background 0.2s; }
.chat-page button:hover { background: #928bf0; }
.chat-page .right { padding: 14px; }
.chat-page .service { padding: 10px; background: #f7f9ff; border: 1px solid #e8eefc; border-radius: 8px; margin-bottom: 10px; }
.chat-page .error { margin-bottom: 8px; }
.chat-page select { width: 100%; padding: 9px; margin-bottom: 8px; }

/* ---------------------------------
   Open Chats / Main App Page
--------------------------------- */
.page { display: grid; grid-template-columns: var(--sidebar-width) 8px minmax(0, 1fr); min-height: 100vh; }
.sidebar { background: var(--card); border-right: 1px solid var(--line); display: flex; flex-direction: column; }
.sidebar-frame-shell { min-height: 100vh; }
.chat-sidebar-iframe {
  width: 100%;
  flex: 1;
  min-height: 0;
  border: 0;
  background: #fff;
}
.chat-sidebar-frame-page {
  margin: 0;
  background: #fff;
}
.chat-sidebar-frame {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--card);
}
.resizer { background: #e6edf9; cursor: col-resize; position: relative; touch-action: none; }
.resizer:hover { background: #cddcff; }
.resizer:active { background: #b5cbff; }
.resize-active,
.resize-active body {
  cursor: col-resize !important;
}
.resize-active body {
  user-select: none;
}
.resize-active .chat-sidebar-iframe {
  pointer-events: none;
}
.active-resize {
  background: #b5cbff !important;
}

.brand { padding: 20px; font-weight: 800; font-size: 24px; color: var(--blue); border-bottom: 1px solid var(--line); }
.side-toolbar { padding: 14px; border-bottom: 1px solid var(--line); }
.side-search { width: 100%; border-radius: 8px; padding: 10px 12px; }

.queue-title { padding: 10px 14px; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .6px; }
.queue-list { padding: 0 10px 12px; overflow: auto; flex: 1; }
.queue-item-row { position: relative; display: flex; align-items: stretch; margin-bottom: 8px; }
.queue-item {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  text-align: left;
  border: 1px solid #e4eaf5;
  border-radius: 10px;
  background: #f9fbff;
  padding: 10px;
  margin-bottom: 0;
  cursor: pointer;
  flex: 1;
  position: relative;
  overflow: visible;
}
.queue-item:hover { border-color: #bfd1ff; background: #f2f7ff; }
.queue-item.active { border-color: var(--blue); background: #edf3ff; }
.queue-item.active .queue-name { color: #266e8c; }
.queue-item.ended { border-color: #d8deea; background: #f4f6fa; color: #5b6e83; }
.queue-item.ended:hover { border-color: #d8deea; background: #f4f6fa; }
.queue-item-row .queue-item { padding-right: 18px; }
.queue-item-header {
  display: block;
  width: 100%;
}
.queue-item-row .close-action {
  position: absolute;
  top: -8px;
  right: -8px;
  z-index: 1;
  width: 22px;
  min-width: 22px;
  height: 22px;
  border-width: 1px;
  box-shadow: 0 2px 8px rgba(18, 36, 58, 0.12);
}
.queue-item-row .close-action svg { width: 12px; height: 12px; }
.queue-name { font-weight: 700; font-size: 14px; }
.queue-timer-row {
  margin-top: 4px;
  display: flex;
  align-items: baseline;
  gap: 6px;
  min-height: 16px;
  width: 100%;
  position: relative;
  z-index: 1;
}
.queue-timer {
  min-width: 48px;
  font-size: 12px;
  font-weight: 700;
  color: var(--blue);
  text-align: left;
  font-variant-numeric: tabular-nums;
}
.queue-meta { margin-top: 4px; font-size: 12px; color: var(--muted); display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

.pill { background: #e7f6ec; color: #0a7c3f; padding: 2px 8px; border-radius: 999px; font-size: 11px; text-transform: uppercase; }
.pill.ended { background: #eef1f5; color: #58697b; }
.main { display: flex; flex-direction: column; min-width: 0; }
.topbar-main { background: var(--card); border-bottom: 1px solid var(--line); padding: 12px 24px; display: flex; justify-content: space-between; align-items: center; min-height: 60px; position: relative; z-index: 20; }
.topbar-nav { display: flex; gap: 12px; align-items: center; }
.topbar-utils { display: flex; gap: 16px; align-items: center; justify-content: flex-end; }

.menu-link {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border-radius: 8px;
  padding: 8px 14px;
  background: transparent;
  color: #5a6c80;
  font-weight: 600;
  text-decoration: none;
  transition: background 0.2s, color 0.2s;
}
.menu-link svg { width: 18px; height: 18px; opacity: 0.7; }
.menu-link:hover {
  background: #f4f7fd;
  color: #163f9a;
}
.menu-link:hover svg { opacity: 1; }
.menu-link.active {
  background: #edf3ff;
  color: var(--blue);
}
.menu-link.active svg { opacity: 1; }

.menu-dropdown {
  position: relative;
  display: inline-flex;
}

.menu-dropdown > summary {
  list-style: none;
  cursor: pointer;
}

.menu-dropdown > summary::-webkit-details-marker {
  display: none;
}

.menu-trigger {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border-radius: 8px;
  padding: 8px 14px;
  background: transparent;
  color: #5a6c80;
  font-weight: 600;
  border: 0;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}
.menu-trigger svg { width: 18px; height: 18px; opacity: 0.7; }

.menu-trigger:hover,
.menu-dropdown:hover .menu-trigger,
.menu-dropdown:focus-within .menu-trigger {
  background: #f4f7fd;
  color: #163f9a;
}
.menu-trigger:hover svg,
.menu-dropdown:hover .menu-trigger svg,
.menu-dropdown:focus-within .menu-trigger svg { opacity: 1; }

.menu-trigger.active {
  color: var(--blue);
  background: #edf3ff;
}
.menu-trigger.active svg { opacity: 1; }

.user-avatar {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--blue);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  margin-right: 4px;
}

.menu-panel {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  min-width: 200px;
  border-radius: 12px;
  border: 1px solid #d6deec;
  background: #fff;
  padding: 8px;
  box-shadow: 0 10px 30px rgba(18, 36, 58, 0.12);
  display: none;
  z-index: 100;
  transform-origin: top right;
  animation: dropdownFade 0.2s ease;
}

/* Invisible bridge to prevent hover loss when moving from trigger to panel */
.menu-panel::before {
  content: '';
  position: absolute;
  top: -12px;
  left: 0;
  right: 0;
  height: 12px;
}

@keyframes dropdownFade {
  from { opacity: 0; transform: scale(0.95); }
  to { opacity: 1; transform: scale(1); }
}

.menu-dropdown:hover .menu-panel,
.menu-dropdown:focus-within .menu-panel,
.menu-dropdown[open] .menu-panel {
  display: block;
}

.menu-panel-link,
.menu-panel-btn {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  border-radius: 8px;
  padding: 10px 14px;
  background: transparent;
  color: #35506f;
  font-weight: 600;
  border: 0;
  cursor: pointer;
  text-decoration: none;
  font-size: 14px;
  transition: background 0.2s, color 0.2s;
}

.menu-panel-link:hover,
.menu-panel-btn:hover {
  background: #f4f8ff;
  color: #163f9a;
}

.menu-panel-link.active {
  background: #edf3ff;
  color: var(--blue);
}

.menu-dropdown[open] .menu-trigger {
  background: #f4f7fd;
  color: #163f9a;
}

.menu-panel-btn.logout-btn {
  color: #d32f2f;
}
.menu-panel-btn.logout-btn:hover {
  background: #fff5f5;
  color: #b71c1c;
}

.tabsbar { background: var(--card); border-bottom: 1px solid var(--line); padding: 10px 20px; min-height: 52px; display: flex; align-items: center; }
.tabs { display: flex; gap: 8px; overflow: auto; max-width: 100%; }
.tab-item { position: relative; display: inline-flex; align-items: center; }
.tab { border: 1px solid var(--blue); background: var(--blue); border-radius: 8px; padding: 8px 10px; cursor: pointer; white-space: nowrap; color: #fff; }
.tab:hover:not(.active):not(.ended) { background: #184fc1; border-color: #184fc1; }
.tab.active { border-color: #163f9a; color: #fff; background: #163f9a; font-weight: 700; }
.tab.ended { border-color: #d8deea; background: #f4f6fa; color: #5b6e83; }
.tab-empty { color: var(--muted); font-size: 13px; }
.close-action {
  width: 34px;
  min-width: 34px;
  height: 34px;
  border: 1px solid #d6deec;
  border-radius: 999px;
  background: #fff;
  color: #5c6e81;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s, color 0.2s;
}
.close-action svg { width: 16px; height: 16px; fill: currentColor; }
.close-action:hover:not(:disabled) { border-color: #f0b6b6; background: #fff3f3; color: #c03c3c; }
.close-action:disabled { opacity: 0.5; cursor: not-allowed; }
.tab-item .close-action {
  position: absolute;
  top: -8px;
  right: -8px;
  z-index: 1;
  width: 22px;
  min-width: 22px;
  height: 22px;
  border-width: 1px;
  box-shadow: 0 2px 8px rgba(18, 36, 58, 0.12);
}
.tab-item .close-action svg { width: 12px; height: 12px; }
.tab-item .tab { padding-right: 18px; }

.workspace { padding: 14px; display: grid; grid-template-columns: minmax(20px, var(--workspace-left-width)) 8px minmax(20px, 1fr); grid-template-rows: 1fr; gap: 14px; height: calc(100vh - 108px); min-width: 0; overflow: hidden; }
.workspace-empty { flex: 1; display: flex; align-items: center; justify-content: center; background: #fbfcff; height: calc(100vh - 108px); }
.empty-main-placeholder { text-align: center; color: #5c6e81; font-size: 15px; font-weight: 500; }
.workspace-resizer { background: #e6edf9; cursor: col-resize; border-radius: 8px; touch-action: none; }
.workspace-resizer:hover { background: #cddcff; }
.workspace-resizer:active { background: #b5cbff; }

.app-page .card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; display: flex; flex-direction: column; height: 100%; min-height: 0; min-width: 0; overflow: hidden; }
.chat-card, .ki-assistant-card, .services-card { padding: 0; overflow: hidden; }
.chat-panel-header { margin-bottom: 10px; }
.chat-header { padding: 14px; border-bottom: 1px solid #edf2fa; font-weight: 700; display: flex; justify-content: space-between; align-items: center; }
.mandant-details {
  padding: 12px 16px;
  background: #f8faff;
  border-bottom: 1px solid #edf2fa;
  font-size: 13px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 12px;
  max-height: 150px;
  overflow-y: auto;
}
.mandant-detail-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.mandant-detail-label {
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  font-size: 10px;
  letter-spacing: 0.5px;
}
.mandant-detail-value {
  color: var(--text);
  font-weight: 500;
}
.huk-result-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: #e7f6ec;
  color: #0a7c3f;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  margin-top: 4px;
}
.huk-result-pill.uninsured {
  background: #fff2f2;
  color: #b42323;
}

.chat-messages { flex: 1; min-height: 0; overflow: auto; padding: 14px; display: flex; flex-direction: column; gap: 10px; background: #fbfcff; }

.msg { max-width: 80%; padding: 12px 16px; border-radius: 12px; line-height: 1.4; font-size: 14px; display: flex; flex-direction: column; gap: 4px; box-shadow: 0 1px 2px rgba(0,0,0,.05); }
.msg.external { 
  background: #fff; border: 1px solid #d9e8ff; 
  border-left: 3px solid #1e5bd7; color: #12243a;
}
.msg.ai { 
  background: #f8f9fa; border: 1px solid #e8edf5;
  border-left: 3px solid #a9b4c2; color: #12243a;
}
.msg.internal { 
  background: #5145cd; color: #fff; margin-left: auto;
}


.app-page .composer { border-top: none; padding: 12px; display: flex; flex-direction: column; gap: 12px; flex-shrink: 0; background: var(--card); }
.composer-field { position: relative; }
.app-page .composer textarea {
  width: 100%;
  min-height: 56px;
  max-height: 132px;
  border: 1px solid #d7dfef;
  border-radius: 18px;
  padding: 14px 68px 14px 16px;
  resize: none;
  overflow-y: hidden;
  font-family: inherit;
  line-height: 1.4;
  outline: none;
  background: #f7f9fd;
  transition: border-color 0.2s, box-shadow 0.2s, background 0.2s;
}
.app-page .composer textarea:focus {
  border-color: #9ab5df;
  background: #fff;
  box-shadow: 0 0 0 3px rgba(31, 78, 153, 0.12);
}
.app-page .composer textarea:disabled {
  background: #f2f4f8;
  color: #6a7c8f;
  cursor: not-allowed;
}
.send-btn {
  transition: transform 0.2s, box-shadow 0.2s, opacity 0.2s, background 0.2s;
}
.icon-send-btn {
  position: absolute;
  right: 12px;
  bottom: 12px;
  width: 44px;
  height: 44px;
  border-radius: 999px;
  border: 1px solid #d7dfef;
  background: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  box-shadow: 0 6px 18px rgba(18, 36, 58, 0.08);
}
.icon-send-btn svg {
  width: 20px;
  height: 20px;
  fill: #1f4e99;
}
.icon-send-btn:hover:not(:disabled) {
  background: #f4f8ff;
  box-shadow: 0 8px 22px rgba(31, 78, 153, 0.18);
  transform: translateY(-1px);
}
.send-btn:disabled {
  opacity: .55;
  cursor: not-allowed;
  box-shadow: none;
  transform: none;
}

.ki-assistant-layout { display: grid; grid-template-columns: minmax(20px, var(--right-ki-assistant-width)) 8px minmax(20px, 1fr); gap: 14px; min-height: 0; min-width: 0; }
.ki-assistant-resizer { background: #e6edf9; cursor: col-resize; border-radius: 8px; touch-action: none; }
.ki-assistant-resizer:hover { background: #cddcff; }
.ki-assistant-resizer:active { background: #b5cbff; }

.ki-assistant-panel-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 14px 0 14px; margin-bottom: 4px; }
.ki-assistant-panel-header .ki-assistant-title { margin-bottom: 0; }
.ki-assistant-tabs { display: flex; gap: 8px; flex-wrap: wrap; }
.ki-assistant-tab { border: 1px solid #d6deec; background: #fff; color: var(--text); border-radius: 8px; padding: 10px 16px; cursor: pointer; font-size: 14px; font-weight: 600; transition: all 0.2s; }
.ki-assistant-tab.active { border-color: var(--blue); color: var(--blue); background: #edf3ff; box-shadow: 0 2px 6px rgba(30, 91, 215, 0.1); }
.ki-assistant-panels { flex: 1; min-height: 0; display: flex; }
.ki-assistant-generated-panels { display: contents; }
.ki-assistant-panel { display: none; flex: 1; min-height: 0; }
.ki-assistant-panel.active { display: flex; flex-direction: column; min-height: 0; }
.chat-card .chat-header,
.chat-card .chat-messages,
.chat-card .composer,
.ki-assistant-chat-header,
.ki-assistant-chat-messages,
.ki-assistant-card .composer { padding-left: 0; padding-right: 0; }
.chat-card .chat-messages,
.ki-assistant-chat-messages { background: transparent; }
.chat-card .composer,
.ki-assistant-card .composer { padding-bottom: 0; }

.ki-assistant-title, .services-title { font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: .8px; margin-bottom: 0; font-weight: 700; }

.msg-text { overflow-wrap: anywhere; font-size: 15px; line-height: 1.5; }
.msg-text p,
.msg-text ul,
.msg-text ol,
.msg-text h1,
.msg-text h2,
.msg-text h3,
.msg-text h4,
.msg-text pre,
.msg-text table { margin: 0; }
.msg-text ul,
.msg-text ol { padding-left: 18px; }
.msg-text h1,
.msg-text h2,
.msg-text h3,
.msg-text h4 { line-height: 1.25; font-weight: 700; }
.msg-text h1 { font-size: 20px; }
.msg-text h2 { font-size: 18px; }
.msg-text h3 { font-size: 16px; }
.msg-text h4 { font-size: 15px; }
.msg-text pre {
  overflow-x: auto;
  padding: 10px 12px;
  border-radius: 10px;
  background: #13233a;
  color: #f3f7ff;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  font-size: 13px;
  line-height: 1.5;
  white-space: pre-wrap;
}
.msg-text code {
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  font-size: 13px;
}
.msg-text :not(pre) > code {
  padding: 2px 6px;
  border-radius: 6px;
  background: #edf3ff;
  color: #193763;
}
.msg-text table {
  width: 100%;
  border-collapse: collapse;
  display: block;
  overflow-x: auto;
}
.msg-text .ki-callout {
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid #d6deec;
  background: #f7f9ff;
}
.msg-text .ki-callout strong:first-child {
  display: block;
  margin-bottom: 6px;
  font-size: 13px;
  letter-spacing: 0.2px;
  text-transform: uppercase;
}
.msg-text .ki-callout-important {
  border-color: #f2c46d;
  background: #fff8e8;
}
.msg-text .ki-callout-important strong:first-child {
  color: #9a5a00;
}
.msg-text .ki-callout-summary {
  border-color: #a8d4ff;
  background: #eef7ff;
}
.msg-text .ki-callout-summary strong:first-child {
  color: #14579b;
}
.msg-text .ki-callout-next-steps {
  border-color: #b8ddb7;
  background: #f0fbef;
}
.msg-text .ki-callout-next-steps strong:first-child {
  color: #206a2d;
}
.msg-text .ki-checklist {
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid #d6deec;
  background: linear-gradient(180deg, #fbfcff 0%, #f5f8fe 100%);
}
.msg-text .ki-checklist-title {
  margin: 0 0 10px;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.2px;
  text-transform: uppercase;
  color: #24446f;
}
.msg-text .ki-checklist-item {
  position: relative;
  padding: 8px 10px 8px 34px;
  border-radius: 10px;
  background: #fff;
  border: 1px solid #e3eaf6;
}
.msg-text .ki-checklist-item::before {
  content: "✓";
  position: absolute;
  top: 8px;
  left: 10px;
  width: 18px;
  height: 18px;
  border-radius: 999px;
  background: #e8f2ff;
  color: #1f5fb8;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
}
.msg-text .ki-checklist-item strong:first-child {
  display: block;
  margin-bottom: 4px;
  color: #18365e;
}
.msg-text .ki-checklist-item p {
  color: #30445f;
}
.msg-text th,
.msg-text td {
  border: 1px solid #d6deec;
  padding: 8px 10px;
  text-align: left;
  vertical-align: top;
}
.msg-text th {
  background: #edf3ff;
  font-weight: 700;
}
.msg-text p + p,
.msg-text p + ul,
.msg-text p + ol,
.msg-text p + h1,
.msg-text p + h2,
.msg-text p + h3,
.msg-text p + h4,
.msg-text p + pre,
.msg-text p + table,
.msg-text ul + p,
.msg-text ol + p,
.msg-text ul + ul,
.msg-text ol + ol,
.msg-text h1 + p,
.msg-text h2 + p,
.msg-text h3 + p,
.msg-text h4 + p,
.msg-text h1 + table,
.msg-text h2 + table,
.msg-text h3 + table,
.msg-text h4 + table,
.msg-text pre + p,
.msg-text pre + .ki-callout,
.msg-text pre + .ki-checklist,
.msg-text table + p,
.msg-text table + pre,
.msg-text table + .ki-callout,
.msg-text table + .ki-checklist,
.msg-text .ki-callout + p,
.msg-text .ki-callout + ul,
.msg-text .ki-callout + ol,
.msg-text .ki-callout + table,
.msg-text .ki-callout + pre,
.msg-text .ki-callout + .ki-checklist,
.msg-text p + .ki-callout,
.msg-text p + .ki-checklist,
.msg-text ul + .ki-callout,
.msg-text ul + .ki-checklist,
.msg-text ol + .ki-callout,
.msg-text ol + .ki-checklist,
.msg-text h1 + .ki-callout,
.msg-text h1 + .ki-checklist,
.msg-text h2 + .ki-callout,
.msg-text h2 + .ki-checklist,
.msg-text h3 + .ki-callout,
.msg-text h3 + .ki-checklist,
.msg-text h4 + .ki-callout,
.msg-text h4 + .ki-checklist,
.msg-text .ki-callout + .ki-callout,
.msg-text .ki-checklist + p,
.msg-text .ki-checklist + ul,
.msg-text .ki-checklist + ol,
.msg-text .ki-checklist + table,
.msg-text .ki-checklist + pre,
.msg-text .ki-checklist + .ki-callout,
.msg-text .ki-checklist + .ki-checklist,
.msg-text .ki-checklist-title + .ki-checklist-item,
.msg-text .ki-checklist-item + .ki-checklist-item { margin-top: 8px; }

.services-list { display: grid; gap: 10px; min-height: 0; overflow: auto; }
.services-cards-layout {
  display: grid;
  grid-template-rows: 
    minmax(120px, var(--services-primary-height, 1fr)) 
    8px 
    minmax(120px, var(--services-secondary-height, 1fr)) 
    8px 
    minmax(120px, 240px);
  gap: 0;
  min-height: 0;
  width: 100%;
}
.services-card {
  display: flex;
  min-height: 0;
}
.services-card-primary {
  padding-bottom: 16px;
}
.services-card-secondary {
  gap: 12px;
  padding-top: 16px;
}
.services-section-resizer {
  min-height: 8px;
  background: #e6edf9;
  cursor: row-resize;
  border-radius: 8px;
  touch-action: none;
}
.services-section-resizer:hover,
.services-section-resizer.active-resize,
.services-section-resizer:active {
  background: #cddcff;
}
.services-subtitle {
  font-size: 13px;
  line-height: 1.5;
  color: #5a6c80;
}
.services-api-status {
  border: 1px solid #dfe7f3;
  border-radius: 12px;
  background: #f9fbff;
  padding: 12px 14px;
  min-height: 72px;
  font-size: 13px;
  line-height: 1.5;
  color: #33485e;
}
.services-api-status.success {
  border-color: #b7e4c7;
  background: #f2fbf6;
  color: #1d5d39;
}
.services-api-status.error {
  border-color: #f0c7c7;
  background: #fff6f6;
  color: #8f2d2d;
}
.services-api-submit-btn {
  width: 100%;
  justify-content: center;
}
.service-row {
  border: 1px solid #edf2fa;
  background: #f9fbff;
  border-radius: 10px;
  min-height: 58px;
  padding: 12px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 16px;
  font-weight: 700;
  color: #33485e;
  text-align: left;
  width: 100%;
}
.service-row:hover:not(:disabled) { border-color: #cddcff; background: #f2f7ff; }
.service-row.active { border-color: var(--blue); background: #edf3ff; color: var(--blue); }
.service-row.disabled { opacity: .7; }
.service-icon { width: 34px; height: 34px; border-radius: 8px; background: #e7efff; display: inline-flex; align-items: center; justify-content: center; color: #2d4b80; font-size: 18px; font-weight: 700; flex-shrink: 0; }
.skill-result-messages { overflow: auto; }

.empty-main { padding: 24px; color: var(--muted); font-size: 14px; }
.app-page .error,
.app-page .success { padding: 10px 14px; font-weight: 700; }
.skills-workspace {
  padding: 14px;
  display: grid;
  grid-template-columns: minmax(280px, 420px) minmax(420px, 1fr);
  gap: 14px;
  min-height: calc(100vh - 80px);
  align-items: start;
}
.skills-form-card,
.skills-list-card { padding: 18px; gap: 16px; }
.skills-section-header { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.skills-section-title { font-size: 16px; font-weight: 700; color: #18365e; }
.skills-count { font-size: 13px; color: var(--muted); }
.skills-form { display: flex; flex-direction: column; gap: 12px; }
.skills-label { font-size: 13px; font-weight: 700; color: #24446f; }
.skills-input,
.skills-textarea {
  width: 100%;
  border: 1px solid #d7dfef;
  border-radius: 12px;
  padding: 14px 16px;
  font-family: inherit;
  line-height: 1.5;
  outline: none;
  background: #f7f9fd;
}
.skills-input { min-height: 48px; }
.skills-textarea { min-height: 180px; resize: vertical; }
.skills-input:focus,
.skills-textarea:focus {
  border-color: #9ab5df;
  background: #fff;
  box-shadow: 0 0 0 3px rgba(31, 78, 153, 0.12);
}
.skills-checkbox { display: inline-flex; align-items: center; gap: 8px; font-size: 14px; color: #24446f; }
.primary-btn,
.secondary-btn,
.danger-btn {
  border-radius: 10px;
  padding: 10px 14px;
  font-weight: 700;
  width: fit-content;
}
.primary-btn { background: var(--color-primary); color: #fff; }
.primary-btn:hover { background: var(--color-primary-hover); }
.ghost-btn { background: var(--color-primary-light); color: var(--color-primary); }
.secondary-btn {
  background: #fff;
  color: #24446f;
  border: 1px solid #d7dfef;
}
.danger-btn { background: #fff2f2; color: #b42323; }
.skills-browser { display: flex; flex-direction: column; gap: 14px; min-height: 0; }
.skills-table-wrap {
  border: 1px solid #dfe7f3;
  border-radius: 14px;
  overflow: auto;
  background: #fff;
}
.skills-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 720px;
}
.skills-table th,
.skills-table td {
  padding: 14px 16px;
  border-bottom: 1px solid #edf2fa;
  text-align: left;
  vertical-align: middle;
}
.skills-table th {
  background: #f6f9ff;
  font-size: 12px;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: #5a6c80;
}
.skills-table tbody tr:last-child td { border-bottom: none; }
.skills-table-row {
  cursor: pointer;
  transition: background-color .18s ease, box-shadow .18s ease;
}
.skills-table-row:hover,
.skills-table-row:focus-visible { background: #f8fbff; }
.skills-table-row.active { background: #edf3ff; }
.skills-row-trigger {
  padding: 0;
  border: 0;
  background: transparent;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  color: inherit;
  font: inherit;
  text-align: left;
}
.skills-row-trigger-title { font-size: 15px; font-weight: 700; color: #18365e; }
.skills-row-trigger-meta { font-size: 12px; color: #5a6c80; }
.skills-accordion-list { display: flex; flex-direction: column; gap: 12px; }
.skill-accordion {
  border: 1px solid #dfe7f3;
  border-radius: 14px;
  background: #fbfcff;
  overflow: hidden;
}
.skill-accordion.active {
  border-color: #cddcff;
  box-shadow: 0 0 0 1px rgba(31, 78, 153, 0.08);
}
.skill-accordion-header {
  width: 100%;
  border: 0;
  background: transparent;
  padding: 16px 18px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  text-align: left;
}
.skill-accordion-header-copy {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
}
.skill-accordion-icon {
  font-size: 18px;
  color: #4b6483;
  line-height: 1;
  transition: transform .18s ease;
}
.skill-accordion.active .skill-accordion-icon { transform: rotate(180deg); }
.skill-accordion-body {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 0 18px 18px;
}
.skill-title { font-size: 18px; font-weight: 700; color: #18365e; margin-bottom: 8px; }
.skill-meta-line {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  font-size: 13px;
  color: #5a6c80;
}
.skills-preview-block {
  border: 1px solid #e1e8f3;
  border-radius: 12px;
  background: #fff;
  padding: 14px;
}
.skills-preview-title { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .6px; margin-bottom: 10px; }
.skills-preview {
  margin: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  font-size: 13px;
  line-height: 1.55;
  color: #18365e;
}
.skills-form-actions,
.skills-delete-form { display: flex; }
.skills-sidebar-copy { display: flex; flex-direction: column; gap: 10px; }
.skills-sidebar-text { font-size: 14px; line-height: 1.5; color: #58708d; }
.archive-workspace {
  padding: 14px;
  display: grid;
  grid-template-columns: minmax(320px, 420px) minmax(420px, 1fr);
  gap: 14px;
  min-height: calc(100vh - 80px);
  align-items: start;
}
.archive-list-card,
.archive-detail-card { padding: 18px; gap: 16px; }
.archive-sidebar-copy { display: flex; flex-direction: column; gap: 10px; }
.archive-sidebar-text { font-size: 14px; line-height: 1.5; color: #58708d; }
.archive-sidebar-stats {
  margin-top: auto;
  padding: 0 14px 14px;
  display: grid;
  gap: 10px;
}
.archive-sidebar-stat {
  border: 1px solid #dfe7f3;
  border-radius: 12px;
  padding: 12px 14px;
  background: #fbfcff;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.archive-sidebar-stat-label,
.archive-stat-label {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: #5a6c80;
}
.archive-section-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}
.archive-state-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.archive-state-chip {
  border-radius: 999px;
  padding: 6px 10px;
  background: #f4f7fd;
  color: #35506f;
  font-size: 12px;
  font-weight: 700;
}
.archive-search-form {
  display: flex;
  gap: 12px;
  align-items: center;
}
.archive-search-form .skills-input { flex: 1; }
.archive-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow: auto;
  padding-right: 4px;
}
.archive-list-item {
  border: 1px solid #dfe7f3;
  border-radius: 14px;
  background: #fbfcff;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  color: inherit;
  transition: border-color .18s ease, box-shadow .18s ease, background-color .18s ease;
}
.archive-list-item:hover {
  border-color: #cddcff;
  background: #fff;
}
.archive-list-item.active {
  border-color: #cddcff;
  background: #edf3ff;
  box-shadow: 0 0 0 1px rgba(31, 78, 153, 0.08);
}
.archive-list-item-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.archive-list-item-name {
  font-size: 15px;
  font-weight: 700;
  color: #18365e;
}
.archive-list-item-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  font-size: 13px;
  color: #5a6c80;
}
.archive-detail-card { min-height: 0; }
.archive-detail-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}
.archive-detail-title {
  font-size: 22px;
  font-weight: 700;
  color: #18365e;
  margin-bottom: 8px;
}
.archive-stats-grid,
.archive-detail-grid {
  display: grid;
  gap: 12px;
}
.archive-stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.archive-detail-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.archive-stat-card,
.archive-detail-block {
  border: 1px solid #e1e8f3;
  border-radius: 12px;
  background: #fff;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
}
.archive-stat-card strong,
.archive-detail-value {
  color: #18365e;
  font-weight: 700;
  overflow-wrap: anywhere;
}
.archive-detail-label {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: #5a6c80;
}
.archive-transcript-block { flex: 1; min-height: 0; }
.archive-transcript {
  min-height: 280px;
  max-height: 100%;
  overflow: auto;
}
.archive-inline-stats {
  margin-top: 0;
  padding: 0;
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.profile-workspace {
  padding: 14px;
}
.profile-card {
  padding: 18px;
  gap: 16px;
  max-width: 960px;
}
.profile-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.profile-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}
.hidden-form { display: none; }
.modal-open { overflow: hidden; }
.user-management-page {
  padding: 14px;
}
.user-management-card {
  padding: 20px;
  gap: 18px;
}
.user-management-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}
.user-management-toolbar-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.user-management-subtitle {
  margin-top: 6px;
  color: var(--muted);
  font-size: 14px;
}
.user-management-new-btn {
  min-height: 42px;
}
.econsult-action-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}
.econsult-inline-form {
  margin: 0;
}
.econsult-singleton-banner {
  margin-bottom: 20px;
  padding: 14px 16px;
  border-radius: 14px;
  border: 1px solid #dbe6f5;
  background: #f6f9ff;
  color: #1f3556;
  font-size: 14px;
}
.econsult-singleton-meta {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
  margin-bottom: 20px;
}
.econsult-singleton-meta-card {
  border: 1px solid #dfe7f3;
  border-radius: 14px;
  padding: 14px 16px;
  background: #ffffff;
}
.econsult-singleton-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.econsult-form-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}
.user-table-wrap {
  border: 1px solid #dfe7f3;
  border-radius: 16px;
  overflow: auto;
  background: #fff;
}
.user-table {
  width: 100%;
  min-width: 980px;
  border-collapse: collapse;
}
.user-table th,
.user-table td {
  padding: 16px 18px;
  border-bottom: 1px solid #edf2fa;
  text-align: left;
  vertical-align: middle;
}
.user-table th {
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  background: #f8faff;
}
.user-table tbody tr:hover {
  background: #fbfdff;
}
.user-table-name {
  font-weight: 700;
  color: #18365e;
}
.user-table-meta {
  margin-top: 4px;
  font-size: 12px;
  color: var(--muted);
}
.user-role-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 4px 10px;
  border-radius: 999px;
  background: #edf3ff;
  color: var(--blue);
  font-size: 12px;
  font-weight: 700;
}
.user-status-text {
  display: inline-block;
  margin-left: 10px;
  font-size: 13px;
  color: #35506f;
  vertical-align: middle;
}
.switch {
  position: relative;
  display: inline-flex;
  width: 48px;
  height: 28px;
  vertical-align: middle;
}
.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}
.switch-slider {
  position: absolute;
  inset: 0;
  border-radius: 999px;
  background: #d8dfeb;
  transition: background 0.2s ease;
}
.switch-slider::before {
  content: "";
  position: absolute;
  width: 22px;
  height: 22px;
  left: 3px;
  top: 3px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 2px 6px rgba(18, 36, 58, 0.18);
  transition: transform 0.2s ease;
}
.switch input:checked + .switch-slider {
  background: #4b7cff;
}
.switch input:checked + .switch-slider::before {
  transform: translateX(20px);
}
.switch input:focus + .switch-slider {
  box-shadow: 0 0 0 3px rgba(30, 91, 215, 0.18);
}
.modal-backdrop {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(18, 36, 58, 0.42);
  z-index: 200;
}
.modal-backdrop.open {
  display: flex;
}
.modal-dialog {
  width: min(760px, 100%);
  max-height: min(92vh, 900px);
  overflow: auto;
  background: #fff;
  border-radius: 20px;
  border: 1px solid #dfe7f3;
  box-shadow: 0 24px 60px rgba(18, 36, 58, 0.22);
  padding: 24px;
}
.modal-header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}
.modal-title {
  margin: 0;
  font-size: 22px;
  color: #18365e;
}
.modal-subtitle {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.5;
}
.modal-close-btn {
  width: 40px;
  min-width: 40px;
  height: 40px;
  border-radius: 999px;
  background: #f4f7fd;
  color: #36516f;
  font-size: 24px;
  line-height: 1;
}
.modal-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.modal-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 8px;
}
.modal-actions-split {
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
}
.modal-actions-split > .modal-actions {
  margin-top: 0;
}
@media (max-width: 1100px) {
  .archive-workspace,
  .skills-workspace {
    grid-template-columns: 1fr;
  }
  .services-cards-layout {
    grid-template-rows: auto 8px auto;
  }
  .archive-detail-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .archive-detail-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .archive-detail-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .user-table {
    min-width: 820px;
  }
  .archive-inline-stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
@media (max-width: 720px) {
  .page {
    grid-template-columns: 1fr;
  }
  .resizer {
    display: none;
  }
  .sidebar-frame-shell {
    min-height: 360px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
  .chat-sidebar-iframe {
    min-height: 300px;
  }
  .topbar-main {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
    padding: 14px 16px;
  }
  .topbar-nav,
  .topbar-utils {
    width: 100%;
    flex-wrap: wrap;
  }
  .topbar-utils {
    justify-content: space-between;
    gap: 10px;
  }
  .menu-link,
  .menu-trigger {
    justify-content: center;
  }
  .menu-dropdown {
    flex: 1 1 auto;
  }
  .menu-dropdown > summary,
  .menu-trigger.user-profile-btn {
    width: 100%;
    justify-content: center;
  }
  .menu-panel {
    left: 0;
    right: 0;
    min-width: 0;
  }
  .archive-search-form,
  .archive-section-header,
  .archive-list-item-top {
    flex-direction: column;
    align-items: stretch;
  }
  .profile-grid { display: grid; grid-template-columns: 1fr; }
  .user-management-toolbar,
  .user-management-toolbar-actions,
  .modal-header,
  .modal-actions {
    align-items: stretch;
  }
  .modal-grid {
    grid-template-columns: 1fr;
  }
  .archive-inline-stats,
  
  .user-table,
  .user-table thead,
  .user-table tbody,
  .user-table th,
  .user-table td,
  .user-table tr {
    display: block;
    min-width: 0;
  }
  .user-table thead {
    display: none;
  }
  .user-table tr {
    padding: 14px 16px;
    border-bottom: 1px solid #edf2fa;
  }
  .user-table td {
    padding: 8px 0;
    border-bottom: 0;
  }
  .user-table td::before {
    content: attr(data-label);
    display: block;
    margin-bottom: 4px;
    font-size: 11px;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
  }

  .modal-backdrop {
    padding: 12px;
  }
  .modal-dialog {
    padding: 18px;
    border-radius: 16px;
  }
  .archive-stats-grid,
  .archive-detail-grid { grid-template-columns: 1fr; }
}

@keyframes typingBounce {
  0%, 80%, 100% { transform: translateY(0); }
  40% { transform: translateY(-6px); }
}

.msg-typing {
  width: fit-content;
}

.typing-bubble {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  min-width: 3.5rem;
}

.typing-dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #94a3b8;
  animation: typingBounce 1.2s ease-in-out infinite;
}

.typing-dot:nth-child(2) {
  animation-delay: 0.2s;
}

.typing-dot:nth-child(3) {
  animation-delay: 0.4s;
}
