:root {
  color-scheme: light;
  --ink: #17211c;
  --muted: #657069;
  --line: #d9dedb;
  --line-strong: #b9c3bd;
  --surface: #ffffff;
  --surface-soft: #f5f7f6;
  --surface-warm: #fff8ec;
  --green: #176b4d;
  --green-dark: #0e4d37;
  --green-soft: #e8f3ee;
  --gold: #b86b12;
  --coral: #b84d3e;
  --danger: #a33b35;
  --white: #ffffff;
  --auth-background: #edf3ef;
  --sidebar-background: #f1f4f2;
  --header-background: rgba(255, 255, 255, 0.97);
  --calculator-line: #b8d8ca;
  --calculator-hover: #d9ece3;
  --focus-ring: rgba(23, 107, 77, 0.13);
  --focus-ring-soft: rgba(23, 107, 77, 0.1);
  --shadow-soft: 0 8px 24px rgba(26, 40, 32, 0.12);
  --overlay: rgba(20, 30, 24, 0.35);
  --toast-background: #26332c;
  --shadow: 0 12px 30px rgba(26, 40, 32, 0.12);
  font-family: Inter, Pretendard, "Noto Sans KR", "Apple SD Gothic Neo", Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { width: 100%; min-height: 100%; margin: 0; }
body { color: var(--ink); background: var(--surface-soft); font-size: 15px; line-height: 1.55; letter-spacing: 0; }
button, input, textarea, select { font: inherit; letter-spacing: 0; }
button { cursor: pointer; }
button:disabled, input:disabled, textarea:disabled, select:disabled { cursor: not-allowed; opacity: 0.6; }
.hidden { display: none !important; }
.mobile-only { display: 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; }
.muted { color: var(--muted); }
.eyebrow { margin: 0 0 2px; color: var(--green); font-size: 12px; font-weight: 800; text-transform: uppercase; }

.brand-lockup { display: flex; align-items: center; gap: 10px; }
.brand-name, .brand-subtitle { margin: 0; }
.brand-name { font-size: 19px; font-weight: 900; color: var(--ink); }
.brand-subtitle { color: var(--muted); font-size: 13px; }
.brand-logo { display: block; object-fit: contain; }
.brand-logo-login { width: 46px; height: 46px; }
.brand-logo-small { width: 32px; height: 32px; }
.brand-logo-mobile { width: 26px; height: 26px; }
.brand-lockup-login { margin-bottom: 28px; }

.button, .icon-button, .calculator-entry { display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 1px solid transparent; border-radius: 7px; min-height: 42px; padding: 0 15px; font-weight: 750; transition: background-color 130ms ease, border-color 130ms ease, color 130ms ease; }
.button svg, .icon-button svg, .calculator-entry svg { width: 18px; height: 18px; flex: 0 0 auto; }
.button-primary { color: white; background: var(--green); border-color: var(--green); }
.button-primary:hover { background: var(--green-dark); border-color: var(--green-dark); }
.button-secondary { color: var(--ink); background: var(--surface); border-color: var(--line-strong); }
.button-secondary:hover, .button-quiet:hover, .icon-button:hover { background: var(--surface-soft); border-color: var(--line-strong); }
.button-quiet { justify-content: flex-start; width: 100%; color: var(--muted); background: transparent; border-color: transparent; }
.button-link { min-height: 36px; padding: 0; color: var(--green); background: transparent; border: 0; }
.icon-button { width: 42px; padding: 0; color: var(--ink); background: var(--surface); border-color: var(--line); }
.icon-button-send { width: 40px; height: 40px; min-height: 40px; color: var(--white); background: var(--green); border-color: var(--green); border-radius: 7px; }

.auth-shell { min-height: 100vh; display: grid; place-items: center; padding: 28px; background: var(--auth-background); }
.auth-card { width: min(100%, 440px); padding: 38px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); box-shadow: var(--shadow); }
.auth-card h1 { margin: 0 0 6px; font-size: 28px; line-height: 1.25; }
.auth-card > .muted { margin: 0 0 24px; }
.form-stack { display: grid; gap: 15px; }
.form-stack label { display: grid; gap: 6px; font-weight: 700; }
input, textarea, select { width: 100%; color: var(--ink); background: var(--surface); border: 1px solid var(--line-strong); border-radius: 6px; outline: none; }
input, select { min-height: 42px; padding: 9px 11px; }
textarea { padding: 12px; resize: none; }
input:focus, textarea:focus, select:focus { border-color: var(--green); box-shadow: 0 0 0 3px var(--focus-ring); }
.form-message { min-height: 24px; margin: 14px 0 0; color: var(--danger); }

