/* ==========================================================================
   AGY·Codex 任务台 — Linear/CodexL-grade Dark-first PWA Stylesheet
   Zero external CDN dependencies. 100% offline / LAN ready.
   ========================================================================== */

:root {
  --font-sans: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB",
    "Noto Sans CJK SC", "Microsoft YaHei", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Monaco, Consolas,
    "Liberation Mono", "Courier New", monospace;

  /* Dark Theme (Default) */
  --bg-canvas: #0b0d12;
  --bg-rail: #10131b;
  --bg-surface: #151923;
  --bg-elevated: #1b202d;
  --bg-hover: #212737;
  --bg-active: rgba(99, 102, 241, 0.14);
  --bg-glass: rgba(16, 19, 27, 0.84);
  --bg-code: #0d1017;
  --bg-code-header: #161b26;
  --bg-input: #0e1118;

  --border-subtle: rgba(255, 255, 255, 0.075);
  --border-default: rgba(255, 255, 255, 0.12);
  --border-strong: rgba(255, 255, 255, 0.22);
  --border-accent: rgba(129, 140, 248, 0.5);

  --text-primary: #f1f5f9;
  --text-secondary: #9aa5b8;
  --text-muted: #647087;
  --text-on-accent: #ffffff;

  --accent: #6366f1;
  --accent-hover: #7577f5;
  --accent-soft: rgba(99, 102, 241, 0.16);
  --accent-text: #a5b4fc;

  --cyan: #38bdf8;
  --cyan-soft: rgba(56, 189, 248, 0.14);

  --emerald: #34d399;
  --emerald-soft: rgba(52, 211, 153, 0.14);

  --violet: #a78bfa;
  --violet-soft: rgba(167, 139, 250, 0.15);

  --amber: #f59e0b;
  --amber-soft: rgba(245, 158, 11, 0.14);
  --amber-border: rgba(245, 158, 11, 0.36);
  --amber-text: #fbbf24;

  --rose: #f87171;
  --rose-soft: rgba(248, 113, 113, 0.14);
  --rose-border: rgba(248, 113, 113, 0.35);

  --slate: #94a3b8;
  --slate-soft: rgba(148, 163, 184, 0.14);

  /* Diff Colors */
  --diff-add-bg: rgba(16, 185, 129, 0.14);
  --diff-add-text: #6ee7b7;
  --diff-del-bg: rgba(239, 68, 68, 0.15);
  --diff-del-text: #fca5a5;
  --diff-hunk-bg: rgba(99, 102, 241, 0.14);
  --diff-hunk-text: #a5b4fc;
  --diff-meta-bg: rgba(255, 255, 255, 0.04);
  --diff-meta-text: #cbd5e1;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.32);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.42);
  --shadow-lg: 0 20px 56px rgba(0, 0, 0, 0.6);

  --radius-xs: 6px;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-pill: 999px;

  --rail-width: 356px;
  --mobile-header-h: 54px;
  --mobile-tabbar-h: 60px;
  --transition-fast: 140ms cubic-bezier(0.2, 0.8, 0.2, 1);
}

[data-theme="light"] {
  --bg-canvas: #f6f8fb;
  --bg-rail: #ffffff;
  --bg-surface: #ffffff;
  --bg-elevated: #f1f5f9;
  --bg-hover: #edf2f7;
  --bg-active: rgba(79, 70, 229, 0.09);
  --bg-glass: rgba(255, 255, 255, 0.88);
  --bg-code: #0f172a;
  --bg-code-header: #1e293b;
  --bg-input: #ffffff;

  --border-subtle: rgba(15, 23, 42, 0.08);
  --border-default: rgba(15, 23, 42, 0.13);
  --border-strong: rgba(15, 23, 42, 0.22);
  --border-accent: rgba(79, 70, 229, 0.45);

  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #64748b;
  --text-on-accent: #ffffff;

  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --accent-soft: rgba(79, 70, 229, 0.1);
  --accent-text: #4338ca;

  --cyan: #0284c7;
  --cyan-soft: rgba(2, 132, 199, 0.11);

  --emerald: #059669;
  --emerald-soft: rgba(5, 150, 105, 0.11);

  --violet: #7c3aed;
  --violet-soft: rgba(124, 58, 237, 0.11);

  --amber: #d97706;
  --amber-soft: rgba(217, 119, 6, 0.1);
  --amber-border: rgba(217, 119, 6, 0.34);
  --amber-text: #b45309;

  --rose: #dc2626;
  --rose-soft: rgba(220, 38, 38, 0.1);
  --rose-border: rgba(220, 38, 38, 0.3);

  --slate: #64748b;
  --slate-soft: rgba(100, 116, 139, 0.12);

  --diff-add-bg: rgba(16, 185, 129, 0.14);
  --diff-add-text: #065f46;
  --diff-del-bg: rgba(239, 68, 68, 0.13);
  --diff-del-text: #991b1b;
  --diff-hunk-bg: rgba(79, 70, 229, 0.1);
  --diff-hunk-text: #3730a3;
  --diff-meta-bg: rgba(15, 23, 42, 0.045);
  --diff-meta-text: #334155;

  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
  --shadow-md: 0 8px 24px rgba(15, 23, 42, 0.1);
  --shadow-lg: 0 20px 56px rgba(15, 23, 42, 0.18);
}

