/* ESP32-S3 远程监控与控制平台 —— 深蓝科技风主题
 * 沿用项目原配色：#0b1020 背景 / #7aa5ff 主蓝 / #42d5a0 在线 / #ff7888 告警 */

:root {
  --bg: #0b1020;
  --panel: #121a2b;
  --panel2: #172238;
  --panel3: #1b2740;
  --line: #27344d;
  --line2: #34445f;
  --text: #eef3ff;
  --muted: #91a0ba;
  --muted2: #6d7c96;
  --blue: #7aa5ff;
  --blue2: #5484ff;
  --cyan: #53d6c6;
  --green: #42d5a0;
  --red: #ff7888;
  --amber: #e5ad58;
  --purple: #d3a0ff;
  --radius: 14px;
  --radius-lg: 18px;
  --shadow: 0 10px 30px #05091466;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background:
    radial-gradient(ellipse at 15% -15%, #253961 0, transparent 42%),
    radial-gradient(ellipse at 100% 100%, #172a4d 0, transparent 45%),
    var(--bg);
  color: var(--text);
  font: 14px/1.55 system-ui, -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-thumb { background: #2a3855; border-radius: 8px; }
::-webkit-scrollbar-track { background: transparent; }

a { color: var(--blue); text-decoration: none; }
code, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }

/* ============================ 布局 ============================ */
.layout { display: flex; min-height: 100vh; }

.sidebar {
  width: 232px; flex: 0 0 232px;
  background: linear-gradient(180deg, #101a2c 0, #0d1524 100%);
  border-right: 1px solid var(--line);
  padding: 18px 14px; position: sticky; top: 0; height: 100vh;
  overflow-y: auto;
}

.brand { display: flex; align-items: center; gap: 11px; padding: 4px 6px 18px; }
.brand .logo {
  width: 40px; height: 40px; border-radius: 13px; flex: 0 0 auto;
  background: linear-gradient(140deg, #74a2ff, #53d6c6);
  color: #091326; font-weight: 900; font-size: 15px;
  display: grid; place-items: center; box-shadow: 0 8px 24px #5488ff33;
}
.brand .kicker { font-size: 10px; letter-spacing: .16em; color: #8ea3c4; }
.brand .name { font-size: 16px; font-weight: 750; letter-spacing: -.03em; }

.nav-group { margin-bottom: 16px; }
.nav-title { font-size: 10px; letter-spacing: .14em; text-transform: uppercase; color: var(--muted2); padding: 8px 10px; }
.nav-item {
  display: flex; align-items: center; gap: 10px; padding: 9px 11px; border-radius: 10px;
  color: #b9c7de; cursor: pointer; border: 1px solid transparent; margin-bottom: 2px;
  transition: background .15s, color .15s, border-color .15s; font-size: 13.5px;
}
.nav-item .ico { width: 18px; text-align: center; opacity: .85; font-size: 14px; }
.nav-item:hover { background: #16203a; color: #dfe9fb; }
.nav-item.active { background: linear-gradient(100deg, #23406f, #1b2c4b); color: #fff; border-color: #35558a; }
.nav-item .tag { margin-left: auto; font-size: 10px; color: var(--muted2); }

.sidebar-foot { margin-top: auto; padding: 12px 8px 0; color: var(--muted2); font-size: 11px; border-top: 1px solid var(--line); }

.main { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  position: sticky; top: 0; z-index: 30; display: flex; align-items: center; gap: 12px;
  padding: 12px 22px; border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, #0e1728ee, #0e1728cc); backdrop-filter: blur(10px);
}
.topbar h1 { font-size: 17px; margin: 0; font-weight: 700; letter-spacing: -.02em; }
.topbar .sub { font-size: 11.5px; color: var(--muted); }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 10px; }

.content { padding: 20px 22px 60px; max-width: 1400px; width: 100%; }

/* ============================ 组件 ============================ */
.card {
  background: linear-gradient(160deg, var(--panel2), var(--panel));
  border: 1px solid var(--line); border-radius: var(--radius-lg);
  padding: 16px 18px; box-shadow: var(--shadow);
}
.card + .card { margin-top: 14px; }
.card-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.card-head h3 { margin: 0; font-size: 14.5px; font-weight: 700; }
.card-head .hint { font-size: 11.5px; color: var(--muted); }
.card-head .right { margin-left: auto; display: flex; gap: 8px; align-items: center; }

.grid { display: grid; gap: 12px; }
.grid.kpi-md { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }

.kpi { padding: 15px 16px; position: relative; overflow: hidden; }
.kpi .label { font-size: 11px; color: var(--muted); letter-spacing: .04em; }
.kpi .value { font-size: 27px; font-weight: 780; letter-spacing: -.03em; margin-top: 4px; line-height: 1.1; }
.kpi .foot { font-size: 11px; color: var(--muted2); margin-top: 4px; }
.kpi.ok .value { color: var(--green); }
.kpi.off .value { color: var(--muted); }
.kpi.warn .value { color: var(--amber); }
.kpi.sim .value { color: var(--purple); }

.pill, .badge {
  display: inline-flex; align-items: center; gap: 5px; font-size: 10.5px; font-weight: 700;
  letter-spacing: .04em; padding: 3px 8px; border-radius: 99px; border: 1px solid transparent;
}
.pill { background: #16203a; border-color: var(--line2); color: #c2d2ea; }
.badge.blue { background: #1c3160; color: #bcd3ff; }
.badge.green { background: #15382f; color: #9ce6d0; }
.badge.red { background: #3d2030; color: #ffc3cb; }
.badge.amber { background: #3a2d18; color: #ffdca6; }
.badge.purple { background: #2e2143; color: #e0c6fb; }
.badge.ghost { background: transparent; border-color: var(--line2); color: var(--muted); }

.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--amber); box-shadow: 0 0 10px #e5ad5866; flex: 0 0 auto; }
.dot.on { background: var(--green); box-shadow: 0 0 10px #42d5a066; }
.dot.off { background: #5c6a83; box-shadow: none; }
.dot.err { background: var(--red); box-shadow: 0 0 10px #ff788866; }

.btn {
  min-height: 36px; border: 0; border-radius: 10px; cursor: pointer; font-size: 13px; font-weight: 650;
  padding: 0 14px; background: #202d43; color: #cfdbed; border: 1px solid var(--line2);
  transition: filter .15s, transform .1s, background .15s; white-space: nowrap;
  display: inline-flex; align-items: center; gap: 6px; justify-content: center;
}
.btn:hover { filter: brightness(1.12); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: linear-gradient(135deg, var(--blue), #6193f5); color: #08142a; border-color: transparent; }
.btn.cyan { background: linear-gradient(135deg, #5ad2d8, #4bb0e8); color: #04141c; border-color: transparent; }
.btn.danger { background: #3a2029; color: #ffb3bd; border-color: #5b2c39; }
.btn.ghost { background: transparent; }
.btn.sm { min-height: 28px; padding: 0 9px; font-size: 12px; border-radius: 8px; }
.btn.block { width: 100%; }

input[type=text], input[type=password], input[type=number], input[type=url], select, textarea {
  background: var(--panel2); border: 1px solid var(--line2); color: var(--text);
  border-radius: 9px; padding: 8px 10px; font: inherit; font-size: 13px; outline: none; width: 100%;
}
textarea { font-family: ui-monospace, monospace; font-size: 12px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--blue); box-shadow: 0 0 0 3px #7aa5ff1f; }
input[type=number] { text-align: center; }
select { cursor: pointer; appearance: none; background-image: linear-gradient(45deg, transparent 50%, #9db1d0 50%), linear-gradient(135deg, #9db1d0 50%, transparent 50%); background-position: calc(100% - 15px) 15px, calc(100% - 10px) 15px; background-size: 5px 5px, 5px 5px; background-repeat: no-repeat; padding-right: 28px; }

.field { margin-bottom: 12px; }
.field > label { display: block; font-size: 11.5px; color: var(--muted); margin-bottom: 5px; }
.field .desc { font-size: 11px; color: var(--muted2); margin-top: 4px; }
.field-row { display: flex; gap: 10px; }
.field-row > * { flex: 1 1 0; min-width: 0; }

/* 开关 */
.switch { position: relative; width: 44px; height: 25px; flex: 0 0 auto; display: inline-block; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch .track { position: absolute; inset: 0; background: #35425b; border-radius: 99px; cursor: pointer; transition: .18s; }
.switch .track:before {
  content: ""; position: absolute; left: 4px; top: 4px; width: 17px; height: 17px;
  background: #e8eeff; border-radius: 50%; transition: .18s;
}
.switch input:checked + .track { background: var(--blue2); }
.switch input:checked + .track:before { transform: translateX(19px); }
.switch input:disabled + .track { opacity: .4; cursor: not-allowed; }
.switch.sm { width: 36px; height: 20px; }
.switch.sm .track:before { width: 14px; height: 14px; left: 3px; top: 3px; }
.switch.sm input:checked + .track:before { transform: translateX(16px); }

input[type=range] { width: 100%; accent-color: var(--blue); height: 24px; background: transparent; }

table.tbl { width: 100%; border-collapse: collapse; font-size: 12.5px; }
table.tbl th { text-align: left; font-size: 11px; color: var(--muted); font-weight: 600; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.tbl td { padding: 9px 10px; border-bottom: 1px solid #1d2740; vertical-align: middle; }
table.tbl tr:last-child td { border-bottom: 0; }
table.tbl tr:hover td { background: #141d31; }
.tbl-wrap { overflow-x: auto; margin: 0 -18px; padding: 0 18px; }

.empty { border: 1px dashed var(--line2); border-radius: var(--radius); padding: 26px 18px; text-align: center; color: var(--muted); font-size: 13px; }
.empty .big { font-size: 15px; color: var(--text); margin-bottom: 6px; font-weight: 650; }

.banner {
  display: flex; gap: 10px; align-items: flex-start; padding: 11px 14px; border-radius: var(--radius);
  font-size: 12.5px; line-height: 1.5; margin-bottom: 14px; border: 1px solid;
}
.banner.warn { background: #2b2416; border-color: #5d4a22; color: #f0d9a8; }
.banner.info { background: #131f38; border-color: #2c4168; color: #c3d5ef; }
.banner.err { background: #2b1a20; border-color: #5c2b38; color: #ffc8ce; }
.banner.sim { background: #241b34; border-color: #453066; color: #dfc9f7; }
.banner b { font-weight: 750; }

/* 日志 / 列表 */
.log-list { display: flex; flex-direction: column; gap: 6px; max-height: 420px; overflow-y: auto; }
.log-item { display: flex; gap: 10px; align-items: baseline; padding: 7px 10px; border-radius: 9px; background: #131c2e; border: 1px solid #202c46; font-size: 12px; }
.log-item .ts { color: var(--muted2); font-family: ui-monospace, monospace; font-size: 11px; flex: 0 0 auto; }
.log-item .who { color: var(--blue); flex: 0 0 auto; }
.log-item .msg { color: #cfdcf0; word-break: break-word; }
.log-item.lv-ok .msg { color: #b9ecd8; }
.log-item.lv-error { border-color: #5b2c39; background: #241722; }
.log-item.lv-error .msg { color: #ffb9c2; }
.log-item.lv-warn { border-color: #5d4a22; background: #252015; }
.log-item.lv-warn .msg { color: #f3dda9; }

.stat-row { display: flex; justify-content: space-between; gap: 10px; padding: 7px 0; border-bottom: 1px dashed #22304c; font-size: 12.5px; }
.stat-row:last-child { border-bottom: 0; }
.stat-row .k { color: var(--muted); }
.stat-row .v { font-family: ui-monospace, monospace; font-size: 12px; text-align: right; word-break: break-all; }

.spark { width: 100%; height: 46px; display: block; }

/* Toast / Modal */
.toast-wrap { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 200; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast {
  padding: 10px 15px; border-radius: 11px; background: #1d2942; border: 1px solid #3a4c6d; color: #eaf1ff;
  font-size: 13px; box-shadow: 0 12px 30px #0007; opacity: 0; transform: translateY(10px); transition: .22s; max-width: 88vw;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast.ok { border-color: #2f6b54; background: #16352a; color: #c3f2df; }
.toast.err { border-color: #6b2f3c; background: #351b22; color: #ffc9d0; }
.toast.warn { border-color: #6b5729; background: #322817; color: #f6e2b0; }

.modal-mask {
  position: fixed; inset: 0; background: #050b1699; backdrop-filter: blur(3px); z-index: 300;
  display: none; align-items: center; justify-content: center; padding: 18px;
}
.modal-mask.show { display: flex; }
.modal { width: min(560px, 100%); max-height: 88vh; overflow: auto; background: linear-gradient(160deg, #17223a, #111a2b); border: 1px solid var(--line2); border-radius: 18px; box-shadow: 0 24px 60px #000a; }
.modal header { padding: 15px 18px; border-bottom: 1px solid var(--line); display: flex; align-items: center; }
.modal header h3 { margin: 0; font-size: 15px; }
.modal .body { padding: 16px 18px; }
.modal .foot { padding: 13px 18px; border-top: 1px solid var(--line); display: flex; gap: 9px; justify-content: flex-end; }
.x-btn { margin-left: auto; background: transparent; border: 0; color: var(--muted); font-size: 19px; cursor: pointer; line-height: 1; padding: 2px 6px; border-radius: 7px; }
.x-btn:hover { background: #ffffff14; color: #fff; }

.device-select { min-width: 190px; font-size: 12.5px; padding: 6px 26px 6px 10px; border-radius: 9px; }
.mobile-only { display: none; }

.hr { height: 1px; background: var(--line); margin: 14px 0; }
.muted { color: var(--muted); }
.small { font-size: 11.5px; }
.right { margin-left: auto; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.hide { display: none !important; }

.step { display: flex; gap: 10px; align-items: flex-start; padding: 9px 0; }
.step .n { width: 22px; height: 22px; border-radius: 7px; background: #22314e; color: #bcd0f0; display: grid; place-items: center; font-size: 11.5px; font-weight: 700; flex: 0 0 auto; }
.step .t { font-size: 13px; }

/* ============================ 移动端 ============================ */
@media (max-width: 900px) {
  .sidebar { position: fixed; inset: 0 auto 0 0; transform: translateX(-100%); z-index: 120; transition: transform .2s; height: 100vh; }
  .sidebar.open { transform: translateX(0); box-shadow: 20px 0 50px #0009; }
  .scrim { position: fixed; inset: 0; background: #0008; z-index: 110; display: none; }
  .scrim.show { display: block; }
  .content { padding: 14px 13px 90px; }
  .topbar { padding: 10px 13px; }
  .topbar h1 { font-size: 15.5px; }
  .topbar .sub { display: none; }
  .mobile-only { display: inline-flex; }
  .modal { width: 100%; }
  .card { padding: 14px 14px; }
  .tbl-wrap { margin: 0 -14px; padding: 0 14px; }
  .device-select { min-width: 0; flex: 1 1 auto; }
}

.bottombar {
  display: none; position: fixed; bottom: 0; left: 0; right: 0; z-index: 100;
  background: #0e1728f2; border-top: 1px solid var(--line); backdrop-filter: blur(10px);
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
}
@media (max-width: 900px) {
  .bottombar { display: flex; }
  .bb-item { flex: 1 1 0; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 5px 2px; font-size: 10px; color: #93a4c0; cursor: pointer; border-radius: 9px; }
  .bb-item .ico { font-size: 16px; line-height: 1; }
  .bb-item.active { color: var(--blue); background: #17233c; }
}

/* ============================ 主题风格 ============================ */
html[data-theme="dark"] {
  --bg: #05070c;
  --panel: #0d1119;
  --panel2: #121824;
  --panel3: #18202d;
  --line: #1f2937;
  --line2: #2c3849;
  --text: #f3f6fb;
  --muted: #93a1b8;
  --muted2: #68778f;
  --cyan: #53d6c6;
  --green: #42d5a0;
  --red: #ff7888;
  --amber: #e5ad58;
  --purple: #d3a0ff;
  --shadow: 0 10px 30px #0009;
  color-scheme: dark;
}

html[data-theme="light"] {
  --bg: #f2f5fb;
  --panel: #fff;
  --panel2: #fff;
  --panel3: #f0f4fa;
  --line: #dce3ef;
  --line2: #c4d0e2;
  --text: #1b2740;
  --muted: #60708a;
  --muted2: #8593a9;
  --blue: #2d6cdf;
  --blue2: #1f5fd0;
  --cyan: #0b8f86;
  --green: #16855f;
  --red: #d94b61;
  --amber: #b57a1e;
  --purple: #8a5bc7;
  --shadow: 0 8px 24px #1b27400f;
  color-scheme: light;
}

html[data-theme="glass"] {
  --bg: #dbe7fb;
  --panel: rgba(255,255,255,.62);
  --panel2: rgba(255,255,255,.78);
  --panel3: rgba(255,255,255,.92);
  --line: rgba(255,255,255,.72);
  --line2: rgba(110,140,190,.35);
  --text: #182640;
  --muted: #59709a;
  --muted2: #7f92b0;
  --blue: #2b6ff0;
  --blue2: #1f5fd0;
  --cyan: #0b9088;
  --green: #16855f;
  --red: #d94b61;
  --amber: #b57a1e;
  --purple: #8a5bc7;
  --shadow: 0 10px 32px rgba(39,74,140,.16);
  color-scheme: light;
}

html[data-theme="dark"] body {
  background: radial-gradient(ellipse at 15% -15%, #101a2e 0, transparent 42%), var(--bg);
}
html[data-theme="light"] body { background: var(--bg); }
html[data-theme="glass"] body {
  background: radial-gradient(circle at 12% 8%, #ffd9ec 0, transparent 34%),
              radial-gradient(circle at 88% 92%, #a9d8ff 0, transparent 38%),
              linear-gradient(135deg, #eef3ff, #dbe7fb);
}

html[data-theme="light"] .sidebar,
html[data-theme="glass"] .sidebar {
  background: linear-gradient(180deg, rgba(255,255,255,.92), rgba(239,244,252,.82));
}
html[data-theme="dark"] .sidebar { background: linear-gradient(180deg, #0a0e16 0, #070a11 100%); }
html[data-theme="light"] .nav-item,
html[data-theme="glass"] .nav-item { color: #445775; }
html[data-theme="light"] .nav-item:hover,
html[data-theme="glass"] .nav-item:hover { background: rgba(45,108,223,.1); color: #1b2740; }
html[data-theme="light"] .nav-item.active,
html[data-theme="glass"] .nav-item.active { background: linear-gradient(100deg, rgba(45,108,223,.2), rgba(45,108,223,.08)); color: #1b2740; border-color: rgba(45,108,223,.3); }

html[data-theme="light"] .topbar,
html[data-theme="light"] .bottombar { background: rgba(255,255,255,.9); }
html[data-theme="glass"] .topbar,
html[data-theme="glass"] .bottombar { background: rgba(255,255,255,.62); }
html[data-theme="dark"] .topbar,
html[data-theme="dark"] .bottombar { background: rgba(5,7,12,.82); }

html[data-theme="light"] .btn,
html[data-theme="glass"] .btn { background: #eef2f8; color: #293b56; border-color: #d4dfef; }
html[data-theme="light"] .btn.ghost,
html[data-theme="glass"] .btn.ghost { background: transparent; }
html[data-theme="light"] .btn.danger,
html[data-theme="glass"] .btn.danger { background: #fdecef; color: #b83248; border-color: #f2c4cc; }
html[data-theme="light"] .btn.primary,
html[data-theme="glass"] .btn.primary { background: linear-gradient(135deg, var(--blue), #5b95f6); color: #fff; border-color: transparent; }

html[data-theme="light"] .pill,
html[data-theme="glass"] .pill { background: #eef2f8; color: #334764; border-color: #d4dfef; }
html[data-theme="light"] .badge.blue,
html[data-theme="glass"] .badge.blue { background: #e3edff; color: #2455a8; }
html[data-theme="light"] .badge.green,
html[data-theme="glass"] .badge.green { background: #dcf5e9; color: #146b4e; }
html[data-theme="light"] .badge.red,
html[data-theme="glass"] .badge.red { background: #fde6ea; color: #b83248; }
html[data-theme="light"] .badge.amber,
html[data-theme="glass"] .badge.amber { background: #f9eed6; color: #8a5c13; }
html[data-theme="light"] .badge.purple,
html[data-theme="glass"] .badge.purple { background: #efe6fb; color: #6d3ea8; }

html[data-theme="light"] ::-webkit-scrollbar-thumb,
html[data-theme="glass"] ::-webkit-scrollbar-thumb { background: #c3cfe0; }

html[data-theme="glass"] .card,
html[data-theme="glass"] .topbar,
html[data-theme="glass"] .sidebar,
html[data-theme="glass"] .bottombar {
  backdrop-filter: blur(18px) saturate(160%);
  -webkit-backdrop-filter: blur(18px) saturate(160%);
}
html[data-theme="glass"] .card {
  background: linear-gradient(160deg, rgba(255,255,255,.82), rgba(255,255,255,.55));
  border-color: rgba(255,255,255,.85);
}

select.sel { width: auto; min-width: 96px; }
select.sel.sm {
  font-size: 12px; padding: 5px 26px 5px 9px; min-height: 30px;
  background-position: calc(100% - 12px) 12px, calc(100% - 8px) 12px;
}

