:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --text: #1b1f24;
  --muted: #6b7280;
  --border: #e3e6ea;
  --brand: #247bbf;
  --brand-soft: #e8f2fb;
  --ok: #1e8e5a;
  --warn: #b7791f;
  --error: #c0392b;
  --idle: #9aa0a6;
  --radius: 14px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161a;
    --card: #1d2026;
    --text: #e9ebee;
    --muted: #9aa1aa;
    --border: #2b3038;
    --brand: #5aa7dd;
    --brand-soft: #1b2a38;
    --ok: #47b881;
    --warn: #d9a441;
    --error: #e57373;
    --idle: #7c838b;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}

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

[hidden] { display: none !important; }

/* ---------------------------------------------------------------- login */

.login {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.login-card {
  width: 100%;
  max-width: 360px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 28px 22px 22px;
  text-align: center;
}

.brand-mark {
  width: 56px;
  height: 56px;
  margin: 0 auto 12px;
  border-radius: 16px;
  background: var(--brand) url("/icons/icon-192.png") center / 56px 56px no-repeat;
}

.brand { margin: 0 0 6px; font-size: 22px; font-weight: 650; letter-spacing: .5px; }

.muted { margin: 0 0 18px; color: var(--muted); font-size: 13px; }

.code {
  width: 100%;
  height: 52px;
  padding: 0 12px;
  text-align: center;
  font-size: 26px;
  letter-spacing: 10px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg);
}

.error { min-height: 20px; margin: 10px 0 0; color: var(--error); font-size: 13px; }

.hint { margin: 14px 0 0; color: var(--muted); font-size: 12px; }

.primary {
  height: 44px;
  padding: 0 16px;
  border: 0;
  border-radius: 11px;
  background: var(--brand);
  color: #fff;
  font-weight: 600;
  cursor: pointer;
}

.primary:disabled { opacity: .5; }

.wide { width: 100%; margin-top: 14px; }

/* ------------------------------------------------------------------ app */

.app { padding-bottom: calc(76px + env(safe-area-inset-bottom)); }

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: calc(8px + env(safe-area-inset-top)) 14px 8px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}

.topbar-title { font-weight: 650; font-size: 17px; display: flex; align-items: center; gap: 8px; }

.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--ok); display: inline-block; }
.dot.connecting { background: var(--warn); }
.dot.offline { background: var(--error); }

.topbar-actions { display: flex; gap: 4px; }

.icon {
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  font-size: 19px;
  cursor: pointer;
}

.icon:active { background: var(--border); }

.install-hint {
  margin: 10px 14px 0;
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--brand-soft);
  color: var(--text);
  font-size: 12.5px;
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: space-between;
}

.install-hint button {
  border: 0;
  background: var(--brand);
  color: #fff;
  border-radius: 9px;
  padding: 7px 12px;
  font-size: 12.5px;
  white-space: nowrap;
}

.tabs {
  display: flex;
  gap: 2px;
  overflow-x: auto;
  padding: 8px 10px 4px;
  scrollbar-width: none;
}

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

.tab {
  flex: none;
  height: 34px;
  padding: 0 12px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
  cursor: pointer;
}

.tab.active { background: var(--card); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.06); }

.tab .count { margin-left: 5px; color: var(--muted); font-size: 12px; }

.list { padding: 8px 14px 8px; display: flex; flex-direction: column; gap: 10px; }

.empty {
  margin: 40px 14px;
  padding: 28px 16px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}

/* ---------------------------------------------------------------- card */

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.card-main { display: flex; align-items: flex-start; gap: 10px; padding: 12px; }

.check {
  flex: none;
  width: 24px;
  height: 24px;
  margin-top: 2px;
  border-radius: 7px;
  border: 1.5px solid var(--border);
  background: transparent;
  color: transparent;
  font-size: 14px;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  cursor: pointer;
}

.check.checked { background: var(--ok); border-color: var(--ok); color: #fff; }

.card-body { flex: 1; min-width: 0; }

.card-title {
  display: block;
  width: 100%;
  border: 0;
  background: none;
  padding: 0;
  text-align: left;
  font-size: 15px;
  font-weight: 550;
  line-height: 1.4;
  word-break: break-word;
  cursor: pointer;
}

.card.done .card-title { color: var(--muted); text-decoration: line-through; }

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

.prio { width: 6px; height: 6px; border-radius: 50%; background: var(--brand); flex: none; }
.prio.low { background: var(--idle); }
.prio.high { background: var(--error); }

.pill {
  padding: 1px 8px;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 11.5px;
  white-space: nowrap;
}

.pill.running { border-color: var(--brand); color: var(--brand); }
.pill.review { border-color: var(--warn); color: var(--warn); }
.pill.done { border-color: var(--ok); color: var(--ok); }
.pill.blocked, .pill.cancelled { border-color: var(--error); color: var(--error); }

.time { color: var(--muted); font-size: 11.5px; margin-left: auto; }

.detail {
  border-top: 1px solid var(--border);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: color-mix(in srgb, var(--bg) 55%, var(--card));
}

.field { display: flex; flex-direction: column; gap: 3px; }
.field-label { color: var(--muted); font-size: 11.5px; }
.field-value { white-space: pre-wrap; word-break: break-word; font-size: 13.5px; }

.alert {
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid var(--error);
  color: var(--error);
  font-size: 12.5px;
  white-space: pre-wrap;
  word-break: break-word;
}

.activity { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 5px; }
.activity li { display: flex; gap: 8px; font-size: 12px; color: var(--muted); }
.activity time { flex: none; font-variant-numeric: tabular-nums; }
.activity span { min-width: 0; word-break: break-word; }

.input, .textarea, .select {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  padding: 9px 10px;
  font-size: 14px;
}

.textarea { min-height: 64px; resize: vertical; }

.row { display: flex; gap: 8px; align-items: center; }
.row > .input { flex: 1; }

.actions { display: flex; gap: 8px; flex-wrap: wrap; }

.btn {
  height: 36px;
  padding: 0 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
}

.btn.primary { border: 0; background: var(--brand); color: #fff; }
.btn.danger { color: var(--error); }
.btn:disabled { opacity: .45; }

/* ------------------------------------------------------------ composer */

.composer {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 6;
  display: flex;
  gap: 8px;
  padding: 10px 14px calc(10px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(10px);
  border-top: 1px solid var(--border);
}

.composer-input {
  flex: 1;
  min-width: 0;
  height: 42px;
  border: 1px solid var(--border);
  border-radius: 11px;
  background: var(--card);
  padding: 0 12px;
  font-size: 15px;
}

.composer-add { height: 42px; flex: none; }

/* --------------------------------------------------------------- sheet */

.sheet {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: calc(84px + env(safe-area-inset-bottom));
  z-index: 7;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  overflow: hidden;
  box-shadow: 0 10px 30px rgba(0,0,0,.18);
}

.sheet-item {
  display: block;
  width: 100%;
  height: 50px;
  border: 0;
  border-bottom: 1px solid var(--border);
  background: transparent;
  font-size: 15px;
  color: var(--text);
  cursor: pointer;
}

.sheet-item:last-child { border-bottom: 0; }
.sheet-item.danger { color: var(--error); }

/* --------------------------------------------------------------- toast */

.toast {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(96px + env(safe-area-inset-bottom));
  z-index: 9;
  max-width: calc(100vw - 32px);
  padding: 10px 14px;
  border-radius: 12px;
  background: rgba(20, 22, 26, .92);
  color: #fff;
  font-size: 13px;
  text-align: center;
}

.toast.error { background: rgba(192, 57, 43, .95); }
