:root {
  --bg: #f3f5f9;
  --card: #ffffff;
  --ink: #1f2937;
  --muted: #6b7280;
  --line: #e5e7eb;
  --primary: #2d8cf0;
  --primary-soft: #e8f3ff;
  --ok: #19be6b;
  --ok-soft: #e8f9f0;
  --warn: #ff9900;
  --danger: #ed4014;
  --danger-soft: #ffece8;
  --shadow: 0 8px 24px rgba(15, 23, 42, 0.06);
  --radius: 14px;
  --font: "Segoe UI", "PingFang SC", "Noto Sans SC", sans-serif;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  min-height: 100%;
  background: linear-gradient(180deg, #eef3f9 0%, var(--bg) 240px);
  color: var(--ink);
  font-family: var(--font);
}

a { color: var(--primary); text-decoration: none; }
.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 13px; }
.err { color: var(--danger); min-height: 1.2em; font-size: 13px; }

button, .btn {
  appearance: none;
  border: 0;
  border-radius: 10px;
  padding: 10px 14px;
  background: var(--primary);
  color: #fff;
  font-weight: 600;
  cursor: pointer;
  font-size: 13px;
}
button.ghost, .btn.ghost {
  background: #fff;
  color: var(--ink);
  border: 1px solid var(--line);
}
button.danger, .btn.danger { background: var(--danger); }
button:disabled { opacity: .5; cursor: not-allowed; }

input, select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  color: var(--ink);
  font-size: 13px;
  outline: none;
}
input:focus, select:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(45,140,240,.12); }

/* ===== List page ===== */
.page { max-width: 1280px; margin: 0 auto; padding: 24px 20px 40px; }
.page-head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
  margin-bottom: 18px;
  flex-wrap: wrap;
}
.page-head h1 { margin: 0 0 6px; font-size: 24px; letter-spacing: .2px; }
.head-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  border-radius: 999px;
  background: #fff;
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
  box-shadow: var(--shadow);
}
.pill strong { color: var(--ink); }

.login-card {
  max-width: 420px;
  margin: 48px auto;
  padding: 28px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
}
.login-card h2 { margin: 0 0 8px; }
.login-card label { display: block; margin: 14px 0 8px; color: var(--muted); font-size: 13px; }
.login-card button { width: 100%; margin-top: 8px; padding: 12px; }

.filters {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 12px;
  padding: 16px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}
.filters label { display: block; margin: 0; color: var(--muted); font-size: 12px; }
.filters label > span, .filters label { }
.filters input, .filters select { margin-top: 6px; }
.filters .check {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--ink);
  font-size: 13px;
  padding-top: 24px;
}
.filters .check input { width: auto; }
.filters .actions {
  display: flex;
  gap: 8px;
  align-items: end;
  padding-top: 18px;
}

