:root {
  --bg: #f3f5f7;
  --surface: #fff;
  --surface-soft: #f8fafb;
  --ink: #17212b;
  --muted: #66727f;
  --line: #dfe5e9;
  --line-strong: #cbd4da;
  --accent: #0f766e;
  --accent-dark: #0b5f59;
  --accent-soft: #e9f6f3;
  --danger: #b42318;
  --danger-soft: #fff0ee;
  --warning: #8a6116;
  --warning-soft: #fff6da;
  --radius: 10px;
  --shadow: 0 14px 40px rgba(23, 33, 43, .08);
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body { background: var(--bg); color: var(--ink); font: 14px/1.45 system-ui, -apple-system, "Segoe UI", "Microsoft YaHei", sans-serif; }
button, input, textarea, select { font: inherit; }
button { min-height: 36px; border: 0; border-radius: 8px; padding: 0 14px; background: var(--accent); color: #fff; font-weight: 700; cursor: pointer; white-space: nowrap; }
button:hover { background: var(--accent-dark); }
button:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible, summary:focus-visible { outline: 3px solid rgba(15, 118, 110, .18); outline-offset: 1px; }
button:disabled { opacity: .5; cursor: not-allowed; }
input, textarea, select { width: 100%; border: 1px solid var(--line-strong); border-radius: 8px; background: #fff; color: var(--ink); padding: 8px 10px; }
input, select { min-height: 36px; }
textarea { resize: vertical; }
label { display: grid; gap: 6px; color: #34414d; font-weight: 650; }
h1, h2, h3, h4, p { margin-top: 0; }
.hidden { display: none !important; }
.muted, .meta { color: var(--muted); }
.eyebrow { margin: 0 0 3px; color: var(--accent); font-size: 11px; font-weight: 850; letter-spacing: .08em; text-transform: uppercase; }
.stack { display: grid; gap: 10px; }
.panel { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); padding: 14px; }
.button-quiet, .icon-button, .ghost { background: transparent; color: var(--muted); }
.button-quiet:hover, .icon-button:hover, .ghost:hover { background: #edf1f3; color: var(--ink); }
.danger { background: var(--danger-soft); color: var(--danger); }
.danger:hover { background: #ffe2de; }

.topbar { position: sticky; z-index: 20; top: 0; height: 58px; display: flex; align-items: center; justify-content: space-between; padding: 0 20px; border-bottom: 1px solid var(--line); background: rgba(255, 255, 255, .96); backdrop-filter: blur(12px); }
.brand { display: inline-flex; align-items: center; gap: 9px; color: var(--ink); text-decoration: none; }
.brand span { display: grid; width: 30px; height: 30px; place-items: center; border-radius: 8px; background: var(--ink); color: #fff; font-size: 12px; font-weight: 900; }
.brand strong { font-size: 15px; letter-spacing: -.01em; }
.user { display: flex; align-items: center; gap: 8px; }
.user > strong { font-size: 13px; }
.role-chip, .metric, .safe-label { display: inline-flex; align-items: center; min-height: 26px; border-radius: 999px; padding: 0 9px; background: var(--surface-soft); color: var(--muted); font-size: 12px; font-weight: 750; }
.metric { background: var(--accent-soft); color: var(--accent); }
.app-main { min-height: calc(100vh - 58px); }

.account-panel { position: fixed; z-index: 50; top: 70px; right: 20px; width: min(680px, calc(100vw - 40px)); border: 1px solid var(--line); border-radius: 12px; background: #fff; box-shadow: var(--shadow); padding: 16px; }
.panel-heading, .pane-heading, .workspace-heading, .section-heading, .item-heading, .resource-head { display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.panel-heading h2, .pane-heading h1, .workspace-heading h1, .section-heading h2 { margin: 0; letter-spacing: -.025em; }
.panel-heading h2, .section-heading h2 { font-size: 17px; }
.icon-button { width: 32px; min-height: 32px; padding: 0; font-size: 22px; }
.row-form { display: grid; grid-template-columns: 1fr 1fr auto; gap: 8px; }

.platform-layout { display: grid; grid-template-columns: 300px minmax(0, 1fr); min-height: calc(100vh - 58px); }
.tenant-pane { position: sticky; top: 58px; height: calc(100vh - 58px); overflow: auto; padding: 18px 14px; border-right: 1px solid var(--line); background: var(--surface); }
.pane-heading { margin-bottom: 13px; }
.pane-heading h1 { font-size: 22px; }
.quick-create { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 7px; margin-bottom: 14px; }
.tenant-list { display: grid; gap: 7px; }
.tenant-item { border: 1px solid var(--line); border-radius: 9px; background: #fff; overflow: hidden; transition: border-color .15s, box-shadow .15s; }
.tenant-item:hover { border-color: var(--line-strong); }
.tenant-item.selected { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(15, 118, 110, .08); }
.tenant-summary { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; align-items: center; padding: 10px; }
.tenant-name { display: flex; align-items: center; gap: 7px; min-width: 0; }
.tenant-name strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tenant-id { margin: 2px 0 0; color: var(--muted); font-size: 11px; }
.tenant-actions { display: flex; gap: 5px; }
.tenant-actions button { min-height: 30px; padding: 0 9px; font-size: 12px; }
.state-dot { width: 7px; height: 7px; flex: none; border-radius: 50%; background: #b7c0c7; }
.state-dot.active { background: #16a36a; box-shadow: 0 0 0 3px #e3f7ee; }
.tenant-settings { border-top: 1px solid var(--line); background: var(--surface-soft); }
.tenant-settings > summary { padding: 8px 10px; color: var(--muted); cursor: pointer; font-size: 12px; font-weight: 750; }
.tenant-settings-body { display: grid; gap: 9px; padding: 2px 10px 10px; }
.tenant-settings-body .row-form { grid-template-columns: minmax(0, 1fr) auto; }
.tenant-settings-body .row-form input:first-child { grid-column: 1 / -1; }
.admin-list { display: grid; gap: 7px; }
.admin-account { padding-bottom: 8px; border-bottom: 1px solid var(--line); }
.subheading { margin: 0; color: var(--muted); font-size: 11px; font-weight: 800; }

.content-pane { min-width: 0; padding: 22px; overflow: auto; }
.empty-state { display: grid; min-height: calc(100vh - 102px); place-content: center; justify-items: center; color: var(--muted); text-align: center; }
.empty-state h2 { margin: 16px 0 6px; color: var(--ink); font-size: 20px; }
.empty-mark { display: grid; width: 54px; height: 54px; place-items: center; border: 1px solid #b9ded8; border-radius: 14px; background: var(--accent-soft); color: var(--accent); font-weight: 900; }
.workspace-heading { margin-bottom: 18px; }
.workspace-heading h1 { font-size: clamp(22px, 3vw, 30px); }
.workspace-metrics { display: flex; gap: 8px; }
.workspace-metrics span { border: 1px solid var(--line); border-radius: 8px; background: #fff; padding: 7px 10px; color: var(--muted); font-size: 12px; }
.workspace-metrics strong { color: var(--ink); font-size: 16px; }
.workspace-grid { display: grid; grid-template-columns: minmax(0, 1.8fr) minmax(270px, .7fr); gap: 18px; align-items: start; }
.workspace-section { min-width: 0; }
.section-heading { margin-bottom: 10px; }
.section-heading p { margin: 2px 0 0; color: var(--muted); font-size: 12px; }
.create-bar { display: grid; grid-template-columns: minmax(150px, .7fr) minmax(180px, 1fr) auto; gap: 7px; margin-bottom: 10px; padding: 10px; border: 1px solid var(--line); border-radius: var(--radius); background: #fff; }
.knowledge-list, .assistant-list { display: grid; gap: 9px; }
.knowledge-card { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); overflow: hidden; }
.knowledge-card > .item-heading { padding: 12px 14px; border-bottom: 1px solid var(--line); }
.item-heading h3 { margin: 0; font-size: 15px; }
.item-heading p { margin: 2px 0 0; color: var(--muted); font-size: 12px; }
.knowledge-actions { display: flex; gap: 6px; }
.knowledge-actions button { min-height: 30px; font-size: 12px; }
.training-tools { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; padding: 10px 14px; background: var(--surface-soft); }
.upload-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 7px; }
.upload-row input { background: #fff; }
.faq-composer { min-width: 92px; }
.faq-composer > summary { display: grid; min-height: 36px; place-items: center; border-radius: 8px; background: #e9eef1; color: #34414d; padding: 0 12px; cursor: pointer; font-weight: 750; list-style: none; }
.faq-composer[open] { grid-column: 1 / -1; }
.faq-create-form { margin-top: 8px; padding: 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.format-note { grid-column: 1 / -1; margin: 0; color: var(--muted); font-size: 11px; }
.resources { border-top: 1px solid var(--line); }
.resources > summary { padding: 9px 14px; cursor: pointer; color: #34414d; font-size: 12px; font-weight: 800; }
.resource-list { border-top: 1px solid var(--line); }
.resource-item { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 7px 12px; padding: 9px 14px; border-bottom: 1px solid var(--line); }
.resource-item:last-child { border-bottom: 0; }
.resource-head { min-width: 0; justify-content: flex-start; }
.resource-head strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.resource-meta { grid-column: 1; margin: -3px 0 0; color: var(--muted); font-size: 11px; }
.resource-action { grid-column: 2; grid-row: 1 / span 2; align-self: center; min-height: 28px; padding: 0 9px; font-size: 11px; }
.status { display: inline-flex; flex: none; align-items: center; min-height: 21px; border-radius: 999px; padding: 0 7px; background: #edf1f3; color: var(--muted); font-size: 10px; font-weight: 850; }
.status-ready { background: var(--accent-soft); color: var(--accent); }
.status-failed { background: var(--danger-soft); color: var(--danger); }
.status-processing { background: var(--warning-soft); color: var(--warning); }
.failure { grid-column: 1 / -1; margin: 0; color: var(--danger); font-size: 11px; overflow-wrap: anywhere; }
.faq-editor { grid-column: 1 / -1; }
.faq-editor > summary { color: var(--accent); cursor: pointer; font-size: 11px; font-weight: 800; }
.faq-editor form { margin-top: 8px; }
.actions { display: flex; flex-wrap: wrap; gap: 6px; }
.actions button { min-height: 30px; padding: 0 10px; font-size: 12px; }
.compact-form { margin-bottom: 9px; }
.compact-form textarea { min-height: 78px; }
.checkbox-row { display: flex; align-items: center; gap: 7px; font-size: 12px; }
.checkbox-row input { width: auto; min-height: 0; }
.form-actions { display: grid; grid-template-columns: 1fr auto; gap: 7px; }
.assistant-item { display: flex; align-items: center; justify-content: space-between; gap: 10px; border: 1px solid var(--line); border-radius: 9px; background: #fff; padding: 10px 12px; }
.assistant-item strong { font-size: 13px; }
.assistant-actions { display: flex; align-items: center; gap: 6px; }
.assistant-actions button { min-height: 28px; padding: 0 9px; font-size: 11px; }

.api-access { margin-top: 18px; border: 1px solid var(--line); border-radius: var(--radius); background: #fff; padding: 14px; }
.api-access .section-heading { margin-bottom: 10px; }
.api-endpoint { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 7px; margin-bottom: 10px; }
.api-endpoint strong { grid-column: 1 / -1; font-size: 12px; }
.api-endpoint input { min-width: 0; font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 12px; }
.api-key-form { display: grid; grid-template-columns: minmax(180px, 1fr) minmax(160px, .8fr) 150px auto; gap: 7px; }
.key-reveal { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; align-items: center; margin-top: 10px; border: 1px solid #e3b341; border-radius: 8px; background: var(--warning-soft); padding: 10px; color: var(--warning); }
.key-reveal strong { grid-column: 1 / -1; font-size: 12px; }
.key-reveal code { overflow: auto; border-radius: 6px; background: #fff; padding: 8px; color: var(--ink); white-space: nowrap; }
.api-key-list { display: grid; gap: 7px; margin-top: 10px; }
.api-key-item { position: relative; display: grid; gap: 2px; border-top: 1px solid var(--line); padding: 9px 76px 2px 0; }
.api-key-summary { display: flex; align-items: center; gap: 8px; }
.api-key-summary > div { min-width: 0; flex: 1; }
.api-key-meta { margin: 2px 0 0; color: var(--muted); font-size: 11px; }
.api-key-revoke { position: absolute; top: 11px; right: 0; min-height: 30px; padding: 0 10px; font-size: 12px; }

.customer-layout { display: grid; grid-template-rows: auto minmax(0, 1fr); height: calc(100vh - 58px); padding: 20px max(20px, calc((100vw - 1180px) / 2)); }
.customer-heading { margin-bottom: 12px; }
.customer-workspace { display: grid; min-height: 0; grid-template-columns: minmax(0, 1fr) minmax(320px, 380px); gap: 14px; }
.customer-workspace .api-access { min-width: 0; margin-top: 0; overflow: auto; }
.customer-workspace .api-key-form { grid-template-columns: 1fr; }
.customer-controls { display: flex; align-items: center; gap: 8px; }
.customer-controls select { width: 240px; }
.safe-label { background: var(--accent-soft); color: var(--accent); }
.chat-panel { display: grid; min-height: 0; grid-template-rows: minmax(0, 1fr) auto; overflow: hidden; border: 1px solid var(--line); border-radius: 12px; background: #fff; box-shadow: 0 6px 24px rgba(23, 33, 43, .04); }
.messages { overflow: auto; padding: 20px; background: linear-gradient(#fbfcfd, #f6f8f9); }
.chat-empty { display: grid; height: 100%; place-content: center; gap: 5px; color: var(--muted); text-align: center; }
.chat-empty strong { color: var(--ink); font-size: 16px; }
.bubble { width: fit-content; max-width: min(760px, 82%); margin: 10px 0; border: 1px solid var(--line); border-radius: 4px 12px 12px; background: #fff; padding: 10px 12px; box-shadow: 0 2px 8px rgba(23, 33, 43, .03); white-space: pre-wrap; }
.bubble.user { margin-left: auto; border: 0; border-radius: 12px 4px 12px 12px; background: var(--accent); color: #fff; }
.citation { display: block; margin-top: 7px; border-top: 1px solid var(--line); padding-top: 6px; color: var(--muted); font-size: 11px; }
.chat-input { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 9px; align-items: end; border-top: 1px solid var(--line); padding: 12px; }
.chat-input textarea { min-height: 54px; max-height: 150px; }
.chat-input button { min-height: 54px; }

#toast { position: fixed; z-index: 100; right: 20px; bottom: 20px; max-width: 380px; border-radius: 9px; background: var(--ink); color: #fff; padding: 11px 14px; box-shadow: var(--shadow); opacity: 0; pointer-events: none; transform: translateY(8px); transition: .18s; }
#toast.show { opacity: 1; transform: translateY(0); }
.form-error { min-height: 20px; margin: 0; color: var(--danger); font-size: 12px; }

.login-page { display: grid; min-height: 100vh; place-items: center; padding: 24px; background: #e9eef1; }
.login-shell { display: grid; width: min(900px, 100%); min-height: 520px; grid-template-columns: 1.1fr .9fr; overflow: hidden; border: 1px solid rgba(255, 255, 255, .7); border-radius: 18px; background: #fff; box-shadow: 0 30px 80px rgba(23, 33, 43, .14); }
.login-intro { display: flex; flex-direction: column; justify-content: space-between; padding: 38px; background: #15252b; color: #dce7e7; }
.login-intro .brand { color: #fff; }
.login-intro .brand span { background: var(--accent); }
.login-intro h1 { margin: 10px 0 16px; color: #fff; font-size: clamp(30px, 4vw, 43px); line-height: 1.18; letter-spacing: -.04em; }
.login-intro p:not(.eyebrow) { max-width: 380px; color: #aebfc1; }
.login-footnote { color: #809496; font-size: 11px; letter-spacing: .06em; }
.login-card { align-self: center; padding: 48px; }
.login-heading { margin-bottom: 24px; }
.login-heading h2 { margin: 3px 0 5px; font-size: 25px; letter-spacing: -.03em; }
.login-heading p:last-child { color: var(--muted); }
.login-card form button { margin-top: 4px; min-height: 42px; }

@media (max-width: 980px) {
  .platform-layout { grid-template-columns: 250px minmax(0, 1fr); }
  .workspace-grid { grid-template-columns: 1fr; }
  .assistant-section { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
  .assistant-section .section-heading { grid-column: 1 / -1; }
  .api-key-form { grid-template-columns: 1fr 1fr; }
  .customer-workspace { grid-template-columns: 1fr; overflow: auto; }
  .customer-workspace .chat-panel { min-height: 560px; }
}

@media (max-width: 720px) {
  .topbar { padding: 0 12px; }
  .role-chip, .user > strong { display: none; }
  .button-quiet { padding: 0 8px; }
  .platform-layout { display: block; }
  .tenant-pane { position: static; width: auto; height: auto; max-height: 52vh; border-right: 0; border-bottom: 1px solid var(--line); }
  .content-pane { padding: 14px; }
  .workspace-heading { align-items: flex-start; }
  .workspace-metrics { display: none; }
  .create-bar, .training-tools, .row-form { grid-template-columns: 1fr; }
  .api-key-form { grid-template-columns: 1fr; }
  .faq-composer { min-width: 0; }
  .assistant-section { display: block; }
  .assistant-section .section-heading { margin-top: 18px; }
  .customer-layout { height: calc(100vh - 58px); padding: 12px; }
  .customer-heading { align-items: flex-start; }
  .customer-controls { display: grid; justify-items: end; }
  .customer-controls select { width: 180px; }
  .safe-label { display: none; }
  .messages { padding: 12px; }
  .bubble { max-width: 92%; }
  .login-page { padding: 0; }
  .login-shell { min-height: 100vh; grid-template-columns: 1fr; border: 0; border-radius: 0; }
  .login-intro { min-height: 220px; padding: 26px; }
  .login-intro > div:nth-child(2) p:last-child, .login-footnote { display: none; }
  .login-intro h1 { margin-bottom: 0; font-size: 29px; }
  .login-card { padding: 30px 26px; }
}
