:root {
  --bg: #f8fafc;
  --surface: #ffffff;
  --surface-muted: #f4f7ff;
  --text: #1e293b;
  --muted: #64748b;
  --border: #e2e8f0;
  --accent: #4f6df5;
  --accent-dark: #4058b5;
  --header: #1e293b;
  --success: #166534;
  --success-bg: #dcfce7;
  --warning: #a16207;
  --warning-bg: #fef3c7;
  --danger: #b42318;
  --danger-bg: #fee4e2;
  --info: #1d4ed8;
  --info-bg: #dbeafe;
  --radius-lg: 16px;
  --radius-md: 13px;
  --shadow: 0 14px 34px rgba(15, 23, 42, 0.12);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  color: var(--text);
  background: var(--bg);
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--bg); }
body { min-height: 100vh; margin: 0; background: var(--bg); }
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: wait; opacity: 0.62; }
[hidden] { display: none !important; }

.app-shell { width: min(100%, 720px); min-height: 100vh; margin: 0 auto; background: var(--bg); }
.dashboard-view { min-height: 100vh; padding-bottom: calc(86px + env(safe-area-inset-bottom)); }
.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 20px;
  padding: calc(22px + env(safe-area-inset-top)) 20px 20px;
  color: white;
  background: linear-gradient(135deg, var(--header), var(--accent-dark));
}
.app-header h1 { margin: 0 0 5px; font-size: 24px; line-height: 1.2; letter-spacing: -0.02em; }
.host-state { display: flex; align-items: center; gap: 7px; margin: 0; color: #dbeafe; font-size: 13px; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: #86efac; box-shadow: 0 0 0 3px rgba(134, 239, 172, 0.16); }
.status-dot.offline { background: #fca5a5; box-shadow: 0 0 0 3px rgba(252, 165, 165, 0.15); }
.header-button { min-height: 44px; padding: 0 14px; border: 1px solid rgba(255, 255, 255, 0.28); border-radius: 11px; color: white; background: rgba(255, 255, 255, 0.1); font-weight: 700; font-size: 14px; }

.main-content { padding: 16px 14px 24px; }
.surface { border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--surface); box-shadow: 0 4px 14px rgba(15, 23, 42, 0.04); }
.quick-task { padding: 16px; }
.section-heading { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 13px; }
.section-heading h2, .section-heading h3, .page-heading h2 { margin: 0 0 4px; line-height: 1.25; color: var(--text); }
.section-heading h2, .page-heading h2 { font-size: 18px; }
.section-heading h3 { font-size: 16px; }
.section-heading p, .page-heading p { margin: 0; color: var(--muted); font-size: 12px; line-height: 1.5; }
.page-heading { padding: 4px 2px 14px; }
.section-block { padding-top: 17px; }

.stack-form, .task-form { display: grid; gap: 9px; }
.task-options { display: grid; gap: 9px; padding-top: 4px; }
.stack-form label, .task-form > label, .mode-fieldset legend { color: #334155; font-size: 13px; font-weight: 700; }
input, textarea, select {
  width: 100%;
  min-height: 46px;
  padding: 11px 12px;
  border: 1px solid #dbe3f2;
  border-radius: 11px;
  color: var(--text);
  background: white;
  font-size: 15px;
  outline: none;
  transition: border-color 150ms ease, box-shadow 150ms ease;
}
textarea { min-height: 70px; resize: vertical; line-height: 1.55; }
input:focus, textarea:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(79, 109, 245, 0.14); }
.mode-fieldset { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 3px 0 2px; padding: 0; border: 0; }
.mode-fieldset legend { grid-column: 1 / -1; margin-bottom: 7px; }
.mode-fieldset label { display: flex; min-height: 44px; align-items: center; gap: 8px; padding: 9px 11px; border: 1px solid var(--border); border-radius: 11px; color: #334155; font-size: 13px; font-weight: 650; }
.mode-fieldset input { width: 18px; min-height: 18px; margin: 0; accent-color: var(--accent); }
.primary-button, .secondary-button, .task-action {
  min-height: 44px;
  border-radius: 11px;
  padding: 10px 14px;
  font-size: 14px;
  font-weight: 750;
}
.primary-button { border: 1px solid var(--accent); color: white; background: var(--accent); }
.secondary-button, .task-action { border: 1px solid var(--border); color: #334155; background: white; }
.danger-text { color: var(--danger); }
.full-width { width: 100%; }

.summary-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 9px; margin: 13px 0 0; }
.summary-card { min-width: 0; padding: 13px 6px 12px; border: 1px solid #e5eaf3; border-radius: 12px; text-align: center; background: white; }
.summary-card strong { display: block; margin-bottom: 2px; color: var(--text); font-size: 23px; line-height: 1.2; }
.summary-card span { color: var(--muted); font-size: 11px; }

.task-list { display: grid; gap: 9px; }
.task-card { padding: 13px; border: 1px solid #e5eaf3; border-radius: var(--radius-md); background: white; }
.task-card-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.task-card h3 { min-width: 0; margin: 0; color: var(--text); font-size: 14px; line-height: 1.45; overflow-wrap: anywhere; }
.task-stage { margin: 8px 0 0; color: var(--muted); font-size: 12px; line-height: 1.5; }
.task-meta { display: flex; flex-wrap: wrap; gap: 7px 12px; margin-top: 8px; color: #94a3b8; font-size: 11px; }
.status-tag { flex: 0 0 auto; padding: 4px 8px; border-radius: 999px; font-size: 10px; font-weight: 750; white-space: nowrap; }
.status-running, .status-queued { color: var(--info); background: var(--info-bg); }
.status-completed { color: var(--success); background: var(--success-bg); }
.status-needs_remote, .status-interrupted { color: var(--warning); background: var(--warning-bg); }
.status-failed, .status-rejected, .status-cancelled { color: var(--danger); background: var(--danger-bg); }
.progress-track { height: 6px; margin-top: 10px; overflow: hidden; border-radius: 6px; background: #e2e8f0; }
.progress-track span { display: block; height: 100%; border-radius: inherit; background: var(--accent); }
.progress-label { margin: 5px 0 0; color: var(--muted); font-size: 11px; }
.task-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 11px; }
.task-action { min-height: 40px; padding: 8px 12px; font-size: 12px; }
.remote-task-note { margin: 9px 0 0; padding: 9px 10px; border-radius: 9px; color: #854d0e; background: #fffbeb; font-size: 12px; line-height: 1.5; }
.empty-state { padding: 24px 16px; border: 1px dashed #cbd5e1; border-radius: var(--radius-md); color: var(--muted); text-align: center; font-size: 13px; background: rgba(255, 255, 255, 0.55); }

.detail-panel { margin-bottom: 12px; padding: 15px; }
.detail-panel h3 { margin: 0 0 7px; font-size: 17px; line-height: 1.45; }
.detail-grid { display: grid; gap: 10px; }
.detail-label { margin: 0 0 3px; color: var(--muted); font-size: 11px; }
.detail-value { margin: 0; color: #334155; font-size: 13px; line-height: 1.55; white-space: pre-wrap; overflow-wrap: anywhere; }
.event-list { display: grid; gap: 7px; margin: 0; padding: 0; list-style: none; }
.event-list li { padding-left: 11px; border-left: 2px solid #c7d2fe; color: #475569; font-size: 12px; line-height: 1.5; }
.result-block { max-height: 340px; margin: 0; overflow: auto; padding: 12px; border-radius: 10px; color: #27354a; background: #f8fafc; font: 12px/1.65 ui-monospace, SFMono-Regular, Menlo, monospace; white-space: pre-wrap; }

.remote-notice { margin-bottom: 12px; padding: 12px 13px; border: 1px solid #fde68a; border-radius: 12px; color: #854d0e; background: #fffbeb; font-size: 13px; line-height: 1.6; }
.settings-section { margin-bottom: 12px; padding: 15px; }
.device-list { display: grid; gap: 8px; }
.device-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 0; border-top: 1px solid #eef2f7; }
.device-row:first-child { border-top: 0; }
.device-row strong { display: block; margin-bottom: 3px; font-size: 13px; }
.device-row span { color: var(--muted); font-size: 11px; }
.device-row button { min-height: 40px; flex: 0 0 auto; }

.bottom-nav {
  position: fixed;
  z-index: 20;
  right: 0;
  bottom: 0;
  left: 0;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  width: min(100%, 720px);
  margin: 0 auto;
  padding: 7px 4px calc(8px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.97);
  box-shadow: 0 -8px 24px rgba(15, 23, 42, 0.06);
  backdrop-filter: blur(12px);
}
.bottom-nav button { display: grid; min-height: 50px; place-items: center; gap: 1px; border: 0; color: var(--muted); background: transparent; font-size: 10px; font-weight: 650; }
.bottom-nav button span { font-size: 17px; line-height: 1; }
.bottom-nav button[aria-current="page"] { color: var(--accent); }

.login-view { display: grid; min-height: 100vh; place-items: center; padding: 28px 18px; background: linear-gradient(160deg, #eef2ff 0%, var(--bg) 55%); }
.login-card { width: min(100%, 420px); padding: 28px 22px 24px; border: 1px solid var(--border); border-radius: 20px; background: white; box-shadow: var(--shadow); }
.brand-mark { display: grid; width: 48px; height: 48px; margin-bottom: 19px; place-items: center; border-radius: 14px; color: white; background: linear-gradient(135deg, var(--header), var(--accent-dark)); font-size: 22px; font-weight: 850; }
.login-card h1 { margin: 0 0 7px; font-size: 24px; letter-spacing: -0.02em; }
.login-copy { margin: 0 0 20px; color: var(--muted); font-size: 14px; }
.form-message { min-height: 20px; margin: 12px 0 0; color: var(--danger); font-size: 13px; line-height: 1.5; }
.security-note { margin: 14px 0 0; padding-top: 13px; border-top: 1px solid #eef2f7; color: var(--muted); font-size: 11px; line-height: 1.6; }
.global-message { margin: 0 0 12px; padding: 10px 12px; border-radius: 10px; color: #334155; background: #eef2ff; font-size: 13px; line-height: 1.5; }
.global-message.error { color: var(--danger); background: var(--danger-bg); }

@media (min-width: 721px) {
  body { padding: 22px 0; }
  .app-shell { min-height: calc(100vh - 44px); overflow: hidden; border: 1px solid var(--border); border-radius: 24px; box-shadow: var(--shadow); }
  .dashboard-view { min-height: calc(100vh - 44px); }
  .bottom-nav { bottom: 22px; border-right: 1px solid var(--border); border-left: 1px solid var(--border); border-radius: 0 0 24px 24px; }
  .main-content { padding: 18px 20px 28px; }
}

@media (max-width: 390px) {
  .mode-fieldset { grid-template-columns: 1fr; }
  .app-header { padding-right: 15px; padding-left: 15px; }
  .main-content { padding-right: 11px; padding-left: 11px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; }
}
