:root {
  color-scheme: dark;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #0f172a;
  color: #e5e7eb;
  --header-h: 3.6rem;
  --bottom-nav-h: 3.75rem;
  --composer-h: 0px;
  --sidebar-w: min(320px, 38vw);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at top left, rgba(56, 189, 248, 0.2), transparent 32rem),
    linear-gradient(180deg, #111827, #020617);
}

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

button {
  border: 0;
  border-radius: 0.9rem;
  background: #38bdf8;
  color: #082f49;
  cursor: pointer;
  font-weight: 700;
  padding: 0.85rem 1rem;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.6;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid #334155;
  border-radius: 0.8rem;
  background: #020617;
  color: #f8fafc;
  margin-top: 0.45rem;
  padding: 0.8rem;
}

textarea {
  resize: vertical;
}

.shell {
  width: min(960px, 100%);
  margin: 0 auto;
  min-height: 100vh;
  padding: 0;
}

.login-card {
  margin: 1rem;
  padding: 1rem;
}

.login-brand {
  margin-bottom: 1rem;
}

.hidden {
  display: none !important;
}

.eyebrow {
  align-items: center;
  color: #7dd3fc;
  display: flex;
  flex-wrap: wrap;
  font-size: 0.8rem;
  gap: 0.5rem;
  letter-spacing: 0.12em;
  margin: 0 0 0.3rem;
  text-transform: uppercase;
}

.version {
  border: 1px solid rgba(125, 211, 252, 0.35);
  border-radius: 999px;
  color: #bae6fd;
  font-size: 0.72rem;
  letter-spacing: 0.04em;
  padding: 0.12rem 0.45rem;
  text-transform: none;
}

h1,
h2 {
  margin: 0;
}

h2 {
  font-size: 1.1rem;
  margin-bottom: 0.8rem;
}

.card {
  border: 1px solid rgba(148, 163, 184, 0.2);
  border-radius: 1.2rem;
  background: rgba(15, 23, 42, 0.84);
  box-shadow: 0 24px 80px rgba(2, 6, 23, 0.3);
}

.stack {
  display: grid;
  gap: 1rem;
}

label {
  color: #cbd5e1;
  display: block;
  font-size: 0.95rem;
}

.ghost {
  background: transparent;
  border: 1px solid #334155;
  color: #e5e7eb;
}

.ghost.small,
button.small {
  border-radius: 0.7rem;
  font-size: 0.82rem;
  padding: 0.45rem 0.7rem;
}

.icon-btn {
  align-items: center;
  border-radius: 0.75rem;
  display: inline-flex;
  justify-content: center;
  min-width: 2.4rem;
  padding: 0.45rem 0.55rem;
}

.chat-back-btn {
  flex-shrink: 0;
  min-width: 2.2rem;
  padding: 0.3rem 0.35rem;
}

.danger {
  border-color: #7f1d1d;
  color: #fecaca;
}

.danger:hover:not(:disabled) {
  background: rgba(185, 28, 28, 0.16);
}

.hint,
.empty {
  color: #94a3b8;
  margin: 0;
}

.meta {
  color: #94a3b8;
  font-size: 0.85rem;
}

/* App shell */

.app-shell {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  max-height: 100vh;
  max-height: 100dvh;
  min-height: 0;
  overflow: hidden;
  padding-bottom: calc(var(--bottom-nav-h) + var(--safe-bottom));
}

.app-shell.has-composer {
  padding-bottom: calc(var(--bottom-nav-h) + var(--composer-h) + var(--safe-bottom));
}

.app-shell.in-chat {
  padding-bottom: var(--safe-bottom);
}

.app-shell.in-chat.has-composer {
  padding-bottom: var(--composer-h);
}

.app-shell.in-chat .bottom-nav,
.app-shell.in-chat .session-switcher,
.app-shell.in-chat .home-header-action,
.app-shell.in-chat .history-aside,
.app-shell.in-chat .session-summary-wrap,
.app-shell.in-chat .context-eyebrow {
  display: none !important;
}

.app-shell.in-chat .chat-back-btn {
  display: inline-flex !important;
}

.app-shell.in-chat .context-header {
  align-items: center;
  min-height: 3.1rem;
  padding: calc(0.45rem + env(safe-area-inset-top, 0px)) 0.65rem 0.45rem;
}

.app-shell.in-chat .context-main {
  flex: 1 1 auto;
  min-width: 0;
}

.app-shell.in-chat .context-meta strong {
  font-size: 1.02rem;
}

.app-shell.in-chat .app-body {
  display: flex;
}

.app-shell.in-chat .session-pull-zone {
  padding: 0;
}

.app-shell.in-chat .chat {
  background: transparent;
  border: 0;
  border-radius: 0;
  flex: 1 1 0;
  min-height: 0;
  min-width: 0;
  padding: 0.75rem 0.85rem 2.25rem;
}

.app-shell.in-chat .follow-up-dock {
  bottom: 0;
  padding-bottom: calc(0.55rem + var(--safe-bottom));
}

.app-shell.in-chat .new-messages-fab {
  bottom: 0.75rem;
}

.context-header {
  align-items: flex-start;
  background: rgba(15, 23, 42, 0.95);
  border-bottom: 1px solid rgba(148, 163, 184, 0.15);
  display: flex;
  flex-shrink: 0;
  gap: 0.75rem;
  justify-content: space-between;
  min-height: var(--header-h);
  padding: 0.65rem 0.85rem calc(0.65rem + env(safe-area-inset-top, 0px));
  position: sticky;
  top: 0;
  z-index: 20;
  backdrop-filter: blur(10px);
}

