    :root {
      --bg: #212121;
      --bg-accent: rgba(255,255,255,0.03);
      --bg-accent-2: rgba(255,255,255,0.02);
      --surface: #2f2f2f;
      --surface-strong: #2f2f2f;
      --surface-2: #373737;
      --surface-3: #424242;
      --border: rgba(255,255,255,0.08);
      --border-strong: rgba(255,255,255,0.15);
      --text: #ececec;
      --text-muted: #9a9a9a;
      --accent: #ececec;
      --accent-strong: #ffffff;
      --accent-green: #34d399;
      --accent-amber: #e5a210;
      --danger: #f87171;
      --backdrop: rgba(0,0,0,0.5);
      --overlay: rgba(0,0,0,0.6);
      --error-text: #fecaca;
      --btn-accent-text: #212121;
      --stop-btn-text: #fecaca;
      --spinner-ring: rgba(33,33,33,0.35);
      --shadow-soft: 0 1px 2px rgba(0,0,0,0.1);
      --shadow-strong: 0 2px 8px rgba(0,0,0,0.15);
      --gradient-accent: var(--surface-2);
      --gradient-accent-strong: var(--accent-strong);
      --link: #60a5fa;
      --safe-top: env(safe-area-inset-top, 0px);
      --safe-right: env(safe-area-inset-right, 0px);
      --safe-bottom: env(safe-area-inset-bottom, 0px);
      --safe-left: env(safe-area-inset-left, 0px);
      --app-height: 100dvh;
      --app-offset-top: 0px;
      --sidebar-width: 280px;
      --sidebar-rail-width: 56px;
    }

    @media (prefers-color-scheme: light) {
      :root {
        --bg: #ffffff;
        --bg-accent: rgba(0,0,0,0.02);
        --bg-accent-2: rgba(0,0,0,0.01);
        --surface: #ffffff;
        --surface-strong: #ffffff;
        --surface-2: #f7f7f8;
        --surface-3: #ececec;
        --border: rgba(0,0,0,0.08);
        --border-strong: rgba(0,0,0,0.15);
        --text: #0d0d0d;
        --text-muted: #6e6e6e;
        --accent: #0d0d0d;
        --accent-strong: #0d0d0d;
        --accent-green: #059669;
        --accent-amber: #b45309;
        --danger: #dc2626;
        --backdrop: rgba(0,0,0,0.3);
        --overlay: rgba(0,0,0,0.4);
        --error-text: #991b1b;
        --btn-accent-text: #ffffff;
        --stop-btn-text: #991b1b;
        --spinner-ring: rgba(255,255,255,0.45);
        --shadow-soft: 0 1px 2px rgba(0,0,0,0.05);
        --shadow-strong: 0 2px 8px rgba(0,0,0,0.08);
        --gradient-accent: var(--surface-2);
        --gradient-accent-strong: var(--accent-strong);
        --link: #2563eb;
      }
    }

    * {
      box-sizing: border-box;
      scrollbar-width: thin;
      scrollbar-color: var(--surface-2) transparent;
    }

    ::-webkit-scrollbar {
      width: 6px;
      height: 6px;
    }

    ::-webkit-scrollbar-track {
      background: transparent;
    }

    ::-webkit-scrollbar-thumb {
      background: var(--surface-2);
      border-radius: 3px;
    }

    ::-webkit-scrollbar-thumb:hover {
      background: var(--border);
    }

    html,
    body {
      margin: 0;
      padding: 0;
      width: 100%;
      min-height: 100%;
      height: 100%;
      background: var(--bg);
      color: var(--text);
      font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    }

    body {
      overflow: hidden;
      letter-spacing: 0.01em;
      overscroll-behavior: none;
      -webkit-text-size-adjust: 100%;
      -webkit-tap-highlight-color: transparent;
    }

    body::before {
      content: none;
    }

    .startup-splash {
      position: fixed;
      inset: 0;
      z-index: 120;
      display: flex;
      align-items: center;
      justify-content: center;
      padding: calc(1.5rem + var(--safe-top)) calc(1.5rem + var(--safe-right)) calc(1.5rem + var(--safe-bottom)) calc(1.5rem + var(--safe-left));
      background:
        radial-gradient(circle at top, var(--bg-accent), transparent 55%),
        var(--bg);
      transition: opacity 180ms ease, visibility 180ms ease;
    }

    .startup-splash.hidden {
      opacity: 0;
      visibility: hidden;
      pointer-events: none;
    }

    .startup-card {
      width: min(320px, 100%);
      padding: 1.5rem 1.35rem;
      border: 1px solid var(--border);
      border-radius: 16px;
      background: var(--surface);
      box-shadow: var(--shadow-strong);
      text-align: center;
      backdrop-filter: blur(12px);
      -webkit-backdrop-filter: blur(12px);
    }

    .startup-mark {
      width: 52px;
      height: 52px;
      margin: 0 auto 0.9rem;
      border-radius: 14px;
      display: grid;
      place-items: center;
      background: var(--surface-2);
      border: 1px solid var(--border);
      font-size: 1.45rem;
      font-weight: 800;
    }

    .startup-title {
      font-size: 1.05rem;
      font-weight: 800;
      letter-spacing: 0.01em;
    }

    .startup-subtitle {
      margin-top: 0.4rem;
      color: var(--text-muted);
      font-size: 0.92rem;
      line-height: 1.45;
    }

    .startup-spinner {
      width: 22px;
      height: 22px;
      margin: 1rem auto 0;
      border-radius: 50%;
      border: 2px solid var(--border);
      border-top-color: var(--accent-strong);
      animation: spin 0.8s linear infinite;
    }

    button,
    input,
    textarea,
    select {
      font: inherit;
      color: inherit;
    }

    .app {
      display: grid;
      grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
      min-height: var(--app-height);
      height: var(--app-height);
      width: 100%;
      background: transparent;
      position: fixed;
      top: var(--app-offset-top);
      left: 0;
      right: 0;
      z-index: 1;
      overflow: hidden;
      transition: grid-template-columns 0.2s ease;
    }

    .app.sidebar-collapsed {
      grid-template-columns: var(--sidebar-rail-width) minmax(0, 1fr);
    }

    .sidebar {
      border-right: 1px solid var(--border);
      background: var(--surface);
      display: flex;
      flex-direction: column;
      min-height: 0;
      z-index: 20;
      padding-left: var(--safe-left);
      position: relative;
      overflow: hidden;
    }

    .sidebar-rail {
      background: transparent;
      display: flex;
      flex-direction: column;
      align-items: center;
      gap: 0.55rem;
      padding: calc(0.85rem + var(--safe-top)) 0.55rem 0.85rem;
      position: absolute;
      top: 0;
      left: 0;
      bottom: 0;
      width: var(--sidebar-rail-width);
      z-index: 1;
      opacity: 0;
      pointer-events: none;
      transition: opacity 0.15s ease;
    }

    .sidebar-rail-btn {
      width: 36px;
      height: 36px;
    }

    .sidebar-panel {
      min-width: 0;
      min-height: 0;
      display: flex;
      flex-direction: column;
      flex: 1;
      transition: opacity 0.15s ease;
    }

    .app.sidebar-collapsed .sidebar-rail {
      opacity: 1;
      pointer-events: auto;
    }

    .app.sidebar-collapsed .sidebar-panel {
      opacity: 0;
      pointer-events: none;
    }

    .sidebar-header {
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 0.5rem;
      padding: calc(0.85rem + var(--safe-top)) 0.8rem 0.85rem;
      min-height: 58px;
    }

    .sidebar-header-actions {
      display: inline-flex;
      gap: 0.4rem;
    }

    .brand {
      display: inline-flex;
      align-items: center;
      gap: 0.55rem;
      font-size: 0.95rem;
      font-weight: 700;
      letter-spacing: 0.01em;
      min-width: 0;
    }

    .icon-btn {
      border: 1px solid var(--border);
      background: var(--surface-2);
      color: var(--text-muted);
      border-radius: 8px;
      width: 34px;
      height: 34px;
      display: inline-flex;
      align-items: center;
      justify-content: center;
      cursor: pointer;
      transition: background 0.15s ease, color 0.15s ease;
      flex-shrink: 0;
    }

    .icon-btn:hover {
      background: var(--surface-3);
      color: var(--text);
    }

    .icon-btn:focus-visible {
      outline: 2px solid var(--accent);
      outline-offset: 2px;
    }

    .sidebar-close {
      display: none;
    }

    .sidebar-content {
      min-height: 0;
      flex: 1;
      display: flex;
      flex-direction: column;
      overflow-y: auto;
      overflow-anchor: none;
      padding: 0.45rem 0 0.75rem;
    }

    .sidebar-actions {
      display: flex;
      flex-direction: column;
      gap: 0.25rem;
      padding: 0 0.55rem 0.35rem;
      flex-shrink: 0;
    }

    .new-chat-btn,
    .widgets-sidebar-btn {
      width: 100%;
      border-radius: 10px;
      border: 1px solid transparent;
      background: transparent;
      color: var(--text);
      padding: 0.58rem 0.65rem;
      text-align: left;
      cursor: pointer;
      font: inherit;
      font-size: 0.92rem;
      font-weight: 600;
      line-height: 1.25;
      transition: background 0.15s ease, border-color 0.15s ease;
      display: flex;
      align-items: center;
      gap: 0.55rem;
    }

    .sidebar-action-icon {
      flex: 0 0 17px;
      width: 17px;
      height: 17px;
      color: currentColor;
    }

    .new-chat-btn:hover,
    .widgets-sidebar-btn:hover {
      background: var(--surface-2);
      border-color: var(--border);
    }

    .widgets-sidebar-btn.hidden {
      display: none;
    }

    .sidebar-search-wrap {
      padding: 0 0.55rem 0.45rem;
      flex-shrink: 0;
    }

    .sidebar-search-input {
      width: 100%;
      border: 1px solid transparent;
      background: var(--surface-2);
      color: var(--text);
      border-radius: 10px;
      padding: 0.58rem 0.65rem;
      font: inherit;
      font-size: 0.9rem;
    }

    .sidebar-search-input:focus {
      outline: 2px solid var(--border-strong);
      border-color: var(--border-strong);
    }

    .widgets-modal {
      width: min(620px, 100%);
      max-height: min(720px, calc(100vh - 2rem));
      display: flex;
      flex-direction: column;
    }

    .modal-title-row {
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 0.75rem;
      margin-bottom: 0.35rem;
    }

    .modal-title-row h2 {
      margin: 0;
    }

    .widgets-modal-list {
      display: flex;
      flex-direction: column;
      gap: 0.2rem;
      margin-top: 0.85rem;
      overflow-y: auto;
      padding-right: 0.15rem;
    }

    .widgets-modal-empty {
      color: var(--text-muted);
      font-size: 0.9rem;
      padding: 0.75rem 0.25rem;
    }

    .widget-link {
      min-width: 0;
      border-radius: 8px;
      color: inherit;
      display: flex;
      flex-direction: column;
      gap: 0.12rem;
      padding: 0.48rem 0.55rem;
      text-decoration: none;
    }

    .widget-link:hover {
      background: var(--surface-3);
    }

    .widget-title-row {
      min-width: 0;
      display: flex;
      align-items: center;
      gap: 0.35rem;
    }

    .widget-title {
      min-width: 0;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
      font-size: 0.84rem;
      font-weight: 700;
    }

    .widget-state {
      flex-shrink: 0;
      border-radius: 999px;
      color: var(--text-muted);
      font-size: 0.65rem;
      font-weight: 800;
      letter-spacing: 0.03em;
      line-height: 1;
      padding: 0.18rem 0.34rem;
      text-transform: uppercase;
    }

    .widget-state.running,
    .widget-state.starting,
    .widget-state.started {
      width: 0.48rem;
      height: 0.48rem;
      padding: 0;
      background: #22c55e;
      box-shadow: 0 0 0 0.18rem rgba(34, 197, 94, 0.12);
    }

    .widget-state.error {
      color: #f87171;
      background: rgba(248, 113, 113, 0.12);
    }

    .widget-meta {
      color: var(--text-muted);
      font-size: 0.72rem;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
    }

    .session-groups {
      overflow: visible;
      min-height: 0;
      padding: 0.25rem 0;
    }

    .session-group {
      margin-bottom: 0.25rem;
    }

    .session-group h3 {
      margin: 0;
      padding: 0.5rem 0.75rem 0.35rem;
      font-size: 0.72rem;
      font-weight: 700;
      color: var(--text-muted);
      letter-spacing: 0.08em;
      text-transform: uppercase;
    }

    .session-btn {
      width: calc(100% - 0.5rem);
      margin: 0 0.25rem;
      border: 1px solid transparent;
      background: transparent;
      color: inherit;
      text-align: left;
      padding: 0.65rem 0.8rem;
      cursor: pointer;
      border-radius: 8px;
      display: flex;
      flex-direction: column;
      gap: 0.18rem;
      transition: background 0.15s ease;
    }

    .session-row {
      position: relative;
      display: flex;
      align-items: stretch;
      margin: 0 0.25rem;
      overflow: visible;
      transform-origin: top center;
      transition: height 0.22s cubic-bezier(0.22, 1, 0.36, 1), opacity 0.18s ease, transform 0.22s cubic-bezier(0.22, 1, 0.36, 1);
    }

    .session-row.is-hiding {
      overflow: hidden;
      opacity: 0;
      transform: translateX(8px) scale(0.985);
    }

    .session-row .session-btn {
      width: 100%;
      margin: 0;
      padding-right: 2.85rem;
    }

    .session-btn:hover {
      background: var(--surface-2);
    }

    .session-btn.active {
      background: var(--surface-2);
    }

    .session-title {
      font-size: 0.9rem;
      line-height: 1.3;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
    }

    .session-meta {
      font-size: 0.77rem;
      color: var(--text-muted);
      white-space: nowrap;
    }

    .session-row.is-active .session-title::before {
      content: '';
      display: inline-block;
      width: 7px;
      height: 7px;
      border-radius: 50%;
      background: #22c55e;
      margin-right: 0.4em;
      flex-shrink: 0;
      animation: pulse-dot 1.8s ease-in-out infinite;
      vertical-align: middle;
    }

    @keyframes pulse-dot {
      0%, 100% { opacity: 1; }
      50% { opacity: 0.35; }
    }

    .session-row-menu {
      position: absolute;
      top: 0.4rem;
      right: 0.45rem;
    }

    .session-menu-trigger {
      width: 28px;
      height: 28px;
      border-radius: 7px;
      border: 1px solid transparent;
      background: transparent;
      color: var(--text-muted);
      cursor: pointer;
      opacity: 0;
      transition: background 0.15s ease, color 0.15s ease, opacity 0.15s ease;
    }

    .session-row:hover .session-menu-trigger,
    .session-row.menu-open .session-menu-trigger,
    .session-row:focus-within .session-menu-trigger {
      opacity: 1;
    }

    @media (hover: none) and (pointer: coarse) {
      .session-menu-trigger {
        opacity: 1;
      }
    }

    .session-menu-trigger:hover,
    .session-row.menu-open .session-menu-trigger {
      background: var(--surface-3);
      color: var(--text);
      border-color: var(--border);
    }

    .session-menu {
      position: absolute;
      top: calc(100% + 0.35rem);
      right: 0;
      min-width: 132px;
      display: none;
      flex-direction: column;
      gap: 0.2rem;
      padding: 0.3rem;
      border-radius: 10px;
      border: 1px solid var(--border);
      background: var(--surface);
      box-shadow: var(--shadow-strong);
      z-index: 5;
    }

    .session-row.menu-open .session-menu {
      display: flex;
    }

    .session-menu button {
      width: 100%;
      border: 0;
      border-radius: 7px;
      background: transparent;
      color: var(--text);
      text-align: left;
      padding: 0.48rem 0.65rem;
      cursor: pointer;
      display: flex;
      align-items: center;
      gap: 0.55rem;
      font-size: 0.84rem;
      line-height: 1.2;
    }

    .session-menu button:hover {
      background: var(--surface-2);
    }

    .session-menu-icon {
      width: 0.95rem;
      height: 0.95rem;
      display: inline-flex;
      align-items: center;
      justify-content: center;
      color: var(--text-muted);
      flex-shrink: 0;
    }

    .session-menu-icon svg {
      width: 100%;
      height: 100%;
      display: block;
    }

    .session-menu button:hover .session-menu-icon {
      color: var(--text);
    }

    .session-menu-label {
      min-width: 0;
    }

    .main {
      min-width: 0;
      min-height: 0;
      display: flex;
      flex-direction: column;
      background: transparent;
      position: relative;
      overflow: hidden;
    }

    .main-header {
      min-height: 64px;
      border-bottom: 1px solid var(--border);
      background: var(--surface);
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 0.75rem;
      padding: calc(0.85rem + var(--safe-top)) calc(1.15rem + var(--safe-right)) 0.85rem calc(1.15rem + var(--safe-left));
      flex-wrap: wrap;
      position: relative;
      z-index: 1;
    }

    .header-left {
      display: inline-flex;
      align-items: center;
      gap: 0.6rem;
      flex: 1;
      min-width: 0;
    }

    .mobile-menu {
      display: none;
    }

    .header-title {
      margin: 0;
      font-size: 1rem;
      line-height: 1.2;
      font-weight: 650;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
      min-width: 0;
    }

    .connection-state {
      color: var(--danger);
      font-size: 0.78rem;
      font-weight: 650;
      white-space: nowrap;
    }

    .connection-state[hidden] {
      display: none;
    }

    .connection-state.bad {
      color: var(--danger);
    }

    .header-right {
      margin-left: auto;
      display: flex;
      align-items: center;
      gap: 0.5rem;
    }

    .header-stats {
      display: inline-flex;
      align-items: center;
      gap: 0;
      font-size: 0.8rem;
      color: var(--text-muted);
      white-space: nowrap;
    }

    .model-picker {
      display: inline-flex;
      align-items: center;
      gap: 0;
      min-width: 0;
    }

    .model-chip {
      position: relative;
      display: inline-flex;
      align-items: center;
      max-width: 100%;
      min-width: 0;
    }

    .model-chip[hidden] {
      display: none;
    }

    .chip-trigger {
      display: inline-flex;
      align-items: center;
      gap: 0.25rem;
      padding: 0.2rem 0.5rem;
      border-radius: 7px;
      border: 0;
      background: transparent;
      color: var(--text-muted);
      font: inherit;
      font-weight: 500;
      cursor: pointer;
      max-width: 100%;
      min-width: 0;
      transition: background 0.12s ease, color 0.12s ease;
    }

    .chip-trigger:hover,
    .chip-trigger:focus-visible,
    .chip-trigger[aria-expanded="true"] {
      background: var(--surface-3);
      color: var(--text);
      outline: none;
    }

    .chip-trigger[disabled] {
      cursor: default;
      background: transparent !important;
      color: var(--text-muted);
    }

    .chip-trigger[disabled] .chip-label {
      color: inherit;
    }

    .model-picker.locked .model-chip-primary .chip-label,
    .model-picker.locked .model-chip[data-chip="provider"] .chip-label {
      color: var(--text);
    }

    .model-chip-primary .chip-label {
      color: var(--text);
      font-weight: 600;
    }

    .model-chip[data-chip="provider"] .chip-label {
      color: var(--text);
      font-weight: 500;
    }

    .model-chip[data-chip="effort"] .chip-label {
      font-variant: small-caps;
      letter-spacing: 0.05em;
    }

    .chip-label {
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
      min-width: 0;
    }

    .chip-label.stats-muted {
      color: var(--text-muted);
      font-weight: 500;
    }

    .chip-select-hidden {
      position: absolute;
      width: 1px;
      height: 1px;
      padding: 0;
      margin: -1px;
      overflow: hidden;
      clip: rect(0, 0, 0, 0);
      white-space: nowrap;
      border: 0;
      pointer-events: none;
    }

    .chip-popover-backdrop {
      position: fixed;
      inset: 0;
      z-index: 999;
      background: transparent;
    }

    .chip-popover-backdrop[hidden] {
      display: none;
    }

    .chip-popover {
      position: fixed;
      z-index: 1000;
      min-width: 180px;
      max-width: min(360px, calc(100vw - 1rem));
      max-height: min(320px, calc(100vh - 8rem));
      background: var(--surface-2);
      border: 1px solid var(--border);
      border-radius: 10px;
      box-shadow: 0 12px 32px rgba(0, 0, 0, 0.45), 0 2px 6px rgba(0, 0, 0, 0.3);
      padding: 0.25rem;
      overflow-y: auto;
      overscroll-behavior: contain;
      font-size: 0.85rem;
      animation: chip-popover-in 0.12s ease-out;
    }

    .chip-popover[hidden] {
      display: none;
    }

    @keyframes chip-popover-in {
      from { opacity: 0; transform: translateY(-2px); }
      to { opacity: 1; transform: translateY(0); }
    }

    .chip-popover-filter {
      width: 100%;
      box-sizing: border-box;
      padding: 0.4rem 0.55rem;
      margin-bottom: 0.35rem;
      border: 1px solid var(--surface-border, var(--surface-3));
      border-radius: 6px;
      background: var(--surface-1, transparent);
      color: var(--text);
      font: inherit;
      font-size: 0.85rem;
      outline: none;
    }

    .chip-popover-filter:focus {
      border-color: var(--accent, var(--surface-3));
    }

    .chip-popover-item[hidden] {
      display: none;
    }

    .chip-popover-item {
      display: flex;
      align-items: center;
      gap: 0.5rem;
      padding: 0.45rem 0.6rem;
      border-radius: 6px;
      cursor: pointer;
      color: var(--text);
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
      user-select: none;
    }

    .chip-popover-item:hover,
    .chip-popover-item.focused,
    .chip-popover-item:focus {
      background: var(--surface-3);
      outline: none;
    }

    .chip-popover-item[aria-selected="true"]::before {
      content: "✓";
      color: var(--accent, var(--text));
      flex: none;
      width: 1em;
      text-align: center;
    }

    .chip-popover-item:not([aria-selected="true"])::before {
      content: "";
      flex: none;
      width: 1em;
    }

    .chip-popover-item-label {
      overflow: hidden;
      text-overflow: ellipsis;
      min-width: 0;
      flex: 1;
    }

    .chip-popover-item-meta {
      color: var(--text-muted);
      font-size: 0.78rem;
      flex: none;
    }

    @media (max-width: 540px) {
      .chip-popover-backdrop {
        background: rgba(0, 0, 0, 0.4);
      }
      .chip-popover {
        position: fixed;
        left: 0.5rem;
        right: 0.5rem;
        bottom: max(0.5rem, env(safe-area-inset-bottom, 0.5rem));
        top: auto;
        max-width: none;
        max-height: 60vh;
        font-size: 0.95rem;
      }
      .chip-popover-item {
        padding: 0.7rem 0.75rem;
      }
    }

    .chip-sep {
      margin: 0 0.1rem;
      opacity: 0.4;
      flex: none;
    }

    .header-tokens {
      display: inline-flex;
      align-items: center;
      gap: 0;
      font-variant-numeric: tabular-nums;
    }

    .header-tokens-sep[hidden] {
      display: none;
    }

    .stats-tokens {
      font-variant-numeric: tabular-nums;
    }

    .stats-cached {
      color: var(--text-muted);
    }

    .stats-sep {
      margin: 0 0.45rem;
      opacity: 0.4;
    }

    .stats-muted {
      color: var(--text-muted);
      font-weight: 500;
    }

    .settings-field {
      margin-bottom: 0.75rem;
    }

    .settings-label {
      display: block;
      font-size: 0.8rem;
      font-weight: 600;
      color: var(--text-muted);
      margin-bottom: 0.3rem;
    }

    .settings-select {
      width: 100%;
      border: 1px solid var(--border);
      background: var(--surface-2);
      color: var(--text);
      border-radius: 8px;
      padding: 0.6rem 0.75rem;
      font: inherit;
    }

    .settings-row {
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 0.75rem;
    }

    .settings-help {
      color: var(--text-muted);
      font-size: 0.8rem;
      line-height: 1.45;
    }

    .settings-toggle {
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 1rem;
      cursor: pointer;
    }

    .settings-label-inline {
      margin-bottom: 0.1rem;
    }

    .settings-select:focus {
      outline: 2px solid var(--border-strong);
      border-color: var(--border-strong);
    }

    .chat-scroll {
      min-height: 0;
      flex: 1;
      overflow-y: auto;
      padding: 1.25rem calc(1.1rem + var(--safe-right)) 1rem calc(1.1rem + var(--safe-left));
      position: relative;
      z-index: 1;
    }

    .messages {
      max-width: 900px;
      margin: 0 auto;
      display: flex;
      flex-direction: column;
      gap: 0.85rem;
    }

    .empty-state {
      margin: 2.5rem auto;
      text-align: center;
      color: var(--text-muted);
      padding: 1.3rem 1.4rem;
      max-width: 520px;
    }

    .message {
      width: min(100%, 820px);
      display: flex;
      flex-direction: column;
      gap: 0.45rem;
    }

    .message.user {
      align-self: flex-end;
      width: min(78%, 820px);
    }

    .message.assistant,
    .message.tool,
    .message.model-swap,
    .message.compaction,
    .message.compaction-boundary,
    .message.error {
      align-self: flex-start;
    }

    .message-body {
      border: 1px solid var(--border);
      border-radius: 12px;
      padding: 0.85rem 1rem;
      line-height: 1.6;
      font-size: 0.96rem;
      overflow-x: auto;
      white-space: pre-wrap;
      word-wrap: break-word;
      background: var(--surface);
      unicode-bidi: plaintext;
    }

    .message-body.rtl,
    .markdown-body.rtl {
      text-align: right;
    }

    .message.user .message-body {
      background: var(--surface-2);
      border-color: var(--border-strong);
      color: var(--text);
      white-space: pre-wrap;
    }

    .message.assistant .message-body {
      background: var(--surface);
    }

    .message.error .message-body {
      background: rgba(248,113,113,0.08);
      border-color: rgba(248,113,113,0.25);
      color: var(--error-text);
    }

    .message.model-swap .message-body {
      background: rgba(125,211,252,0.08);
      border-color: rgba(125,211,252,0.22);
      color: var(--muted);
      font-size: 0.9rem;
    }

    .message.compaction,
    .message.compaction-boundary {
      width: min(100%, 820px);
    }

    .message.compaction .message-body,
    .message.compaction-boundary .message-body {
      background: rgba(229,162,16,0.08);
      border-color: rgba(229,162,16,0.22);
      color: var(--text-muted);
      font-size: 0.9rem;
      white-space: normal;
    }

    .message.compaction .message-body.active-boundary,
    .message.compaction-boundary .message-body.active-boundary {
      border-color: rgba(229,162,16,0.45);
    }

    .compaction-summary-row {
      display: flex;
      align-items: center;
      gap: 0.5rem;
      flex-wrap: wrap;
    }

    .compaction-label {
      color: var(--accent-amber);
      font-weight: 600;
    }

    .compaction-detail {
      color: var(--text-muted);
    }

    .compaction-toggle {
      border: 1px solid var(--border-strong);
      border-radius: 999px;
      background: transparent;
      color: var(--text);
      padding: 0.15rem 0.55rem;
      font: inherit;
      font-size: 0.82rem;
      cursor: pointer;
    }

    .compaction-toggle:hover {
      border-color: var(--accent-amber);
      color: var(--accent-strong);
    }

    .compaction-raw {
      margin: 0.7rem 0 0;
      max-height: 24rem;
      overflow: auto;
      border: 1px solid var(--border);
      border-radius: 8px;
      padding: 0.75rem;
      background: var(--surface);
      color: var(--text);
      white-space: pre-wrap;
      font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
      font-size: 0.82rem;
      line-height: 1.45;
    }

    .markdown-body {
      white-space: normal;
    }

    .markdown-stream-stable:empty,
    .markdown-stream-tail:empty {
      display: none;
    }

    .markdown-stream-tail.streaming-plain-text {
      white-space: pre-wrap;
    }

    .markdown-stream-piece > :first-child {
      margin-top: 0;
    }

    .markdown-stream-piece > :last-child {
      margin-bottom: 0;
    }

    .markdown-body h1,
    .markdown-body h2,
    .markdown-body h3,
    .markdown-body h4,
    .markdown-body h5,
    .markdown-body h6 {
      margin: 0.4em 0 0.3em;
      line-height: 1.25;
    }

    .markdown-body p {
      margin: 0.45em 0;
    }

    .markdown-body ul,
    .markdown-body ol {
      margin: 0.45em 0 0.55em;
      padding-left: 1.3rem;
    }

    .markdown-body blockquote {
      margin: 0.7em 0;
      padding: 0.15em 0.8em;
      border-left: 3px solid var(--border-strong);
      color: var(--text-muted);
      background: var(--surface-2);
      border-radius: 4px;
    }

    .markdown-body pre {
      margin: 0.6em 0;
      padding: 0;
      border-radius: 8px;
      overflow: auto;
      border: 1px solid var(--border);
    }

    .markdown-body pre code {
      display: block;
      padding: 0.85rem;
      line-height: 1.45;
      font-size: 0.87rem;
    }

    .code-copy-btn {
      position: absolute;
      top: 6px;
      right: 6px;
      width: 28px;
      height: 28px;
      border: 1px solid var(--border);
      border-radius: 6px;
      background: var(--surface);
      color: var(--text-muted);
      display: inline-flex;
      align-items: center;
      justify-content: center;
      cursor: pointer;
      opacity: 0;
      transition: opacity 0.15s ease, background 0.15s ease, color 0.15s ease;
      padding: 0;
      z-index: 1;
    }

    .markdown-body pre:hover .code-copy-btn {
      opacity: 1;
    }

    .code-copy-btn:hover {
      background: var(--surface-2);
      color: var(--text);
    }

    .code-copy-btn.copied {
      color: var(--accent-green);
      opacity: 1;
    }

    .turn-action-panel {
      display: inline-flex;
      align-items: center;
      gap: 0.25rem;
      align-self: flex-start;
      padding: 0 0.2rem;
      margin-top: -0.1rem;
    }

    .turn-action-btn {
      width: 30px;
      height: 30px;
      border: 1px solid transparent;
      border-radius: 8px;
      background: transparent;
      color: var(--text-muted);
      display: inline-flex;
      align-items: center;
      justify-content: center;
      cursor: pointer;
      position: relative;
      padding: 0;
      transition: background 0.16s ease, color 0.16s ease, transform 0.16s ease;
    }

    .turn-action-btn:hover,
    .turn-action-btn:focus-visible {
      background: var(--surface-2);
      color: var(--text);
      outline: none;
    }

    .turn-action-btn:focus-visible {
      border-color: var(--border-strong);
    }

    .turn-action-btn:disabled {
      color: var(--text-muted);
      cursor: default;
      opacity: 0.45;
    }

    .turn-action-btn.copied {
      color: var(--accent-green);
      background: rgba(52,211,153,0.08);
    }

    .turn-action-btn.copied::after {
      content: '';
      position: absolute;
      inset: 3px;
      border-radius: 999px;
      border: 1px solid currentColor;
      pointer-events: none;
      opacity: 0;
    }

    @media (prefers-reduced-motion: no-preference) {
      .turn-action-btn.copied {
        animation: copy-success-pop 420ms cubic-bezier(.2,.8,.2,1);
      }

      .turn-action-btn.copied::after {
        animation: copy-success-ring 520ms cubic-bezier(.2,.8,.2,1);
      }
    }

    @keyframes copy-success-pop {
      0% { transform: scale(1); }
      45% { transform: scale(1.14); }
      100% { transform: scale(1); }
    }

    @keyframes copy-success-ring {
      0% { opacity: 0.35; transform: scale(0.72); }
      100% { opacity: 0; transform: scale(1.55); }
    }

    @media (prefers-reduced-motion: reduce) {
      .turn-action-btn,
      .turn-action-btn.copied,
      .turn-action-btn.copied::after {
        animation: none;
        transition: none;
      }
    }

    .markdown-body :not(pre) > code {
      font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
      background: var(--surface-2);
      border: 1px solid var(--border);
      padding: 0.11rem 0.35rem;
      border-radius: 4px;
      font-size: 0.88em;
    }

    .markdown-body pre,
    .markdown-body code,
    .compaction-raw,
    .tool-details pre,
    .tool-entry-args .arg-value,
    .approval-path {
      direction: ltr;
      text-align: left;
    }

    .markdown-body table {
      width: 100%;
      border-collapse: collapse;
      margin: 0.6rem 0;
      font-size: 0.9rem;
    }

    .markdown-body th,
    .markdown-body td {
      border: 1px solid var(--border);
      padding: 0.35rem 0.5rem;
      text-align: left;
      vertical-align: top;
    }

    .markdown-body th {
      background: var(--surface-2);
    }

    .markdown-body a {
      color: var(--link);
      text-decoration: underline;
    }

    .markdown-body .katex {
      font-size: 1.02em;
    }

    .markdown-body .katex-display {
      margin: 0.85em 0;
      overflow-x: auto;
      overflow-y: hidden;
      padding-bottom: 0.1rem;
      position: relative;
    }

    .markdown-body .katex-display > .katex {
      white-space: nowrap;
    }

    .math-copy-btn {
      position: sticky;
      right: 0;
      float: right;
      margin-left: 0.5rem;
      border: 1px solid var(--border);
      border-radius: 999px;
      background: color-mix(in srgb, var(--surface) 92%, transparent);
      color: var(--text-muted);
      font-size: 0.68rem;
      line-height: 1;
      padding: 0.28rem 0.45rem;
      cursor: pointer;
      opacity: 0;
      transition: opacity 0.15s ease, background 0.15s ease, color 0.15s ease;
      z-index: 1;
    }

    .markdown-body .katex-display:hover .math-copy-btn,
    .math-copy-btn:focus-visible,
    .math-copy-btn.copied {
      opacity: 1;
    }

    .math-copy-btn:hover,
    .math-copy-btn:focus-visible {
      background: var(--surface-2);
      color: var(--text);
      outline: none;
    }

    .math-copy-btn:disabled {
      cursor: default;
      opacity: 0.45;
    }

    .math-copy-btn.copied {
      color: var(--accent-green);
    }

    .message-meta {
      display: inline-flex;
      align-items: center;
      gap: 0.45rem;
      color: var(--text-muted);
      font-size: 0.74rem;
      padding: 0 0.2rem;
      align-self: flex-end;
    }

    .interrupt-badge {
      display: inline-flex;
      align-items: center;
      gap: 0.32rem;
      border: 1px solid var(--border);
      border-radius: 999px;
      padding: 0.08rem 0.42rem;
      font-size: 0.69rem;
      line-height: 1.2;
      color: var(--text-muted);
      background: var(--surface-2);
      white-space: nowrap;
    }

    .interrupt-badge .interrupt-spinner {
      width: 0.62rem;
      height: 0.62rem;
      border-radius: 999px;
      border: 1.5px solid var(--border);
      border-top-color: var(--text);
      animation: spin 0.75s linear infinite;
      flex-shrink: 0;
    }

    .interrupt-badge.pending {
      color: var(--text);
      border-color: var(--border-strong);
      background: var(--surface-2);
    }

    .interrupt-badge.interject {
      color: var(--accent-green);
      border-color: rgba(52,211,153,0.3);
      background: rgba(52,211,153,0.08);
    }

    .interrupt-badge.cancel {
      color: var(--danger);
      border-color: rgba(248,113,113,0.3);
      background: rgba(248,113,113,0.08);
    }

    .interrupt-badge.queue {
      color: var(--accent-amber);
      border-color: var(--border);
      background: var(--surface);
    }

    .interrupt-badge.error {
      color: var(--danger);
      border-color: rgba(248,113,113,0.3);
      background: rgba(248,113,113,0.06);
    }

    .message.assistant .message-meta,
    .message.tool .message-meta,
    .message.error .message-meta {
      align-self: flex-start;
    }

    .usage-line {
      margin-top: -0.1rem;
      font-size: 0.76rem;
      color: var(--text-muted);
      padding: 0 0.2rem;
    }


    .tool-card {
      border: 1px solid var(--border);
      border-radius: 8px;
      background: var(--surface);
      overflow: hidden;
    }

    .tool-toggle {
      width: 100%;
      border: 0;
      background: transparent;
      color: inherit;
      padding: 0.65rem 0.75rem;
      display: flex;
      align-items: center;
      gap: 0.6rem;
      cursor: pointer;
      text-align: left;
      font-size: 0.92rem;
    }

    .tool-toggle:hover {
      background: var(--surface-2);
    }

    .tool-arrow {
      transition: transform 0.14s ease;
      color: var(--text-muted);
      width: 1rem;
      text-align: center;
      flex-shrink: 0;
    }

    .tool-toggle[aria-expanded="true"] .tool-arrow {
      transform: rotate(90deg);
      color: var(--text);
    }

    .tool-name {
      font-weight: 600;
      min-width: 0;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
    }

    .tool-status {
      margin-left: auto;
      color: var(--text-muted);
      font-size: 0.78rem;
      flex-shrink: 0;
    }

    .tool-details {
      border-top: 1px solid var(--border);
      padding: 0.58rem 0.75rem 0.72rem;
      display: none;
    }

    .tool-details.open {
      display: block;
    }

    .tool-details-label {
      font-size: 0.78rem;
      color: var(--text-muted);
      margin-bottom: 0.3rem;
    }

    .tool-details pre {
      margin: 0;
      padding: 0.65rem;
      border-radius: 8px;
      border: 1px solid var(--border);
      background: var(--surface);
      font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
      font-size: 0.83rem;
      white-space: pre-wrap;
      word-break: break-word;
    }

    .tool-group-card {
      border: 1px solid var(--border);
      border-radius: 8px;
      background: var(--surface);
      overflow: hidden;
    }

    .tool-group-toggle {
      width: 100%;
      border: 0;
      background: transparent;
      color: inherit;
      padding: 0.65rem 0.75rem;
      display: flex;
      align-items: center;
      gap: 0.6rem;
      cursor: pointer;
      text-align: left;
      font-size: 0.92rem;
    }

    .tool-group-toggle:hover {
      background: var(--surface-2);
    }

    .tool-group-toggle[aria-expanded="true"] .tool-arrow {
      transform: rotate(90deg);
      color: var(--text);
    }

    .tool-group-summary {
      font-weight: 600;
      min-width: 0;
    }

    .tool-group-details {
      border-top: 1px solid var(--border);
      display: none;
    }

    .tool-group-details.open {
      display: block;
    }

    .tool-group-entry {
      display: flex;
      align-items: center;
      gap: 0.5rem;
      padding: 0.4rem 0.75rem;
      font-size: 0.88rem;
      border-bottom: 1px solid var(--border);
    }

    .tool-group-entry:last-child {
      border-bottom: none;
    }

    .tool-group-entry .tool-entry-name {
      min-width: 0;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
    }

    .tool-group-entry .tool-entry-status {
      margin-left: auto;
      color: var(--accent-amber);
      font-size: 0.76rem;
      flex-shrink: 0;
    }

    .tool-group-entry .tool-entry-status.done {
      color: var(--accent-green);
    }

    .tool-entry-args {
      padding: 0.25rem 0.75rem 0.35rem 2rem;
      font-size: 0.78rem;
      color: var(--text-muted);
      line-height: 1.5;
    }

    .tool-entry-args .arg-line {
      display: flex;
      gap: 0.4rem;
    }

    .tool-entry-args .arg-label {
      color: var(--text-muted);
      flex-shrink: 0;
    }

    .tool-entry-args .arg-value {
      font-family: 'SF Mono', 'Cascadia Code', 'Fira Code', Menlo, Consolas, monospace;
      color: var(--text);
      white-space: pre-wrap;
      word-break: break-all;
      min-width: 0;
    }

    .tool-artifacts {
      display: flex;
      gap: 0.5rem;
      flex-wrap: wrap;
      padding: 0.7rem 0.75rem 0.7rem 2rem;
      border-top: 1px solid var(--border);
      background: var(--surface);
    }

    .tool-artifacts img {
      max-width: min(360px, 100%);
      max-height: 270px;
      border-radius: 8px;
      border: 1px solid var(--border);
      object-fit: cover;
      cursor: pointer;
      transition: opacity 0.15s ease;
      background: var(--surface-2);
    }

    .tool-artifacts img:hover {
      opacity: 0.85;
    }

    .markdown-body img,
    .markdown-body video {
      max-width: 100%;
      border-radius: 8px;
      margin: 0.5rem 0;
    }

    .deferred-video {
      display: inline-flex;
      flex-direction: column;
      gap: 0.75rem;
      margin: 0.5rem 0;
      max-width: 100%;
    }

    .deferred-video-poster {
      max-width: 100%;
      border-radius: 8px;
    }

    .deferred-video-btn {
      align-self: flex-start;
      border: 1px solid var(--border);
      border-radius: 999px;
      background: var(--surface-elevated);
      color: var(--text);
      padding: 0.55rem 0.9rem;
      cursor: pointer;
      font: inherit;
    }

    .deferred-video-btn:hover {
      background: color-mix(in srgb, var(--surface-elevated) 70%, var(--accent) 30%);
    }

    .composer {
      background: var(--bg);
      padding: 0.75rem calc(1rem + var(--safe-right)) max(0.3rem, calc(var(--safe-bottom) * 0.35)) calc(1rem + var(--safe-left));
      position: relative;
      z-index: 1;
    }

    .composer-inner {
      max-width: 900px;
      margin: 0 auto;
      display: flex;
      flex-direction: column;
      gap: 0;
    }

    .voice-status {
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 0.75rem;
      flex-wrap: wrap;
      margin: 0 0.3rem 0.45rem;
      padding: 0.65rem 0.85rem;
      border-radius: 14px;
      border: 1px solid var(--border);
      background: var(--surface);
      color: var(--text);
      min-height: 44px;
      backdrop-filter: blur(10px);
      -webkit-backdrop-filter: blur(10px);
    }

    .voice-status.hidden {
      display: none;
    }

    .voice-status-copy {
      min-width: 0;
      line-height: 1.35;
      font-size: 0.92rem;
    }

    .voice-status strong {
      font-variant-numeric: tabular-nums;
    }

    .voice-status-dot {
      width: 10px;
      height: 10px;
      border-radius: 999px;
      background: var(--danger);
      flex-shrink: 0;
      box-shadow: 0 0 0 0 rgba(248,113,113,0.5);
      animation: voice-pulse 1.35s infinite;
    }

    .voice-status-spinner {
      width: 15px;
      height: 15px;
      border-radius: 999px;
      border: 2px solid var(--border);
      border-top-color: var(--text);
      animation: spin 0.8s linear infinite;
      flex-shrink: 0;
    }

    .voice-status-cancel {
      border: 1px solid var(--border);
      background: var(--surface-2);
      color: var(--text);
      border-radius: 999px;
      padding: 0.42rem 0.7rem;
      font-size: 0.82rem;
      font-weight: 600;
      cursor: pointer;
      flex-shrink: 0;
    }

    .voice-status-cancel:hover {
      background: var(--surface-3);
    }

    @keyframes voice-pulse {
      0% { box-shadow: 0 0 0 0 rgba(248,113,113,0.55); }
      70% { box-shadow: 0 0 0 10px rgba(248,113,113,0); }
      100% { box-shadow: 0 0 0 0 rgba(248,113,113,0); }
    }

    .pending-interjection {
      display: flex;
      align-items: center;
      gap: 0.5rem;
      margin: 0 0.3rem 0.45rem;
      padding: 0.5rem 0.85rem;
      border-radius: 12px;
      border: 1px solid var(--border);
      background: var(--surface-2);
      color: var(--muted);
      font-size: 0.88rem;
      font-style: italic;
      line-height: 1.3;
    }

    .pending-interjection.hidden {
      display: none;
    }

    .pending-interjection .pending-interjection-icon {
      flex-shrink: 0;
      font-style: normal;
    }

    .pending-interjection .pending-interjection-text {
      min-width: 0;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
    }

    .pending-interjection .pending-interjection-label {
      flex-shrink: 0;
      opacity: 0.75;
      font-style: normal;
    }

    .composer-box {
      display: grid;
      grid-template-columns: auto 1fr auto;
      align-items: end;
      border: 1px solid var(--border);
      border-radius: 24px;
      background: var(--surface-2);
      padding: 6px;
    }

    .composer-box:focus-within {
      border-color: var(--border-strong);
    }

    .composer-icon-btn {
      border: none;
      background: transparent;
      color: var(--text-muted);
      width: 36px;
      height: 36px;
      display: inline-flex;
      align-items: center;
      justify-content: center;
      cursor: pointer;
      border-radius: 50%;
      flex-shrink: 0;
      margin-bottom: 6px;
      transition: background 0.15s ease, color 0.15s ease;
    }

    .composer-icon-btn:hover {
      background: var(--surface-3);
      color: var(--text);
    }

    .composer-icon-btn:disabled {
      opacity: 0.45;
      cursor: not-allowed;
    }

    .composer-icon-btn svg {
      width: 20px;
      height: 20px;
    }

    .voice-btn {
      margin-bottom: 6px;
    }

    .voice-btn.recording {
      background: rgba(248,113,113,0.14);
      color: var(--danger);
    }

    .voice-btn.recording:hover {
      background: rgba(248,113,113,0.2);
      color: var(--danger);
    }

    .voice-btn.busy {
      color: var(--text);
    }

    .prompt {
      resize: none;
      min-height: 36px;
      max-height: min(300px, max(200px, 45dvh));
      border: none;
      background: transparent;
      color: var(--text);
      padding: 14px 8px;
      line-height: 1.5;
      font-size: 1rem;
      overflow-y: auto;
      field-sizing: content;
      scrollbar-gutter: stable;
      unicode-bidi: plaintext;
    }

    .prompt:focus {
      outline: none;
    }

    .composer-actions {
      display: inline-flex;
      align-items: center;
      gap: 4px;
      flex-shrink: 0;
    }

    .stop-btn {
      border: 1px solid rgba(248,113,113,0.3);
      background: rgba(248,113,113,0.08);
      color: var(--stop-btn-text);
      border-radius: 999px;
      height: 36px;
      padding: 0 14px;
      cursor: pointer;
      display: none;
      font-weight: 600;
      font-size: 0.85rem;
      align-items: center;
      transition: background 0.15s ease;
    }

    .stop-btn:hover {
      background: rgba(248,113,113,0.14);
    }

    .stop-btn.visible {
      display: inline-flex;
    }

    .send-btn {
      width: 36px;
      height: 36px;
      border: none;
      border-radius: 999px;
      background: var(--gradient-accent-strong);
      color: var(--btn-accent-text);
      display: inline-flex;
      align-items: center;
      justify-content: center;
      font-weight: 700;
      cursor: pointer;
      flex-shrink: 0;
      margin-bottom: 7px;
      margin-right: 4px;
      transition: opacity 0.15s ease;
    }

    .send-btn:hover:not(:disabled) {
      opacity: 0.85;
    }

    .send-btn.interject {
      opacity: 1;
    }

    .send-btn:disabled {
      opacity: 0.35;
      cursor: not-allowed;
    }

    .send-btn .spinner {
      width: 14px;
      height: 14px;
      border-radius: 50%;
      border: 2px solid var(--spinner-ring);
      border-top-color: var(--btn-accent-text);
      animation: spin 0.8s linear infinite;
      display: none;
    }

    .send-btn.loading .spinner {
      display: inline-block;
    }

    .send-btn.loading .arrow {
      display: none;
    }

    @keyframes spin {
      to {
        transform: rotate(360deg);
      }
    }


    .sidebar-backdrop {
      position: fixed;
      inset: 0;
      background: var(--backdrop);
      opacity: 0;
      pointer-events: none;
      transition: opacity 0.18s ease;
      z-index: 15;
    }

    .sidebar-backdrop.open {
      opacity: 1;
      pointer-events: auto;
    }

    .modal-overlay {
      position: fixed;
      inset: 0;
      background: var(--overlay);
      z-index: 60;
      display: flex;
      align-items: center;
      justify-content: center;
      padding: 1rem;
    }

    .modal-overlay.hidden {
      display: none;
    }

    .modal {
      width: min(480px, 100%);
      border: 1px solid var(--border);
      background: var(--surface);
      border-radius: 8px;
      padding: 1.15rem;
      box-shadow: var(--shadow-strong);
    }

    .modal h2 {
      margin: 0 0 0.8rem;
      font-size: 1.05rem;
    }

    .modal p {
      margin: 0 0 0.85rem;
      color: var(--text-muted);
      font-size: 0.92rem;
      line-height: 1.5;
    }

    .modal input:not([type="radio"]):not([type="checkbox"]) {
      width: 100%;
      border: 1px solid var(--border);
      background: var(--surface-2);
      border-radius: 8px;
      padding: 0.78rem 0.85rem;
    }

    .modal input:not([type="radio"]):not([type="checkbox"]):focus {
      outline: 2px solid var(--border-strong);
      border-color: var(--border-strong);
    }

    .modal-error {
      min-height: 1.1rem;
      color: var(--danger);
      font-size: 0.84rem;
      margin-top: 0.5rem;
    }

    .modal-actions {
      margin-top: 0.75rem;
      display: flex;
      justify-content: flex-end;
      gap: 0.45rem;
      flex-wrap: wrap;
    }

    .btn {
      border-radius: 8px;
      border: 1px solid var(--border);
      background: var(--surface-2);
      color: var(--text);
      padding: 0.62rem 0.9rem;
      cursor: pointer;
      font-weight: 600;
      transition: background 0.15s ease;
    }

    .btn:hover:not(:disabled) {
      background: var(--surface-3);
    }

    .btn.primary {
      border-color: var(--border-strong);
      background: var(--gradient-accent-strong);
      color: var(--btn-accent-text);
      font-weight: 700;
    }

    .btn.primary:hover:not(:disabled) {
      opacity: 0.85;
      background: var(--gradient-accent-strong);
    }

    .btn:disabled {
      opacity: 0.65;
      cursor: not-allowed;
    }

    .rename-session-modal {
      width: min(420px, 100%);
    }

    .approval-modal { width: min(480px, 100%); }
    .approval-path {
      font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
      font-size: 0.88rem;
      background: var(--surface-2);
      border: 1px solid var(--border);
      border-radius: 6px;
      padding: 0.55rem 0.75rem;
      margin-bottom: 0.85rem;
      word-break: break-all;
    }
    .approval-body { max-height: min(50vh, 420px); overflow-y: auto; }

    .approval-options {
      display: flex;
      flex-direction: column;
      gap: 0.35rem;
    }
    .approval-option {
      display: flex;
      align-items: center;
      gap: 0.65rem;
      padding: 0.55rem 0.7rem;
      border-radius: 6px;
      cursor: pointer;
      transition: background 0.12s ease;
    }
    .approval-option:hover { background: var(--surface-2); }
    .approval-option:has(input:checked) { background: var(--surface-2); }
    .approval-option:has(input:focus-visible) {
      outline: 2px solid var(--border-strong);
      outline-offset: -2px;
    }
    .approval-option input {
      width: auto;
      padding: 0;
      border: 0;
      background: transparent;
      border-radius: 0;
      margin: 0;
      flex-shrink: 0;
      appearance: auto;
      accent-color: var(--accent-strong);
    }
    .approval-option-copy {
      display: flex;
      align-items: baseline;
      gap: 0.45rem;
      min-width: 0;
    }
    .approval-option-title {
      font-weight: 600;
      font-size: 0.92rem;
      white-space: nowrap;
    }
    .approval-option-desc {
      color: var(--text-muted);
      font-size: 0.82rem;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
    }

    .ask-user-modal {
      width: min(760px, 100%);
      max-height: min(86vh, 960px);
      display: flex;
      flex-direction: column;
    }

    .ask-user-body {
      display: flex;
      flex-direction: column;
      gap: 1rem;
      max-height: min(62vh, 580px);
      overflow-y: auto;
      padding-right: 0.2rem;
      margin-right: -0.1rem;
    }

    .ask-user-steps {
      display: flex;
      align-items: center;
      justify-content: center;
      gap: 0;
    }

    .ask-user-step {
      width: 30px;
      height: 30px;
      border-radius: 50%;
      border: 1.5px solid var(--border-strong);
      background: transparent;
      color: var(--text-muted);
      font-size: 0.78rem;
      font-weight: 700;
      display: inline-flex;
      align-items: center;
      justify-content: center;
      cursor: pointer;
      padding: 0;
      flex-shrink: 0;
      transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
    }

    .ask-user-step:hover {
      border-color: var(--text-muted);
    }

    .ask-user-step.active {
      border-color: var(--text);
      background: var(--text);
      color: var(--bg);
    }

    .ask-user-step.completed {
      border-color: var(--text-muted);
      background: var(--text-muted);
      color: var(--bg);
    }

    .ask-user-step-line {
      width: 28px;
      height: 2px;
      background: var(--border);
      flex-shrink: 0;
    }

    .ask-user-step-line.done {
      background: var(--text-muted);
    }

    .ask-user-question {
      border: 1px solid var(--border);
      border-radius: 8px;
      background: var(--surface-2);
      padding: 1rem;
    }

    .ask-user-question-header {
      display: inline-flex;
      align-items: center;
      gap: 0.35rem;
      font-size: 0.72rem;
      font-weight: 800;
      letter-spacing: 0.1em;
      text-transform: uppercase;
      color: var(--text-muted);
      margin-bottom: 0.55rem;
      padding: 0.28rem 0.55rem;
      border-radius: 999px;
      background: var(--surface-3);
      border: 1px solid var(--border);
    }

    .ask-user-question-text {
      margin: 0 0 0.9rem;
      font-size: 1.02rem;
      font-weight: 700;
      line-height: 1.45;
      color: var(--text);
    }

    .ask-user-options {
      display: grid;
      grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
      gap: 0.75rem;
    }

    .ask-user-option {
      display: flex;
      align-items: flex-start;
      gap: 0.8rem;
      border: 1px solid var(--border);
      border-radius: 8px;
      padding: 0.8rem 0.85rem;
      background: var(--surface);
      cursor: pointer;
      min-height: 100%;
      transition: background 0.15s ease;
    }

    .ask-user-option:hover {
      background: var(--surface-2);
    }

    .ask-user-option:has(input:checked) {
      border-color: var(--border-strong);
      background: var(--surface-2);
    }

    .ask-user-option:has(input:focus-visible) {
      outline: 2px solid var(--border-strong);
      outline-offset: 2px;
    }

    .ask-user-option input {
      width: auto;
      padding: 0;
      border: 0;
      background: transparent;
      border-radius: 0;
      margin: 0.18rem 0 0;
      flex-shrink: 0;
      appearance: auto;
      accent-color: var(--accent-strong);
    }

    .ask-user-option-copy {
      display: flex;
      flex-direction: column;
      gap: 0.2rem;
      min-width: 0;
    }

    .ask-user-option-title {
      font-weight: 700;
      line-height: 1.35;
    }

    .ask-user-option-desc {
      color: var(--text-muted);
      font-size: 0.86rem;
      line-height: 1.45;
    }

    .ask-user-custom-input {
      display: none;
      width: 100%;
      min-height: 80px;
      resize: vertical;
      border: 1px solid var(--border);
      background: var(--surface);
      color: var(--text);
      border-radius: 8px;
      padding: 0.75rem 0.85rem;
      margin-top: 0.75rem;
      font: inherit;
      font-size: 0.92rem;
      line-height: 1.5;
    }

    .ask-user-custom-input.visible {
      display: block;
    }

    .ask-user-custom-input:focus {
      outline: 2px solid var(--border-strong);
      border-color: var(--border-strong);
    }

    .ask-user-note {
      margin-top: 0.7rem;
      color: var(--text-muted);
      font-size: 0.8rem;
      line-height: 1.45;
    }

    .attachments {
      display: flex;
      gap: 0.5rem;
      flex-wrap: wrap;
      padding: 0.35rem 0.3rem 0;
    }

    .attachment-chip {
      display: inline-flex;
      align-items: center;
      gap: 0.35rem;
      background: var(--surface-2);
      border: 1px solid var(--border);
      border-radius: 4px;
      padding: 0.25rem 0.5rem;
      font-size: 0.82rem;
      max-width: 200px;
    }

    .attachment-chip img {
      width: 32px;
      height: 32px;
      object-fit: cover;
      border-radius: 4px;
    }

    .attachment-chip .att-name {
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
      min-width: 0;
    }

    .attachment-chip .att-remove {
      background: none;
      border: none;
      color: var(--text-muted);
      cursor: pointer;
      padding: 0 0.15rem;
      font-size: 1rem;
      line-height: 1;
      flex-shrink: 0;
    }

    .attachment-chip .att-remove:hover {
      color: var(--danger);
    }


    .drop-overlay {
      position: absolute;
      inset: 0;
      background: rgba(255,255,255,0.04);
      border: 2px dashed var(--border-strong);
      border-radius: 8px;
      z-index: 50;
      display: flex;
      align-items: center;
      justify-content: center;
      font-size: 1.1rem;
      color: var(--text);
      font-weight: 600;
      pointer-events: none;
    }

    .drop-overlay.hidden {
      display: none;
    }

    .message-attachments {
      display: flex;
      gap: 0.5rem;
      flex-wrap: wrap;
      margin-bottom: 0.4rem;
    }

    .message-attachments img {
      max-width: 360px;
      max-height: 270px;
      border-radius: 8px;
      border: 1px solid var(--border);
      object-fit: cover;
      cursor: pointer;
      transition: opacity 0.15s ease;
    }

    .message-attachments img:hover {
      opacity: 0.85;
    }

    .message-attachments .att-file {
      display: inline-flex;
      align-items: center;
      gap: 0.3rem;
      background: var(--surface-2);
      border: 1px solid var(--border);
      border-radius: 4px;
      padding: 0.2rem 0.5rem;
      font-size: 0.82rem;
      color: var(--text-muted);
    }

    .markdown-body img {
      cursor: zoom-in;
    }

    .video-link {
      text-decoration-style: dotted;
    }
    .video-link::after {
      content: ' ▶';
      font-size: 0.75em;
      opacity: 0.7;
    }

    .lightbox {
      position: fixed;
      inset: 0;
      z-index: 100;
      display: flex;
      align-items: center;
      justify-content: center;
      visibility: hidden;
      pointer-events: none;
    }

    .lightbox.active {
      visibility: visible;
      pointer-events: auto;
    }

    .lightbox-backdrop {
      position: absolute;
      inset: 0;
      background: rgba(0, 0, 0, 0.85);
      backdrop-filter: blur(12px);
      -webkit-backdrop-filter: blur(12px);
      cursor: zoom-out;
      opacity: 0;
      transition: opacity 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    }
    .lightbox.active .lightbox-backdrop {
      opacity: 1;
    }

    .lightbox-content {
      position: relative;
      z-index: 1;
      display: flex;
      align-items: center;
      justify-content: center;
      padding: 2rem;
      max-width: 100vw;
      max-height: 100vh;
      box-sizing: border-box;
      opacity: 0;
      transform: scale(0.92);
      transition: opacity 0.25s cubic-bezier(0.4, 0, 0.2, 1),
                  transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    }
    .lightbox.active .lightbox-content {
      opacity: 1;
      transform: scale(1);
    }

    .lightbox-content img,
    .lightbox-content video {
      max-width: 90vw;
      max-height: 85vh;
      object-fit: contain;
      border-radius: 8px;
    }

    .lightbox.lightbox-maximized .lightbox-content {
      padding: 0;
    }
    .lightbox.lightbox-maximized .lightbox-content img,
    .lightbox.lightbox-maximized .lightbox-content video {
      max-width: 100vw;
      max-height: 100vh;
      border-radius: 0;
    }

    .lightbox-toolbar {
      position: absolute;
      top: calc(var(--safe-top) + 0.75rem);
      right: calc(var(--safe-right) + 0.75rem);
      z-index: 2;
      display: flex;
      gap: 0.25rem;
      background: rgba(0, 0, 0, 0.5);
      border-radius: 999px;
      padding: 0.25rem;
      opacity: 0;
      transform: translateY(-8px);
      transition: opacity 0.2s cubic-bezier(0.4, 0, 0.2, 1) 0.08s,
                  transform 0.2s cubic-bezier(0.4, 0, 0.2, 1) 0.08s;
    }
    .lightbox.active .lightbox-toolbar {
      opacity: 1;
      transform: translateY(0);
    }

    .lightbox-btn {
      width: 36px;
      height: 36px;
      display: flex;
      align-items: center;
      justify-content: center;
      background: none;
      border: none;
      border-radius: 50%;
      color: #fff;
      cursor: pointer;
      transition: background 0.15s;
    }
    .lightbox-btn:hover {
      background: rgba(255, 255, 255, 0.15);
    }
    .lightbox-btn.copied {
      color: #4ade80;
    }

    @media (max-width: 767px) {
      body {
        overflow: hidden;
      }

      .app {
        grid-template-columns: 1fr;
        height: var(--app-height);
        min-height: var(--app-height);
        overflow: hidden;
      }

      .app.sidebar-collapsed {
        grid-template-columns: 1fr;
      }

      .sidebar {
        position: fixed;
        top: 0;
        bottom: 0;
        left: 0;
        width: min(280px, 85vw);
        display: flex;
        flex-direction: column;
        transform: translateX(-100%);
        transition: transform 0.22s cubic-bezier(0.4, 0, 0.2, 1), visibility 0s linear 0.22s;
        box-shadow: none;
        padding-bottom: var(--safe-bottom);
        visibility: hidden;
        pointer-events: none;
      }

      .sidebar-rail {
        display: none;
      }

      .sidebar-panel {
        display: flex;
        flex-direction: column;
        width: 100%;
      }

      .app.sidebar-collapsed .sidebar-panel {
        display: flex;
        opacity: 1;
        pointer-events: auto;
      }

      .sidebar.open {
        transform: translateX(0);
        box-shadow: 4px 0 20px rgba(0, 0, 0, 0.28);
        visibility: visible;
        pointer-events: auto;
        transition: transform 0.22s cubic-bezier(0.4, 0, 0.2, 1), visibility 0s linear 0s;
      }

      .sidebar-close {
        display: inline-flex;
      }

      .main {
        height: var(--app-height);
        min-height: 0;
      }

      .main-header {
        padding: calc(0.7rem + var(--safe-top)) calc(0.8rem + var(--safe-right)) 0.7rem calc(0.8rem + var(--safe-left));
        flex-wrap: nowrap;
      }

      .mobile-menu {
        display: inline-flex;
      }


      .header-right {
        margin-left: auto;
        flex-shrink: 0;
      }

      .header-stats {
        font-size: 0.78rem;
        min-width: 0;
        flex-shrink: 1;
      }

      .header-tokens,
      .header-tokens-sep {
        display: none;
      }

      .model-picker {
        flex-wrap: nowrap;
        min-width: 0;
      }

      .chip-trigger {
        padding: 0.32rem 0.45rem;
      }

      .model-chip[data-chip="model"] .chip-label {
        max-width: 38vw;
      }

      .model-chip[data-chip="provider"] .chip-label {
        max-width: 22vw;
      }

      .chat-scroll {
        padding: 0.8rem calc(0.75rem + var(--safe-right)) 0.7rem calc(0.75rem + var(--safe-left));
      }

      .composer {
        padding: 0.45rem calc(0.5rem + var(--safe-right)) max(0.1rem, calc(var(--safe-bottom) * 0.2)) calc(0.5rem + var(--safe-left));
      }

      .voice-status {
        margin: 0 0.15rem 0.4rem;
        padding: 0.65rem 0.75rem;
        border-radius: 16px;
        gap: 0.6rem;
      }

      .voice-status-copy {
        font-size: 0.89rem;
      }

      .voice-status-cancel {
        padding: 0.48rem 0.72rem;
      }

      .composer-box {
        grid-template-columns: auto minmax(0, 1fr) auto;
        border-radius: 22px;
        padding: 5px;
      }

      .composer-icon-btn,
      .send-btn,
      .stop-btn {
        min-height: 40px;
      }

      .composer-icon-btn,
      .send-btn {
        width: 40px;
        height: 40px;
      }

      .prompt {
        padding: 12px 6px;
      }

      .message.user {
        width: min(92%, 820px);
      }

      .settings-row {
        align-items: flex-start;
        flex-direction: column;
      }

      .ask-user-modal {
        width: 100%;
        max-height: min(88vh, 1000px);
        padding: 1rem;
      }

      .ask-user-body {
        max-height: min(64vh, 620px);
      }

      .ask-user-options {
        grid-template-columns: 1fr;
      }

      .ask-user-question {
        padding: 0.9rem;
      }
    }
