:root {
  --bg: #f2f5f9;
  --surface: #ffffff;
  --surface-alt: #edf3f8;
  --text: #142033;
  --muted: #64748b;
  --line: #d4dfeb;
  --primary: #087c96;
  --primary-strong: #075c70;
  --secondary: #475569;
  --success: #117a56;
  --warning: #9a6200;
  --danger: #b42318;
  --info: #1d4ed8;
  --focus: #36b4c7;
  --radius: 8px;
  --radius-sm: 6px;
  --shadow: 0 14px 34px rgba(15, 33, 51, .07);
  --space-1: .25rem;
  --space-2: .5rem;
  --space-3: .75rem;
  --space-4: 1rem;
  --space-5: 1.5rem;
  --space-6: 2rem;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.45;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; }
input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: .7rem .8rem;
  background: #fff;
  color: var(--text);
}
textarea { resize: vertical; min-height: 10rem; }
input:focus, select:focus, textarea:focus, button:focus-visible, a:focus-visible {
  outline: 3px solid rgba(108, 156, 255, .45);
  outline-offset: 2px;
}

.skip-link {
  position: absolute;
  top: -40px;
  left: 1rem;
  background: var(--primary);
  color: #fff;
  padding: .6rem .8rem;
  z-index: 30;
}
.skip-link:focus { top: 1rem; }

.app-shell { display: grid; grid-template-columns: 272px minmax(0, 1fr); min-height: 100vh; }
.sidebar {
  display: flex;
  flex-direction: column;
  background: #091525;
  color: #f5f8fb;
  padding: 1.25rem;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand {
  display: flex;
  gap: .8rem;
  align-items: center;
  margin-bottom: 2.25rem;
}
.brand.large { margin-bottom: var(--space-5); }
.brand-mark {
  display: block;
  width: 44px;
  height: 44px;
  flex: 0 0 44px;
  object-fit: cover;
  border: 1px solid rgba(89, 220, 239, .35);
  border-radius: 8px;
  background: #02060d;
}
.brand strong { display: block; letter-spacing: 0; }
.brand small, .muted { display: block; color: var(--muted); }
.sidebar .brand small { color: #91a5bb; margin-top: .15rem; }
.nav-list { display: grid; gap: .25rem; }
.nav-item {
  display: flex;
  align-items: center;
  gap: .7rem;
  padding: .72rem .8rem;
  border-radius: var(--radius-sm);
  color: #c9d6e5;
}
.nav-item:hover { background: #13253c; color: #fff; text-decoration: none; }
.nav-icon {
  width: .65rem;
  height: .65rem;
  border-radius: 999px;
  background: #28c4c6;
}
.sidebar-bottom { margin-top: auto; padding-top: 1.25rem; border-top: 1px solid rgba(180, 207, 232, .15); }
.main-shell { display: flex; flex-direction: column; min-width: 0; min-height: 100vh; }
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  padding: var(--space-5) var(--space-6);
  border-bottom: 1px solid var(--line);
  background: rgba(255,255,255,.94);
  backdrop-filter: blur(12px);
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar h1 { margin: .15rem 0 0; font-size: 1.55rem; letter-spacing: 0; }
.eyebrow { margin: 0; color: var(--muted); font-size: .82rem; text-transform: uppercase; letter-spacing: .08em; }
.topbar-actions, .button-row, .form-actions { display: flex; gap: .65rem; align-items: center; flex-wrap: wrap; }
.language-switch {
  display: inline-flex;
  align-items: center;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface-alt);
}
.sidebar-language { width: 100%; background: #0e2035; border-color: #25415e; }
.language-switch form { margin: 0; }
.sidebar-language form { flex: 1; }
.language-option {
  min-width: 36px;
  min-height: 30px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--secondary);
  font-size: .76rem;
  font-weight: 800;
  cursor: pointer;
}
.language-option.is-active { background: #fff; color: var(--primary-strong); box-shadow: 0 1px 2px rgba(31, 42, 55, .12); }
.sidebar-language .language-option { width: 100%; color: #c9d6e5; }
.sidebar-language .language-option.is-active { color: #082638; }
.content { flex: 1; padding: var(--space-6); display: grid; gap: var(--space-5); }
.app-footer {
  display: flex;
  justify-content: space-between;
  gap: var(--space-4);
  padding: 1rem var(--space-6) 1.25rem;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: .78rem;
}
.app-footer strong { color: var(--secondary); }

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: var(--space-5);
}
.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  margin-bottom: var(--space-4);
}
h2 { margin: 0 0 var(--space-3); font-size: 1.08rem; letter-spacing: 0; }
.section-head h2 { margin: 0; }

.metric-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: var(--space-4); }
.metric {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: var(--space-5);
  box-shadow: var(--shadow);
}
.metric span { display: block; font-size: 2rem; font-weight: 800; }
.metric p { margin: .2rem 0 0; color: var(--muted); }

.split-layout { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-5); }
.workspace-grid { display: grid; grid-template-columns: minmax(220px, 248px) minmax(0, 1fr); gap: var(--space-5); align-items: start; }
.insight-panel { grid-column: 2; }
.review-grid { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: var(--space-5); align-items: start; }
.editor-layout.single { max-width: 1100px; }

.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-4); }
.form-grid label, .stack label { display: grid; gap: .35rem; color: var(--secondary); font-weight: 650; }
.span-2 { grid-column: 1 / -1; }
.stack { display: grid; gap: var(--space-3); }
.full { width: 100%; justify-content: center; }

