:root {
  --bg: #070d18;
  --bg-2: #0b1424;
  --panel: #111c2e;
  --panel-2: #16233a;
  --line: rgba(94, 132, 196, 0.22);
  --line-strong: rgba(94, 132, 196, 0.42);
  --text: #e8f0fc;
  --muted: #8ba0c2;
  --teal: #2fd3b0;
  --blue: #5b8cff;
  --amber: #f0b64a;
  --pink: #ff7a9c;
  --danger: #ff6a6a;
  --radius: 14px;
  --shadow: 0 18px 40px rgba(3, 8, 18, 0.55);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "PingFang SC", "Microsoft YaHei", system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

body { min-height: 100vh; overflow-x: hidden; }

h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: 0.2px; }

/* ---------- 低多边形背景 ---------- */
.bg-shapes { position: fixed; inset: 0; z-index: 0; pointer-events: none; overflow: hidden; }
.bg-shapes .shape { position: absolute; display: block; opacity: 0.5; }
.bg-shapes .s1 {
  width: 520px; height: 520px; top: -220px; right: -120px;
  background: linear-gradient(150deg, rgba(47, 211, 176, 0.16), rgba(91, 140, 255, 0.04));
  clip-path: polygon(50% 0, 100% 38%, 78% 100%, 18% 88%, 0 30%);
}
.bg-shapes .s2 {
  width: 420px; height: 420px; bottom: -180px; left: -140px;
  background: linear-gradient(40deg, rgba(91, 140, 255, 0.16), rgba(47, 211, 176, 0.03));
  clip-path: polygon(20% 0, 90% 12%, 100% 70%, 46% 100%, 0 66%);
}
.bg-shapes .s3 {
  width: 260px; height: 260px; top: 42%; left: 46%;
  background: rgba(240, 182, 74, 0.05);
  clip-path: polygon(50% 0, 100% 50%, 50% 100%, 0 50%);
}

.app { position: relative; z-index: 1; max-width: 1500px; margin: 0 auto; padding: 18px 20px 34px; }

/* ---------- 顶栏 ---------- */
.topbar {
  display: flex; align-items: center; gap: 18px; flex-wrap: wrap;
  padding: 14px 18px;
  background: linear-gradient(120deg, rgba(20, 33, 53, 0.95), rgba(13, 21, 36, 0.92));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 260px; }
.logo { width: 42px; height: 42px; flex: 0 0 42px; filter: drop-shadow(0 6px 14px rgba(47, 211, 176, 0.28)); }
.logo svg { width: 100%; height: 100%; }
.brand-text h1 { font-size: 17px; }
.brand-text p { margin: 2px 0 0; color: var(--muted); font-size: 12px; }

.top-stats { display: flex; gap: 10px; flex-wrap: wrap; margin-left: auto; }
.pill {
  display: flex; flex-direction: column; gap: 1px;
  min-width: 92px; padding: 7px 12px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
}
.pill b { font-size: 16px; font-weight: 600; letter-spacing: 0.3px; }
.pill span { font-size: 11px; color: var(--muted); }
.pill.teal b { color: var(--teal); }
.pill.blue b { color: var(--blue); }
.pill.amber b { color: var(--amber); }

.top-actions { display: flex; align-items: center; gap: 10px; }
.badge {
  padding: 6px 12px; border-radius: 999px; font-size: 12px;
  border: 1px solid rgba(240, 182, 74, 0.45);
  color: var(--amber); background: rgba(240, 182, 74, 0.1);
  white-space: nowrap;
}
.badge.on { border-color: rgba(47, 211, 176, 0.5); color: var(--teal); background: rgba(47, 211, 176, 0.12); }
.icon-btn {
  width: 36px; height: 36px; display: grid; place-items: center;
  border-radius: 10px; cursor: pointer;
  background: var(--panel); color: var(--muted);
  border: 1px solid var(--line);
  transition: 0.18s;
}
.icon-btn:hover { color: var(--text); border-color: var(--line-strong); }
.icon-btn svg { width: 19px; height: 19px; }

