:root {
  color-scheme: light;
  --bg: #f4f2ee;
  --panel: #ffffff;
  --ink: #1a1d21;
  --muted: #68707a;
  --line: #d8d4cc;
  --strong-line: #9f9589;
  --accent: #245b4f;
  --accent-soft: #e5f0ec;
  --warn: #8a5a00;
  font-family: Arial, Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  background: var(--bg);
  color: var(--ink);
  margin: 0;
}

.topbar {
  align-items: center;
  background: #fff;
  border-bottom: 1px solid var(--line);
  display: flex;
  gap: 20px;
  justify-content: space-between;
  padding: 20px clamp(16px, 4vw, 42px);
}

.brand {
  color: var(--accent);
  font-size: 0.82rem;
  font-weight: 800;
  letter-spacing: 0;
  margin: 0 0 6px;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  font-size: clamp(1.8rem, 4vw, 3.2rem);
  line-height: 1;
  margin-bottom: 0;
}

h2 {
  font-size: 1.08rem;
  margin-bottom: 6px;
}

p {
  color: var(--muted);
  line-height: 1.45;
  margin-bottom: 0;
}

main {
  display: grid;
  gap: 16px;
  margin: 0 auto;
  max-width: 1300px;
  padding: 18px clamp(12px, 3vw, 30px) 40px;
}

.status {
  background: var(--accent);
  border-radius: 6px;
  color: #fff;
  font-size: 0.9rem;
  font-weight: 700;
  max-width: 420px;
  min-width: 190px;
  padding: 10px 12px;
  text-align: right;
}

.panel,
.summary-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}

.panel {
  padding: 18px;
}

.section-heading {
  align-items: start;
  display: flex;
  gap: 16px;
  justify-content: space-between;
  margin-bottom: 16px;
}

.judgment-form {
  align-items: end;
  display: grid;
  gap: 12px;
  grid-template-columns: minmax(180px, 1fr) auto minmax(190px, 240px) auto;
}

.compact-field {
  min-width: 0;
}

.ai-model-field select {
  width: 100%;
}

.template-manager {
  display: grid;
  gap: 12px;
  grid-template-columns: minmax(0, 1.3fr) minmax(280px, 0.7fr);
}

.template-editor-card {
  align-items: end;
  background: #f8f7f4;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 12px;
  grid-template-columns: minmax(220px, 1.2fr) minmax(180px, 0.8fr) minmax(160px, 0.65fr) auto auto;
  padding: 14px;
}

#add-template-form {
  grid-template-columns: 1fr;
}

#template-select,
#template-name,
#template-jurisdiction,
#new-template-name,
#new-template-jurisdiction,
#new-template-file {
  min-height: 40px;
  width: 100%;
}

label {
  display: grid;
  gap: 6px;
}

label span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
}

input,
button,
select,
textarea {
  background: #fff;
  border: 1px solid var(--strong-line);
  border-radius: 6px;
  color: var(--ink);
  font: inherit;
  min-height: 42px;
  padding: 9px 11px;
}

button {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  cursor: pointer;
  font-weight: 800;
  white-space: nowrap;
}

.link-button {
  align-items: center;
  display: inline-flex;
  justify-content: center;
  min-height: 42px;
  padding: 9px 11px;
  text-decoration: none;
  white-space: nowrap;
}

button:disabled {
  background: #9aa39f;
  border-color: #9aa39f;
  cursor: progress;
}

.danger-button {
  background: #b33a3a;
  border-color: #b33a3a;
  color: #fff;
}

.danger-button:hover {
  background: #942f2f;
  border-color: #942f2f;
}

.secondary-button {
  background: #fff;
  border-color: var(--strong-line);
  color: var(--ink);
}

input:focus,
button:focus-visible {
  outline: 3px solid var(--accent-soft);
  outline-offset: 2px;
}

.toggle {
  align-items: center;
  background: var(--accent-soft);
  border: 1px solid var(--line);
  border-radius: 6px;
  display: flex;
  gap: 8px;
  min-height: 42px;
  padding: 9px 11px;
}

.toggle input {
  min-height: auto;
}

.summary-grid {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(4, minmax(180px, 1fr));
}

.summary-card {
  display: grid;
  gap: 8px;
  min-height: 112px;
  padding: 14px;
}

.summary-card span,
.flow-item span {
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 800;
  text-transform: uppercase;
}

