:root {
  --bg: #eef1f6;
  --bg-login: linear-gradient(165deg, #e8eef8 0%, #f4f6fa 45%, #eef2f7 100%);
  --card: #ffffff;
  --text: #0f172a;
  --muted: #475569;
  --primary: #1d4ed8;
  --primary-dark: #1e40af;
  --primary-soft: #dbeafe;
  --danger: #dc2626;
  --success: #059669;
  --border: #cbd5e1;
  --shadow: 0 12px 32px rgba(15, 23, 42, 0.08);
  --shadow-sm: 0 4px 14px rgba(15, 23, 42, 0.06);
  --radius: 14px;
  --radius-lg: 18px;
  --focus-ring: 0 0 0 3px rgba(29, 78, 216, 0.22);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

.view { min-height: 100vh; min-height: 100dvh; }

.card,
.item-card,
.modal-card {
  background: var(--card);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  border: 1px solid rgba(203, 213, 225, 0.65);
}

/* ── 登录页 ── */
#login-view {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: max(24px, env(safe-area-inset-top)) 16px max(24px, env(safe-area-inset-bottom));
  background: var(--bg-login);
}

.login-card {
  width: min(420px, 100%);
  margin: 0;
  padding: 32px 28px 28px;
}

.login-brand {
  text-align: center;
  margin-bottom: 24px;
}

.login-brand h1 {
  font-size: clamp(1.5rem, 5vw, 1.75rem);
  letter-spacing: -0.02em;
  margin-bottom: 6px;
}

.login-brand .subtitle {
  margin: 0;
  font-size: 14px;
  color: var(--muted);
}

#login-form {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

#login-form label {
  margin: 14px 0 6px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
}

#login-form label:first-of-type {
  margin-top: 0;
}

#login-form .btn.primary {
  width: 100%;
  margin-top: 22px;
  min-height: 48px;
  font-size: 16px;
  font-weight: 600;
}

#login-error {
  margin-top: 14px;
  padding: 10px 12px;
  border-radius: 10px;
  background: #fef2f2;
  border: 1px solid #fecaca;
}

#login-error.hidden {
  display: none !important;
}

/* ── 通用表单 ── */
h1, h2, h3 { margin: 0 0 8px; }

.subtitle,
.hint,
.meta {
  color: var(--muted);
  font-size: 14px;
}

label {
  display: block;
  margin: 14px 0 6px;
  font-size: 14px;
  font-weight: 500;
}

input,
textarea {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 16px;
  background: #fff;
  color: var(--text);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

input:focus,
textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: var(--focus-ring);
}

textarea {
  resize: vertical;
  min-height: 88px;
}

.btn {
  border: none;
  border-radius: var(--radius);
  padding: 12px 16px;
  min-height: 44px;
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.1s ease;
  touch-action: manipulation;
}

.btn:active {
  transform: scale(0.98);
}

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

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

.btn.ghost {
  background: var(--primary-soft);
  color: var(--primary);
}

.btn.small {
  padding: 8px 12px;
  min-height: 36px;
  font-size: 14px;
}

.btn.danger {
  background: #fee2e2;
  color: var(--danger);
}

.error {
  color: var(--danger);
  font-size: 14px;
  margin-top: 10px;
}

/* ── 主界面 ── */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar h2 {
  font-size: 1.125rem;
  margin-bottom: 2px;
}

#user-label,
#version-label {
  margin: 0;
  font-size: 13px;
}

.tabs {
  display: flex;
  gap: 8px;
  padding: 12px 16px 0;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

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

.tab {
  flex: 1;
  min-width: 80px;
  min-height: 44px;
  padding: 10px 12px;
  border: none;
  border-radius: 999px;
  background: #e2e8f0;
  color: var(--text);
  font-weight: 500;
}

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

main {
  padding: 16px;
  padding-bottom: max(16px, env(safe-area-inset-bottom));
}

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

.panel-head h3 {
  font-size: 1rem;
}

.list {
  display: grid;
  gap: 12px;
}

.item-card {
  padding: 16px;
}

.item-title {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 8px;
  line-height: 1.4;
}

.badges {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 10px 0;
}

.badge {
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--primary-soft);
  color: var(--primary-dark);
}

