:root {
  --bg: #f5f7fb; --card: #ffffff; --ink: #14213d; --muted: #5b6475; --line: #e3e7ef;
  --brand: #003087; --btn: #003087; --brand-2: #0070e0; --ok: #127a3a; --ok-bg: #e5f5ea; --warn: #8a5a00;
  --warn-bg: #fff4dc; --bad: #b42318; --bad-bg: #fde8e7; --held: #f0a500; --chip: #eef3fb;
  --radius: 14px; --shadow: 0 1px 2px rgba(20,33,61,.06), 0 4px 16px rgba(20,33,61,.05);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d1220; --card: #151c2e; --ink: #e8ecf6; --muted: #9aa4b8; --line: #263049;
    --brand: #6ea8ff; --btn: #2563eb; --brand-2: #4f93ff; --ok: #5fd08a; --ok-bg: #12301f; --warn: #f3c463;
    --warn-bg: #33270d; --bad: #ff8a80; --bad-bg: #3a1614; --chip: #1d2742;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  --bg: #0d1220; --card: #151c2e; --ink: #e8ecf6; --muted: #9aa4b8; --line: #263049;
  --brand: #6ea8ff; --btn: #2563eb; --brand-2: #4f93ff; --ok: #5fd08a; --ok-bg: #12301f; --warn: #f3c463;
  --warn-bg: #33270d; --bad: #ff8a80; --bad-bg: #3a1614; --chip: #1d2742; --shadow: none;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--brand-2); }
button { font: inherit; color: #fff; cursor: pointer; border: 0; border-radius: 10px; padding: 8px 14px; background: var(--btn); font-weight: 600; }
button:disabled { opacity: .55; cursor: default; }
button.ghost { background: transparent; color: var(--muted); border: 1px solid var(--line); padding: 4px 10px; font-weight: 500; }
.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 24px; max-width: 1240px; margin: 0 auto; }
.brand { display: flex; align-items: center; gap: 12px; }
.brand strong { display: block; font-size: 18px; }
.sub { color: var(--muted); font-size: 13px; }
.logo { width: 36px; height: 36px; border-radius: 10px; background: #003087; color: #fff; display: grid; place-items: center; font-weight: 800; }
.badge { font-size: 12px; font-weight: 600; padding: 3px 10px; border-radius: 99px; }
.sandbox { background: var(--warn-bg); color: var(--warn); }
.layout { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(320px, 1fr); gap: 20px; max-width: 1240px; margin: 0 auto; padding: 0 24px 24px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }
.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.card-head h2 { font-size: 15px; margin: 0; letter-spacing: .02em; text-transform: uppercase; color: var(--muted); }
.side { display: grid; gap: 20px; align-content: start; min-width: 0; }
.side > *, .chat { min-width: 0; }
.chat { display: flex; flex-direction: column; min-height: 72vh; }
.log { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; padding: 4px; max-height: 62vh; }
.msg { max-width: 88%; padding: 10px 14px; border-radius: 14px; }
.msg p { margin: 0 0 6px; white-space: pre-wrap; } .msg p:last-child { margin: 0; }
.msg.user { align-self: flex-end; background: var(--btn); color: #fff; border-bottom-right-radius: 4px; }
.msg.agent { align-self: flex-start; background: var(--chip); border-bottom-left-radius: 4px; }
.msg.agent a { font-weight: 600; }
.trace { align-self: flex-start; font-size: 13px; color: var(--muted); border-left: 3px solid var(--line); padding: 2px 10px; max-width: 92%; }
.trace summary { cursor: pointer; list-style: none; }
.trace summary::-webkit-details-marker { display: none; }
.trace pre { white-space: pre-wrap; word-break: break-word; font-size: 12px; background: var(--bg); padding: 8px; border-radius: 8px; max-height: 240px; overflow: auto; }
.trace.deny { border-color: var(--bad); color: var(--bad); }
.trace.auto { border-color: var(--ok); }
.trace.approval { border-color: var(--held); }
.typing { align-self: flex-start; color: var(--muted); font-size: 13px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0; }
.chips button { background: var(--chip); color: var(--ink); font-weight: 500; font-size: 13px; padding: 6px 12px; border-radius: 99px; }
.composer { display: flex; gap: 8px; }
.composer input { flex: 1; min-width: 0; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); color: var(--ink); font: inherit; }
.meter { position: relative; height: 12px; border-radius: 99px; background: var(--chip); overflow: hidden; display: flex; }
.meter .spent { background: var(--brand-2); height: 100%; transition: width .4s; }
.meter .held { background: var(--held); height: 100%; transition: width .4s; }
.stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin: 12px 0; }
.stats dt { font-size: 12px; color: var(--muted); } .stats dd { margin: 0; font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }
.autopay { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 12px; border-radius: 10px; background: var(--bg); font-size: 14px; }
.autopay .on { color: var(--ok); font-weight: 600; } .autopay .off { color: var(--muted); }
.lock { font-size: 12px; color: var(--muted); }
.policy { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.policy label { display: grid; gap: 4px; font-size: 12px; color: var(--muted); }
.policy label.wide { grid-column: 1 / -1; }
.policy input { padding: 8px 10px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg); color: var(--ink); font: inherit; font-size: 14px; }
.policy button { grid-column: 1 / -1; }
.hint { grid-column: 1 / -1; margin: 0; font-size: 12px; color: var(--muted); }
.purchases { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.purchases .empty { color: var(--muted); font-size: 14px; }
.p { border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; display: grid; gap: 6px; }
.p.flash { animation: flash 1.6s ease-out; }
@keyframes flash { from { box-shadow: 0 0 0 3px var(--brand-2); } to { box-shadow: none; } }
.p-row { display: flex; justify-content: space-between; gap: 10px; align-items: baseline; }
.p-title { font-weight: 600; font-size: 14px; }
.p-meta { font-size: 12px; color: var(--muted); }
.p-total { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.p-reasons { font-size: 12px; color: var(--muted); margin: 0; padding-left: 16px; }
.p-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.p-actions a, .p-actions button { font-size: 12px; padding: 5px 10px; border-radius: 8px; }
.p-actions a { background: #ffc439; color: #111; text-decoration: none; font-weight: 700; }
.st { font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 99px; letter-spacing: .03em; }
.st.PAID { background: var(--ok-bg); color: var(--ok); }
.st.AWAITING_APPROVAL, .st.PROPOSED, .st.PROCESSING, .st.REFUNDING { background: var(--warn-bg); color: var(--warn); }
.st.DENIED, .st.FAILED { background: var(--bad-bg); color: var(--bad); }
.st.CANCELED, .st.EXPIRED, .st.REFUNDED { background: var(--chip); color: var(--muted); }
.foot { text-align: center; color: var(--muted); font-size: 12px; padding: 0 16px 24px; }
.notice { max-width: 520px; margin: 15vh auto; padding: 24px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-size: 14px; z-index: 10; }
@media (max-width: 900px) {
  .layout { grid-template-columns: minmax(0, 1fr); padding: 0 16px 16px; }
  .autopay { flex-wrap: wrap; }
  .policy { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .policy input { min-width: 0; width: 100%; }
  .top { padding: 12px 16px; }
  .chat { min-height: 60vh; }
  .stats dd { font-size: 17px; }
}
.ap-btns { display: flex; gap: 6px; flex-wrap: wrap; }
