@layer base, layout, components, responsive;

@font-face {
  font-family: 'JetBrains Mono';
  src: url('/src/fonts/JetBrainsMono-SemiBold.woff2') format('woff2');
  font-style: normal;
  font-weight: 600;
  font-display: swap;
}

@layer components {
  .sessions-page { display: grid; grid-template-columns: 280px minmax(0, 1fr); height: calc(100dvh - 56px); gap: 24px; position: relative; }
  .conversation-list { background: var(--sidebar-bg); border-radius: var(--radius); padding: 16px 12px; display: flex; flex-direction: column; min-height: 0; }
  .conversation-heading { display: flex; align-items: center; justify-content: space-between; margin: 0 4px 12px; }
  .conversation-heading h1 { font-size: var(--text-section); font-weight: var(--weight-medium); margin: 0; }
  .conversation-picker { position: relative; margin-bottom: 12px; }
  [data-agent-picker] { width: 100%; display: flex; align-items: center; justify-content: space-between; gap: 8px; text-align: left; padding: 10px 12px; }
  [data-agent-picker] .icon { width: 16px; height: 16px; flex: 0 0 auto; }
  .conversation-options { position: absolute; z-index: 10; top: calc(100% + 4px); width: 100%; max-height: 300px; overflow: auto; padding: 6px; background: var(--menu); box-shadow: var(--shadow-menu); border-radius: var(--radius); }
  .conversation-options button { display: flex; align-items: center; gap: 12px; width: 100%; text-align: left; padding: 10px; }
  .conversation-options [aria-selected=true] { background: var(--hover); }
  .conversation-search { width: 100%; margin-bottom: 16px; padding: 10px 12px; background: var(--panel); color: var(--text); border: 0; border-radius: var(--radius); outline-offset: 2px; }
  .conversation-items { overflow-y: auto; min-height: 0; flex: 1; }
  .conversation-item { display: block; width: 100%; text-align: left; padding: 12px; margin-bottom: 4px; }
  .conversation-item[aria-current] { background: var(--hover); }
  .conversation-item > span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .conversation-item small { display: flex; justify-content: space-between; gap: 8px; margin-top: 7px; color: var(--muted); font-size: var(--text-caption); }
  .conversation-item time { flex: 0 0 auto; }
  .conversation-thread { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
  .conversation-heading h1 { margin-right: auto; }
  .web-composer { display: flex; align-items: flex-end; gap: 8px; flex-shrink: 0; margin: 0 auto 16px; padding: 8px; width: min(760px, calc(100% - 32px)); background: var(--panel); border-radius: 28px; }
  .web-composer:focus-within { box-shadow: 0 0 0 1px var(--separator); }
  .web-editor { position: relative; flex: 1; min-width: 0; min-height: 40px; max-height: 184px; overflow-y: auto; padding: 8px 8px 8px 14px; color: var(--text); font: inherit; line-height: 24px; white-space: pre-wrap; overflow-wrap: anywhere; }
  .web-editor:focus-visible { outline: none; }
  .web-editor[data-empty="true"]::before { content: attr(data-placeholder); position: absolute; color: var(--muted); pointer-events: none; }
  .web-composer .web-send { width: 40px; height: 40px; flex: 0 0 auto; border-radius: 50%; }
  .web-turn-status, .web-read-only { margin: 8px auto 12px; width: min(760px, calc(100% - 32px)); color: var(--muted); font-size: var(--text-caption); }
  .conversation-toolbar { display: flex; align-items: center; min-height: 48px; gap: 12px; padding: 0 16px 12px; }
  .conversation-toolbar > span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .conversation-toolbar [data-session-back] { display: none; }
  .conversation-scroll { overflow-y: auto; min-height: 0; flex: 1; padding: 12px 24px 32px; overflow-anchor: none; }
  .conversation-messages { max-width: 760px; margin: 0 auto; }
  .conversation-message { margin: 0 0 28px; overflow-wrap: anywhere; line-height: 1.75; }
  .conversation-message.user { margin-left: min(12%, 72px); background: var(--panel); border-radius: var(--radius); padding: 16px 20px; }
  .message-meta { display: flex; align-items: baseline; gap: 12px; color: var(--muted); font-size: var(--text-caption); margin-bottom: 8px; }
  .message-meta time { font-size: 11px; }
  .message-meta { flex-wrap: wrap; }
  .conversation-origin { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .conversation-options button.conversation-retired, [data-agent-picker].conversation-retired, .archived-row.is-retired { color: var(--muted); }
  .conversation-retired-label { margin-left: auto; font-size: var(--text-caption); color: var(--muted); white-space: nowrap; }
  [data-session-latest] { margin-left: auto; white-space: nowrap; }
  .message-text { white-space: pre-wrap; }
  .conversation-message pre { overflow-x: auto; white-space: pre; background: var(--panel); padding: 16px; border-radius: var(--radius); }
  .conversation-message code { font-family: ui-monospace, monospace; font-size: .92em; }
  .conversation-empty { color: var(--muted); padding: 28px 12px; text-align: center; }
  .conversation-error { position: absolute; bottom: 0; right: 16px; max-width: calc(100% - 32px); padding: 12px 16px; background: var(--menu); border-radius: var(--radius); box-shadow: var(--shadow-menu); }
  .older-messages { display: block; margin: 0 auto 24px; }
  .account-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; width: 100%; padding: 14px 12px; text-align: left; }
  .account-row small { display: block; color: var(--muted); margin-top: 6px; font-size: var(--text-caption); }
  .account-row > span:last-child { display: flex; align-items: center; gap: 12px; white-space: nowrap; color: var(--muted); }
  .account-row svg { width: var(--icon-inline); height: var(--icon-inline); transform: rotate(-90deg); }
  .account-row.is-retired { color: var(--muted); }
  #account-form .field, #my-account-form .field { margin-bottom: 16px; }
  #account-form .type-picker { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
  #account-form .type-picker::before { display: none; }
  #account-form .type-option:has(input:checked) { background: var(--hover); }
  #read-only-dialog p { color: var(--muted); line-height: 1.7; }
  [data-help] { display: flex; align-items: center; gap: 6px; }
  .inline-help { display: inline-flex; position: relative; font-weight: var(--weight-regular); }
  .help-trigger { width: 26px; height: 26px; padding: 5px; color: var(--muted); display: grid; place-items: center; }
  .help-trigger svg { width: var(--icon-inline); height: var(--icon-inline); }
  .help-tooltip { position: fixed; inset: auto; margin: 0; border: 0; width: min(260px, calc(100vw - 32px)); max-height: calc(100dvh - 32px); overflow: auto; padding: 12px 14px; border-radius: var(--radius); background: var(--menu); color: var(--text); box-shadow: var(--shadow-menu); font-size: var(--text-body); font-weight: var(--weight-regular); line-height: 1.6; text-align: left; }
  .help-tooltip:popover-open { display: block; }
  .console-actions { display: flex; gap: 8px; flex-wrap: wrap; }
  .console-login-dialog { width: min(900px, calc(100vw - 32px)); }
  #console-qr { width: 100%; max-height: 65vh; object-fit: contain; border-radius: 12px; }
  .login-page { display: grid; place-items: center; min-height: 100dvh; padding: 112px 24px; }
  .login-brand, .brand { font-family: 'JetBrains Mono', monospace; color: var(--text); font-weight: 600; line-height: 1.15; letter-spacing: .025em; }
  .login-brand { position: absolute; top: clamp(24px, 3vw, 40px); left: clamp(24px, 3vw, 48px); font-size: clamp(32px, 6vw, 72px); }
  .login-form { width: min(100%, 400px); display: grid; gap: 48px; }
  .login-form .field { position: relative; margin: 0; gap: 0; }
  .login-label { position: absolute; bottom: calc(100% + 8px); left: 0; }
  .login-form .field input { min-height: 48px; padding: 12px 14px; }
  .login-form > .button { min-height: 48px; margin: 0; border: 1px solid var(--separator); }
  .handoff-page { width: min(100%, 440px); margin: 0; padding: 0; min-height: 0; }
  .handoff-page h1 { font-size: var(--text-title); font-weight: var(--weight-medium); margin: 0 0 28px; }
  .handoff-page dl { margin: 0 0 28px; }
  .handoff-page dl > div { display: grid; grid-template-columns: 64px minmax(0, 1fr); gap: 16px; margin: 12px 0; }
  .handoff-page dt { color: var(--muted); }
  .handoff-page dd { margin: 0; text-align: left; overflow-wrap: anywhere; }
  .handoff-page form { display: grid; gap: 24px; }
  .handoff-page [hidden] { display: none; }
  .handoff-page .field { margin: 0; }
  .handoff-page input, .handoff-page .button { min-height: 48px; }
  .handoff-page .button { border: 1px solid var(--separator); }
  #handoff-status { color: var(--muted); margin-top: 20px; }
  #handoff-status:empty { display: none; }
  #login-error { font-size: var(--text-body); line-height: 1.5; }
  #login-error:empty { display: none; }
  input:autofill { box-shadow: 0 0 0 1000px var(--panel) inset !important; -webkit-text-fill-color: var(--text) !important; caret-color: var(--text); }
  input:autofill:hover, input:autofill:focus { box-shadow: 0 0 0 1000px var(--hover) inset !important; }
}

@layer base {
  :root {
    color-scheme: light;
    --canvas: #ffffff;
    --sidebar-bg: #f9f9f9;
    --panel: #f5f5f5;
    --overlay: #ffffff;
    --menu: #ffffff;
    --menu-hover: #f0f0f0;
    --menu-selected: #e7e7e7;
    --separator: #00000014;
    --hover: #ebebeb;
    --pressed: #e3e3e3;
    --text: #171717;
    --muted: #6b6b6b;
    --focus: #737373;
    --avatar: #e8e8e8;
    --avatar-text: #525252;
    --scrim: #00000026;
    --detail-scrim: #0000001a;
    --radius: 12px;
    --surface-radius: var(--radius);
    --form-motion: 260ms cubic-bezier(.2, .8, .2, 1);
    --sidebar-expanded: 236px;
    --sidebar: var(--sidebar-expanded);
    --sidebar-motion: 260ms cubic-bezier(.2, .8, .2, 1);
    --shadow-menu: 0 12px 32px #00000016, 0 2px 6px #00000008;
    --shadow-dialog: 0 24px 80px #00000024, 0 4px 12px #00000008;
    --text-caption: 12px;
    --text-body: 14px;
    --text-section: 16px;
    --text-title: 20px;
    --weight-regular: 400;
    --weight-medium: 500;
    --icon-control: 20px;
    --icon-inline: 16px;
    font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC", "Microsoft YaHei", sans-serif;
    font-size: var(--text-body);
    font-weight: var(--weight-regular);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
  }
  :root[data-theme="dark"] {
    color-scheme: dark;
    --canvas: #000000;
    --sidebar-bg: #0d0d0d;
    --panel: #1a1a1a;
    --overlay: #212121;
    --menu: #303030;
    --menu-hover: #414141;
    --menu-selected: #3b3b3b;
    --separator: #ffffff1a;
    --hover: #333333;
    --pressed: #3a3a3a;
    --text: #f3f3f3;
    --muted: #afafaf;
    --focus: #b7b7b7;
    --avatar: #2e2e2e;
    --avatar-text: #d6d6d6;
    --scrim: #00000080;
    --detail-scrim: #00000066;
    --shadow-menu: 0 12px 32px #00000066, 0 2px 6px #00000033;
    --shadow-dialog: 0 24px 80px #00000080, 0 4px 12px #00000040;
  }
  * { box-sizing: border-box; }
  html { scrollbar-gutter: stable; }
  html:has(dialog[open]) { overflow: hidden; }
  body { margin: 0; background: var(--canvas); color: var(--text); }
  button, input, select { font: inherit; accent-color: var(--text); }
  ::selection { background: var(--text); color: var(--canvas); }
  button, a, input, select, summary { -webkit-tap-highlight-color: transparent; }
  button {
    cursor: pointer; color: inherit; border: 0; border-radius: var(--radius);
    background: transparent; transition: background-color 140ms;
  }
  button:hover:not(:disabled), .nav-item:hover, summary:hover { background-color: var(--hover); }
  button:active:not(:disabled), .nav-item:active { background-color: var(--pressed); }
  button:disabled { opacity: .4; cursor: not-allowed; }
  a { color: inherit; text-decoration: none; }
  button:focus-visible, a:focus-visible, summary:focus-visible {
    outline: 2px solid var(--focus); outline-offset: 2px;
  }
  input:focus-visible, select:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
  h1, h2, h3, p { margin: 0; }
  h1, h2 { font-size: var(--text-title); font-weight: var(--weight-medium); line-height: 1.4; }
  h3 { font-size: var(--text-section); font-weight: var(--weight-medium); line-height: 1.5; }
  svg { width: var(--icon-control); height: var(--icon-control); flex: 0 0 auto; vertical-align: middle; }
  .icon { display: block; }
  [data-icon] { display: inline-flex; }
  [hidden] { display: none !important; }
  .sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
  .skip-link { position: fixed; left: 16px; top: -70px; z-index: 10; padding: 12px; border-radius: var(--radius); background: var(--text); color: var(--canvas); }
  .skip-link:focus { top: 10px; }
}

@layer layout {
  .sidebar {
    position: fixed; inset: 0 auto 0 0; z-index: 4; width: var(--sidebar);
    height: 100dvh; padding: 12px 10px; background: var(--sidebar-bg);
    display: flex; flex-direction: column; gap: 20px;
  }
  .sidebar-top { position: relative; display: flex; align-items: center; justify-content: flex-end; gap: 8px; flex-shrink: 0; min-height: 44px; }
  .brand { position: absolute; left: 12px; border-radius: var(--radius); font-size: var(--text-title); white-space: nowrap; }
  .sidebar-actions { min-height: 0; flex: 1; overflow-y: auto; }
  .sidebar-footer { flex-shrink: 0; }
  main { margin-left: var(--sidebar); padding: 28px clamp(24px, 2vw, 28px); min-height: 100dvh; }
  .agent-cluster { width: 100%; max-width: 1440px; margin-inline: auto; }
  .archived-row { width: 100%; display: flex; justify-content: space-between; align-items: center; gap: 16px; padding: 14px 8px; text-align: left; }
  .archived-row > span:last-child { display: flex; align-items: center; gap: 8px; color: var(--muted); white-space: nowrap; }
  .archived-row > span:first-child { overflow-wrap: anywhere; }
  .archived-row .icon { width: 16px; height: 16px; transform: rotate(-90deg); }
  .archived-row + .archived-row { margin-top: 4px; }
  .about-summary { padding-block: 4px 28px; }
  .about-summary h3 { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 0; }
  .about-summary p { margin: 8px 0 0; line-height: 1.6; }
  .about-summary p, .about-version, .release-entry time { color: var(--muted); }
  .about-version { font-size: var(--text-body); font-weight: var(--weight-regular); }
  .release-heading { margin: 0 0 8px; font-size: var(--text-body); font-weight: var(--weight-medium); }
  .release-entry + .release-entry { margin-top: 4px; }
  .release-entry summary { cursor: pointer; display: flex; align-items: center; gap: 12px; min-height: 48px; padding: 12px 8px; list-style: none; border-radius: var(--radius); font-size: var(--text-body); }
  .release-entry summary::-webkit-details-marker { display: none; }
  .release-entry time { margin-left: auto; font-size: var(--text-caption); }
  .release-entry summary .icon { width: 16px; height: 16px; color: var(--muted); transform: rotate(-90deg); }
  .release-entry[open] summary .icon { transform: none; }
  .release-entry ul { list-style: disc outside; padding: 0 12px 16px 28px; margin: 0; color: var(--muted); font-size: var(--text-body); line-height: 1.7; }
  .release-entry li { margin-top: 8px; }
  .release-entry li::marker { font-size: .75em; }
  .settings-category [data-icon] { display: flex; flex: 0 0 20px; width: 20px; height: 20px; }
  .settings-category .icon { width: 20px; height: 20px; }
  .detail-actions { display: flex; flex-wrap: wrap; gap: 8px; }
  .agent-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 216px), 1fr)); gap: 14px; }
}

