:root {
  --bg: #0b0910;
  --bg2: #110e17;
  --panel: #17131f;
  --panel2: #1e1928;
  --line: #2b2438;
  --line2: #3a3049;
  --text: #efeaf7;
  --muted: #9c93ad;
  --accent: #e0447a;
  --accent2: #8b5cf6;
  --ok: #3ddc97;
  --warn: #f3b74d;
  --bad: #ff5f6d;
  --radius: 12px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background:
    radial-gradient(1200px 600px at 80% -10%, rgba(224, 68, 122, 0.12), transparent 60%),
    radial-gradient(900px 500px at 0% 100%, rgba(139, 92, 246, 0.12), transparent 60%),
    var(--bg);
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 14px;
  line-height: 1.55;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.error-text { color: var(--bad); min-height: 20px; font-size: 13px; }
.pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 10px; border-radius: 999px; font-size: 12px;
  background: var(--panel2); border: 1px solid var(--line); color: var(--muted);
}
.pill.ok { color: var(--ok); border-color: rgba(61, 220, 151, 0.35); }
.pill.bad { color: var(--bad); border-color: rgba(255, 95, 109, 0.35); }
.pill.warn { color: var(--warn); border-color: rgba(243, 183, 77, 0.35); }

/* ---------- login ---------- */
.login-screen {
  min-height: 100%;
  display: grid; place-items: center; padding: 24px;
}
.login-card {
  width: min(420px, 100%);
  background: linear-gradient(180deg, rgba(30, 25, 40, 0.96), rgba(20, 16, 28, 0.96));
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 28px;
  box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 12px;
}
.login-logo, .logo {
  width: 44px; height: 44px; border-radius: 12px;
  display: grid; place-items: center;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  color: white; font-weight: 800; letter-spacing: 0.5px;
}
.login-card h1 { margin: 4px 0 0; font-size: 22px; }
.login-card label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
.login-card input {
  background: var(--bg2); border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 12px; outline: none;
}
.login-card input:focus { border-color: var(--accent2); }
.login-foot { color: var(--muted); font-size: 12px; margin-top: 4px; word-break: break-all; }

/* ---------- layout ---------- */
.app {
  height: 100vh;
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
}
.sidebar {
  min-height: 0;
  display: flex; flex-direction: column;
  border-right: 1px solid var(--line);
  background: rgba(17, 14, 23, 0.75);
  backdrop-filter: blur(10px);
}
.brand { display: flex; align-items: center; gap: 10px; padding: 18px 16px 12px; }
.brand b { display: block; font-size: 15px; letter-spacing: 0.3px; }
.brand small { color: var(--muted); font-size: 11px; }
.list-head { display: flex; gap: 8px; padding: 6px 12px 10px; }
.list-head input {
  flex: 1; min-width: 0; background: var(--panel); border: 1px solid var(--line);
  border-radius: 9px; padding: 8px 10px; outline: none;
}
.list-head input:focus { border-color: var(--accent2); }
.icon-btn {
  width: 36px; border-radius: 9px; background: var(--panel); border: 1px solid var(--line);
  color: var(--muted); font-size: 16px;
}
.icon-btn:hover { color: var(--text); border-color: var(--line2); }
.device-list { flex: 1; overflow-y: auto; padding: 0 8px 12px; }
.device-item {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 10px; border-radius: 10px; cursor: pointer;
  border: 1px solid transparent;
}
.device-item:hover { background: var(--panel); }
.device-item.active { background: linear-gradient(135deg, rgba(224, 68, 122, 0.16), rgba(139, 92, 246, 0.12)); border-color: rgba(224, 68, 122, 0.3); }
.device-dot { width: 8px; height: 8px; border-radius: 50%; margin-top: 7px; background: var(--muted); flex: none; }
.device-dot.online { background: var(--ok); box-shadow: 0 0 10px rgba(61, 220, 151, 0.8); }
.device-meta { min-width: 0; flex: 1; }
.device-meta b { display: block; font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.device-meta small { display: block; color: var(--muted); font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.badge {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 18px; height: 18px; padding: 0 6px; border-radius: 999px;
  background: var(--accent); color: white; font-size: 11px; font-weight: 700;
}
.sidebar-foot { display: flex; gap: 8px; padding: 12px; border-top: 1px solid var(--line); }

/* ---------- main ---------- */
.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  height: 58px; flex: none;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 0 20px; border-bottom: 1px solid var(--line);
  background: rgba(11, 9, 16, 0.65); backdrop-filter: blur(8px);
}
#topTitle { font-weight: 650; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar-right { display: flex; align-items: center; gap: 10px; }
.stats { color: var(--muted); font-size: 12px; white-space: nowrap; }
.content { flex: 1; overflow-y: auto; padding: 18px 20px 60px; }

.empty-state { height: 100%; min-height: 300px; display: grid; place-items: center; align-content: center; gap: 10px; color: var(--muted); }
.empty-icon { font-size: 42px; opacity: 0.35; }

/* ---------- tabs ---------- */
.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 16px; }
.tab {
  padding: 7px 12px; border-radius: 9px; border: 1px solid var(--line);
  background: transparent; color: var(--muted); font-size: 13px;
}
.tab:hover { color: var(--text); border-color: var(--line2); }
.tab.active { background: var(--panel2); color: var(--text); border-color: var(--line2); }

