:root {
  --bg: #f3f5fa;
  --card: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --primary: #2563eb;
  --primary-soft: #dbeafe;
  --danger: #dc2626;
  --warn: #d97706;
  --ok: #16a34a;
  --radius: 16px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei",
    "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.5;
}

body { min-height: 100vh; }

.hidden { display: none !important; }
.muted { color: var(--muted); font-weight: 400; font-size: 12px; }
.error { color: var(--danger); font-size: 13px; min-height: 18px; margin: 10px 0 0; }

.app {
  max-width: 560px;
  margin: 0 auto;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ---------- 登录 ---------- */
.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-card {
  width: 100%;
  max-width: 380px;
  padding: 30px 26px 24px;
  text-align: center;
}

.login-card .logo { font-size: 40px; line-height: 1; }
.login-card h1 { margin: 12px 0 4px; font-size: 22px; }
.login-card .muted { margin: 0 0 22px; }

.field {
  display: block;
  text-align: left;
  margin-bottom: 14px;
}

.field span {
  display: block;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 6px;
}

.field input,
textarea,
input[type="datetime-local"] {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 16px;
  font-family: inherit;
  background: #fbfcfe;
  color: var(--text);
  outline: none;
}

.field input:focus,
textarea:focus,
input[type="datetime-local"]:focus {
  border-color: var(--primary);
  background: #fff;
}

/* ---------- 顶栏 ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 18px 10px;
  background: rgba(243, 245, 250, 0.94);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.brand { display: flex; align-items: center; gap: 10px; }
.brand h1 { margin: 0; font-size: 17px; }

.logo.small {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  background: var(--primary);
  font-size: 20px;
}

.device-line {
  margin: 2px 0 0;
  font-size: 12px;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 6px;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #cbd5e1;
  flex: none;
}
.dot.online { background: var(--ok); box-shadow: 0 0 0 3px rgba(22, 163, 74, 0.15); }
.dot.offline { background: #f59e0b; }

.ghost {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--muted);
  border-radius: 999px;
  padding: 7px 14px;
  font-size: 13px;
  font-family: inherit;
}

/* ---------- 主体 ---------- */
.main {
  flex: 1;
  padding: 4px 18px 22px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.06);
}

textarea { resize: vertical; min-height: 104px; line-height: 1.6; }

.counter {
  text-align: right;
  font-size: 12px;
  color: var(--muted);
  margin: 4px 2px 10px;
}

/* ---------- 分段 ---------- */
.seg {
  display: inline-flex;
  background: #eef2f7;
  padding: 4px;
  border-radius: 12px;
  gap: 2px;
  margin: 6px 0 12px;
}

.seg button {
  border: 0;
  background: transparent;
  padding: 8px 16px;
  border-radius: 9px;
  font-size: 15px;
  font-family: inherit;
  color: var(--muted);
  cursor: pointer;
}

.seg button.active {
  background: #fff;
  color: var(--text);
  font-weight: 600;
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.12);
}

.seg button[data-p="important"].active { color: var(--warn); }
.seg button[data-p="urgent"].active { color: var(--danger); }

.seg.wide { display: flex; width: 100%; }
.seg.wide button { flex: 1; }

/* ---------- 开关 ---------- */
.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 2px 0 14px;
  font-size: 15px;
}

.switch { position: relative; flex: none; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }

.switch i {
  display: block;
  width: 52px;
  height: 30px;
  border-radius: 999px;
  background: #cbd5e1;
  transition: background 0.2s;
  position: relative;
}

.switch i::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
  transition: transform 0.2s;
}

.switch input:checked + i { background: var(--primary); }
.switch input:checked + i::after { transform: translateX(22px); }

/* ---------- 定时 ---------- */
.quick {
  display: flex;
  gap: 8px;
  margin-top: 10px;
  flex-wrap: wrap;
}

.quick button {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 999px;
  padding: 7px 14px;
  font-size: 13px;
  color: var(--muted);
  font-family: inherit;
}

.quick button:active { background: var(--primary-soft); color: var(--primary); }

/* ---------- 主按钮 ---------- */
.primary {
  width: 100%;
  border: 0;
  border-radius: 12px;
  padding: 15px;
  font-size: 17px;
  font-weight: 600;
  font-family: inherit;
  color: #fff;
  background: var(--primary);
  cursor: pointer;
  margin-top: 14px;
  transition: transform 0.08s, opacity 0.2s;
}

.primary:active { transform: scale(0.985); }
.primary:disabled { opacity: 0.55; }

/* ---------- 记录 ---------- */
.block h2 {
  font-size: 14px;
  color: var(--muted);
  font-weight: 600;
  margin: 0 0 10px 4px;
}

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

.history .item {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
}

.history .item.active-item {
  border-color: var(--primary);
  background: #f8fbff;
}

.history .row1 {
  display: flex;
  gap: 8px;
  margin-bottom: 4px;
}

.history .text {
  margin: 0;
  font-size: 15px;
  line-height: 1.5;
  word-break: break-word;
}

.history .meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 8px;
  font-size: 12px;
  color: var(--muted);
}

.badge {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  background: #eef2f7;
  color: var(--muted);
}

.badge.important { background: #fef3c7; color: #b45309; }
.badge.urgent { background: #fee2e2; color: #b91c1c; }
.badge.s-active { background: var(--primary-soft); color: var(--primary); }
.badge.s-closed { background: #dcfce7; color: #15803d; }
.badge.s-canceled { background: #f1f5f9; color: #94a3b8; }
.badge.s-failed { background: #fef2f2; color: #b91c1c; }
.badge.s-missed { background: #fef2f2; color: #b91c1c; }

.link-btn {
  border: 0;
  background: transparent;
  color: var(--primary);
  font-family: inherit;
  font-size: 13px;
  padding: 4px 0;
  cursor: pointer;
}

.empty { color: var(--muted); font-size: 14px; padding: 8px 4px; }

.foot {
  padding: 10px 18px 22px;
  text-align: center;
  font-size: 12px;
  color: #94a3b8;
}

/* ---------- 提示 ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 40px;
  transform: translate(-50%, 20px);
  max-width: 86vw;
  padding: 11px 20px;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.92);
  color: #fff;
  font-size: 14px;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: all 0.25s;
  z-index: 60;
}

.toast.show { opacity: 1; transform: translate(-50%, 0); }
