:root {
  --bg: #f6f4ef; --card: #ffffff; --ink: #1d232b; --muted: #5b6672; --line: #d9d4ca;
  --accent: #23527c; --accent-ink: #ffffff; --urgent: #a12b1f; --urgent-bg: #fbe9e6;
  --high: #8a5a00; --high-bg: #fdf3dc; --ok: #2f6b3a; --ok-bg: #e5f2e7; --soft: #eef2f6;
  --fs: 18px;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #14181d; --card: #1d232b; --ink: #edf0f3; --muted: #a7b1bb; --line: #333c46; --accent: #7fb2e5; --accent-ink: #0d1217; --urgent: #ff9b8f; --urgent-bg: #3a1d1a; --high: #f2c46b; --high-bg: #362b14; --ok: #8fd19c; --ok-bg: #1b3020; --soft: #232b34; }
}
* { box-sizing: border-box; }
html { font-size: var(--fs); }
body.big { --fs: 23px; }
body { margin: 0; background: var(--bg); color: var(--ink); font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; line-height: 1.5; }
[hidden] { display: none !important; }
.top { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 12px 16px; background: var(--card); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 2; flex-wrap: wrap; }
.brand { font-weight: 700; font-size: 1.15rem; }
.brand span { color: var(--accent); }
.tools { display: flex; gap: 8px; flex-wrap: wrap; }
main { max-width: 980px; margin: 0 auto; padding: 16px; }
.foot { max-width: 980px; margin: 24px auto; padding: 0 16px 32px; color: var(--muted); font-size: 0.85rem; }
h1 { font-size: 1.5rem; margin: 0.4em 0; }
h2 { font-size: 1.2rem; margin: 1.2em 0 0.4em; }
h3 { font-size: 1.05rem; margin: 0.6em 0 0.3em; }
p { margin: 0.4em 0; }
.muted { color: var(--muted); }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; margin: 12px 0; }
.problem-dialog { color: var(--ink); max-width: min(94vw, 620px); max-height: 90vh; overflow: auto; }
.problem-dialog::backdrop { background: rgba(0, 0, 0, 0.6); }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 12px; }
button, .btnlink { font: inherit; border-radius: 10px; border: 1px solid var(--accent); background: var(--accent); color: var(--accent-ink); padding: 10px 16px; cursor: pointer; min-height: 44px; text-decoration: none; display: inline-flex; align-items: center; }
button.ghost, .btnlink.ghost { background: transparent; color: var(--accent); }
button.small { padding: 4px 10px; min-height: 34px; font-size: 0.9rem; }
button:disabled { opacity: 0.5; cursor: default; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, a:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
label { display: block; font-weight: 600; margin: 10px 0 4px; }
input, select, textarea { font: inherit; width: 100%; padding: 10px 12px; border-radius: 8px; border: 1px solid var(--line); background: var(--card); color: var(--ink); }
textarea { min-height: 90px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-top: 10px; }
.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin: 8px 0 4px; }
.tabs button { background: var(--soft); color: var(--ink); border-color: var(--line); }
.tabs button[aria-selected="true"] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.badge { display: inline-block; border-radius: 999px; padding: 1px 10px; font-size: 0.8rem; font-weight: 600; background: var(--soft); color: var(--muted); margin-right: 6px; }
.badge.urgent { background: var(--urgent-bg); color: var(--urgent); }
.badge.high { background: var(--high-bg); color: var(--high); }
.card.ok { border-color: var(--ok); }
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.item { border-top: 1px solid var(--line); padding: 10px 0; }
.item:first-child { border-top: 0; }
.err { color: var(--urgent); background: var(--urgent-bg); padding: 10px 12px; border-radius: 8px; margin: 8px 0; }
.note { background: var(--soft); padding: 10px 12px; border-radius: 8px; margin: 8px 0; }
ul.plain { margin: 0.3em 0; padding-left: 1.2em; }
table { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
th, td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
.code { font-family: ui-monospace, monospace; font-size: 1.3rem; letter-spacing: 0.08em; background: var(--soft); padding: 8px 12px; border-radius: 8px; display: inline-block; }
.q4 h3 { margin-top: 0; }
@media print {
  .top, .tabs, .row, button, .foot { display: none !important; }
  body { background: #fff; color: #000; }
  .card { border: 0; padding: 0; }
  .no-print { display: none !important; }
}
.reading { border-left: 3px solid var(--line, #ccc); padding-left: 0.75rem; margin-top: 0.5rem; }
.pagetext { white-space: pre-wrap; word-break: break-word; font: inherit; margin: 0.25rem 0 0; }
.steps { padding-left: 1.4rem; }
.steps li { margin: 0.35rem 0; }
button.linklike { background: none; border: 0; padding: 0; color: var(--accent, #1d5fa8); text-decoration: underline; font: inherit; cursor: pointer; min-height: 0; }
fieldset { border: 1px solid var(--line); border-radius: 8px; margin: 0.5rem 0; }
.block { padding: 6px 0; border-top: 1px dashed var(--line); }
.block:first-child { border-top: 0; }
.block p.missing { color: var(--urgent); font-weight: 600; }
.card.urgent { border-color: var(--urgent); }

/* Research (section 7) */
.opinion { max-height: 24rem; overflow-y: auto; white-space: pre-wrap; border: 1px solid var(--line, #ccc); padding: .75rem; border-radius: .5rem; font-family: Georgia, serif; line-height: 1.5; }
blockquote { margin: .5rem 0; padding: .25rem .75rem; border-left: 4px solid var(--accent, #2a5db0); font-family: Georgia, serif; }
.context { white-space: pre-wrap; font-family: Georgia, serif; }
.context mark { background: #fff3a0; color: #000; }
.card.next { border-left: 6px solid var(--accent); }
.card.next h2 { margin-top: 0; }
.talk-log p { margin: 6px 0; padding: 8px 10px; border-radius: 8px; white-space: pre-wrap; }
.talk-log p.judy { background: var(--soft); }
.choices { display: grid; gap: 8px; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.choices button { padding: 14px; text-align: left; }
.choices button.urgent { background: var(--urgent); color: #fff; }

/* Conversation-first workspace. Case data stays in the existing tools. */
:root { --accent: #236257; --accent-ink: #fff; }
.settings-menu { position: relative; font-size: .85rem; }
summary { cursor: pointer; padding: 10px 0; }
.settings-menu > summary { padding: 8px 12px; min-height: 44px; }
.settings-menu[open] .tools { position: absolute; right: 0; top: 100%; width: min(340px, 90vw); padding: 12px; background: var(--card); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 10px 28px #0002; z-index: 10; }
.top { padding: 10px 24px; }
main.workspace { display: grid; grid-template-columns: 230px minmax(0, 1fr); max-width: 1500px; padding: 0; min-height: calc(100dvh - 150px); }
.case-sidebar { position: sticky; top: 76px; align-self: start; max-height: calc(100dvh - 76px); overflow-y: auto; background: var(--card); border-right: 1px solid var(--line); padding: 24px 16px; min-width: 0; }
.sidebar-label { font-size: .65rem; letter-spacing: .14em; font-weight: 700; color: var(--muted); }
.case-title { font-size: .92rem; line-height: 1.5; margin: 8px 4px 4px; overflow-wrap: anywhere; }
.case-details { font-size: .75rem; margin: 0 4px 16px; overflow-wrap: anywhere; }
.case-list { display: grid; gap: 4px; margin: 12px 0 20px; max-height: 35dvh; overflow-y: auto; }
.case-list button { font-size: .82rem; text-align: left; border: 0; color: var(--ink); overflow-wrap: anywhere; }
.case-list button[aria-current="true"] { background: var(--soft); font-weight: 650; }
.case-sidebar > button { width: 100%; justify-content: center; margin-bottom: 20px; }
.case-tools { border-top: 1px solid var(--line); margin-top: 20px; font-size: .8rem; color: var(--muted); }
.case-sidebar .case-tools .tabs { flex-direction: column; }
.active-case-name { font-size: .8rem; color: var(--muted); margin: 0 0 12px; }
.new-case { max-width: 560px; margin: 32px auto; }
@media (max-width: 760px) {
  .case-list { max-height: 130px; margin: 8px 0; }
  .case-sidebar > button { margin-bottom: 4px; width: auto; }
  .case-tools { margin-top: 8px; }
}
.workspace-tabs { display: flex; flex-direction: column; gap: 6px; }
.case-sidebar .tabs button { width: 100%; justify-content: flex-start; text-align: left; border: 0; background: transparent; font-size: .88rem; padding: 10px 12px; }
.case-sidebar .tabs button[aria-selected="true"] { background: var(--soft); color: var(--accent); font-weight: 650; }
.case-sidebar .tabs button[aria-expanded] { color: var(--muted); margin-top: 12px; }
.sidebar-bottom { border-top: 1px solid var(--line); margin-top: 24px; padding-top: 12px; font-size: .75rem; }
.sidebar-bottom button { font-size: .88rem; border: 0; }
.workspace-content { min-width: 0; padding: 24px 32px; }
.workspace-heading { display: flex; gap: 12px; align-items: center; justify-content: space-between; flex-wrap: wrap; }
.chat-workspace { max-width: 840px; margin: 0 auto; }
.chat-form { margin: 0; }
.chat-welcome { text-align: center; padding: 40px 16px 28px; }
.chat-welcome h1 { font-size: clamp(1.6rem, 3vw, 2.15rem); font-weight: 600; letter-spacing: -.035em; }
.chat-welcome p { max-width: 490px; margin: 12px auto; }
.judith-mark { display: grid; place-items: center; width: 48px; height: 48px; background: var(--soft); color: var(--accent); border-radius: 16px; margin: 0 auto 20px; font: 600 1.5rem Georgia, serif; }
.chat-starters { grid-template-columns: repeat(3, minmax(0, 1fr)); margin: 0 auto 24px; gap: 10px; }
.chat-starters button { font-size: .85rem; border-color: var(--line); background: var(--card); color: var(--ink); justify-content: center; }
.chat-composer { position: sticky; bottom: 12px; background: var(--card); border: 1px solid var(--line); border-radius: 20px; padding: 12px; box-shadow: 0 6px 24px #0000000a; z-index: 1; }
.chat-composer textarea { border: 0; resize: vertical; min-height: 78px; max-height: 35dvh; padding: 10px; background: transparent; }
.chat-composer label { font-size: .78rem; margin: 0 0 4px; color: var(--muted); }
.chat-composer select { font-size: .85rem; padding: 7px 10px; margin-bottom: 8px; }
.composer-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.composer-actions button { font-size: .85rem; flex-shrink: 0; }
.composer-actions button[type="submit"] { margin-left: auto; border-radius: 12px; }
.composer-actions .ghost { border-color: transparent; }
.composer-hint { font-size: .62rem; }
.conversation-options { margin: 10px 0; font-size: .8rem; color: var(--muted); }
.conversation-options button { font-size: .8rem; }
.chat-extra { border-top: 1px solid var(--line); font-size: .85rem; padding: 2px 0; }
.chat-notice { font-size: .72rem; padding-top: 16px; }
.is-chat .talk-log { position: relative; min-height: 180px; max-height: 52dvh; overflow-y: auto; overscroll-behavior: contain; overflow-anchor: none; }
.is-chat .talk-log p { padding: 16px 18px; line-height: 1.7; overflow-wrap: anywhere; }
.is-chat .talk-log .me { background: var(--soft); max-width: 85%; margin: 20px 0 20px auto; border-radius: 18px 18px 4px 18px; }
.is-chat .talk-log .judy { background: transparent; margin: 20px 0; padding-left: 0; }
.is-chat .talk-log p strong { display: block; font-size: .75rem; color: var(--muted); margin-bottom: 4px; }
.upload-dialog { width: min(580px, 94vw); max-height: 90dvh; overflow-y: auto; }
.upload-dialog::backdrop { background: #0007; }
.check-line { display: flex; align-items: flex-start; gap: 10px; font-size: .85rem; font-weight: 400; margin: 18px 0; }
.check-line input { width: 20px; height: 20px; flex-shrink: 0; margin-top: 3px; }
@media (prefers-color-scheme: dark) { :root { --accent: #91cfc1; --accent-ink: #102721; } }
@media (max-width: 760px) {
  .top { padding: 8px 12px; }
  main.workspace { grid-template-columns: minmax(0, 1fr); }
  .case-sidebar { position: static; max-height: none; overflow: visible; padding: 12px; border-right: 0; border-bottom: 1px solid var(--line); }
  .sidebar-label, .sidebar-bottom { display: none; }
  .case-title { font-size: .75rem; margin: 0 4px 8px; }
  .workspace-tabs, .case-sidebar > .tabs { flex-direction: row; flex-wrap: wrap; gap: 4px; }
  .case-sidebar .tabs button { width: auto; min-height: 44px; padding: 6px 9px; font-size: .75rem; }
  .case-sidebar .tabs button[aria-expanded] { margin: 0; }
  .workspace-content { padding: 16px 12px; }
  .chat-welcome { padding: 22px 4px 14px; }
  .chat-starters { grid-template-columns: minmax(0, 1fr); gap: 6px; }
  .chat-starters button { padding: 9px 12px; }
  .composer-hint { display: none; }
  .chat-composer { bottom: 6px; }
  .is-chat .talk-log { max-height: 38dvh; }
  .is-chat .talk-log .me { max-width: 95%; }
}
@media print {
  main.workspace { display: block; }
  .case-sidebar, .settings-menu, .chat-extra, .conversation-options { display: none !important; }
  .workspace-content { padding: 0; }
  .is-chat .talk-log { max-height: none; overflow: visible; }
}


/* Chat owns the remaining viewport; only its history scrolls. */
@media screen {
  body:has(main.chat-mode) { height: 100dvh; display: flex; flex-direction: column; overflow: hidden; }
  body:has(main.chat-mode) > .top { flex: 0 0 auto; position: relative; }
  body:has(main.chat-mode) > .foot { display: none; }
  main.workspace.chat-mode { flex: 1 1 0; width: 100%; min-height: 0; overflow: hidden; }
  .chat-mode .case-sidebar { position: static; align-self: stretch; max-height: none; overflow-y: auto; }
  .chat-mode .workspace-content { display: flex; flex-direction: column; min-height: 0; padding-top: 12px; padding-bottom: 12px; }
  .chat-mode .active-case-name { flex: 0 0 auto; margin-bottom: 8px; }
  .chat-mode .chat-workspace { display: flex; flex-direction: column; flex: 1 1 0; min-height: 0; width: 100%; }
  .chat-mode .chat-form { display: flex; flex-direction: column; flex: 1 1 0; min-height: 0; }
  .chat-mode .talk-log { flex: 1 1 0; min-height: 0; max-height: none; padding-bottom: 12px; }
  .chat-mode .chat-composer { position: relative; bottom: auto; flex: 0 0 auto; }
  .chat-mode .chat-more { flex: 0 0 auto; max-height: 35dvh; overflow-y: auto; font-size: .8rem; }
  .chat-mode .chat-more > summary { padding: 5px 0; }
}
@media screen and (max-width: 760px) {
  main.workspace.chat-mode { grid-template-rows: auto minmax(0, 1fr); }
  .chat-mode .case-sidebar { max-height: 28dvh; padding: 8px 12px; }
  .chat-mode .case-list { max-height: 76px; }
  .chat-mode .workspace-content { padding: 8px 12px; }
  .chat-mode .chat-composer textarea { min-height: 54px; max-height: 18dvh; }
}

.email-workspace { border: 1px solid var(--line); border-radius: 14px; background: var(--card); padding: 14px; margin: 12px 0; }
.email-workspace h2 { margin: 0; font-size: 1rem; }
.email-editor { min-width: 0; }
.email-editor input, .email-editor select, .email-editor textarea { width: 100%; }
.email-editor textarea { white-space: pre-wrap; min-height: 180px; }
.email-notes { border-left: 3px solid var(--accent); padding-left: 10px; }
.email-notes:empty { display:none; }
.email-original, .email-review { white-space:pre-wrap; overflow-wrap:anywhere; }
.email-canvas { width:min(820px,96vw); max-height:94dvh; overflow:auto; color:var(--ink); background:var(--card); border:1px solid var(--line); border-radius:16px; }
.email-canvas::backdrop { background:#0007; }
.email-canvas textarea { min-height:40dvh; }
.voice-dialog { position:fixed; inset:76px 16px auto auto; margin:0; width:min(330px,94vw); max-height:max(180px,calc(100dvh - 360px)); overflow:auto; z-index:8; color:var(--ink); background:var(--card); border:1px solid var(--line); border-radius:16px; padding:16px; }
.voice-dialog h2 { margin:0; font-size:1rem; }
.voice-dialog canvas { width:100%; height:180px; }
.voice-dialog p, .voice-dialog label { font-size:.8rem; }
@media(max-width:760px) { .composer-actions {gap:4px;} .composer-actions button {padding:7px 9px; font-size:.75rem;} .email-canvas {width:100vw;max-height:100dvh;} }
@media print { .email-workspace,.voice-dialog {display:none !important;} }

.voice-dialog button { font-size:.8rem; padding:8px 10px; }