/* Reset & Base */
*, *::before, *::after {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg-canvas);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

body {
  overflow: hidden;
}

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

button {
  cursor: pointer;
  background: none;
  border: none;
  padding: 0;
}

code, pre {
  font-family: var(--font-mono);
}

.hidden {
  display: none !important;
}

/* Scrollbar polish */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: var(--border-default);
  border-radius: 999px;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--border-strong);
}

/* ==========================================================================
   Buttons & Inputs
   ========================================================================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 38px;
  padding: 0 14px;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  font-weight: 500;
  border: 1px solid transparent;
  transition: background var(--transition-fast), border-color var(--transition-fast),
    color var(--transition-fast), transform var(--transition-fast), opacity var(--transition-fast);
  white-space: nowrap;
  user-select: none;
}

.btn:active:not(:disabled) {
  transform: scale(0.985);
}

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

.btn-block {
  width: 100%;
}

.btn-sm {
  min-height: 32px;
  padding: 0 10px;
  font-size: 12.5px;
  border-radius: var(--radius-xs);
}

.btn-primary {
  background: var(--accent);
  color: var(--text-on-accent);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.14) inset, 0 2px 8px rgba(99, 102, 241, 0.28);
}
.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
}

.btn-secondary {
  background: var(--bg-elevated);
  border-color: var(--border-default);
  color: var(--text-primary);
}
.btn-secondary:hover:not(:disabled) {
  background: var(--bg-hover);
  border-color: var(--border-strong);
}

.btn-danger {
  background: #dc2626;
  color: #ffffff;
}
.btn-danger:hover:not(:disabled) {
  background: #b91c1c;
}

.btn-danger-soft {
  background: var(--rose-soft);
  border-color: var(--rose-border);
  color: var(--rose);
}
.btn-danger-soft:hover:not(:disabled) {
  background: rgba(248, 113, 113, 0.22);
}

.btn-ghost-danger {
  color: var(--text-secondary);
  border-color: transparent;
}
.btn-ghost-danger:hover:not(:disabled) {
  background: var(--rose-soft);
  color: var(--rose);
}

.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: var(--radius-xs);
  color: var(--text-secondary);
  border: 1px solid transparent;
  transition: background var(--transition-fast), color var(--transition-fast), border-color var(--transition-fast);
}
.btn-icon:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}
.btn-icon-sm {
  width: 30px;
  height: 30px;
}

.btn-icon-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 32px;
  padding: 0 10px;
  border-radius: var(--radius-pill);
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  color: var(--text-primary);
  font-size: 12.5px;
  font-weight: 500;
  transition: background var(--transition-fast), border-color var(--transition-fast);
}
.btn-icon-pill:hover {
  background: var(--bg-hover);
  border-color: var(--border-default);
}

.input-control,
.textarea-control,
.select-control {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 14px;
  padding: 9px 12px;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
  outline: none;
}

.input-control:focus,
.textarea-control:focus,
.select-control:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.textarea-control {
  resize: vertical;
  min-height: 112px;
  line-height: 1.6;
}

.select-control {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%239aa5b8' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 32px;
}

.select-compact {
  flex: 1;
  min-width: 0;
  height: 30px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-xs);
  color: var(--text-secondary);
  font-size: 12.5px;
  padding: 0 26px 0 9px;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%239aa5b8' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
  outline: none;
}
.select-compact:focus {
  border-color: var(--accent);
  color: var(--text-primary);
}

.field-label {
  display: block;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.field-label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
}
.field-label-row .field-label {
  margin-bottom: 0;
}

.field-optional {
  font-weight: 400;
  color: var(--text-muted);
}

.micro-hint,
.kbd-hint {
  font-size: 11.5px;
  color: var(--text-muted);
}

.form-error {
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  background: var(--rose-soft);
  border: 1px solid var(--rose-border);
  color: var(--rose);
  font-size: 13px;
}

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 20px;
  padding: 0 7px;
  border-radius: var(--radius-pill);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.01em;
  white-space: nowrap;
}
.badge-neutral {
  background: var(--slate-soft);
  color: var(--text-secondary);
}
.badge-git {
  background: var(--emerald-soft);
  color: var(--emerald);
}
.badge-running {
  background: var(--cyan-soft);
  color: var(--cyan);
}
.badge-amber {
  background: var(--amber-soft);
  color: var(--amber-text);
}
.badge-agy {
  background: var(--accent-soft);
  color: var(--accent-text);
}
.badge-codex {
  background: var(--emerald-soft);
  color: var(--emerald);
}
.badge-wt {
  background: var(--violet-soft);
  color: var(--violet);
}

/* ==========================================================================
   Auth Screen
   ========================================================================== */
.auth-screen {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: radial-gradient(circle at 20% 20%, rgba(99, 102, 241, 0.14), transparent 45%),
              radial-gradient(circle at 80% 80%, rgba(6, 182, 212, 0.11), transparent 45%),
              var(--bg-canvas);
}

.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  padding: 28px 24px 24px;
  box-shadow: var(--shadow-lg);
}

