@font-face {
  font-family: "Instrument Sans";
  src: url("/assets/fonts/instrument-sans-latin.woff2") format("woff2");
  font-weight: 400 700;
  font-display: swap;
}

@font-face {
  font-family: "IBM Plex Mono";
  src: url("/assets/fonts/ibm-plex-mono-latin-400.woff2") format("woff2");
  font-weight: 400;
  font-display: swap;
}

@font-face {
  font-family: "IBM Plex Mono";
  src: url("/assets/fonts/ibm-plex-mono-latin-500.woff2") format("woff2");
  font-weight: 500;
  font-display: swap;
}

:root {
  color-scheme: light;
  --background: #f5f4f0;
  --surface-1: #ffffff;
  --surface-2: #faf9f6;
  --surface-3: #eceae4;
  --border: #dddad2;
  --border-visible: #b9b5ac;
  --text-1: #191918;
  --text-2: #66635d;
  --text-3: #8a867e;
  --text-4: #b9b5ac;
  --accent: #79b8f3;
  --accent-ink: #0e3658;
  --accent-subtle: #e1f0fd;
  --success: #238a68;
  --success-bg: #edfdf7;
  --warning: #9a651b;
  --warning-bg: #fff8e8;
  --error: #c73e3e;
  --error-bg: #fff0f0;
  --focus-ring: rgba(121, 184, 243, 0.42);
  --overlay: rgba(16, 16, 15, 0.42);
  --font-body: "Instrument Sans", "Microsoft YaHei UI", Inter, system-ui, sans-serif;
  --font-mono: "IBM Plex Mono", Consolas, monospace;
  --shadow-floating: 0 12px 36px rgba(25, 25, 24, 0.1);
  --shadow-sheet: 0 24px 72px rgba(25, 25, 24, 0.18);
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  font-family: var(--font-body);
  background: var(--background);
  color: var(--text-1);
  font-synthesis: none;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
}

button,
input,
textarea {
  font: inherit;
  letter-spacing: 0;
}

button {
  touch-action: manipulation;
}

button svg,
.field-icon svg {
  display: block;
  pointer-events: none;
}

[hidden] {
  display: none !important;
}

:focus-visible {
  outline: 3px solid var(--focus-ring);
  outline-offset: 2px;
}

.login-view {
  display: grid;
  min-height: 100dvh;
  place-items: center;
  padding: 24px;
  background: var(--background);
}

.login-panel {
  width: min(100%, 360px);
  padding: 32px 24px 28px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--surface-1);
  box-shadow: var(--shadow-floating);
}

.brand-mark {
  display: grid;
  width: 44px;
  height: 44px;
  margin-bottom: 24px;
  place-items: center;
  border-radius: 12px;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 20px;
  font-weight: 700;
}

.login-panel h1 {
  margin: 0;
  font-size: 23px;
  line-height: 1.25;
}

.login-panel > p {
  margin: 8px 0 28px;
  color: var(--text-2);
  font-size: 15px;
}

.login-panel label {
  display: block;
  margin-bottom: 8px;
  font-size: 14px;
  font-weight: 600;
}

.login-panel input,
.search-box input,
.composer textarea {
  width: 100%;
  border: 1px solid var(--border-visible);
  border-radius: 12px;
  outline: none;
  background: var(--surface-1);
  color: var(--text-1);
}

.login-panel input {
  min-height: 48px;
  padding: 0 14px;
}

.login-panel input:focus,
.search-box:focus-within,
.composer textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--focus-ring);
}

.primary-button,
.secondary-button,
.danger-button {
  min-height: 48px;
  border-radius: 12px;
  font-weight: 650;
}

.primary-button {
  width: 100%;
  margin-top: 16px;
  border: 0;
  background: var(--accent);
  color: var(--accent-ink);
}

.primary-button:active:not(:disabled) {
  background: #8bc3f5;
}

.primary-button:disabled {
  border: 1px solid var(--border);
  background: var(--surface-3);
  color: var(--text-2);
}

.form-error {
  display: block;
  min-height: 20px;
  margin-top: 12px;
  color: var(--error);
  font-size: 13px;
}