.context-main {
  display: grid;
  gap: 0.15rem;
  min-width: 0;
}

.context-eyebrow {
  color: #7dd3fc;
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  margin: 0;
  text-transform: uppercase;
}

.context-meta {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.context-meta strong {
  font-size: 1rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.context-actions {
  display: flex;
  flex-shrink: 0;
  flex-wrap: wrap;
  gap: 0.35rem;
  justify-content: flex-end;
}

.app-body {
  display: flex;
  flex: 1 1 0;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.main-panel {
  display: flex;
  flex: 1 1 0;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
  overflow: hidden;
}

.tab-panel {
  display: flex;
  flex: 1 1 0;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
  overflow: hidden;
}

.tab-panel.active:not([hidden]) {
  display: flex !important;
}

.tab-panel[hidden] {
  display: none !important;
}

.history-aside {
  display: none;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
  overflow: hidden;
}

#appView[data-active-tab="history"] .history-aside {
  display: flex;
  flex: 1 1 0;
  min-height: 0;
}

#appView[data-active-tab="history"]:not(.is-wide) .main-panel {
  display: none;
}

.history-panel {
  flex-shrink: 0;
  min-width: 0;
  padding: 0 0.75rem 0.75rem;
  width: 100%;
}

.history-panel > * {
  max-width: 100%;
  min-width: 0;
}

.filter-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.filter-chip {
  background: rgba(2, 6, 23, 0.55);
  border: 1px solid #334155;
  border-radius: 999px;
  color: #94a3b8;
  font-size: 0.78rem;
  font-weight: 600;
  padding: 0.35rem 0.7rem;
}

.filter-chip.active {
  background: rgba(56, 189, 248, 0.18);
  border-color: rgba(56, 189, 248, 0.45);
  color: #e0f2fe;
}

.inline-toggle {
  align-items: center;
  color: #cbd5e1;
  display: flex;
  font-size: 0.88rem;
  gap: 0.5rem;
}

.inline-toggle input {
  flex-shrink: 0;
  margin: 0;
  width: auto;
}

.inline-toggle span {
  min-width: 0;
}

.settings-toggle {
  justify-content: space-between;
}

.pull-refresh-zone {
  display: flex;
  flex: 1 1 0;
  flex-direction: column;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior-y: contain;
  position: relative;
  touch-action: pan-y;
  -webkit-overflow-scrolling: touch;
}

.session-pull-zone {
  padding: 0 0.75rem 0.75rem;
}

.session-pull-zone.is-active-job {
  overflow: hidden;
}

.session-pull-zone.is-active-job .session-summary-wrap {
  flex-shrink: 0;
}

.session-pull-zone.is-active-job .chat:not(.hidden) {
  flex: 1 1 0;
  min-height: 0;
  min-width: 0;
}

.pull-refresh-indicator {
  align-items: center;
  color: #7dd3fc;
  display: flex;
  font-size: 0.78rem;
  height: 0;
  justify-content: center;
  overflow: hidden;
  transition: height 0.15s ease;
}

.pull-refresh-zone.is-pulling .pull-refresh-indicator,
.pull-refresh-zone.is-refreshing .pull-refresh-indicator {
  height: 2rem;
}

.pull-refresh-zone.is-refreshing .pull-refresh-text::after {
  animation: spin 0.8s linear infinite;
  content: " ⟳";
  display: inline-block;
}

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

.onboarding {
  background: rgba(56, 189, 248, 0.08);
  border: 1px solid rgba(56, 189, 248, 0.28);
  border-radius: 1rem;
  margin-bottom: 0.75rem;
  padding: 0.85rem;
}

.onboarding-title {
  font-weight: 700;
  margin: 0 0 0.5rem;
}

.onboarding-steps {
  color: #cbd5e1;
  margin: 0 0 0.75rem;
  padding-left: 1.2rem;
}

.onboarding-steps li + li {
  margin-top: 0.25rem;
}

.model-advanced {
  border: 1px solid #334155;
  border-radius: 0.85rem;
  padding: 0.55rem 0.75rem;
}

.model-advanced summary {
  color: #cbd5e1;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 600;
  list-style: none;
  user-select: none;
}

.model-advanced summary::-webkit-details-marker {
  display: none;
}

.model-advanced[open] {
  display: grid;
  gap: 0.75rem;
}

.job-item {
  position: relative;
}

.job-item-actions {
  display: flex;
  gap: 0.35rem;
  justify-content: flex-end;
  margin-top: 0.45rem;
}

.job-item-actions .ghost {
  font-size: 0.72rem;
  padding: 0.25rem 0.55rem;
}

.session-empty {
  align-items: center;
  display: grid;
  gap: 1rem;
  justify-items: center;
  margin: auto;
  max-width: 22rem;
  padding: 2rem 1rem;
  text-align: center;
}

.session-empty p {
  color: #94a3b8;
  margin: 0;
}

.session-summary-wrap {
  flex-shrink: 0;
}

.session-summary {
  border: 1px solid #1e293b;
  border-radius: 0.9rem;
  background: rgba(2, 6, 23, 0.55);
  flex-shrink: 0;
}

.session-summary > summary {
  align-items: center;
  cursor: pointer;
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  list-style: none;
  padding: 0.55rem 0.75rem;
  user-select: none;
}

.session-summary > summary::-webkit-details-marker {
  display: none;
}

.session-summary > summary::before {
  color: #64748b;
  content: "▸";
  flex-shrink: 0;
  font-size: 0.72rem;
  margin-right: 0.15rem;
  transition: transform 0.15s ease;
}

.session-summary[open] > summary::before {
  transform: rotate(90deg);
}

.session-summary-body {
  border-top: 1px solid #1e293b;
  padding: 0.55rem 0.75rem 0.65rem;
}

.session-summary-body p {
  margin: 0.35rem 0 0;
}

.chat {
  background: #020617;
  border: 1px solid #1e293b;
  border-radius: 1rem;
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 0.75rem;
  min-height: 12rem;
  min-width: 0;
  overflow-x: hidden;
  overflow-y: auto;
  padding: 1rem 1rem 1.75rem;
  position: relative;
}

.new-messages-fab {
  align-self: center;
  background: #0f172a;
  border: 1px solid #38bdf8;
  border-radius: 999px;
  bottom: 0.5rem;
  box-shadow: 0 8px 24px rgba(2, 6, 23, 0.45);
  color: #7dd3fc;
  font-size: 0.82rem;
  margin-top: -2.5rem;
  padding: 0.45rem 0.85rem;
  position: sticky;
  z-index: 5;
}

.projects-panel {
  flex-shrink: 0;
  padding: 0 0.75rem 1.25rem;
}

.project-current-card {
  background: rgba(56, 189, 248, 0.08);
  border: 1px solid rgba(56, 189, 248, 0.28);
  border-radius: 1rem;
  padding: 0.85rem;
}

.project-list {
  display: grid;
  gap: 0.55rem;
}

.project-item {
  align-items: flex-start;
  background: rgba(2, 6, 23, 0.55);
  border: 1px solid #1e293b;
  border-radius: 0.95rem;
  cursor: pointer;
  display: grid;
  gap: 0.2rem;
  padding: 0.8rem 0.9rem;
  text-align: left;
  transition:
    border-color 0.15s ease,
    background 0.15s ease;
  width: 100%;
}

.project-item:hover,
.project-item.active {
  border-color: rgba(56, 189, 248, 0.45);
  background: rgba(56, 189, 248, 0.06);
}

.project-item-name {
  color: #f8fafc;
  font-weight: 700;
}

.project-item-path {
  color: #94a3b8;
  font-size: 0.78rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.project-item-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  justify-content: flex-end;
  margin-top: 0.45rem;
}

.project-item-actions .ghost {
  font-size: 0.72rem;
  padding: 0.25rem 0.55rem;
}

#browseOpenButton {
  width: 100%;
}