.auth-logo {
  display: flex;
  justify-content: center;
  margin-bottom: 14px;
  color: var(--text-primary);
}

.auth-title {
  margin: 0 0 6px;
  text-align: center;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.auth-subtitle {
  margin: 0 0 20px;
  text-align: center;
  font-size: 13px;
  color: var(--text-secondary);
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.auth-hint {
  margin: 16px 0 0;
  font-size: 12px;
  color: var(--text-muted);
  text-align: center;
  line-height: 1.6;
}
.auth-hint code {
  background: var(--bg-elevated);
  padding: 2px 5px;
  border-radius: 4px;
  font-size: 11.5px;
  color: var(--text-secondary);
}

/* ==========================================================================
   App Shell Layout (Desktop >= 900px)
   ========================================================================== */
.app-shell {
  display: grid;
  grid-template-columns: var(--rail-width) minmax(0, 1fr);
  height: 100dvh;
  width: 100%;
  overflow: hidden;
  background: var(--bg-canvas);
}

.mobile-header,
.mobile-tabbar {
  display: none;
}

/* Brand & SSE Indicator */
.brand-wrap {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
}

.brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: 9px;
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.24), rgba(6, 182, 212, 0.16));
  border: 1px solid rgba(129, 140, 248, 0.34);
  color: var(--text-primary);
  flex-shrink: 0;
}

.brand-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.brand-name {
  font-size: 14px;
  font-weight: 700;
  letter-spacing: -0.015em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.sse-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  font-weight: 500;
  color: var(--text-muted);
  padding: 2px 7px;
  border-radius: var(--radius-pill);
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  transition: color var(--transition-fast), border-color var(--transition-fast);
}
.sse-pill-compact {
  background: transparent;
  border: none;
  padding: 0;
  height: auto;
  justify-content: flex-start;
}
.sse-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--amber);
  flex-shrink: 0;
}
.sse-pill[data-state="open"] .sse-dot {
  background: var(--emerald);
  box-shadow: 0 0 0 3px var(--emerald-soft);
}
.sse-pill[data-state="open"] {
  color: var(--emerald);
}
.sse-pill[data-state="connecting"] .sse-dot {
  background: var(--amber);
  animation: pulse-dot 1.4s infinite;
}
.sse-pill[data-state="closed"] .sse-dot {
  background: var(--rose);
}
.sse-pill[data-state="closed"] {
  color: var(--rose);
}

/* ==========================================================================
   Left Rail (Task Board)
   ========================================================================== */
.rail-pane {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
  background: var(--bg-rail);
  border-right: 1px solid var(--border-subtle);
}

.rail-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 13px 14px 10px;
  border-bottom: 1px solid var(--border-subtle);
  flex-shrink: 0;
}

.rail-cta-wrap {
  padding: 12px 14px 8px;
  flex-shrink: 0;
}

.rail-new-btn {
  justify-content: center;
  position: relative;
}

.concurrency-chip {
  margin-left: auto;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: var(--radius-pill);
  background: rgba(255, 255, 255, 0.18);
  color: #ffffff;
}

.rail-filters {
  padding: 6px 14px 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  border-bottom: 1px solid var(--border-subtle);
  flex-shrink: 0;
}

.status-pills {
  display: flex;
  gap: 4px;
  overflow-x: auto;
  scrollbar-width: none;
}
.status-pills::-webkit-scrollbar {
  display: none;
}

.filter-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 27px;
  padding: 0 9px;
  border-radius: var(--radius-pill);
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  background: transparent;
  border: 1px solid transparent;
  white-space: nowrap;
  transition: background var(--transition-fast), color var(--transition-fast), border-color var(--transition-fast);
}
.filter-pill:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}
.filter-pill.active {
  background: var(--accent-soft);
  border-color: var(--border-accent);
  color: var(--accent-text);
}

.pill-count {
  font-family: var(--font-mono);
  font-size: 11px;
  opacity: 0.78;
}

.workspace-filter-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

/* Task Cards List */
.task-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 10px 10px 24px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.task-card {
  display: flex;
  flex-direction: column;
  gap: 7px;
  width: 100%;
  text-align: left;
  padding: 11px 12px;
  border-radius: var(--radius-md);
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  transition: background var(--transition-fast), border-color var(--transition-fast), box-shadow var(--transition-fast);
}
.task-card:hover {
  background: var(--bg-elevated);
  border-color: var(--border-default);
}
.task-card.selected {
  background: var(--bg-active);
  border-color: var(--border-accent);
  box-shadow: var(--shadow-sm);
}

.task-card-top {
  display: flex;
  align-items: flex-start;
  gap: 8px;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-top: 6px;
  flex-shrink: 0;
}
.status-dot.running {
  background: var(--cyan);
  box-shadow: 0 0 0 3px var(--cyan-soft);
  animation: pulse-dot 1.5s infinite;
}
.status-dot.queued {
  background: var(--violet);
  box-shadow: 0 0 0 3px var(--violet-soft);
  animation: pulse-dot 1.8s infinite;
}
.status-dot.completed {
  background: var(--emerald);
}
.status-dot.failed {
  background: var(--rose);
}
.status-dot.canceled {
  background: var(--slate);
}

