:root {
  color-scheme: light;
  --ink: #111111;
  --muted: #666666;
  --paper: #ffffff;
  --panel: #ffffff;
  --line: #dddddd;
  --accent: #c41230;
  --accent-dark: #9e0e27;
  --green: #2f7556;
  --warning: #666666;
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
}

@media (max-width: 480px) {
  .login-shell { min-height: 100dvh; place-items: start center; padding: 16px; }
  .login-card { border-radius: 22px; }
  .login-card .subtle, .field-hint, .auth-switch { font-size: 16px; }
}

* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; color: var(--ink); background: var(--paper); }
button, input, textarea { font: inherit; }
button { cursor: pointer; }
button:focus-visible { outline: 3px solid var(--accent-dark); outline-offset: 3px; }
[hidden] { display: none !important; }

.login-shell { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: var(--paper); }
.login-card { width: min(440px, 100%); padding: 40px; border: 1px solid var(--line); border-radius: 28px; background: var(--panel); box-shadow: 0 24px 70px rgba(0,0,0,.08); }
.login-card h1 { margin: 8px 0 14px; font-size: clamp(30px, 5vw, 48px); line-height: 1.05; letter-spacing: -.05em; }
.login-card h1 span { display: block; }
.auth-heading { display: grid; gap: 6px; }
.auth-heading h2, .auth-heading p { margin: 0; }
.auth-heading h2 { font-size: 24px; letter-spacing: -.025em; }
.eyebrow { margin: 0; color: var(--accent); font-size: 12px; font-weight: 800; letter-spacing: .14em; text-transform: uppercase; }
.subtle { color: var(--muted); font-size: 14px; line-height: 1.6; }
.stack { display: grid; gap: 16px; margin-top: 28px; }
label { display: grid; gap: 7px; font-size: 13px; font-weight: 700; }
input, textarea { width: 100%; min-height: 44px; border: 1px solid var(--line); border-radius: 14px; padding: 13px 14px; color: var(--ink); background: white; outline: none; }
input:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(196,18,48,.12); }
.primary, .ghost, .nav-item { min-height: 44px; border: 0; border-radius: 999px; padding: 11px 18px; font-weight: 750; }
.primary { color: white; background: var(--accent); }
.primary:hover { background: var(--accent-dark); }
.primary:disabled { cursor: not-allowed; opacity: .5; }
.ghost { color: var(--ink); background: transparent; border: 1px solid var(--line); }
.error { min-height: 20px; margin: 0; color: #b42318; font-size: 13px; }
.field-hint { color: var(--muted); font-size: 12px; font-weight: 500; line-height: 1.5; }
.auth-switch { margin: -8px 0 0; color: var(--muted); font-size: 14px; text-align: center; }
.text-button { display: inline-flex; align-items: center; min-height: 44px; border: 0; padding: 6px; color: var(--accent-dark); background: transparent; font-weight: 750; text-decoration: underline; text-underline-offset: 3px; }
.login-card .primary { background: var(--accent-dark); }
.login-card .primary:hover { background: #7a0b1e; }
.password-field { display: flex; align-items: center; gap: 8px; margin-top: -10px; }
.password-field input { min-width: 0; flex: 1; }
.password-field button { flex-shrink: 0; white-space: nowrap; }
.remember-login { display: flex; align-items: center; gap: 8px; }
.remember-login input { width: 20px; min-height: 20px; height: 20px; margin: 0; }
.password-reset-dialog { width: min(440px, calc(100vw - 32px)); padding: 26px; border: 1px solid var(--line); border-radius: 20px; color: var(--ink); line-height: 1.6; }
.password-reset-dialog::backdrop { background: rgba(0,0,0,.4); }
.demo-entry { display: inline-block; margin-top: 18px; color: var(--accent-dark); font-size: 14px; font-weight: 750; }

.app-shell { min-height: 100vh; }
.topbar { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 18px 30px; border-bottom: 1px solid var(--line); background: rgba(255,255,255,.96); backdrop-filter: blur(18px); }
.topbar h1 { margin: 4px 0 0; font-size: 22px; }
.top-actions { display: flex; align-items: center; gap: 10px; }
.badge, .status { display: inline-flex; align-items: center; border-radius: 999px; padding: 6px 10px; font-size: 12px; font-weight: 750; }
.badge { color: var(--green); background: #e2f0e8; }
.status.warning { color: var(--warning); background: #f2f2f2; }
.status.ready { color: var(--green); background: #e2f0e8; }
.status.danger { color: #b42318; background: #fee4e2; }

.workspace { display: grid; grid-template-columns: 210px minmax(0, 1fr); min-height: calc(100vh - 79px); }
.side-nav { display: flex; flex-direction: column; gap: 8px; padding: 24px 18px; border-right: 1px solid var(--line); }
.nav-item { display: flex; align-items: center; text-align: left; text-decoration: none; color: var(--muted); background: transparent; }
.nav-item.active { color: var(--ink); background: white; box-shadow: inset 3px 0 var(--accent); }
.content-pane { width: min(100%, 1080px); padding: 36px; }
.hero-panel { padding: 42px; border: 1px solid var(--ink); border-radius: 28px; color: var(--ink); background: var(--panel); }
.hero-panel h2 { max-width: 650px; margin: 8px 0 12px; font-size: clamp(26px, 3.5vw, 40px); line-height: 1.05; letter-spacing: -.045em; }
.hero-panel h2 span + span::before { content: " "; }
.hero-panel p:not(.eyebrow) { max-width: 630px; color: var(--muted); line-height: 1.7; }
.metric-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 14px; margin-top: 18px; }
.metric { padding: 20px; border: 1px solid var(--line); border-radius: 18px; background: var(--panel); }
.metric strong { display: block; margin-top: 8px; font-size: 30px; }
.metric span { color: var(--muted); font-size: 13px; }
.training-launch { display: flex; align-items: center; justify-content: space-between; gap: 24px; margin-top: 18px; padding: 22px; border: 1px solid var(--line); border-radius: 22px; background: var(--panel); }
.training-launch h3 { margin: 6px 0; font-size: 23px; }
.training-launch p:not(.eyebrow) { margin: 0; color: var(--muted); line-height: 1.6; }
.training-links { display: grid; flex: 0 0 220px; gap: 8px; }
.training-links a { padding: 11px 14px; border-radius: 999px; color: var(--ink); background: var(--paper); font-size: 13px; font-weight: 750; text-align: center; text-decoration: none; }
.training-links a:hover { color: white; background: var(--accent); }
.section-heading { display: flex; align-items: center; justify-content: space-between; gap: 18px; margin-bottom: 22px; }
.section-heading h2 { margin: 5px 0 0; font-size: 32px; letter-spacing: -.035em; }
/* The conversation and composer share one readable column. */
.chat-panel { max-width: 820px; margin: 0 auto; }
.chat-heading { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 24px; }
.chat-heading h2 { margin: 8px 0 0; font-size: clamp(26px, 3vw, 34px); letter-spacing: -.04em; }
.chat-heading .subtle { margin: 8px 0 0; }
.chat-heading .status { flex-shrink: 0; font-size: 12px; }
.chat-toolbar { display: grid; gap: 10px; padding-bottom: 18px; border-bottom: 1px solid #ececee; }
.chat-toolbar-row { display: grid; grid-template-columns: auto minmax(0, 1fr) auto auto; align-items: center; gap: 12px; }
.chat-toolbar label { color: var(--muted); font-size: 12px; font-weight: 500; }
#conversationSelect { width: 100%; min-width: 0; max-width: 100%; min-height: 44px; padding: 10px 28px 10px 12px; border: 1px solid #e5e5e7; border-radius: 10px; font: inherit; font-size: 14px; color: var(--ink); background: white; }
#newConversationButton { min-height: 44px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; color: var(--ink); background: #fff; white-space: nowrap; font-size: 14px; }
#newConversationButton:hover { background: #ececee; }
.font-controls { display: flex; align-items: center; justify-content: flex-end; gap: 6px; color: var(--muted); font-size: 13px; }
.font-controls button { min-width: 44px; min-height: 44px; border: 1px solid var(--line); border-radius: 10px; color: var(--ink); background: white; font: inherit; font-weight: 800; cursor: pointer; }
.font-controls button:disabled { cursor: not-allowed; opacity: .45; }
.font-controls output { min-width: 44px; color: var(--ink); text-align: center; font-variant-numeric: tabular-nums; }
.message-list { display: flex; flex-direction: column; gap: 26px; min-height: 320px; max-height: 52dvh; overflow: auto; overscroll-behavior: contain; padding: 28px 4px; scrollbar-width: thin; }
.message { max-width: min(720px, 92%); min-width: 0; white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.85; font-size: var(--chat-font-size, 18px); }
.message.customer { align-self: flex-end; padding: 14px 18px; color: #27272b; background: #fff; border: 1px solid var(--line); border-radius: 18px 18px 4px 18px; }
.message.assistant { align-self: flex-start; padding: 4px 12px 4px 16px; border-left: 2px solid var(--accent); }
.message-meta { display: block; margin-top: 8px; color: #747478; font-size: 12px; line-height: 1.5; }
.message details { margin-top: 12px; font-size: 13px; color: var(--muted); }
.message summary { cursor: pointer; min-height: 32px; }
.message .record { white-space: normal; font-size: 13px; margin-top: 8px; padding: 12px; border-color: #ececee; border-radius: 10px; }
.message-actions { display: flex; gap: 8px; margin-top: 8px; }
.message-actions button { min-height: 44px; padding: 8px 12px; border: 1px solid var(--line); border-radius: 9px; color: var(--ink); background: white; font: inherit; font-size: 13px; cursor: pointer; }
.message-actions button:disabled { cursor: wait; opacity: .6; }
.chat-welcome { width: 100%; margin: auto; padding: 14px 12px 22px; text-align: center; }
.chat-mark { display: block; color: var(--accent); font-size: 46px; line-height: 1; font-family: sans-serif; }
.chat-welcome h3 { margin: 18px 0 8px; font-size: 23px; font-weight: 650; letter-spacing: -.03em; }
.chat-welcome p { margin: 0; font-size: 14px; line-height: 1.7; color: var(--muted); }
.chat-suggestions { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-top: 24px; }
.chat-suggestions button { min-height: 44px; padding: 10px 14px; border: 1px solid #e5e5e7; border-radius: 10px; background: white; color: #49494e; font-size: 13px; }
.chat-suggestions button:hover { border-color: var(--accent); color: var(--accent); }
.composer { padding: 8px 16px 12px; border: 1px solid #d6d6db; border-radius: 18px; background: white; box-shadow: 0 6px 24px rgba(20,20,30,.04); transition: border-color .15s, box-shadow .15s; }
.composer:focus-within { border-color: #a7a7b0; box-shadow: 0 6px 24px rgba(20,20,30,.07); }
.composer textarea { display: block; min-height: 86px; max-height: 180px; resize: none; padding: 14px 2px; border: 0; border-radius: 0; box-shadow: none; background: transparent; font-size: var(--chat-font-size, 18px); line-height: 1.7; }
.composer textarea::placeholder { color: #818188; }
.composer textarea:disabled { color: #666; -webkit-text-fill-color: #666; opacity: 1; }
.composer-footer { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 10px; }
#messageKeyboardHint { color: #77777f; font-size: 12px; line-height: 1.5; }
#messageStatus { min-width: 0; overflow-wrap: anywhere; }
.chat-status { min-height: 26px; margin: 12px 4px 0; font-size: 13px; }
#sendButton { display: flex; align-items: center; justify-content: center; gap: 12px; flex-shrink: 0; min-width: 90px; min-height: 44px; border-radius: 11px; white-space: nowrap; }
#sendButton span { font-size: 20px; line-height: 1; }
.upload-card { display: grid; gap: 14px; padding: 22px; border: 1px dashed #bdbdbd; border-radius: 20px; background: var(--panel); }
.progress-track { height: 7px; overflow: hidden; border-radius: 999px; background: #ececec; }
.progress-track span { display: block; width: 0; height: 100%; background: var(--accent); transition: width .18s; }
.record-list { display: grid; gap: 10px; margin-top: 18px; }
.record { padding: 15px; border: 1px solid var(--line); border-radius: 16px; background: var(--panel); }
.record strong { display: block; margin-bottom: 5px; }
.record small { color: var(--muted); }
.empty-state { padding: 70px 24px; border: 1px dashed var(--line); border-radius: 24px; text-align: center; }
.empty-state h2 { font-size: 34px; }

.diagnosis-layout { display: grid; grid-template-columns: minmax(320px, .8fr) minmax(0, 1.2fr); gap: 24px; align-items: start; }
.diagnosis-form { display: grid; gap: 16px; padding: 22px; border: 1px solid var(--line); border-radius: 22px; background: var(--panel); }
.form-intro h3 { margin: 0 0 8px; font-size: 22px; }
.form-intro p { margin: 0; color: var(--muted); font-size: 14px; line-height: 1.6; }
.date-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.confirm-row { display: flex; align-items: flex-start; gap: 10px; color: var(--muted); font-weight: 500; line-height: 1.5; }
.confirm-row input { width: auto; margin-top: 3px; accent-color: var(--accent); }
.diagnosis-output { min-width: 0; }
.diagnosis-output > .record-list { margin-top: 0; }
.diagnosis-metrics { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.diagnosis-metrics > div { min-width: 0; padding: 16px; border: 1px solid var(--line); border-radius: 16px; background: var(--panel); }
.diagnosis-metrics span { display: block; color: var(--muted); font-size: 12px; }
.diagnosis-metrics strong { display: block; margin-top: 6px; font-size: 24px; overflow-wrap: anywhere; }
.diagnosis-metrics strong + span { margin-top: 8px; }
.diagnosis-evidence { min-width: 0; padding: 0 15px; border: 1px solid var(--line); border-radius: 16px; overflow-wrap: anywhere; }
.diagnosis-evidence > summary { min-height: 44px; padding: 12px 0; cursor: pointer; font-weight: 700; }
.diagnosis-evidence > summary:focus-visible { outline: 3px solid var(--accent-dark); outline-offset: 3px; }
.diagnosis-evidence > .record { margin-bottom: 10px; }
.claim-list { display: grid; gap: 9px; }
.audit-pass { border-left: 4px solid var(--green); }
.audit-block { border-left: 4px solid #b42318; }
.ghost.compact { margin-top: 12px; padding: 7px 12px; font-size: 12px; }

.owner-workspace { padding: 36px; }
.owner-summary, .owner-knowledge, .owner-security, .owner-detail { max-width: 1200px; margin: 0 auto; }
.owner-summary h2 { margin: 6px 0; font-size: 42px; letter-spacing: -.045em; }
.tenant-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; margin-top: 24px; }
.tenant-card { padding: 20px; border: 1px solid var(--line); border-radius: 20px; background: var(--panel); text-align: left; }
.tenant-card:hover { border-color: var(--accent); }
.tenant-card h3 { margin: 0 0 12px; }
.tenant-card dl { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 0; color: var(--muted); font-size: 13px; }
.tenant-card dd { margin: 0; color: var(--ink); font-weight: 800; }
.owner-detail { margin-top: 32px; padding-top: 30px; border-top: 1px solid var(--line); }
.owner-knowledge { margin-top: 32px; padding: 28px; border: 1px solid var(--line); border-radius: 22px; background: var(--panel); }
.owner-knowledge .section-heading { margin-bottom: 8px; }
.owner-knowledge .metric-grid { grid-template-columns: repeat(4, 1fr); }
.boundary-list { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 18px; }
.boundary-list .record { border-left: 4px solid var(--warning); }
.knowledge-search { display: grid; gap: 10px; margin-top: 22px; padding-top: 22px; border-top: 1px solid var(--line); }
.knowledge-guard { margin: 10px 0 0; padding-top: 10px; border-top: 1px solid var(--line); color: var(--muted); font-size: 13px; line-height: 1.55; }
.owner-security { margin-top: 32px; padding: 28px; border: 1px solid var(--line); border-radius: 22px; background: var(--panel); }
.owner-security .section-heading { margin-bottom: 8px; }
.reason-row { display: flex; gap: 10px; }
.reason-row button { white-space: nowrap; }
.owner-columns { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }

@media (max-width: 800px) {
  .topbar { padding: 14px 16px; }
  .topbar .eyebrow, #roleBadge { display: none; }
  .workspace { display: block; padding-bottom: 76px; }
  .side-nav { position: fixed; z-index: 20; right: 0; bottom: 0; left: 0; flex-direction: row; justify-content: space-around; gap: 0; padding: 6px; border: 0; border-top: 1px solid var(--line); background: rgba(255,255,255,.98); }
  .nav-item { flex: 1; justify-content: center; min-width: 0; min-height: 48px; padding: 9px 1px; text-align: center; font-size: 13px; line-height: 1.1; white-space: nowrap; }
  .nav-item.active { box-shadow: inset 0 3px var(--accent); }
  .content-pane, .owner-workspace { padding: 20px 14px; }
  .hero-panel { padding: 28px 22px; }
  .hero-panel h2 { font-size: clamp(26px, 3.5vw, 32px); line-height: 1.08; }
  .hero-panel h2 span { display: block; }
  .hero-panel h2 span + span::before { content: none; }
  .hero-panel p:not(.eyebrow), .form-intro p, .record > div, label { font-size: 16px; }
  .record small { font-size: 14px; }
  .metric-grid { grid-template-columns: 1fr 1fr; }
  .training-launch { align-items: stretch; flex-direction: column; }
  .training-links { flex-basis: auto; }
  .diagnosis-layout { grid-template-columns: 1fr; }
  .date-grid { grid-template-columns: 1fr; }
  .section-heading { align-items: flex-start; flex-direction: column; }
  .message-list { max-height: 55vh; }
  .tenant-grid, .owner-columns, .owner-knowledge .metric-grid, .boundary-list { grid-template-columns: 1fr; }
  .reason-row { flex-direction: column; }
  .owner-security .subtle, .owner-knowledge .subtle, .knowledge-guard { font-size: 16px; }
  .login-card { padding: 28px 22px; }
}

#operatingEntryStatus { margin: 16px 20px; }
#diagnosisForm { scroll-margin-top: 100px; }
.form-intro details { margin-top: 12px; }
.form-intro summary { cursor: pointer; }
.form-intro li { margin: 8px 0; }
.form-intro pre { white-space: pre-wrap; overflow-wrap: anywhere; }
 .message-sources { display: flex; align-items: center; flex-wrap: wrap; gap: 8px 12px; padding: 10px 0; border-bottom: 1px solid #efeff1; font-size: 12px; line-height: 1.6; }
#messageSourceNames { flex: 1 1 180px; min-width: 0; overflow-wrap: anywhere; color: #66666e; }
.message-source-actions { display: flex; flex-wrap: wrap; gap: 4px; margin-left: auto; }
.message-source-actions .ghost.compact { margin-top: 0; }
.message-source-actions button { min-height: 44px; padding: 8px 10px; border: 0; border-radius: 8px; font-size: 12px; color: #53535b; white-space: nowrap; }
.message-source-actions button:hover { background: #f5f5f6; }
#clearMessageSources { color: var(--accent-dark); }
@media (max-width: 600px) {
  .chat-heading { gap: 10px; align-items: flex-start; margin-bottom: 18px; }
  .chat-heading .status { margin-top: 4px; }
  .chat-heading .subtle { font-size: 13px; }
  .chat-toolbar { gap: 8px; padding-bottom: 14px; }
  .chat-toolbar-row { grid-template-columns: minmax(0, 1fr) auto; gap: 8px; }
  .chat-toolbar label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
  .chat-toolbar-row #conversationSelect { grid-column: 1 / -1; grid-row: 1; }
  .chat-toolbar-row #refreshConversationButton { grid-column: 1; grid-row: 2; }
  .chat-toolbar-row #newConversationButton { grid-column: 2; grid-row: 2; }
  .font-controls { justify-content: flex-start; }
  .message-list { min-height: 280px; max-height: 48dvh; gap: 22px; padding: 22px 0; }
  .message { max-width: 96%; }
  .chat-welcome { padding: 12px 0; }
  .chat-welcome h3 { font-size: 21px; }
  .chat-suggestions { margin-top: 18px; gap: 7px; }
  .chat-suggestions button { font-size: 12px; padding: 10px; }
  .composer { padding: 6px 12px 12px; border-radius: 16px; }
  #messageSourceNames { flex-basis: 100%; }
  .message-source-actions { margin-left: 0; }
  #messageKeyboardHint { max-width: 145px; font-size: 11px; }
}
@media (prefers-reduced-motion: reduce) { .composer { transition: none; } }

.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
.chat-status:empty { display: none; }
.chat-status { margin: 4px 0 8px; }
.composer { scroll-margin-bottom: 90px; }
@media (max-width: 800px) {
  html { scroll-padding-bottom: 90px; }
  .message-list { min-height: 240px; }
  #messageStatus { scroll-margin-bottom: 110px; }
}
