:root {
  --bg: #0c1017;
  --bg-soft: #111722;
  --surface: #161e2c;
  --surface-2: #1c2638;
  --border: #243046;
  --border-soft: #1a2333;
  --text: #e6ecf5;
  --muted: #8b97ab;
  --accent: #38bdf8;
  --accent-soft: rgba(56, 189, 248, .14);
  --ok: #34d399;
  --warn: #fbbf24;
  --bad: #f87171;
  --info: #a78bfa;
  --radius: 14px;
  --mono: ui-monospace, "Cascadia Mono", "JetBrains Mono", Consolas, monospace;
  --sans: -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei", Roboto, sans-serif;
}

/* 亮色主题（关闭夜间模式时启用） */
[data-theme="light"] {
  --bg: #f2f5f9;
  --bg-soft: #e9eef5;
  --surface: #ffffff;
  --surface-2: #eef1f7;
  --border: #d4dce8;
  --border-soft: #e2e8f1;
  --text: #1c2637;
  --muted: #5d6b81;
  --accent: #0284c7;
  --accent-soft: rgba(2, 132, 199, .12);
  --info: #7c5cf0;
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  background:
    radial-gradient(1200px 500px at 15% -10%, rgba(56, 189, 248, .08), transparent 60%),
    radial-gradient(900px 420px at 90% -10%, rgba(167, 139, 250, .07), transparent 60%),
    var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.5;
  min-height: 100vh;
}

/* ---------- Top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 28px;
  border-bottom: 1px solid var(--border-soft);
  background: linear-gradient(180deg, rgba(255,255,255,.02), transparent);
  position: sticky;
  top: 0;
  z-index: 20;
  backdrop-filter: blur(8px);
  background-color: rgba(42, 52, 70, .5);
}
[data-theme="light"] .topbar {
  background-color: rgba(255, 255, 255, .72);
}
[data-theme="light"] .topbar .brand-text h1,
[data-theme="light"] .topbar .conn { color: var(--text); }
[data-theme="light"] .topbar .brand-text p { color: var(--muted); }
.brand { display: flex; align-items: center; gap: 12px; }
.topbar .btn.icon-btn {
  width: 36px; height: 36px; padding: 0;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 20px; line-height: 1;
}
.brand-mark {
  width: 42px; height: 42px;
  display: grid; place-items: center;
  color: var(--accent);
  background: var(--accent-soft);
  border: 1px solid rgba(56,189,248,.25);
  border-radius: 12px;
}
.brand h1 { margin: 0; font-size: 17px; letter-spacing: .2px; }
.brand p { margin: 2px 0 0; font-size: 12px; color: var(--muted); }

.topbar-right { display: flex; align-items: center; gap: 18px; }
.conn { display: inline-flex; align-items: center; gap: 7px; font-size: 12.5px; color: var(--muted); }
.conn .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--warn); box-shadow: 0 0 8px var(--warn); }
.conn.ok .dot { background: var(--ok); box-shadow: 0 0 8px var(--ok); }
.conn.off .dot { background: var(--bad); box-shadow: 0 0 8px var(--bad); }

.ctrl { display: inline-flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--muted); }
.ctrl select {
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px;
  padding: 5px 8px; font: inherit; font-size: 12.5px; cursor: pointer;
}
.btn {
  background: var(--accent); color: #06121b;
  border: none; border-radius: 9px;
  padding: 7px 14px; font: inherit; font-weight: 600; font-size: 12.5px;
  cursor: pointer; transition: filter .15s, transform .05s;
}
.btn:hover { filter: brightness(1.1); }
.btn:active { transform: translateY(1px); }
.btn.ghost {
  background: transparent; color: var(--muted);
  border: 1px solid var(--border); font-weight: 500;
}
.btn.ghost:hover { color: var(--text); border-color: var(--muted); }

/* ---------- Layout ---------- */
main { padding: 26px 28px 10px; max-width: 1460px; margin: 0 auto; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.section-head h2 { margin: 0; font-size: 15px; font-weight: 700; letter-spacing: .3px; }
.muted { color: var(--muted); font-size: 12.5px; }

.hidden { display: none !important; }

/* ---------- Device grid ---------- */
.device-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 16px;
}
.device-card {
  background: linear-gradient(180deg, var(--surface), var(--bg-soft));
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: 16px 18px 14px;
  cursor: pointer;
  transition: border-color .18s, transform .18s, box-shadow .18s;
}
.device-card:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
  box-shadow: 0 10px 26px rgba(0,0,0,.35);
}
.device-card.offline { opacity: .62; }