.task-card-title {
  flex: 1;
  min-width: 0;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text-primary);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  line-height: 1.4;
}

.task-card-time {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
  flex-shrink: 0;
  margin-top: 2px;
}

.task-card-meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 5px;
}

.meta-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  max-width: 100%;
  font-size: 11px;
  color: var(--text-secondary);
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  padding: 1px 6px;
  border-radius: 5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.task-card-live {
  font-size: 12px;
  color: var(--cyan);
  background: var(--cyan-soft);
  border-radius: var(--radius-xs);
  padding: 4px 8px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.task-card-error {
  font-size: 11.5px;
  color: var(--rose);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.task-list-empty {
  padding: 44px 16px;
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
}

/* ==========================================================================
   Main Pane (Right Side)
   ========================================================================== */
.main-pane {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-width: 0;
  min-height: 0;
  background: var(--bg-canvas);
}

/* ==========================================================================
   Compose View
   ========================================================================== */
.compose-view {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 28px 28px 48px;
}

.compose-container {
  max-width: 820px;
  margin: 0 auto;
}

.compose-header {
  margin-bottom: 18px;
}

.compose-title {
  margin: 0 0 4px;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.025em;
}

.compose-subtitle {
  margin: 0;
  font-size: 13.5px;
  color: var(--text-secondary);
}

.compose-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 22px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  box-shadow: var(--shadow-sm);
}

.form-group {
  display: flex;
  flex-direction: column;
}

.form-grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

/* Workspace Picker */
.ws-picker {
  position: relative;
}

.ws-picker-trigger {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: var(--bg-input);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-sm);
  text-align: left;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}
.ws-picker-trigger:hover {
  border-color: var(--border-strong);
}
.ws-picker-trigger[aria-expanded="true"] {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.ws-trigger-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.ws-trigger-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ws-trigger-path {
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ws-trigger-badges {
  display: flex;
  align-items: center;
  gap: 5px;
  flex-shrink: 0;
}

.ws-chevron {
  color: var(--text-muted);
  flex-shrink: 0;
  transition: transform var(--transition-fast);
}
.ws-picker-trigger[aria-expanded="true"] .ws-chevron {
  transform: rotate(180deg);
}

.ws-picker-menu {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  z-index: 40;
  max-height: 290px;
  overflow-y: auto;
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  padding: 6px;
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.ws-option {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  text-align: left;
  transition: background var(--transition-fast);
}
.ws-option:hover {
  background: var(--bg-hover);
}
.ws-option.selected {
  background: var(--bg-active);
}
.ws-option-main {
  min-width: 0;
  flex: 1;
}
.ws-option-name {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ws-option-path {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ws-option-badges {
  display: flex;
  align-items: center;
  gap: 5px;
  flex-shrink: 0;
}

/* Segmented Control */
.segmented-control {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 4px;
  background: var(--bg-input);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-sm);
}

.seg-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 32px;
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  transition: background var(--transition-fast), color var(--transition-fast), box-shadow var(--transition-fast);
}
.seg-btn:hover {
  color: var(--text-primary);
}
.seg-btn.active {
  background: var(--bg-elevated);
  color: var(--text-primary);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border-subtle);
}

.seg-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
}
.seg-dot-agy {
  background: var(--accent);
}
.seg-dot-codex {
  background: var(--emerald);
}

.seg-code {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-muted);
}

/* Mode Pills */
.mode-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.mode-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 32px;
  padding: 0 11px;
  border-radius: var(--radius-pill);
  font-size: 12.5px;
  font-weight: 500;
  background: var(--bg-input);
  border: 1px solid var(--border-default);
  color: var(--text-secondary);
  transition: all var(--transition-fast);
}
.mode-pill:hover {
  border-color: var(--border-strong);
  color: var(--text-primary);
}
.mode-pill.active {
  background: var(--accent-soft);
  border-color: var(--border-accent);
  color: var(--accent-text);
}
.mode-pill-sub {
  font-size: 11px;
  opacity: 0.75;
}

/* Switches & Toggle */
.switches-stack {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.switch-card {
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  transition: border-color var(--transition-fast);
}
.switch-card.disabled {
  opacity: 0.65;
}
.switch-card.has-warning {
  border-color: var(--amber-border);
}

.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  cursor: pointer;
}
.switch-card.disabled .switch-row {
  cursor: not-allowed;
}

.switch-info {
  min-width: 0;
  flex: 1;
}

.switch-title-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 7px;
}

.switch-title {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text-primary);
}

.switch-desc {
  margin: 3px 0 0;
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.45;
}

.toggle-wrap {
  position: relative;
  width: 44px;
  height: 24px;
  flex-shrink: 0;
}

.toggle-input {
  position: absolute;
  opacity: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  cursor: pointer;
  z-index: 2;
}
.toggle-input:disabled {
  cursor: not-allowed;
}

.toggle-track {
  position: absolute;
  inset: 0;
  border-radius: var(--radius-pill);
  background: var(--bg-hover);
  border: 1px solid var(--border-default);
  transition: background var(--transition-fast), border-color var(--transition-fast);
}
.toggle-track::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #ffffff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.35);
  transition: transform var(--transition-fast);
}