@layer components {
  .icon-button { width: 36px; height: 36px; display: inline-flex; align-items: center; justify-content: center; color: var(--muted); flex: 0 0 auto; padding: 0; }
  #sidebar-toggle { width: 44px; height: 44px; }
  #mobile-nav-toggle { display: none; }
  .nav-item {
    display: flex; align-items: center; gap: 11px; width: 100%; min-height: 44px;
    padding: 0 12px; border-radius: var(--radius); text-align: left; white-space: nowrap; overflow: hidden;
    font-size: var(--text-body); font-weight: var(--weight-regular); transition: background-color 140ms;
  }
  .nav-item[aria-current="page"] { background: var(--hover); }
  .nav-item svg { width: var(--icon-control); height: var(--icon-control); }
  .nav-label { flex-shrink: 0; }
  #sidebar-nav { margin-top: 4px; display: grid; gap: 4px; }
  .nav-item > [data-icon] { flex: 0 0 20px; width: var(--icon-control); height: var(--icon-control); display: grid; place-items: center; }
  .account { position: relative; }
  .account-toggle { position: relative; display: flex; gap: 10px; align-items: center; width: 100%; height: 44px; padding: 8px; text-align: left; overflow: hidden; }
  .account-avatar { display: grid; place-items: center; flex-shrink: 0; width: 28px; height: 28px; border-radius: var(--radius); background: var(--avatar); color: var(--avatar-text); font-size: var(--text-caption); font-weight: var(--weight-medium); transition: background-color 140ms; }
  .account-toggle:hover .account-avatar { background: transparent; }
  .account-label { position: absolute; left: 46px; right: 30px; display: flex; min-width: 0; flex-direction: column; gap: 1px; line-height: 1.4; white-space: nowrap; }
  .account-name { font-size: var(--text-body); font-weight: var(--weight-regular); }
  .account-label small { font-size: var(--text-caption); color: var(--muted); }
  .account-menu {
    --hover: var(--menu-hover);
    position: absolute; left: 0; bottom: calc(100% + 8px); width: 280px; max-width: calc(100vw - 32px);
    max-height: calc(100dvh - 84px); overflow-y: auto;
    padding: 8px; border-radius: var(--surface-radius); background: var(--menu); box-shadow: var(--shadow-menu);
  }
  .account-menu:not([hidden]) { animation: menu-in 140ms ease-out; }
  @keyframes menu-in { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }
  .account-intro { display: flex; align-items: center; gap: 12px; padding: 12px; font-size: var(--text-body); font-weight: var(--weight-medium); }
  .account-intro .account-avatar { width: 36px; height: 36px; background: var(--hover); font-size: var(--text-body); }
  .account-intro small { display: block; color: var(--muted); font-size: var(--text-caption); margin-top: 2px; font-weight: var(--weight-regular); }
  .menu-separator { height: 1px; margin: 8px 12px; background: var(--separator); }
  .account-menu button { display: flex; align-items: center; gap: 12px; width: 100%; min-height: 44px; padding: 10px 12px; text-align: left; font-size: var(--text-body); }
  .account-menu button:focus-visible { outline-offset: -2px; }
  .account-menu svg { width: var(--icon-control); height: var(--icon-control); }

  .agent-tile { min-width: 0; border-radius: var(--radius); background: var(--panel); }
  .agent-card {
    width: 100%; height: 100%; min-height: 150px; display: flex; flex-direction: column; gap: 22px;
    padding: 20px; text-align: left; scroll-margin: 24px;
  }
  .agent-card[aria-expanded="true"] { outline: 2px solid var(--focus); outline-offset: -2px; }
  .card-header { display: flex; align-items: center; gap: 10px; width: 100%; }
  .agent-avatar { display: grid; place-items: center; flex: 0 0 auto; width: 36px; height: 36px; border-radius: var(--radius); background: var(--avatar); color: var(--avatar-text); font-size: var(--text-body); font-weight: var(--weight-medium); letter-spacing: normal; }
  .card-identity { display: flex; flex-direction: column; gap: 3px; min-width: 0; flex: 1; }
  .agent-name { display: block; font-size: var(--text-body); font-weight: var(--weight-medium); letter-spacing: normal; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .agent-type { font-size: var(--text-caption); color: var(--muted); }
  .card-open { display: inline-flex; color: var(--muted); opacity: .4; transition: opacity 140ms; }
  .card-open svg { width: var(--icon-inline); height: var(--icon-inline); }
  .agent-card:is(:hover, :focus-visible) .card-open { opacity: 1; }
  .card-footer { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; margin-top: auto; width: 100%; }
  .agent-activity { display: block; max-width: 100%; font-size: var(--text-caption); color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .status-badge { display: inline-flex; align-items: center; gap: 7px; flex: 0 0 auto; white-space: nowrap; font-size: var(--text-caption); line-height: 1.5; font-weight: var(--weight-regular); }
  .status-badge svg { width: var(--icon-inline); height: var(--icon-inline); }
  .status-creating svg { animation: pending 800ms linear infinite; }
  .status-offline, .status-unknown { color: var(--muted); }
  .status-error, .status-failed { font-weight: var(--weight-medium); }
  @keyframes pending { to { transform: rotate(360deg); } }
  .empty { padding: 120px 12px; text-align: center; color: var(--muted); }
  .empty > [data-icon] { padding: 14px; border-radius: var(--radius); background: var(--panel); }
  .empty h2 { color: var(--text); font-size: var(--text-title); margin: 20px 0 24px; }

  dialog { color: var(--text); background: var(--overlay); border: 0; border-radius: var(--surface-radius); padding: 0; box-shadow: var(--shadow-dialog); }
  dialog::backdrop { background: var(--scrim); }
  .modal { --dialog-padding: 28px; width: min(520px, calc(100% - 32px)); max-height: calc(100dvh - 40px); padding: var(--dialog-padding); overflow-y: auto; overscroll-behavior: contain; }
  .modal[open], .settings-dialog[open] { animation: dialog-in 160ms ease-out; }
  @keyframes dialog-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }
  .modal-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 24px; }
  h2 { font-size: var(--text-title); letter-spacing: normal; font-weight: var(--weight-medium); }
  .type-picker { position: relative; isolation: isolate; display: grid; grid-template-columns: 1fr 1fr; gap: 6px; padding: 0; margin: 0 0 28px; border: 0; }
  .type-picker::before { content: ""; position: absolute; inset: 0 auto 0 0; z-index: -1; width: calc((100% - 6px) / 2); border-radius: var(--radius); background: var(--hover); pointer-events: none; transition: transform var(--form-motion); }
  .type-picker:has(input[value="project"]:checked)::before { transform: translateX(calc(100% + 6px)); }
  .type-option { display: flex; position: relative; align-items: center; justify-content: center; gap: 8px; cursor: pointer; padding: 12px; border-radius: var(--radius); min-width: 0; color: var(--muted); transition: background-color 140ms; }
  .type-option input { position: absolute; opacity: 0; width: 1px; height: 1px; }
  .type-option:hover { color: var(--text); background: var(--hover); }
  .type-option:has(input:checked) { color: var(--text); background: transparent; }
  .type-option:has(input:focus-visible) { outline: 2px solid var(--focus); outline-offset: 1px; }
  .type-option svg { width: var(--icon-control); height: var(--icon-control); }
  .type-option strong { font-size: var(--text-body); font-weight: var(--weight-regular); white-space: nowrap; }
  .conditional-fields { display: grid; grid-template-rows: 0fr; opacity: 0; pointer-events: none; transition: grid-template-rows var(--form-motion), opacity 180ms ease; }
  .conditional-fields.is-visible { grid-template-rows: 1fr; opacity: 1; pointer-events: auto; }
  .conditional-fields-inner { min-height: 0; overflow: hidden; padding-inline: 3px; margin-inline: -3px; }
  #create-dialog:not([open]) .conditional-fields, #create-dialog:not([open]) .type-picker::before { transition: none; }
  .field { display: flex; flex-direction: column; gap: 8px; font-size: var(--text-body); font-weight: var(--weight-regular); margin-bottom: 20px; }
  .field input, .field select, .admin-group-add input { width: 100%; min-height: 44px; border: 0; border-radius: var(--radius); padding: 11px 12px; color: var(--text); background: var(--panel); font-size: var(--text-body); transition: background-color 140ms; }
  .field input:hover, .field select:hover, .admin-group-add input:hover { background: var(--hover); }
  .field small { font-size: var(--text-caption); font-weight: var(--weight-regular); color: var(--muted); line-height: 1.6; }
  input::placeholder { color: var(--muted); opacity: 1; }
  .field input[aria-invalid="true"] { outline: 2px dashed var(--text); outline-offset: 1px; }
  .field .field-error { color: var(--text); font-weight: var(--weight-regular); }
  .field:has([aria-invalid="true"]) > small:not(.field-error) { display: none; }
  .creation-note { display: flex; align-items: flex-start; gap: 8px; color: var(--muted); font-size: var(--text-caption); line-height: 1.7; padding-top: 4px; }
  .creation-note svg { width: var(--icon-inline); height: var(--icon-inline); margin-top: 2px; }
  .form-error { color: var(--text); font-size: var(--text-body); font-weight: var(--weight-regular); line-height: 1.6; margin-top: 12px; }
  .form-error:empty { display: none; }
  .modal-footer { display: flex; gap: 8px; justify-content: flex-end; margin-top: 26px; }
  .button { min-height: 40px; padding: 9px 16px; display: inline-flex; gap: 8px; align-items: center; justify-content: center; font-size: var(--text-body); font-weight: var(--weight-regular); }
  .settings-body [data-release-more] { display: flex; margin: 16px auto 0; }
  .danger { font-weight: var(--weight-medium); }
  .small-modal { width: min(440px, calc(100% - 32px)); }
  .small-modal p { color: var(--muted); line-height: 1.8; font-size: var(--text-body); margin-top: 16px; }

  .settings-dialog { --muted: #595959; --separator: #00000020; width: min(880px, calc(100% - 32px)); max-height: calc(100dvh - 48px); overflow: hidden; }
  :root[data-theme="dark"] .settings-dialog { --overlay: #242424; --text: #fafafa; --muted: #c2c2c2; --separator: #ffffff22; --hover: #3a3a3a; }
  .settings-layout { display: grid; grid-template-columns: 208px minmax(0, 1fr); height: min(680px, calc(100dvh - 48px)); }
  .settings-sidebar { padding: 16px 12px; border-right: 1px solid var(--separator); }
  .settings-close { margin: 0 0 16px 4px; width: 40px; height: 40px; }
  .settings-tabs { display: flex; flex-direction: column; gap: 4px; }
  .settings-category { display: flex; align-items: center; gap: 10px; width: 100%; min-height: 44px; padding: 12px; text-align: left; font-size: var(--text-body); font-weight: var(--weight-regular); white-space: nowrap; }
  .settings-category[aria-selected="true"] { background: var(--hover); }
  .settings-content { min-width: 0; min-height: 0; overflow: hidden; }
  .settings-panel { display: flex; flex-direction: column; flex: 1; min-height: 0; }
  .settings-panel > h2 { flex-shrink: 0; margin: 0 24px; padding: 20px 0; border-bottom: 1px solid var(--separator); font-size: var(--text-title); font-weight: var(--weight-medium); }
  .settings-panel-header { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-shrink: 0; margin: 0 24px; padding: 14px 0; border-bottom: 1px solid var(--separator); }
  .settings-panel-header .button { flex-shrink: 0; }
  .settings-body { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 0 24px 24px; }
  #archived-agents, #about-content, #accounts-panel > .settings-body { padding-top: 16px; }
  .setting-row { display: flex; justify-content: space-between; align-items: center; gap: 16px; padding: 10px 0; font-size: var(--text-body); }
  .setting-select { display: flex; align-items: center; justify-content: space-between; gap: 18px; min-height: 44px; padding: 10px 12px; }
  .setting-select svg { width: var(--icon-inline); height: var(--icon-inline); }
  .select-menu { --hover: var(--menu-hover); position: fixed; margin: 0; width: 192px; max-width: calc(100vw - 24px); max-height: calc(100dvh - 24px); padding: 6px; border: 0; border-radius: var(--radius); background: var(--menu); color: var(--text); box-shadow: var(--shadow-menu); }
  .select-menu:popover-open { display: flex; flex-direction: column; gap: 4px; animation: menu-in 120ms ease-out; }
  .select-menu button { display: flex; align-items: center; justify-content: space-between; gap: 16px; min-height: 44px; width: 100%; padding: 10px 12px; text-align: left; }
  .select-menu button[aria-checked="true"] { background: var(--menu-selected); }
  .select-menu button:focus-visible { outline-offset: -2px; }
  .select-menu [aria-checked="false"] [data-icon] { visibility: hidden; }
  .select-menu svg { width: var(--icon-inline); height: var(--icon-inline); }
  .settings-message { margin-top: 12px; color: var(--muted); font-size: var(--text-body); }
  .settings-form { display: flex; flex-direction: column; flex: 1; min-height: 0; }
  .settings-form > .settings-body { padding-top: 20px; }
  .profile-note, .profile-fixed { color: var(--muted); font-size: var(--text-body); line-height: 1.65; }
  .profile-fixed { margin-bottom: 12px; }
  .profile-section { min-width: 0; margin: 24px 0 0; padding: 0; border: 0; }
  .profile-section legend, .profile-section h3 { margin-bottom: 10px; padding: 0; font-size: var(--text-section); font-weight: var(--weight-medium); }
  .profile-fields { display: grid; grid-template-columns: minmax(0, 1fr); }
  .profile-fields .full-field { grid-column: 1 / -1; }
  .profile-fields .field { min-width: 0; }
  .settings-form .field { display: grid; grid-template-columns: minmax(120px, 1fr) minmax(0, 1.25fr); align-items: center; column-gap: 20px; margin: 0; padding: 8px 0; border-top: 1px solid var(--separator); font-size: var(--text-body); font-weight: var(--weight-regular); }
  .settings-form input::placeholder { color: var(--muted); opacity: 1; }
  .settings-form .field input { min-width: 0; background: transparent; text-align: right; }
  #gateway-admin { justify-self: end; }
  #gateway-admin-error { margin: 8px 0 16px; color: var(--muted); }
  .settings-form .field input:hover, .settings-form .field input:focus { background: var(--hover); }
  .settings-form .field small { grid-column: 1 / -1; }
  .settings-form .profile-section > .profile-note { margin-top: 12px; }
  .console-section { margin-top: 0; padding: 20px 0; border-bottom: 1px solid var(--separator); }
  .console-setting-row { display: flex; align-items: center; justify-content: space-between; gap: 20px; flex-wrap: wrap; }
  .console-setting-copy { flex: 1 1 200px; min-width: 0; }
  .console-setting-copy h3 { margin-bottom: 6px; }
  .console-actions { flex: 0 0 auto; gap: 4px; }
  .console-actions .button { padding-inline: 12px; white-space: nowrap; }
  .console-help { max-width: 52ch; }
  .settings-save-status { flex-shrink: 0; padding: 12px 32px 0; color: var(--muted); font-size: var(--text-body); }

  .detail-drawer { position: fixed; margin: 12px 12px 12px auto; height: calc(100dvh - 24px); max-height: none; width: 400px; max-width: calc(100% - 24px); overflow: hidden; }
  .detail-drawer::backdrop { backdrop-filter: none; background: var(--detail-scrim); }
  .detail-drawer[open] { animation: drawer-in 180ms ease-out; }
  @keyframes drawer-in { from { opacity: 0; transform: translateX(12px); } to { opacity: 1; transform: translateX(0); } }
  #detail-content { height: 100%; display: grid; grid-template-rows: auto minmax(0, 1fr); }
  .drawer-top { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px 14px 24px; font-size: var(--text-body); font-weight: var(--weight-regular); }
  .drawer-tools { display: flex; gap: 2px; }
  .drawer-tools svg { width: var(--icon-inline); height: var(--icon-inline); }
  .drawer-body { overflow-y: auto; overscroll-behavior: contain; padding: 0 24px 32px; }
  .detail-identity { display: flex; align-items: center; gap: 16px; padding: 24px 0; }
  .detail-identity .agent-avatar { width: 52px; height: 52px; font-size: var(--text-title); background: var(--panel); }
  .detail-identity > div { min-width: 0; }
  .detail-identity h2 { overflow-wrap: anywhere; font-size: var(--text-title); line-height: 1.4; font-weight: var(--weight-medium); letter-spacing: normal; }
  .detail-identity p { color: var(--muted); font-size: var(--text-caption); margin-top: 4px; }
  .detail-section { padding: 24px 0; }
  .detail-section h3 { font-size: var(--text-section); font-weight: var(--weight-medium); margin-bottom: 16px; }
  .detail-status { border-radius: var(--radius); padding: 18px; background: var(--panel); }
  .detail-status p { margin-top: 8px; color: var(--muted); font-size: var(--text-body); overflow-wrap: anywhere; line-height: 1.7; }
  .detail-status .button { margin: 12px 0 -4px -10px; }
  .detail-facts > div { margin: 0; padding: 10px 0; align-items: baseline; gap: 24px; }
  .detail-facts dd { font-variant-numeric: tabular-nums; }
  .admin-group-row, .admin-group-add { display: flex; align-items: center; gap: 12px; padding: 12px 0; }
  .admin-group-row span { flex: 1; min-width: 0; overflow-wrap: anywhere; }
  .admin-group-add input { flex: 1; min-width: 0; }
  .admin-group-row .icon-button { flex-shrink: 0; }
  .detail-history summary { display: flex; align-items: center; justify-content: space-between; cursor: pointer; list-style: none; font-size: var(--text-section); padding: 10px 12px; margin: -10px -12px 0; border-radius: var(--radius); }
  .detail-history summary::-webkit-details-marker { display: none; }
  .detail-history summary svg { width: 16px; height: 16px; }
  .detail-history[open] summary svg { transform: rotate(180deg); }
  .detail-history ol { list-style: none; margin: 16px 0 0; padding: 0; max-height: 320px; overflow-y: auto; }
  .detail-history li { padding: 12px 0; border-bottom: 1px solid var(--separator); }
  .detail-history li > div { display: flex; justify-content: space-between; gap: 16px; }
  .detail-history li > div + div { margin-top: 6px; color: var(--muted); font-size: var(--text-caption); overflow-wrap: anywhere; }
  .detail-project { padding-top: 4px; }
  .detail-repository { display: flex; align-items: center; gap: 12px; margin: -8px -10px; padding: 10px; border-radius: var(--radius); text-decoration: none; overflow-wrap: anywhere; }
  .detail-repository:hover { background: var(--hover); }
  .detail-repository svg { flex-shrink: 0; width: var(--icon-control); height: var(--icon-control); color: var(--muted); }
  .detail-repository small { display: block; color: var(--muted); margin-top: 4px; font-size: var(--text-caption); }
  .section-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
  .section-heading h3 { margin: 0; }
  .activity-text { font-size: var(--text-body); overflow-wrap: anywhere; }
  dl { margin: 0; }
  dl > div { display: flex; justify-content: space-between; gap: 20px; margin-top: 14px; font-size: var(--text-body); }
  dt { color: var(--muted); flex-shrink: 0; }
  dd { margin: 0; text-align: right; overflow-wrap: anywhere; min-width: 0; }
  .repository-row { flex-direction: column; gap: 6px; }
  .repository-row dd { text-align: left; line-height: 1.6; }
  .demo-controls { padding: 10px 0 24px; color: var(--muted); font-size: var(--text-caption); }
  .demo-controls summary { cursor: pointer; padding: 10px; margin: 0 -10px; border-radius: var(--radius); }
  .demo-controls p { margin: 14px 0; line-height: 1.7; }
  .demo-controls .field { margin-bottom: 0; }
  .drawer-footer { padding: 18px 24px 24px; background: var(--panel); }
  .drawer-footer > p { font-size: var(--text-caption); color: var(--muted); margin-bottom: 14px; }
  .drawer-footer > div { display: flex; gap: 10px; }
  .drawer-footer .button { flex: 1; }
  .navigation-dialog { margin: 8px auto 8px 8px; width: min(280px, calc(100% - 32px)); max-width: none; height: calc(100dvh - 16px); max-height: none; padding: 0; overflow: visible; background: var(--sidebar-bg); }
  .navigation-dialog .sidebar { position: static; width: 100%; height: 100%; border-radius: var(--surface-radius); }
  .toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); z-index: 8; width: max-content; max-width: calc(100% - 40px); padding: 12px 18px; border-radius: var(--radius); background: var(--text); color: var(--canvas); box-shadow: var(--shadow-menu); font-size: var(--text-body); }
}

