:root {
  color-scheme: dark;
  --bg: #09121f;
  --surface: #0e1b2a;
  --surface-strong: #12243a;
  --line: #2c4057;
  --line-soft: #203247;
  --text: #f4f7fb;
  --muted: #aab8ca;
  --dim: #8797aa;
  --blue: #6db3ff;
  --green: #6fd38a;
  --green-bg: #133d2b;
  --amber: #f1b64c;
  --amber-bg: #3c2d14;
  --red: #ff6c72;
  --red-bg: #401c26;
  --focus: #9bc8ff;
  --radius: 12px;
  --serif: "Telegram UI", Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --mono: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { min-height: 100%; scroll-behavior: smooth; background: var(--bg); }
body { min-width: 320px; min-height: 100%; margin: 0; color: var(--text); background: var(--bg); font: 400 16px/1.45 var(--serif); }
button, input, select, textarea { font: inherit; }
button, select { cursor: pointer; }
button:disabled, input:disabled, select:disabled, textarea:disabled { cursor: not-allowed; opacity: .5; }
a { color: inherit; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }

.app-shell { width: min(100%, 720px); min-height: 100vh; margin: 0 auto; padding-bottom: calc(78px + env(safe-area-inset-bottom)); }
.app-header { position: sticky; z-index: 5; top: 0; display: flex; align-items: center; justify-content: space-between; min-height: 70px; padding: max(15px, env(safe-area-inset-top)) 20px 13px; background: var(--bg); border-bottom: 1px solid var(--line-soft); }
.brand { color: var(--text); font-size: 22px; font-weight: 800; letter-spacing: .035em; text-decoration: none; }
.connection { display: inline-flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; font-weight: 650; }
.connection i { width: 9px; height: 9px; border-radius: 50%; background: var(--amber); box-shadow: 0 0 0 3px rgba(241,182,76,.12); }
.connection.online i { background: var(--green); box-shadow: 0 0 0 3px rgba(111,211,138,.12); }
.connection.offline i { background: var(--red); box-shadow: 0 0 0 3px rgba(255,108,114,.12); }

main { padding: 22px 20px 34px; }
main [id] { scroll-margin-top: 86px; }
section + section { margin-top: 34px; }
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: clamp(29px, 8vw, 38px); line-height: 1.08; letter-spacing: -.025em; }
h2 { margin-bottom: 0; font-size: 21px; line-height: 1.2; letter-spacing: -.015em; }
.section-label { margin-bottom: 6px; color: var(--dim); font-size: 11px; font-weight: 760; letter-spacing: .08em; text-transform: uppercase; }
.section-copy { margin: 11px 0 18px; color: var(--muted); font-size: 14px; }
.intro { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; }
.updated { max-width: 130px; margin: 0; color: var(--dim); font-size: 12px; text-align: right; }