.toggle-input:checked + .toggle-track {
  background: var(--accent);
  border-color: var(--accent);
}
.toggle-input:checked + .toggle-track::after {
  transform: translateX(20px);
}
.toggle-input:focus-visible + .toggle-track {
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.amber-banner {
  margin-top: 10px;
  padding: 9px 11px;
  border-radius: var(--radius-sm);
  background: var(--amber-soft);
  border: 1px solid var(--amber-border);
  color: var(--amber-text);
  font-size: 12.5px;
  display: flex;
  align-items: flex-start;
  gap: 8px;
  line-height: 1.45;
}
.amber-banner svg {
  flex-shrink: 0;
  margin-top: 1px;
}

.compose-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  padding-top: 4px;
}

/* ==========================================================================
   Task Detail Thread View
   ========================================================================== */
.detail-view {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.detail-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.detail-header {
  padding: 14px 22px 12px;
  background: var(--bg-glass);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  gap: 10px;
  flex-shrink: 0;
}

.detail-header-top {
  display: flex;
  align-items: flex-start;
  gap: 10px;
}

.detail-back-btn {
  display: none;
  flex-shrink: 0;
  margin-top: -2px;
}

.detail-title-wrap {
  flex: 1;
  min-width: 0;
}

.detail-title-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.detail-title {
  margin: 0;
  font-size: 16.5px;
  font-weight: 700;
  letter-spacing: -0.015em;
  line-height: 1.35;
  word-break: break-word;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 23px;
  padding: 0 9px;
  border-radius: var(--radius-pill);
  font-size: 11.5px;
  font-weight: 600;
  flex-shrink: 0;
}
.status-badge.running {
  background: var(--cyan-soft);
  color: var(--cyan);
}
.status-badge.queued {
  background: var(--violet-soft);
  color: var(--violet);
}
.status-badge.completed {
  background: var(--emerald-soft);
  color: var(--emerald);
}
.status-badge.failed {
  background: var(--rose-soft);
  color: var(--rose);
}
.status-badge.canceled {
  background: var(--slate-soft);
  color: var(--slate);
}

.status-badge .badge-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
}
.status-badge.running .badge-dot,
.status-badge.queued .badge-dot {
  animation: pulse-dot 1.4s infinite;
}

.detail-meta-strip {
  margin-top: 6px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

.detail-action-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 7px;
}

/* Thread Scroll Area */
.thread-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 20px 22px 28px;
  scroll-behavior: smooth;
}

.thread-messages {
  max-width: 880px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.msg-card {
  border-radius: var(--radius-md);
  padding: 14px 16px;
  border: 1px solid var(--border-subtle);
  background: var(--bg-surface);
}

.msg-user {
  background: var(--bg-active);
  border-color: var(--border-accent);
  margin-left: 36px;
}

.msg-system {
  background: var(--bg-elevated);
  border-style: dashed;
  font-size: 13px;
  color: var(--text-secondary);
}

.msg-live {
  border-color: rgba(56, 189, 248, 0.38);
  box-shadow: 0 0 0 1px rgba(56, 189, 248, 0.12);
}

.msg-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

.msg-role-tag {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-secondary);
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.msg-user .msg-role-tag {
  color: var(--accent-text);
}

.msg-time {
  font-size: 11.5px;
  color: var(--text-muted);
}

.msg-live-tag {
  font-size: 11px;
  font-weight: 600;
  color: var(--cyan);
  background: var(--cyan-soft);
  padding: 2px 7px;
  border-radius: var(--radius-pill);
}

.msg-user-text {
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 14px;
  line-height: 1.6;
}

.msg-footer {
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px solid var(--border-subtle);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  font-size: 11.5px;
  color: var(--text-muted);
  font-family: var(--font-mono);
}

.msg-error-banner,
.error-callout {
  margin-top: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--rose-soft);
  border: 1px solid var(--rose-border);
  color: var(--rose);
  font-size: 13px;
  white-space: pre-wrap;
  word-break: break-word;
}
.error-callout {
  max-width: 880px;
  margin: 14px auto 0;
}

/* Live Stream Region */
.live-stream-region {
  max-width: 880px;
  margin: 14px auto 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.live-status-bar {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  align-self: flex-start;
  padding: 7px 13px;
  border-radius: var(--radius-pill);
  background: var(--cyan-soft);
  border: 1px solid rgba(56, 189, 248, 0.28);
  color: var(--cyan);
  font-size: 12.5px;
  font-weight: 500;
}

.pulse-ring {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--cyan);
  box-shadow: 0 0 0 0 rgba(56, 189, 248, 0.65);
  animation: pulse-ring 1.5s infinite;
  flex-shrink: 0;
}

.typing-cursor {
  display: inline-block;
  width: 7px;
  height: 15px;
  margin-left: 2px;
  vertical-align: -2px;
  background: var(--cyan);
  border-radius: 1px;
  animation: blink 1s steps(1) infinite;
}

/* Follow-up Bar */
.followup-bar {
  padding: 12px 22px 14px;
  background: var(--bg-rail);
  border-top: 1px solid var(--border-subtle);
  flex-shrink: 0;
}

.followup-input-row {
  max-width: 880px;
  margin: 0 auto;
  display: flex;
  align-items: flex-end;
  gap: 9px;
}

