:root {
  color-scheme: light;
  --background: #ffffff;
  --surface: #ffffff;
  --surface-subtle: #f9fafb;
  --surface-muted: #f3f4f6;
  --text: #111827;
  --text-soft: #374151;
  --muted: #6b7280;
  --border: #e5e7eb;
  --border-strong: #d1d5db;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-soft: #eff6ff;
  --primary-border: #bfdbfe;
  --success: #15803d;
  --success-soft: #f0fdf4;
  --success-border: #bbf7d0;
  --warning: #a16207;
  --warning-soft: #fffbeb;
  --warning-border: #fde68a;
  --danger: #b91c1c;
  --danger-soft: #fef2f2;
  --danger-border: #fecaca;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, .05);
  --shadow-card: 0 10px 30px rgba(15, 23, 42, .08);
  --radius-sm: 7px;
  --radius: 10px;
  --radius-lg: 14px;
  --font: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { width: 100%; min-height: 100%; }
body { margin: 0; background: var(--background); color: var(--text); font: 14px/1.5 var(--font); -webkit-font-smoothing: antialiased; }
button, input, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .58; }
a { color: inherit; }
[hidden] { display: none !important; }

:focus-visible { outline: 3px solid rgba(37, 99, 235, .24); outline-offset: 2px; }
.skip-link { position: fixed; top: 8px; left: 8px; z-index: 100; transform: translateY(-160%); border-radius: var(--radius-sm); background: var(--text); color: white; padding: 9px 12px; text-decoration: none; }
.skip-link:focus { transform: translateY(0); }
.icon { width: 18px; height: 18px; flex: 0 0 auto; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.icon-sm { width: 15px; height: 15px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; clip-path: inset(50%); }

.button {
  min-height: 40px; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 1px solid transparent; border-radius: var(--radius); padding: 9px 14px;
  background: var(--primary); color: #fff; font-weight: 600; text-decoration: none;
  transition: background-color .2s ease, border-color .2s ease, color .2s ease, box-shadow .2s ease;
}
.button:hover:not(:disabled) { background: var(--primary-hover); }
.button.secondary { background: #fff; border-color: var(--border); color: var(--text-soft); box-shadow: var(--shadow-sm); }
.button.secondary:hover:not(:disabled) { background: var(--surface-muted); border-color: var(--border-strong); }
.button.ghost { background: transparent; color: var(--muted); }
.button.ghost:hover:not(:disabled) { background: var(--surface-muted); color: var(--text); }
.button.danger-ghost { background: transparent; color: #dc2626; }
.button.danger-ghost:hover { background: var(--danger-soft); color: var(--danger); }
.icon-button { width: 40px; min-width: 40px; padding: 0; }

.field { display: grid; gap: 7px; }
.field label { color: var(--text-soft); font-size: 13px; font-weight: 600; }
.input, .field input, .field textarea {
  width: 100%; border: 1px solid var(--border-strong); border-radius: var(--radius);
  background: #fff; color: var(--text); padding: 10px 12px; outline: none;
  transition: border-color .2s ease, box-shadow .2s ease;
}
.input:focus, .field input:focus, .field textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37, 99, 235, .11); }
.form-error { min-height: 20px; color: var(--danger); font-size: 13px; }

/* Login — mirrors the previous BuddyBot web chat. */
.login-page { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: #f5f5f5; }
.login-card { width: min(400px, 100%); border: 1px solid var(--border); border-radius: var(--radius-lg); background: #fff; box-shadow: var(--shadow-card); padding: 30px; }
.login-brand { display: flex; align-items: center; justify-content: center; gap: 10px; margin-bottom: 24px; font-size: 18px; font-weight: 700; }
.brand-mark { width: 34px; height: 34px; display: grid; place-items: center; border-radius: 10px; background: var(--primary); color: #fff; }
.login-card h1 { margin: 0; text-align: center; font-size: 24px; line-height: 1.2; }
.login-subtitle { margin: 7px 0 24px; color: var(--muted); text-align: center; }
.login-form { display: grid; gap: 17px; }
.password-wrap { position: relative; }
.password-wrap input { padding-right: 44px; }
.password-toggle { position: absolute; top: 50%; right: 5px; transform: translateY(-50%); width: 36px; height: 36px; display: grid; place-items: center; border: 0; border-radius: 8px; background: transparent; color: var(--muted); }
.password-toggle:hover { background: var(--surface-muted); color: var(--text); }
.login-form .button { width: 100%; margin-top: 2px; }

/* Shared application shell. */
.app-shell { height: 100vh; min-height: 620px; display: flex; overflow: hidden; background: #fff; }
.sidebar { width: 280px; flex: 0 0 280px; display: flex; flex-direction: column; padding: 16px; border-right: 1px solid var(--border); background: var(--surface-subtle); }
.sidebar-brand { display: flex; align-items: center; gap: 10px; min-height: 40px; padding: 4px 6px; margin-bottom: 12px; font-weight: 700; text-decoration: none; }
.sidebar-brand .brand-mark { width: 30px; height: 30px; border-radius: 9px; }
.sidebar .new-chat { width: 100%; justify-content: flex-start; margin-bottom: 16px; }
.sidebar-section-label { margin: 2px 10px 7px; color: var(--muted); font-size: 11px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; }
.chat-list { min-height: 0; flex: 1; overflow-y: auto; display: grid; align-content: start; gap: 2px; margin: 0 -4px; padding: 0 4px; }
.chat-item { width: 100%; min-height: 40px; border: 0; border-radius: 8px; background: transparent; color: var(--text-soft); padding: 9px 11px; overflow: hidden; text-align: left; text-overflow: ellipsis; white-space: nowrap; transition: background-color .2s ease, color .2s ease; }
.chat-item:hover { background: var(--surface-muted); color: var(--text); }
.chat-item.active { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.sidebar-empty { padding: 24px 12px; color: var(--muted); text-align: center; font-size: 13px; }
.sidebar-footer { display: grid; gap: 3px; padding-top: 10px; border-top: 1px solid var(--border); }
.sidebar-link { min-height: 40px; display: flex; align-items: center; gap: 10px; border: 0; border-radius: 8px; background: transparent; color: var(--muted); padding: 9px 11px; text-align: left; text-decoration: none; transition: background-color .2s ease, color .2s ease; }
.sidebar-link:hover { background: var(--surface-muted); color: var(--text); }
.sidebar-user { overflow: hidden; padding: 8px 11px 4px; color: var(--muted); font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.mobile-header { display: none; height: 54px; align-items: center; justify-content: space-between; padding: 7px 12px; border-bottom: 1px solid var(--border); background: #fff; }
.mobile-header strong { font-size: 15px; }
.sidebar-backdrop { display: none; }

/* Chat. */
.chat-main { min-width: 0; flex: 1; display: flex; flex-direction: column; background: #fff; }
.messages-viewport { min-height: 0; flex: 1; overflow-y: auto; }
.messages { width: min(768px, 100%); min-height: 100%; margin: 0 auto; padding: 28px 24px 36px; display: flex; flex-direction: column; gap: 22px; }
.message { display: flex; flex-direction: column; animation: message-in .2s ease both; }
.message.user { align-items: flex-end; }
.message.assistant { align-items: flex-start; }
.message-bubble { max-width: 85%; border-radius: 16px; padding: 12px 16px; overflow-wrap: anywhere; }
.message.user .message-bubble { max-width: 80%; border: 1px solid var(--border); border-bottom-right-radius: 5px; background: #fff; color: var(--text); box-shadow: var(--shadow-sm); white-space: pre-wrap; }
.message.assistant .message-bubble { border-bottom-left-radius: 5px; background: var(--surface-subtle); color: var(--text-soft); }
.message.stream .message-bubble { min-width: min(560px, 85%); }
.streaming-cursor { display: inline-block; width: 2px; height: 1em; margin-left: 3px; vertical-align: -.1em; background: var(--primary); animation: cursor-blink 1s steps(1) infinite; }

.start-screen { min-height: 100%; display: grid; place-items: center; padding: 36px 24px; }
.start-content { width: min(610px, 100%); text-align: center; }
.start-icon { width: 52px; height: 52px; display: grid; place-items: center; margin: 0 auto 15px; border-radius: 50%; background: var(--primary-soft); color: var(--primary); }
.start-icon .icon { width: 25px; height: 25px; }
.start-content h1 { margin: 0; font-size: 24px; line-height: 1.25; }
.start-content > p { max-width: 500px; margin: 8px auto 26px; color: var(--muted); }
.suggestions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.suggestion { min-height: 70px; border: 1px solid var(--border); border-radius: 12px; background: #fff; color: var(--text-soft); padding: 13px 14px; text-align: left; line-height: 1.4; transition: background-color .2s ease, border-color .2s ease, color .2s ease; }
.suggestion:hover { border-color: var(--primary-border); background: var(--primary-soft); color: var(--primary-hover); }

.composer-wrap { flex: 0 0 auto; padding: 12px 24px 18px; background: linear-gradient(to bottom, rgba(255,255,255,.86), #fff 18px); }
.composer { width: min(768px, 100%); margin: 0 auto; }
.composer-box { display: flex; align-items: flex-end; gap: 8px; border: 1px solid var(--border-strong); border-radius: 16px; background: #fff; padding: 7px 7px 7px 13px; box-shadow: 0 3px 14px rgba(15,23,42,.06); transition: border-color .2s ease, box-shadow .2s ease; }
.composer-box:focus-within { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,.10); }
.composer textarea { min-height: 42px; max-height: 120px; flex: 1; resize: none; border: 0; outline: 0; padding: 10px 2px 8px; color: var(--text); background: transparent; line-height: 1.45; }
.send-button { width: 38px; height: 38px; min-width: 38px; border: 0; border-radius: 11px; display: grid; place-items: center; background: var(--primary); color: #fff; transition: background-color .2s ease; }
.send-button:hover:not(:disabled) { background: var(--primary-hover); }
.composer-hint { min-height: 20px; margin: 6px 3px 0; color: var(--muted); font-size: 12px; text-align: center; }
.composer-hint.error { color: var(--danger); }

.agent-activity { width: 100%; margin-bottom: 11px; border: 1px solid var(--primary-border); border-radius: 10px; background: rgba(239,246,255,.7); overflow: hidden; }
.agent-activity summary { list-style: none; display: flex; align-items: center; gap: 8px; min-height: 38px; padding: 8px 10px; color: var(--primary-hover); cursor: pointer; font-size: 12px; font-weight: 600; }
.agent-activity summary::-webkit-details-marker { display: none; }
.activity-chevron { transition: transform .2s ease; }
.agent-activity[open] .activity-chevron { transform: rotate(90deg); }
.activity-pulse { width: 8px; height: 8px; border-radius: 50%; background: var(--primary); box-shadow: 0 0 0 0 rgba(37,99,235,.35); animation: activity-pulse 1.6s ease-out infinite; }
.activity-steps { margin: 0; padding: 0 12px 10px 32px; display: grid; gap: 6px; color: var(--muted); font-size: 12px; }
.activity-steps li::marker { color: var(--primary); }
.activity-current { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.citations { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 12px; padding-top: 11px; border-top: 1px solid var(--border); }
.citation { display: inline-flex; align-items: flex-start; gap: 7px; max-width: 100%; border: 1px solid var(--primary-border); border-radius: 8px; background: var(--primary-soft); color: var(--primary-hover); padding: 6px 9px; font-size: 12px; line-height: 1.35; }
.citation-copy { min-width: 0; }
.citation-name { display: block; overflow: hidden; font-weight: 600; text-overflow: ellipsis; white-space: nowrap; }
.citation-location { display: block; color: #3b65a7; font-size: 11px; }
.message-feedback { display: flex; align-items: center; gap: 6px; margin-top: 10px; padding-top: 9px; border-top: 1px solid var(--border); color: var(--muted); font-size: 11px; }
.message-feedback > span { margin-right: 3px; }
.feedback-button { width: 30px; height: 30px; display: grid; place-items: center; border: 1px solid transparent; border-radius: 8px; background: transparent; color: var(--muted); transition: color .2s ease, background-color .2s ease, border-color .2s ease; }
.feedback-button:hover { border-color: var(--border); background: #fff; color: var(--primary); }
.feedback-button.selected { border-color: var(--success-border); background: var(--success-soft); color: var(--success); }
.feedback-button.selected.negative { border-color: var(--danger-border); background: var(--danger-soft); color: var(--danger); }
dialog.feedback-dialog { width: min(520px, calc(100vw - 28px)); border: 0; border-radius: 14px; padding: 0; box-shadow: 0 24px 80px rgba(15,23,42,.22); }
.feedback-caption { margin: 0 0 16px; color: var(--text-soft); }
.feedback-dialog label { display: grid; gap: 7px; color: var(--text-soft); font-weight: 600; }
.feedback-dialog textarea { width: 100%; resize: vertical; border: 1px solid var(--border-strong); border-radius: var(--radius); padding: 10px 12px; }

/* Safe Markdown output. */
.markdown { font-size: 14.5px; line-height: 1.65; }
.markdown > :first-child { margin-top: 0; }
.markdown > :last-child { margin-bottom: 0; }
.markdown p { margin: 0 0 10px; }
.markdown h1, .markdown h2, .markdown h3 { margin: 19px 0 8px; color: var(--text); line-height: 1.3; }
.markdown h1 { font-size: 20px; }
.markdown h2 { font-size: 17px; }
.markdown h3 { font-size: 15px; }
.markdown ul, .markdown ol { margin: 7px 0 11px; padding-left: 22px; }
.markdown li { margin: 3px 0; }
.markdown blockquote { margin: 10px 0; border-left: 3px solid var(--primary-border); padding: 4px 0 4px 12px; color: var(--muted); }
.markdown code { border-radius: 5px; background: #eef0f3; color: #9f1239; padding: 2px 5px; font: 12.5px/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.markdown pre { margin: 10px 0; overflow-x: auto; border-radius: 10px; background: #111827; color: #e5e7eb; padding: 13px 15px; }
.markdown pre code { background: transparent; color: inherit; padding: 0; }
.markdown a { color: var(--primary); text-decoration-thickness: 1px; text-underline-offset: 2px; }
.markdown strong { color: var(--text); }
.markdown hr { margin: 15px 0; border: 0; border-top: 1px solid var(--border); }
.markdown-table-wrap { max-width: 100%; overflow-x: auto; margin: 11px 0; }
.markdown table { width: 100%; border-collapse: collapse; font-size: 13px; }
.markdown th, .markdown td { border: 1px solid var(--border); padding: 7px 9px; text-align: left; vertical-align: top; }
.markdown th { background: var(--surface-muted); color: var(--text); font-weight: 600; }

/* Admin. */
.admin-shell { min-height: 100vh; display: flex; background: #f5f5f5; }
.admin-sidebar { width: 240px; flex: 0 0 240px; display: flex; flex-direction: column; background: #111827; color: #d1d5db; padding: 18px 12px; }
.admin-sidebar .sidebar-brand { color: #fff; padding-inline: 9px; }
.admin-sidebar .sidebar-link { color: #d1d5db; }
.admin-sidebar .sidebar-link:hover, .admin-sidebar .sidebar-link.active { background: rgba(255,255,255,.10); color: #fff; }
.admin-sidebar .sidebar-footer { margin-top: auto; border-color: rgba(255,255,255,.12); }
.admin-main { min-width: 0; flex: 1; overflow-y: auto; padding: 30px; }
.admin-content { width: min(1180px, 100%); margin: 0 auto; }
.admin-v2 .admin-sidebar { position: sticky; top: 0; height: 100vh; }
.admin-nav { display: grid; gap: 3px; }
.admin-page { min-width: 0; }
.page-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; margin-bottom: 20px; }
.page-header h1 { margin: 0; font-size: 28px; line-height: 1.2; }
.page-header p { margin: 6px 0 0; color: var(--muted); }
.card { border: 1px solid var(--border); border-radius: 12px; background: #fff; box-shadow: var(--shadow-sm); }
.card-header { min-height: 58px; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 13px 17px; border-bottom: 1px solid var(--border); }
.card-header h2 { margin: 0; font-size: 16px; }
.card-body { padding: 8px 17px 16px; }
.table-card { padding: 0 10px 8px; }
.table-wrap { overflow-x: auto; }
.card table { width: 100%; border-collapse: collapse; }
.card th, .card td { padding: 13px 10px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; }
.card th { color: var(--muted); font-size: 12px; font-weight: 600; white-space: nowrap; }
.card tbody tr:last-child td { border-bottom: 0; }
.card tbody tr { transition: background-color .2s ease; }
.card tbody tr:hover { background: var(--surface-subtle); }
.document-name { min-width: 260px; color: var(--text); font-weight: 600; }
.meta { display: block; margin-top: 2px; color: var(--muted); font-size: 12px; font-weight: 400; }
.status { display: inline-flex; align-items: center; gap: 6px; border: 1px solid; border-radius: 999px; padding: 4px 9px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.status::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.status.ready { border-color: var(--success-border); background: var(--success-soft); color: var(--success); }
.status.queued, .status.processing, .status.uploaded { border-color: var(--warning-border); background: var(--warning-soft); color: var(--warning); }
.status.processing::before { animation: status-pulse 1.3s ease-in-out infinite; }
.status.failed { border-color: var(--danger-border); background: var(--danger-soft); color: var(--danger); }
.status.active { border-color: var(--success-border); background: var(--success-soft); color: var(--success); }
.status.invited { border-color: var(--warning-border); background: var(--warning-soft); color: var(--warning); }
.status.blocked { border-color: var(--danger-border); background: var(--danger-soft); color: var(--danger); }
.status.neutral { border-color: var(--border); background: var(--surface-muted); color: var(--muted); }
.metric-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 16px; }
.metric-card { min-height: 116px; display: flex; flex-direction: column; justify-content: space-between; border: 1px solid var(--border); border-radius: 12px; background: #fff; box-shadow: var(--shadow-sm); padding: 18px; }
.metric-card span { color: var(--muted); font-size: 13px; font-weight: 600; }
.metric-card strong { color: var(--text); font-size: 30px; line-height: 1; }
.dashboard-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; margin-bottom: 16px; }
.dashboard-grid + .card, .dashboard-grid + .card + .card { margin-bottom: 16px; }
.summary-row { display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 10px 0; border-bottom: 1px solid var(--border); color: var(--text-soft); }
.summary-row:last-child { border-bottom: 0; }
.summary-row strong { color: var(--text); font-size: 17px; }
.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.search-field { width: min(360px, 100%); }
.search-field input, .form-grid input, .form-grid select, .admin-dialog input, .admin-dialog select { width: 100%; min-height: 40px; border: 1px solid var(--border-strong); border-radius: var(--radius); background: #fff; color: var(--text); padding: 8px 11px; }
.search-field input:focus, .form-grid input:focus, .form-grid select:focus, .admin-dialog input:focus { border-color: var(--primary); outline: 3px solid rgba(37,99,235,.11); }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.form-grid label, .admin-dialog label { display: grid; gap: 6px; color: var(--text-soft); font-size: 13px; font-weight: 600; }
.form-grid .form-error { grid-column: 1 / -1; }
.table-actions { display: flex; flex-wrap: wrap; gap: 5px; min-width: 220px; }
.table-action { min-height: 30px; display: inline-flex; align-items: center; border: 0; border-radius: 7px; background: transparent; color: var(--primary); padding: 5px 7px; font-size: 12px; font-weight: 600; text-decoration: none; transition: background-color .2s ease, color .2s ease; }
.table-action:hover { background: var(--primary-soft); color: var(--primary-hover); }
.table-action.danger { color: var(--danger); }
.table-action.danger:hover { background: var(--danger-soft); }
.table-empty { height: 110px; color: var(--muted); text-align: center !important; }
.log-details { max-width: 320px; overflow: hidden; color: var(--muted); font: 11px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace; text-overflow: ellipsis; white-space: nowrap; }
.progress-track { width: min(220px, 100%); height: 5px; margin-top: 7px; overflow: hidden; border-radius: 999px; background: var(--surface-muted); }
.progress-track span { display: block; height: 100%; border-radius: inherit; background: var(--primary); transition: width .3s ease; }
.progress-track.ready span { background: var(--success); }
.progress-track.failed span { background: var(--danger); }
.integration-placeholder { display: grid; justify-items: center; max-width: 760px; padding: 42px 28px; text-align: center; }
.integration-placeholder.compact { margin-top: 16px; padding: 26px; }
.integration-placeholder h2 { margin: 12px 0 4px; }
.integration-placeholder p { max-width: 580px; margin: 0 0 18px; color: var(--muted); }
.integration-icon { width: 54px; height: 54px; display: grid; place-items: center; border-radius: 15px; background: var(--primary-soft); color: var(--primary); }
.integration-icon .icon { width: 27px; height: 27px; }
.settings-card { max-width: 760px; }
.settings-card .card-header { align-items: flex-start; padding-block: 17px; }
.settings-card .card-header p { margin: 4px 0 0; color: var(--muted); font-size: 13px; }
.settings-form { display: grid; gap: 10px; padding: 20px; }
.settings-form label { display: grid; gap: 7px; color: var(--text-soft); font-size: 13px; font-weight: 600; }
.settings-form input {
  width: 100%; min-height: 42px; border: 1px solid var(--border-strong); border-radius: var(--radius);
  background: #fff; color: var(--text); padding: 9px 12px; outline: none;
  transition: border-color .2s ease, box-shadow .2s ease;
}
.settings-form input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37, 99, 235, .11); }
.settings-form .meta { margin: 0; }
.locale-fieldset { display: grid; gap: 9px; margin: 10px 0 0; border: 0; padding: 0; }
.locale-fieldset legend { margin-bottom: 7px; color: var(--text-soft); font-size: 13px; font-weight: 600; }
.locale-switch { display: inline-grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 4px; width: min(100%, 308px); border: 1px solid var(--border); border-radius: 10px; background: var(--surface-muted); padding: 4px; }
.locale-switch input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.locale-switch label { display: flex; align-items: center; justify-content: center; gap: 8px; min-height: 40px; border: 1px solid transparent; border-radius: 7px; padding: 7px 13px; color: var(--muted); cursor: pointer; transition: border-color .2s ease, background-color .2s ease, color .2s ease, box-shadow .2s ease; }
.locale-switch label span { color: inherit; font-size: 11px; font-weight: 700; letter-spacing: .06em; }
.locale-switch label strong { color: inherit; font-size: 13px; font-weight: 600; }
.locale-switch input:checked + label { border-color: var(--primary-border); background: #fff; color: var(--primary-hover); box-shadow: var(--shadow-sm); }
.locale-switch input:focus-visible + label { outline: 3px solid rgba(37, 99, 235, .2); outline-offset: 2px; }
.locale-switch label:hover { color: var(--primary-hover); }
.settings-actions { display: flex; justify-content: flex-start; margin-top: 2px; }
.empty-state { display: grid; place-items: center; min-height: 220px; color: var(--muted); text-align: center; }
.empty-state .icon { width: 32px; height: 32px; margin-bottom: 8px; color: #9ca3af; }
.processing-banner { display: flex; align-items: center; gap: 11px; margin-bottom: 16px; border: 1px solid var(--primary-border); border-radius: 10px; background: var(--primary-soft); color: var(--primary-hover); padding: 11px 13px; }
.processing-banner.success { border-color: var(--success-border); background: var(--success-soft); color: var(--success); }
.processing-banner.warning { align-items: flex-start; border-color: var(--warning-border); background: var(--warning-soft); color: var(--warning); }
.processing-banner.error { border-color: var(--danger-border); background: var(--danger-soft); color: var(--danger); }
.processing-spinner { width: 16px; height: 16px; flex: 0 0 auto; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .8s linear infinite; }
.processing-banner.success .processing-spinner, .processing-banner.error .processing-spinner { animation: none; border: 0; }
.pivot-warning-details { margin-top: 7px; color: var(--warning); font-size: 12px; line-height: 1.4; }
.toast { position: fixed; right: 22px; top: 22px; z-index: 80; max-width: min(410px, calc(100vw - 44px)); border: 1px solid var(--border); border-radius: 10px; background: #fff; color: var(--text-soft); box-shadow: var(--shadow-card); padding: 11px 14px; }
.toast[data-tone="error"] { border-color: var(--danger-border); background: var(--danger-soft); color: var(--danger); }
.toast[data-tone="success"] { border-color: var(--success-border); background: var(--success-soft); color: var(--success); }

dialog.upload-dialog { width: min(760px, calc(100vw - 28px)); max-height: calc(100dvh - 34px); overflow: auto; border: 0; border-radius: 14px; padding: 0; box-shadow: 0 24px 80px rgba(15,23,42,.22); }
dialog.admin-dialog { width: min(620px, calc(100vw - 28px)); max-height: calc(100vh - 34px); overflow: auto; border: 0; border-radius: 14px; padding: 0; box-shadow: 0 24px 80px rgba(15,23,42,.22); }
dialog.preview-dialog { width: min(1120px, calc(100vw - 28px)); }
dialog.chat-viewer-dialog { width: min(820px, calc(100vw - 28px)); }
dialog::backdrop { background: rgba(17,24,39,.48); }
.dialog-header { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 18px 20px; border-bottom: 1px solid var(--border); }
.dialog-header h2 { margin: 0; font-size: 18px; }
.dialog-header p { margin: 2px 0 0; color: var(--muted); font-size: 12px; }
.dialog-body { padding: 20px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 9px; padding: 14px 20px 18px; }
.dropzone { min-height: 190px; display: grid; place-items: center; border: 1.5px dashed var(--border-strong); border-radius: 12px; background: var(--surface-subtle); padding: 26px; text-align: center; transition: border-color .2s ease, background-color .2s ease; }
.dropzone.dragging { border-color: var(--primary); background: var(--primary-soft); }
.dropzone .icon { width: 34px; height: 34px; margin-bottom: 9px; color: var(--primary); }
.dropzone strong { display: block; margin-bottom: 5px; font-size: 15px; }
.dropzone p { margin: 0; color: var(--muted); font-size: 13px; }
.folder-upload-row { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-top: 12px; color: var(--muted); font-size: 13px; }
.folder-upload-row .button { flex: 0 0 auto; }
.selected-files { max-height: 145px; overflow-y: auto; display: grid; gap: 6px; margin-top: 12px; }
.selected-file { display: flex; justify-content: space-between; gap: 10px; border-radius: 8px; background: var(--surface-muted); padding: 8px 10px; color: var(--text-soft); font-size: 12px; }
.skipped-files { max-height: 128px; overflow-y: auto; margin-top: 7px; border: 1px solid color-mix(in srgb, var(--danger) 25%, var(--border)); border-radius: 9px; background: color-mix(in srgb, var(--danger) 4%, var(--surface)); }
.skipped-files[hidden] { display: none; }
.skipped-files ul { margin: 0; padding: 5px 10px; list-style: none; }
.skipped-files li { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 12px; align-items: baseline; padding: 6px 0; color: var(--text-soft); font-size: 12px; }
.skipped-files li + li { border-top: 1px solid color-mix(in srgb, var(--danger) 12%, var(--border)); }
.skipped-files li > span { min-width: 0; overflow-wrap: anywhere; }
.skipped-files small { color: var(--muted); white-space: nowrap; font-size: 11px; }
.upload-activity { min-height: 460px; }
.upload-overview { padding: 18px 20px 16px; border-bottom: 1px solid var(--border); background: var(--surface-subtle); }
.upload-overview-row { display: flex; align-items: baseline; justify-content: space-between; gap: 16px; color: var(--text); }
.upload-overview-row strong { font-size: 15px; }
.upload-overview-row span { color: var(--primary); font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }
.upload-total-track { height: 8px; margin-top: 11px; overflow: hidden; border-radius: 999px; background: #dfe7f3; }
.upload-total-track > span { display: block; width: 0; height: 100%; border-radius: inherit; background: var(--primary); transition: width .2s ease; }
.upload-overview-meta { display: flex; flex-wrap: wrap; gap: 8px 18px; margin-top: 9px; color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.upload-recovery { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin: 14px 20px 0; border: 1px solid var(--warning-border); border-radius: 10px; background: var(--warning-soft); padding: 12px 14px; }
.upload-recovery strong { display: block; color: #854d0e; font-size: 13px; }
.upload-recovery p { margin: 2px 0 0; color: var(--warning); font-size: 12px; }
.upload-recovery .button { flex: 0 0 auto; }
.upload-filterbar { display: flex; gap: 6px; overflow-x: auto; padding: 14px 20px 10px; }
.upload-filterbar button { min-height: 32px; display: inline-flex; align-items: center; gap: 7px; border: 1px solid transparent; border-radius: 8px; background: transparent; color: var(--muted); padding: 5px 9px; white-space: nowrap; }
.upload-filterbar button:hover { background: var(--surface-muted); color: var(--text); }
.upload-filterbar button.active { border-color: var(--primary-border); background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.upload-filterbar button span { min-width: 20px; border-radius: 999px; background: rgba(107,114,128,.1); padding: 1px 5px; text-align: center; font-size: 11px; font-variant-numeric: tabular-nums; }
.upload-items { max-height: min(440px, calc(100dvh - 330px)); min-height: 190px; overflow-y: auto; padding: 0 20px 12px; }
.upload-item { display: grid; grid-template-columns: 28px minmax(0, 1fr) auto; gap: 10px; align-items: start; padding: 12px 2px; border-top: 1px solid var(--border); }
.upload-item:first-child { border-top: 0; }
.upload-item-status { width: 24px; height: 24px; display: grid; place-items: center; margin-top: 1px; border-radius: 50%; background: var(--surface-muted); color: var(--muted); font-size: 12px; font-weight: 700; }
.upload-item.uploading .upload-item-status, .upload-item.queued .upload-item-status, .upload-item.processing .upload-item-status { background: var(--primary-soft); color: var(--primary); }
.upload-item.ready .upload-item-status { background: var(--success-soft); color: var(--success); }
.upload-item.failed .upload-item-status { background: var(--danger-soft); color: var(--danger); }
.upload-item-copy { min-width: 0; }
.upload-item-name { display: block; overflow: hidden; color: var(--text-soft); font-size: 13px; font-weight: 600; text-overflow: ellipsis; white-space: nowrap; }
.upload-item-detail { display: block; margin-top: 2px; color: var(--muted); font-size: 11px; overflow-wrap: anywhere; }
.upload-item-detail.error { color: var(--danger); }
.upload-item-aside { min-width: 76px; color: var(--muted); text-align: right; font-size: 11px; font-variant-numeric: tabular-nums; }
.upload-item-track { grid-column: 2 / 4; height: 4px; overflow: hidden; border-radius: 999px; background: var(--surface-muted); }
.upload-item-track span { display: block; width: 0; height: 100%; border-radius: inherit; background: var(--primary); transition: width .2s ease; }
.upload-item.ready .upload-item-track span { background: var(--success); }
.upload-item.failed .upload-item-track span { background: var(--danger); }
.upload-activity-actions { align-items: center; justify-content: space-between; border-top: 1px solid var(--border); }
.upload-activity-actions > span { color: var(--muted); font-size: 11px; }
.upload-empty { display: grid; place-items: center; min-height: 180px; color: var(--muted); text-align: center; }
.preview-body { min-height: 420px; max-height: calc(100vh - 210px); overflow: auto; background: var(--surface-subtle); }
.pdf-preview { width: 100%; min-height: 660px; border: 0; background: #525659; }
.sheet-tabs { position: sticky; top: 0; z-index: 1; display: flex; gap: 6px; overflow-x: auto; border-bottom: 1px solid var(--border); background: #fff; padding: 10px 12px; }
.sheet-tabs button { border: 1px solid var(--border); border-radius: 7px; background: #fff; color: var(--text-soft); padding: 6px 10px; white-space: nowrap; }
.sheet-tabs button.active { border-color: var(--primary); background: var(--primary-soft); color: var(--primary); }
.excel-preview-wrap { overflow: auto; padding: 12px; }
.excel-preview-table { width: max-content; min-width: 100%; border-collapse: collapse; background: #fff; font-size: 12px; }
.excel-preview-table td { min-width: 90px; max-width: 260px; border: 1px solid var(--border); padding: 6px 8px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.preview-note { padding: 10px; text-align: center; }
.chat-viewer { max-height: calc(100vh - 130px); overflow-y: auto; padding: 18px; background: var(--surface-subtle); }
.viewer-message { max-width: 82%; margin: 0 0 14px; border-radius: 12px; background: #fff; padding: 12px 14px; box-shadow: var(--shadow-sm); }
.viewer-message.user { margin-left: auto; background: var(--primary-soft); }
.viewer-message-meta { margin-bottom: 6px; color: var(--muted); font-size: 11px; }
.credential-box { display: flex; align-items: center; justify-content: space-between; gap: 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface-muted); padding: 12px; }
.credential-box code { overflow-wrap: anywhere; color: var(--text); font-size: 15px; }

@keyframes message-in { from { opacity: 0; transform: translateY(4px); } }
@keyframes cursor-blink { 50% { opacity: 0; } }
@keyframes activity-pulse { 70% { box-shadow: 0 0 0 7px rgba(37,99,235,0); } 100% { box-shadow: 0 0 0 0 rgba(37,99,235,0); } }
@keyframes status-pulse { 50% { opacity: .35; } }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 820px) {
  .app-shell { min-height: 100vh; height: 100dvh; }
  .sidebar { position: fixed; inset: 0 auto 0 0; z-index: 50; transform: translateX(-102%); transition: transform .22s ease; box-shadow: 12px 0 30px rgba(15,23,42,.16); }
  .sidebar.open { transform: translateX(0); }
  .sidebar-backdrop { position: fixed; inset: 0; z-index: 40; display: block; background: rgba(17,24,39,.42); }
  .mobile-header { display: flex; }
  .messages { padding: 20px 14px 28px; }
  .message-bubble, .message.user .message-bubble, .message.stream .message-bubble { max-width: 92%; min-width: 0; }
  .composer-wrap { padding: 10px 12px 13px; }
  .suggestions { grid-template-columns: 1fr; }
  .admin-sidebar { width: 210px; flex-basis: 210px; }
  .admin-main { padding: 22px 16px; }
  .page-header { align-items: stretch; flex-direction: column; }
  .page-header .button { align-self: flex-start; }
  .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .dashboard-grid { grid-template-columns: 1fr; }
}

@media (max-width: 560px) {
  .upload-recovery { align-items: stretch; flex-direction: column; }
  .upload-overview-meta { display: grid; grid-template-columns: 1fr 1fr; }
  .upload-overview-meta span:last-child { grid-column: 1 / -1; }
  .upload-item { grid-template-columns: 28px minmax(0, 1fr); }
  .upload-item-aside { grid-column: 2; text-align: left; }
  .upload-item-track { grid-column: 2; }
  .upload-activity-actions > span { display: none; }
  .upload-activity-actions { justify-content: flex-end; }
}

@media (prefers-reduced-motion: reduce) {
  .upload-total-track > span, .upload-item-track span { transition: none; }
}

@media (max-width: 640px) {
  .login-card { padding: 24px 20px; }
  .admin-shell { display: block; }
  .admin-sidebar { width: 100%; min-height: auto; padding: 10px 12px; }
  .admin-sidebar .sidebar-brand { margin: 0; }
  .admin-sidebar .sidebar-footer { margin-top: 0; }
  .admin-sidebar nav { display: flex; gap: 4px; }
  .admin-sidebar nav { overflow-x: auto; }
  .admin-sidebar .sidebar-link { flex: 1; justify-content: center; }
  .admin-sidebar .sidebar-link span { display: none; }
  .documents th:nth-child(2), .documents td:nth-child(2), .documents th:nth-child(4), .documents td:nth-child(4) { display: none; }
  .document-name { min-width: 180px; }
  .metric-grid { grid-template-columns: 1fr 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .toolbar { align-items: stretch; flex-direction: column; }
  .preview-body { min-height: 340px; }
  .pdf-preview { min-height: 520px; }
}

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