.app-view,
.product-shell {
  width: 100%;
  height: var(--app-height, 100dvh);
  background: var(--background);
}

.product-shell {
  display: grid;
  min-width: 0;
}

.task-view,
.conversation-view {
  min-width: 0;
  min-height: 0;
}

.product-shell[data-mobile-view="conversation"] .task-view,
.product-shell[data-mobile-view="tasks"] .conversation-view {
  display: none;
}

.product-shell[data-mobile-view="tasks"] .task-view {
  display: grid;
}

.conversation-view {
  display: grid;
  height: 100%;
  grid-template-rows: auto minmax(0, 1fr) auto;
  background: var(--background);
}

.task-view {
  height: 100%;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  background: var(--surface-1);
}

.task-view-header,
.topbar {
  z-index: 5;
  display: grid;
  min-height: 64px;
  align-items: center;
  border-bottom: 1px solid var(--border);
  background: var(--surface-1);
}

.task-view-header {
  grid-template-columns: 48px minmax(0, 1fr) 48px;
  gap: 8px;
  padding: max(8px, env(safe-area-inset-top)) 10px 8px;
}

.task-view-header h1 {
  margin: 0;
  font-size: 18px;
  line-height: 1.3;
  text-align: center;
}

.topbar {
  grid-template-columns: 48px minmax(0, 1fr) 48px;
  gap: 8px;
  padding: max(8px, env(safe-area-inset-top)) 10px 8px;
}

.icon-button {
  display: grid;
  width: 48px;
  height: 48px;
  place-items: center;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: var(--text-1);
}

.icon-button:active {
  background: var(--surface-3);
}

.task-heading {
  min-width: 0;
}

.task-heading h1 {
  overflow: hidden;
  margin: 0;
  color: var(--text-1);
  font-size: 15px;
  line-height: 1.35;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.connection-line {
  display: flex;
  min-height: 22px;
  align-items: center;
  gap: 6px;
  color: var(--text-2);
  font-size: 12px;
}

.status-dot {
  width: 8px;
  height: 8px;
  flex: 0 0 auto;
  border: 1px solid var(--text-3);
  border-radius: 50%;
  background: var(--surface-1);
}

.status-dot.online {
  border-color: var(--success);
  background: var(--success);
}

.status-dot.offline {
  border-color: var(--error);
  background: var(--error);
}

.mode-tag {
  display: inline-flex;
  min-height: 22px;
  align-items: center;
  padding: 0 7px;
  border: 1px solid #e6c78f;
  border-radius: 999px;
  background: var(--warning-bg);
  color: var(--warning);
  font-size: 11px;
  font-weight: 600;
}

.mode-tag.control {
  border-color: #b5d8f4;
  background: var(--accent-subtle);
  color: var(--accent-ink);
}

.search-box {
  display: grid;
  min-height: 48px;
  grid-template-columns: 24px minmax(0, 1fr);
  align-items: center;
  gap: 8px;
  margin: 12px 14px 8px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface-2);
  color: var(--text-3);
}

.search-box input {
  min-width: 0;
  min-height: 44px;
  padding: 0;
  border: 0;
  background: transparent;
}

.search-box:focus-within {
  border-color: var(--accent);
}

.search-box input:focus {
  box-shadow: none;
}