/* ---------- 布局 ---------- */
.workspace { display: grid; grid-template-columns: minmax(0, 1fr) 392px; gap: 16px; margin-top: 16px; align-items: start; }
.col-main { min-width: 0; display: flex; flex-direction: column; gap: 14px; }

.room-bar { display: flex; gap: 8px; flex-wrap: wrap; }
.room-tab {
  padding: 8px 15px; border-radius: 10px; cursor: pointer; font-size: 13px;
  background: var(--panel); border: 1px solid var(--line); color: var(--muted);
  transition: 0.16s;
}
.room-tab:hover { color: var(--text); border-color: var(--line-strong); }
.room-tab.active {
  color: #06231d; background: linear-gradient(135deg, #45e6c2, #23b79c);
  border-color: transparent; font-weight: 600;
  box-shadow: 0 8px 20px rgba(47, 211, 176, 0.25);
}
.room-tab .cnt { opacity: 0.65; font-size: 11px; margin-left: 4px; }

.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.section-head h2 { font-size: 14px; color: var(--text); }
.section-head h2::before {
  content: ""; display: inline-block; width: 4px; height: 13px; margin-right: 8px;
  transform: skewX(-18deg) translateY(1px);
  background: linear-gradient(180deg, var(--teal), var(--blue)); border-radius: 2px;
}
.head-actions { display: flex; align-items: center; gap: 10px; }
.hint { color: var(--muted); font-size: 12px; }

.ghost-btn {
  padding: 7px 12px; border-radius: 9px; cursor: pointer; font-size: 12px;
  background: transparent; color: var(--muted); border: 1px solid var(--line);
  transition: 0.16s;
}
.ghost-btn:hover { color: var(--text); border-color: var(--line-strong); background: var(--panel); }
.ghost-btn.small { padding: 5px 10px; font-size: 11px; }
.primary-btn {
  padding: 8px 18px; border-radius: 9px; cursor: pointer; font-size: 13px; font-weight: 600;
  background: linear-gradient(135deg, #45e6c2, #1fa98f); color: #04211b;
  border: none; transition: 0.16s;
}
.primary-btn:hover { filter: brightness(1.06); }

/* ---------- 设备卡片 ---------- */
.device-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(228px, 1fr)); gap: 12px; }

.device-card {
  position: relative; overflow: hidden;
  background: linear-gradient(160deg, var(--panel-2), var(--panel));
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 13px 14px 12px;
  transition: 0.18s;
}
.device-card::before {
  content: ""; position: absolute; top: 0; right: 0; width: 54px; height: 54px;
  background: linear-gradient(225deg, rgba(91, 140, 255, 0.14), transparent 62%);
  clip-path: polygon(100% 0, 100% 100%, 0 0);
}
.device-card:hover { border-color: var(--line-strong); transform: translateY(-2px); }
.device-card.on { border-color: rgba(47, 211, 176, 0.42); box-shadow: 0 10px 26px rgba(47, 211, 176, 0.1); }
.device-card.offline { opacity: 0.55; }

.dev-head { display: flex; align-items: flex-start; gap: 10px; }
.dev-icon { width: 34px; height: 34px; flex: 0 0 34px; }
.dev-icon svg { width: 100%; height: 100%; }
.dev-title { min-width: 0; flex: 1; }
.dev-title b { display: block; font-size: 14px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dev-title span { font-size: 11px; color: var(--muted); }

.switch {
  position: relative; width: 42px; height: 23px; flex: 0 0 42px;
  border-radius: 999px; background: #223149; cursor: pointer; border: 1px solid var(--line);
  transition: 0.18s;
}
.switch::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 17px; height: 17px;
  border-radius: 50%; background: #7e91b1; transition: 0.18s;
}
.switch.on { background: rgba(47, 211, 176, 0.28); border-color: rgba(47, 211, 176, 0.6); }
.switch.on::after { left: 21px; background: var(--teal); box-shadow: 0 0 10px rgba(47, 211, 176, 0.7); }
.switch.disabled { cursor: not-allowed; opacity: 0.4; }