.followup-textarea {
  flex: 1;
  min-height: 42px;
  max-height: 160px;
  resize: none;
  background: var(--bg-input);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  font-size: 14px;
  line-height: 1.5;
  outline: none;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}
.followup-textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.followup-send-btn {
  min-height: 42px;
  padding: 0 16px;
  flex-shrink: 0;
}

.followup-footer {
  max-width: 880px;
  margin: 7px auto 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.inline-check {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-secondary);
  cursor: pointer;
  user-select: none;
}
.inline-check input {
  accent-color: var(--accent);
  width: 15px;
  height: 15px;
  cursor: pointer;
}

.followup-hint {
  font-size: 11.5px;
  color: var(--text-muted);
}

/* ==========================================================================
   Markdown Body Styling
   ========================================================================== */
.markdown-body {
  font-size: 14px;
  line-height: 1.65;
  word-break: break-word;
  color: var(--text-primary);
}
.markdown-body > *:first-child {
  margin-top: 0;
}
.markdown-body > *:last-child {
  margin-bottom: 0;
}

.markdown-body h1,
.markdown-body h2,
.markdown-body h3,
.markdown-body h4 {
  margin: 16px 0 8px;
  font-weight: 700;
  line-height: 1.35;
  letter-spacing: -0.015em;
}
.markdown-body h1 { font-size: 18px; }
.markdown-body h2 { font-size: 16px; }
.markdown-body h3 { font-size: 14.5px; }
.markdown-body h4 { font-size: 14px; }

.markdown-body p {
  margin: 0 0 10px;
}

.markdown-body ul,
.markdown-body ol {
  margin: 0 0 10px;
  padding-left: 22px;
}
.markdown-body li {
  margin: 3px 0;
}

.markdown-body blockquote {
  margin: 10px 0;
  padding: 6px 12px;
  border-left: 3px solid var(--accent);
  background: var(--bg-elevated);
  border-radius: 0 var(--radius-xs) var(--radius-xs) 0;
  color: var(--text-secondary);
}

.markdown-body hr {
  border: none;
  border-top: 1px solid var(--border-default);
  margin: 14px 0;
}

.markdown-body a {
  color: var(--cyan);
  text-decoration: underline;
  text-underline-offset: 2px;
}
.markdown-body a:hover {
  opacity: 0.85;
}

.markdown-body code.inline-code {
  font-size: 0.88em;
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  padding: 1px 5px;
  border-radius: 5px;
  color: var(--accent-text);
}

/* Fenced Code Block */
.code-block {
  margin: 10px 0;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--border-default);
  background: var(--bg-code);
  color: #e2e8f0;
}

.code-block-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 10px;
  background: var(--bg-code-header);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  font-size: 11.5px;
}

.code-lang {
  font-family: var(--font-mono);
  color: #94a3b8;
  text-transform: lowercase;
}

.code-copy-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 5px;
  font-size: 11.5px;
  color: #cbd5e1;
  background: rgba(255, 255, 255, 0.07);
  transition: background var(--transition-fast), color var(--transition-fast);
}
.code-copy-btn:hover {
  background: rgba(255, 255, 255, 0.14);
  color: #ffffff;
}
.code-copy-btn.copied {
  color: #34d399;
  background: rgba(52, 211, 153, 0.16);
}

.code-block pre {
  margin: 0;
  padding: 12px 14px;
  overflow-x: auto;
  font-size: 12.5px;
  line-height: 1.55;
  tab-size: 2;
}

/* Markdown Tables */
.md-table-wrap {
  margin: 10px 0;
  overflow-x: auto;
  border: 1px solid var(--border-default);
  border-radius: var(--radius-sm);
}
.md-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.md-table th,
.md-table td {
  padding: 7px 10px;
  border-bottom: 1px solid var(--border-subtle);
  text-align: left;
}
.md-table th {
  background: var(--bg-elevated);
  font-weight: 600;
  color: var(--text-secondary);
}
.md-table tr:last-child td {
  border-bottom: none;
}

/* Multi-Image Thumbnail Grid & Lightbox Gallery */
.md-gallery {
  margin: 12px 0 4px;
  padding: 10px;
  border-radius: var(--radius-sm);
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
}
.md-gallery-header {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 8px;
}
.md-gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(104px, 1fr));
  gap: 8px;
}
.md-gallery-tile {
  position: relative;
  aspect-ratio: 1 / 1;
  padding: 0;
  border: 1px solid var(--border-default);
  border-radius: var(--radius-xs);
  overflow: hidden;
  background: var(--bg-input);
  cursor: pointer;
  transition: transform 120ms ease, border-color 120ms ease;
}
.md-gallery-tile:hover {
  transform: translateY(-1px);
  border-color: var(--accent);
}
.md-gallery-tile img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.md-gallery-badge {
  position: absolute;
  right: 5px;
  bottom: 5px;
  padding: 1px 6px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  background: rgba(11, 13, 18, 0.72);
  color: #f8fafc;
}