.summary-card strong {
  font-size: 0.98rem;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.flow-grid {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(3, minmax(180px, 1fr));
}

.flow-item {
  background: #f8f7f4;
  border: 1px solid var(--line);
  border-radius: 6px;
  display: grid;
  gap: 7px;
  padding: 12px;
}

.flow-item strong {
  font-size: 0.95rem;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.params-list {
  display: grid;
  gap: 8px;
}

.param-row {
  align-items: center;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 6px;
  display: grid;
  gap: 12px;
  grid-template-columns: 22px minmax(150px, 0.28fr) minmax(180px, 0.32fr) minmax(220px, 1fr);
  min-height: 48px;
  padding: 9px 12px;
}

.param-row.learned {
  border-color: #7aa68f;
  box-shadow: inset 3px 0 0 #4c8a68;
}

.param-row input {
  min-height: auto;
  padding: 0;
}

.param-row strong {
  font-size: 0.92rem;
  font-weight: 700;
  overflow-wrap: anywhere;
}

.param-value-cell {
  align-items: stretch;
  display: grid;
  gap: 6px;
  min-width: 0;
}

.param-label {
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 700;
  line-height: 1.25;
}

.learning-badge {
  background: #e8f2ee;
  border: 1px solid #c7ddd1;
  border-radius: 999px;
  color: #2c6b4d;
  display: inline-block;
  font-size: 0.68rem;
  margin-left: 6px;
  padding: 2px 6px;
  text-transform: none;
}

.param-key,
.param-value {
  border-radius: 4px;
  cursor: text;
  min-height: 28px;
  padding: 4px 6px;
}

.param-key {
  background: #f8f7f4;
  border: 1px solid var(--line);
  color: #46505a;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 0.82rem;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.param-key:hover,
.param-value:hover {
  background: var(--accent-soft);
}

.param-value.empty {
  color: #9a6a16;
  font-style: italic;
  font-weight: 600;
}

.param-candidates {
  background: #f8f7f4;
  border: 1px solid var(--line);
  border-radius: 4px;
  color: var(--ink);
  font-size: 0.82rem;
  min-height: 30px;
  min-width: 0;
  padding: 4px 8px;
  width: 100%;
}

.param-edit {
  min-height: 34px;
  padding: 6px 8px;
  width: 100%;
}

.param-key-edit {
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 0.86rem;
}

.lex-fields {
  display: grid;
  gap: 12px;
}

#lex-panel[data-collapsed="true"] .section-heading {
  margin-bottom: 0;
}

#lex-panel[data-collapsed="true"] .lex-fields {
  display: none;
}

.collapse-toggle {
  align-items: center;
  display: inline-flex;
  gap: 8px;
  min-height: 36px;
  padding: 7px 10px;
}

.collapse-chevron {
  border-bottom: 2px solid currentColor;
  border-right: 2px solid currentColor;
  display: inline-block;
  height: 8px;
  transform: rotate(45deg);
  transition: transform 140ms ease;
  width: 8px;
}

#lex-panel[data-collapsed="false"] .collapse-chevron {
  transform: rotate(225deg);
}

.lex-group {
  background: #f8f7f4;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 10px;
  padding: 12px;
}

.lex-group h3 {
  font-size: 0.9rem;
  margin: 0;
}

.lex-field-grid {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(3, minmax(180px, 1fr));
}

.lex-field {
  min-width: 0;
}

.lex-field.wide {
  grid-column: span 3;
}

.lex-field input,
.lex-field select,
.lex-field textarea {
  border-color: var(--line);
  min-height: 38px;
  width: 100%;
}

.lex-field textarea {
  resize: vertical;
}

.learning-layout {
  align-items: start;
  display: grid;
  gap: 16px;
  grid-template-columns: minmax(300px, 0.9fr) minmax(280px, 0.7fr);
}

.learning-form {
  background: #f8f7f4;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 12px;
  padding: 14px;
}

.learning-form textarea {
  resize: vertical;
  width: 100%;
}

.learning-form textarea[readonly] {
  background: #efede8;
  color: #46505a;
}

.learning-actions {
  align-items: end;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: space-between;
}

.learning-actions .compact-toggle {
  min-width: 180px;
}

.learning-history {
  align-content: start;
  align-self: start;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  grid-template-rows: auto auto;
  min-height: 0;
}

.learning-history-header {
  align-items: center;
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  padding: 12px 14px;
}

.learning-history-header span,
.learning-detail-grid p span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.learning-rules-list {
  align-content: start;
  display: grid;
  gap: 5px;
  grid-auto-rows: max-content;
  max-height: 260px;
  overflow: auto;
  padding: 8px;
}

