:root {
  --bg: #f4f7f8; --card: #ffffff; --ink: #14232b; --muted: #5d6f78; --line: #dde5e9;
  --brand: #0e7490; --brand-ink: #ffffff; --brand-soft: #e3f3f7;
  --ok: #167a4a; --ok-soft: #e1f5ea; --warn: #9a5b00; --warn-soft: #fdf0d5; --bad: #b3261e; --bad-soft: #fbe5e3;
  --radius: 16px; --shadow: 0 1px 2px rgba(20, 35, 43, .06), 0 4px 14px rgba(20, 35, 43, .05);
  --font: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Malgun Gothic", "Noto Sans KR", system-ui, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e171c; --card: #16232a; --ink: #e8f0f3; --muted: #93a7b0; --line: #26373f;
    --brand: #38b6d3; --brand-ink: #062229; --brand-soft: #14323b;
    --ok: #55c88d; --ok-soft: #12301f; --warn: #f0b955; --warn-soft: #342a10; --bad: #ff8d84; --bad-soft: #3a1b19;
    --shadow: none;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.6 var(--font); padding-bottom: calc(76px + env(safe-area-inset-bottom)); }
button, input, textarea, select { font: inherit; color: inherit; }
.wrap { max-width: 760px; margin: 0 auto; padding: 0 16px; }
header.top { position: sticky; top: 0; z-index: 5; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); }
header.top .wrap { display: flex; align-items: center; gap: 10px; height: 56px; }
header.top h1 { font-size: 17px; margin: 0; flex: 1; letter-spacing: -.02em; }
.logo { width: 30px; height: 30px; border-radius: 9px; }
.icon-btn { border: 0; background: transparent; color: var(--muted); padding: 8px; border-radius: 10px; cursor: pointer; font-size: 14px; }
.icon-btn:hover { background: var(--brand-soft); }

nav.tabs { position: fixed; left: 0; right: 0; bottom: 0; z-index: 6; background: var(--card); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
nav.tabs .wrap { display: grid; grid-template-columns: repeat(3, 1fr); }
nav.tabs button { border: 0; background: none; padding: 9px 4px 10px; color: var(--muted); font-size: 12.5px; display: grid; justify-items: center; gap: 2px; cursor: pointer; min-height: 56px; }
nav.tabs button span.i { font-size: 21px; line-height: 1; }
nav.tabs button[aria-selected="true"] { color: var(--brand); font-weight: 700; }

section.view { display: none; padding: 16px 0 24px; }
section.view.on { display: block; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); margin-bottom: 14px; }
.card h2 { font-size: 16px; margin: 0 0 4px; letter-spacing: -.01em; }
.muted { color: var(--muted); font-size: 14px; }
.small { font-size: 13px; }

.seg { display: grid; grid-template-columns: repeat(3, 1fr); background: var(--brand-soft); border-radius: 14px; padding: 4px; gap: 4px; margin-bottom: 12px; }
.seg button { border: 0; background: transparent; padding: 10px 4px; line-height: 1.35; font-size: 15px; border-radius: 11px; font-weight: 600; color: var(--muted); cursor: pointer; }
.seg button[aria-pressed="true"] { background: var(--card); color: var(--brand); box-shadow: var(--shadow); }

.emergency { background: var(--bad-soft); color: var(--bad); border-radius: 12px; padding: 10px 12px; font-size: 14px; margin: 0 0 12px; line-height: 1.5; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0 2px; }
.chip { border: 1px solid var(--line); background: var(--card); border-radius: 999px; padding: 7px 13px; font-size: 14px; cursor: pointer; }
.chip:hover { border-color: var(--brand); color: var(--brand); }