.app-shell { height: 100vh; display: grid; grid-template-columns: 256px minmax(0, 1fr); overflow: hidden; background: var(--surface); }
.case-sidebar { min-width: 0; display: flex; flex-direction: column; padding: 18px 14px; border-right: 1px solid var(--line); background: var(--sidebar-background); }
.sidebar-header { height: 42px; display: flex; align-items: center; justify-content: space-between; padding: 0 5px; }
.sidebar-primary { width: 100%; margin: 18px 0 22px; }
.recent-nav { min-height: 0; flex: 1; overflow: auto; }
.recent-nav h2 { margin: 0 8px 9px; color: var(--muted); font-size: 12px; font-weight: 800; }
.case-list { display: grid; gap: 3px; }
.case-list-item { width: 100%; min-height: 58px; display: grid; gap: 2px; padding: 9px 10px; text-align: left; color: var(--ink); background: transparent; border: 1px solid transparent; border-radius: 6px; }
.case-list-item:hover { background: var(--surface); border-color: var(--line); }
.case-list-item strong { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }
.case-list-item span, .case-list-empty { color: var(--muted); font-size: 12px; }
.case-list-empty { margin: 14px 9px; }
.sidebar-footer { display: grid; gap: 5px; padding-top: 14px; border-top: 1px solid var(--line); }
.tenant-select { margin-bottom: 8px; background: var(--surface); }

.conversation-shell { min-width: 0; height: 100vh; display: grid; grid-template-rows: 64px minmax(0, 1fr) auto; background: var(--surface); }
.top-header { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 16px; padding: 0 24px; border-bottom: 1px solid var(--line); background: var(--header-background); }
.conversation-title { min-width: 0; display: flex; align-items: center; gap: 9px; }
.conversation-title strong { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 15px; }
.calculator-entry { height: 40px; min-height: 40px; color: var(--green-dark); background: var(--green-soft); border-color: var(--calculator-line); }
.calculator-entry:hover { background: var(--calculator-hover); }
.calculator-entry svg:last-child { width: 15px; }

.conversation-scroll { min-height: 0; overflow-y: auto; overscroll-behavior: contain; }
.empty-state { min-height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 48px 24px 150px; text-align: center; }
.empty-mascot { width: clamp(150px, 20vw, 220px); height: clamp(150px, 20vw, 220px); object-fit: contain; margin-bottom: 22px; }
.empty-state h1 { max-width: 680px; margin: 0; font-size: 38px; line-height: 1.25; }
.empty-state p { max-width: 640px; margin: 12px 0 0; color: var(--muted); font-size: 16px; }
.conversation { width: min(100%, 850px); margin: 0 auto; padding: 32px 26px 140px; }
.turn { width: 100%; display: flex; gap: 12px; margin: 0 0 28px; }
.turn-user { justify-content: flex-end; }
.turn-user p { max-width: min(76%, 650px); margin: 0; padding: 12px 15px; border-radius: 8px 8px 2px 8px; background: var(--green); color: var(--white); white-space: pre-wrap; }
.turn-avatar { width: 24px; height: 24px; flex: 0 0 24px; object-fit: contain; margin-top: 3px; }
.turn-content { min-width: 0; width: min(100%, 720px); }
.turn-content > h2 { margin: 0 0 10px; font-size: 19px; line-height: 1.4; }
.turn-content > p { margin: 7px 0; }
.turn-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }
.turn-loading .turn-content { display: flex; align-items: center; gap: 12px; color: var(--muted); }
.turn-loading p { margin: 0; }
.loading-line { display: flex; gap: 4px; }
.loading-line span { width: 6px; height: 6px; border-radius: 50%; background: var(--green); animation: pulse 1s infinite ease-in-out; }
.loading-line span:nth-child(2) { animation-delay: 120ms; }
.loading-line span:nth-child(3) { animation-delay: 240ms; }
@keyframes pulse { 0%, 70%, 100% { opacity: .25; transform: translateY(0); } 35% { opacity: 1; transform: translateY(-3px); } }