.task-list {
  overflow-y: auto;
  min-height: 0;
  padding: 4px 10px max(12px, env(safe-area-inset-bottom));
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.task-item {
  display: block;
  width: 100%;
  min-height: 64px;
  padding: 10px 12px;
  border: 0;
  border-bottom: 1px solid var(--border);
  border-radius: 0;
  background: transparent;
  color: var(--text-1);
  text-align: left;
}

.task-item.active {
  border-bottom-color: transparent;
  border-radius: 12px;
  background: var(--accent-subtle);
  color: var(--accent-ink);
}

.task-item:active:not(.active) {
  background: var(--surface-2);
}

.task-title {
  display: -webkit-box;
  overflow: hidden;
  font-size: 14px;
  font-weight: 600;
  line-height: 1.4;
  overflow-wrap: anywhere;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.task-meta {
  display: block;
  margin-top: 5px;
  color: var(--text-3);
  font-size: 12px;
}

.task-empty {
  display: grid;
  grid-row: 3;
  min-height: 200px;
  place-content: center;
  gap: 12px;
  padding: 24px;
  color: var(--text-2);
  text-align: center;
}

.task-empty p {
  margin: 0;
}

.task-empty button {
  min-width: 128px;
}

.conversation {
  position: relative;
  overflow: auto;
  min-height: 0;
  padding: 16px max(12px, env(safe-area-inset-left)) 24px max(12px, env(safe-area-inset-right));
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.empty-state {
  display: grid;
  min-height: 55vh;
  place-items: center;
  padding: 24px;
  color: var(--text-2);
  text-align: center;
}

.load-older {
  display: block;
  min-width: 148px;
  min-height: 44px;
  margin: 0 auto 20px;
  padding: 0 16px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface-1);
  color: var(--text-2);
  font-size: 13px;
  font-weight: 600;
}

.turns {
  width: min(100%, 780px);
  margin: 0 auto;
}

.turn {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 22px;
}

.message {
  max-width: min(88%, 680px);
}

.message.user {
  align-self: flex-end;
}

.message.assistant {
  align-self: flex-start;
}

.message-label {
  margin: 0 5px 5px;
  color: var(--text-3);
  font-size: 11px;
  font-weight: 600;
}

.message.user .message-label {
  text-align: right;
}

.message pre {
  overflow-wrap: anywhere;
  margin: 0;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--surface-2);
  color: var(--text-1);
  font-family: inherit;
  font-size: 14px;
  line-height: 1.58;
  white-space: pre-wrap;
  word-break: break-word;
}

.message.user pre {
  border-color: #c6e3fb;
  background: var(--accent-subtle);
  color: var(--accent-ink);
}

.message.assistant.commentary pre {
  border-color: var(--accent);
}

.new-message-button {
  position: sticky;
  bottom: 8px;
  z-index: 3;
  display: block;
  min-height: 44px;
  margin: 0 auto;
  padding: 0 16px;
  border: 0;
  border-radius: 999px;
  background: var(--text-1);
  color: var(--surface-1);
  box-shadow: var(--shadow-floating);
  font-size: 13px;
  font-weight: 600;
}

.composer {
  z-index: 4;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 48px;
  gap: 8px;
  padding: 8px max(10px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
  border-top: 1px solid var(--border);
  background: var(--surface-1);
}

.approval-reminder,
.action-notice {
  grid-column: 1 / -1;
}

.approval-reminder {
  display: grid;
  min-height: 46px;
  grid-template-columns: 22px minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  border: 1px solid #e6c78f;
  border-radius: 12px;
  background: var(--warning-bg);
  color: var(--warning);
  text-align: left;
}

.approval-reminder-icon {
  display: grid;
  place-items: center;
}

#approvalReminderText {
  overflow-wrap: anywhere;
  font-size: 13px;
  font-weight: 600;
}

.approval-reminder-action {
  font-size: 12px;
  font-weight: 700;
}

.action-notice {
  color: var(--text-2);
  font-size: 12px;
  line-height: 1.4;
}

.action-notice:empty {
  display: none;
}

.action-notice.error {
  color: var(--error);
}

.action-notice.success {
  color: var(--success);
}

.composer textarea {
  min-height: 48px;
  max-height: 120px;
  resize: none;
  padding: 12px 14px;
  line-height: 1.45;
}

.composer textarea:disabled {
  border-color: var(--border);
  background: var(--surface-3);
  color: var(--text-2);
}

.composer-action {
  display: grid;
  width: 48px;
  height: 48px;
  place-items: center;
  border: 0;
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-ink);
  transition: background-color 180ms var(--ease), color 180ms var(--ease);
}

.composer-action[data-action="stop"] {
  background: var(--error);
  color: var(--surface-1);
}

.composer-action:disabled {
  border: 1px solid var(--border);
  background: var(--surface-3);
  color: var(--text-2);
}

.approval-dialog,
.confirm-dialog {
  width: min(100%, 560px);
  max-width: none;
  max-height: 88dvh;
  margin: auto auto 0;
  padding: 0;
  overflow: hidden;
  border: 0;
  border-radius: 24px 24px 0 0;
  background: var(--surface-1);
  color: var(--text-1);
  box-shadow: var(--shadow-sheet);
}

