:root {
  --bg: #f6f6f3; --panel: #ffffff; --panel-2: #f0efea; --line: #e3e1da; --line-2: #d4d1c7;
  --text: #1d1c19; --muted: #6b6860; --faint: #9a968b;
  --accent: #2f5d50; --accent-2: #3f7a69; --accent-soft: #e3eee9; --on-accent: #fff;
  --good: #2e7d4f; --good-soft: #e2f1e7; --warn: #a86a12; --warn-soft: #fbf0dc; --bad: #b3372b; --bad-soft: #f8e3e0;
  --info: #2c5d8f; --info-soft: #e2ecf7;
  --radius: 10px; --shadow: 0 1px 2px rgba(20,18,10,.05), 0 4px 16px rgba(20,18,10,.04);
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, "Helvetica Neue", Arial, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #131412; --panel: #1b1c1a; --panel-2: #222320; --line: #2d2e2a; --line-2: #3a3b36;
    --text: #ecebe6; --muted: #a3a197; --faint: #75736b;
    --accent: #6fb39d; --accent-2: #8cc6b2; --accent-soft: #1f3530; --on-accent: #0f1a17;
    --good: #6cc08d; --good-soft: #1b3024; --warn: #e0a54b; --warn-soft: #36290f; --bad: #ec7b6e; --bad-soft: #3a1d19;
    --info: #79aee0; --info-soft: #172a3d; --shadow: none;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 14px/1.5 var(--sans); -webkit-font-smoothing: antialiased; }
a { color: var(--accent); text-decoration: none; } a:hover { text-decoration: underline; }
h1 { font-size: 22px; font-weight: 650; letter-spacing: -.01em; margin: 0; }
h2 { font-size: 16px; font-weight: 620; margin: 0 0 12px; }
h3 { font-size: 13px; font-weight: 620; margin: 0 0 8px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
code, pre { font-family: var(--mono); font-size: 12.5px; }
pre { background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 12px; overflow: auto; white-space: pre-wrap; word-break: break-word; }
hr { border: 0; border-top: 1px solid var(--line); margin: 16px 0; }

/* layout */
.app { display: grid; grid-template-columns: 228px minmax(0, 1fr); min-height: 100vh; }
.side { background: var(--panel); border-right: 1px solid var(--line); padding: 18px 12px; position: sticky; top: 0; height: 100vh; overflow-y: auto; display: flex; flex-direction: column; }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px 18px; font-weight: 680; font-size: 15px; }
.brand .logo { width: 28px; height: 28px; border-radius: 8px; background: var(--accent); color: var(--on-accent); display: grid; place-items: center; font-weight: 750; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; color: var(--muted); font-weight: 520; text-decoration: none; margin-bottom: 1px; }
.nav a:hover { background: var(--panel-2); color: var(--text); }
.nav a.on { background: var(--accent-soft); color: var(--accent); }
.nav .sec { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--faint); padding: 14px 10px 6px; }
.nav .pill { margin-left: auto; }
.side .foot { margin-top: auto; padding: 12px 10px 0; border-top: 1px solid var(--line); font-size: 12px; color: var(--muted); }
.main { padding: 26px 32px 60px; max-width: 1280px; width: 100%; min-width: 0; }
.head { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.head .sub { color: var(--muted); font-size: 13px; }
.head .grow, .grow { flex: 1; }
.menu-btn { display: none; }

/* elements */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.card + .card { margin-top: 14px; }
.grid > .card + .card, .chatwrap > .card + .card, .unibox > .card + .card { margin-top: 0; }
.stack > a { display: block; }
.grid { display: grid; gap: 14px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); } .g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.kpi .v { font-size: 26px; font-weight: 660; letter-spacing: -.02em; }
.kpi .l { color: var(--muted); font-size: 12px; }
.kpi .d { font-size: 12px; color: var(--faint); }
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.stack > * + * { margin-top: 10px; }
.muted { color: var(--muted); } .faint { color: var(--faint); } .small { font-size: 12px; } .mono { font-family: var(--mono); font-size: 12px; }
.right { text-align: right; } .nowrap { white-space: nowrap; } .ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

