:root {
  --bg: #f6f5f1;
  --surface: #ffffff;
  --surface-subtle: #faf9f6;
  --text: #181a1f;
  --text-muted: #5c6370;
  --text-faint: #8c93a0;
  --border: rgba(15, 23, 42, 0.075);
  --border-strong: rgba(15, 23, 42, 0.14);
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.03), 0 10px 26px rgba(15, 23, 42, 0.035);
  --accent: #1f2937;
  --ok-fg: #15803d;
  --ok-bg: #ecf9f1;
  --warn-fg: #b45309;
  --warn-bg: #fff8e6;
  --err-fg: #be123c;
  --err-bg: #fff1f3;
  --run-fg: #3730a3;
  --run-bg: #eef2ff;
  --idle-fg: #475569;
  --idle-bg: #f1f5f9;
  --font-sans: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text", "PingFang SC", "Helvetica Neue", sans-serif;
  --font-mono: ui-monospace, "SF Mono", Menlo, Monaco, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0c0e12;
    --surface: #141820;
    --surface-subtle: #191e28;
    --text: #eceff4;
    --text-muted: #98a2b3;
    --text-faint: #667085;
    --border: rgba(255, 255, 255, 0.075);
    --border-strong: rgba(255, 255, 255, 0.15);
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.25), 0 12px 28px rgba(0, 0, 0, 0.28);
    --accent: #f3f4f6;
    --ok-fg: #34d399;
    --ok-bg: rgba(16, 185, 129, 0.14);
    --warn-fg: #fbbf24;
    --warn-bg: rgba(245, 158, 11, 0.14);
    --err-fg: #fb7185;
    --err-bg: rgba(244, 63, 94, 0.15);
    --run-fg: #a5b4fc;
    --run-bg: rgba(99, 102, 241, 0.16);
    --idle-fg: #94a3b8;
    --idle-bg: rgba(148, 163, 184, 0.13);
  }
}

[data-theme="dark"] {
  --bg: #0c0e12;
  --surface: #141820;
  --surface-subtle: #191e28;
  --text: #eceff4;
  --text-muted: #98a2b3;
  --text-faint: #667085;
  --border: rgba(255, 255, 255, 0.075);
  --border-strong: rgba(255, 255, 255, 0.15);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.25), 0 12px 28px rgba(0, 0, 0, 0.28);
  --accent: #f3f4f6;
  --ok-fg: #34d399;
  --ok-bg: rgba(16, 185, 129, 0.14);
  --warn-fg: #fbbf24;
  --warn-bg: rgba(245, 158, 11, 0.14);
  --err-fg: #fb7185;
  --err-bg: rgba(244, 63, 94, 0.15);
  --run-fg: #a5b4fc;
  --run-bg: rgba(99, 102, 241, 0.16);
  --idle-fg: #94a3b8;
  --idle-bg: rgba(148, 163, 184, 0.13);
}

