:root {
  --bg: #f5f7fa;
  --panel: #ffffff;
  --panel-2: #f8fafc;
  --line: #e3e8ef;
  --text: #1f2937;
  --muted: #6b7280;
  --dim: #9ca3af;
  --accent: #2f7ff0;
  --accent-soft: rgba(47, 127, 240, .12);
  --ok: #059669;
  --warn: #d97706;
  --bad: #dc2626;
  --radius: 12px;
  color-scheme: light;
}

[data-theme="dark"] {
  --bg: #0d1117;
  --panel: #161b22;
  --panel-2: #1c232c;
  --line: #293341;
  --text: #e6edf3;
  --muted: #9aa7b4;
  --dim: #6b7885;
  --accent: #58a6ff;
  --accent-soft: rgba(88, 166, 255, .16);
  --ok: #3fb950;
  --warn: #d29922;
  --bad: #f85149;
  color-scheme: dark;
}

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

body {
  margin: 0;
  padding: 20px 16px calc(32px + env(safe-area-inset-bottom));
  background: var(--bg);
  color: var(--text);
  font: 15px/1.6 system-ui, -apple-system, "Segoe UI", "Microsoft YaHei", sans-serif;
  min-height: 100vh;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.wrap { max-width: 860px; margin: 0 auto; }

/* ---------------- 头部 ---------------- */
.head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}

.head h1 { font-size: 19px; margin: 0; font-weight: 650; }
.head .sub { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.head .links { display: flex; gap: 8px; align-items: center; }

/* ---------------- 面板 ---------------- */
.box {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 14px;
}

.box h2 {
  font-size: 14px;
  margin: 0 0 12px;
  color: var(--muted);
  font-weight: 600;
}

/* ---------------- 按钮 ----------------
   ⚠️ 高度统一由 --btn-h 控制，**所有按钮一律同高**。

   为什么用变量而不是各处写死：之前 .mini 是 30px、普通按钮 38px、
   门禁按钮 44px，同一行里并排放着就像没对齐。现在只有一个高度，
   想整体调整只改这一个值。
   变体（primary / ghost / danger / mini）只改**字号和内边距**，不改高度。 */
:root {
  --btn-h: 38px;
}

button, .btnlike {
  font: inherit;
  font-size: 13px;
  height: var(--btn-h);
  padding: 0 14px;
  border-radius: 9px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  /* 关键：不让 flex/grid 容器把按钮拉伸或压缩到别的高度 */
  flex: 0 0 auto;
  box-sizing: border-box;
  transition: background .15s, border-color .15s, opacity .15s;
}

button:hover:not(:disabled) { border-color: var(--accent); }
button:disabled { opacity: .55; cursor: default; }

button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}
button.primary:hover:not(:disabled) { filter: brightness(1.08); }

button.ghost { background: transparent; }
button.danger { color: var(--bad); }

/* 小号按钮：只缩字号与内边距，高度仍然一致 */
button.mini {
  height: var(--btn-h);
  padding: 0 10px;
  font-size: 12px;
  border-radius: 8px;
}

/* ---------------- 门户卡片（导航页） ---------------- */
.portal-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 12px;
}

.portal-card {
  display: flex;
  gap: 12px;
  padding: 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  transition: border-color .15s, transform .15s;
  color: inherit;
}

.portal-card:hover {
  border-color: var(--accent);
  text-decoration: none;
  transform: translateY(-1px);
}

.portal-icon {
  flex: 0 0 40px;
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: var(--accent-soft);
  color: var(--accent);
  display: grid;
  place-items: center;
  font-size: 19px;
  overflow: hidden;
}
.portal-icon img { width: 100%; height: 100%; object-fit: cover; }

.portal-main { min-width: 0; flex: 1; }
.portal-name { font-weight: 620; margin-bottom: 3px; }
.portal-desc { font-size: 12.5px; color: var(--muted); line-height: 1.5; }
.portal-url { font-size: 11.5px; color: var(--dim); margin-top: 5px; word-break: break-all; }