.table-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.table-wrap { overflow: auto; }
table { width: 100%; border-collapse: collapse; min-width: 1180px; font-size: 13px; }
th, td { padding: 12px 10px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; vertical-align: middle; }
th {
  color: var(--muted);
  font-weight: 600;
  background: #f8fafc;
  position: sticky;
  top: 0;
  z-index: 1;
}
tr:hover td { background: #f8fbff; }
tr.off td { color: #9aa3af; }

.dot {
  display: inline-block;
  width: 8px; height: 8px;
  border-radius: 50%;
  margin-right: 6px;
  background: #c0c4cc;
}
.dot.on { background: var(--ok); box-shadow: 0 0 0 3px rgba(25,190,107,.15); }
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}
.badge.on { background: var(--ok-soft); color: #0f8a4b; }
.badge.off { background: #f3f4f6; color: #6b7280; }
.badge.lock { background: #fff7e6; color: #d48806; }
.badge.unlock { background: var(--primary-soft); color: #1d6fd0; }

.remark-cell { display: flex; gap: 6px; align-items: center; }
.remark-input { width: 110px; padding: 7px 8px; border-radius: 8px; }
.mini { padding: 7px 10px; font-size: 12px; }
.btn-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 7px 12px;
  border-radius: 8px;
  background: var(--primary);
  color: #fff !important;
  font-weight: 600;
  font-size: 12px;
}
.btn-link.disabled { pointer-events: none; opacity: .4; background: #9dbfe8; }
.empty {
  padding: 48px 16px;
  text-align: center;
  color: var(--muted);
}

@media (max-width: 1100px) {
  .filters { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 720px) {
  .filters { grid-template-columns: 1fr 1fr; }
}

/* ===== Control page ===== */
.control-page {
  max-width: 1760px;
  margin: 0 auto;
  padding: 18px 18px 36px;
}
.control-top {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  margin-bottom: 14px;
  flex-wrap: wrap;
}
.control-top h1 { margin: 0; font-size: 20px; }
.back {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  border-radius: 10px;
  background: #fff;
  border: 1px solid var(--line);
  color: var(--ink);
  font-weight: 600;
  font-size: 13px;
}
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  padding: 6px 10px;
  border-radius: 999px;
  background: #fff;
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
}

.control-grid {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  width: 100%;
}
.screen-panel {
  flex: 1 1 480px;
  max-width: 620px;
  position: sticky;
  top: 12px;
  padding-bottom: 12px;
  min-width: 0;
}
.mid-rail {
  flex: 0 0 100px;
  width: 100px;
  position: sticky;
  top: 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  z-index: 2;
}
.side-panels {
  flex: 1 1 420px;
  min-width: 360px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.panel {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px;
}
.panel h3 {
  margin: 0 0 12px;
  font-size: 14px;
  color: var(--muted);
  font-weight: 700;
  letter-spacing: .3px;
}
.screen-wrap {
  position: relative;
  min-height: min(72vh, 760px);
  border-radius: 12px;
  background: #0b1220;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: none;
  user-select: none;
  border: 1px solid #122033;
}
#frame {
  max-width: 100%;
  max-height: min(72vh, 760px);
  width: auto;
  height: auto;
  display: block;
  pointer-events: none;
}
.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #9fb0c7;
  background: rgba(8, 12, 20, .45);
  pointer-events: none;
  font-size: 14px;
}
.screen-hint { margin: 8px 0 0; font-size: 12px; }

.nav-bar {
  display: flex;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
  padding: 8px 10px;
  border-radius: 999px;
  background: #0f172a;
  border: 1px solid #1e293b;
}
.nav-btn {
  min-width: 52px;
  height: 34px;
  padding: 0 10px !important;
  border-radius: 999px !important;
  background: #1e293b !important;
  color: #e2e8f0 !important;
  border: 1px solid #334155 !important;
  font-size: 12px !important;
  font-weight: 600;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.nav-btn:hover {
  background: #334155 !important;
  color: #fff !important;
}

.rail-block {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 10px 8px;
  width: 100%;
  box-sizing: border-box;
}
.rail-block h4 {
  margin: 0 0 8px;
  font-size: 12px;
  color: var(--muted);
  text-align: center;
  font-weight: 700;
  letter-spacing: .2px;
}
.rail-stack {
  display: flex !important;
  flex-direction: column !important;
  flex-wrap: nowrap !important;
  gap: 6px;
  width: 100%;
}
.rail-btn {
  display: block !important;
  width: 100% !important;
  box-sizing: border-box;
  padding: 9px 4px !important;
  border-radius: 8px !important;
  font-size: 12px !important;
  font-weight: 600;
  line-height: 1.2;
  background: #f5f7fb !important;
  color: var(--ink) !important;
  border: 1px solid var(--line) !important;
  white-space: nowrap;
}
.rail-btn:hover {
  background: var(--primary-soft) !important;
  border-color: #b7d6f8 !important;
  color: #1d6fd0 !important;
}
.rail-btn.warn {
  background: #fff7e6 !important;
  border-color: #ffe1a8 !important;
  color: #d48806 !important;
}
.rail-btn.danger-soft {
  background: var(--danger-soft) !important;
  border-color: #ffd0c5 !important;
  color: var(--danger) !important;
}
.rail-btn.ghost {
  background: #fff !important;
}

.btn-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 14px;
}
.btn-grid button { width: 100%; background: #f5f7fb; color: var(--ink); border: 1px solid var(--line); }
.btn-grid button:hover { background: var(--primary-soft); border-color: #b7d6f8; color: #1d6fd0; }
.btn-grid button.warn { background: #fff7e6; border-color: #ffe1a8; color: #d48806; }
.btn-grid button.danger-soft { background: var(--danger-soft); border-color: #ffd0c5; color: var(--danger); }

.info-list { display: grid; gap: 8px; margin-bottom: 14px; }
.info-row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 10px;
  background: #f8fafc;
  border: 1px solid var(--line);
  font-size: 13px;
}
.info-row span { color: var(--muted); }
.info-row strong { color: var(--ink); font-weight: 600; text-align: right; }

.input-row { display: flex; gap: 8px; }
.input-row input { margin: 0; }
.input-row button { white-space: nowrap; }

.tabs {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 4px;
}
.tab {
  background: #fff !important;
  color: var(--muted) !important;
  border: 1px solid var(--line) !important;
  padding: 8px 12px !important;
  font-weight: 600;
}
.tab.active {
  background: var(--primary-soft) !important;
  color: #1d6fd0 !important;
  border-color: #b7d6f8 !important;
}
.tab-pane { display: none; }
.tab-pane.active { display: grid; gap: 14px; }
.toolbar-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}
.toolbar-row input { flex: 1; min-width: 140px; margin: 0; }
.scroll-list {
  max-height: min(70vh, 640px);
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fafbfc;
}
.list-item {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  font-size: 13px;
}
.list-item:last-child { border-bottom: 0; }
.list-actions { display: flex; gap: 6px; flex-shrink: 0; }
.file-link { cursor: pointer; }
.file-link:hover { color: var(--primary); }
.empty-mini { padding: 24px 12px; text-align: center; color: var(--muted); font-size: 13px; }
.upload-btn {
  display: inline-flex;
  align-items: center;
  padding: 10px 14px;
  border-radius: 10px;
  background: var(--primary);
  color: #fff;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
}
.mini.danger-soft {
  background: var(--danger-soft);
  color: var(--danger);
  border: 1px solid #ffd0c5;
}

@media (max-width: 1100px) {
  .control-grid {
    flex-wrap: wrap;
  }
  .screen-panel {
    flex: 1 1 calc(100% - 120px);
    max-width: none;
    position: static;
  }
  .mid-rail {
    flex: 0 0 100px;
  }
  .side-panels {
    flex: 1 1 100%;
    min-width: 0;
    width: 100%;
  }
  .screen-wrap { min-height: 520px; }
  #frame { max-height: 62vh; }
}
@media (max-width: 720px) {
  .control-grid { flex-direction: column; }
  .screen-panel,
  .mid-rail,
  .side-panels {
    width: 100%;
    flex: none;
    max-width: none;
    position: static;
  }
  .mid-rail {
    flex-direction: row;
    align-items: stretch;
  }
  .rail-block { flex: 1; }
  /* 窄屏也保持每组内部竖排 */
  .rail-stack {
    flex-direction: column !important;
  }
  .screen-wrap { min-height: 420px; }
  .nav-btn { min-width: 44px; height: 32px; padding: 0 8px !important; font-size: 11px !important; }
}