.learning-rule {
  align-self: start;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 6px;
  display: grid;
  overflow: hidden;
}

.learning-rule-row {
  align-items: center;
  display: flex;
  gap: 6px;
  min-height: 38px;
  padding: 4px 6px;
}

.learning-expand {
  align-items: center;
  background: transparent;
  border: 0;
  color: var(--ink);
  display: grid;
  flex: 1;
  gap: 7px;
  grid-template-columns: 12px minmax(118px, 0.55fr) minmax(120px, 1fr);
  min-height: 30px;
  min-width: 0;
  padding: 0;
  text-align: left;
}

.learning-expand:hover {
  background: transparent;
}

.learning-chevron {
  border-bottom: 2px solid #6b7280;
  border-right: 2px solid #6b7280;
  display: inline-block;
  height: 7px;
  margin-left: 2px;
  transform: rotate(-45deg);
  transition: transform 140ms ease;
  width: 7px;
}

.learning-rule[data-expanded="true"] .learning-chevron {
  transform: rotate(45deg);
}

.learning-rule-title {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.learning-rule-title strong {
  font-size: 0.82rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.learning-rule code {
  color: #46505a;
  font-size: 0.72rem;
  line-height: 1.2;
  overflow-wrap: anywhere;
}

.learning-rule-summary {
  align-items: center;
  color: #46505a;
  display: flex;
  font-size: 0.76rem;
  gap: 8px;
  min-width: 0;
}

.learning-rule-summary span {
  flex: 1 1 0;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.learning-rule-summary span:first-child::after {
  color: #9aa39f;
  content: " ->";
}

.learning-rule-summary span:last-child {
  color: #276749;
  font-weight: 700;
}

.learning-rule-actions {
  align-items: center;
  display: flex;
  gap: 4px;
}

.learning-icon-button {
  align-items: center;
  background: #f8f7f4;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: #46505a;
  display: inline-flex;
  height: 28px;
  justify-content: center;
  min-height: 28px;
  padding: 0;
  position: relative;
  width: 28px;
}

.learning-icon-button:hover {
  background: #efede8;
}

.learning-icon-button.trash {
  background: #fff8f7;
  border-color: #e2c4bd;
  color: #9a3a31;
}

.learning-icon-button.trash span::before {
  border: 2px solid currentColor;
  border-top: 0;
  border-radius: 0 0 3px 3px;
  content: "";
  height: 10px;
  left: 8px;
  position: absolute;
  top: 11px;
  width: 10px;
}

.learning-icon-button.trash span::after {
  background: currentColor;
  border-radius: 1px;
  box-shadow: 3px -3px 0 -1px currentColor;
  content: "";
  height: 2px;
  left: 7px;
  position: absolute;
  top: 8px;
  width: 14px;
}

.learning-icon-button.edit span::before {
  background: currentColor;
  border-radius: 2px;
  content: "";
  height: 4px;
  left: 8px;
  position: absolute;
  top: 12px;
  transform: rotate(-35deg);
  width: 13px;
}

.learning-icon-button.edit span::after {
  border-bottom: 2px solid currentColor;
  border-left: 2px solid currentColor;
  content: "";
  height: 5px;
  left: 7px;
  position: absolute;
  top: 16px;
  width: 11px;
}

.learning-icon-button.trash:hover {
  background: #f8ebe8;
  border-color: #c9887d;
}

.learning-rule-details {
  background: #f8f7f4;
  border-top: 1px solid var(--line);
  display: none;
  gap: 8px;
  padding: 8px;
}

.learning-rule[data-expanded="true"] .learning-rule-details {
  display: grid;
}

.learning-detail-grid {
  display: grid;
  gap: 6px;
}

.learning-detail-grid p {
  font-size: 0.82rem;
  line-height: 1.35;
  margin: 0;
  overflow-wrap: anywhere;
}

.learning-detail-grid p span {
  display: block;
  margin-bottom: 2px;
}

.learning-rule .learning-note {
  color: #46505a;
}

.learning-edit-form {
  border-top: 1px solid var(--line);
  display: none;
  gap: 8px;
  padding-top: 10px;
}

.learning-rule.is-editing .learning-edit-form {
  display: grid;
}

.learning-edit-form textarea {
  min-height: 64px;
  resize: vertical;
}

.learning-edit-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

.learning-edit-actions button {
  min-height: 34px;
  padding: 6px 10px;
}

.empty-learning {
  color: var(--muted);
  margin: 0;
  padding: 8px 2px;
}

#preview-panel.panel,
#template-editor-panel.panel {
  background: rgba(47, 50, 53, 0.58);
  border: 0;
  border-radius: 0;
  box-shadow: none;
  display: grid;
  inset: 0;
  padding: 24px;
  place-items: center;
  position: fixed;
  z-index: 950;
}

#preview-panel.hidden,
#template-editor-panel.hidden {
  display: none;
}

#preview-panel > .section-heading,
#preview-panel > .editor-toolbar,
#preview-panel > .editor-with-chat,
#template-editor-panel > .section-heading,
#template-editor-panel > .editor-toolbar,
#template-editor-panel > .docx-preview {
  max-width: 1280px;
  width: min(100%, 1280px);
}

