:root {
  --bg: #0b1220;
  --bg2: #121a2b;
  --card: #172033;
  --line: #2a3a55;
  --text: #e8eef9;
  --muted: #8fa0bb;
  --accent: #2dd4bf;
  --accent2: #0d9488;
  --danger: #f07178;
  --warn: #e6b450;
  --on: #34d399;
  --row: #141e30;
  --row2: #101827;
  --head: #0f1a2e;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }
/* 强制隐藏：避免遮罩层在部分浏览器里仍可点穿/挡住按钮 */
[hidden] { display: none !important; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--text); }
body.page-login {
  background:
    radial-gradient(900px 420px at 10% -10%, rgba(45, 212, 191, 0.16), transparent 55%),
    var(--bg);
}

button, input, select, textarea {
  font: inherit;
  color: inherit;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--bg2);
}
input, select, textarea { width: 100%; padding: 10px 12px; }
textarea { resize: vertical; }
label { display: grid; gap: 6px; margin: 0 0 12px; font-size: 13px; color: var(--muted); }
label.check { display: flex; align-items: center; gap: 8px; }
label.check input { width: auto; }

.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--text);
  padding: 9px 12px;
  cursor: pointer;
  font-weight: 600;
  white-space: nowrap;
}
.btn.primary { background: linear-gradient(180deg, var(--accent), var(--accent2)); color: #042f2e; border-color: transparent; }
.btn.ghost { background: transparent; }
.btn.danger { background: rgba(240, 113, 120, 0.14); color: var(--danger); border-color: rgba(240, 113, 120, 0.35); }
.btn.sm { padding: 6px 10px; font-size: 12px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: 0.45; }

.login-view {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px 16px calc(24px + var(--safe-b));
}
.login-card {
  width: min(400px, 100%);
  background: rgba(23, 32, 51, 0.94);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 28px 22px;
}
.brand { margin: 0; font-size: 28px; font-weight: 800; color: var(--accent); letter-spacing: 0.06em; }
.login-card h1 { margin: 4px 0 6px; font-size: 22px; }
.sub, .muted { color: var(--muted); font-size: 13px; }
.err { color: var(--danger); margin: 10px 0 0; font-size: 13px; }

.page-app { padding-top: var(--safe-t); min-height: 100dvh; display: flex; flex-direction: column; }
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  background: rgba(11, 18, 32, 0.95);
  position: sticky;
  top: 0;
  z-index: 30;
}
.brand-mini { font-weight: 700; color: var(--accent); }
.topbar-actions { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }

.nav {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  background: var(--bg2);
  position: sticky;
  top: 48px;
  z-index: 29;
}
.nav a {
  text-align: center;
  text-decoration: none;
  color: var(--muted);
  font-weight: 700;
  padding: 9px 4px;
  border-radius: 999px;
}
.nav a.active {
  color: #042f2e;
  background: var(--accent);
}

.main { flex: 1; padding: 10px 10px calc(16px + var(--safe-b)); }
.toolbar { display: grid; gap: 8px; margin-bottom: 10px; }
.chips { display: flex; gap: 6px; overflow-x: auto; }
#app-chips { padding-bottom: 2px; border-bottom: 1px dashed rgba(42, 58, 85, 0.7); }
.chip {
  flex: 0 0 auto;
  padding: 7px 11px;
  border-radius: 999px;
  background: var(--bg2);
  color: var(--muted);
  border: 1px solid var(--line);
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}
.chip.active { color: #042f2e; background: var(--accent); border-color: transparent; }
#app-chips .chip.active { background: #38bdf8; color: #082f49; }
.row { display: flex; gap: 8px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.row > input { flex: 1; min-width: 120px; }

.table-wrap {
  width: 100%;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--card);
  -webkit-overflow-scrolling: touch;
  max-height: calc(100dvh - 210px);
}
.ver-table-wrap { max-height: none; }
.ver-table-wrap table.grid { width: 100%; min-width: 720px; }
.ver-table-wrap table.grid tbody td { white-space: normal; }
.ver-table-wrap input {
  width: 100%;
  min-width: 90px;
  padding: 7px 8px;
  font-size: 12px;
}

table.grid {
  width: max-content;
  min-width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 12px;
}
table.grid thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--head);
  color: #c5d4ee;
  font-weight: 700;
  text-align: left;
  padding: 10px 10px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