*, *::before, *::after {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

.page-shell {
  max-width: 1080px;
  margin: 0 auto;
  padding: max(20px, env(safe-area-inset-top)) 16px max(32px, env(safe-area-inset-bottom));
}

@media (min-width: 720px) {
  .page-shell {
    padding: 28px 28px 44px;
  }
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 22px;
}

.brand-group {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.pulse-dot {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  flex-shrink: 0;
}

.dot-ok {
  background: var(--ok-fg);
  box-shadow: 0 0 0 4px var(--ok-bg);
}

.dot-warn {
  background: var(--warn-fg);
  box-shadow: 0 0 0 4px var(--warn-bg);
}

.dot-error {
  background: var(--err-fg);
  box-shadow: 0 0 0 4px var(--err-bg);
}

.dot-running {
  background: var(--run-fg);
  box-shadow: 0 0 0 4px var(--run-bg);
}

.dot-idle, .dot-paused {
  background: var(--text-faint);
  box-shadow: 0 0 0 4px var(--idle-bg);
}

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

.brand-title {
  margin: 0;
  font-size: 20px;
  font-weight: 650;
  letter-spacing: -0.02em;
}

.tag-pill {
  font-size: 11px;
  font-weight: 500;
  padding: 2px 8px;
  border-radius: 999px;
  color: var(--text-muted);
  background: var(--surface);
  border: 1px solid var(--border);
}

.brand-sub {
  margin: 2px 0 0;
  font-size: 12px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

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

.logout-form {
  margin: 0;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 36px;
  padding: 0 11px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 500;
  cursor: pointer;
  transition: border-color 150ms ease, transform 120ms ease, background 150ms ease;
}

.icon-btn:hover {
  border-color: var(--border-strong);
}

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

.icon-btn-muted {
  color: var(--text-muted);
}

.icon-btn.is-spinning svg {
  animation: spin 750ms linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.btn-label {
  display: none;
}

@media (min-width: 540px) {
  .btn-label {
    display: inline;
  }
}

#icon-sun { display: none; }
#icon-moon { display: block; }
[data-theme="dark"] #icon-sun { display: block; }
[data-theme="dark"] #icon-moon { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) #icon-sun { display: block; }
  :root:not([data-theme="light"]) #icon-moon { display: none; }
}

/* KPI Grid */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}

@media (min-width: 820px) {
  .kpi-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 14px;
  }
}

.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 15px 16px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.kpi-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.kpi-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
}

.kpi-value {
  font-size: 22px;
  font-weight: 650;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.kpi-sub {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.status-pill {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
  white-space: nowrap;
  flex-shrink: 0;
}

.pill-ok { color: var(--ok-fg); background: var(--ok-bg); }
.pill-warn { color: var(--warn-fg); background: var(--warn-bg); }
.pill-error { color: var(--err-fg); background: var(--err-bg); }
.pill-running { color: var(--run-fg); background: var(--run-bg); }
.pill-idle, .pill-paused { color: var(--idle-fg); background: var(--idle-bg); }

/* Toolbar */
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.filter-tabs {
  display: flex;
  align-items: center;
  gap: 6px;
  overflow-x: auto;
  max-width: 100%;
  scrollbar-width: none;
  padding-bottom: 2px;
}

.filter-tabs::-webkit-scrollbar {
  display: none;
}

.filter-chip {
  height: 32px;
  padding: 0 13px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
  transition: all 140ms ease;
}

.filter-chip:hover {
  color: var(--text);
  border-color: var(--border-strong);
}

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

.attention-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 32px;
  padding: 0 12px;
  border-radius: 999px;
  border: 1px solid rgba(180, 83, 9, 0.25);
  background: var(--warn-bg);
  color: var(--warn-fg);
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
}

.attention-chip.is-active {
  background: var(--warn-fg);
  color: #ffffff;
}

.mini-badge {
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  padding: 0 5px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.08);
}

/* Task List */
.task-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.task-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
  overflow: hidden;
  transition: border-color 150ms ease;
}

.task-card:hover {
  border-color: var(--border-strong);
}

.task-card.is-paused {
  opacity: 0.72;
}

.task-row {
  width: 100%;
  text-align: left;
  background: transparent;
  border: 0;
  color: inherit;
  font-family: inherit;
  padding: 14px 16px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

@media (min-width: 720px) {
  .task-row {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    padding: 15px 18px;
    gap: 16px;
  }
}

.task-main {
  min-width: 0;
  flex: 1 1 auto;
}

.task-head {
  display: flex;
  align-items: center;
  gap: 9px;
  flex-wrap: wrap;
}

.task-dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  flex-shrink: 0;
}