.preview-heading {
  background: #fff;
  border: 1px solid var(--line);
  border-bottom: 0;
  border-radius: 8px 8px 0 0;
  margin: 0;
  padding: 18px;
}

.preview-actions {
  align-items: center;
  display: flex;
  gap: 10px;
}

.docx-options {
  align-items: end;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
}

.docx-options label {
  display: grid;
  gap: 6px;
  min-width: 190px;
}

.docx-options label:has(#manual-template) {
  min-width: min(360px, 100%);
}

.docx-options .compact-toggle {
  align-items: center;
  align-self: end;
  display: flex;
  gap: 8px;
  min-height: 42px;
  min-width: 210px;
}

.docx-options .compact-toggle input {
  min-height: auto;
  padding: 0;
  width: auto;
}

.docx-options span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
}

.docx-options select {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--ink);
  min-height: 40px;
  padding: 8px 10px;
}

.editor-toolbar {
  align-items: center;
  background: #f8f7f4;
  border: 1px solid var(--line);
  border-bottom: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 10px 18px;
}

.toolbar-group {
  align-items: center;
  border-right: 1px solid var(--line);
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  padding-right: 8px;
}

.toolbar-group:last-child {
  border-right: 0;
}

.editor-tool {
  align-items: center;
  background: #fff;
  border-color: var(--line);
  color: var(--ink);
  display: inline-flex;
  justify-content: center;
  min-height: 34px;
  min-width: 38px;
  padding: 6px 8px;
}

.editor-select {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--ink);
  font-size: 0.85rem;
  min-height: 34px;
  padding: 5px 8px;
}

.editor-select.small-select {
  min-width: 68px;
}

.color-tool {
  align-items: center;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--ink);
  display: inline-flex;
  font-size: 0.82rem;
  font-weight: 800;
  gap: 5px;
  min-height: 34px;
  padding: 4px 7px;
}

.color-tool input {
  border: 0;
  height: 22px;
  padding: 0;
  width: 24px;
}

.docx-preview {
  background: #fff;
  border: 1px solid var(--strong-line);
  border-radius: 0 0 8px 8px;
  color: var(--ink);
  font: 0.98rem/1.55 Georgia, "Times New Roman", serif;
  min-height: min(62vh, 620px);
  max-height: 62vh;
  overflow: auto;
  padding: 22px;
  resize: vertical;
  white-space: pre-wrap;
}

.docx-preview:focus {
  outline: 3px solid var(--accent-soft);
  outline-offset: 2px;
}

.editor-with-chat,
.template-editor-with-chat {
  align-items: stretch;
  display: grid;
  gap: 14px;
  grid-template-columns: minmax(0, 1fr) 330px;
  min-height: 0;
}

.editor-with-chat .docx-preview {
  max-height: 68vh;
  min-height: min(68vh, 760px);
}

.assistant-chat {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 8px 26px rgba(20, 24, 28, 0.12);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  min-height: 360px;
  overflow: hidden;
}

.assistant-chat-header {
  border-bottom: 1px solid var(--line);
  display: grid;
  gap: 3px;
  padding: 14px;
}

.assistant-chat-header strong {
  font-size: 0.95rem;
}

.assistant-chat-header span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
}

.assistant-chat-messages {
  align-content: start;
  display: grid;
  gap: 8px;
  overflow: auto;
  padding: 12px;
}

.assistant-chat-message {
  border-radius: 8px;
  font-size: 0.86rem;
  line-height: 1.35;
  overflow-wrap: anywhere;
  padding: 9px 10px;
  white-space: pre-wrap;
}

.assistant-chat-message.user {
  background: #e8f2ee;
  justify-self: end;
  max-width: 92%;
}