.badge.off {
  background: #fef2f2;
  color: #b91c1c;
}

.badge.ok {
  background: #ecfdf5;
  color: #047857;
}

.item-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.link-text {
  color: var(--muted);
  font-size: 13px;
  word-break: break-all;
  margin-top: 8px;
}

.history-item {
  padding: 14px 16px;
}

.history-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 10px;
}

.history-title {
  font-weight: 600;
  line-height: 1.4;
}

.history-summary {
  font-size: 14px;
  color: var(--text);
  margin-bottom: 10px;
  line-height: 1.5;
}

.log-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  margin: 8px 0 10px;
}

.log-table th,
.log-table td {
  border: 1px solid var(--border);
  padding: 8px 10px;
  text-align: left;
  vertical-align: top;
}

.log-table th {
  background: #f8fafc;
  color: var(--muted);
  font-weight: 600;
}

.log-table .old-val {
  color: var(--muted);
}

.log-table .new-val {
  color: var(--primary-dark);
  font-weight: 600;
}

.log-filters {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  margin-bottom: 12px;
  padding-bottom: 2px;
  -webkit-overflow-scrolling: touch;
}

.filter-btn {
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  border-radius: 999px;
  padding: 8px 12px;
  min-height: 36px;
  font-size: 13px;
  white-space: nowrap;
}

.filter-btn.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.type-badge {
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 999px;
  white-space: nowrap;
}

.type-update { background: #fef3c7; color: #92400e; }
.type-periodic { background: #dbeafe; color: #1d4ed8; }
.type-init { background: #ecfdf5; color: #047857; }
.type-error { background: #fee2e2; color: #b91c1c; }
.type-pending { background: #fef3c7; color: #92400e; }
.type-expired { background: #f1f5f9; color: #64748b; }
.type-active { background: #ecfdf5; color: #047857; }
.type-check { background: #ede9fe; color: #6d28d9; }

.log-section { margin-top: 12px; }

.log-section-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 6px;
}

.analysis-box {
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  font-size: 14px;
  line-height: 1.5;
}

.log-highlight {
  box-shadow: 0 0 0 2px rgba(29, 78, 216, 0.35);
}

.type-always { background: var(--primary-soft); color: #4338ca; }
.notify-ok { background: #ecfdf5; color: #047857; }
.notify-no { background: #f1f5f9; color: #64748b; }

.modal {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  display: flex;
  align-items: end;
  justify-content: center;
  padding: 16px;
  z-index: 20;
}

.modal-card {
  width: min(520px, 100%);
  max-height: calc(100dvh - 32px);
  overflow-y: auto;
  padding: 20px;
  border-radius: 20px 20px 16px 16px;
}

.actions {
  display: flex;
  gap: 10px;
  margin-top: 16px;
}

.actions .btn {
  flex: 1;
}

.checkbox-line {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
}

.checkbox-line input {
  width: auto;
  min-width: 18px;
  min-height: 18px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: max(24px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: rgba(15, 23, 42, 0.92);
  color: #fff;
  padding: 12px 16px;
  border-radius: var(--radius);
  z-index: 30;
  max-width: calc(100vw - 32px);
  font-size: 14px;
}

.history-load-status {
  text-align: center;
  padding: 8px 0 16px;
}

.history-sentinel {
  height: 1px;
}

.history-sentinel.hidden {
  display: none;
}
  .modal {
    align-items: center;
  }

  .modal-card {
    border-radius: var(--radius-lg);
  }

  main {
    max-width: 960px;
    margin: 0 auto;
  }

  .topbar {
    padding-left: calc((100vw - 960px) / 2 + 16px);
    padding-right: calc((100vw - 960px) / 2 + 16px);
  }

  .tabs {
    max-width: 960px;
    margin: 0 auto;
  }
}

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

  .btn:active {
    transform: none;
  }
}
