:root {
  --bg: #e7eee6;
  --surface: rgba(247, 250, 246, 0.92);
  --ink: #3a403c;
  --muted: #5e675e;
  --line: #d3ddd2;
  --saffron: #5f6d5c;
  --terracotta: #8c4d42;
  --sage: #6d7f6c;
  --indigo: #3a403c;
  --radius: 14px;
}
* { box-sizing: border-box; }
body {
  margin: 0; font: 15px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif; color: var(--ink);
  background-color: #d5ddd4;
  background-image: linear-gradient(
    180deg,
    #eef2ee 0% 11%,
    #e3ebe4 11% 22%,
    #d7e1d6 22% 36%,
    #e6eee5 36% 48%,
    #d3ddd2 48% 61%,
    #e0e8df 61% 73%,
    #c9d4c8 73% 86%,
    #b7c4b6 86% 100%
  );
  background-attachment: fixed;
  padding-bottom: calc(3.6rem + env(safe-area-inset-bottom));
}
.hidden { display: none !important; }
code { background: #e4ebe3; padding: 1px 5px; border-radius: 5px; }
.muted { color: var(--muted); }
.error { color: var(--terracotta); min-height: 1.2em; }
h1, h2, h3 { font-weight: 650; letter-spacing: -0.01em; }
h2 { margin: 0 0 12px; }
h3 { margin: 18px 0 8px; font-size: 1.02rem; }

header { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 18px; padding: 10px 22px;
  background: rgba(232, 237, 230, 0.94); color: var(--ink); flex-wrap: wrap;
  border-bottom: 1px solid var(--line); }
.brand { font-weight: 650; font-size: 1.15rem; white-space: nowrap; display: flex; align-items: center; gap: 8px; }
.brand small { font-weight: 400; opacity: .75; margin-left: 2px; font-size: .8rem; }
.brand .mark-wrap { width: 34px; height: 34px; flex: none; }
.mark { width: 34px; height: 34px; display: block; }
.login .mark-wrap { display: block; width: 148px; height: 148px; margin: 0 auto 8px; }
.login .mark,
.mark-wrap .mark { width: 100%; height: 100%; margin: 0; }
header nav { display: flex; gap: 6px; flex: 1; flex-wrap: wrap; }
header nav a {
  padding: 6px 12px; border-radius: 999px; cursor: pointer; text-decoration: none;
  color: var(--ink); font-weight: 650; background: rgba(255, 255, 255, .45);
  border: 1px solid rgba(58, 64, 60, .18);
}
header nav a:visited { color: var(--ink); }
header nav a:hover { background: rgba(255, 255, 255, .75); color: var(--ink); }
header nav a.active, header nav a.active:visited { background: var(--saffron); color: #f4f6f3; border-color: var(--saffron); }
header button.ghost { color: var(--ink); border-color: rgba(58, 64, 60, .45); opacity: 1; }
main { max-width: 1240px; margin: 0 auto; padding: 22px; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: 0 1px 2px rgba(60,40,20,.04); }
.grid { display: grid; gap: 16px; }
.grid.cols-2 { grid-template-columns: 300px 1fr; }
.grid.cols-2.equal { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
@media (max-width: 860px) {
  .grid.cols-2,
  .grid.cols-2.equal { grid-template-columns: 1fr; }
}
.card .table-scroll { overflow-x: auto; margin: 0 -4px; }
.card table { min-width: 100%; }

.mode-card { max-width: 560px; margin: 0 auto 18px; text-align: center; }
.mode-card .stat { margin: 4px 0; }
.mode-actions { justify-content: center; margin-top: 8px; }
.stat { font-size: 1.6rem; font-weight: 700; }
.pill { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: .78rem; background: #e4ebe3; color: var(--muted); }
.pill.ok { background: #e3efe2; color: #3f6b43; }
.pill.bad { background: #f8e1da; color: var(--terracotta); }
.pill.active { background: var(--saffron); color: #fff; }

button { font: inherit; border: 0; border-radius: 10px; padding: 8px 14px; cursor: pointer; background: var(--saffron); color: #fff; font-weight: 600; }
button:hover { filter: brightness(.96); }
button.ghost { background: transparent; color: inherit; border: 1px solid currentColor; opacity: .9; }
button.secondary { background: #e4ebe3; color: var(--ink); }
button.danger { background: var(--terracotta); }
button.small { padding: 4px 10px; font-size: .85rem; }
button:disabled { opacity: .5; cursor: default; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }

label { display: block; font-size: .85rem; color: var(--muted); margin: 10px 0 4px; }
input, select, textarea { width: 100%; font: inherit; padding: 8px 10px; border: 1px solid var(--line); border-radius: 10px; background: #fff; color: var(--ink); }
textarea { min-height: 90px; resize: vertical; }
textarea.prompt { min-height: 260px; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: .86rem; }
input[type=checkbox] { width: auto; margin-right: 6px; }
input[type=range] { padding: 0; }
.checks { display: flex; flex-wrap: wrap; gap: 6px 16px; }
.checks label { display: flex; align-items: center; margin: 0; color: var(--ink); font-size: .9rem; }

.list { display: flex; flex-direction: column; gap: 6px; }
.item { padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line); background: #fff; cursor: pointer; }
.item:hover, .item:focus-visible { border-color: var(--saffron); outline: none; }
.item.selected { border-color: var(--saffron); box-shadow: 0 0 0 2px rgba(95, 109, 92, .25); }
.item .title { font-weight: 600; }
.item .sub { font-size: .82rem; color: var(--muted); }

table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { text-align: left; padding: 7px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; }
td.wrap,
.card p.wrap { white-space: pre-wrap; word-break: break-word; }

.messages { display: flex; flex-direction: column; gap: 8px; max-height: 60vh; overflow: auto; padding-right: 4px; }
.msg { max-width: 80%; padding: 8px 12px; border-radius: 14px; white-space: pre-wrap; }
.msg.user { align-self: flex-end; background: #dce5da; }
.msg.assistant { align-self: flex-start; background: #f4f7f3; }
.msg.tool { align-self: center; background: #e7eee6; font-size: .85rem; max-width: 95%; width: 95%; white-space: normal; }
.msg.tool.failed { background: #f7e6e4; }
.qr { background: #fff; padding: 8px; border-radius: 10px; width: max-content; margin: 8px 0; }
.qr svg { width: 220px; height: 220px; display: block; }
.steps { padding-left: 18px; }
#sec-flow input, #login-otp input, #login-token input { display: block; width: 100%; margin: 6px 0; }
button.small { padding: 4px 10px; font-size: .8rem; }
.tool-head { margin-bottom: 4px; }
.tool-meta { margin-top: 6px; white-space: pre-wrap; }
.bad-tag { color: #a3312a; font-weight: 600; }
.msg.tool details { margin-top: 6px; }
.msg.tool pre { max-height: 320px; overflow: auto; background: #fff; padding: 8px; border-radius: 8px; white-space: pre-wrap; word-break: break-word; }
.chat-image { display: block; max-width: 100%; max-height: 420px; border-radius: 10px; cursor: zoom-in; margin-top: 4px; }
.lightbox { position: fixed; inset: 0; background: rgba(0, 0, 0, .88); display: flex; flex-direction: column; align-items: center; justify-content: center; z-index: 1000; overflow: auto; cursor: zoom-out; }
.lightbox img { max-width: 95vw; max-height: 90vh; cursor: zoom-in; }
.lightbox img.zoomed { max-width: none; max-height: none; cursor: zoom-out; }
.lightbox .caption { color: #eee; margin-top: 8px; max-width: 90vw; font-size: .85rem; text-align: center; }
.summary { background: #f4f7f3; border-left: 3px solid var(--sage); padding: 10px 12px; border-radius: 8px; white-space: pre-wrap; }

.hit { border-left: 3px solid var(--sage); padding: 8px 12px; margin: 8px 0; background: #fbfaf6; border-radius: 8px; }
.hit pre { white-space: pre-wrap; margin: 6px 0 0; font: inherit; font-size: .88rem; }

.login { min-height: 100vh; display: grid; place-items: center; background: transparent; }
.login form { width: 340px; text-align: center; }
.login .lotus { font-size: 2.6rem; }
.login input { margin: 10px 0; }
.login button { width: 100%; }

.toast {
  position: fixed; z-index: 60; left: 50%; transform: translateX(-50%);
  bottom: calc(4.4rem + env(safe-area-inset-bottom));
  width: max-content; max-width: min(560px, calc(100vw - 32px));
  background: var(--indigo); color: #f4f6f3; padding: 10px 18px; border-radius: var(--radius);
  text-align: center; white-space: pre-line; overflow-wrap: anywhere; box-shadow: 0 6px 20px rgba(0,0,0,.18);
}
.toast.bad {
  background: #f8e1da; color: var(--terracotta); border: 1px solid #e6bfb4;
  box-shadow: 0 6px 20px rgba(140,77,66,.16);
}

.confirm {
  width: min(420px, calc(100vw - 32px)); padding: 26px 24px 20px; border: 1px solid var(--line); border-radius: var(--radius);
  background: #f7faf6; color: var(--ink); text-align: center; box-shadow: 0 18px 50px rgba(40, 50, 40, .22);
}
.confirm::backdrop { background: rgba(58, 64, 60, .38); backdrop-filter: blur(2px); }
.confirm .mark-wrap { width: 54px; height: 54px; margin-bottom: 4px; }
.confirm h3 { margin: 6px 0 6px; font-size: 1.12rem; }
.confirm p { margin: 0 0 4px; }
.confirm-actions { justify-content: center; margin-top: 16px; }
.confirm-actions button { min-width: 120px; }
.code-box { font-size: 1.6rem; letter-spacing: .2em; font-weight: 700; color: var(--indigo); }
