:root {
  color-scheme: light;
  --paper: #f1efe9;
  --surface: #fbfaf6;
  --ink: #171b19;
  --muted: #686d69;
  --line: #cbc9c1;
  --accent: #dc5b36;
  --accent-dark: #a9361b;
  --positive: #26725a;
  --danger: #9b3428;
  --radius: 14px;
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 320px; background: var(--paper); color: var(--ink); }
button, input, select { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; }

.masthead, footer { display: flex; align-items: center; justify-content: space-between; padding: 22px clamp(22px, 5vw, 72px); }
.masthead { border-bottom: 1px solid var(--line); }
.brand { display: inline-flex; align-items: center; gap: 10px; color: var(--ink); font-weight: 750; text-decoration: none; letter-spacing: -.02em; }
.brand-mark { display: grid; place-items: center; width: 29px; height: 29px; border-radius: 50%; background: var(--ink); color: var(--surface); font-family: Georgia, serif; }
.environment { display: flex; gap: 8px; align-items: center; color: var(--muted); font-size: .78rem; font-weight: 650; letter-spacing: .08em; text-transform: uppercase; }
.environment-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--positive); box-shadow: 0 0 0 4px #26725a18; }
.environment a { color: var(--accent-dark); text-underline-offset: 3px; }

main { width: min(1180px, calc(100% - 44px)); margin: 0 auto; padding: 26px 0 0; }
.viewnav { position: sticky; top: 0; z-index: 5; display: flex; gap: 26px; overflow-x: auto; padding: 0 clamp(22px, 5vw, 72px); background: var(--paper); border-bottom: 1px solid var(--line); scrollbar-width: none; }
.viewnav::-webkit-scrollbar { display: none; }
.viewtab { flex: none; border: 0; border-bottom: 2px solid transparent; margin-bottom: -1px; padding: 15px 2px; background: transparent; color: var(--muted); font-size: .92rem; font-weight: 650; letter-spacing: -.01em; white-space: nowrap; transition: color .16s; }
.viewtab:hover:not([aria-selected="true"]) { color: var(--ink); }
.viewtab[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--accent); }
.viewtab:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; border-radius: 7px; }
.view { animation: viewin .18s ease-out; }
.view > :first-child { margin-top: 0; }
.view-head { padding: clamp(18px, 3.5vw, 34px) 0 26px; }
.view-head h1 { margin: 0; max-width: 26ch; font-family: Georgia, "Times New Roman", serif; font-size: clamp(2rem, 3vw, 2.6rem); font-weight: 400; letter-spacing: -.035em; line-height: 1.03; text-wrap: balance; }
.view-head p { margin: 12px 0 0; max-width: 62ch; color: var(--muted); font-size: .96rem; line-height: 1.55; }
@keyframes viewin { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.notice { margin: 0 0 18px; padding: 13px 16px; border: 1px solid var(--line); border-radius: 7px; background: #fffefa; font-size: .9rem; }
.notice.error { border-color: #d6b8ae; background: #fff7f3; color: var(--danger); }
.workspace { max-width: 760px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); overflow: hidden; box-shadow: 0 20px 60px #30332f0a; }
.setup-panel, .status-panel { padding: clamp(25px, 4vw, 46px); }
.status-panel { min-height: 460px; flex-direction: column; background: #e7e4dc; }
/* One panel at a time: setup form while idle, live status while active. */
.workspace:not(.is-active) .status-panel { display: none; }
.workspace.is-active .setup-panel { display: none; }
.workspace.is-active .status-panel { display: flex; }
.section-heading, .status-topline { display: flex; align-items: center; justify-content: space-between; gap: 22px; }
.section-heading h2, .status-topline h2, .last-session h2, .connection-group h2 { margin: 0; font-family: Georgia, serif; font-size: 1.75rem; font-weight: 400; letter-spacing: -.03em; }
.connection-group h2 { margin-bottom: 4px; }
.connection-group + .connection-group { margin-top: 22px; }
.section-heading > p { margin: 0; color: var(--muted); font-size: .77rem; }
.field-label { display: block; margin: 28px 0 9px; font-size: .82rem; font-weight: 700; }
input[type="url"], input[type="text"] { width: 100%; padding: 15px 16px; border: 1px solid #aaa9a3; border-radius: 7px; outline: none; background: white; color: var(--ink); transition: border-color .18s, box-shadow .18s; }
input[type="url"]:focus, input[type="text"]:focus { border-color: var(--ink); box-shadow: 0 0 0 3px #171b1912; }
.field-help, .field-error, .local-note { color: var(--muted); font-size: .78rem; line-height: 1.5; }
.field-error { color: var(--danger); }
.bots-heading { margin-top: 38px; padding-top: 30px; border-top: 1px solid var(--line); }
.text-button { border: 0; padding: 4px 0; background: transparent; color: var(--accent-dark); font-size: .78rem; font-weight: 700; }
.bot-list { display: grid; gap: 10px; margin-top: 20px; }
.bot-option { position: relative; display: grid; grid-template-columns: auto 1fr auto; gap: 14px; align-items: center; padding: 14px 17px; border: 1px solid var(--line); border-radius: 9px; background: #fffefa; transition: border-color .16s, background .16s; }
.bot-option:has(input:checked) { border-color: #5d625e; background: white; }
.bot-option input { width: 18px; height: 18px; margin: 0; accent-color: var(--accent); }
.bot-option strong { display: block; font-size: .92rem; }
.bot-meta { color: var(--muted); font-size: .68rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; }
.bot-skeleton { height: 78px; border-radius: 9px; background: linear-gradient(100deg, #e9e7e0 30%, #f4f2ed 50%, #e9e7e0 70%); background-size: 250% 100%; animation: shimmer 1.4s infinite; }
@keyframes shimmer { to { background-position-x: -250%; } }
.primary-button, .stop-button { display: flex; width: 100%; align-items: center; justify-content: space-between; border-radius: 7px; font-weight: 750; }
.primary-button { margin-top: 26px; padding: 16px 18px; border: 1px solid var(--accent); background: var(--accent); color: white; }
.primary-button:hover:not(:disabled) { background: var(--accent-dark); border-color: var(--accent-dark); }
.primary-button:disabled { border-color: #b9b7b0; background: #d2d0ca; color: #777a76; }

.status-badge { display: inline-flex; align-items: center; gap: 7px; padding: 6px 9px; border: 1px solid #b4b2ab; border-radius: 999px; color: var(--muted); font-size: .7rem; font-weight: 750; letter-spacing: .06em; text-transform: uppercase; }
.status-badge span { width: 7px; height: 7px; border-radius: 50%; background: #8b8e89; }
.status-badge.running { border-color: #71a493; color: var(--positive); }
.status-badge.running span { background: var(--positive); animation: pulse 2s infinite; }
.status-badge.starting span, .status-badge.stopping span { background: var(--accent); animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .3; } }
.status-visual { position: relative; display: grid; place-items: center; width: 178px; height: 178px; margin: 48px auto 35px; }
.orbit, .status-core { position: absolute; border-radius: 50%; }
.orbit { border: 1px solid #aaa9a2; }
.orbit-one { width: 100%; height: 100%; }
.orbit-two { width: 66%; height: 66%; border-style: dashed; }
.status-core { width: 28px; height: 28px; background: #9a9c97; box-shadow: 0 0 0 12px #9a9c9715; transition: background .3s, box-shadow .3s; }
.status-core.running { background: var(--positive); box-shadow: 0 0 0 12px #26725a18; }
.session-details { margin: 0; }
.session-details div { display: grid; grid-template-columns: 85px 1fr; gap: 16px; padding: 11px 0; border-bottom: 1px solid #c7c4bc; }
.session-details dt { color: var(--muted); font-size: .72rem; }
.session-details dd { margin: 0; overflow-wrap: anywhere; font-size: .78rem; font-weight: 650; }
.stop-button { margin-top: auto; padding: 13px 15px; border: 1px solid #a5a39d; background: transparent; color: var(--ink); }
.stop-button:hover:not(:disabled) { border-color: var(--danger); color: var(--danger); }
.stop-button:disabled { opacity: .48; }
.local-note { margin: 12px 0 0; text-align: center; }
.manage-bots, .connection-group { margin: 22px 0 0; padding: clamp(25px, 4vw, 46px); border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.view-head + section { margin-top: 0; }
.model-gate { max-width: 620px; padding: clamp(26px, 4vw, 42px); border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.model-gate h2 { margin: 0 0 10px; font-family: Georgia, serif; font-size: 1.55rem; font-weight: 400; letter-spacing: -.02em; }
.model-gate p { margin: 0 0 22px; max-width: 54ch; color: var(--muted); line-height: 1.55; }
.model-gate-cta { padding: 13px 18px; border: 1px solid var(--accent); border-radius: 7px; background: var(--accent); color: #fff; font-weight: 750; }
.model-gate-cta:hover { background: var(--accent-dark); border-color: var(--accent-dark); }
.roster-toolbar { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 6px 18px; margin: 22px 0 0; border-bottom: 1px solid var(--line); }
.roster-toolbar .roster-tabs { flex: 1 1 auto; margin: 0; border: 0; }
.roster-toolbar #add-bot { flex: none; padding-bottom: 10px; white-space: nowrap; }
.roster-tabs { display: flex; flex-wrap: wrap; gap: 2px; margin: 22px 0 0; border-bottom: 1px solid var(--line); }
.roster-tab { border: 0; border-bottom: 2px solid transparent; margin-bottom: -1px; padding: 9px 14px; background: transparent; color: var(--muted); font-size: .85rem; font-weight: 650; }
.roster-tab:hover:not([aria-selected="true"]) { color: var(--ink); }
.roster-tab[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--accent); }
.roster-tab:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; border-radius: 7px; }
.roster-editor { display: grid; gap: 12px; margin: 20px 0; }
.roster-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px; padding: 15px; border: 1px solid var(--line); border-radius: 9px; background: #fffefa; }
.roster-row[hidden] { display: none; } /* [hidden] alone loses to display:grid above */
.roster-row input, .roster-row select, .roster-row textarea { min-width: 0; padding: 10px 12px; border: 1px solid #aaa9a3; border-radius: 7px; outline: none; background-color: white; color: var(--ink); font: inherit; font-size: .88rem; }
.roster-row input:focus, .roster-row select:focus, .roster-row textarea:focus { border-color: var(--ink); box-shadow: 0 0 0 3px #171b1912; }
.roster-row textarea { min-height: 116px; resize: vertical; line-height: 1.45; }
.roster-row select:disabled { background-color: #ecebe6; color: var(--muted); cursor: not-allowed; }
.roster-row .field-note { margin-top: 6px; color: var(--danger); font-size: .72rem; line-height: 1.4; }
.roster-row > label { display: flex; flex-direction: column; gap: 4px; font-size: .74rem; font-weight: 650; color: var(--muted); }
.roster-row .draft-field, .roster-row label:has(.bot-voice-instructions) { grid-column: 1 / -1; }
.draft-field { min-width: 0; }
.draft-field-heading { display: flex; align-items: baseline; justify-content: space-between; gap: 16px; margin-bottom: 4px; }
.draft-field-heading label { color: var(--muted); font-size: .74rem; font-weight: 650; }
.draft-field textarea { width: 100%; }
.draft-link { border: 0; padding: 2px 0; background: transparent; color: var(--accent-dark); font: inherit; font-size: .74rem; font-weight: 700; text-decoration: underline; text-underline-offset: 2px; }
.draft-link:hover:not(:disabled) { color: var(--ink); }
.draft-link:focus-visible { outline: 2px solid var(--ink); outline-offset: 3px; border-radius: 2px; }
.draft-link:disabled { color: var(--muted); cursor: wait; text-decoration: none; }
.draft-status { display: block; min-height: 1rem; margin-top: 4px; color: var(--muted); font-size: .72rem; }
.draft-status.error { color: var(--danger); }
.draft-status.success { color: var(--accent-dark); }
.roster-row .text-button { justify-self: end; }
.roster-row .voice-preview { align-self: end; justify-self: start; padding: 10px 16px; border: 1px solid var(--line); border-radius: 7px; color: var(--accent-dark); }
.roster-row .voice-preview:hover:not(:disabled) { border-color: var(--ink); }
.manage-bots .primary-button { max-width: 320px; }
.provider-unavailable { margin: 20px 0 0; padding: 14px 16px; border: 1px solid #d6b8ae; border-radius: 7px; background: #fff7f3; color: var(--danger); font-size: .82rem; line-height: 1.5; }
.connection-cards { display: grid; grid-template-columns: 1fr; gap: 12px; margin: 18px 0 0; align-items: start; }
.provider-card { display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 16px 18px; border: 1px solid var(--line); border-radius: 9px; background: #fffefa; }
.provider-card h3 { margin: 0 0 5px; font-family: Georgia, serif; font-size: 1.2rem; font-weight: 400; }
.provider-card p { margin: 0; color: var(--muted); font-size: .75rem; line-height: 1.45; }
.provider-card .provider-scope { margin-top: 4px; color: var(--ink); }
.provider-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; align-items: center; gap: 13px; }
.provider-status { padding: 5px 8px; border: 1px solid var(--line); border-radius: 999px; color: var(--muted); font-size: .65rem; font-weight: 750; letter-spacing: .07em; text-transform: uppercase; }
.provider-status.active { border-color: #7ea997; color: var(--positive); }
.provider-status.revoked { border-color: #d6b8ae; color: var(--danger); }
.text-button.danger { color: var(--danger); }
/* Add tile: same grid cell as a card, styled as an empty affordance rather than data. */
.connection-add-tile { display: flex; align-items: center; justify-content: center; min-height: 84px; border: 1px dashed #aaa9a3; border-radius: 9px; background: transparent; color: var(--muted); font-size: 1.6rem; font-weight: 400; transition: border-color .16s, color .16s; }
.connection-add-tile:hover:not(:disabled) { border-color: var(--ink); color: var(--ink); }
.connection-add-tile:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
/* Expanded card: an existing card (Edit) or the add-tile (Add), showing the shared form in place. */
.provider-card-expanded { display: block; grid-column: 1 / -1; }
.provider-card-expanded > h3 { margin: 0 0 16px; }
.provider-card-expanded .provider-form { margin-top: 0; padding-top: 0; border-top: 0; }
.provider-form { margin-top: 24px; padding-top: 24px; border-top: 1px solid var(--line); }
#provider-secret-toggle { margin-top: 10px; }
#provider-cancel { margin-top: 10px; }
.provider-grid, .secret-fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.provider-form label, .provider-bots legend { color: var(--muted); font-size: .73rem; font-weight: 700; }
.provider-form label span { font-weight: 400; }
.provider-form input, .provider-form select { display: block; width: 100%; margin-top: 7px; padding: 11px 12px; border: 1px solid #aaa9a3; border-radius: 7px; outline: none; background-color: white; color: var(--ink); }
.provider-form input:focus, .provider-form select:focus { border-color: var(--ink); box-shadow: 0 0 0 3px #171b1912; }
/* Safari forces native <select> to its own height and ignores padding; appearance:none makes it match
   the text inputs. Caret is drawn with gradients (a data: URI would be blocked by the panel's img-src CSP). */
.provider-form select, .roster-row select {
  appearance: none; -webkit-appearance: none; padding-right: 30px;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: right 15px center, right 11px center;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}
.secret-fields { margin-top: 12px; padding: 15px; border: 1px solid #d4cfc2; border-radius: 9px; background: #f6f2e9; }
.provider-bots { margin: 16px 0 0; padding: 0; border: 0; }
#agent-bot-list { display: flex; flex-wrap: wrap; gap: 9px; margin-top: 9px; }
#agent-bot-list label { display: inline-flex; align-items: center; gap: 7px; padding: 8px 11px; border: 1px solid var(--line); border-radius: 999px; background: white; color: var(--ink); }
#agent-bot-list input { width: auto; margin: 0; accent-color: var(--accent); }
.provider-form .primary-button { max-width: 360px; }
.agent-token-panel { margin-top: 20px; padding: 16px; border: 1px solid #b69767; border-radius: 9px; background: #fff7e8; font-size: .82rem; }
.agent-token-panel code { display: block; margin: 10px 0; padding: 12px; overflow-wrap: anywhere; user-select: all; background: #f4ead7; }
.agent-token-panel p { margin: 0; color: var(--muted); line-height: 1.45; }
.last-session { margin: 22px 0 0; padding: 24px 28px; border-left: 1px solid var(--line); }
.last-session p:last-child { margin: 8px 0 0; color: var(--muted); font-size: .85rem; }
footer { margin-top: 70px; border-top: 1px solid var(--line); color: var(--muted); font-size: .7rem; letter-spacing: .08em; text-transform: uppercase; }

@media (max-width: 780px) {
  .masthead { padding: 18px 22px; }
  main { width: min(100% - 28px, 620px); }
  .provider-card { align-items: flex-start; flex-direction: column; }
  .provider-actions { justify-content: flex-start; }
  .provider-grid, .secret-fields { grid-template-columns: 1fr; }
  footer { gap: 14px; padding: 20px 22px; }
}

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