.gate { max-width: 470px; margin: 12vh auto 0; padding: 25px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.gate h1 { font-size: 28px; }
.gate p { margin: 12px 0 0; color: var(--muted); }
.notice { display: flex; flex-direction: column; gap: 3px; margin: 0 0 20px; padding: 13px 15px; border-radius: 10px; }
.stale-notice { color: #ffe6a6; background: var(--amber-bg); border: 1px solid #75531e; font-size: 13px; }

.safety-rail { display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 15px 16px; border: 1px solid #33506e; border-radius: var(--radius); background: var(--surface-strong); }
.safety-rail strong { display: block; color: var(--amber); font-family: var(--mono); font-size: 14px; letter-spacing: .05em; }
.safety-rail span { display: block; margin-top: 3px; color: var(--muted); font-size: 13px; }
.safety-rail dl { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; min-width: 172px; margin: 0; }
.safety-rail dt { color: var(--dim); font-size: 10px; font-weight: 700; text-transform: uppercase; }
.safety-rail dd { margin: 1px 0 0; color: var(--text); font-family: var(--mono); font-size: 14px; font-weight: 750; text-align: right; }

.conversation-section { padding: 20px; border: 1px solid #365274; border-radius: var(--radius); background: var(--surface); }
.conversation-log { display: grid; gap: 10px; max-height: 360px; margin: 0 0 14px; overflow: auto; overscroll-behavior: contain; }
.conversation-empty { margin: 0; color: var(--dim); font-size: 13px; }
.conversation-entry { max-width: 92%; padding: 11px 13px; border: 1px solid var(--line-soft); border-radius: 10px; background: #0a1726; overflow-wrap: anywhere; white-space: pre-wrap; }
.conversation-entry.user { justify-self: end; color: #dcecff; border-color: #365b82; background: #10243a; }
.conversation-entry.assistant { justify-self: start; color: var(--text); }
.conversation-entry strong { display: block; margin-bottom: 4px; color: var(--dim); font-size: 10px; letter-spacing: .06em; text-transform: uppercase; }
.conversation-handoff { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 10px; }
.conversation-action-button { min-height: 34px; padding: 7px 10px; color: var(--blue); border: 1px solid #345577; border-radius: 8px; background: #10243a; font-family: inherit; font-size: 12px; font-weight: 700; }
.conversation-receipt { display: block; margin-top: 8px; color: var(--dim); font: 11px var(--mono); }
.conversation-actions { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.conversation-actions p { min-height: 20px; margin: 0; color: var(--dim); font-size: 12px; }
.conversation-actions .secondary-button { flex: 0 0 auto; }

.analysis-section { padding: 20px; border: 1px solid #365274; border-radius: var(--radius); background: var(--surface); }
.analysis-section form { display: grid; gap: 14px; }
.analysis-actions { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.analysis-actions p { min-height: 20px; margin: 0; color: var(--dim); font-size: 12px; }
.analysis-stack { display: grid; gap: 12px; margin-top: 16px; }
.analysis-card { overflow: hidden; border: 1px solid #365274; border-radius: 10px; background: #0a1726; }
.analysis-card[data-state="failed"], .analysis-card[data-state="canceled"] { border-color: #88404c; }
.analysis-card[data-state="requested"], .analysis-card[data-state="preparing_evidence"], .analysis-card[data-state="researching"], .analysis-card[data-state="synthesizing"] { border-color: #75531e; }
.analysis-card[data-state="expired"], .analysis-card[data-state="stale"] { border-color: #75531e; }
.analysis-card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 14px 15px; border-bottom: 1px solid var(--line-soft); }
.analysis-card-head h3 { margin: 0; font-size: 16px; line-height: 1.25; overflow-wrap: anywhere; }
.analysis-card-head p { margin: 4px 0 0; color: var(--dim); font-size: 12px; }
.analysis-state { flex: 0 0 auto; padding: 3px 6px; color: var(--amber); border: 1px solid #75531e; border-radius: 5px; font: 700 10px var(--mono); letter-spacing: .04em; text-transform: uppercase; }
.analysis-card[data-state="completed"] .analysis-state { color: var(--green); border-color: #3d7550; }
.analysis-card[data-state="failed"] .analysis-state, .analysis-card[data-state="canceled"] .analysis-state { color: var(--red); border-color: #88404c; }
.analysis-body { display: grid; gap: 13px; padding: 14px 15px 16px; }
.analysis-summary { margin: 0; color: var(--text); font-size: 14px; white-space: pre-wrap; overflow-wrap: anywhere; }
.analysis-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px; }
.analysis-fact { min-width: 0; padding: 10px; border: 1px solid var(--line-soft); border-radius: 8px; background: var(--surface); }
.analysis-fact span { display: block; color: var(--dim); font-size: 10px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; }
.analysis-fact strong { display: block; margin-top: 3px; color: var(--text); font-size: 13px; overflow-wrap: anywhere; }
.analysis-detail { padding-top: 12px; border-top: 1px solid var(--line-soft); }
.analysis-detail h4 { margin: 0 0 6px; color: var(--blue); font-size: 12px; }
.analysis-detail p { margin: 0; color: var(--muted); font-size: 13px; white-space: pre-wrap; overflow-wrap: anywhere; }
.analysis-detail ul { display: grid; gap: 5px; margin: 0; padding-left: 19px; color: var(--muted); font-size: 13px; }
.analysis-source-list { display: grid; gap: 7px; margin: 0; padding: 0; list-style: none; }
.analysis-source-list a { color: var(--blue); font-size: 13px; font-weight: 650; overflow-wrap: anywhere; }
.analysis-source-list small { display: block; margin-top: 1px; color: var(--dim); font-size: 11px; overflow-wrap: anywhere; }

.section-heading { display: flex; align-items: end; justify-content: space-between; gap: 18px; margin-bottom: 14px; }
.compact-heading { margin-bottom: 0; }
.proposal-count { display: grid; min-width: 30px; min-height: 30px; place-items: center; padding: 0 8px; color: var(--blue); border: 1px solid #345577; border-radius: 50%; font: 750 13px var(--mono); }
.proposal-stack { display: grid; gap: 13px; }
.proposal-card { overflow: hidden; border: 1px solid #386548; border-radius: var(--radius); background: var(--surface); }
.proposal-card.approved { border-color: #3d668e; }
.proposal-card-head { display: flex; gap: 12px; padding: 16px; border-bottom: 1px solid var(--line-soft); }
.lot-photo { display: grid; flex: 0 0 54px; width: 54px; height: 54px; place-items: center; overflow: hidden; color: var(--blue); background: #172942; border: 1px solid #365274; border-radius: 9px; font-size: 20px; font-weight: 800; }
.lot-photo img { width: 100%; height: 100%; object-fit: cover; }
.proposal-card-head > div { min-width: 0; flex: 1; }
.proposal-card-head h3 { margin: 0; font-size: 17px; line-height: 1.25; overflow-wrap: anywhere; }
.proposal-card-head p { margin: 4px 0 0; color: var(--muted); font-size: 12px; }
.proposal-status { align-self: start; padding: 3px 6px; color: var(--green); border: 1px solid #3d7550; border-radius: 5px; font: 700 10px var(--mono); letter-spacing: .04em; text-transform: uppercase; }
.proposal-status.approved { color: var(--blue); border-color: #3b668e; }
.proposal-amounts { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); padding: 0 16px; }
.proposal-amounts > div { min-width: 0; padding: 14px 8px 15px 0; border-right: 1px solid var(--line-soft); }
.proposal-amounts > div + div { padding-left: 11px; }
.proposal-amounts > div:last-child { border: 0; }
.proposal-amounts span { display: block; color: var(--dim); font-size: 10px; font-weight: 650; }
.proposal-amounts strong { display: block; margin-top: 3px; overflow: hidden; color: var(--text); font: 750 16px var(--mono); text-overflow: ellipsis; white-space: nowrap; }
.proposal-amounts .all-in strong { color: var(--green); }
.cost-breakdown { margin: 0 16px; padding: 11px 0; border-block: 1px solid var(--line-soft); }
.cost-breakdown dl { display: grid; grid-template-columns: 1fr auto; gap: 5px 12px; margin: 0; font-size: 12px; }
.cost-breakdown dt { color: var(--muted); }
.cost-breakdown dd { margin: 0; color: var(--text); font-family: var(--mono); text-align: right; }
.proposal-meta { display: flex; align-items: center; justify-content: space-between; gap: 13px; padding: 12px 16px; color: var(--muted); font-size: 12px; }
.proposal-meta strong { color: var(--amber); font-family: var(--mono); }
.proposal-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; padding: 0 16px 16px; }
.approved-note { padding: 0 16px 16px; color: var(--blue); font-size: 13px; }
.empty-state { margin: 0; padding: 20px 0 4px; color: var(--muted); font-size: 14px; text-align: center; }

.form-section { padding: 20px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.form-section form { display: grid; gap: 14px; }
label { display: grid; gap: 7px; color: var(--muted); font-size: 13px; font-weight: 650; }
input, select, textarea { width: 100%; min-height: 47px; padding: 10px 12px; color: var(--text); background: #0a1726; border: 1px solid #385069; border-radius: 9px; }
select { appearance: auto; }
textarea { min-height: 90px; resize: vertical; }
input::placeholder, textarea::placeholder { color: #67798e; }
.input-prefix { position: relative; display: block; }
.input-prefix b { position: absolute; z-index: 1; top: 12px; left: 13px; color: var(--dim); font-family: var(--mono); }
.input-prefix input { padding-left: 29px; font-family: var(--mono); }
.form-split { display: grid; grid-template-columns: minmax(0, 1fr) 112px; gap: 13px; align-items: end; }
.safe-max { min-height: 67px; margin: 0; padding: 9px 0 0 12px; color: var(--dim); border-left: 1px solid var(--line); font-size: 11px; }
.safe-max strong { display: block; margin-top: 2px; color: var(--green); font: 750 17px var(--mono); }
.form-hint { min-height: 19px; margin: -5px 0 0; color: var(--dim); font-size: 12px; }
.form-hint.error { color: #ff9ba0; }

.primary-button, .secondary-button, .danger-button, .text-button { display: inline-flex; align-items: center; justify-content: center; min-height: 47px; padding: 10px 14px; border: 1px solid transparent; border-radius: 9px; font-weight: 760; text-align: center; }
.primary-button { color: #04110a; background: var(--green); border-color: #90e6a7; }
.primary-button:hover:not(:disabled) { background: #8ce3a4; }
.secondary-button { color: var(--text); background: #182b41; border-color: #48647f; }
.secondary-button:hover:not(:disabled) { background: #213b58; }
.danger-button { color: #ffe9eb; background: var(--red-bg); border-color: var(--red); }
.danger-button:hover:not(:disabled) { background: #55222d; }
.text-button { color: var(--muted); background: transparent; border-color: transparent; }

.valuation-section { border-color: #334b68; }
.valuation-list { display: grid; gap: 8px; margin-top: 16px; }
.valuation-row { display: flex; align-items: center; justify-content: space-between; gap: 13px; padding: 10px 0; border-top: 1px solid var(--line-soft); }
.valuation-row strong, .valuation-row span { display: block; }
.valuation-row strong { font-size: 13px; }
.valuation-row span { margin-top: 2px; color: var(--dim); font-size: 11px; }
.valuation-row time { color: var(--blue); font-family: var(--mono); font-size: 11px; white-space: nowrap; }

.policy-section { border-color: #4a5565; }
.policy-section #executorState { flex: 0 0 auto; color: var(--amber); font: 750 11px var(--mono); letter-spacing: .04em; }
.policy-inputs { grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: stretch; }
.policy-inputs .safe-max { display: none; }
.policy-status { min-height: 20px; margin: 14px 0 0; color: var(--amber); font-size: 13px; }
.policy-status:empty { display: none; }
.policy-actions { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 9px; margin-top: 13px; }
.policy-arm { width: 100%; margin-top: 11px; color: var(--blue); border: 1px solid #3c6285; }
.policy-note { margin: 8px 0 0; color: var(--dim); font-size: 12px; }
.stop-section { display: flex; align-items: center; justify-content: space-between; gap: 18px; padding: 18px; border: 1px solid #88404c; border-radius: var(--radius); background: #1c1521; }
.stop-section h2 { color: var(--red); }
.stop-section p:last-child { max-width: 400px; margin: 7px 0 0; color: var(--muted); font-size: 13px; }
.stop-section .danger-button { flex: 0 0 auto; }

.bottom-nav { position: fixed; z-index: 8; right: 0; bottom: 0; left: 0; display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); width: min(100%, 720px); margin: auto; padding: 7px 12px calc(7px + env(safe-area-inset-bottom)); background: #0c1928; border-top: 1px solid var(--line); }
.bottom-nav a { display: grid; min-height: 47px; place-items: center; color: var(--muted); font-size: 11px; font-weight: 700; text-decoration: none; }
.bottom-nav a:hover, .bottom-nav a:focus-visible { color: var(--blue); }

dialog { width: min(440px, calc(100% - 32px)); padding: 0; color: var(--text); background: var(--surface-strong); border: 1px solid #426280; border-radius: var(--radius); box-shadow: 0 24px 80px rgba(0,0,0,.5); }
dialog::backdrop { background: rgba(2, 8, 15, .75); }
dialog form { padding: 22px; }
dialog h2 { font-size: 24px; }
dialog p { color: var(--muted); }
.confirm-amount { margin: 14px 0; color: var(--green) !important; font: 800 28px var(--mono); letter-spacing: -.04em; }
.check-row { display: flex; grid-template-columns: none; align-items: flex-start; gap: 10px; margin: 18px 0; color: var(--text); font-size: 14px; font-weight: 600; }
.check-row input { width: 19px; min-width: 19px; min-height: 19px; margin-top: 1px; accent-color: var(--green); }
.dialog-note { color: var(--dim); font-size: 12px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 22px; }
.danger-copy { color: var(--red); }
.toast { position: fixed; z-index: 20; right: 16px; bottom: calc(88px + env(safe-area-inset-bottom)); left: 16px; width: min(520px, calc(100% - 32px)); margin: auto; padding: 13px 15px; color: #dffbe7; background: #16452d; border: 1px solid #43895d; border-radius: 10px; box-shadow: 0 12px 35px rgba(0,0,0,.35); font-size: 14px; font-weight: 650; }
.toast.error { color: #ffe5e7; background: #55242e; border-color: #b45460; }

@media (max-width: 460px) {
  main { padding-right: 15px; padding-left: 15px; }
  .app-header { padding-right: 15px; padding-left: 15px; }
  .safety-rail { align-items: flex-start; flex-direction: column; }
  .safety-rail dl { width: 100%; }
  .safety-rail dd { text-align: left; }
  .proposal-amounts { grid-template-columns: 1fr 1fr; row-gap: 0; }
  .proposal-amounts > div:last-child { grid-column: 1 / -1; padding-left: 0; border-top: 1px solid var(--line-soft); }
  .proposal-actions { grid-template-columns: 1fr; }
  .stop-section { align-items: stretch; flex-direction: column; }
  .stop-section .danger-button { width: 100%; }
  .policy-inputs, .policy-actions { grid-template-columns: 1fr; }
  .conversation-actions { align-items: stretch; flex-direction: column; }
  .conversation-actions .secondary-button { width: 100%; }
  .analysis-actions { align-items: stretch; flex-direction: column; }
  .analysis-actions .secondary-button { width: 100%; }
  .analysis-grid { grid-template-columns: 1fr; }
}

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