.dev-state { margin-top: 8px; font-size: 12px; color: var(--muted); min-height: 18px; }
.dev-state b { color: var(--text); font-weight: 600; }

.dev-del {
  flex: 0 0 18px; width: 18px; height: 18px; padding: 0; margin-top: 2px;
  font-size: 10px; line-height: 1; border-radius: 50%; cursor: pointer;
  background: rgba(255, 106, 106, 0.12); color: var(--danger); border: 1px solid rgba(255, 106, 106, 0.35);
  opacity: 0; transition: 0.15s;
}
.device-card:hover .dev-del { opacity: 1; }
.dev-del:hover { background: rgba(255, 106, 106, 0.24); }

.dev-controls { margin-top: 9px; display: flex; flex-direction: column; gap: 8px; }
.slider-row { display: flex; align-items: center; gap: 9px; }
.slider-row input[type="range"] {
  -webkit-appearance: none; appearance: none; flex: 1; height: 4px; border-radius: 4px;
  background: linear-gradient(90deg, var(--teal) 0%, var(--teal) var(--fill, 50%), #24344e var(--fill, 50%), #24344e 100%);
  outline: none;
}
.slider-row input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 14px; height: 14px; border-radius: 50%;
  background: #eaf6ff; border: 2px solid var(--teal); cursor: pointer;
  box-shadow: 0 0 8px rgba(47, 211, 176, 0.6);
}
.slider-row input[type="range"]::-moz-range-thumb {
  width: 13px; height: 13px; border-radius: 50%; background: #eaf6ff;
  border: 2px solid var(--teal); cursor: pointer;
}
.slider-val { width: 38px; text-align: right; font-size: 12px; color: var(--text); }

.stepper { display: flex; align-items: center; gap: 10px; }
.stepper button {
  width: 28px; height: 28px; border-radius: 8px; cursor: pointer; font-size: 15px;
  background: #1b2942; color: var(--text); border: 1px solid var(--line);
}
.stepper button:hover { border-color: var(--line-strong); }
.stepper .temp { font-size: 20px; font-weight: 600; color: var(--teal); min-width: 62px; text-align: center; }
.stepper .temp small { font-size: 11px; color: var(--muted); font-weight: 400; }

.mode-chips { display: flex; gap: 6px; flex-wrap: wrap; }
.mode-chips button {
  padding: 3px 9px; font-size: 11px; border-radius: 7px; cursor: pointer;
  background: transparent; color: var(--muted); border: 1px solid var(--line);
}
.mode-chips button.active { color: var(--teal); border-color: rgba(47, 211, 176, 0.55); background: rgba(47, 211, 176, 0.1); }

.reading { display: flex; gap: 14px; margin-top: 4px; }
.reading div { font-size: 12px; color: var(--muted); }
.reading b { display: block; font-size: 19px; color: var(--text); font-weight: 600; }

/* ---------- 场景 ---------- */
.scene-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(168px, 1fr)); gap: 10px; }
.scene-card {
  position: relative; text-align: left; cursor: pointer; overflow: hidden;
  padding: 13px 14px; border-radius: 12px;
  background: linear-gradient(150deg, rgba(27, 42, 66, 0.95), rgba(16, 26, 42, 0.95));
  border: 1px solid var(--line); color: var(--text);
  clip-path: polygon(0 0, 100% 0, 100% calc(100% - 14px), calc(100% - 14px) 100%, 0 100%);
  transition: 0.18s;
}
.scene-card:hover { border-color: rgba(240, 182, 74, 0.5); transform: translateY(-2px); }
.scene-card b { display: block; font-size: 13.5px; margin-bottom: 3px; }
.scene-card span { font-size: 11px; color: var(--muted); line-height: 1.45; display: block; }
.scene-card .sc-ico { position: absolute; right: 10px; top: 9px; font-size: 16px; opacity: 0.5; }
.scene-card.running { border-color: var(--teal); box-shadow: 0 0 0 1px rgba(47, 211, 176, 0.35) inset; }