/* Bottom nav */

.bottom-nav {
  align-items: stretch;
  background: rgba(15, 23, 42, 0.96);
  border-top: 1px solid rgba(148, 163, 184, 0.15);
  bottom: 0;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  left: 0;
  min-height: var(--bottom-nav-h);
  padding-bottom: var(--safe-bottom);
  position: fixed;
  right: 0;
  z-index: 30;
  backdrop-filter: blur(10px);
}

.nav-item {
  align-items: center;
  background: transparent;
  border-radius: 0;
  color: #94a3b8;
  display: flex;
  flex-direction: column;
  font-size: 0.72rem;
  font-weight: 600;
  gap: 0.15rem;
  justify-content: center;
  padding: 0.45rem 0.25rem;
}

.nav-item.active {
  background: rgba(56, 189, 248, 0.08);
  color: #7dd3fc;
}

.nav-icon-wrap {
  position: relative;
}

.nav-icon {
  font-size: 1rem;
  line-height: 1;
}

.nav-badge {
  background: #1d4ed8;
  border-radius: 999px;
  color: #dbeafe;
  font-size: 0.62rem;
  font-weight: 800;
  line-height: 1;
  min-width: 1rem;
  padding: 0.12rem 0.28rem;
  position: absolute;
  right: -0.65rem;
  top: -0.35rem;
}

.session-switcher {
  background: rgba(15, 23, 42, 0.94);
  border-bottom: 1px solid rgba(148, 163, 184, 0.12);
  display: flex;
  flex-shrink: 0;
  gap: 0.55rem;
  overflow: hidden;
  padding: 0.4rem 0.75rem 0.5rem;
  position: sticky;
  top: var(--header-h);
  z-index: 19;
}

.session-switcher.hidden {
  display: none;
}

.session-switcher-label {
  align-self: center;
  color: #94a3b8;
  flex-shrink: 0;
  font-size: 0.72rem;
  font-weight: 700;
}

.session-switcher-list {
  display: flex;
  gap: 0.4rem;
  min-width: 0;
  overflow-x: auto;
  padding-bottom: 0.1rem;
  scrollbar-width: thin;
}

.session-switch-chip {
  align-items: center;
  background: #0f172a;
  border: 1px solid #334155;
  border-radius: 999px;
  color: #e2e8f0;
  display: inline-flex;
  flex-shrink: 0;
  font-size: 0.75rem;
  font-weight: 650;
  gap: 0.35rem;
  max-width: 14rem;
  padding: 0.28rem 0.65rem;
}

.session-switch-chip .status {
  font-size: 0.68rem;
  margin-left: 0;
  padding: 0.1rem 0.35rem;
}

.session-switch-chip-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.session-switch-chip.current {
  background: rgba(56, 189, 248, 0.12);
  border-color: rgba(56, 189, 248, 0.55);
  color: #e0f2fe;
}

/* Follow-up dock */

.follow-up-dock {
  background: linear-gradient(180deg, transparent, rgba(15, 23, 42, 0.92) 28%);
  bottom: calc(var(--bottom-nav-h) + var(--safe-bottom));
  left: 0;
  overflow: visible;
  padding: 0.55rem 0.75rem 0.6rem;
  position: fixed;
  right: 0;
  z-index: 25;
}

