:root {
  --primary: #2f6fed;
  --primary-dark: #245bd0;
  --green: #22a06b;
  --green-bg: #e6f5ee;
  --orange: #f28b0c;
  --orange-bg: #fdf1df;
  --red: #e5484d;
  --red-bg: #fdecec;
  --bg: #f5f6fa;
  --card: #ffffff;
  --text: #1a1d23;
  --muted: #7a8290;
  --border: #e6e8ef;
  --shadow: 0 1px 3px rgba(16, 24, 40, 0.08);
  --radius: 14px;
  --appbar-h: 56px;
}

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

html,
body {
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  padding-bottom: calc(88px + env(safe-area-inset-bottom));
}

/* ---- 顶部栏 ---- */
.appbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--appbar-h);
  padding: 0 16px;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}

.app-title {
  font-size: 17px;
  font-weight: 700;
  margin: 0;
}

.icon-btn {
  border: none;
  background: none;
  font-size: 20px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  cursor: pointer;
  display: grid;
  place-items: center;
  color: var(--text);
}

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

/* ---- 统计卡 ---- */
.stats {
  display: flex;
  gap: 10px;
  padding: 12px 16px 4px;
}

.stat {
  flex: 1;
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 10px 8px;
  text-align: center;
}

.stat .num {
  display: block;
  font-size: 24px;
  font-weight: 700;
  line-height: 1.2;
}

.stat .label {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
}

.stat-normal .num { color: var(--green); }
.stat-expiring .num { color: var(--orange); }
.stat-expired .num { color: var(--red); }

/* ---- Tab ---- */
.tabs {
  display: flex;
  gap: 8px;
  padding: 12px 16px;
  overflow-x: auto;
}

.tab {
  border: none;
  background: #eceef4;
  color: var(--muted);
  padding: 8px 16px;
  border-radius: 20px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}

.tab.active {
  background: var(--primary);
  color: #fff;
}

.tab-expiring.active { background: var(--orange); }

/* ---- 列表 ---- */
.list {
  padding: 4px 16px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.empty {
  text-align: center;
  color: var(--muted);
  padding: 48px 16px;
  font-size: 14px;
}

.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 12px 14px;
}

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

.card-name {
  font-size: 16px;
  font-weight: 700;
  word-break: break-all;
}

.card-meta {
  font-size: 13px;
  color: var(--muted);
  margin-top: 4px;
  display: flex;
  flex-wrap: wrap;
  gap: 4px 12px;
}

.badge {
  flex-shrink: 0;
  font-size: 13px;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 12px;
  white-space: nowrap;
}

.badge-normal { color: var(--green); background: var(--green-bg); }
.badge-expiring { color: var(--orange); background: var(--orange-bg); }
.badge-expired { color: var(--red); background: var(--red-bg); }

.card-actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}

.btn {
  border: none;
  border-radius: 10px;
  padding: 7px 14px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

.btn-remove { background: var(--red-bg); color: var(--red); }
.btn-edit { background: #eef1f7; color: var(--text); }
.btn-del { background: #f1f1f3; color: var(--muted); }

.btn:active { opacity: 0.75; }

/* ---- 悬浮新增按钮 ---- */
.fab {
  position: fixed;
  right: 18px;
  bottom: calc(24px + env(safe-area-inset-bottom));
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: none;
  background: var(--primary);
  color: #fff;
  font-size: 28px;
  font-weight: 600;
  box-shadow: 0 6px 16px rgba(47, 111, 237, 0.4);
  cursor: pointer;
  z-index: 30;
}

.fab:active { transform: scale(0.94); }

/* ---- 底部弹层 ---- */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 40;
}

.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 50;
  background: #fff;
  border-radius: 18px 18px 0 0;
  padding: 16px 16px calc(20px + env(safe-area-inset-bottom));
  max-height: 92vh;
  overflow-y: auto;
  box-shadow: 0 -8px 30px rgba(0, 0, 0, 0.18);
}

@media (min-width: 520px) {
  .sheet {
    left: 50%;
    right: auto;
    width: 480px;
    transform: translateX(-50%);
    border-radius: 18px;
    margin-bottom: 16px;
    box-shadow: 0 16px 50px rgba(0, 0, 0, 0.25);
  }
}

.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.sheet-head h2 {
  font-size: 17px;
  margin: 0;
}

.hidden { display: none !important; }

/* ---- 表单 ---- */
.field { margin-bottom: 14px; }

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

.field label em { color: var(--red); font-style: normal; }
.hint { font-weight: 400; color: var(--muted); }

.field input {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 15px;
  background: #fff;
  color: var(--text);
}

.field input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(47, 111, 237, 0.15);
}

