:root {
  color-scheme: dark;
  --bg: #101214;
  --card: #181b1e;
  --card-2: #202428;
  --line: #30353a;
  --text: #f4f1ea;
  --muted: #969da3;
  --accent: #f4b860;
  --green: #53d2a8;
  --blue: #78b8ff;
  --red: #ff807b;
  --radius: 18px;
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--text); }
body { min-height: 100dvh; }
button, textarea, input, select { font: inherit; }
button { color: inherit; }
button:focus-visible, textarea:focus-visible, input:focus-visible, select:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
svg { fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
[hidden] { display: none !important; }

.app-shell { width: min(100%, 760px); min-height: 100dvh; margin: 0 auto; border-inline: 1px solid transparent; }
.topbar { height: 68px; position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 12px; padding: max(10px, env(safe-area-inset-top)) 16px 8px; background: rgba(16,18,20,.96); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; }
.brand-icon, .auth-logo { display: grid; place-items: center; background: var(--accent); color: #211707; font-weight: 900; font-family: ui-monospace, monospace; }
.brand-icon { width: 34px; height: 34px; border-radius: 10px; }
.brand strong { display: block; font-size: 14px; }
.brand small { display: flex; align-items: center; gap: 5px; margin-top: 3px; color: var(--muted); font-size: 9px; }
.brand small i { width: 6px; height: 6px; border-radius: 50%; background: var(--green); }
.brand small i.offline { background: var(--red); }
.new-button { border: 0; background: var(--accent); color: #211707; border-radius: 11px; padding: 9px 12px; font-weight: 800; font-size: 12px; cursor: pointer; }
.back-button, .refresh-button, .close-button { border: 0; background: transparent; cursor: pointer; color: var(--muted); }
.back-button { width: 34px; height: 34px; padding: 6px; }
.back-button svg, .refresh-button svg { width: 22px; height: 22px; }

.screen { display: none; padding-bottom: calc(94px + env(safe-area-inset-bottom)); }
.screen.active { display: block; }
.home-heading, .detail-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 18px; padding: 28px 18px 20px; }
.home-heading h1, .detail-heading h1 { margin: 5px 0 3px; font-size: 30px; letter-spacing: -.04em; }
.home-heading > div > p:last-child { color: var(--muted); font-size: 12px; margin: 0; }
.kicker { margin: 0; color: var(--accent); font: 700 9px/1.2 ui-monospace, monospace; letter-spacing: .15em; }
.refresh-button { padding: 8px; }

.summary-row { margin: 0 16px 16px; display: grid; grid-template-columns: repeat(3, 1fr); border: 1px solid var(--line); border-radius: 14px; overflow: hidden; }
.summary-row div { padding: 13px; border-right: 1px solid var(--line); }
.summary-row div:last-child { border-right: 0; }
.summary-row strong { display: block; font: 750 21px/1 ui-monospace, monospace; }
.summary-row span { display: block; margin-top: 7px; color: var(--muted); font-size: 9px; }

.task-grid { display: grid; gap: 10px; padding: 0 16px; }
.task-card { position: relative; width: 100%; overflow: hidden; border: 1px solid var(--line); background: var(--card); border-radius: var(--radius); }
.task-card:hover { border-color: #4a5056; background: #1b1f22; }
.task-card-open { display: block; width: 100%; border: 0; padding: 16px; text-align: left; background: transparent; cursor: pointer; }
.task-card-top { display: flex; align-items: flex-start; gap: 12px; }
.task-card h2 { flex: 1; margin: 0; font-size: 15px; line-height: 1.45; }
.status-pill { flex: 0 0 auto; border: 1px solid var(--line); border-radius: 999px; padding: 5px 8px; color: var(--muted); font: 700 9px/1 ui-monospace, monospace; }
.status-pill.draft { color: var(--accent); border-color: #665231; }
.status-pill.running { color: var(--blue); border-color: #35577a; }
.status-pill.success { color: var(--green); border-color: #275f50; }
.status-pill.failed { color: var(--red); border-color: #70423f; }
.task-card-meta { display: flex; align-items: center; gap: 8px; margin-top: 13px; color: var(--muted); font-size: 10px; }
.task-card-meta span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.agent-chip { display: flex; align-items: center; gap: 6px; margin-top: 10px; border-top: 1px solid var(--line); padding: 10px 42px 0 0; color: #c5c9cc; font: 9px/1.4 ui-monospace, monospace; }
.agent-chip::before { content: "A"; display: grid; place-items: center; width: 20px; height: 20px; flex: 0 0 20px; border-radius: 6px; background: #30291f; color: var(--accent); font-weight: 800; }
.task-delete-button { position: absolute; right: 10px; bottom: 10px; width: 34px; height: 34px; display: grid; place-items: center; border: 0; border-radius: 10px; background: transparent; color: var(--muted); cursor: pointer; }
.task-delete-button:hover { background: #342326; color: var(--red); }
.task-delete-button:disabled { opacity: .3; cursor: not-allowed; }
.task-delete-button svg { width: 17px; height: 17px; }
.empty-state { border: 1px dashed var(--line); border-radius: var(--radius); padding: 48px 20px; text-align: center; color: var(--muted); }
.empty-state h2 { color: var(--text); font-size: 17px; margin: 0 0 7px; }
.empty-state p { margin: 0 0 18px; font-size: 11px; }

.bottom-nav { position: fixed; z-index: 18; left: 50%; bottom: 0; transform: translateX(-50%); width: min(100%, 760px); display: grid; grid-template-columns: repeat(2, 1fr); padding: 8px 12px calc(8px + env(safe-area-inset-bottom)); background: rgba(16,18,20,.97); border-top: 1px solid var(--line); backdrop-filter: blur(18px); }
.bottom-nav-button { min-height: 48px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; border: 0; border-radius: 13px; background: transparent; color: var(--muted); cursor: pointer; font-size: 9px; font-weight: 700; }
.bottom-nav-button svg { width: 21px; height: 21px; }
.bottom-nav-button.active { background: #29251f; color: var(--accent); }

.resource-heading { padding-bottom: 14px; }
.dashboard-meta { margin: 0 16px 12px; display: flex; align-items: center; justify-content: space-between; gap: 12px; color: var(--muted); font-size: 9px; }
.dashboard-meta span { display: flex; align-items: center; gap: 7px; }
.dashboard-meta b { color: #c7cbce; font-weight: 650; }
.dashboard-meta i { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); }
.dashboard-meta i.online { background: var(--green); box-shadow: 0 0 0 4px rgba(83,210,168,.1); }
.dashboard-meta i.partial { background: var(--accent); box-shadow: 0 0 0 4px rgba(244,184,96,.1); }
.dashboard-meta i.offline { background: var(--red); box-shadow: 0 0 0 4px rgba(255,128,123,.1); }
.resource-summary { margin: 0 16px 14px; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.resource-summary-card { min-width: 0; padding: 13px; border: 1px solid var(--line); border-radius: 14px; background: var(--card); }
.resource-summary-card strong { display: block; font: 750 20px/1 ui-monospace, monospace; }
.resource-summary-card strong em { color: var(--muted); font-size: 11px; font-style: normal; font-weight: 600; }
.resource-summary-card span { display: block; margin-top: 7px; color: var(--muted); font-size: 9px; }
.resource-grid { display: grid; gap: 10px; padding: 0 16px; }
.resource-card { overflow: hidden; border: 1px solid var(--line); border-radius: var(--radius); background: var(--card); }
.resource-card.offline { opacity: .72; }
.resource-card-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 14px 14px 11px; }
.resource-card-title { min-width: 0; }
.resource-card-title h2 { margin: 0; font-size: 14px; line-height: 1.35; }
.resource-card-title p { margin: 5px 0 0; color: var(--muted); font: 9px/1.45 ui-monospace, monospace; overflow-wrap: anywhere; }
.resource-health { flex: 0 0 auto; display: flex; align-items: center; gap: 5px; border: 1px solid #275f50; border-radius: 999px; padding: 5px 7px; color: var(--green); font: 700 8px/1 ui-monospace, monospace; }
.resource-health::before { content: ""; width: 5px; height: 5px; border-radius: 50%; background: currentColor; }
.resource-health.offline { color: var(--red); border-color: #70423f; }
.resource-card-stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); border-block: 1px solid var(--line); }
.resource-stat { min-width: 0; padding: 10px; border-right: 1px solid var(--line); }
.resource-stat:last-child { border-right: 0; }
.resource-stat strong { display: block; overflow: hidden; color: var(--text); font: 700 12px/1.2 ui-monospace, monospace; text-overflow: ellipsis; white-space: nowrap; }
.resource-stat span { display: block; margin-top: 5px; overflow: hidden; color: var(--muted); font-size: 8px; text-overflow: ellipsis; white-space: nowrap; }
.gpu-list, .job-list { display: grid; gap: 8px; padding: 11px 14px 14px; }
.gpu-row { padding: 10px; border-radius: 11px; background: var(--card-2); }
.gpu-row-head, .gpu-row-meta, .job-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.gpu-row-head strong { min-width: 0; overflow: hidden; font-size: 10px; text-overflow: ellipsis; white-space: nowrap; }
.gpu-row-head span { flex: 0 0 auto; color: var(--blue); font: 750 10px/1 ui-monospace, monospace; }
.gpu-row.busy .gpu-row-head span { color: var(--accent); }
.gpu-row-meta { margin-top: 7px; color: var(--muted); font-size: 8px; }
.metric-bar { height: 4px; overflow: hidden; margin-top: 8px; border-radius: 999px; background: #32373c; }
.metric-bar i { display: block; width: var(--value); height: 100%; border-radius: inherit; background: var(--blue); }
.gpu-row.busy .metric-bar i { background: var(--accent); }
.job-list { padding-top: 12px; }
.job-row { padding: 9px 10px; border-radius: 10px; background: var(--card-2); }
.job-copy { min-width: 0; }
.job-copy strong { display: block; overflow: hidden; font-size: 9px; text-overflow: ellipsis; white-space: nowrap; }
.job-copy small { display: block; margin-top: 4px; color: var(--muted); font: 8px/1.3 ui-monospace, monospace; }
.job-state { flex: 0 0 auto; color: var(--blue); font: 700 8px/1 ui-monospace, monospace; }
.job-state.pending { color: var(--accent); }
.resource-note { margin: 0; padding: 3px 14px 14px; color: var(--muted); font-size: 9px; line-height: 1.5; overflow-wrap: anywhere; }
.refresh-button.refreshing svg { animation: resource-spin .8s linear infinite; }
@keyframes resource-spin { to { transform: rotate(360deg); } }

.detail-screen { padding-bottom: calc(104px + env(safe-area-inset-bottom)); }
.detail-heading { align-items: flex-start; padding-bottom: 14px; }
.detail-heading h1 { max-width: 560px; font-size: 23px; line-height: 1.35; }
.detail-heading .kicker { overflow-wrap: anywhere; color: var(--muted); }
.agent-binding-card { margin: 0 16px 12px; display: flex; align-items: center; gap: 12px; padding: 14px; background: var(--card); border: 1px solid #564729; border-radius: var(--radius); }
.agent-avatar { width: 38px; height: 38px; flex: 0 0 38px; display: grid; place-items: center; background: var(--accent); color: #211707; border-radius: 11px; font: 900 14px/1 ui-monospace, monospace; }
.agent-copy { flex: 1; min-width: 0; }
.agent-title { display: flex; align-items: center; gap: 7px; }
.agent-title strong { font-size: 12px; }
.agent-title span { color: var(--green); font-size: 9px; }
.agent-copy code { display: block; margin-top: 4px; color: var(--accent); font-size: 9px; overflow-wrap: anywhere; }
.agent-copy p { margin: 5px 0 0; color: var(--muted); font-size: 9px; }
.lock-icon { width: 19px; height: 19px; color: var(--accent); }
.task-actions { display: flex; gap: 8px; margin: 0 16px 18px; }
.task-actions button { flex: 1; border: 1px solid var(--line); background: var(--card); border-radius: 11px; padding: 10px; font-size: 11px; cursor: pointer; }
.task-actions .primary { border-color: transparent; background: var(--accent); color: #211707; font-weight: 800; }

.conversation, .artifacts { border-top: 1px solid var(--line); padding: 18px 16px 0; }
.section-title { display: flex; justify-content: space-between; align-items: center; margin-bottom: 13px; }
.section-title h2 { margin: 0; font-size: 15px; }
.section-title span { color: var(--muted); font-size: 9px; }
.message-list { display: flex; flex-direction: column; gap: 10px; }
.message { max-width: 88%; }
.message.user { align-self: flex-end; }
.message.agent { align-self: flex-start; }
.message-bubble { border: 1px solid var(--line); background: var(--card); border-radius: 5px 15px 15px; padding: 11px 12px; }
.message.user .message-bubble { background: #30291f; border-color: #594a2f; border-radius: 15px 5px 15px 15px; }
.message p { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; font-size: 12px; line-height: 1.6; }
.message time { display: block; margin-top: 5px; color: var(--muted); font-size: 8px; }
.live-message .message-bubble { min-width: 190px; border-color: #35577a; background: #162433; }
.live-label { display: flex; align-items: center; gap: 7px; color: var(--blue); font-size: 11px; }
.live-label i { width: 7px; height: 7px; border-radius: 50%; background: var(--blue); animation: live-pulse 1.2s ease-in-out infinite; }
.live-message small { display: block; margin-top: 7px; color: var(--muted); font-size: 9px; line-height: 1.45; overflow-wrap: anywhere; }
.live-message p { margin-top: 9px; padding-top: 9px; border-top: 1px solid #29445f; }
@keyframes live-pulse { 50% { opacity: .3; transform: scale(.78); } }
.artifact-list { display: flex; flex-wrap: wrap; gap: 7px; }
.artifact-button { border: 1px solid var(--line); background: var(--card); border-radius: 10px; padding: 8px 10px; font-size: 10px; cursor: pointer; }

.task-composer { position: fixed; z-index: 15; bottom: 0; left: 50%; transform: translateX(-50%); width: min(100%, 760px); display: flex; align-items: flex-end; gap: 8px; padding: 10px 14px calc(10px + env(safe-area-inset-bottom)); background: rgba(16,18,20,.97); border-top: 1px solid var(--line); }
.task-composer textarea { flex: 1; min-height: 40px; max-height: 120px; resize: none; border: 1px solid var(--line); background: var(--card); color: var(--text); border-radius: 13px; padding: 10px 12px; line-height: 1.45; }
.voice-button, .send-button { width: 40px; height: 40px; flex: 0 0 40px; display: grid; place-items: center; border: 0; border-radius: 12px; cursor: pointer; }
.voice-button { background: var(--card-2); color: var(--muted); }
.voice-button.listening { color: var(--red); border: 1px solid #70423f; }
.send-button { background: var(--accent); color: #211707; }
.voice-button svg, .send-button svg { width: 20px; height: 20px; }

.modal-overlay, .auth-overlay { position: fixed; inset: 0; z-index: 100; display: grid; place-items: end center; padding: 16px; background: rgba(0,0,0,.72); }
.modal-card, .auth-card { width: min(100%, 470px); background: var(--card); border: 1px solid var(--line); border-radius: 24px; padding: 22px; }
.modal-header { display: flex; justify-content: space-between; align-items: flex-start; }
.modal-header h2, .auth-card h2 { margin: 5px 0 0; font-size: 22px; }
.close-button { font-size: 26px; line-height: 1; }
.modal-note, .auth-card > p { color: var(--muted); font-size: 11px; line-height: 1.55; }
.modal-card label { display: block; margin: 16px 0 7px; color: var(--muted); font-size: 9px; }
.goal-input { position: relative; }
.goal-input textarea, .modal-card select, .auth-card input { width: 100%; border: 1px solid var(--line); background: var(--bg); color: var(--text); border-radius: 13px; padding: 12px; }
.goal-input textarea { resize: vertical; padding-right: 56px; line-height: 1.55; }
.goal-input .voice-button { position: absolute; right: 8px; bottom: 8px; }
.binding-note { display: flex; gap: 9px; align-items: center; margin-top: 15px; padding: 10px; background: #211d17; border-radius: 11px; }
.binding-note p { margin: 0; color: #d8c39d; font-size: 10px; }
.primary-button { width: 100%; border: 0; background: var(--accent); color: #211707; border-radius: 12px; margin-top: 13px; padding: 12px; font-weight: 800; cursor: pointer; }
.auth-overlay { place-items: center; }
.auth-overlay.hidden { display: none; }
.auth-logo { width: 48px; height: 48px; border-radius: 14px; margin-bottom: 20px; }
.auth-card input { margin-top: 10px; }
.form-error { min-height: 16px; color: var(--red) !important; text-align: center; }
.toast { position: fixed; z-index: 150; left: 50%; bottom: 24px; transform: translate(-50%, 16px); opacity: 0; pointer-events: none; background: var(--text); color: var(--bg); border-radius: 999px; padding: 9px 13px; font-size: 10px; font-weight: 700; transition: .18s ease; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (min-width: 600px) {
  .app-shell { border-color: var(--line); }
  .task-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .resource-summary { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .resource-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .modal-overlay { place-items: center; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; scroll-behavior: auto !important; }
}