.follow-up-composer {
  position: relative;
  border: 1px solid #334155;
  border-radius: 1.35rem;
  background: #0b1220;
  box-shadow: 0 10px 28px rgba(2, 6, 23, 0.35);
  display: grid;
  gap: 0.35rem;
  padding: 0.7rem 0.75rem 0.55rem;
}

.composer-popover {
  background: #0f172a;
  border: 1px solid #334155;
  border-radius: 1rem;
  bottom: calc(100% + 0.5rem);
  box-shadow: 0 12px 32px rgba(2, 6, 23, 0.45);
  display: grid;
  gap: 0.55rem;
  left: 0;
  max-height: min(60vh, 28rem);
  overflow: auto;
  padding: 0.75rem;
  position: absolute;
  right: 0;
  z-index: 30;
}

.follow-up-status {
  color: #94a3b8;
  font-size: 0.72rem;
  line-height: 1.35;
  margin: 0 0.15rem;
}

.follow-up-status.is-ready,
.follow-up-status:empty {
  display: none;
}

.follow-up-composer textarea {
  border: 0;
  border-radius: 0.7rem;
  background: transparent;
  margin: 0;
  min-height: 2.4rem;
  padding: 0.15rem 0.35rem;
  resize: none;
}

.follow-up-composer textarea:focus {
  outline: none;
}

.follow-up-toolbar {
  align-items: center;
  display: flex;
  gap: 0.4rem;
  justify-content: space-between;
  min-width: 0;
}

.follow-up-toolbar-start,
.follow-up-toolbar-end {
  align-items: center;
  display: flex;
  gap: 0.2rem;
  min-width: 0;
}

.follow-up-toolbar-start {
  flex: 1 1 auto;
}

.follow-up-toolbar-end {
  flex-shrink: 0;
}

.composer-icon-btn,
.composer-send-btn {
  align-items: center;
  border-radius: 999px;
  display: inline-flex;
  flex-shrink: 0;
  height: 2rem;
  justify-content: center;
  min-width: 2rem;
  padding: 0;
  width: 2rem;
}

.composer-icon-btn {
  background: transparent;
  border: 1px solid #475569;
  color: #cbd5e1;
}

.composer-icon-btn:hover:not(:disabled) {
  background: rgba(148, 163, 184, 0.12);
  color: #f8fafc;
}

.voice-mode-btn.is-active {
  background: rgba(56, 189, 248, 0.16);
  border-color: #38bdf8;
  color: #7dd3fc;
}

.voice-btn.is-recording {
  background: rgba(239, 68, 68, 0.16);
  border-color: #ef4444;
  color: #fecaca;
}

.voice-btn.is-recording svg {
  animation: voice-pulse 1s ease-in-out infinite;
}

.voice-btn.is-busy {
  border-color: #38bdf8;
  color: #7dd3fc;
}

@keyframes voice-pulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.45;
  }
}

.composer-icon-btn svg,
.composer-send-btn svg,
.composer-chevron {
  display: block;
  height: 1.05rem;
  width: 1.05rem;
}

.composer-model-btn {
  align-items: center;
  background: transparent;
  border: 0;
  border-radius: 0.7rem;
  color: #94a3b8;
  display: inline-flex;
  font-size: 0.82rem;
  font-weight: 500;
  gap: 0.2rem;
  max-width: min(14rem, 46vw);
  min-width: 0;
  padding: 0.3rem 0.35rem;
}

.composer-model-btn:hover:not(:disabled) {
  background: rgba(148, 163, 184, 0.1);
  color: #e2e8f0;
}

.composer-model-btn[aria-expanded="true"] {
  color: #e2e8f0;
}

.composer-model-btn[aria-expanded="true"] .composer-chevron {
  transform: rotate(180deg);
}

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

.composer-chevron {
  flex-shrink: 0;
  height: 0.7rem;
  width: 0.7rem;
}

.composer-send-btn {
  background: #38bdf8;
  color: #082f49;
}

.composer-send-btn:hover:not(:disabled) {
  background: #7dd3fc;
}

.composer-send-btn:disabled {
  background: #1e293b;
  color: #64748b;
  opacity: 1;
}

.follow-up-previews:not(:empty) {
  padding: 0 0.2rem;
}

.follow-up-toolbar-end .ghost.small {
  min-width: 0;
  padding: 0.35rem 0.65rem;
}

.follow-up-settings {
  display: grid;
  gap: 0.55rem;
  grid-template-columns: repeat(auto-fit, minmax(9.5rem, 1fr));
}

.follow-up-composer .model-params label,
.follow-up-mode {
  font-size: 0.85rem;
}

.follow-up-composer .model-params select,
.follow-up-mode select {
  border: 1px solid #334155;
  border-radius: 0.65rem;
  font-size: 0.9rem;
  margin-top: 0.25rem;
  padding: 0.55rem 0.65rem;
}

.new-task-composer textarea {
  min-height: 5.5rem;
}

.new-task-composer .composer-popover {
  bottom: auto;
  top: calc(100% + 0.5rem);
}

.new-task-composer .composer-model-btn {
  max-width: min(16rem, 58vw);
}

/* Sheets & overlays */

.sheet,
.overlay {
  inset: 0;
  position: fixed;
  z-index: 40;
}

.sheet-backdrop {
  background: rgba(2, 6, 23, 0.72);
  inset: 0;
  position: absolute;
}

