:root {
  --bg: #0f1720;
  --bg-2: #16212e;
  --panel: #1c2a3a;
  --border: #26364a;
  --text: #e6edf3;
  --muted: #8797a8;
  --primary: #2f81f7;
  --primary-2: #1f6feb;
  --danger: #e5484d;
  --warn: #e3a008;
  --ok: #3fb950;
  --radius: 10px;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}
.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 13px; }
.error { color: var(--danger); margin-top: 10px; min-height: 18px; font-size: 13px; }

/* Buttons */
.btn {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 8px 12px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 13px;
  transition: background .15s, border-color .15s;
}
.btn:hover { background: var(--bg-2); border-color: var(--primary); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; width: 100%; padding: 11px; font-weight: 600; }
.btn-primary:hover { background: var(--primary-2); }
.btn-ghost { background: transparent; }
.btn-sm { padding: 5px 9px; font-size: 12px; }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-warn { background: var(--warn); border-color: var(--warn); color: #1a1a1a; }

/* Login */
.login-wrap { display: flex; align-items: center; justify-content: center; height: 100vh; }
.login-card {
  background: var(--bg-2);
  border: 1px solid var(--border);
  padding: 32px;
  border-radius: 14px;
  width: 340px;
}
.login-card h1 { margin: 0 0 4px; font-size: 22px; }
.login-card label { display: block; margin: 16px 0 6px; font-size: 13px; color: var(--muted); }
.login-card input {
  width: 100%;
  padding: 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
}
.login-card button { margin-top: 22px; }

/* Topbar */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 20px; background: var(--bg-2); border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; }
.topbar-right { display: flex; align-items: center; gap: 12px; }
.ws-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--muted); display: inline-block; }
.ws-dot.on { background: var(--ok); }

/* Layout */
.layout { display: flex; height: calc(100vh - 49px); }
.sidebar { width: 280px; border-right: 1px solid var(--border); background: var(--bg-2); overflow-y: auto; }
.sidebar-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 16px; font-weight: 600; border-bottom: 1px solid var(--border); }
.device-list { list-style: none; margin: 0; padding: 0; }
.device-item { padding: 12px 16px; border-bottom: 1px solid var(--border); cursor: pointer; }
.device-item:hover { background: var(--panel); }
.device-item.active { background: var(--panel); border-left: 3px solid var(--primary); }
.device-item .dv-name { font-weight: 600; display: flex; align-items: center; gap: 8px; }
.device-item .dv-meta { font-size: 12px; color: var(--muted); margin-top: 3px; }
.status-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); display: inline-block; }
.status-dot.online { background: var(--ok); }
.mini-badge { background: var(--danger); color: #fff; border-radius: 10px; font-size: 11px; padding: 1px 7px; margin-left: auto; }

/* Content */
.content { flex: 1; overflow-y: auto; padding: 20px; }
.empty { display: flex; height: 100%; align-items: center; justify-content: center; color: var(--muted); }
.detail-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; }
.detail-head h2 { margin: 0 0 4px; }
.detail-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* Tabs */
.tabs { display: flex; gap: 4px; margin: 18px 0 14px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.tab { background: transparent; border: none; color: var(--muted); padding: 10px 14px; cursor: pointer; border-bottom: 2px solid transparent; font-size: 13px; }
.tab:hover { color: var(--text); }
.tab.active { color: var(--text); border-bottom-color: var(--primary); }
.badge { background: var(--danger); color: #fff; border-radius: 10px; font-size: 11px; padding: 0 6px; }

.tab-panel { animation: fade .15s ease; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.panel-toolbar { display: flex; gap: 8px; align-items: center; margin-bottom: 12px; }
.panel-toolbar input, .panel-toolbar select {
  padding: 7px 10px; background: var(--bg-2); border: 1px solid var(--border); border-radius: var(--radius); color: var(--text);
}

/* Map */
#map { height: 60vh; border-radius: var(--radius); border: 1px solid var(--border); }

/* Grids */
.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
.photo-cell {
  position: relative; background: var(--bg-2); border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden; aspect-ratio: 1; cursor: pointer;
}
.photo-cell img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo-cell .cell-tag { position: absolute; top: 6px; left: 6px; background: rgba(0,0,0,.6); font-size: 10px; padding: 2px 6px; border-radius: 6px; }
.photo-cell .cell-status { position: absolute; bottom: 6px; right: 6px; background: rgba(0,0,0,.6); font-size: 10px; padding: 2px 6px; border-radius: 6px; }
.photo-cell .cell-play { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 28px; color: #fff; text-shadow: 0 0 8px #000; }

/* Lists */
.alert-list, .activity-list, .command-list { list-style: none; margin: 0; padding: 0; }
.alert-list li, .command-list li { padding: 12px 14px; border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 8px; background: var(--bg-2); }
.alert-list li.unseen { border-left: 3px solid var(--danger); }
.alert-list .alert-actions { margin-top: 8px; display: flex; gap: 8px; }
.activity-list li { padding: 9px 12px; border-bottom: 1px solid var(--border); font-size: 13px; }
.activity-list .act-meta { color: var(--muted); font-size: 11px; margin-bottom: 2px; }
.activity-list .act-text { white-space: pre-wrap; word-break: break-word; }
.time { color: var(--muted); font-size: 12px; }
.pill { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: 11px; background: var(--panel); border: 1px solid var(--border); }
.pill.done { color: var(--ok); }
.pill.pending, .pill.sent { color: var(--warn); }
.pill.failed { color: var(--danger); }

/* Modal */
.modal { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; z-index: 1000; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.75); }
.modal-body { position: relative; max-width: 90vw; max-height: 90vh; z-index: 1; }
.modal-body img, .modal-body video { max-width: 90vw; max-height: 80vh; border-radius: var(--radius); }
.modal-close { position: absolute; top: -38px; right: 0; background: transparent; border: none; color: #fff; font-size: 30px; cursor: pointer; }
.modal-info { margin-top: 8px; text-align: center; }

/* Toast */
.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: var(--panel); border: 1px solid var(--border); padding: 12px 18px;
  border-radius: var(--radius); z-index: 2000; box-shadow: 0 8px 24px rgba(0,0,0,.4);
}
.toast.alert { border-color: var(--danger); }
