:root {
  color-scheme: dark;
  --bg: #0d0f12;
  --bg-elev: #15181d;
  --bg-elev-2: #1d2127;
  --border: #2a2f37;
  --text: #e6e8eb;
  --text-dim: #8b9099;
  --text-muted: #5d646e;
  --accent: #4f8cff;
  --accent-2: #2563eb;
  --ok: #36c27a;
  --warn: #e0a23a;
  --err: #ef5350;
  --running: #4f8cff;
  --idle: #6b7280;
  --done: #36c27a;
  --failed: #ef5350;
  --cancelled: #e0a23a;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 4px 12px rgba(0, 0, 0, 0.3);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue",
    "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 16px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  min-height: 100dvh;
}

body {
  display: flex;
  flex-direction: column;
}

.topbar {
  position: sticky;
  top: 0;
  background: rgba(13, 15, 18, 0.92);
  backdrop-filter: saturate(180%) blur(14px);
  -webkit-backdrop-filter: saturate(180%) blur(14px);
  border-bottom: 1px solid var(--border);
  padding: env(safe-area-inset-top) 16px 8px;
  z-index: 10;
}

.topbar-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0 4px;
}

.brand {
  font-weight: 600;
  font-size: 17px;
  letter-spacing: 0.02em;
  display: flex;
  align-items: center;
  gap: 8px;
}

.brand-dot {
  width: 10px;
  height: 10px;
  background: var(--accent);
  border-radius: 50%;
  box-shadow: 0 0 12px var(--accent);
}

.icon-btn {
  background: var(--bg-elev);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 999px;
  width: 36px;
  height: 36px;
  font-size: 18px;
  cursor: pointer;
}

.icon-btn:active {
  transform: scale(0.95);
}

.status-line {
  font-size: 12px;
  color: var(--text-dim);
  padding-bottom: 4px;
}

main {
  flex: 1;
  padding: 16px 16px 24px;
  max-width: 720px;
  width: 100%;
  margin: 0 auto;
}

.view.hidden,
.hidden {
  display: none !important;
}

h1 {
  font-size: 22px;
  margin: 12px 0 4px;
}

h2 {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin: 24px 0 10px;
}

.hint,
.muted {
  color: var(--text-dim);
  font-size: 14px;
}

.error {
  color: var(--err);
  margin-top: 12px;
  font-size: 14px;
  white-space: pre-wrap;
}

code {
  background: var(--bg-elev);
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 13px;
  font-family: "SF Mono", ui-monospace, Menlo, Consolas, monospace;
}

.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 14px 0;
}

.field span {
  font-size: 13px;
  color: var(--text-dim);
}

.field input,
.field select,
.field textarea {
  font-family: inherit;
  font-size: 16px;
  background: var(--bg-elev);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  outline: none;
  width: 100%;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  border-color: var(--accent);
}

button {
  font-family: inherit;
}

.primary {
  background: var(--accent);
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  padding: 12px 20px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  width: 100%;
  margin-top: 6px;
}

.primary.big {
  padding: 14px 24px;
  font-size: 16px;
  margin-top: 16px;
}

.primary:active {
  background: var(--accent-2);
}

.primary:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.danger {
  background: transparent;
  color: var(--err);
  border: 1px solid var(--err);
  border-radius: var(--radius-sm);
  padding: 8px 16px;
  font-size: 14px;
  cursor: pointer;
}

.link-btn {
  background: transparent;
  color: var(--accent);
  border: none;
  font-size: 14px;
  padding: 4px 0;
  cursor: pointer;
}

.link-btn.inline {
  font-size: 12px;
  margin-left: 8px;
  padding: 0;
}

/* task list toolbar */
.task-toolbar {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 6px 0 10px;
}

.task-toolbar input[type="search"] {
  font-family: inherit;
  font-size: 14px;
  background: var(--bg-elev);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  outline: none;
  width: 100%;
  -webkit-appearance: none;
  appearance: none;
}

.task-toolbar input[type="search"]:focus {
  border-color: var(--accent);
}

.filter-chips {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 2px;
}

.filter-chips .chip {
  background: var(--bg-elev);
  color: var(--text-dim);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 12px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  text-transform: lowercase;
  letter-spacing: 0.02em;
}

.filter-chips .chip:active {
  transform: scale(0.96);
}