@layer responsive {
  @media (min-width: 761px) {
    .sidebar-animated .sidebar { transition: width var(--sidebar-motion); }
    .sidebar-animated main { transition: margin-left var(--sidebar-motion); }
    .sidebar-animated :is(.brand, .nav-label, .account-label) { transition: opacity 140ms, transform var(--sidebar-motion), visibility 0s; }
    .sidebar-collapsed { --sidebar: 64px; }
    .sidebar-collapsed .sidebar { cursor: e-resize; }
    .sidebar-collapsed :is(.brand, .nav-label, .account-label) { opacity: 0; visibility: hidden; transform: translateX(-6px); }
    .sidebar-animated.sidebar-collapsed :is(.brand, .nav-label, .account-label) { transition: opacity 90ms, transform var(--sidebar-motion), visibility 0s 90ms; }
  }
  @media (max-width: 760px) {
    #mobile-nav-toggle { display: inline-flex; position: absolute; top: 12px; left: 12px; z-index: 2; width: 44px; height: 44px; }
    body > .sidebar { display: none; }
    main { margin-left: 0; padding: 68px 20px 24px; }
    .sidebar { padding-top: 12px; }
    .sidebar-footer { padding-bottom: env(safe-area-inset-bottom); }
    .modal { --dialog-padding: 24px; }
    .field input, .field select { font-size: var(--text-section); }
    .icon-button { width: 44px; height: 44px; }
    .account-menu button, .button { min-height: 44px; }
    .drawer-footer { padding-bottom: max(20px, env(safe-area-inset-bottom)); }
  }
  @media (max-width: 480px) {
    main { padding-left: 16px; padding-right: 16px; }
    .detail-drawer { margin: 8px; width: calc(100% - 16px); max-width: none; height: calc(100dvh - 16px); }
    .modal { --dialog-padding: 20px; }
  }
  @media (max-width: 600px) {
    .settings-layout { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); height: min(640px, calc(100dvh - 48px)); }
    .settings-sidebar { display: flex; align-items: center; gap: 8px; padding: 12px; border-right: 0; border-bottom: 1px solid var(--separator); }
    .settings-close { margin: 0; }
    .settings-tabs { flex: 1; flex-direction: row; min-width: 0; overflow-x: auto; }
    .settings-category { width: auto; justify-content: center; padding: 10px; font-size: var(--text-body); }
    .settings-category [data-icon] { display: none; }
    .settings-panel > h2 { margin-inline: 20px; padding: 20px 0; }
    .settings-panel-header { margin-inline: 20px; }
    .settings-body { padding-inline: 20px; }
    .settings-save-status { padding-inline: 20px; }
    .settings-form .field { grid-template-columns: minmax(0, 1fr); gap: 6px; }
    .settings-form .field input { text-align: left; background: var(--panel); }
    .console-setting-row { align-items: flex-start; gap: 12px; }
    .console-setting-copy { flex-basis: 100%; }
    .console-actions { margin-left: -12px; }
  }
  @media (max-width: 360px) {
    .type-picker { grid-template-columns: minmax(0, 1fr); }
    .type-picker::before { width: 100%; height: calc((100% - 6px) / 2); }
    .type-picker:has(input[value="project"]:checked)::before { transform: translateY(calc(100% + 6px)); }
    .profile-fields { grid-template-columns: minmax(0, 1fr); }
  }
  @media (max-width: 1000px) {
    .sessions-page { grid-template-columns: 230px minmax(0, 1fr); gap: 12px; }
    .conversation-scroll { padding-inline: 8px; }
  }
  @media (max-width: 760px) {
    .sessions-page { display: block; height: calc(100dvh - 96px); }
    .conversation-list, .conversation-thread { height: 100%; }
    .sessions-page:not(.has-conversation) .conversation-thread, .sessions-page.has-conversation .conversation-list { display: none; }
    .conversation-toolbar [data-session-back] { display: inline-flex; }
  }
  @media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { transition: none !important; animation: none !important; }
  }
}