.approval-dialog::backdrop,
.confirm-dialog::backdrop {
  background: var(--overlay);
}

.sheet-shell,
.confirm-dialog form {
  padding: 10px 18px max(18px, env(safe-area-inset-bottom));
}

.sheet-shell {
  display: grid;
  max-height: 88dvh;
  grid-template-rows: auto auto minmax(0, 1fr);
}

.sheet-handle {
  width: 36px;
  height: 4px;
  margin: 0 auto 10px;
  border-radius: 999px;
  background: var(--border);
}

.sheet-header {
  display: grid;
  min-height: 56px;
  grid-template-columns: minmax(0, 1fr) 48px;
  align-items: start;
  gap: 12px;
  border-bottom: 1px solid var(--border);
}

.sheet-header h2,
.confirm-dialog h2 {
  margin: 0;
  font-size: 19px;
  line-height: 1.3;
}

.sheet-header p,
.confirm-dialog p {
  margin: 5px 0 16px;
  color: var(--text-2);
  font-size: 13px;
  line-height: 1.5;
}

.approval-list {
  overflow-y: auto;
  min-height: 0;
  padding: 4px 0;
  overscroll-behavior: contain;
}

.approval-card {
  padding: 16px 0;
  border-bottom: 1px solid var(--border);
}

.approval-card:last-child {
  border-bottom: 0;
}

.approval-card h3 {
  margin: 0 0 6px;
  color: var(--text-1);
  font-size: 15px;
  line-height: 1.4;
}

.approval-meta,
.approval-reason {
  margin: 5px 0;
  color: var(--text-2);
  font-size: 12px;
  line-height: 1.5;
  overflow-wrap: anywhere;
}

.approval-command {
  overflow: auto;
  max-height: 180px;
  margin: 12px 0;
  padding: 11px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface-2);
  color: var(--text-1);
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
  -webkit-overflow-scrolling: touch;
}

.approval-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.approval-actions button {
  min-width: 0;
  min-height: 44px;
  padding: 8px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 650;
  line-height: 1.35;
}

.approve-once {
  border: 1px solid var(--accent);
  background: var(--accent);
  color: var(--accent-ink);
}

.approve-session {
  grid-column: 1 / -1;
  grid-row: 2;
  border: 1px solid var(--border-visible);
  background: var(--surface-1);
  color: var(--text-1);
}

.decline-approval {
  border: 1px solid #efb6b6;
  background: var(--error-bg);
  color: var(--error);
}

.confirm-dialog form {
  padding-top: 10px;
}

.confirm-dialog p {
  margin-top: 8px;
  margin-bottom: 20px;
}

.confirm-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.secondary-button {
  border: 1px solid var(--border-visible);
  background: var(--surface-1);
  color: var(--text-1);
}

.danger-button {
  border: 0;
  background: var(--error);
  color: var(--surface-1);
}

@media (min-width: 640px) {
  .conversation {
    padding-top: 24px;
  }

  .message {
    max-width: min(78%, 680px);
  }
}

@media (min-width: 900px) {
  .product-shell {
    grid-template-columns: minmax(280px, 340px) minmax(0, 1fr);
  }

  .product-shell[data-mobile-view] .task-view,
  .product-shell[data-mobile-view] .conversation-view {
    display: grid;
  }

  .task-view {
    position: static;
    border-right: 1px solid var(--border);
  }

  .conversation-view {
    min-width: 0;
  }

  .mobile-only,
  #menuButton {
    display: none;
  }

  .task-view-header {
    grid-template-columns: minmax(0, 1fr) 48px;
    padding-left: 18px;
  }

  .task-view-header h1 {
    text-align: left;
  }

  .topbar {
    grid-template-columns: minmax(0, 1fr) 48px;
    padding-left: 20px;
  }

  .approval-dialog,
  .confirm-dialog {
    margin: auto max(24px, calc((100vw - 340px - 560px) / 2)) 0 auto;
    border-radius: 24px 24px 0 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
  }
}