.dc-head { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 12px; }
.dc-title { display: flex; align-items: center; gap: 9px; min-width: 0; }
.dc-name { font-size: 15px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dc-ip { font-family: var(--mono); font-size: 12px; color: var(--muted); margin-top: 1px; }
.status-pill {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 11.5px; font-weight: 600; padding: 3px 9px; border-radius: 99px;
  white-space: nowrap;
}
.status-pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.status-pill.online { color: var(--ok); background: rgba(52,211,153,.1); }
.status-pill.offline { color: var(--bad); background: rgba(248,113,113,.1); }

.dc-metrics { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.gauge { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.gauge .g-label { font-size: 11px; color: var(--muted); letter-spacing: .4px; }
.gauge svg { width: 52px; height: 52px; display: block; }

.dc-foot { display: flex; align-items: center; justify-content: space-between; margin-top: 12px; padding-top: 10px; border-top: 1px dashed var(--border-soft); }
.dc-spark { flex: 1; min-width: 0; margin-right: 12px; }
.dc-spark svg { width: 100%; height: 30px; display: block; }
.dc-meta { text-align: right; font-size: 11.5px; color: var(--muted); white-space: nowrap; }
.dc-meta b { color: var(--text); font-weight: 600; font-family: var(--mono); }
.dc-meta > div { margin: 2px 0; }
.docker-box { display: flex; flex-direction: column; gap: 8px; padding: 8px 2px; }
.docker-line { font-size: 13px; color: var(--text); }
.docker-box .state-badge { align-self: flex-start; }
.app-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.app-table th { text-align: left; color: var(--muted); font-weight: 600; padding: 4px 8px; border-bottom: 1px solid var(--border, rgba(255,255,255,.08)); }
.app-table td { padding: 6px 8px; border-bottom: 1px solid var(--border, rgba(255,255,255,.06)); }
.app-table td.l { font-weight: 600; color: var(--text); }
.app-table td.c { text-align: center; }
.app-table td.c .state-badge { display: inline-block; }

/* ---------- Detail ---------- */
#detail { margin-top: 30px; padding-top: 22px; border-top: 1px solid var(--border-soft); }

.detail-shell { display: grid; grid-template-columns: 1fr; gap: 16px; }
.detail-top {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 14px;
}
.stat-band {
  background: var(--surface); border: 1px solid var(--border-soft);
  border-radius: var(--radius); padding: 14px 16px;
}
.big-gauge { display: flex; align-items: center; gap: 16px; }
.big-gauge svg { width: 92px; height: 92px; }
.bg-info .bg-title { font-size: 13px; font-weight: 700; }
.bg-info .bg-val { font-size: 26px; font-weight: 800; font-family: var(--mono); letter-spacing: .5px; margin: 2px 0; }
.bg-info .bg-sub { font-size: 12px; color: var(--muted); }

.host-stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.host-stat { background: var(--surface); border: 1px solid var(--border-soft); border-radius: 10px; padding: 10px 12px; }
.host-stat .hs-label { font-size: 11px; color: var(--muted); }
.host-stat .hs-value { font-size: 14px; font-weight: 600; font-family: var(--mono); margin-top: 2px; }

.panel {
  background: var(--surface); border: 1px solid var(--border-soft);
  border-radius: var(--radius); padding: 16px 18px;
}
.panel h3 { margin: 0 0 12px; font-size: 13px; font-weight: 700; letter-spacing: .4px; }
.panel-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.panel-col { display: flex; flex-direction: column; gap: 16px; align-items: stretch; }

.chart-wrap svg { width: 100%; height: 150px; display: block; }
.chart-legend { display: flex; gap: 16px; margin-top: 8px; font-size: 11.5px; color: var(--muted); flex-wrap: wrap; }
.legend-item { display: inline-flex; align-items: center; gap: 6px; }
.legend-item .swatch { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
th {
  text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .6px;
  color: var(--muted); font-weight: 600; padding: 6px 10px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
td { padding: 7px 10px; border-bottom: 1px solid var(--border-soft); white-space: nowrap; font-family: var(--mono); }
td:first-child { font-family: var(--sans); }
tr:last-child td { border-bottom: none; }
tr:hover td { background: rgba(255,255,255,.02); }

.state-badge { display: inline-flex; align-items: center; gap: 6px; font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 99px; font-family: var(--sans); }
.state-badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.state-badge.run, .state-badge.active { color: var(--ok); background: rgba(52,211,153,.1); }
.state-badge.exited { color: var(--muted); background: rgba(139,151,171,.12); }
.state-badge.dead, .state-badge.failed { color: var(--bad); background: rgba(248,113,113,.1); }
.state-badge.waiting { color: var(--warn); background: rgba(251,191,36,.1); }
.state-badge.not-found, .state-badge.inactive { color: var(--warn); background: rgba(251,191,36,.1); }

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

/* ---------- 告警铃铛 ---------- */
.bell {
  position: relative;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 9px;
  width: 36px; height: 34px;
  display: grid; place-items: center;
  color: var(--muted);
  cursor: pointer;
  transition: color .15s, border-color .15s;
}
.bell:hover { color: var(--text); border-color: var(--accent); }
.bell-badge {
  position: absolute;
  top: -6px; right: -6px;
  min-width: 17px; height: 17px;
  padding: 0 4px;
  border-radius: 99px;
  background: var(--bad);
  color: #fff;
  font-size: 10.5px;
  font-weight: 700;
  display: grid; place-items: center;
  box-shadow: 0 0 0 2px var(--bg);
}
.bell-badge.hidden { display: none; }

/* ---------- 告警面板 ---------- */
.alert-panel {
  position: fixed;
  top: 64px;
  right: 20px;
  width: min(400px, calc(100vw - 32px));
  max-height: 70vh;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 18px 50px rgba(0,0,0,.45);
  z-index: 40;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.alert-panel.hidden { display: none; }
.alert-panel-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-soft);
  font-weight: 700; font-size: 13px;
}
.btn.small { padding: 4px 10px; font-size: 12px; }
.alert-panel-actions { display: flex; align-items: center; gap: 8px; }
.btn.danger { color: var(--bad); border-color: var(--bad); }
.btn.danger:hover { background: rgba(220, 88, 88, .12); }
.alert-list { overflow-y: auto; padding: 6px 0; }
.alert-item {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border-soft);
}
.alert-item:last-child { border-bottom: none; }
.alert-item .a-dot {
  width: 8px; height: 8px; border-radius: 50%;
  margin-top: 5px; flex: none;
}
.alert-item .a-dot.warning { background: var(--warn); box-shadow: 0 0 8px var(--warn); }
.alert-item .a-dot.critical { background: var(--bad); box-shadow: 0 0 8px var(--bad); }
.alert-item .a-body { flex: 1; min-width: 0; }
.alert-item .a-msg { font-size: 12.5px; line-height: 1.45; word-break: break-word; }
.alert-item .a-meta { margin-top: 3px; font-size: 11px; color: var(--muted); }
.alert-item .a-ack {
  flex: none; background: transparent; border: 1px solid var(--border);
  color: var(--muted); border-radius: 7px; font: inherit; font-size: 11px;
  padding: 3px 8px; cursor: pointer;
}
.alert-item .a-ack:hover { color: var(--text); border-color: var(--muted); }
.alert-item.acked { opacity: .55; }
.alert-empty { padding: 22px; text-align: center; color: var(--muted); font-size: 12.5px; }

/* ---------- Toast ---------- */
.toasts {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 60;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: min(360px, calc(100vw - 32px));
}
.toast {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--warn);
  border-radius: 10px;
  padding: 11px 14px;
  box-shadow: 0 12px 34px rgba(0,0,0,.4);
  font-size: 12.5px;
  line-height: 1.45;
  animation: toastIn .25s ease;
}
.toast.critical { border-left-color: var(--bad); }
.toast .toast-title { font-weight: 700; margin-bottom: 2px; }
.toast .toast-close { float: right; background: none; border: none; color: var(--muted); cursor: pointer; font-size: 13px; }
@keyframes toastIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.section-actions { display: flex; align-items: center; gap: 12px; }

/* ---------- 管理设置弹窗 ---------- */
.modal {
  position: fixed; inset: 0;
  background: rgba(5, 8, 14, .55);
  z-index: 50;
  display: grid; place-items: center;
  padding: 20px;
}
.modal.hidden { display: none; }
.modal-card {
  width: min(720px, 100%);
  max-height: 86vh;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: 0 30px 80px rgba(0,0,0,.5);
  display: flex; flex-direction: column;
  overflow: hidden;
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-soft);
}
.modal-head h2 { margin: 0; font-size: 15px; }

.tabs { display: flex; gap: 4px; padding: 10px 16px 0; border-bottom: 1px solid var(--border-soft); }
.tab {
  background: transparent; border: none; cursor: pointer;
  color: var(--muted); font: inherit; font-size: 13px; font-weight: 600;
  padding: 9px 14px; border-bottom: 2px solid transparent;
  transition: color .15s, border-color .15s;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }

.tab-pane { display: none; padding: 18px 20px 20px; overflow-y: auto; }
.tab-pane.active { display: block; }

/* 设备管理 */
.device-mgr-list { margin-bottom: 16px; }
.dm-head { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); padding: 4px 2px 8px; }
.dm-item {
  display: flex; align-items: center; gap: 12px;
  padding: 9px 12px; margin-bottom: 6px;
  background: var(--surface-2);
  border: 1px solid var(--border-soft);
  border-radius: 10px;
}
.dm-item .dm-status { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.dm-item .dm-status.on { background: var(--ok); box-shadow: 0 0 6px var(--ok); }
.dm-item .dm-status.off { background: var(--bad); box-shadow: 0 0 6px var(--bad); }
.dm-item .dm-info { flex: 1; min-width: 0; }
.dm-item .dm-name { font-weight: 700; font-size: 13px; }
.dm-item .dm-host { font-family: var(--mono); font-size: 11.5px; color: var(--muted); }
.dm-item .dm-actions { display: flex; gap: 6px; flex: none; }
.dm-item .dm-btn {
  background: transparent; border: 1px solid var(--border);
  color: var(--muted); border-radius: 7px; font: inherit; font-size: 11.5px;
  padding: 4px 10px; cursor: pointer;
}
.dm-item .dm-btn:hover { color: var(--text); border-color: var(--muted); }
.dm-item .dm-btn.danger:hover { color: var(--bad); border-color: var(--bad); }

.device-form {
  background: var(--surface-2);
  border: 1px dashed var(--border);
  border-radius: 12px;
  padding: 16px;
}
.device-form h3,
.tab-pane h3 { margin: 0 0 12px; font-size: 13px; font-weight: 700; }
.alert-form h3 + .form-grid { margin-bottom: 6px; }
.alert-form h3 { margin-top: 18px; }
.alert-form h3:first-child { margin-top: 0; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.field label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.field input {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font: inherit; font-size: 13px;
  padding: 8px 10px;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.field input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.form-actions { display: flex; align-items: center; gap: 10px; margin-top: 14px; flex-wrap: wrap; }
.form-msg { font-size: 12px; color: var(--muted); }
.form-msg.ok { color: var(--ok); }
.form-msg.err { color: var(--bad); }

/* 账户 / 外观 */
.form-stack .field { margin-bottom: 14px; }
.appearance-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; padding: 6px 2px;
}
.appearance-title { font-size: 13.5px; font-weight: 600; }
.appearance-desc { font-size: 12px; color: var(--muted); margin-top: 3px; }
.switch { position: relative; display: inline-block; width: 46px; height: 25px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .slider {
  position: absolute; inset: 0; cursor: pointer;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 99px; transition: background .2s;
}
.switch .slider::before {
  content: ""; position: absolute; width: 17px; height: 17px;
  left: 3px; top: 3px; border-radius: 50%;
  background: var(--muted); transition: transform .2s, background .2s;
}
.switch input:checked + .slider { background: var(--accent); border-color: var(--accent); }
.switch input:checked + .slider::before { transform: translateX(21px); background: #fff; }

.foot { text-align: center; padding: 26px 0 22px; }

@media (max-width: 760px) {
  .topbar { flex-direction: column; align-items: flex-start; padding: 14px 16px; }
  .topbar-right { width: 100%; flex-wrap: wrap; gap: 10px; }
  main { padding: 18px 14px 8px; }
  .panel-grid { grid-template-columns: 1fr; }
  .device-grid { grid-template-columns: 1fr; }
}