.intake-summary { border-left: 3px solid var(--green); padding: 12px 0 12px 16px; }
.intake-summary > p { display: flex; flex-wrap: wrap; gap: 7px 12px; margin: 0 0 12px; }
.intake-summary > p span { color: var(--muted); }
.intake-summary dl { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin: 0; }
.intake-summary dl div { min-width: 0; padding: 10px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface-soft); }
.intake-summary dt { color: var(--muted); font-size: 12px; }
.intake-summary dd { margin: 2px 0 0; font-weight: 800; overflow-wrap: anywhere; }

.clarification-form { display: grid; gap: 12px; }
.question-field { min-width: 0; margin: 0; padding: 14px; border: 1px solid var(--line); border-radius: 7px; background: var(--surface); }
.question-field legend { padding: 0 5px; font-weight: 800; }
.field-help { margin: 0 0 8px; color: var(--muted); font-size: 13px; }
.question-control { max-width: 420px; }
.unknown-control { display: inline-flex; align-items: center; gap: 7px; margin: 10px 0 0 12px; color: var(--muted); font-size: 13px; }
.unknown-control input { width: 17px; height: 17px; min-height: auto; margin: 0; }
.field-error { min-height: 0; margin: 5px 0 0; color: var(--danger); font-size: 13px; }
.blocked-detail { padding: 12px 14px; border-left: 3px solid var(--gold); background: var(--surface-warm); }
.answer-conclusion { font-size: 16px; white-space: pre-wrap; }
.calculation-status { display: inline-flex; min-height: 26px; align-items: center; margin: 0 0 10px; padding: 3px 9px; border-radius: 6px; color: var(--green-dark); background: var(--green-soft); font-size: 12px; font-weight: 800; }
.calculation-status.conditional { color: var(--gold); background: var(--surface-warm); }
.calculator-breakdown { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin: 16px 0 0; }
.calculator-breakdown div { min-width: 0; padding: 11px 12px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface-soft); }
.calculator-breakdown dt { color: var(--muted); font-size: 12px; }
.calculator-breakdown dd { margin: 3px 0 0; font-weight: 850; overflow-wrap: anywhere; }
.confirmed-inputs { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 5px 14px; margin: 0; }
.confirmed-inputs div { display: flex; justify-content: space-between; gap: 12px; min-width: 0; border-bottom: 1px solid var(--line); padding: 6px 0; }
.confirmed-inputs dt { color: var(--muted); }
.confirmed-inputs dd { margin: 0; text-align: right; overflow-wrap: anywhere; }
.expert-draft { margin: 0; padding: 14px 16px; border-left: 3px solid var(--green); background: var(--green-soft); font-size: 16px; white-space: pre-wrap; }
.review-section { margin-top: 16px; }
.review-section h3 { margin: 0 0 6px; font-size: 14px; }
.review-section ul { margin: 0; padding-left: 20px; color: var(--muted); }