.lightbox-backdrop {
  position: fixed;
  inset: 0;
  z-index: 120;
  background: rgba(4, 6, 12, 0.92);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 14px 18px;
}
.lightbox-backdrop.hidden {
  display: none;
}
.lightbox-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: #e2e8f0;
  font-size: 13px;
}
.lightbox-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}
.lightbox-btn {
  padding: 5px 12px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: rgba(255, 255, 255, 0.08);
  color: #f8fafc;
  font-size: 13px;
  text-decoration: none;
  cursor: pointer;
}
.lightbox-btn:hover {
  background: rgba(255, 255, 255, 0.18);
}
.lightbox-stage {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 10px 0;
}
.lightbox-img {
  max-width: min(86vw, 1100px);
  max-height: 78dvh;
  object-fit: contain;
  border-radius: 8px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.6);
}
.lightbox-nav {
  width: 40px;
  height: 40px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(255, 255, 255, 0.1);
  color: #ffffff;
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
  flex-shrink: 0;
}
.lightbox-nav:hover {
  background: rgba(255, 255, 255, 0.22);
}
.lightbox-caption {
  text-align: center;
  color: #cbd5e1;
  font-size: 13px;
  min-height: 20px;
}

/* ==========================================================================
   Modals (Diff, Connect/Settings, Confirm)
   ========================================================================== */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 80;
  background: rgba(4, 6, 12, 0.68);
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  animation: fade-in 130ms ease-out;
}

.modal-panel {
  width: 100%;
  max-width: 560px;
  max-height: min(88dvh, 780px);
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: slide-up 160ms cubic-bezier(0.2, 0.8, 0.2, 1);
}

.modal-panel-lg {
  max-width: 920px;
  max-height: 90dvh;
}

.modal-panel-sm {
  max-width: 420px;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border-subtle);
  flex-shrink: 0;
}

.modal-title-group {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  min-width: 0;
}

.modal-title {
  margin: 0;
  font-size: 15.5px;
  font-weight: 700;
}

.modal-header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.modal-body {
  padding: 16px 18px 20px;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}

/* Diff Viewer */
.diff-modal-body {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.diff-status-box {
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
}
.diff-section-label {
  font-size: 11.5px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 6px;
}
.diff-status-pre {
  margin: 0;
  font-size: 12px;
  line-height: 1.5;
  color: var(--text-secondary);
  white-space: pre-wrap;
  overflow-x: auto;
}

.diff-view {
  border: 1px solid var(--border-default);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.55;
}

.diff-line {
  padding: 1px 12px;
  white-space: pre;
  min-width: max-content;
}
.diff-line.add {
  background: var(--diff-add-bg);
  color: var(--diff-add-text);
}
.diff-line.del {
  background: var(--diff-del-bg);
  color: var(--diff-del-text);
}
.diff-line.hunk {
  background: var(--diff-hunk-bg);
  color: var(--diff-hunk-text);
  font-weight: 600;
  padding-top: 3px;
  padding-bottom: 3px;
}
.diff-line.meta {
  background: var(--diff-meta-bg);
  color: var(--diff-meta-text);
  font-weight: 600;
}
.diff-line.ctx {
  color: var(--text-secondary);
}

.loading-box {
  padding: 36px 16px;
  text-align: center;
  color: var(--text-muted);
}

/* Connect & Settings Modal */
.connect-modal-body {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.settings-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.settings-section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.settings-section-head h3 {
  margin: 0;
  font-size: 13.5px;
  font-weight: 700;
}

.settings-help {
  margin: 0;
  font-size: 12.5px;
  color: var(--text-muted);
  line-height: 1.5;
}

.urls-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.url-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
}
.url-row.preferred {
  border-color: var(--border-accent);
  background: var(--bg-active);
}

.url-row-info {
  min-width: 0;
  flex: 1;
}
.url-row-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 2px;
}
.url-row-value {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.notify-test-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
}

.notify-test-result {
  font-size: 12.5px;
  color: var(--text-secondary);
}
.notify-test-result.ok {
  color: var(--emerald);
}
.notify-test-result.fail {
  color: var(--rose);
}

.settings-footer-section {
  padding-top: 12px;
  border-top: 1px solid var(--border-subtle);
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
}

.sys-info {
  font-size: 12px;
  color: var(--text-muted);
}

/* Confirm Modal */
.confirm-message {
  margin: 0 0 18px;
  font-size: 14px;
  color: var(--text-secondary);
  line-height: 1.55;
}

.confirm-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

/* Empty State */
.empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 36px 24px;
  color: var(--text-secondary);
}
.empty-icon {
  width: 56px;
  height: 56px;
  border-radius: 16px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  margin-bottom: 14px;
}
.empty-state h2 {
  margin: 0 0 6px;
  font-size: 16px;
  color: var(--text-primary);
}
.empty-state p {
  margin: 0 0 18px;
  max-width: 320px;
  font-size: 13px;
  color: var(--text-muted);
}
.empty-actions {
  display: flex;
  gap: 10px;
}

/* ==========================================================================
   Toasts
   ========================================================================== */
.toast-container {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: min(360px, calc(100vw - 32px));
  pointer-events: none;
}