button, .btn { font: inherit; font-weight: 560; border: 1px solid var(--line-2); background: var(--panel); color: var(--text); padding: 7px 13px; border-radius: 8px; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; text-decoration: none; }
button:hover, .btn:hover { background: var(--panel-2); text-decoration: none; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
button.primary:hover { background: var(--accent-2); }
button.danger { color: var(--bad); } button.danger.solid { background: var(--bad); color: #fff; border-color: var(--bad); }
button.ghost { border-color: transparent; background: transparent; }
button.sm { padding: 4px 9px; font-size: 12.5px; }
button:disabled { opacity: .5; cursor: default; }

input, select, textarea { font: inherit; color: var(--text); background: var(--panel); border: 1px solid var(--line-2); border-radius: 8px; padding: 7px 10px; width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
textarea { resize: vertical; min-height: 80px; line-height: 1.45; }
input[type=checkbox] { width: auto; accent-color: var(--accent); }
label.f { display: block; } label.f > span { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 4px; }
label.f .hint { font-weight: 400; color: var(--faint); }
label.chk { display: inline-flex; gap: 8px; align-items: center; cursor: pointer; }
.form { display: grid; gap: 12px; }

table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 11.5px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; padding: 8px 10px; border-bottom: 1px solid var(--line); }
td { padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
tr.click { cursor: pointer; } tr.click:hover td { background: var(--panel-2); }
.tablewrap { overflow-x: auto; }

.pill { display: inline-block; font-size: 11.5px; font-weight: 600; padding: 2px 8px; border-radius: 99px; background: var(--panel-2); color: var(--muted); white-space: nowrap; }
.pill.good { background: var(--good-soft); color: var(--good); } .pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.bad { background: var(--bad-soft); color: var(--bad); } .pill.info { background: var(--info-soft); color: var(--info); } .pill.acc { background: var(--accent-soft); color: var(--accent); }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; background: var(--faint); } .dot.good { background: var(--good); } .dot.bad { background: var(--bad); } .dot.warn { background: var(--warn); }
.notice { border-radius: 8px; padding: 10px 12px; font-size: 13px; background: var(--info-soft); color: var(--info); }
.notice.warn { background: var(--warn-soft); color: var(--warn); } .notice.bad { background: var(--bad-soft); color: var(--bad); } .notice.good { background: var(--good-soft); color: var(--good); }
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 16px; overflow-x: auto; }
.tabs a { padding: 9px 14px; color: var(--muted); font-weight: 560; border-bottom: 2px solid transparent; margin-bottom: -1px; text-decoration: none; white-space: nowrap; }
.tabs a.on { color: var(--text); border-color: var(--accent); }
.empty { text-align: center; color: var(--muted); padding: 40px 20px; }
.bar { height: 6px; background: var(--panel-2); border-radius: 99px; overflow: hidden; } .bar > i { display: block; height: 100%; background: var(--accent); }

/* chart */
.chart { display: flex; align-items: flex-end; gap: 6px; height: 120px; padding-top: 6px; }
.chart .col { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: 2px; height: 100%; }
.chart .b { width: 100%; max-width: 26px; border-radius: 4px 4px 0 0; background: var(--accent); min-height: 1px; }
.chart .r { width: 100%; max-width: 26px; background: var(--good); border-radius: 2px; }
.chart .x { font-size: 10px; color: var(--faint); }

/* modal & toast */
.modal-bg { position: fixed; inset: 0; background: rgba(10,10,8,.45); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal { background: var(--panel); border-radius: 12px; width: min(720px, 100%); max-height: 90vh; overflow: auto; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.modal .mh { padding: 16px 20px; border-bottom: 1px solid var(--line); display: flex; align-items: center; }
.modal .mh h2 { margin: 0; flex: 1; } .modal .mb { padding: 18px 20px; } .modal .mf { padding: 14px 20px; border-top: 1px solid var(--line); display: flex; gap: 8px; justify-content: flex-end; }
.toasts { position: fixed; right: 16px; bottom: 16px; display: grid; gap: 8px; z-index: 60; }
.toast { background: var(--text); color: var(--bg); padding: 10px 14px; border-radius: 8px; font-size: 13px; max-width: 380px; box-shadow: 0 6px 24px rgba(0,0,0,.2); }
.toast.bad { background: var(--bad); color: #fff; }

/* login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login .card { width: min(380px, 100%); padding: 28px; }

/* Bard chat */
.chatwrap { display: grid; grid-template-columns: 1fr 300px; gap: 14px; height: calc(100vh - 120px); }
.chat { display: flex; flex-direction: column; min-height: 0; padding: 0; }
.msgs { flex: 1; overflow-y: auto; padding: 18px; }
.msg { margin-bottom: 14px; max-width: 86%; }
.msg.user { margin-left: auto; }
.msg .bubble { padding: 10px 14px; border-radius: 12px; background: var(--panel-2); }
.msg.user .bubble { background: var(--accent); color: var(--on-accent); }
.msg.user .bubble a { color: inherit; text-decoration: underline; }
.msg.system .bubble { background: transparent; border: 1px dashed var(--line-2); color: var(--muted); font-size: 12.5px; }
.msg .who { font-size: 11.5px; color: var(--faint); margin-bottom: 3px; }
.msg .bubble p { margin: 0 0 8px; } .msg .bubble p:last-child { margin-bottom: 0; }
.msg .bubble ul, .msg .bubble ol { margin: 4px 0 8px; padding-left: 20px; }
.msg .bubble pre { background: var(--panel); margin: 6px 0; }
.msg .bubble h1, .msg .bubble h2, .msg .bubble h3, .msg .bubble h4 { font-size: 14px; margin: 10px 0 4px; text-transform: none; letter-spacing: 0; color: inherit; }
.toolcall { font-size: 12px; color: var(--muted); display: flex; gap: 6px; align-items: center; margin: 2px 0; font-family: var(--mono); }
.toolcall details { width: 100%; } .toolcall summary { cursor: pointer; }
.toolcall pre { max-height: 240px; margin-top: 4px; }
.composer { border-top: 1px solid var(--line); padding: 12px; display: flex; gap: 8px; align-items: flex-end; }
.composer textarea { min-height: 44px; max-height: 200px; }
.typing { color: var(--muted); font-size: 12.5px; padding: 0 18px 10px; }
.typing i { display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: var(--accent); margin-right: 3px; animation: blink 1.2s infinite; }
.typing i:nth-child(2) { animation-delay: .2s; } .typing i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .2 } 40% { opacity: 1 } }

/* unibox */
.unibox { display: grid; grid-template-columns: 360px 1fr; gap: 14px; height: calc(100vh - 140px); }
.unibox .list { overflow-y: auto; padding: 0; }
.unibox .item { padding: 12px 14px; border-bottom: 1px solid var(--line); cursor: pointer; }
.unibox .item:hover { background: var(--panel-2); } .unibox .item.on { background: var(--accent-soft); }
.unibox .item.unread .from { font-weight: 700; }
.thread { overflow-y: auto; }
.mail { border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; margin-bottom: 10px; }
.mail.out { background: var(--panel-2); }
.mail .meta { font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.mail .body { white-space: pre-wrap; word-break: break-word; }

/* sequence editor */
.step { border: 1px solid var(--line); border-radius: 10px; padding: 14px; background: var(--panel); }
.step + .step { margin-top: 0; }
.wait { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; padding: 10px 14px; }
.wait input { width: 70px; }
.variant { border-left: 3px solid var(--accent-soft); padding-left: 12px; margin-top: 10px; }
.lint { font-size: 12px; margin-top: 6px; }
.diff { font-family: var(--mono); font-size: 12px; white-space: pre; overflow: auto; max-height: 420px; background: var(--panel-2); border-radius: 8px; padding: 10px; border: 1px solid var(--line); }
.diff .a { color: var(--good); } .diff .d { color: var(--bad); } .diff .h { color: var(--info); }

@media (max-width: 900px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .side { position: fixed; left: 0; top: 0; width: 240px; z-index: 40; transform: translateX(-100%); transition: transform .2s; box-shadow: 0 0 40px rgba(0,0,0,.2); }
  .side.open { transform: none; }
  .menu-btn { display: inline-flex; }
  .main { padding: 16px 16px 60px; }
  .g2, .g3, .g4 { grid-template-columns: 1fr 1fr; }
  .chatwrap, .unibox { grid-template-columns: 1fr; height: auto; }
  .chat { height: calc(100vh - 110px); }
  .chatwrap > .card:last-child { display: none; }
  .unibox .list { max-height: 40vh; }
}
@media (max-width: 520px) { .g2, .g3, .g4 { grid-template-columns: 1fr; } }