/* ---------- cards / forms ---------- */
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; }
.card {
  background: linear-gradient(180deg, rgba(30, 25, 40, 0.85), rgba(23, 19, 31, 0.85));
  border: 1px solid var(--line); border-radius: var(--radius); padding: 14px;
}
.card h3 { margin: 0 0 10px; font-size: 13px; color: var(--muted); font-weight: 600; letter-spacing: 0.3px; }
.kv { display: flex; justify-content: space-between; gap: 12px; padding: 5px 0; border-bottom: 1px dashed rgba(255,255,255,0.05); font-size: 13px; }
.kv:last-child { border-bottom: none; }
.kv span:first-child { color: var(--muted); flex: none; }
.kv span:last-child { text-align: right; word-break: break-all; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; }
pre.code {
  margin: 0; padding: 12px; border-radius: 10px; background: var(--bg2);
  border: 1px solid var(--line); overflow: auto; max-height: 340px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px;
}

label.field { display: flex; flex-direction: column; gap: 6px; font-size: 12px; color: var(--muted); margin-bottom: 10px; }
input, textarea, select {
  background: var(--bg2); border: 1px solid var(--line); border-radius: 9px;
  padding: 9px 10px; outline: none; width: 100%;
}
input:focus, textarea:focus, select:focus { border-color: var(--accent2); }
textarea { min-height: 76px; resize: vertical; }
input[type="checkbox"] { width: auto; accent-color: var(--accent); }
.check { flex-direction: row; align-items: center; gap: 8px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; }
.row > * { flex: 1 1 180px; }
.actions-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }

button.primary {
  background: linear-gradient(135deg, var(--accent), #c53264);
  border: none; color: white; padding: 10px 16px; border-radius: 9px; font-weight: 600;
}
button.primary:hover { filter: brightness(1.08); }
button.ghost {
  background: var(--panel); border: 1px solid var(--line); color: var(--text);
  padding: 8px 12px; border-radius: 9px; font-size: 13px;
}
button.ghost:hover { border-color: var(--line2); }
button.ghost.danger { color: var(--bad); }
button.ghost.ok { color: var(--ok); }
button.mini { padding: 5px 9px; font-size: 12px; border-radius: 7px; }
button:disabled { opacity: 0.5; cursor: not-allowed; }

/* ---------- device header ---------- */
.device-head { display: flex; align-items: center; gap: 14px; margin-bottom: 16px; flex-wrap: wrap; }
.device-avatar {
  width: 46px; height: 46px; border-radius: 14px; display: grid; place-items: center;
  background: linear-gradient(135deg, rgba(224, 68, 122, 0.9), rgba(139, 92, 246, 0.9));
  font-weight: 800; color: #fff;
}
.device-head h2 { margin: 0; font-size: 18px; }
.device-head .sub { color: var(--muted); font-size: 12px; }
.spacer { flex: 1; }

/* ---------- chat ---------- */
.chat-wrap { display: flex; flex-direction: column; height: calc(100vh - 220px); min-height: 360px; }
.chat-log { flex: 1; overflow-y: auto; padding: 8px 4px 12px; display: flex; flex-direction: column; gap: 10px; }
.msg { max-width: min(720px, 82%); padding: 9px 12px; border-radius: 12px; background: var(--panel2); border: 1px solid var(--line); white-space: pre-wrap; word-break: break-word; }
.msg .msg-meta { font-size: 10px; color: var(--muted); margin-top: 4px; }
.msg.client { align-self: flex-start; border-bottom-left-radius: 4px; }
.msg.admin { align-self: flex-end; background: linear-gradient(135deg, rgba(224, 68, 122, 0.28), rgba(139, 92, 246, 0.2)); border-color: rgba(224, 68, 122, 0.35); border-bottom-right-radius: 4px; }
.msg.system { align-self: center; max-width: 92%; background: transparent; border-style: dashed; color: var(--muted); font-size: 12px; }
.msg .role { font-size: 11px; color: var(--muted); margin-bottom: 3px; }
.chat-compose { display: flex; gap: 8px; align-items: flex-end; padding-top: 10px; border-top: 1px solid var(--line); }
.chat-compose textarea { min-height: 44px; max-height: 140px; }
.chat-compose button { flex: none; }

/* ---------- tables / lists ---------- */
table.list { width: 100%; border-collapse: collapse; font-size: 13px; }
table.list th, table.list td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.list th { color: var(--muted); font-weight: 600; font-size: 12px; }
table.list tr:hover td { background: rgba(255,255,255,0.02); }
.tag { display: inline-block; padding: 1px 7px; border-radius: 999px; font-size: 11px; border: 1px solid var(--line2); color: var(--muted); }
.tag.ok { color: var(--ok); border-color: rgba(61,220,151,0.35); }
.tag.bad { color: var(--bad); border-color: rgba(255,95,109,0.35); }
.tag.warn { color: var(--warn); border-color: rgba(243,183,77,0.35); }

.shot-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 10px; }
.shot { border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: var(--panel); }
.shot img { display: block; width: 100%; height: 120px; object-fit: cover; background: #000; }
.shot .shot-meta { padding: 6px 8px; font-size: 11px; color: var(--muted); }

/* ---------- toast / modal ---------- */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px);
  background: var(--panel2); border: 1px solid var(--line2); color: var(--text);
  padding: 10px 16px; border-radius: 10px; box-shadow: var(--shadow);
  opacity: 0; pointer-events: none; transition: all .2s ease; z-index: 50; max-width: 80vw;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.ok { border-color: rgba(61,220,151,0.45); }
.toast.bad { border-color: rgba(255,95,109,0.45); }

.modal { position: fixed; inset: 0; background: rgba(5, 4, 8, 0.7); display: grid; place-items: center; z-index: 60; padding: 20px; }
.modal-box { width: min(520px, 100%); background: var(--panel); border: 1px solid var(--line2); border-radius: 14px; padding: 18px; box-shadow: var(--shadow); }
.modal-box h3 { margin: 0 0 10px; }
.modal-box p { color: var(--muted); }

/* ---------- responsive ---------- */
@media (max-width: 820px) {
  .app { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .sidebar { border-right: none; border-bottom: 1px solid var(--line); max-height: 38vh; }
  .device-list { max-height: 20vh; }
  .content { padding: 14px; }
  .chat-wrap { height: calc(100vh - 330px); }
  .topbar { padding: 0 12px; }
}