.button, button.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .45rem;
  min-height: 42px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: .6rem .9rem;
  cursor: pointer;
  font-weight: 700;
  text-decoration: none;
}
.button:hover { text-decoration: none; }
.button.primary { background: var(--primary); color: #fff; }
.button.primary:hover { background: var(--primary-strong); }
.button.secondary { background: var(--surface-alt); color: var(--text); border-color: var(--line); }
.button.ghost { background: transparent; border-color: var(--line); color: var(--text); }
.button.success { background: var(--success); color: #fff; }
.button.danger { background: var(--danger); color: #fff; }
.icon-button {
  display: inline-grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: #fff;
  cursor: pointer;
}
.icon-button svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: .22rem .55rem;
  font-size: .78rem;
  font-weight: 800;
  border: 1px solid transparent;
  white-space: nowrap;
}
.status-draft, .status-pending { background: #eef3f8; color: #3d4b5c; border-color: #d7e0ea; }
.status-validating, .status-under_review, .status-submitted, .status-retrieving, .status-generating { background: #e7f0ff; color: #2554a4; border-color: #c7d9ff; }
.status-correction_ready, .status-needs_employee_review, .status-returned { background: #fff4da; color: #8a5700; border-color: #f2d391; }
.status-approved, .status-active, .status-completed, .status-requires_review { background: #e5f7ee; color: #116447; border-color: #bde7d0; }
.status-rejected, .status-processing_failed, .status-retired { background: #ffe8e6; color: #a11f16; border-color: #ffc6c1; }
.status-archived { background: #eeeef4; color: #55566a; border-color: #d7d7e2; }

.alert {
  border-radius: var(--radius);
  border: 1px solid var(--line);
  padding: .85rem 1rem;
  background: #fff;
}
.messages { padding: var(--space-4) var(--space-6) 0; display: grid; gap: var(--space-2); }
.alert.success { border-color: #bde7d0; background: #eaf8f0; color: #116447; }
.alert.error { border-color: #ffc6c1; background: #fff0ef; color: var(--danger); }
.alert.warning { border-color: #f2d391; background: #fff8e8; color: var(--warning); }
.alert.info { border-color: #c7d9ff; background: #edf4ff; color: var(--info); }

.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); }
table { border-collapse: collapse; width: 100%; min-width: 760px; background: #fff; }
th, td { text-align: left; padding: .85rem 1rem; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: .78rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; background: #f8fafc; }
tr:last-child td { border-bottom: 0; }

.filter-bar { display: grid; grid-template-columns: minmax(220px, 1fr) 190px 160px auto auto; gap: var(--space-3); align-items: end; margin-bottom: var(--space-4); }
.filter-bar label { display: grid; gap: .3rem; color: var(--secondary); font-weight: 650; }

.item-list { display: grid; gap: .65rem; }
.item-list.compact { margin-top: var(--space-4); }
.list-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--space-3);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: .85rem 1rem;
  background: #fff;
}
.list-row:hover { text-decoration: none; border-color: #a7b7c9; }
.list-row.static:hover { border-color: var(--line); }
.list-row small { display: block; color: var(--muted); margin-top: .15rem; }
.empty-state {
  border: 1px dashed #b8c4d4;
  border-radius: var(--radius);
  padding: var(--space-5);
  color: var(--muted);
  background: #fbfcfe;
}

/* Local chat workspace */
.chat-workspace {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  min-height: calc(100vh - 178px);
  height: calc(100vh - 178px);
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: #fff;
  box-shadow: 0 16px 45px rgba(15, 33, 51, .08);
}
.chat-library {
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 1rem .75rem;
  background: #f5f7fa;
  border-right: 1px solid var(--line);
}
.chat-library-head { display: flex; justify-content: space-between; align-items: center; gap: .75rem; padding: .15rem .35rem .85rem; }
.chat-library-head > div { display: grid; gap: .12rem; min-width: 0; }
.chat-library-head strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-kicker { color: var(--muted); font-size: .68rem; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; }
.round-action, .composer-icon-button, .send-button, .icon-text-button {
  display: grid;
  place-items: center;
  border: 0;
  cursor: pointer;
  text-decoration: none;
}
.round-action { width: 34px; height: 34px; border-radius: 10px; background: var(--primary); color: #fff; font-size: 1.3rem; list-style: none; }
.round-action::-webkit-details-marker, .welcome-create > summary::-webkit-details-marker { display: none; }
.chat-create-popover { position: relative; }
.chat-popover-form {
  position: absolute;
  z-index: 20;
  top: 42px;
  right: 0;
  display: grid;
  gap: .7rem;
  width: 290px;
  padding: 1rem;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fff;
  box-shadow: 0 18px 45px rgba(15, 33, 51, .18);
}
.chat-popover-form.static { position: static; margin-top: .75rem; text-align: left; box-shadow: none; }
.chat-popover-form label, .chat-project-form label { display: grid; gap: .28rem; color: var(--secondary); font-size: .78rem; font-weight: 750; }
.chat-library-tools { padding: 0 .3rem .7rem; }
.project-create { padding-bottom: .65rem; border-bottom: 1px solid var(--line); }
.project-create summary { cursor: pointer; color: var(--primary); font-size: .8rem; font-weight: 800; }
.chat-project-form { display: grid; gap: .65rem; padding-top: .75rem; }
.chat-project-form textarea { min-height: 62px; }
.chat-thread-list { overflow-y: auto; display: grid; align-content: start; gap: 1rem; padding: .45rem .25rem 1rem; }
.project-group h2 {
  display: flex;
  align-items: center;
  gap: .45rem;
  margin: 0 0 .35rem;
  padding: 0 .45rem;
  color: #536274;
  font-size: .72rem;
  letter-spacing: .04em;
  text-transform: uppercase;
}
.project-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--primary); }
.project-dot.neutral { background: #99a6b5; }
.chat-thread-link {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: .55rem;
  padding: .62rem .7rem;
  border-radius: 10px;
  color: var(--text);
  font-size: .82rem;
}
.chat-thread-link:hover { background: #e9eef4; text-decoration: none; }
.chat-thread-link.is-active { background: #dfecef; color: #0b5f71; text-decoration: none; }
.chat-thread-link span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 650; }
.chat-thread-link small, .small-copy { color: var(--muted); font-size: .72rem; }
.chat-panel {
  display: grid;
  grid-template-rows: 66px minmax(0, 1fr) auto;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background: #fff;
}
.chat-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding: .75rem 1.35rem;
  border-bottom: 1px solid var(--line);
  background: rgba(255,255,255,.96);
}
.chat-heading { min-width: 0; }
.chat-heading h2 { margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 1rem; }
.chat-heading p { display: flex; gap: .4rem; margin: .15rem 0 0; color: var(--muted); font-size: .74rem; }
.icon-text-button { min-width: 36px; height: 34px; padding: 0 .65rem; border-radius: 9px; background: transparent; color: var(--muted); font-weight: 900; }
.icon-text-button:hover { background: var(--surface-alt); color: var(--text); }
.chat-messages {
  overflow-y: auto;
  min-height: 0;
  padding: 1.5rem clamp(1rem, 4vw, 3.5rem) 1rem;
  background: #fbfcfd;
}
.conversation-column { width: min(850px, 100%); min-height: 100%; margin: 0 auto; display: flex; flex-direction: column; gap: 1.35rem; }
.chat-message { display: grid; grid-template-columns: 34px minmax(0, 1fr); gap: .8rem; align-items: start; }
.chat-message.role-user { grid-template-columns: minmax(0, 1fr) 34px; width: min(720px, 92%); align-self: flex-end; }
.chat-message.role-user .message-avatar { grid-column: 2; grid-row: 1; }
.chat-message.role-user .message-body { grid-column: 1; grid-row: 1; justify-self: end; width: auto; max-width: 100%; background: #eaf3f5; border-radius: 16px 4px 16px 16px; padding: .78rem 1rem; }
.message-avatar {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  flex: 0 0 34px;
  border-radius: 999px;
  background: linear-gradient(145deg, #16748b, #0b5364);
  color: #fff;
  font-size: .72rem;
  font-weight: 850;
  box-shadow: 0 4px 10px rgba(12, 91, 109, .18);
}
.role-user .message-avatar { background: var(--secondary); }
.message-body {
  min-width: 0;
  width: 100%;
  padding-top: .12rem;
}
.message-meta { display: flex; align-items: center; gap: .55rem; margin-bottom: .35rem; }
.message-meta strong { font-size: .76rem; color: #435164; }
.message-meta time { color: #98a3af; font-size: .68rem; }
.role-user .message-meta { justify-content: flex-end; }
.message-content { margin: 0; overflow-wrap: anywhere; color: #233244; line-height: 1.65; }
.error-copy { color: var(--danger); }
.markdown-body > :first-child { margin-top: 0; }
.markdown-body > :last-child { margin-bottom: 0; }
.markdown-body p { margin: .55rem 0; }
.markdown-body h1, .markdown-body h2, .markdown-body h3, .markdown-body h4 { margin: 1.1rem 0 .45rem; color: #172a3d; line-height: 1.25; }
.markdown-body h1 { font-size: 1.35rem; } .markdown-body h2 { font-size: 1.18rem; } .markdown-body h3 { font-size: 1.04rem; }
.markdown-body ul, .markdown-body ol { margin: .55rem 0; padding-left: 1.4rem; }
.markdown-body li + li { margin-top: .22rem; }
.markdown-body blockquote { margin: .8rem 0; padding: .55rem .9rem; border-left: 3px solid var(--primary); background: #eef6f8; color: #46596b; }
.markdown-body pre { overflow-x: auto; margin: .8rem 0; padding: .9rem 1rem; border-radius: 12px; background: #182330; color: #e8edf4; line-height: 1.5; }
.markdown-body code { padding: .12rem .32rem; border-radius: 5px; background: #edf1f5; color: #9c2e50; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .88em; }
.markdown-body pre code { padding: 0; background: transparent; color: inherit; }
.markdown-body table { width: 100%; margin: .85rem 0; border-collapse: collapse; font-size: .88rem; }
.markdown-body th, .markdown-body td { padding: .5rem .65rem; border: 1px solid #dbe3eb; text-align: left; }
.markdown-body th { background: #eef3f7; }
.markdown-body a { overflow-wrap: anywhere; }
.markdown-body .katex-display { overflow-x: auto; overflow-y: hidden; padding: .25rem 0; }
.thinking-indicator { display: flex; gap: .28rem; padding-top: .55rem; }
.thinking-indicator i { width: 7px; height: 7px; border-radius: 50%; background: #7f909f; animation: chat-pulse 1.2s infinite ease-in-out; }
.thinking-indicator i:nth-child(2) { animation-delay: .15s; } .thinking-indicator i:nth-child(3) { animation-delay: .3s; }
@keyframes chat-pulse { 0%, 80%, 100% { opacity: .3; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-3px); } }
.attachment-list { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: .65rem; }
.attachment-chip { display: flex; align-items: center; gap: .55rem; max-width: 330px; padding: .55rem .7rem; border: 1px solid #cfdae5; border-radius: 10px; background: #fff; color: var(--text); }
.attachment-chip:hover { border-color: var(--primary); text-decoration: none; }
.attachment-chip > span:last-child { display: grid; min-width: 0; }
.attachment-chip strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .76rem; }
.attachment-chip small { color: var(--muted); font-size: .67rem; }
.attachment-icon { display: grid; place-items: center; width: 28px; height: 28px; flex: 0 0 28px; border-radius: 8px; background: #e6f1f3; color: var(--primary); font-weight: 900; }
.composer-wrap { padding: .75rem clamp(1rem, 4vw, 3.5rem) 1rem; background: linear-gradient(to top, #fff 78%, rgba(255,255,255,.7)); }
.chat-composer { width: min(850px, 100%); margin: 0 auto; padding: .62rem .7rem .55rem; border: 1px solid #cfd9e4; border-radius: 18px; background: #fff; box-shadow: 0 9px 28px rgba(22, 44, 66, .10); }
.chat-composer:focus-within { border-color: #75aeba; box-shadow: 0 0 0 3px rgba(23, 107, 135, .09), 0 9px 28px rgba(22, 44, 66, .10); }
.chat-composer textarea { min-height: 44px; max-height: 180px; padding: .45rem .55rem; resize: none; border: 0; box-shadow: none; background: transparent; line-height: 1.5; }
.chat-composer textarea:focus { outline: none; box-shadow: none; }
.composer-footer { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: .65rem; align-items: center; }
.composer-footer small { overflow: hidden; color: var(--muted); font-size: .68rem; text-overflow: ellipsis; white-space: nowrap; }
.composer-icon-button { width: 32px; height: 32px; border-radius: 9px; color: #455467; font-size: 1.2rem; }
.composer-icon-button:hover { background: var(--surface-alt); }
.composer-icon-button input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.send-button { width: 34px; height: 34px; border-radius: 10px; background: var(--primary); color: #fff; font-size: 1.15rem; font-weight: 900; }
.send-button:hover { background: var(--primary-strong); }
.selected-files { display: flex; flex-wrap: wrap; gap: .4rem; padding: .15rem .25rem .45rem; }
.selected-file { max-width: 220px; overflow: hidden; padding: .3rem .55rem; border-radius: 8px; background: #edf3f6; color: #455467; font-size: .72rem; text-overflow: ellipsis; white-space: nowrap; }
.chat-empty { margin: auto; text-align: center; color: var(--muted); max-width: 480px; }
.chat-empty.large { grid-row: 1 / -1; padding: var(--space-6); }
.empty-orb { display: grid; place-items: center; width: 54px; height: 54px; margin: 0 auto 1rem; border-radius: 17px; background: linear-gradient(145deg, #197991, #0b5263); color: #fff; font-weight: 900; box-shadow: 0 12px 28px rgba(12, 91, 109, .2); }
.welcome-create > summary { list-style: none; margin: 1rem auto 0; }
.sr-only { position: absolute !important; width: 1px !important; height: 1px !important; padding: 0 !important; margin: -1px !important; overflow: hidden !important; clip: rect(0,0,0,0) !important; white-space: nowrap !important; border: 0 !important; }

@media (max-width: 980px) {
  .chat-workspace { grid-template-columns: 230px minmax(0, 1fr); }
  .composer-footer small { display: none; }
}
@media (max-width: 720px) {
  .chat-workspace { grid-template-columns: 1fr; height: auto; min-height: 70vh; overflow: visible; }
  .chat-library { max-height: 310px; border-right: 0; border-bottom: 1px solid var(--line); }
  .chat-panel { min-height: 70vh; }
  .chat-messages { padding: 1rem; }
  .composer-wrap { padding: .65rem; }
  .message-avatar { display: none; }
  .chat-message, .chat-message.role-user { display: block; width: 100%; }
}

/* Chat uses a compact application rail so projects and conversations remain the primary navigation. */
.chat-page .app-shell { grid-template-columns: 74px minmax(0, 1fr); }
.chat-page .sidebar { padding: .85rem .55rem; align-items: stretch; }
.chat-page .brand { justify-content: center; margin-bottom: 1.35rem; }
.chat-page .brand span { display: none; }
.chat-page .brand-mark { width: 42px; height: 42px; flex-basis: 42px; }
.chat-page .nav-item { justify-content: center; min-height: 42px; padding: .65rem; font-size: 0; }
.chat-page .nav-icon { width: .72rem; height: .72rem; }
.chat-page .sidebar-language { display: grid; grid-template-columns: 1fr; gap: .15rem; }
.chat-page .topbar, .chat-page .app-footer { display: none; }
.chat-page .content { padding: .75rem; gap: 0; }
.chat-page .chat-workspace { min-height: calc(100vh - 1.5rem); height: calc(100vh - 1.5rem); }

@media (max-width: 720px) {
  .chat-page .app-shell { grid-template-columns: 1fr; }
  .chat-page .sidebar { display: none; }
  .chat-page .content { padding: 0; }
  .chat-page .chat-workspace { min-height: 100vh; height: auto; border: 0; border-radius: 0; }
}

.muted-copy { color: var(--muted); margin: .25rem 0 0; }
.catalog-upload-form {
  display: grid;
  grid-template-columns: minmax(260px, 1.4fr) minmax(180px, .65fr) minmax(210px, .8fr) minmax(260px, 1fr) auto;
  gap: var(--space-3);
  align-items: end;
}
.catalog-upload-form label { display: grid; gap: .35rem; color: var(--secondary); font-weight: 700; }
.catalog-upload-form .checkbox-label { grid-template-columns: 24px minmax(0, 1fr); align-items: center; }
.catalog-upload-form .checkbox-label span { grid-column: 2; grid-row: 1; }
.catalog-upload-form .checkbox-label input { grid-column: 1; grid-row: 1; width: 18px; height: 18px; }
.field-error { color: var(--danger); font-weight: 700; }
.progress-track.large { height: 14px; margin-bottom: var(--space-5); }
.catalog-meta { margin-top: var(--space-5); }
.path-value { overflow-wrap: anywhere; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .85rem; }
.inline-actions { display: flex; flex-wrap: wrap; gap: .4rem; }
.inline-actions form { margin: 0; }
.alert pre { white-space: pre-wrap; overflow-wrap: anywhere; font-size: .78rem; }
.status-queued { color: var(--secondary); }
.status-extracting, .status-analyzing, .status-exporting { color: var(--info); }
.status-completed { color: var(--success); }
.status-failed { color: var(--danger); }
.status-cancelled { color: var(--warning); }
@media (max-width: 1180px) {
  .catalog-upload-form { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 720px) {
  .catalog-upload-form { grid-template-columns: 1fr; }
}
.meta-list { display: grid; grid-template-columns: 1fr; gap: .3rem; margin: 0 0 var(--space-5); }
.meta-list.wide { grid-template-columns: 180px 1fr; }
.meta-list dt { color: var(--muted); font-size: .82rem; }
.meta-list dd { margin: 0 0 .55rem; font-weight: 650; }

.document-panel textarea { min-height: clamp(420px, 54vh, 700px); font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; line-height: 1.55; }
.document-text {
  white-space: pre-wrap;
  font-family: ui-serif, Georgia, serif;
  line-height: 1.65;
  margin: 0;
  color: #243041;
}
.autosave-indicator { color: var(--muted); font-size: .85rem; }
.tabs {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: .35rem;
  margin-bottom: var(--space-4);
}
.tab {
  min-width: 0;
  border: 1px solid var(--line);
  background: var(--surface-alt);
  border-radius: var(--radius-sm);
  padding: .6rem .45rem;
  cursor: pointer;
  font-weight: 700;
  line-height: 1.2;
  overflow-wrap: anywhere;
}
.tab.is-active { background: var(--primary); color: #fff; border-color: var(--primary); }
.finding-list { display: grid; gap: .65rem; }
.finding {
  border: 1px solid var(--line);
  border-left-width: 4px;
  border-radius: var(--radius);
  padding: .8rem;
  background: #fff;
}
.finding p { margin: .35rem 0 0; }
.finding small { display: block; margin-top: .45rem; color: var(--muted); }
.finding.error, .finding.critical { border-left-color: var(--danger); }
.finding.warning { border-left-color: var(--warning); }
.finding.info { border-left-color: var(--info); }
.rule-link { display: inline-flex; margin-top: .55rem; font-size: .84rem; font-weight: 750; }

.correction-activity { display: grid; gap: var(--space-4); }
.correction-activity .section-head { margin-bottom: 0; }
.progress-track { height: 8px; overflow: hidden; border-radius: 999px; background: #e6edf5; }
.progress-track span { display: block; width: 0; height: 100%; border-radius: inherit; background: var(--primary); transition: width .35s ease; }
.correction-stages { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: var(--space-2); padding: 0; margin: 0; list-style: none; }
.correction-stages li { display: grid; grid-template-columns: 24px minmax(0, 1fr); gap: .45rem; align-items: center; color: var(--muted); font-size: .8rem; }
.correction-stages .stage-step { display: grid; place-items: center; width: 24px; height: 24px; border: 1px solid #bdc9d8; border-radius: 50%; background: #fff; font-size: .73rem; font-weight: 800; }
.correction-stages li.is-current { color: var(--primary-strong); }
.correction-stages li.is-current .stage-step { border-color: var(--primary); background: var(--primary); color: #fff; box-shadow: 0 0 0 4px rgba(23, 107, 135, .12); }
.correction-stages li.is-complete { color: var(--success); }
.correction-stages li.is-complete .stage-step { border-color: var(--success); background: var(--success); color: #fff; }
.correction-stages li.is-failed { color: var(--danger); }
.correction-stages li.is-failed .stage-step { border-color: var(--danger); background: var(--danger); color: #fff; }
.correction-status-copy { font-weight: 750; }
.correction-history { display: flex; flex-wrap: wrap; gap: .4rem; }
.correction-history span { padding: .2rem .48rem; border: 1px solid var(--line); border-radius: 999px; color: var(--muted); font-size: .78rem; }
.correction-safe-note { margin: 0; }
.model-correction-form { display: grid; gap: .45rem; }
.model-correction-form label { color: var(--secondary); font-size: .82rem; font-weight: 750; }
.model-correction-form select { min-width: 0; background: #f8fbfd; }
.model-correction-form small { color: var(--muted); font-size: .76rem; line-height: 1.35; }

.diff-list { display: grid; gap: .35rem; }
.diff-line {
  display: grid;
  grid-template-columns: 92px minmax(0, 1fr);
  gap: .8rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  padding: .5rem .7rem;
}
.diff-line span { color: var(--muted); font-weight: 800; text-transform: uppercase; font-size: .74rem; }
.diff-line pre { margin: 0; white-space: pre-wrap; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.diff-line.added { background: #effaf4; border-color: #ccebd9; }
.diff-line.removed { background: #fff0ef; border-color: #ffd1cc; }
.diff-line.unchanged { background: #fbfcfe; }
.comparison-documents { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.comparison-document { min-width: 0; background: #fff; }
.comparison-document + .comparison-document { border-left: 1px solid var(--line); }
.document-label { display: flex; justify-content: space-between; gap: var(--space-3); padding: .75rem 1rem; border-bottom: 1px solid var(--line); font-size: .85rem; font-weight: 800; }
.document-label small { color: var(--muted); font-weight: 650; }
.comparison-document pre { min-height: 420px; margin: 0; padding: 1rem; white-space: pre-wrap; color: #243041; font-family: ui-serif, Georgia, serif; line-height: 1.65; }
.original-document .document-label { background: #fff7f5; color: #9a281e; }
.corrected-document .document-label { background: #effaf4; color: #116447; }
.change-summary-list { display: grid; gap: .55rem; margin-top: var(--space-4); }
.change-summary-list > div { display: grid; gap: .2rem; border-left: 3px solid var(--primary); padding-left: .75rem; }
.change-summary-list span { color: var(--secondary); }
.evidence-list { display: grid; gap: var(--space-3); }
.evidence-item { border-bottom: 1px solid var(--line); padding-bottom: var(--space-3); }
.evidence-item:last-child { border-bottom: 0; padding-bottom: 0; }
.evidence-meta { display: flex; justify-content: space-between; gap: var(--space-3); }
.evidence-meta span, .evidence-item small { color: var(--muted); font-size: .82rem; }
.evidence-item p { margin: .55rem 0 0; color: var(--secondary); white-space: pre-wrap; }

.pagination { display: flex; gap: var(--space-3); justify-content: flex-end; align-items: center; margin-top: var(--space-4); }
.inline-form { margin: 0; }

.login-body { min-height: 100vh; display: grid; place-items: center; background: #eef3f8; }
.login-layout { width: min(430px, calc(100% - 2rem)); }
.login-panel {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: var(--space-6);
}
.login-panel h1 { margin: 0 0 .35rem; }

@media (min-width: 1520px) {
  .workspace-grid { grid-template-columns: minmax(220px, 248px) minmax(460px, 1fr) minmax(320px, 360px); }
  .insight-panel { grid-column: auto; }
}
@media (max-width: 980px) {
  .workspace-grid, .review-grid { grid-template-columns: 1fr; }
  .insight-panel { grid-column: auto; }
  .meta-panel, .insight-panel { position: static; }
}
@media (max-width: 860px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; }
  .nav-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .topbar { position: static; padding: var(--space-4); align-items: flex-start; }
  .content, .messages { padding-left: var(--space-4); padding-right: var(--space-4); }
  .metric-grid, .split-layout, .form-grid { grid-template-columns: 1fr; }
  .span-2 { grid-column: auto; }
  .filter-bar { grid-template-columns: 1fr; }
  .correction-stages { grid-template-columns: 1fr; }
  .comparison-documents { grid-template-columns: 1fr; }
  .comparison-document + .comparison-document { border-left: 0; border-top: 1px solid var(--line); }
  .comparison-document pre { min-height: 260px; }
  .app-footer { padding: 1rem var(--space-4); flex-direction: column; }
}
@media (max-width: 520px) {
  .topbar-actions { width: 100%; }
  .topbar-actions .button { flex: 1; min-width: 0; }
  .tabs { grid-template-columns: 1fr; }
}
