:root {
  --ink: #14161a; --ink2: #2a2f37; --paper: #f4f2ee; --card: #ffffff; --line: #dcd8d0; --mute: #5d6672;
  --spark: #ffb800; --spark-ink: #1b1500; --ok: #1f7a3d; --okbg: #e3f4e8; --warn: #8a5a00; --warnbg: #fff3d6;
  --bad: #b3261e; --badbg: #fde7e5; --info: #165a9b; --infobg: #e4f0fb; --focus: #1d6fd6;
  --radius: 14px; --tab-h: 62px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root { --ink: #0c0d10; --ink2: #d9dde3; --paper: #101216; --card: #1a1d23; --line: #2d323b; --mute: #98a2b0;
    --okbg: #11301c; --warnbg: #3a2c08; --badbg: #3b1714; --infobg: #10263d; --ok: #62d08a; --warn: #f2c25b; --bad: #ff8a80; --info: #7fbcf2; }
  body { color: #eceff3; }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body { font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--paper); color: #17191d; overscroll-behavior-y: contain; }
@media (prefers-color-scheme: dark) { body { color: #eceff3; } }
h1, h2, h3, h4 { margin: 0; line-height: 1.2; }
a { color: var(--info); }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .92em; background: rgba(127,127,127,.15); padding: 1px 5px; border-radius: 5px; }

/* ---------- shell ---------- */
#top { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; justify-content: space-between; gap: 10px;
  background: var(--ink); color: #fff; padding: calc(env(safe-area-inset-top) + 8px) 14px 8px; min-height: 52px; }
.brand { display: flex; align-items: center; gap: 8px; font-size: 19px; letter-spacing: .02em; }
.bolt { color: var(--spark); font-size: 22px; }
.jobchip { max-width: 62%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; background: #272c34; color: #fff; border: 1px solid #3a414c;
  border-radius: 999px; padding: 8px 14px; font-size: 14px; min-height: 40px; cursor: pointer; }
#banner:empty { display: none; }
#banner .banner { margin: 10px 12px 0; }
main#app { padding: 12px 12px calc(var(--tab-h) + env(safe-area-inset-bottom) + 24px); max-width: 880px; margin: 0 auto; }
#tabs { position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; display: grid; grid-template-columns: repeat(6, 1fr); background: var(--ink);
  padding-bottom: env(safe-area-inset-bottom); border-top: 1px solid #2d323b; }
#tabs button { background: none; border: 0; color: #aab2bf; padding: 7px 2px 6px; min-height: var(--tab-h); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-size: 11px; cursor: pointer; }
#tabs button .ic { font-size: 21px; line-height: 1; }
#tabs button[aria-current="page"] { color: var(--spark); box-shadow: inset 0 3px 0 var(--spark); }
#toast { position: fixed; left: 50%; bottom: calc(var(--tab-h) + env(safe-area-inset-bottom) + 14px); transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: #111; color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 15px; max-width: 90vw; z-index: 60; transition: .2s; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- cards & layout ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin: 0 0 12px; }
.card > h3, .card > summary h3 { font-size: 17px; }
.card > h3 + * { margin-top: 10px; }
.card h3 small, .sub { color: var(--mute); font-weight: 400; font-size: 13px; }
.card.flat { background: transparent; border-style: dashed; }
details.card > summary { cursor: pointer; list-style: none; display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 28px; }
details.card > summary::-webkit-details-marker { display: none; }
details.card > summary::after { content: "▾"; color: var(--mute); }
details.card[open] > summary::after { content: "▴"; }
details.card[open] > summary { margin-bottom: 10px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.nowrap { flex-wrap: nowrap; }
.grow { flex: 1 1 0; min-width: 0; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
@media (max-width: 420px) { .grid2.stack { grid-template-columns: 1fr; } }
.gap { margin-top: 10px; }
.muted { color: var(--mute); }
.small { font-size: 13px; }
.right { margin-left: auto; }
hr { border: 0; border-top: 1px solid var(--line); margin: 12px 0; }

/* ---------- forms ---------- */
.field { display: block; margin: 0 0 10px; }
.field > span { display: block; font-size: 13px; color: var(--mute); margin-bottom: 4px; }
input[type=text], input[type=tel], input[type=email], input[type=number], input[type=password], input[type=search], select, textarea {
  width: 100%; font: inherit; font-size: 16px; color: inherit; background: var(--card); border: 1.5px solid var(--line); border-radius: 10px; padding: 11px 12px; min-height: 46px; }
textarea { min-height: 84px; resize: vertical; }
input:focus, select:focus, textarea:focus, button:focus-visible, summary:focus-visible { outline: 3px solid var(--focus); outline-offset: 1px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: .04em; }
.big-in { font-size: 24px !important; font-weight: 700; min-height: 56px; text-transform: uppercase; }
.with-mic { position: relative; }
.with-mic > textarea, .with-mic > input { padding-right: 52px; }
.mic { position: absolute; right: 6px; top: 6px; width: 40px; height: 40px; border-radius: 50%; border: 0; background: var(--paper); font-size: 18px; cursor: pointer; }
.mic.listening { background: var(--bad); color: #fff; animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .55; } }

/* ---------- buttons ---------- */
.btn { font: inherit; font-weight: 600; font-size: 16px; min-height: 48px; padding: 10px 16px; border-radius: 12px; border: 1.5px solid var(--ink2); background: var(--card); color: inherit; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 8px; text-decoration: none; }
.btn.primary { background: var(--spark); border-color: var(--spark); color: var(--spark-ink); }
.btn.dark { background: var(--ink); border-color: var(--ink); color: #fff; }
.btn.danger { border-color: var(--bad); color: var(--bad); }
.btn.ghost { border-color: var(--line); font-weight: 500; }
.btn.sm { min-height: 38px; padding: 6px 12px; font-size: 14px; border-radius: 10px; }
.btn.block { display: flex; width: 100%; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.btn:active { transform: translateY(1px); }

/* ---------- chips / banners ---------- */
.chip { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; font-weight: 600; padding: 3px 9px; border-radius: 999px; background: var(--paper); border: 1px solid var(--line); color: var(--mute); white-space: nowrap; }
.chip.ok { background: var(--okbg); color: var(--ok); border-color: transparent; }
.chip.warn { background: var(--warnbg); color: var(--warn); border-color: transparent; }
.chip.bad { background: var(--badbg); color: var(--bad); border-color: transparent; }
.chip.info { background: var(--infobg); color: var(--info); border-color: transparent; }
.chip.btn-chip { font-size: 14px; padding: 8px 12px; cursor: pointer; background: var(--card); color: inherit; font-weight: 500; }
.chip.on { background: var(--spark); color: var(--spark-ink); border-color: var(--spark); }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.banner { border-radius: 12px; padding: 10px 12px; font-size: 14.5px; border: 1px solid transparent; }
.banner.warn { background: var(--warnbg); color: var(--warn); border-color: rgba(138,90,0,.25); }
.banner.bad { background: var(--badbg); color: var(--bad); border-color: rgba(179,38,30,.25); }
.banner.info { background: var(--infobg); color: var(--info); border-color: rgba(22,90,155,.2); }
.banner.ok { background: var(--okbg); color: var(--ok); }
.banner + .banner, .card + .banner, .banner + .card { margin-top: 10px; }
.banner b { color: inherit; }

/* ---------- tick rows ---------- */
.check { display: flex; gap: 12px; align-items: flex-start; padding: 12px 0; border-top: 1px solid var(--line); }
.check:first-of-type { border-top: 0; }
.check input[type=checkbox], .md-tick input[type=checkbox] { width: 28px; height: 28px; flex: 0 0 28px; margin: 2px 0 0; accent-color: var(--ok); }
.check .body { flex: 1; min-width: 0; }
.check .ttl { font-weight: 650; }
.check.done .ttl { text-decoration: line-through; color: var(--mute); }
.check .warn-line { color: var(--bad); font-size: 14px; margin-top: 4px; }
.reading { display: flex; gap: 8px; align-items: center; margin-top: 8px; flex-wrap: wrap; }
.reading input[type=text], .reading input[type=number] { width: 120px; min-height: 40px; padding: 7px 10px; }
.seg { display: inline-flex; border: 1.5px solid var(--line); border-radius: 10px; overflow: hidden; }
.seg button { font: inherit; font-size: 14px; border: 0; background: var(--card); color: inherit; padding: 8px 12px; min-height: 40px; cursor: pointer; }
.seg button + button { border-left: 1.5px solid var(--line); }
.seg button.pass[aria-pressed=true] { background: var(--ok); color: #fff; }
.seg button.fail[aria-pressed=true] { background: var(--bad); color: #fff; }
.progress { height: 8px; background: var(--paper); border-radius: 99px; overflow: hidden; margin: 8px 0 4px; border: 1px solid var(--line); }
.progress > i { display: block; height: 100%; background: var(--ok); transition: width .25s; }

/* ---------- diagnosis bits ---------- */
.headline { font-size: 20px; font-weight: 750; line-height: 1.25; }
.codebadge { display: inline-block; font: 800 26px/1 ui-monospace, Menlo, monospace; background: var(--ink); color: var(--spark); padding: 8px 12px; border-radius: 10px; letter-spacing: .05em; }
.cause { padding: 10px 0; border-top: 1px solid var(--line); }
.cause:first-of-type { border-top: 0; }
.cause .rank { width: 26px; height: 26px; border-radius: 50%; background: var(--ink); color: #fff; display: inline-flex; align-items: center; justify-content: center; font-weight: 700; font-size: 14px; flex: 0 0 26px; }
.like-high { color: var(--bad); } .like-medium { color: var(--warn); } .like-low { color: var(--mute); }
.source { display: flex; gap: 8px; align-items: center; padding: 8px 0; border-top: 1px solid var(--line); font-size: 14.5px; }
.source:first-of-type { border-top: 0; }
.source a { word-break: break-word; }
.status-log { font-size: 14px; color: var(--mute); margin: 8px 0 0; padding: 0; list-style: none; max-height: 190px; overflow: auto; }
.status-log li { padding: 3px 0; }
.status-log li:last-child { color: inherit; font-weight: 600; }
.spinner { width: 18px; height: 18px; border: 3px solid var(--line); border-top-color: var(--spark); border-radius: 50%; animation: spin .8s linear infinite; display: inline-block; vertical-align: -3px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- age ---------- */
.age { display: flex; gap: 12px; align-items: center; }
.age .big { font-size: 28px; font-weight: 800; line-height: 1.05; }
.cand { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }

/* ---------- photos ---------- */
.thumbs { display: flex; gap: 8px; flex-wrap: wrap; margin: 8px 0; }
.thumb { position: relative; width: 88px; height: 88px; border-radius: 10px; overflow: hidden; border: 1px solid var(--line); }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb button { position: absolute; top: 3px; right: 3px; width: 28px; height: 28px; border-radius: 50%; border: 0; background: rgba(0,0,0,.65); color: #fff; font-size: 15px; cursor: pointer; }

/* ---------- chat ---------- */
.chat { display: flex; flex-direction: column; gap: 10px; padding-bottom: 8px; }
.bubble { max-width: 92%; padding: 10px 13px; border-radius: 16px; word-break: break-word; }
.bubble.user { align-self: flex-end; background: var(--ink); color: #fff; border-bottom-right-radius: 4px; white-space: pre-wrap; }
.bubble.bot { align-self: flex-start; background: var(--card); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.bubble .tools { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; }
.composer { position: sticky; bottom: calc(var(--tab-h) + env(safe-area-inset-bottom) + 6px); background: var(--paper); padding: 8px 0 4px; z-index: 5; }
.composer .row { align-items: flex-end; flex-wrap: nowrap; }
.composer textarea { min-height: 50px; max-height: 140px; }

/* ---------- markdown ---------- */
.md p { margin: 0 0 8px; }
.md p:last-child { margin-bottom: 0; }
.md ul, .md ol { margin: 4px 0 8px; padding-left: 22px; }
.md li { margin: 3px 0; }
.md-h { margin: 10px 0 4px; font-size: 16px; }
.md-tick { list-style: none; padding-left: 0 !important; }
.md-tick li { padding: 6px 0; }
.md-tick label { display: flex; gap: 10px; align-items: flex-start; cursor: pointer; }
.md-tablewrap { overflow-x: auto; margin: 6px 0; }
.md-table { border-collapse: collapse; font-size: 14px; }
.md-table th, .md-table td { border: 1px solid var(--line); padding: 5px 8px; text-align: left; vertical-align: top; }

/* ---------- parts ---------- */
.part { display: flex; gap: 10px; align-items: flex-start; padding: 12px 0; border-top: 1px solid var(--line); }
.part:first-child { border-top: 0; }
.part img { width: 56px; height: 56px; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); flex: 0 0 56px; }
.price { font-size: 21px; font-weight: 800; white-space: nowrap; }
table.t { width: 100%; border-collapse: collapse; font-size: 15px; }
table.t td, table.t th { padding: 7px 4px; border-top: 1px solid var(--line); text-align: left; vertical-align: top; }
table.t td.r, table.t th.r { text-align: right; white-space: nowrap; }
table.t tr.total td { font-weight: 800; border-top: 2px solid var(--ink2); }
pre.block { white-space: pre-wrap; word-break: break-word; font: 14px/1.45 ui-monospace, Menlo, monospace; background: var(--paper); border: 1px solid var(--line); border-radius: 10px; padding: 12px; margin: 8px 0; max-height: 380px; overflow: auto; }

/* ---------- modal ---------- */
#modal { position: fixed; inset: 0; z-index: 80; background: rgba(0,0,0,.55); display: flex; align-items: flex-end; justify-content: center; }
#modal[hidden] { display: none; }
#modal .sheet { background: var(--card); width: 100%; max-width: 520px; border-radius: 18px 18px 0 0; padding: 18px 16px calc(18px + env(safe-area-inset-bottom)); max-height: 92vh; overflow: auto; }
@media (min-width: 600px) { #modal { align-items: center; } #modal .sheet { border-radius: 18px; } }
.gate { min-height: 70vh; display: flex; align-items: center; justify-content: center; }
.gate .card { width: 100%; max-width: 420px; }

/* ---------- print ---------- */
#print { display: none; }
@media print {
  body > *:not(#print) { display: none !important; }
  #print { display: block; color: #000; background: #fff; font: 12pt/1.4 system-ui, sans-serif; }
  #print h1 { font-size: 20pt; margin: 0 0 4pt; } #print h2 { font-size: 13pt; margin: 14pt 0 4pt; border-bottom: 1px solid #999; }
  #print pre { white-space: pre-wrap; font: inherit; margin: 0; }
  #print table { border-collapse: collapse; width: 100%; } #print td, #print th { border: 1px solid #bbb; padding: 4pt 6pt; text-align: left; }
  #print img { max-width: 48%; margin: 4pt; border: 1px solid #999; }
}