/* ---------------- 状态 / 提示 ---------------- */
.status {
  padding: 9px 12px;
  border-radius: 9px;
  font-size: 13px;
  margin-bottom: 12px;
  border: 1px solid transparent;
}
.status.ok { background: rgba(5, 150, 105, .1); color: var(--ok); border-color: rgba(5, 150, 105, .3); }
.status.err { background: rgba(220, 38, 38, .1); color: var(--bad); border-color: rgba(220, 38, 38, .3); }

.hint { font-size: 12.5px; color: var(--muted); line-height: 1.6; }
.muted { color: var(--muted); }
.dim { color: var(--dim); }
.hidden { display: none !important; }

/* ---------------- 表单 ---------------- */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 11px; }
.field label { font-size: 12.5px; color: var(--muted); }

.field input[type=text],
.field input[type=password],
.field input[type=number],
.field input[type=date],
.field select {
  height: 40px;
  padding: 0 12px;
  border-radius: 9px;
  font-size: 15px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  outline: none;
  font-family: inherit;
  width: 100%;
}

.field input:focus, .field select:focus { border-color: var(--accent); }
.field .note { font-size: 11.5px; color: var(--dim); }

.row { display: flex; align-items: center; gap: 10px; margin-bottom: 11px; flex-wrap: wrap; }
.check { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; margin-right: 14px; }
.check input { width: 16px; height: 16px; }

.form-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 4px; }

/* ---------------- 后台列表 ---------------- */
.item {
  border: 1px solid var(--line);
  border-radius: 11px;
  padding: 12px;
  margin-bottom: 10px;
  background: var(--panel-2);
}
.item.off { opacity: .62; }
.item-top { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 6px; }
.item-title { font-weight: 600; }
.item-meta { font-size: 12px; color: var(--muted); line-height: 1.6; word-break: break-all; }
.item-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }

.tag {
  font-size: 11px;
  padding: 1px 7px;
  border-radius: 6px;
  background: rgba(148, 163, 184, .16);
  color: var(--muted);
}
.tag-on { background: rgba(5, 150, 105, .14); color: var(--ok); }
.tag-off { background: rgba(220, 38, 38, .14); color: var(--bad); }
.tag-ext { background: rgba(217, 119, 6, .15); color: var(--warn); }
.tag-err { background: rgba(220, 38, 38, .14); color: var(--bad); }

code {
  background: rgba(127, 127, 127, .14);
  padding: 1px 6px;
  border-radius: 5px;
  font-size: 12.5px;
  font-family: ui-monospace, Consolas, monospace;
}

/* ---------------- 弹层 ---------------- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 300;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  background: rgba(0, 0, 0, .6);
}

.modal-box {
  width: 100%;
  max-width: 420px;
  max-height: 86vh;
  overflow-y: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 18px;
}

.modal-box h2 { font-size: 15px; margin: 0 0 14px; }
.modal-actions { display: flex; gap: 8px; margin-top: 14px; }
.modal-actions button { flex: 1; }

/* ---------------- 门禁 ---------------- */
.gate {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.gate-box {
  width: 100%;
  max-width: 330px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 26px 22px;
  text-align: center;
}

.gate-logo {
  width: 52px;
  height: 52px;
  margin: 0 auto 14px;
  border-radius: 14px;
  background: var(--accent-soft);
  color: var(--accent);
  display: grid;
  place-items: center;
  font-size: 24px;
}

.gate-box h2 { font-size: 16px; margin: 0 0 16px; }

.gate-box input {
  width: 100%;
  height: 44px;
  padding: 0 13px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  font-size: 16px;
  outline: none;
  margin-bottom: 10px;
}

.gate-box input:focus { border-color: var(--accent); }
.gate-tip { min-height: 18px; font-size: 12.5px; color: var(--bad); margin-bottom: 10px; }
.gate-btn { width: 100%; }

@media (max-width: 560px) {
  body { padding: 14px 12px calc(26px + env(safe-area-inset-bottom)); }
  .portal-grid { grid-template-columns: 1fr; }
  .head h1 { font-size: 17px; }
}
