:root {
  color-scheme: light;
  font: 15px/1.5 Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --ink: #252525;
  --muted: #666;
  --canvas: #fff;
  --sidebar: #f6f6f5;
  --surface: #fff;
  --line: #e8e8e7;
  --hover: #f4f4f3;
  --selected: #eaeaea;
  --radius: 7px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; min-width: 280px; color: var(--ink); background: var(--canvas); }
a, button { color: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button { font: inherit; cursor: pointer; }
button:disabled { cursor: default; }
:focus-visible { outline: 2px solid #646464; outline-offset: 3px; }
[tabindex="-1"]:focus { outline: none; }
h1, h2, h3, p { margin: 0; }
.skip { position: fixed; z-index: 10; top: 12px; left: 12px; padding: 8px 12px; background: white; transform: translateY(-200%); }
.skip:focus { transform: translateY(0); }

.sidebar { position: fixed; z-index: 2; inset: 0 auto 0 0; width: 224px; padding: 26px 16px; background: var(--sidebar); border-right: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 11px; padding: 0 8px; }
.brand strong { display: block; font-size: 16px; letter-spacing: -.025em; }
.brand small { display: block; color: var(--muted); font-size: 12px; }
.brand-icon { display: grid; grid-template-columns: 1fr 1fr; gap: 3px; width: 36px; height: 36px; padding: 10px; border-radius: 8px; background: var(--ink); }
.brand-icon i { background: #fff; border-radius: 1.5px; }
.brand-icon i:last-child { opacity: .48; }
.navigation { display: grid; gap: 5px; margin-top: 36px; }
.navigation a { display: flex; align-items: center; gap: 11px; min-height: 42px; padding: 8px 11px; border-radius: 8px; color: var(--muted); text-decoration: none; font-weight: 500; }
.navigation a:hover { background: #ededec; color: var(--ink); }
.navigation a[aria-current="page"] { color: var(--ink); background: var(--selected); font-weight: 650; }
.mobile-label { display: none; }
.icon { display: inline-grid; place-items: center; width: 19px; height: 19px; flex: 0 0 19px; }
.icon::before { display: block; }
.icon-agents::before { content: "▤"; font-size: 20px; line-height: 1; }
.icon-access::before { content: "♙"; font-size: 23px; line-height: 1; }
.icon-telegram::before { content: "➤"; transform: rotate(-32deg); font-size: 17px; line-height: 1; }
.icon-models::before { content: "✧"; font-size: 24px; line-height: 1; }
.icon-connections::before { content: "⛓"; font-size: 17px; line-height: 1; }

.workspace { margin-left: 224px; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; min-height: 58px; padding: 12px clamp(24px, 4vw, 60px); }
.workspace-name { min-width: 0; color: var(--muted); font-size: 13px; overflow-wrap: anywhere; }
.workspace-name strong { color: var(--ink); font-weight: 620; }
.slash { color: #999; margin: 0 7px; }
.workspace-controls { display: flex; align-items: center; gap: 8px; min-width: 0; margin-left: auto; }
.demo-label { white-space: nowrap; color: #595959; background: #f0f0ef; border-radius: 5px; padding: 3px 9px; font-size: 12px; font-weight: 550; }
.session-name { max-width: min(18vw, 180px); overflow: hidden; color: var(--muted); font-size: 13px; text-overflow: ellipsis; white-space: nowrap; }
main { max-width: 1120px; margin: auto; padding: 56px clamp(24px, 4vw, 60px) 64px; }
.heading { display: flex; align-items: end; justify-content: space-between; gap: 18px; margin-bottom: 28px; }
h1 { font-size: clamp(34px, 4vw, 45px); line-height: 1.12; letter-spacing: -.055em; font-weight: 720; }
.heading p { color: var(--muted); margin-top: 9px; max-width: 52ch; }
.button { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 42px; padding: 8px 14px; border: 1px solid #dedede; border-radius: 6px; color: var(--ink); background: white; font-size: 13px; font-weight: 630; white-space: nowrap; text-decoration: none; }
.button:hover { background: var(--hover); }
.button.primary { background: var(--ink); color: #fff; border-color: var(--ink); }
.button.primary:hover { background: #3d3d3d; }
.button:disabled { color: var(--muted); background: #f6f6f6; }

.metrics { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); margin-bottom: 32px; padding: 2px 0 16px; border-bottom: 1px solid var(--line); }
.metric { display: grid; gap: 4px; align-content: start; padding: 0 20px; min-width: 0; }
.metric:first-child { padding-left: 0; }
.metric + .metric { border-left: 1px solid var(--line); }
.metric span { color: var(--muted); font-size: 13px; }
.metric strong { font-size: 30px; line-height: 1.1; letter-spacing: -.04em; }
.columns { display: grid; align-items: start; grid-template-columns: minmax(0,1fr) minmax(210px,.43fr); gap: 18px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); min-width: 0; }
.card-title { padding: 17px 20px; border-bottom: 1px solid var(--line); }
h2 { font-size: 16px; letter-spacing: -.02em; font-weight: 680; }
.list { padding: 0; margin: 0; list-style: none; }
.row + .row, .run + .run { border-top: 1px solid var(--line); }
.row { display: grid; grid-template-columns: auto minmax(0,1fr) auto; align-items: center; gap: 13px; padding: 16px 20px; }
.glyph { display: grid; place-items: center; width: 36px; height: 36px; border-radius: 6px; background: #f0f0ef; color: #575757; font-weight: 680; font-size: 13px; }
.row-info { min-width: 0; }
.row-title { min-width: 0; display: flex; align-items: center; flex-wrap: wrap; gap: 5px 9px; }
.row h3 { font-size: 14px; font-weight: 660; }
.row p, .run p, .muted { color: var(--muted); font-size: 13px; }
.row p { margin-top: 3px; }
.row-action { display: inline-flex; align-items: center; justify-content: center; gap: 7px; min-width: 44px; min-height: 44px; border: none; border-radius: 6px; padding: 0 6px; background: transparent; color: #555; font-size: 13px; font-weight: 600; text-decoration: none; }
.row-action:hover { background: var(--hover); }
a.row-action { font-size: 24px; line-height: 1; }
.pill { display: inline-flex; align-items: center; gap: 5px; border-radius: 4px; padding: 2px 7px; background: #f3f3f2; color: #555; font-size: 11px; font-weight: 600; white-space: nowrap; }
.pill::before { content: ""; width: 5px; height: 5px; border-radius: 50%; background: currentColor; }
.pill.ok::before { background: #818181; }
.pill.warn { background: #e9e9e7; color: #3b3b3b; }
.pill.warn::before { content: "!"; width: auto; height: auto; background: none; font-weight: 800; }
.run { display: grid; gap: 4px; padding: 14px 18px; }
.run strong { font-size: 13px; font-weight: 660; }
.run time { color: var(--muted); font-size: 12px; }
.settings-card { max-width: 920px; }
.agent-page { max-width: 900px; }
.agent-document { max-width: 64ch; margin-inline: auto; }
.back-link { display: inline-flex; align-items: center; gap: 8px; min-height: 44px; color: var(--muted); text-decoration: none; font-size: 13px; }
.back-link:hover { color: var(--ink); text-decoration: underline; }
.agent-heading { margin-top: 20px; }
.agent-heading p { margin-top: 12px; color: var(--muted); line-height: 1.7; }
.agent-properties { margin: 28px 0 0; padding-bottom: 22px; border-bottom: 1px solid var(--line); }
.agent-properties div { display: grid; grid-template-columns: minmax(100px, 180px) minmax(0,1fr); gap: 12px; padding: 6px 0; }
.agent-properties dt { color: var(--muted); font-size: 13px; }
.agent-properties dd { margin: 0; font-size: 14px; }
.agent-result { margin-top: 28px; }
.agent-result h2 { font-size: 22px; }
.agent-result p { margin-top: 6px; }
.detail-history { margin-top: 24px; border: 1px solid var(--line); border-radius: var(--radius); }
.agent-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 24px; }

html[data-live]:not([data-admin-ready]) .sidebar,
html[data-live]:not([data-admin-ready]) .topbar { display: none; }
html[data-live]:not([data-admin-ready]) .workspace { margin-left: 0; }
.session-exit { min-height: 44px; }
.session-message, .form-error { color: #852b2b; font-size: 13px; }
.session-message { order: -1; }
.access-sections { display: grid; gap: 18px; max-width: 920px; }
.access-sections .row-info, .access-document .agent-heading { overflow-wrap: anywhere; }
.access-empty { padding: 16px 20px; color: var(--muted); font-size: 14px; }
.access-status { margin-top: 12px; color: var(--muted); }
.auth-document { max-width: 430px; }
.access-retry { margin-top: 22px; }
.access-form { display: grid; gap: 20px; margin-top: 26px; }
.form-field { display: grid; gap: 6px; font-size: 14px; font-weight: 620; }
.form-field input, .form-field select {
  width: 100%;
  min-height: 44px;
  padding: 8px 11px;
  border: 1px solid #d5d5d4;
  border-radius: 6px;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-size: 16px;
  font-weight: 400;
}
.form-field small { font-size: 13px; font-weight: 400; color: var(--muted); }
.permission-fields { min-width: 0; margin: 0; padding: 0; border: 0; }
.permission-fields legend { margin-bottom: 3px; padding: 0; font-size: 14px; font-weight: 620; }
.permission-fields label { display: flex; align-items: center; gap: 9px; min-height: 44px; cursor: pointer; }
.permission-fields input { width: 17px; height: 17px; margin: 0; accent-color: var(--ink); }
.form-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.form-actions .button { min-height: 44px; }
.auth-document > .form-actions { margin-top: 22px; }
.auth-document > .form-error { margin-top: 12px; }

@media (max-width: 1040px) {
  .columns { grid-template-columns: 1fr; }
  .columns > :last-child .list { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); }
  .columns > :last-child .run + .run { border-top: 0; border-left: 1px solid var(--line); }
}

@media (max-width: 760px) {
  .workspace { margin-left: 0; }
  .brand { display: none; }
  .sidebar { inset: auto 0 0; width: auto; padding: 0 5px env(safe-area-inset-bottom); border: 0; border-top: 1px solid var(--line); background: var(--sidebar); }
  .navigation { margin: 0; gap: 1px; grid-template-columns: repeat(5,minmax(0,1fr)); }
  .navigation a { display: flex; flex-direction: column; justify-content: center; gap: 3px; min-height: 60px; padding: 6px 1px; font-size: clamp(10px,2.7vw,12px); border-radius: 0; text-align: center; }
  .navigation a[aria-current="page"] { box-shadow: inset 0 2px var(--ink); }
  .desktop-label, .slash { display: none; }
  .mobile-label { display: inline; }
  .topbar { min-height: 58px; padding: 9px 16px; gap: 6px; }
  .workspace-name { font-size: 0; }
  .workspace-name strong { font-size: 13px; }
  .workspace-controls { flex-shrink: 0; }
  .session-name { display: none; }
  main { padding: 27px 16px calc(86px + env(safe-area-inset-bottom)); }
  .heading { align-items: start; flex-direction: column; margin-bottom: 20px; gap: 13px; }
  .heading p { font-size: 14px; margin-top: 6px; }
  .metrics { margin-bottom: 18px; }
  .metric { padding: 0 8px; gap: 6px; }
  .metric span { font-size: 11px; }
  .metric strong { font-size: 24px; }
  .card-title { padding: 12px; }
  .row { padding: 12px; gap: 8px; }
  .glyph { width: 34px; height: 34px; }
  .row h3 { font-size: 13px; }
  .row p { font-size: 12px; }
  .row-action { padding: 0 4px; }
  .agent-heading { margin-top: 12px; }
  .agent-properties div { grid-template-columns: minmax(100px, .42fr) minmax(0,1fr); }
  .columns > :last-child .list { display: block; }
  .columns > :last-child .run { padding: 12px; }
  .columns > :last-child .run + .run { border-left: 0; border-top: 1px solid var(--line); }
  .access-sections { gap: 12px; }
  .access-empty { padding: 12px; }
}
