:root {
  color-scheme: light;
  --ink: #152c26;
  --muted: #50635c;
  --accent: #145344;
  --accent-hover: #0c4235;
  --line: #dbe5de;
  --surface: #fff;
  --soft: #eef5f0;
  --page: #f5f7f2;
  --error: #792b22;
  font-family: system-ui, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--page);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; font-size: 15px; line-height: 1.55; }
h1, h2, p { margin: 0; }
h1 { font-size: clamp(1.8rem, 4vw, 2.75rem); line-height: 1.12; letter-spacing: -.035em; }
h2 { font-size: 1.12rem; line-height: 1.3; }
a { color: var(--accent); text-underline-offset: .16em; }
button, textarea, input, select { font: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid #2c795f; outline-offset: 3px; }

.shell { width: min(1320px, calc(100% - 48px)); margin-inline: auto; }
.site-header { background: var(--surface); border-bottom: 1px solid var(--line); }
.masthead { min-height: 70px; display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.header-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; align-items: center; gap: 8px; }
.header-link { display: inline-block; padding: 8px 13px; border: 1px solid var(--line); border-radius: 8px; font-weight: 650; text-decoration: none; }
.brand { display: flex; align-items: center; gap: 12px; line-height: 1.2; }
.brand span:not(.brand-mark) { display: block; margin-top: 3px; font-size: .78rem; color: var(--muted); }
.brand-mark { display: grid; place-items: center; width: 40px; height: 40px; border-radius: 11px; background: var(--accent); color: #fff; font-weight: 700; }
.choices { display: grid; gap: 8px; padding: 14px 18px; }

button { background: var(--accent); color: #fff; border: 1px solid transparent; border-radius: 8px; padding: 8px 13px; font-weight: 650; }
button:hover:not(:disabled) { background: var(--accent-hover); }
button:disabled { opacity: .62; cursor: default; }
.secondary { background: var(--surface); border-color: var(--line); color: var(--accent); }
.secondary:hover:not(:disabled) { background: var(--soft); border-color: #a8c4b7; }
.choice { background: var(--surface); color: var(--ink); border-color: var(--line); text-align: left; }
.choice:hover:not(:disabled) { background: var(--soft); border-color: #9abdad; }

.workspace-heading { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; margin: 30px 0 22px; }
.layout { display: grid; grid-template-columns: minmax(0, 1.22fr) minmax(0, 1fr); align-items: start; gap: 16px; }
.layout.chat-collapsed { grid-template-columns: minmax(0, 1fr); }
.layout.has-plan { grid-template-areas: "chat plan" "card plan"; grid-template-rows: auto 1fr; }
.layout.has-plan.chat-collapsed { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); grid-template-areas: "plan card"; grid-template-rows: auto; }
.has-plan #conversation { grid-area: chat; }
.has-plan #my-plan { grid-area: plan; }
.has-plan #chooser, .has-plan #case-details { grid-area: card; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 13px; overflow: hidden; }
.panel-heading { padding: 16px 18px; border-bottom: 1px solid var(--line); display: flex; align-items: start; justify-content: space-between; gap: 12px; }
.muted { color: var(--muted); font-size: .86rem; }
.compact { margin-top: 6px; }
.badge { padding: 3px 8px; border-radius: 12px; background: var(--soft); color: var(--accent); font-size: .76rem; font-weight: 650; white-space: nowrap; }
.notice { margin-top: 14px; padding: 10px 13px; border: 1px solid #efcdc4; border-radius: 8px; background: #fff3ee; color: var(--error); overflow-wrap: anywhere; }
#replace-note { margin-top: 3px; }

.messages { list-style: none; min-height: 170px; max-height: 41vh; overflow-y: auto; margin: 0; padding: 14px 18px; display: flex; flex-direction: column; gap: 10px; }
.message { align-self: start; max-width: 92%; border: 1px solid var(--line); background: var(--surface); border-radius: 10px; padding: 8px 12px; overflow-wrap: anywhere; }
.message.user { align-self: end; background: var(--soft); }
.message strong, .question strong { display: block; color: var(--accent); font-size: .77rem; margin-bottom: 2px; }
.message p, .question p, #result-text { white-space: pre-wrap; overflow-wrap: anywhere; }
.sources { display: flex; flex-wrap: wrap; gap: 5px 12px; margin-top: 7px; font-size: .84rem; }
.message-actions { display: flex; flex-wrap: wrap; gap: 7px; }
.message-actions button { margin-top: 8px; padding: 4px 8px; font-size: .82rem; }
.question { margin: 0 18px 14px; padding: 9px 12px; border-left: 3px solid #64a087; background: var(--soft); border-radius: 4px; }
.question button { margin-top: 7px; }
.composer, .result-content { padding: 14px 18px; }
.composer { border-top: 1px solid var(--line); }
label { display: block; font-weight: 650; margin-bottom: 4px; }
textarea, input, select { display: block; width: 100%; padding: 8px 10px; background: var(--surface); border: 1px solid #aebfb6; border-radius: 8px; color: var(--ink); }
textarea { resize: vertical; min-height: 82px; }
.actions { display: flex; justify-content: flex-end; align-items: center; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.actions #example { margin-right: auto; }

.sidebar { display: grid; gap: 14px; min-width: 0; }
.fields { max-height: 46vh; overflow-y: auto; }
.field-group + .field-group { border-top: 1px solid var(--line); }
summary { cursor: pointer; padding: 10px 18px; font-weight: 650; }
.field-row { border-top: 1px solid var(--line); padding: 9px 16px 10px 18px; display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.field-label { display: block; font-size: .82rem; font-weight: 650; }
.field-value { display: block; overflow-wrap: anywhere; }
.field-source { display: block; font-size: .77rem; color: var(--muted); }
.field-edit { padding: 4px 7px; font-size: .79rem; }
.field-edit:focus, #confirm:focus { outline: 3px solid #2c795f; outline-offset: 2px; }
.result-content #confirm { margin-top: 12px; }
.documents { display: grid; gap: 7px; margin-top: 10px; }
.documents:empty { display: none; }
.download { text-align: left; }

.plan-content { overflow-wrap: anywhere; }
.plan-content h3 { font-size: 1rem; line-height: 1.35; margin: 0 0 8px; }
.plan-section { padding: 14px 16px; }
.plan-section + .plan-section { border-top: 1px solid var(--line); }
.plan-summary { font-weight: 650; }
.plan-next { background: var(--soft); }
.plan-content ol, .plan-content ul { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.plan-content .plan-conditions { list-style: disc; padding-inline-start: 1.1em; margin-top: 8px; gap: 3px; }
.plan-content .plan-row { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 4px 10px; }
.plan-row > :first-child { min-width: 0; }
.plan-card { border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; }
.plan-state { font-size: .78rem; font-weight: 650; color: var(--muted); }
.plan-state[data-status="ready"], .plan-state[data-status="done"] { color: var(--accent); }
.plan-state[data-status="review"] { color: var(--error); }
.plan-detail { margin-top: 3px; }
.plan-content dl { margin: 0; }
.plan-content dl > div + div { margin-top: 6px; }
.plan-content dt { font-weight: 650; }
.plan-content dd { margin: 0; }
.plan-estimate[data-assessment="conditional"] { background: #fbf7ea; }
.plan-estimate[data-assessment="calculated"] { background: var(--soft); }
.plan-estimate dl, .plan-document dl { margin-top: 8px; }
.plan-calculation-detail summary { padding: 8px 0 0; }
.plan-facts summary { padding: 0; }
.plan-facts[open] summary { padding-bottom: 8px; }
.plan-missing summary { padding: 0 0 7px; }
.plan-missing button { text-align: left; font-size: .83rem; padding: 5px 9px; }
.plan-actions { display: flex; flex-wrap: wrap; align-items: flex-start; gap: 7px; margin-top: 7px; }
.plan-actions button { font-size: .83rem; padding: 5px 9px; }
.plan-actions .sources { margin-top: 0; }
.plan-request { border-top: 1px solid var(--line); margin-top: 8px; }
.plan-request summary { padding: 8px 0 3px; }
.plan-request .request-text { white-space: pre-wrap; font-size: .85rem; }
.plan-request [role="status"] { margin-top: 5px; }
#plan-status { white-space: normal; text-align: right; }

dialog { width: min(500px, calc(100% - 30px)); border: 1px solid var(--line); border-radius: 12px; padding: 18px; color: var(--ink); box-shadow: 0 12px 50px #162b2633; }
dialog::backdrop { background: #172d2870; }
dialog h2 { margin-bottom: 12px; }
dialog #edit-hint { margin-top: 7px; }
.site-footer { padding: 20px 0; color: var(--muted); font-size: .82rem; }

@media (min-width: 1200px) {
  .layout.has-plan:not(.chat-collapsed) {
    grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr) minmax(0, 1fr);
    grid-template-areas: "chat plan card";
    grid-template-rows: auto;
  }
}

@media (max-width: 825px) {
  .layout { grid-template-columns: 1fr; }
  .layout.has-plan { grid-template-areas: "chat" "plan" "card"; grid-template-rows: auto; }
  .layout.has-plan.chat-collapsed { grid-template-columns: minmax(0, 1fr); grid-template-areas: "plan" "card"; }
  .fields { max-height: 52vh; }
}

@media (max-width: 520px) {
  .shell { width: calc(100% - 24px); }
  .masthead { min-height: 62px; }
  .brand-mark { display: none; }
  .message { max-width: 100%; }
}