.assistant-chat-message.assistant {
  background: #f6f4ef;
  justify-self: start;
  max-width: 96%;
}

.assistant-chat-message.error {
  background: #fdeeee;
  color: #8f1f1f;
}

.assistant-chat-form {
  border-top: 1px solid var(--line);
  display: grid;
  gap: 8px;
  padding: 12px;
}

.assistant-chat-form textarea {
  min-height: 92px;
  resize: vertical;
  width: 100%;
}

.assistant-chat-form button {
  width: 100%;
}

.hidden {
  display: none;
}

.loading-overlay {
  align-items: center;
  background: rgba(47, 50, 53, 0.58);
  backdrop-filter: grayscale(0.8) blur(3px);
  display: flex;
  inset: 0;
  justify-content: center;
  padding: 20px;
  position: fixed;
  z-index: 1000;
}

.loading-overlay.hidden {
  display: none;
}

.loading-panel {
  background: rgba(255, 255, 255, 0.96);
  border: 1px solid rgba(255, 255, 255, 0.72);
  border-radius: 8px;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.26);
  display: grid;
  gap: 16px;
  max-width: 520px;
  padding: 26px;
  width: min(100%, 520px);
}

.loading-animation {
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(4, 1fr);
  height: 74px;
  overflow: hidden;
}