.drop { display: flex; gap: 10px; flex-wrap: wrap; margin: 4px 0 10px; }
.btn { border: 1px solid var(--line); background: var(--card); border-radius: 12px; padding: 11px 14px; cursor: pointer; font-weight: 600; display: inline-flex; align-items: center; gap: 6px; min-height: 44px; }
.btn.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.btn.ghost { background: transparent; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.thumbs { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.thumb { position: relative; width: 74px; height: 74px; border-radius: 12px; overflow: hidden; border: 1px solid var(--line); background: var(--brand-soft); display: grid; place-items: center; font-size: 12px; color: var(--muted); text-align: center; padding: 4px; }
.thumb img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.thumb button { position: absolute; top: 2px; right: 2px; width: 24px; height: 24px; border-radius: 50%; border: 0; background: rgba(0, 0, 0, .65); color: #fff; cursor: pointer; line-height: 1; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
label.f { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
input[type=date], input[type=text], input[type=search], textarea, select { border: 1px solid var(--line); background: var(--card); border-radius: 12px; padding: 11px 12px; width: 100%; }
textarea { resize: vertical; min-height: 84px; }
input:focus, textarea:focus, select:focus { outline: 2px solid var(--brand); outline-offset: 1px; }

.chat { display: grid; gap: 12px; margin-top: 4px; }
.msg { border-radius: var(--radius); padding: 13px 15px; max-width: 100%; overflow-wrap: anywhere; }
.msg.user { background: var(--brand); color: var(--brand-ink); justify-self: end; max-width: 92%; white-space: pre-wrap; }
.msg.ai { background: var(--card); border: 1px solid var(--line); box-shadow: var(--shadow); }
.status { color: var(--muted); font-size: 14px; display: flex; gap: 8px; align-items: center; }
.dots::after { content: ""; display: inline-block; width: 1.2em; text-align: left; animation: dots 1.2s steps(4) infinite; }
@keyframes dots { 0% { content: ""; } 25% { content: "."; } 50% { content: ".."; } 75% { content: "..."; } }
details.extract { margin: 0 0 10px; border: 1px dashed var(--line); border-radius: 12px; padding: 8px 12px; background: var(--brand-soft); }
details.extract summary { cursor: pointer; font-weight: 600; font-size: 14px; }
details.extract pre { white-space: pre-wrap; font: 13px/1.5 var(--font); margin: 8px 0 0; }
.sources { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--line); align-items: center; }
.sources b { font-size: 12.5px; color: var(--muted); margin-right: 2px; }
a.cite, .src { display: inline-block; background: var(--brand-soft); color: var(--brand); border: 0; border-radius: 8px; padding: 1px 8px; font-size: 13px; text-decoration: none; cursor: pointer; font-weight: 600; }

.md h1, .md h2, .md h3 { margin: 16px 0 6px; line-height: 1.35; letter-spacing: -.01em; }
.md h1 { font-size: 19px; } .md h2 { font-size: 17px; } .md h3 { font-size: 15.5px; }
.md > :first-child { margin-top: 0; }
.md p { margin: 8px 0; } .md ul, .md ol { padding-left: 20px; margin: 8px 0; } .md li { margin: 3px 0; }
.md ul.tasks { list-style: none; padding-left: 2px; } .md ul.tasks li::before { content: "☐"; margin-right: 8px; color: var(--brand); }
.md blockquote { margin: 10px 0; padding: 8px 12px; border-left: 4px solid var(--brand); background: var(--brand-soft); border-radius: 0 10px 10px 0; }
.md hr { border: 0; border-top: 1px solid var(--line); margin: 14px 0; }
.md .tw { overflow-x: auto; margin: 10px -4px; padding: 0 4px; }
.md table { border-collapse: collapse; font-size: 14px; min-width: 100%; }
.md th, .md td { border: 1px solid var(--line); padding: 7px 9px; text-align: left; vertical-align: top; }
.md th { background: var(--brand-soft); white-space: nowrap; }
.md strong { font-weight: 700; }
.disclaimer { font-size: 12.5px; color: var(--muted); text-align: center; margin: 18px 4px 0; }

.tag { display: inline-block; font-size: 12.5px; padding: 2px 9px; border-radius: 999px; font-weight: 600; margin: 2px 4px 2px 0; }
.tag.ok { background: var(--ok-soft); color: var(--ok); } .tag.warn { background: var(--warn-soft); color: var(--warn); } .tag.bad { background: var(--bad-soft); color: var(--bad); } .tag.neutral { background: var(--brand-soft); color: var(--brand); }
.contract h2 { font-size: 16px; } .kv { display: grid; grid-template-columns: 6.2em 1fr; gap: 2px 10px; font-size: 14px; margin: 8px 0; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; }
details.fold { margin-top: 10px; } details.fold > summary { cursor: pointer; font-weight: 600; color: var(--brand); padding: 6px 0; }
table.plain { border-collapse: collapse; width: 100%; font-size: 13.5px; } table.plain th, table.plain td { border-bottom: 1px solid var(--line); padding: 7px 4px; text-align: left; vertical-align: top; }
table.plain td.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.cov-row { display: grid; grid-template-columns: 1fr 110px 36px; gap: 6px; margin: 6px 0; }
.cov-row button { border: 0; background: var(--bad-soft); color: var(--bad); border-radius: 10px; cursor: pointer; }

.hit { display: block; width: 100%; text-align: left; background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 11px 13px; margin: 8px 0; cursor: pointer; }
.hit b { color: var(--brand); } .hit span { display: block; color: var(--muted); font-size: 13.5px; margin-top: 3px; }

.viewer { position: fixed; inset: 0; z-index: 20; background: rgba(5, 12, 16, .88); display: none; flex-direction: column; }
.viewer.on { display: flex; }
.viewer .bar { display: flex; align-items: center; gap: 8px; padding: 10px 12px; color: #fff; }
.viewer .bar strong { flex: 1; font-size: 15px; }
.viewer .bar button { border: 0; background: rgba(255, 255, 255, .16); color: #fff; border-radius: 10px; padding: 8px 13px; cursor: pointer; font-size: 15px; min-height: 40px; }
.viewer .scroll { flex: 1; overflow: auto; -webkit-overflow-scrolling: touch; text-align: center; }
.viewer img { background: #fff; width: 100%; max-width: 900px; height: auto; display: inline-block; }
.viewer img.zoom { width: 190%; max-width: none; }
.masker .scroll { padding: 4px 8px; }
.masker canvas { width: 100%; max-width: 900px; height: auto; background: #fff; touch-action: none; cursor: crosshair; display: inline-block; }
.mbar { display: flex; flex-wrap: wrap; gap: 8px; padding: 10px 12px 4px; justify-content: center; }
.mbar button { border: 0; background: rgba(255, 255, 255, .16); color: #fff; border-radius: 10px; padding: 10px 14px; cursor: pointer; font-size: 15px; min-height: 44px; }
.mbar button.go { background: var(--brand); color: var(--brand-ink); font-weight: 700; }
.mnote { color: #cfe0e6; font-size: 12.5px; text-align: center; margin: 4px 12px calc(10px + env(safe-area-inset-bottom)); }
.toast { position: fixed; left: 50%; bottom: calc(86px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: #14232b; color: #fff; padding: 10px 16px; border-radius: 12px; font-size: 14px; z-index: 30; max-width: 90vw; display: none; }
.toast.on { display: block; }
.banner { background: var(--warn-soft); color: var(--warn); border-radius: 12px; padding: 10px 12px; font-size: 14px; margin-bottom: 12px; }
@media (min-width: 900px) { body { padding-bottom: 0; } nav.tabs { position: static; border: 0; background: transparent; } header.top .wrap { max-width: 760px; } }
