/* 无线话筒频率规划 — 浅色主题，贴近 demo.py 视觉 */

* { box-sizing: border-box; }

/* hidden 属性优先：避免被 #id 选择器的 display 覆盖 */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC",
               "Microsoft YaHei", "Segoe UI", sans-serif;
  font-size: 13px;
  color: #222;
  background: #f5f6f8;
}

button {
  font: inherit;
  padding: 4px 10px;
  border: 1px solid #c8ccd2;
  border-radius: 6px;
  background: #fff;
  cursor: pointer;
  white-space: nowrap;
}
button:hover { background: #f0f2f5; }
button:disabled { opacity: 0.55; cursor: default; }
button.primary {
  background: #1565c0;
  border-color: #1565c0;
  color: #fff;
  font-weight: 600;
}
button.primary:hover { background: #0d47a1; }
button.danger { color: #c62828; }
button.danger:hover { background: #ffebee; }

input[type="text"], input[type="number"], select {
  font: inherit;
  padding: 3px 6px;
  border: 1px solid #c8ccd2;
  border-radius: 6px;
  background: #fff;
}
input:focus, select:focus { outline: 2px solid rgba(21, 101, 192, 0.35); }
input.invalid { border-color: #c62828; background: #ffebee; }

h2 { font-size: 13px; margin: 0; }
.muted { color: #888; font-weight: normal; }

/* ---------------- 顶栏 ---------------- */
#topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 8px 12px;
  background: #fff;
  border-bottom: 1px solid #e0e3e8;
  flex-wrap: wrap;
}
.plan-group, .actions-group {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}
.top-label { color: #666; }
#plan-select { min-width: 160px; max-width: 260px; }

.save-status {
  font-size: 12px;
  color: #2e7d32;
  cursor: default;
  min-width: 88px;
  text-align: right;
}
.save-status.saving { color: #ef6c00; }
.save-status.failed { color: #c62828; cursor: pointer; text-decoration: underline; }

/* ---------------- 主区三栏 ---------------- */
#main {
  display: grid;
  grid-template-columns: 300px 1fr 280px;
  gap: 8px;
  padding: 8px;
  height: calc(100vh - 45px);
}
#main.no-plan { grid-template-columns: 1fr; }
#main.no-plan #sidebar, #main.no-plan #status-panel { display: none; }

#sidebar, #status-panel {
  background: #fff;
  border: 1px solid #e0e3e8;
  border-radius: 8px;
  padding: 10px;
  overflow-y: auto;
  min-height: 0;
}
.sidebar-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

/* ---------------- 设备行 ---------------- */
.device-row {
  border: 1px solid #e4e7ec;
  border-radius: 8px;
  padding: 6px 8px;
  margin-bottom: 6px;
  cursor: pointer;
}
.device-row:hover { border-color: #b6bcc6; }
.device-row.selected {
  border-color: #1565c0;
  box-shadow: 0 0 0 2px rgba(21, 101, 192, 0.18);
}
.device-row.hit { background: #fff8e1; }
.device-row .row1 {
  display: flex;
  align-items: center;
  gap: 4px;
}
.drag-handle {
  cursor: grab;
  color: #b6bcc6;
  font-size: 12px;
  padding: 0 1px;
  user-select: none;
  flex: none;
}
.drag-handle:hover { color: #666; }
.drag-handle:active { cursor: grabbing; }
.device-row.dragging { opacity: 0.45; }
.device-row.drag-over-top { box-shadow: 0 -2px 0 0 #1565c0; }
.device-row.drag-over-bottom { box-shadow: 0 2px 0 0 #1565c0; }
.device-row input[type="color"] {
  width: 22px; height: 22px;
  padding: 0; border: none; background: none;
  cursor: pointer;
  flex: none;
}
.device-row .dev-name {
  flex: 1;
  min-width: 0;
  border: 1px solid transparent;
  font-weight: 600;
}
.device-row .dev-name:hover, .device-row .dev-name:focus { border-color: #c8ccd2; }
.device-row .lock-btn, .device-row .del-btn {
  border: none;
  background: none;
  padding: 2px 4px;
  font-size: 13px;
  flex: none;
}
.device-row .lock-btn { opacity: 0.35; }
.device-row .lock-btn.locked { opacity: 1; }
.device-row .del-btn { color: #c62828; opacity: 0.55; }
.device-row .del-btn:hover { opacity: 1; }
.device-row .row2 {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-top: 5px;
  padding-left: 20px;
}
/* 设备行空间有限：隐藏数字输入框的步进箭头，省出宽度 */
.device-row input[type="number"]::-webkit-outer-spin-button,
.device-row input[type="number"]::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
.device-row .field-label { color: #999; font-size: 11px; flex: none; }
.device-row .freq-input {
  flex: 1.4 1 0;
  min-width: 46px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.device-row .range-input {
  flex: 1 1 0;
  min-width: 36px;
  text-align: right;
  font-variant-numeric: tabular-nums;
  color: #555;
}
.device-row .range-sep { color: #999; flex: none; }

/* ---------------- 图区 ---------------- */
#chart-area {
  position: relative;
  background: #fff;
  border: 1px solid #e0e3e8;
  border-radius: 8px;
  overflow: hidden;
  min-width: 0;
}
#chart {
  display: block;
  width: 100%;
  height: 100%;
}
#chart-hint {
  position: absolute;
  right: 10px;
  top: 96px;
  font-size: 11px;
  color: #c3c9d2;
  pointer-events: none;
}
#tooltip {
  position: absolute;
  pointer-events: none;
  background: rgba(33, 33, 33, 0.92);
  color: #fff;
  font-size: 11px;
  padding: 4px 8px;
  border-radius: 5px;
  white-space: pre;
  z-index: 5;
}
#empty-state {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: #888;
  font-size: 15px;
  background: #fff;
}

/* ---------------- 状态面板 ---------------- */
#status-summary {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  margin: 8px 0;
}
.stat-card {
  border: 1px solid #e4e7ec;
  border-radius: 8px;
  padding: 6px 4px;
  text-align: center;
}
.stat-card .num { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat-card .lbl { font-size: 11px; color: #777; margin-top: 2px; }
.stat-card.ok .num { color: #2e7d32; }
.stat-card.bad .num { color: #c62828; }

#status-details { font-size: 12px; }
.detail-section { margin-bottom: 10px; }
.detail-section h3 {
  font-size: 12px;
  margin: 6px 0 4px;
  color: #555;
}
.detail-item {
  padding: 3px 6px;
  border-radius: 5px;
  margin-bottom: 2px;
  background: #f6f7f9;
  font-variant-numeric: tabular-nums;
  line-height: 1.5;
}
.detail-item.conflict { background: #ffebee; color: #8e0000; }
.detail-item.hit { background: #fff8e1; color: #6d4c00; cursor: pointer; }
.detail-item.hit:hover { background: #ffecb3; }
.detail-ok {
  color: #2e7d32;
  padding: 6px;
  background: #e8f5e9;
  border-radius: 6px;
  text-align: center;
}

/* ---------------- 设置抽屉 ---------------- */
#settings-drawer {
  position: fixed;
  top: 45px;
  right: 8px;
  z-index: 20;
  background: #fff;
  border: 1px solid #dfe3e9;
  border-radius: 10px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.14);
  padding: 14px 16px;
  width: 460px;
}
#settings-drawer h2 { margin-bottom: 10px; }
.settings-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 14px;
}
.settings-grid label {
  display: flex;
  flex-direction: column;
  gap: 3px;
  color: #555;
  font-size: 12px;
}
.orders-field {
  grid-column: 1 / -1;
  border: 1px solid #e0e3e8;
  border-radius: 8px;
  display: flex;
  gap: 16px;
  padding: 6px 10px;
}
.orders-field legend { color: #555; font-size: 12px; padding: 0 4px; }
.orders-field label { display: flex; flex-direction: row; align-items: center; gap: 4px; }

/* ---------------- Toast ---------------- */
#toast-container {
  position: fixed;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 50;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}
.toast {
  background: rgba(33, 33, 33, 0.92);
  color: #fff;
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 13px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
  animation: toast-in 0.18s ease-out;
  max-width: 70vw;
}
.toast.success { background: #2e7d32; }
.toast.error { background: #c62828; }
.toast.warn { background: #ef6c00; }
@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* 窄屏适配：状态面板换到下方 */
@media (max-width: 1100px) {
  #main { grid-template-columns: 260px 1fr; }
  #status-panel { display: none; }
}