.composer { position: relative; z-index: 2; width: min(calc(100% - 40px), 850px); margin: 0 auto 20px; padding: 9px 10px 8px; border: 1px solid var(--line-strong); border-radius: 8px; background: var(--surface); box-shadow: var(--shadow-soft); }
.composer:focus-within { border-color: var(--green); box-shadow: 0 0 0 3px var(--focus-ring-soft), var(--shadow-soft); }
.composer textarea { min-height: 46px; max-height: 180px; padding: 8px 8px 2px; border: 0; box-shadow: none; line-height: 1.55; }
.composer textarea:focus { box-shadow: none; }
.composer-actions { display: flex; align-items: center; gap: 8px; }
.composer-actions .icon-button:first-child { border-color: transparent; }
.composer-privacy { min-width: 0; flex: 1; color: var(--muted); font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.side-dialog { width: min(430px, 94vw); height: 100vh; max-height: 100vh; margin: 0 0 0 auto; padding: 24px; border: 0; border-left: 1px solid var(--line); background: var(--surface); box-shadow: var(--shadow); }
.side-dialog::backdrop, .modal::backdrop { background: var(--overlay); }
.dialog-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; margin-bottom: 20px; }
.dialog-header h2 { margin: 0; font-size: 22px; }
.evidence-list { display: grid; gap: 12px; }
.evidence-item { padding: 14px; border: 1px solid var(--line); border-radius: 7px; background: var(--surface); }
.evidence-item h3 { margin: 7px 0 5px; font-size: 15px; line-height: 1.45; overflow-wrap: anywhere; }
.evidence-item p { margin: 5px 0; }
.evidence-item a { display: inline-flex; margin-top: 8px; color: var(--green); font-weight: 750; }
.evidence-status { display: inline-flex; align-items: center; min-height: 24px; padding: 2px 8px; border-radius: 6px; color: var(--green-dark); background: var(--green-soft); font-size: 12px; font-weight: 800; }
.evidence-status-candidate, .evidence-status-review_needed { color: var(--gold); background: var(--surface-warm); }
.evidence-status-conflict, .evidence-status-missing { color: var(--danger); background: var(--surface-warm); }
.evidence-meta, .evidence-limitation { color: var(--muted); font-size: 13px; }
.fact-entry-list { display: grid; gap: 10px; margin: 18px 0; }
.fact-entry-row { display: grid; grid-template-columns: minmax(100px, .8fr) minmax(140px, 1.4fr) 42px; gap: 8px; align-items: center; }

.modal { width: min(480px, calc(100% - 28px)); padding: 0; border: 0; border-radius: 8px; background: transparent; }
.modal-card { padding: 28px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); box-shadow: var(--shadow); }
.modal-card h2 { margin: 0 0 8px; }
.modal-actions { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: 8px; margin-top: 20px; }
#mfa-code { margin-top: 12px; font-size: 22px; text-align: center; letter-spacing: 4px; }
#mfa-qr { width: 190px; height: 190px; object-fit: contain; border: 1px solid var(--line); }
.toast { position: fixed; z-index: 100; left: 50%; bottom: 24px; max-width: min(560px, calc(100% - 32px)); transform: translate(-50%, 18px); padding: 11px 16px; border-radius: 7px; color: var(--white); background: var(--toast-background); box-shadow: var(--shadow); opacity: 0; pointer-events: none; transition: opacity 150ms ease, transform 150ms ease; }
.toast.is-visible { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 760px) {
  .mobile-only { display: inline-flex; }
  .app-shell { display: block; }
  .case-sidebar { position: fixed; z-index: 20; inset: 0 auto 0 0; width: min(310px, 88vw); transform: translateX(-102%); transition: transform 180ms ease; box-shadow: var(--shadow); }
  .case-sidebar.is-open { transform: translateX(0); }
  .drawer-backdrop { position: fixed; z-index: 19; inset: 0; background: var(--overlay); }
  .conversation-shell { height: 100dvh; grid-template-rows: 58px minmax(0, 1fr) auto; }
  .top-header { grid-template-columns: 42px minmax(0, 1fr) auto; padding: 0 10px; gap: 8px; }
  .calculator-entry { width: 42px; padding: 0; }
  .calculator-entry span, .calculator-entry svg:last-child { display: none; }
  .conversation { padding: 24px 16px 125px; }
  .empty-state { padding: 36px 20px 130px; }
  .empty-state h1 { font-size: 28px; }
  .turn-user p { max-width: 88%; }
  .intake-summary dl { grid-template-columns: 1fr; }
  .question-control { max-width: 100%; }
  .calculator-breakdown { grid-template-columns: 1fr; }
  .confirmed-inputs { grid-template-columns: 1fr; }
  .unknown-control { margin-left: 0; }
  .composer { width: calc(100% - 20px); margin-bottom: 10px; }
  .composer-privacy { display: none; }
  .fact-entry-row { grid-template-columns: 1fr 42px; }
  .fact-entry-row input:nth-child(2) { grid-column: 1 / -1; grid-row: 2; }
  .fact-entry-row button { grid-column: 2; grid-row: 1; }
  .auth-shell { padding: 14px; }
  .auth-card { padding: 26px 22px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