.toast {
  pointer-events: auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 13px;
  border-radius: var(--radius-md);
  background: var(--bg-elevated);
  border: 1px solid var(--border-default);
  color: var(--text-primary);
  font-size: 13px;
  box-shadow: var(--shadow-md);
  animation: slide-up 180ms cubic-bezier(0.2, 0.8, 0.2, 1);
}
.toast.success {
  border-color: rgba(52, 211, 153, 0.4);
}
.toast.error {
  border-color: var(--rose-border);
  color: var(--rose);
}
.toast-action {
  color: var(--accent-text);
  font-weight: 600;
  font-size: 12.5px;
  padding: 3px 6px;
  border-radius: 5px;
  flex-shrink: 0;
}
.toast-action:hover {
  background: var(--accent-soft);
}

/* ==========================================================================
   Animations
   ========================================================================== */
@keyframes pulse-dot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.55; transform: scale(0.92); }
}

@keyframes pulse-ring {
  0% { box-shadow: 0 0 0 0 rgba(56, 189, 248, 0.65); }
  70% { box-shadow: 0 0 0 8px rgba(56, 189, 248, 0); }
  100% { box-shadow: 0 0 0 0 rgba(56, 189, 248, 0); }
}

@keyframes blink {
  0%, 49% { opacity: 1; }
  50%, 100% { opacity: 0; }
}

@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes slide-up {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ==========================================================================
   Mobile Layout (< 900px)
   ========================================================================== */
@media (max-width: 899px) {
  .app-shell {
    display: flex;
    flex-direction: column;
    height: 100dvh;
  }

  .mobile-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: calc(8px + env(safe-area-inset-top, 0px)) 14px 8px;
    min-height: calc(var(--mobile-header-h) + env(safe-area-inset-top, 0px));
    background: var(--bg-glass);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    border-bottom: 1px solid var(--border-subtle);
    flex-shrink: 0;
    z-index: 20;
  }

  .rail-header,
  .rail-cta-wrap {
    display: none;
  }

  .rail-pane,
  .main-pane {
    flex: 1;
    min-height: 0;
    width: 100%;
    border-right: none;
  }

  /* Switch visible pane via data-mobile-tab on #app-shell */
  .app-shell[data-mobile-tab="tasks"] .rail-pane {
    display: flex;
  }
  .app-shell[data-mobile-tab="tasks"] .main-pane {
    display: none;
  }
  .app-shell[data-mobile-tab="compose"] .rail-pane,
  .app-shell[data-mobile-tab="detail"] .rail-pane {
    display: none;
  }
  .app-shell[data-mobile-tab="compose"] .main-pane,
  .app-shell[data-mobile-tab="detail"] .main-pane {
    display: flex;
  }

  .detail-back-btn {
    display: inline-flex;
  }

  /* Bottom Tab Bar */
  .mobile-tabbar {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    padding: 4px 8px calc(6px + env(safe-area-inset-bottom, 0px));
    min-height: calc(var(--mobile-tabbar-h) + env(safe-area-inset-bottom, 0px));
    background: var(--bg-glass);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-top: 1px solid var(--border-subtle);
    flex-shrink: 0;
    z-index: 25;
  }

  .tab-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    min-height: 46px;
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    transition: color var(--transition-fast), background var(--transition-fast);
  }
  .tab-btn.active {
    color: var(--accent-text);
    background: var(--accent-soft);
  }

  .tab-icon-wrap {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  .tab-label {
    font-size: 11px;
    font-weight: 600;
  }

  .tab-badge {
    position: absolute;
    top: -5px;
    right: -10px;
    min-width: 17px;
    height: 17px;
    padding: 0 4px;
    border-radius: var(--radius-pill);
    background: var(--cyan);
    color: #06131c;
    font-size: 10px;
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  .tab-dot {
    position: absolute;
    top: -2px;
    right: -4px;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--cyan);
    box-shadow: 0 0 0 2px var(--bg-rail);
  }

  /* Touch Target Sizing (>= 44px) & Prevent iOS Zoom */
  .btn,
  .btn-icon,
  .seg-btn,
  .mode-pill,
  .filter-pill,
  .select-compact,
  .ws-picker-trigger {
    min-height: 44px;
  }
  .btn-icon {
    width: 44px;
    height: 44px;
  }
  .btn-icon-pill {
    min-height: 36px;
  }
  .btn-sm {
    min-height: 38px;
    padding: 0 12px;
  }

  .input-control,
  .textarea-control,
  .select-control,
  .followup-textarea {
    font-size: 16px;
  }

  .compose-view {
    padding: 16px 14px 28px;
  }
  .compose-card {
    padding: 16px;
    gap: 15px;
  }
  .form-grid-2 {
    grid-template-columns: 1fr;
  }
  .compose-actions {
    flex-direction: column-reverse;
  }
  .compose-actions .btn {
    width: 100%;
  }

  .detail-header {
    padding: 10px 14px;
  }
  .thread-scroll {
    padding: 14px 12px 20px;
  }
  .msg-user {
    margin-left: 14px;
  }
  .followup-bar {
    padding: 10px 12px;
  }

  .toast-container {
    right: 12px;
    left: 12px;
    bottom: calc(var(--mobile-tabbar-h) + env(safe-area-inset-bottom, 0px) + 10px);
    max-width: none;
  }

  .hide-xs {
    display: none;
  }
}