.filter-chips .chip.active {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

/* templates */
.templates {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

.template-card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  text-align: left;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 4px;
  transition: background 0.12s ease, transform 0.05s ease;
  color: var(--text);
}

.template-card:active {
  background: var(--bg-elev-2);
  transform: scale(0.99);
}

.template-card.armed {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(95, 178, 255, 0.25);
  background: var(--bg-elev-2);
}

.template-card .confirm-hint {
  margin-top: 6px;
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
  letter-spacing: 0.02em;
}

.template-card .label {
  font-weight: 600;
  font-size: 15px;
}

.template-card .desc {
  color: var(--text-dim);
  font-size: 13px;
}

.template-card .ws {
  color: var(--text-muted);
  font-size: 12px;
  font-family: "SF Mono", ui-monospace, Menlo, monospace;
}

/* custom form */
.custom-form {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 4px 14px 14px;
  margin-top: 6px;
}

/* task list */
.task-list {
  list-style: none;
  padding: 0;
  margin: 8px 0 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.task-item {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.task-item:active {
  background: var(--bg-elev-2);
}

.task-item .row1 {
  display: flex;
  align-items: center;
  gap: 8px;
}

.task-item .title {
  font-size: 15px;
  font-weight: 500;
  flex: 1;
  word-break: break-word;
}

.task-item .subtitle {
  font-size: 12px;
  color: var(--text-dim);
  margin-top: 2px;
  word-break: break-word;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.mode-pill {
  display: inline-block;
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 4px;
  background: var(--bg-elev-2);
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border: 1px solid var(--border);
}

.task-item .row2 {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-dim);
}

.task-item .row2 .ws {
  font-family: "SF Mono", ui-monospace, Menlo, monospace;
  color: var(--text-muted);
  font-size: 11px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 60%;
}

.task-item .row2 .src {
  color: var(--text-muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.badge {
  display: inline-block;
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 600;
  border: 1px solid var(--border);
  color: var(--text-dim);
  flex-shrink: 0;
}

.badge.running {
  color: white;
  background: var(--running);
  border-color: var(--running);
}

.badge.done {
  color: white;
  background: var(--done);
  border-color: var(--done);
}

.badge.failed {
  color: white;
  background: var(--failed);
  border-color: var(--failed);
}

.badge.cancelled {
  color: white;
  background: var(--cancelled);
  border-color: var(--cancelled);
}

.badge.idle,
.badge.unknown,
.badge.pending {
  color: var(--text);
  background: var(--bg-elev-2);
}

/* detail */
.meta {
  font-size: 13px;
  color: var(--text-dim);
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  margin-bottom: 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.meta .kv {
  display: flex;
  gap: 8px;
}

.meta .kv .k {
  color: var(--text-muted);
  width: 80px;
  flex-shrink: 0;
}

.meta .kv .v {
  flex: 1;
  word-break: break-word;
  font-family: "SF Mono", ui-monospace, Menlo, monospace;
  font-size: 12px;
}

.detail-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 8px;
}

.log-shell {
  position: relative;
}

.log-pane {
  background: #07080a;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
  margin: 0;
  font-family: "SF Mono", ui-monospace, Menlo, Consolas, monospace;
  font-size: 12px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
  overflow-y: auto;
  max-height: calc(100dvh - 280px);
  min-height: 220px;
  -webkit-overflow-scrolling: touch;
}

.scroll-bottom {
  position: absolute;
  right: 12px;
  bottom: 12px;
  background: rgba(79, 140, 255, 0.92);
  color: white;
  border: none;
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: var(--shadow);
  z-index: 5;
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
}

.scroll-bottom:active {
  transform: scale(0.96);
}

.prompt-toggle {
  display: block;
  border-top: 1px dashed var(--border);
  margin-top: 6px;
  padding-top: 6px;
}

.prompt-toggle > summary {
  cursor: pointer;
  color: var(--text-muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.prompt-body {
  margin: 6px 0 0;
  padding: 8px 10px;
  background: var(--bg-elev-2);
  border-radius: 6px;
  font-family: "SF Mono", ui-monospace, Menlo, monospace;
  font-size: 12px;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 240px;
  overflow-y: auto;
}

.log-pretty {
  background: #07080a;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px;
  margin: 0;
  font-size: 13px;
  line-height: 1.5;
  overflow-y: auto;
  max-height: calc(100dvh - 280px);
  min-height: 220px;
  -webkit-overflow-scrolling: touch;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.bubble {
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  font-size: 13px;
  line-height: 1.5;
  word-break: break-word;
  white-space: pre-wrap;
}

.bubble .bubble-head {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 4px;
  font-weight: 600;
}

.bubble.assistant {
  background: #131c2c;
  border-color: #25406b;
}

.bubble.user {
  background: #182018;
  border-color: #2f4d2f;
}

.bubble.thinking,
.bubble.dim {
  background: var(--bg-elev-2);
  color: var(--text-dim);
  font-style: italic;
}

.bubble.result,
.bubble.tool,
.bubble.tool-result {
  font-family: "SF Mono", ui-monospace, Menlo, Consolas, monospace;
  font-size: 12px;
}

.bubble.tool {
  background: #1a1a13;
  border-color: #4a3f1d;
}

.bubble.tool-result {
  background: #131815;
  border-color: #2c4036;
}

.bubble.tool > summary,
.bubble.tool-result > summary {
  cursor: pointer;
  list-style: revert;
  color: var(--text);
}

.bubble .tool-input {
  margin: 6px 0 0;
  padding: 8px;
  background: #07080a;
  border-radius: 6px;
  font-size: 11px;
  color: var(--text-dim);
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 220px;
  overflow-y: auto;
}

.bubble.meta {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 11px;
  font-family: "SF Mono", ui-monospace, Menlo, monospace;
  padding: 2px 4px;
}

.bubble.error {
  background: rgba(239, 83, 80, 0.12);
  border-color: var(--err);
  color: var(--err);
}

.agent-banner {
  margin-top: 6px;
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 12px;
  line-height: 1.45;
  word-break: break-word;
}

.agent-banner.warn {
  background: rgba(224, 162, 58, 0.14);
  border: 1px solid var(--warn);
  color: var(--warn);
}

.agent-banner.info {
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  color: var(--text-dim);
}

/* Folder picker modal */
.fs-modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  z-index: 100;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0;
}

@media (min-width: 600px) {
  .fs-modal {
    align-items: center;
    padding: 32px 16px;
  }
}

.fs-sheet {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius) var(--radius) 0 0;
  width: 100%;
  max-width: 640px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  padding: 12px 14px calc(12px + env(safe-area-inset-bottom));
  gap: 10px;
}

@media (min-width: 600px) {
  .fs-sheet {
    border-radius: var(--radius);
    padding: 16px;
  }
}

.fs-head {
  display: flex;
  align-items: center;
  gap: 8px;
}

.fs-cwd {
  flex: 1;
  font-size: 12px;
  color: var(--text-dim);
  font-family: "SF Mono", ui-monospace, Menlo, monospace;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  direction: rtl;
  text-align: left;
}

.fs-pick-btn {
  width: auto;
  padding: 8px 14px;
  font-size: 13px;
  margin: 0;
}

.fs-shortcuts {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 2px;
}

.fs-shortcut-groups {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 28vh;
  overflow-y: auto;
}

.fs-shortcut-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

.fs-shortcut-label {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 600;
  margin-right: 4px;
  flex-shrink: 0;
}

.fs-shortcut {
  background: var(--bg-elev);
  color: var(--text-dim);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 5px 12px;
  font-size: 12px;
  cursor: pointer;
  white-space: nowrap;
  font-family: inherit;
}

.fs-shortcut:active {
  background: var(--bg-elev-2);
  transform: scale(0.96);
}

.fs-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.fs-toolbar > .link-btn {
  padding: 6px 0;
}

.fs-toggle {
  font-size: 12px;
  color: var(--text-dim);
  display: flex;
  align-items: center;
  gap: 4px;
  margin-left: auto;
}

.fs-mkdir-row {
  display: flex;
  gap: 8px;
  align-items: stretch;
}

.fs-mkdir-row input {
  flex: 1;
  font-family: inherit;
  font-size: 14px;
  background: var(--bg-elev);
  color: var(--text);
  border: 1px solid var(--accent);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
}

.fs-mkdir-btn {
  width: auto;
  padding: 8px 14px;
  font-size: 13px;
  margin: 0;
}

.fs-entries {
  list-style: none;
  padding: 0;
  margin: 0;
  overflow-y: auto;
  flex: 1;
  min-height: 240px;
  max-height: 60vh;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-elev);
  -webkit-overflow-scrolling: touch;
}

.fs-entry {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  font-size: 14px;
  color: var(--text);
}

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

.fs-entry:active {
  background: var(--bg-elev-2);
}

.fs-icon {
  flex-shrink: 0;
}

.fs-name {
  flex: 1;
  word-break: break-word;
}

.fs-empty {
  padding: 12px;
  text-align: center;
  color: var(--text-muted);
  font-size: 12px;
}

.fs-error {
  font-size: 12px;
  margin: 0;
}

/* small picked-path hint under the workspace dropdown */
.picked-path {
  margin-top: 6px;
  padding: 6px 8px;
  background: var(--bg-elev-2);
  border-radius: 6px;
  font-size: 11px;
  color: var(--text-dim);
  word-break: break-all;
}

.mono {
  font-family: "SF Mono", ui-monospace, Menlo, monospace;
}

.bottombar {
  border-top: 1px solid var(--border);
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
  text-align: center;
  font-size: 12px;
  color: var(--text-muted);
  background: var(--bg);
}

.bottombar a {
  color: var(--text-dim);
  text-decoration: none;
}

.bottombar .dot {
  margin: 0 8px;
}

@media (min-width: 600px) {
  .templates {
    grid-template-columns: 1fr 1fr;
  }
}