.sheet-panel,
.overlay-panel {
  background: #0f172a;
  border: 1px solid rgba(148, 163, 184, 0.2);
  border-radius: 1.2rem 1.2rem 0 0;
  bottom: 0;
  box-shadow: 0 -24px 80px rgba(2, 6, 23, 0.45);
  left: 0;
  max-height: 92vh;
  overflow: auto;
  padding: calc(0.85rem + env(safe-area-inset-top, 0px))
    max(1rem, env(safe-area-inset-left, 0px), env(safe-area-inset-right, 0px))
    calc(1rem + var(--safe-bottom));
  position: absolute;
  right: 0;
}

.overlay-panel.browse-overlay {
  border-radius: 0;
  display: grid;
  gap: 0.75rem;
  max-height: 100vh;
  padding: calc(0.75rem + env(safe-area-inset-top, 0px)) 0.85rem calc(1rem + var(--safe-bottom));
}

.sheet-header,
.overlay-header {
  align-items: center;
  display: flex;
  gap: 0.75rem;
  justify-content: space-between;
  margin-bottom: 0.85rem;
  position: sticky;
  top: 0;
  background: #0f172a;
  padding-top: 0.25rem;
  z-index: 1;
}

.sheet-body {
  padding-bottom: 0.25rem;
}

.sheet-project-row {
  align-items: center;
  display: flex;
  gap: 0.75rem;
  justify-content: space-between;
  min-width: 0;
}

.sheet-project-row > div:first-child {
  flex: 1;
  min-width: 0;
}

.sheet-project-row > .ghost {
  flex-shrink: 0;
}

.sheet-label {
  color: #94a3b8;
  display: block;
  font-size: 0.82rem;
}

.sheet-project-name {
  color: #f8fafc;
  font-weight: 700;
  margin: 0.15rem 0 0;
  word-break: break-all;
}

.sheet-project-path {
  color: #94a3b8;
  font-size: 0.78rem;
  font-weight: 400;
  margin: 0.2rem 0 0;
  word-break: break-all;
}

.mode-segment {
  background: rgba(2, 6, 23, 0.7);
  border: 1px solid #334155;
  border-radius: 0.85rem;
  display: grid;
  gap: 0.2rem;
  grid-template-columns: 1fr 1fr;
  padding: 0.2rem;
}

.mode-segment-btn {
  background: transparent;
  border-radius: 0.7rem;
  color: #94a3b8;
  font-size: 0.88rem;
  padding: 0.65rem 0.5rem;
}

.mode-segment-btn.active {
  background: rgba(56, 189, 248, 0.18);
  color: #e0f2fe;
}

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

.settings-row .lang-switch {
  flex-shrink: 0;
}

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

.settings-account {
  background: rgba(2, 6, 23, 0.45);
  border: 1px solid #334155;
  border-radius: 0.9rem;
  padding: 0.85rem 1rem;
}

.user-list {
  display: grid;
  gap: 0.5rem;
}

.user-item {
  align-items: flex-start;
  background: rgba(2, 6, 23, 0.45);
  border: 1px solid #334155;
  border-radius: 0.85rem;
  color: inherit;
  display: grid;
  gap: 0.15rem;
  padding: 0.75rem 0.9rem;
  text-align: left;
}

.user-item.active {
  border-color: #38bdf8;
  background: rgba(56, 189, 248, 0.12);
}

.permission-list {
  display: grid;
  gap: 0.45rem;
  margin-top: 0.4rem;
}

.user-edit-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
}

.user-edit-actions button {
  flex: 1 1 6rem;
}

.lang-switch {
  align-items: stretch;
  background: rgba(2, 6, 23, 0.55);
  border: 1px solid #334155;
  border-radius: 0.9rem;
  display: inline-flex;
  overflow: hidden;
  padding: 0.15rem;
}

.lang-option {
  background: transparent;
  border: 0;
  border-radius: 0.75rem;
  color: #94a3b8;
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  min-width: 2.2rem;
  padding: 0.4rem 0.55rem;
}

.lang-option.active {
  background: rgba(56, 189, 248, 0.18);
  color: #e0f2fe;
}

.lang-option:not(.active):hover {
  color: #e5e7eb;
}

.browse-path {
  margin: 0;
  word-break: break-all;
}

.browse-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.browse-toolbar .ghost {
  padding: 0.45rem 0.75rem;
}

.browse-create {
  align-items: end;
  display: grid;
  gap: 0.5rem;
  grid-template-columns: minmax(0, 1fr) auto;
}

.browse-create-field {
  display: grid;
  gap: 0.35rem;
  min-width: 0;
}

.browse-create-field input {
  width: 100%;
}

.browse-create-hint {
  grid-column: 1 / -1;
  margin: 0;
}

.browse-list {
  display: grid;
  flex: 1;
  gap: 0.5rem;
  max-height: none;
  min-height: 12rem;
  overflow: auto;
}

.browse-item {
  align-items: center;
  background: rgba(15, 23, 42, 0.8);
  border: 1px solid #1e293b;
  border-radius: 0.85rem;
  cursor: pointer;
  display: flex;
  gap: 0.65rem;
  justify-content: space-between;
  padding: 0.7rem 0.85rem;
  text-align: left;
  transition:
    border-color 0.15s ease,
    background 0.15s ease;
  width: 100%;
}

.browse-item:hover {
  border-color: rgba(56, 189, 248, 0.45);
  background: rgba(56, 189, 248, 0.06);
}

.browse-item-main {
  display: grid;
  gap: 0.2rem;
  min-width: 0;
}

.browse-item-name {
  color: #f8fafc;
  font-weight: 600;
}