/* ---------- 面板 ---------- */
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.panel {
  background: linear-gradient(165deg, rgba(20, 33, 53, 0.95), rgba(12, 20, 33, 0.95));
  border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px;
}
.panel-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 10px; }
.panel-head h3 { font-size: 13px; }
.panel-head h3::before {
  content: ""; display: inline-block; width: 3px; height: 11px; margin-right: 7px;
  background: var(--blue); transform: skewX(-18deg); border-radius: 2px;
}

.auto-list, .log-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; max-height: 236px; overflow-y: auto; }
.auto-list li { display: flex; align-items: center; gap: 10px; font-size: 12.5px; }
.auto-list .auto-name { flex: 1; min-width: 0; }
.auto-list .auto-name b { display: block; font-weight: 600; font-size: 12.5px; }
.auto-list .auto-name span { color: var(--muted); font-size: 11px; }
.auto-list .switch { width: 36px; height: 20px; flex: 0 0 36px; }
.auto-list .switch::after { width: 14px; height: 14px; }
.auto-list .switch.on::after { left: 17px; }

.log-list li { display: flex; gap: 8px; font-size: 12px; color: var(--muted); line-height: 1.5; }
.log-list .tag {
  flex: 0 0 auto; font-size: 10px; padding: 1px 6px; border-radius: 5px; height: 17px; line-height: 15px;
  border: 1px solid var(--line); color: var(--muted);
}
.log-list .tag.ai { color: var(--teal); border-color: rgba(47, 211, 176, 0.45); }
.log-list .tag.scene { color: var(--blue); border-color: rgba(91, 140, 255, 0.45); }
.log-list .tag.auto { color: var(--amber); border-color: rgba(240, 182, 74, 0.45); }
.log-list .tag.manual { color: #b9a6ff; border-color: rgba(185, 166, 255, 0.4); }
.log-list time { flex: 0 0 auto; font-variant-numeric: tabular-nums; opacity: 0.7; }

/* ---------- 对话 ---------- */
.chat-panel {
  position: sticky; top: 16px;
  display: flex; flex-direction: column;
  height: calc(100vh - 60px); max-height: 900px; min-height: 520px;
  background: linear-gradient(170deg, rgba(21, 35, 56, 0.97), rgba(10, 17, 29, 0.97));
  border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); overflow: hidden;
}
.chat-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; padding: 14px 16px 10px; border-bottom: 1px solid var(--line); }
.chat-head h3 { font-size: 14px; }
.chat-head h3::before { content: "◆"; color: var(--teal); font-size: 10px; margin-right: 7px; vertical-align: 1px; }
.chat-head p { margin: 3px 0 0; font-size: 11px; color: var(--muted); }
.chat-body { flex: 1; overflow-y: auto; padding: 14px 14px 6px; display: flex; flex-direction: column; gap: 10px; }
.msg { max-width: 88%; padding: 9px 12px; border-radius: 12px; font-size: 13px; line-height: 1.62; white-space: pre-line; word-break: break-word; }
.msg.ai { align-self: flex-start; background: rgba(35, 53, 80, 0.75); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.msg.user { align-self: flex-end; background: linear-gradient(135deg, rgba(47, 211, 176, 0.22), rgba(91, 140, 255, 0.22)); border: 1px solid rgba(47, 211, 176, 0.3); border-bottom-right-radius: 4px; }
.msg .meta { display: block; margin-top: 5px; font-size: 10px; color: var(--muted); }
.msg.typing::after { content: "…"; animation: blink 1s infinite; }
@keyframes blink { 0%, 100% { opacity: 0.25; } 50% { opacity: 1; } }

.chips { display: flex; gap: 6px; flex-wrap: wrap; padding: 4px 14px 8px; }
.chip {
  padding: 5px 10px; font-size: 11.5px; border-radius: 999px; cursor: pointer;
  background: rgba(47, 211, 176, 0.08); color: #a9e9da; border: 1px solid rgba(47, 211, 176, 0.28);
  transition: 0.15s;
}
.chip:hover { background: rgba(47, 211, 176, 0.18); }

.composer { display: flex; gap: 8px; padding: 10px 14px; border-top: 1px solid var(--line); }
.composer input {
  flex: 1; padding: 10px 13px; border-radius: 10px; font-size: 13px;
  background: rgba(8, 14, 24, 0.85); color: var(--text);
  border: 1px solid var(--line); outline: none; transition: 0.16s;
}
.composer input:focus { border-color: rgba(47, 211, 176, 0.6); box-shadow: 0 0 0 3px rgba(47, 211, 176, 0.1); }
.composer button {
  padding: 0 18px; border-radius: 10px; cursor: pointer; font-size: 13px; font-weight: 600;
  background: linear-gradient(135deg, #45e6c2, #1fa98f); color: #04211b; border: none;
}
.composer button:disabled { opacity: 0.5; cursor: wait; }
.chat-note { margin: 0; padding: 0 16px 12px; font-size: 11px; color: var(--muted); }

/* ---------- 弹层 ---------- */
.modal {
  border: 1px solid var(--line-strong); border-radius: var(--radius); padding: 0;
  background: linear-gradient(165deg, #17253c, #0b1424); color: var(--text);
  box-shadow: 0 30px 70px rgba(0, 0, 0, 0.6); width: min(440px, 92vw);
}
.modal::backdrop { background: rgba(3, 8, 16, 0.72); backdrop-filter: blur(3px); }
.modal-body { padding: 20px 22px; display: flex; flex-direction: column; gap: 11px; }
.modal-body h3 { font-size: 15px; }
.modal-tip { margin: 0 0 4px; font-size: 12px; color: var(--muted); line-height: 1.6; }
.modal-body label { display: flex; flex-direction: column; gap: 5px; font-size: 12px; color: var(--muted); }
.modal-body input, .modal-body select {
  padding: 9px 11px; border-radius: 9px; font-size: 13px;
  background: rgba(8, 14, 24, 0.9); color: var(--text); border: 1px solid var(--line); outline: none;
  font-family: inherit;
}
.modal-body input:focus, .modal-body select:focus { border-color: rgba(47, 211, 176, 0.6); }
.switch-row { flex-direction: row !important; align-items: center; gap: 8px !important; color: var(--text) !important; }
.modal-actions { display: flex; justify-content: flex-end; gap: 9px; margin-top: 6px; }

.toast {
  position: fixed; left: 50%; bottom: 26px; transform: translate(-50%, 20px);
  padding: 10px 18px; border-radius: 10px; font-size: 13px;
  background: rgba(20, 34, 55, 0.97); border: 1px solid var(--line-strong);
  color: var(--text); box-shadow: var(--shadow);
  opacity: 0; pointer-events: none; transition: 0.22s; z-index: 60; max-width: 80vw;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.err { border-color: rgba(255, 106, 106, 0.6); color: #ffc9c9; }

.foot {
  display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap;
  margin-top: 18px; padding: 10px 4px 0; border-top: 1px solid var(--line);
  font-size: 11px; color: var(--muted);
}

.empty { padding: 24px 8px; text-align: center; color: var(--muted); font-size: 12.5px; }

::-webkit-scrollbar { width: 7px; height: 7px; }
::-webkit-scrollbar-thumb { background: #24344e; border-radius: 6px; }
::-webkit-scrollbar-track { background: transparent; }

@media (max-width: 1120px) {
  .workspace { grid-template-columns: 1fr; }
  .chat-panel { position: static; height: 70vh; max-height: 640px; }
  .two-col { grid-template-columns: 1fr; }
}
@media (max-width: 560px) {
  .app { padding: 12px 12px 26px; }
  .brand { min-width: 0; }
  .top-stats { width: 100%; margin-left: 0; }
  .pill { flex: 1; min-width: 78px; }
  .device-grid { grid-template-columns: 1fr 1fr; }
  .scene-grid { grid-template-columns: 1fr 1fr; }
}