.field-row {
  display: flex;
  gap: 12px;
}

.field-row .field { flex: 1; }

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

.exp-preview {
  background: var(--green-bg);
  color: var(--green);
  font-size: 13px;
  font-weight: 600;
  padding: 8px 12px;
  border-radius: 10px;
  margin: -4px 0 14px;
}

.cron-row {
  display: flex;
  gap: 8px;
}

.cron-row input {
  flex: 1;
  background: var(--bg);
  font-size: 12px;
}

.btn-row {
  display: flex;
  gap: 8px;
  margin-top: 4px;
}

.btn-row .btn-flex { flex: 1; }

.primary {
  border: none;
  background: var(--primary);
  color: #fff;
  border-radius: 10px;
  padding: 12px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}

.primary:active { background: var(--primary-dark); }

.secondary {
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  border-radius: 10px;
  padding: 11px 14px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

.btn-block { width: 100%; }

.help {
  margin-top: 14px;
  font-size: 13px;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
}

.help summary { cursor: pointer; font-weight: 600; color: var(--text); }
.help ol { margin: 8px 0 0; padding-left: 20px; }

/* ---- Toast ---- */
.toast {
  position: fixed;
  left: 50%;
  top: 76px;
  transform: translateX(-50%);
  background: rgba(20, 24, 32, 0.92);
  color: #fff;
  font-size: 14px;
  padding: 10px 18px;
  border-radius: 22px;
  z-index: 60;
  max-width: 84vw;
  text-align: center;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
}

.toast.err { background: rgba(229, 72, 77, 0.95); }

/* ---- 批量导入 ---- */
.field textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 14px;
  background: #fff;
  color: var(--text);
  resize: vertical;
  font-family: inherit;
  line-height: 1.6;
  min-height: 120px;
}

.field textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(47, 111, 237, 0.15);
}

#importPreview { margin-top: 4px; }

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

.import-row {
  display: flex;
  align-items: baseline;
  gap: 6px;
  font-size: 14px;
  padding: 7px 10px;
  border-radius: 8px;
  background: var(--bg);
  margin-bottom: 6px;
  word-break: break-all;
}

.import-row.err {
  background: var(--red-bg);
  color: var(--red);
}

.import-idx {
  color: var(--muted);
  font-size: 12px;
  flex-shrink: 0;
}

.import-exp {
  color: var(--green);
  font-size: 12px;
  flex-shrink: 0;
}

.import-row.err em {
  font-style: normal;
  font-size: 12px;
  margin-left: auto;
  flex-shrink: 0;
}

#importPreview .primary { margin-top: 8px; }

.empty-actions {
  text-align: center;
  padding: 0 16px 16px;
}

/* ---- 添加菜单（右下角 +） ---- */
.menu-item {
  display: block;
  width: 100%;
  border: none;
  background: #fff;
  color: var(--text);
  font-size: 16px;
  font-weight: 600;
  padding: 16px 12px;
  text-align: left;
  cursor: pointer;
  border-radius: 0;
}

.menu-item + .menu-item { border-top: 1px solid var(--border); }
.menu-item:active { background: var(--bg); }

/* ---- 访问密码门 ---- */
.gate {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(245, 246, 250, 0.97);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.gate-card {
  width: 100%;
  max-width: 360px;
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.12);
  padding: 28px 24px;
}

.gate-card h2 {
  margin: 0 0 4px;
  font-size: 18px;
  text-align: center;
}

.gate-sub {
  margin: 0 0 18px;
  font-size: 13px;
  color: var(--muted);
  text-align: center;
}

.gate-card input {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 16px;
}

.gate-card input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(47, 111, 237, 0.15);
}

.gate-err {
  min-height: 18px;
  margin: 8px 0 0;
  font-size: 13px;
  color: var(--red);
  text-align: center;
}