.loading-animation span {
  animation: loading-wave 1.08s ease-in-out infinite;
  background: linear-gradient(180deg, #245b4f 0%, #d7a642 100%);
  border-radius: 6px;
  transform-origin: bottom;
}

.loading-animation span:nth-child(2) {
  animation-delay: 0.12s;
}

.loading-animation span:nth-child(3) {
  animation-delay: 0.24s;
}

.loading-animation span:nth-child(4) {
  animation-delay: 0.36s;
}

.loading-copy {
  display: grid;
  gap: 6px;
}

.loading-kicker {
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.loading-copy h2 {
  font-size: 1.45rem;
  margin: 0;
}

.loading-progress {
  background: #e2ded6;
  border-radius: 999px;
  height: 9px;
  overflow: hidden;
}

.loading-progress div {
  background: linear-gradient(90deg, #245b4f, #d7a642);
  border-radius: inherit;
  height: 100%;
  transition: width 360ms ease;
  width: 8%;
}

.loading-steps {
  display: grid;
  gap: 8px;
  list-style: none;
  margin: 0;
  padding: 0;
}

.loading-steps li {
  align-items: center;
  color: var(--muted);
  display: grid;
  font-size: 0.9rem;
  gap: 10px;
  grid-template-columns: 18px 1fr;
}

.loading-steps li::before {
  background: #c8c2b8;
  border-radius: 50%;
  content: "";
  height: 10px;
  justify-self: center;
  width: 10px;
}

.loading-steps li.active {
  color: var(--ink);
  font-weight: 800;
}

.loading-steps li.active::before {
  animation: loading-pulse 900ms ease-in-out infinite;
  background: var(--accent);
  box-shadow: 0 0 0 6px rgba(36, 91, 79, 0.14);
}

.loading-steps li.done {
  color: #41524c;
}

.loading-steps li.done::before {
  background: #d7a642;
}

body.is-loading {
  overflow: hidden;
}

body.is-modal-open {
  overflow: hidden;
}

.models-page {
  background: #eceff1;
  min-height: 100vh;
  overflow: hidden;
}

.models-topbar {
  align-items: center;
  background: #fff;
  border-bottom: 1px solid var(--line);
  display: flex;
  gap: 18px;
  height: 74px;
  justify-content: space-between;
  padding: 12px 18px;
}

.models-topbar h1 {
  font-size: 1.32rem;
  line-height: 1.1;
}

.models-topbar-actions {
  align-items: center;
  display: flex;
  gap: 10px;
}

.models-workbench {
  display: grid;
  gap: 0;
  grid-template-columns: 340px minmax(0, 1fr);
  height: calc(100vh - 74px);
  margin: 0;
  max-width: none;
  padding: 0;
}

.models-sidebar {
  background: #fff;
  border-right: 1px solid var(--line);
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  min-width: 0;
  overflow: hidden;
}

.sidebar-heading {
  align-items: start;
  border-bottom: 1px solid var(--line);
  display: flex;
  gap: 10px;
  justify-content: space-between;
  padding: 16px;
}

.sidebar-heading h2,
.new-model-panel h2 {
  font-size: 0.98rem;
  margin: 0 0 4px;
}

.icon-text-button {
  min-height: 34px;
  padding: 6px 9px;
}

.model-search-wrap {
  border-bottom: 1px solid var(--line);
  padding: 12px 16px;
}

.model-search-wrap input {
  width: 100%;
}

.models-list {
  display: grid;
  gap: 6px;
  overflow: auto;
  padding: 10px;
}

.model-list-item {
  background: #fff;
  border: 1px solid transparent;
  color: var(--ink);
  display: grid;
  gap: 5px;
  min-height: auto;
  padding: 10px;
  text-align: left;
  white-space: normal;
}

.model-list-item:hover,
.model-list-item.active {
  background: var(--accent-soft);
  border-color: #b9d3c8;
}

.model-list-item strong {
  font-size: 0.86rem;
  line-height: 1.25;
}

.model-list-item span {
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 700;
}

.new-model-panel {
  border-top: 1px solid var(--line);
  display: grid;
  gap: 10px;
  padding: 14px 16px 16px;
}

.document-workspace {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  min-width: 0;
  overflow: hidden;
}

.document-meta-bar {
  align-items: end;
  background: #fff;
  border-bottom: 1px solid var(--line);
  display: grid;
  gap: 10px;
  grid-template-columns: minmax(240px, 1fr) minmax(170px, 240px) auto auto auto;
  padding: 12px 16px;
}

.model-title-field {
  min-width: 0;
}

.word-toolbar {
  align-items: center;
  background: #f8f7f4;
  border-bottom: 1px solid var(--line);
  display: flex;
  gap: 6px;
  min-height: 48px;
  overflow-x: auto;
  padding: 7px 16px;
}

.toolbar-field {
  align-items: center;
  display: flex;
  gap: 6px;
  min-width: 170px;
}

.toolbar-field-small {
  min-width: 120px;
}

.toolbar-field span {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
}

.toolbar-field select {
  min-height: 34px;
  padding: 5px 8px;
}

.document-canvas {
  background: #dfe4e7;
  overflow: auto;
  padding: 26px;
}

.template-editor-with-chat {
  align-items: start;
}

.model-doc-editor {
  background: #fff;
  box-shadow: 0 8px 28px rgba(20, 24, 28, 0.16);
  color: var(--ink);
  font: 11pt/1.15 Arial, sans-serif;
  margin: 0 auto;
  min-height: 1120px;
  max-width: 920px;
  outline: none;
  padding: 72px;
  width: min(100%, 920px);
}

.template-chat {
  max-height: calc(100vh - 190px);
  min-height: 520px;
  position: sticky;
  top: 0;
}

.model-doc-editor:focus {
  box-shadow: 0 8px 28px rgba(20, 24, 28, 0.16), 0 0 0 3px var(--accent-soft);
}

.model-doc-editor table {
  border-collapse: collapse;
  width: 100%;
}

.model-doc-editor td {
  border: 1px solid var(--line);
  padding: 6px;
}

@keyframes loading-wave {
  0%,
  100% {
    transform: scaleY(0.34);
  }

  50% {
    transform: scaleY(1);
  }
}

@keyframes loading-pulse {
  0%,
  100% {
    transform: scale(0.88);
  }

  50% {
    transform: scale(1.1);
  }
}

@media (max-width: 900px) {
  .topbar,
  .models-topbar,
  .section-heading {
    display: grid;
    height: auto;
  }

  .status {
    max-width: none;
    text-align: left;
  }

  .models-page {
    overflow: auto;
  }

  .models-topbar-actions,
  .document-meta-bar {
    align-items: stretch;
    grid-template-columns: 1fr;
  }

  .models-workbench {
    grid-template-columns: 1fr;
    height: auto;
  }

  .models-sidebar {
    border-right: 0;
    max-height: none;
  }

  .models-list {
    max-height: 320px;
  }

  .document-canvas {
    padding: 12px;
  }

  .model-doc-editor {
    min-height: 720px;
    padding: 28px;
  }

  .editor-with-chat,
  .template-editor-with-chat {
    grid-template-columns: 1fr;
  }

  .assistant-chat,
  .template-chat {
    max-height: none;
    min-height: 320px;
    position: static;
  }

  .judgment-form,
  .template-manager,
  .template-editor-card,
  .summary-grid,
  .flow-grid,
  .lex-field-grid,
  .learning-layout,
  .param-row {
    grid-template-columns: 1fr;
  }

  .lex-field.wide {
    grid-column: auto;
  }
}
