:root {
  color-scheme: light;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: #1b2433;
  background: #f2f4f7;
  font-synthesis: none;
}

* { box-sizing: border-box; }
[x-cloak] { display: none !important; }
html, body { min-height: 100%; }
body { margin: 0; min-width: 720px; background: #f2f4f7; }
button, input, textarea, select { font: inherit; }
a { color: inherit; text-decoration: none; }
button, summary, select { cursor: pointer; }

.topbar {
  position: sticky; top: 0; z-index: 40; display: flex; height: 62px; padding: 0 28px;
  align-items: center; justify-content: space-between; color: #fff; background: #111827;
  border-bottom: 1px solid #293348;
}
.brand { font-size: 19px; font-weight: 800; letter-spacing: -.03em; }
.topbar nav { display: flex; height: 100%; gap: 4px; align-items: center; }
.nav-link { padding: 9px 13px; border-radius: 8px; color: #aeb8c9; font-size: 13px; font-weight: 700; }
.nav-link:hover { color: #fff; background: #222d42; }
.nav-link.active { color: #fff; background: #3157d5; }
.request-progress { position: fixed; top: 62px; left: 0; z-index: 60; width: 100%; height: 3px; opacity: 0; background: linear-gradient(90deg, #3157d5, #84a0ff); transition: opacity .15s; }
.request-progress.htmx-request { opacity: 1; animation: progress 1.2s ease-in-out infinite; }
@keyframes progress { 0% { transform: scaleX(.1); transform-origin: left; } 60% { transform: scaleX(.75); transform-origin: left; } 100% { transform: scaleX(1); transform-origin: left; } }

#workspace { min-height: calc(100vh - 62px); }
.split-page { display: grid; grid-template-columns: 290px minmax(0, 1fr); min-height: calc(100vh - 62px); }
.sidebar { padding: 24px 18px; color: #eef2f8; background: #172033; overflow: auto; }
.sidebar-heading, .page-header, .section-heading, .document-title, .row-actions, .toolbar-row, .editor-toolbar, .session-topline, .chat-heading {
  display: flex; align-items: center; justify-content: space-between; gap: 14px;
}
.sidebar-heading { align-items: flex-start; margin-bottom: 18px; }
.sidebar h2 { margin: 3px 0 0; font-size: 18px; }
.eyebrow { color: #71809a; font-size: 10px; font-weight: 800; letter-spacing: .1em; text-transform: uppercase; }
.sidebar .eyebrow { color: #91a0b9; }
.sidebar-list { display: grid; gap: 5px; margin-top: 12px; }
.sidebar-item { display: block; padding: 11px 12px; border: 1px solid transparent; border-radius: 9px; color: #dce4f0; }
.sidebar-item:hover { background: #222d42; }
.sidebar-item.selected { color: #fff; background: #2a3650; border-color: #465572; }
.sidebar-item strong, .sidebar-item small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-item strong { font-size: 13px; }
.sidebar-item small { margin-top: 4px; color: #9da9bb; font-size: 11px; }
.folder-item { padding-left: calc(12px + var(--depth) * 14px); }
.sidebar-details { margin-top: 16px; padding-top: 14px; border-top: 1px solid #303b50; }
.sidebar-details summary { color: #c5cfdd; font-size: 12px; font-weight: 750; }

.page-content { min-width: 0; padding: 34px; }
.centered-page { width: min(1240px, calc(100% - 48px)); margin: 0 auto; }
.schema-content { max-width: 1600px; width: 100%; margin: 0 auto; }
.page-header { align-items: flex-start; margin-bottom: 22px; }
.page-header h1, .session-topline h1 { margin: 4px 0 0; font-size: 27px; letter-spacing: -.025em; }
.page-header p { margin: 6px 0 0; color: #697386; font-size: 13px; }
.back-link { display: inline-block; margin-bottom: 8px; color: #52617b; font-size: 12px; font-weight: 700; }

.panel { border: 1px solid #dce1e9; border-radius: 12px; background: #fff; box-shadow: 0 2px 12px #23304a0b; }
.button { display: inline-flex; min-height: 38px; padding: 9px 14px; border: 0; border-radius: 8px; align-items: center; justify-content: center; font-weight: 750; }
.button.primary { color: #fff; background: #3157d5; }
.button.primary:hover { background: #294cc3; }
.button.secondary { color: #344054; background: #e9edf3; }
.button.danger { color: #a52c32; background: #fbe8e8; }
.button.completed { color: #1f7140; background: #e4f4e9; }
.button.compact { min-height: 31px; padding: 6px 9px; font-size: 11px; }
.button.full, .full { width: 100%; }
.button:disabled { cursor: not-allowed; opacity: .45; }
.icon-button { width: 30px; height: 30px; padding: 0; border: 0; border-radius: 7px; font-size: 19px; }
.icon-button.danger { color: #a52c32; background: #fbe8e8; }

label { color: #344054; font-size: 12px; font-weight: 750; }
input, textarea, select { width: 100%; margin-top: 6px; padding: 9px 10px; color: #1b2433; background: #fff; border: 1px solid #cbd2dc; border-radius: 8px; outline: none; }
input:focus, textarea:focus, select:focus { border-color: #5574dc; box-shadow: 0 0 0 3px #3157d51c; }
.sidebar input, .sidebar select { color: #eef2f8; background: #222d42; border-color: #3b4659; }
.search-form { display: flex; gap: 7px; }
.search-form input { margin: 0; }
.search-form.wide { width: min(500px, 100%); }
.stack-form { display: grid; gap: 8px; margin: 12px 0; }
.stack-form input, .stack-form select { margin: 0; }
.form-grid { display: grid; gap: 16px; }
.two-columns { grid-template-columns: 1fr 1fr; }
.notice { margin: 0 0 16px; padding: 11px 13px; border-radius: 8px; font-size: 12px; }
.notice.success { color: #176536; background: #e5f5ea; border: 1px solid #c8e8d2; }
.notice.error { color: #9e2a31; background: #fbe8e8; border: 1px solid #f1c9cb; }
.muted { color: #7b8595; font-size: 12px; }
.empty { padding: 34px 16px !important; color: #7b8595; text-align: center; }

.schema-form { padding: 24px; }
.schema-workbench { display: grid; grid-template-columns: minmax(360px, .9fr) minmax(440px, 1.1fr); margin-top: 22px; gap: 16px; }
.schema-code-pane, .schema-graph-pane { min-width: 0; overflow: hidden; border: 1px solid #dce1e9; border-radius: 10px; background: #f8f9fb; }
.editor-toolbar, .schema-graph-toolbar { min-height: 58px; padding: 10px 12px; border-bottom: 1px solid #dce1e9; background: #fff; }
.editor-toolbar > div, .schema-graph-toolbar > div:first-child { display: grid; gap: 3px; }
.editor-toolbar strong, .schema-graph-toolbar strong { color: #344054; font-size: 12px; }
.editor-toolbar small, .schema-graph-toolbar small { color: #7b8595; font-size: 10px; }
.code-editor { min-height: 600px; margin: 0; resize: vertical; border: 0; border-radius: 0; font: 12px/1.55 Consolas, "SFMono-Regular", monospace; }
.code-editor:focus { box-shadow: inset 0 0 0 2px #3157d533; }
.schema-graph-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.schema-graph-controls { display: flex; gap: 3px; }
.schema-graph-controls button { min-width: 30px; height: 29px; padding: 0 7px; color: #52617b; background: #edf0f4; border: 0; border-radius: 6px; font-size: 11px; font-weight: 800; }
.schema-graph-controls button:hover { color: #294cc3; background: #e1e7f6; }
.schema-graph-viewport { position: relative; height: 600px; background-color: #f7f9fc; background-image: radial-gradient(#cdd5e2 1px, transparent 1px); background-size: 18px 18px; overflow: auto; }
.schema-graph { display: block; max-width: none; }
.schema-graph-error { position: absolute; inset: 0; display: grid; margin: 0; padding: 28px; place-items: center; color: #9e2a31; background: #fbe8e8dd; font-size: 12px; text-align: center; }
.schema-graph-legend { display: flex; min-height: 35px; padding: 8px 12px; align-items: center; gap: 14px; color: #758096; background: #fff; border-top: 1px solid #dce1e9; font-size: 9px; }
.schema-graph-legend span { display: inline-flex; align-items: center; gap: 5px; }
.schema-graph-legend i { display: inline-block; width: 11px; height: 11px; border-radius: 3px; background: #556b95; }
.schema-graph-legend i.root { background: #3157d5; }
.schema-graph-legend b { color: #d15258; font-size: 8px; }
.schema-edge { fill: none; stroke: #99a7bc; stroke-width: 1.4; opacity: .82; }
.schema-edge.reference { stroke: #738ac8; stroke-dasharray: 5 3; }
.schema-edge-arrow { fill: #738198; }
.schema-edge-label { fill: #65738a; stroke: #f7f9fc; stroke-width: 4px; paint-order: stroke; font-size: 9px; font-weight: 700; }
.schema-node-card { fill: #fff; stroke: #cfd7e4; stroke-width: 1.2; filter: drop-shadow(0 2px 3px #26375212); }
.schema-node-header, .schema-node-header-square { fill: #556b95; }
.schema-node.root .schema-node-header, .schema-node.root .schema-node-header-square { fill: #3157d5; }
.schema-node.inline .schema-node-header, .schema-node.inline .schema-node-header-square { fill: #64748b; }
.schema-node-title { fill: #fff; font-size: 12px; font-weight: 800; }
.schema-field-name { fill: #344054; font-size: 9.5px; font-weight: 650; }
.schema-field-type { fill: #7a8597; font-size: 8.5px; }
.schema-field-divider { stroke: #edf0f4; stroke-width: 1; }
.form-actions { display: flex; margin-top: 18px; padding-top: 18px; align-items: center; justify-content: space-between; border-top: 1px solid #e6eaf0; }

.document-header { align-items: center; }
.file-button input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.toolbar-row { margin-bottom: 16px; }
.format-chips { display: flex; max-width: 45%; flex-wrap: wrap; justify-content: flex-end; gap: 5px; }
.format-chips span { padding: 4px 7px; border: 1px solid #d7dce5; border-radius: 999px; color: #667185; background: #fafbfc; font-size: 10px; font-weight: 750; }
.table-panel { overflow: auto; }
table { width: 100%; border-collapse: collapse; }
th { padding: 11px 14px; color: #737d8d; background: #f7f8fa; border-bottom: 1px solid #e1e5eb; font-size: 10px; letter-spacing: .07em; text-align: left; text-transform: uppercase; }
td { padding: 13px 14px; border-bottom: 1px solid #edf0f4; color: #344054; font-size: 12px; vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
td select { min-width: 145px; margin: 0; padding: 6px 7px; font-size: 11px; }
.align-right { text-align: right; }
.row-actions { justify-content: flex-end; }
.row-actions form { margin: 0; }
.document-title { min-width: 230px; justify-content: flex-start; }
.document-title strong, .document-title small { display: block; }
.document-title small, .cell-detail { margin-top: 3px; color: #8b94a3; font-size: 10px; }
.file-icon { display: grid; width: 35px; height: 39px; flex: 0 0 auto; place-items: center; color: #fff; background: #59677c; border-radius: 6px; font-size: 8px; font-weight: 850; }
.file-icon.pdf { background: #c5484d; } .file-icon.excel { background: #26855c; } .file-icon.powerpoint { background: #cc633b; } .file-icon.word { background: #3970bd; }

.create-session-form { display: grid; grid-template-columns: 1.4fr 1fr auto; padding: 18px; align-items: end; gap: 14px; }
.create-session-form input, .create-session-form select { margin-bottom: 0; }
.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(270px, 1fr)); gap: 14px; margin-top: 20px; }
.session-card { padding: 19px; transition: transform .15s, border-color .15s; }
.session-card:hover { border-color: #aebbd4; transform: translateY(-1px); }
.session-card strong { font-size: 15px; }
.session-card p { margin: 10px 0 18px; color: #6f798a; font-size: 12px; }
.session-card footer { display: flex; justify-content: space-between; color: #7e8899; font-size: 11px; }
.status-dot { display: inline-block; width: 8px; height: 8px; margin-right: 7px; border-radius: 50%; background: #4a70dc; }

.session-page { display: flex; height: calc(100vh - 62px); min-height: 620px; padding: 22px 28px; flex-direction: column; overflow: hidden; }
.session-topline { flex: 0 0 auto; align-items: flex-end; }
.session-topline h1 { font-size: 23px; }
.session-notice { flex: 0 0 auto; margin: 10px 0 0; }
.session-layout { display: grid; grid-template-columns: 350px minmax(0, 1fr); min-height: 0; margin-top: 16px; flex: 1; gap: 16px; }
.document-sidebar { min-height: 0; padding: 18px; border: 1px solid #dce1e9; border-radius: 12px; background: #fff; overflow-y: auto; }
.sidebar-section + .sidebar-section { margin-top: 18px; padding-top: 18px; border-top: 1px solid #e6eaf0; }
.sidebar-section select { margin-top: 8px; }
.section-heading { align-items: flex-start; }
.section-heading h2, .chat-heading h2 { margin: 3px 0 0; font-size: 17px; }
.count-badge { min-width: 25px; padding: 4px 7px; color: #3755a3; background: #e8edff; border-radius: 999px; font-size: 10px; font-weight: 800; text-align: center; }
.document-options { display: grid; gap: 7px; margin: 12px 0; }
.document-option { padding: 10px; border: 1px solid #e1e5eb; border-radius: 9px; background: #fafbfc; }
.document-option.linked { border-color: #c7d2f2; background: #f7f9ff; }
.document-option > label { display: grid; grid-template-columns: auto minmax(0, 1fr); align-items: start; gap: 8px; cursor: pointer; }
.document-option > label input { width: 15px; height: 15px; margin: 2px 0 0; }
.document-option strong, .document-option small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.document-option small { margin-top: 3px; color: #7e8898; font-size: 10px; font-weight: 500; }
.extraction-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 5px; margin-top: 9px; padding-left: 23px; }
.extraction-actions form, .extraction-actions button { width: 100%; }
.chat-panel { display: flex; min-width: 0; min-height: 0; padding: 18px; flex-direction: column; border: 1px solid #dce1e9; border-radius: 12px; background: #fff; }
.chat-heading { flex: 0 0 auto; padding-bottom: 14px; border-bottom: 1px solid #e7eaf0; }
.chat-thread { display: flex; min-height: 0; padding: 18px 4px; flex: 1; flex-direction: column; gap: 13px; overflow-y: auto; }
.chat-empty { margin: auto; padding: 30px; color: #7b8595; text-align: center; }
.chat-empty strong { color: #344054; }
.chat-message { position: relative; width: min(86%, 850px); padding: 14px 42px 14px 16px; border: 1px solid #dfe4eb; border-radius: 12px; background: #f7f8fa; }
.chat-message.user { align-self: flex-end; border-color: #cbd5f1; background: #eef2ff; }
.chat-message.assistant { align-self: flex-start; }
.chat-message header { display: flex; margin-bottom: 9px; align-items: center; justify-content: space-between; color: #7a8494; font-size: 10px; }
.chat-message header strong { color: #42506a; font-size: 11px; }
.message-source { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; opacity: 0; pointer-events: none; }
.copy-button { position: absolute; top: 35px; right: 8px; padding: 5px 7px; color: #657084; background: #e6eaf0; border: 0; border-radius: 6px; font-size: 9px; font-weight: 750; }
.markdown-body { color: #283448; font-size: 13px; line-height: 1.55; overflow-wrap: anywhere; }
.markdown-body.markdown-pending { white-space: pre-wrap; }
.markdown-body > :first-child { margin-top: 0; } .markdown-body > :last-child { margin-bottom: 0; }
.markdown-body pre, .markdown-body code { font-family: Consolas, "SFMono-Regular", monospace; }
.markdown-body code { padding: 2px 4px; border-radius: 4px; background: #e8ebf0; font-size: .92em; }
.markdown-body pre { padding: 12px; border-radius: 8px; background: #202938; color: #edf2f8; overflow-x: auto; }
.markdown-body pre code { padding: 0; background: transparent; color: inherit; }
.markdown-body table { display: block; max-width: 100%; margin: 12px 0; border-collapse: collapse; overflow-x: auto; }
.markdown-body th, .markdown-body td { padding: 7px 9px; border: 1px solid #cfd6e1; font-size: 11px; text-align: left; }
.markdown-body th { background: #e9edf3; }
.markdown-body blockquote { margin-left: 0; padding-left: 12px; color: #59677c; border-left: 3px solid #a8b5ca; }
.chat-form { display: grid; grid-template-columns: minmax(0, 1fr) auto; flex: 0 0 auto; gap: 8px; padding-top: 13px; border-top: 1px solid #e7eaf0; }
.chat-form textarea { min-height: 62px; max-height: 150px; margin: 0; resize: vertical; font-family: inherit; }
.chat-form .button { align-self: end; }
.chat-hint { grid-column: 1 / -1; color: #929baa; font-size: 9px; }
.inline-details { position: relative; }
.inline-details summary { list-style: none; }
.popover-form { position: absolute; top: 39px; right: 0; z-index: 20; display: flex; width: 310px; padding: 10px; gap: 7px; border: 1px solid #d7dde6; border-radius: 9px; background: #fff; box-shadow: 0 10px 30px #1f293725; }
.popover-form input { margin: 0; }

.kind-badge, .status-badge { display: inline-block; padding: 4px 7px; border-radius: 999px; font-size: 9px; font-weight: 850; text-transform: uppercase; }
.kind-badge.text { color: #385170; background: #e7edf4; } .kind-badge.json { color: #4b3f91; background: #ece9ff; }
.status-badge.completed { color: #1e6e3e; background: #e4f4e9; } .status-badge.failed { color: #9e2a31; background: #fbe8e8; } .status-badge.running { color: #805a11; background: #fff2cf; }
.detail-grid { display: grid; grid-template-columns: minmax(0, 1fr) 310px; gap: 16px; align-items: start; }
.detail-grid > .panel, .detail-sidebar .panel { padding: 20px; }
.detail-sidebar { display: grid; gap: 16px; }
.result-block { max-height: 68vh; margin: 16px 0 0; padding: 15px; color: #dce5f1; background: #202938; border-radius: 9px; font: 12px/1.55 Consolas, "SFMono-Regular", monospace; white-space: pre-wrap; overflow: auto; }
.result-block.small { max-height: 300px; font-size: 10px; }
.metadata-list h3 { margin: 7px 0; }
.metadata-list p { color: #6e798a; font-size: 12px; }
.metadata-list dl { display: grid; grid-template-columns: 70px minmax(0, 1fr); margin: 14px 0 0; gap: 9px; font-size: 11px; }
.metadata-list dt { color: #7b8595; } .metadata-list dd { margin: 0; overflow-wrap: anywhere; }
.metadata-list details { margin-top: 15px; }
.metadata-list summary { color: #43516a; font-size: 11px; font-weight: 750; }

@media (max-width: 980px) {
  .session-layout { grid-template-columns: 300px minmax(0, 1fr); }
  .detail-grid { grid-template-columns: 1fr; }
  .detail-sidebar { grid-template-columns: 1fr 1fr; }
  .format-chips { display: none; }
}

@media (max-width: 1250px) {
  .schema-workbench { grid-template-columns: 1fr; }
}