table.grid tbody td {
  padding: 8px 10px;
  border-bottom: 1px solid rgba(42, 58, 85, 0.55);
  white-space: nowrap;
  background: var(--row);
  vertical-align: middle;
}
table.grid tbody tr:nth-child(even) td { background: var(--row2); }
table.grid tbody tr:hover td { background: #1a2942; }
table.grid tbody tr { cursor: pointer; }
.col-check { width: 36px; text-align: center; }
.col-check input { width: auto; }
.cell-strong { font-weight: 700; color: #fff; }
.mono { font-family: ui-monospace, Consolas, monospace; font-size: 12px; white-space: pre-wrap; word-break: break-all; }
.txt-on { color: var(--on); font-weight: 700; }
.txt-off { color: var(--muted); }
.txt-ban { color: var(--danger); font-weight: 700; }
.txt-warn-user { color: #ff4d4f !important; font-weight: 800; }
.empty { text-align: center; color: var(--muted); padding: 28px; }

.panel-box {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px;
  margin-bottom: 12px;
}
.panel-box h2 { margin: 0 0 12px; font-size: 16px; }
.panel-box.compact h2 { margin-bottom: 8px; }
.form-page .form-grid {
  display: grid;
  gap: 12px;
}
@media (min-width: 900px) {
  .form-page .form-grid { grid-template-columns: 1fr 1fr; }
  .table-wrap { max-height: calc(100dvh - 180px); }
  table.grid { font-size: 13px; }
}

.preview {
  margin: 8px 0 12px;
  padding: 10px 12px;
  border-radius: 8px;
  background: #0a0f1a;
  border: 1px dashed var(--line);
  min-height: 40px;
}
.preview.warn { color: var(--warn); }

.drawer-mask {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.55);
  z-index: 40;
}
.drawer {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  max-height: min(88dvh, 720px);
  overflow: auto;
  background: var(--bg2);
  border-radius: 16px 16px 0 0;
  border: 1px solid var(--line);
  z-index: 50;
  padding-bottom: var(--safe-b);
}
.drawer header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  background: var(--bg2);
}
.drawer-body { padding: 14px; }
.drawer-body h3 { margin: 16px 0 8px; font-size: 13px; color: var(--muted); }
.btn-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(18px + var(--safe-b));
  transform: translateX(-50%);
  z-index: 80;
  max-width: min(92vw, 420px);
  padding: 12px 16px;
  border-radius: 12px;
  background: #10233a;
  border: 1px solid var(--line);
  font-size: 14px;
}

label.inline {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 0;
  color: var(--muted);
  font-size: 12px;
}
label.inline select { width: auto; min-width: 88px; padding: 6px 8px; }

.modal-mask {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.65);
  z-index: 60;
}
.modal {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(920px, 96vw);
  max-height: min(90dvh, 860px);
  overflow: auto;
  background: var(--bg2);
  border: 1px solid var(--line);
  border-radius: 14px;
  z-index: 70;
}
.modal header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  background: var(--bg2);
}
.modal-body { padding: 14px; }
.remote-img {
  display: block;
  width: 100%;
  max-height: min(70dvh, 720px);
  object-fit: contain;
  background: #000;
  border-radius: 8px;
  border: 1px solid var(--line);
}
.hist-list { display: grid; gap: 8px; }
.hist-item {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: center;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--card);
}
.hist-item .meta { font-size: 12px; color: var(--muted); }

@media (min-width: 900px) {
  .drawer {
    left: auto;
    right: 16px;
    bottom: 16px;
    width: min(420px, 100%);
    border-radius: 14px;
  }
}