.task-name {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.task-schedule {
  font-size: 11.5px;
  color: var(--text-muted);
  background: var(--surface-subtle);
  border: 1px solid var(--border);
  padding: 1px 8px;
  border-radius: 999px;
}

.task-summary {
  margin: 5px 0 0 17px;
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.45;
}

.task-right {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-left: 17px;
  flex-shrink: 0;
}

@media (min-width: 720px) {
  .task-right {
    margin-left: 0;
    justify-content: flex-end;
  }
}

.task-times {
  display: flex;
  gap: 14px;
  font-size: 12px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.time-pair {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  min-width: 78px;
}

@media (min-width: 720px) {
  .time-pair {
    align-items: flex-end;
  }
}

.time-k {
  font-size: 10.5px;
  color: var(--text-faint);
}

.time-v {
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--text);
}

.spark-strip {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 3px;
}

@media (min-width: 720px) {
  .spark-strip {
    min-width: 112px;
  }
}

.spark-pill {
  width: 6px;
  height: 14px;
  border-radius: 3px;
  background: var(--idle-bg);
}

.spark-ok { background: var(--ok-fg); opacity: 0.85; }
.spark-warn { background: var(--warn-fg); }
.spark-error { background: var(--err-fg); }
.spark-none { background: var(--border-strong); opacity: 0.5; }

.chevron {
  color: var(--text-faint);
  transition: transform 160ms ease;
  flex-shrink: 0;
}

.task-card.is-open .chevron {
  transform: rotate(180deg);
}

.task-drawer {
  display: none;
  padding: 12px 18px 15px 33px;
  border-top: 1px solid var(--border);
  background: var(--surface-subtle);
}

.task-card.is-open .task-drawer {
  display: block;
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 10px 18px;
}

.detail-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.detail-k {
  font-size: 11px;
  color: var(--text-faint);
}

.detail-v {
  font-size: 12.5px;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  word-break: break-word;
}

/* Daemons */
.daemons-section {
  margin-top: 26px;
}

.section-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 12px;
}

.section-title {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
}

.section-meta {
  font-size: 12px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.daemons-grid {
  display: grid;
  grid-template-columns: repeat(1, minmax(0, 1fr));
  gap: 8px;
}

@media (min-width: 560px) {
  .daemons-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (min-width: 860px) {
  .daemons-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

.daemon-pill {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 13px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.daemon-left {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.daemon-name {
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.daemon-meta {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
}

.empty-state {
  background: var(--surface);
  border: 1px dashed var(--border-strong);
  border-radius: 16px;
  padding: 28px 16px;
  text-align: center;
  color: var(--text-muted);
  font-size: 13.5px;
}

.footer {
  margin-top: 28px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  text-align: center;
  font-size: 11.5px;
  color: var(--text-faint);
}

/* Login */
.login-body {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.login-wrap {
  width: 100%;
  max-width: 376px;
}

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 28px 24px;
  box-shadow: var(--shadow);
}

.login-header {
  text-align: center;
  margin-bottom: 22px;
}

.login-mark {
  width: 42px;
  height: 42px;
  margin: 0 auto 12px;
  border-radius: 14px;
  background: var(--surface-subtle);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
}

.login-title {
  margin: 0;
  font-size: 19px;
  font-weight: 650;
}

.login-sub {
  margin: 4px 0 0;
  font-size: 12.5px;
  color: var(--text-muted);
}

.login-error {
  margin-bottom: 14px;
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 12.5px;
  color: var(--err-fg);
  background: var(--err-bg);
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.field-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
}

.field-input {
  height: 44px;
  padding: 0 13px;
  border-radius: 12px;
  border: 1px solid var(--border-strong);
  background: var(--surface-subtle);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 14px;
  outline: none;
  transition: border-color 140ms ease;
}

.field-input:focus {
  border-color: var(--ok-fg);
}

.primary-btn {
  margin-top: 6px;
  height: 44px;
  border: 0;
  border-radius: 12px;
  background: var(--accent);
  color: var(--surface);
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

.primary-btn:active {
  transform: scale(0.99);
}