.browse-item-path {
  color: #94a3b8;
  font-size: 0.78rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.browse-badge {
  border-radius: 999px;
  background: rgba(16, 185, 129, 0.18);
  color: #6ee7b7;
  flex-shrink: 0;
  font-size: 0.72rem;
  font-weight: 700;
  padding: 0.15rem 0.45rem;
}

.browse-empty {
  color: #94a3b8;
  margin: 0;
  padding: 0.5rem 0;
}

/* Chat bubbles */

.chat-row {
  display: flex;
  max-width: 100%;
  min-width: 0;
  width: 100%;
}

.chat-left {
  justify-content: flex-start;
}

.chat-right {
  justify-content: flex-end;
}

.chat-col {
  display: flex;
  flex-direction: column;
  max-width: min(85%, 36rem);
  min-width: 0;
  width: fit-content;
}

.chat-right .chat-col {
  align-items: flex-end;
}

.chat-bubble {
  max-width: 100%;
  min-width: 0;
  overflow-wrap: anywhere;
  padding: 0.55rem 0.85rem 0.65rem;
  border-radius: 1rem;
}

.chat-bubble-assistant {
  background: #1e293b;
  border: 1px solid #334155;
  border-bottom-left-radius: 0.3rem;
  color: #e2e8f0;
}

.chat-bubble-user {
  background: #0369a1;
  border: 1px solid #0ea5e9;
  border-bottom-right-radius: 0.3rem;
  color: #f0f9ff;
}

.chat-meta {
  align-items: center;
  color: #94a3b8;
  display: flex;
  font-size: 0.72rem;
  gap: 0.5rem;
  justify-content: space-between;
  line-height: 1.2;
  margin-bottom: 0.2rem;
  min-width: 0;
}

.chat-meta span,
.chat-thinking summary span,
.chat-tool summary span {
  min-width: 0;
  overflow-wrap: anywhere;
}

.chat-meta time,
.chat-thinking summary time,
.chat-tool summary time {
  flex-shrink: 0;
}

.chat-bubble-user .chat-meta {
  color: #bae6fd;
}

.chat-actions {
  display: flex;
  flex-shrink: 0;
  gap: 0.15rem;
  margin-top: 0.2rem;
}

.chat-right .chat-actions {
  justify-content: flex-end;
}

.chat-copy-btn {
  -webkit-appearance: none;
  appearance: none;
  align-items: center;
  background: transparent;
  border: 0;
  border-radius: 0.5rem;
  color: #64748b;
  cursor: pointer;
  display: inline-flex;
  flex-shrink: 0;
  font-weight: 500;
  height: 2rem;
  justify-content: center;
  line-height: 1;
  min-width: 2rem;
  padding: 0;
  touch-action: manipulation;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  width: 2rem;
}

.chat-copy-btn svg {
  display: block;
  pointer-events: none;
}

.chat-copy-btn:focus-visible {
  background: rgba(148, 163, 184, 0.14);
  color: #e2e8f0;
  outline: 2px solid #38bdf8;
  outline-offset: 1px;
}

@media (hover: hover) {
  .chat-copy-btn:hover {
    background: rgba(148, 163, 184, 0.14);
    color: #e2e8f0;
  }
}

.chat-copy-btn.is-copied,
.chat-copy-btn.is-copied:hover {
  background: transparent;
  color: #4ade80;
}

.chat-thinking {
  background: rgba(15, 23, 42, 0.72);
  border: 1px dashed rgba(148, 163, 184, 0.45);
  border-radius: 1rem;
  color: #cbd5e1;
  max-width: min(85%, 36rem);
  min-width: 0;
  overflow-wrap: anywhere;
  padding: 0.45rem 0.75rem 0.65rem;
}

.chat-thinking summary {
  align-items: center;
  color: #94a3b8;
  cursor: pointer;
  display: flex;
  font-size: 0.78rem;
  gap: 0.5rem;
  justify-content: space-between;
  list-style: none;
  min-width: 0;
  user-select: none;
}

.chat-thinking summary::-webkit-details-marker {
  display: none;
}

.chat-thinking summary::before {
  content: "▸";
  color: #7dd3fc;
  display: inline-block;
  flex-shrink: 0;
  width: 0.9rem;
}

.chat-thinking[open] summary::before {
  content: "▾";
}

.chat-thinking .chat-text {
  border-top: 1px solid rgba(51, 65, 85, 0.8);
  color: #94a3b8;
  font-size: 0.88rem;
  margin-top: 0.45rem;
  padding-top: 0.45rem;
}

.chat-text {
  line-height: 1.5;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.chat-markdown {
  min-width: 0;
  overflow-wrap: anywhere;
  white-space: normal;
}

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

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

.chat-markdown p,
.chat-markdown ul,
.chat-markdown ol,
.chat-markdown pre,
.chat-markdown blockquote,
.chat-markdown table {
  margin: 0.55em 0;
}

.chat-markdown h1,
.chat-markdown h2,
.chat-markdown h3,
.chat-markdown h4 {
  font-size: 1em;
  font-weight: 700;
  line-height: 1.35;
  margin: 0.75em 0 0.35em;
}

.chat-markdown h1 {
  font-size: 1.15em;
}

.chat-markdown h2 {
  font-size: 1.08em;
}

.chat-markdown ul,
.chat-markdown ol {
  padding-left: 1.35rem;
}

.chat-markdown li + li {
  margin-top: 0.2em;
}

.chat-markdown a {
  color: #7dd3fc;
  text-decoration: underline;
  text-underline-offset: 0.12em;
  word-break: break-all;
}

.chat-bubble-user .chat-markdown a {
  color: #e0f2fe;
}

.chat-markdown code {
  background: rgba(2, 6, 23, 0.55);
  border: 1px solid rgba(51, 65, 85, 0.9);
  border-radius: 0.3rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.88em;
  padding: 0.08em 0.3em;
}

.chat-markdown :not(pre) > code {
  overflow-wrap: anywhere;
  white-space: break-spaces;
  word-break: break-all;
}

.chat-markdown pre {
  background: #020617;
  border: 1px solid #1e293b;
  border-radius: 0.65rem;
  max-width: 100%;
  min-width: 0;
  overflow-wrap: normal;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  padding: 0.7rem 0.8rem;
  touch-action: pan-x pan-y;
  -webkit-overflow-scrolling: touch;
}

.chat-markdown pre code {
  background: transparent;
  border: 0;
  border-radius: 0;
  display: block;
  font-size: 0.82em;
  line-height: 1.45;
  overflow-wrap: normal;
  padding: 0;
  white-space: pre;
  word-break: normal;
}

.chat-markdown blockquote {
  border-left: 3px solid #38bdf8;
  color: #cbd5e1;
  margin-left: 0;
  overflow-wrap: anywhere;
  padding-left: 0.75em;
}

.chat-markdown img {
  height: auto;
  max-width: 100%;
}

.chat-markdown table {
  border-collapse: collapse;
  display: block;
  max-width: 100%;
  min-width: 0;
  overflow-x: auto;
}

.chat-markdown th,
.chat-markdown td {
  border: 1px solid #334155;
  overflow-wrap: anywhere;
  padding: 0.35em 0.55em;
  text-align: left;
}

.chat-markdown th {
  background: rgba(15, 23, 42, 0.8);
}

.chat-markdown hr {
  border: 0;
  border-top: 1px solid #334155;
  margin: 0.8em 0;
}

.chat-system {
  align-items: center;
  color: #94a3b8;
  display: flex;
  font-size: 0.78rem;
  gap: 0.5rem;
  justify-content: center;
  max-width: 100%;
  min-width: 0;
  overflow-wrap: anywhere;
  text-align: center;
}

.chat-system span {
  min-width: 0;
}

.chat-system time {
  color: #64748b;
  flex-shrink: 0;
}

.chat-system-error {
  color: #fca5a5;
}

.chat-system-info {
  color: #7dd3fc;
}

/* Jobs */

.job-list {
  display: grid;
  gap: 0.75rem;
  min-width: 0;
}

.job-item {
  border: 1px solid #1e293b;
  border-radius: 1rem;
  cursor: pointer;
  max-width: 100%;
  min-width: 0;
  padding: 0.85rem;
  transition:
    border-color 0.15s ease,
    background 0.15s ease;
}

.job-item:hover,
.job-item.active {
  border-color: rgba(56, 189, 248, 0.45);
  background: rgba(56, 189, 248, 0.04);
}

.job-item-summary {
  min-width: 0;
}

.job-item-summary strong {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 0.28rem 0.25rem;
  margin-bottom: 0.35rem;
  min-width: 0;
}

.job-item-name {
  min-width: 0;
  overflow-wrap: anywhere;
}

.job-item-summary .job-item-prompt,
.job-item-summary .meta {
  overflow-wrap: anywhere;
  word-break: break-word;
}

.job-item .status,
.job-item .mode-badge {
  flex-shrink: 0;
  margin-left: 0;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status {
  border-radius: 999px;
  display: inline-flex;
  font-size: 0.78rem;
  font-weight: 700;
  margin-left: 0.4rem;
  padding: 0.15rem 0.45rem;
}

.status-running,
.status-queued {
  background: #1d4ed8;
  color: #dbeafe;
}

.status-finished {
  background: #047857;
  color: #d1fae5;
}

.status-error,
.status-cancelled {
  background: #b91c1c;
  color: #fee2e2;
}

.mode-badge {
  border-radius: 999px;
  display: inline-flex;
  font-size: 0.72rem;
  font-weight: 700;
  margin-left: 0.35rem;
  padding: 0.12rem 0.4rem;
  vertical-align: middle;
}

.mode-agent {
  background: rgba(56, 189, 248, 0.18);
  color: #7dd3fc;
}

.mode-plan {
  background: rgba(167, 139, 250, 0.18);
  color: #c4b5fd;
}

.mode-scheduled {
  background: rgba(251, 191, 36, 0.16);
  color: #fcd34d;
}

.schedules-panel {
  padding: 0.75rem 0 1rem;
}

.schedule-list {
  display: grid;
  gap: 0.65rem;
}

.schedule-item {
  background: rgba(2, 6, 23, 0.45);
  border: 1px solid #334155;
  border-radius: 0.9rem;
  display: grid;
  gap: 0.45rem;
  padding: 0.85rem 0.95rem;
}

.schedule-item.disabled {
  opacity: 0.72;
}

.schedule-item-top {
  align-items: flex-start;
  display: flex;
  gap: 0.6rem;
  justify-content: space-between;
}

.schedule-item-title {
  display: grid;
  gap: 0.2rem;
  min-width: 0;
}

.schedule-item-title strong {
  color: #f8fafc;
}

.schedule-item-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  justify-content: flex-end;
}

.schedule-item-actions .ghost {
  padding: 0.35rem 0.55rem;
}

.schedule-error {
  color: #fca5a5;
  font-size: 0.8rem;
  margin: 0;
}

.schedule-form-actions {
  display: grid;
  gap: 0.55rem;
}

.model-settings,
.model-params {
  display: grid;
  gap: 0.85rem;
}

.model-params {
  grid-template-columns: repeat(auto-fit, minmax(10.5rem, 1fr));
}

.model-params.compact {
  gap: 0.55rem;
}

.model-badge {
  background: rgba(148, 163, 184, 0.16);
  color: #cbd5e1;
}

.chip-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin: 0.45rem 0 0.15rem;
}

.option-chip {
  background: rgba(15, 23, 42, 0.9);
  border: 1px solid #334155;
  border-radius: 999px;
  color: #cbd5e1;
  font-size: 0.78rem;
  padding: 0.28rem 0.65rem;
}

.option-chip.active {
  background: rgba(248, 113, 113, 0.16);
  border-color: rgba(248, 113, 113, 0.55);
  color: #fecaca;
}

.option-chip[data-extra-project].active {
  background: rgba(56, 189, 248, 0.16);
  border-color: rgba(56, 189, 248, 0.5);
  color: #7dd3fc;
}

.image-attach {
  display: grid;
  gap: 0.45rem;
}

.image-previews {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.image-preview {
  position: relative;
}

.image-preview img,
.chat-images img {
  background: #0f172a;
  border: 1px solid #334155;
  border-radius: 0.7rem;
  display: block;
  height: 4.5rem;
  object-fit: cover;
  width: 4.5rem;
}

.image-preview button {
  background: rgba(15, 23, 42, 0.88);
  border: 0;
  border-radius: 999px;
  color: #e2e8f0;
  font-size: 0.75rem;
  height: 1.25rem;
  line-height: 1;
  padding: 0;
  position: absolute;
  right: -0.35rem;
  top: -0.35rem;
  width: 1.25rem;
}

.chat-images {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-bottom: 0.4rem;
}

.chat-tool {
  background: rgba(15, 23, 42, 0.72);
  border: 1px solid rgba(125, 211, 252, 0.28);
  border-radius: 1rem;
  color: #cbd5e1;
  max-width: min(85%, 36rem);
  min-width: 0;
  overflow-wrap: anywhere;
  padding: 0.45rem 0.75rem 0.65rem;
}

.chat-tool summary {
  align-items: center;
  color: #7dd3fc;
  cursor: pointer;
  display: flex;
  font-size: 0.78rem;
  gap: 0.5rem;
  justify-content: space-between;
  list-style: none;
  min-width: 0;
  user-select: none;
}

.chat-tool summary::-webkit-details-marker {
  display: none;
}

.chat-tool .chat-text {
  border-top: 1px solid rgba(51, 65, 85, 0.8);
  color: #94a3b8;
  font-size: 0.82rem;
  margin-top: 0.45rem;
  overflow-wrap: anywhere;
  padding-top: 0.45rem;
  white-space: pre-wrap;
}

.chat-system-status {
  color: #94a3b8;
}

.usage-meta {
  color: #94a3b8;
  font-size: 0.78rem;
  margin: 0.35rem 0 0;
}

#newTaskAgentAdvanced[open],
#followUpAgentAdvanced[open] {
  display: grid;
  gap: 0.65rem;
  padding-bottom: 0.75rem;
}

.toast {
  background: #0f172a;
  border: 1px solid #38bdf8;
  border-radius: 0.9rem;
  bottom: calc(1rem + var(--bottom-nav-h) + var(--safe-bottom));
  left: 1rem;
  padding: 0.85rem;
  position: fixed;
  right: 1rem;
  z-index: 50;
}

.shell:has(#appView.in-chat) .toast {
  bottom: calc(1rem + var(--safe-bottom));
}

.shell:has(#appView.in-chat.has-composer) .toast {
  bottom: calc(1rem + var(--composer-h));
}

@media (min-width: 768px) {
  .shell {
    padding: 0 1rem;
  }

  .app-shell {
    border: 1px solid rgba(148, 163, 184, 0.15);
    border-radius: 1.2rem;
    height: calc(100dvh - 2rem);
    margin: 1rem auto;
    max-height: calc(100dvh - 2rem);
    overflow: hidden;
  }

  .bottom-nav {
    left: 50%;
    max-width: 960px;
    transform: translateX(-50%);
  }

  .follow-up-dock {
    left: 50%;
    max-width: 960px;
    transform: translateX(-50%);
  }

  .sheet-panel {
    border-radius: 1.2rem;
    bottom: auto;
    left: 50%;
    max-width: 32rem;
    top: 50%;
    transform: translate(-50%, -50%);
    width: calc(100% - 2rem);
  }

  .overlay-panel.browse-overlay {
    border-radius: 1.2rem;
    bottom: auto;
    left: 50%;
    max-height: 85vh;
    max-width: 40rem;
    top: 50%;
    transform: translate(-50%, -50%);
    width: calc(100% - 2rem);
  }
}

@media (min-width: 900px) {
  .app-body {
    display: grid;
    grid-template-columns: var(--sidebar-w) 1fr;
    min-height: 0;
  }

  .app-shell.in-chat .app-body {
    display: flex;
    grid-template-columns: none;
  }

  .history-aside {
    border-right: 1px solid rgba(148, 163, 184, 0.15);
    display: flex !important;
    max-height: none;
  }

  #appView.in-chat .history-aside {
    display: none !important;
  }

  .history-panel {
    padding-top: 0.75rem;
  }

  #appView.is-wide .bottom-nav {
    grid-template-columns: repeat(3, 1fr);
  }

  #appView.is-wide .bottom-nav .nav-item[data-tab="history"] {
    display: none;
  }

  .tab-panel {
    min-height: 0;
  }

  .chat {
    max-height: none;
  }
}

@media (min-width: 900px) and (orientation: landscape) {
  .app-shell {
    height: 100dvh;
    margin: 0 auto;
    max-height: 100dvh;
  }

  .app-body {
    min-height: 0;
  }
}
