:root {
  --bg: #0b0c14;
  --surface: rgba(17, 19, 30, 0.72);
  --surface-solid: #141622;
  --surface-2: #1b1e2e;
  --border: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.14);
  --text: #e9eaf2;
  --muted: #8b8ea3;
  --accent: #5b8cff;
  --danger: #ff5c6c;
  --ok: #2bd67a;
  --radius: 10px;
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

.hidden {
  display: none !important;
}

#map {
  position: absolute;
  inset: 0;
  z-index: 0;
}

/* ============================= TOP BAR ============================= */
#topbar {
  position: absolute;
  top: 16px;
  left: 16px;
  right: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  z-index: 20;
  pointer-events: none;
}

#topbar > * {
  pointer-events: auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  backdrop-filter: blur(14px);
  box-shadow: var(--shadow);
}

.brand-logo {
  width: 22px;
  height: 22px;
  color: var(--accent);
}

.brand-name {
  font-weight: 650;
  letter-spacing: 0.2px;
  font-size: 15px;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.live-pill {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 9px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  backdrop-filter: blur(14px);
  font-size: 13px;
  color: var(--muted);
  box-shadow: var(--shadow);
  transition: color 0.3s, border-color 0.3s;
}

.live-pill.on {
  color: var(--ok);
  border-color: rgba(43, 214, 122, 0.35);
}

.pulse-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.4;
}

.live-pill.on .pulse-dot {
  opacity: 1;
  animation: pulse 1.8s ease-out infinite;
}

@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(43, 214, 122, 0.5); }
  70% { box-shadow: 0 0 0 8px rgba(43, 214, 122, 0); }
  100% { box-shadow: 0 0 0 0 rgba(43, 214, 122, 0); }
}

#account-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  backdrop-filter: blur(14px);
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: background 0.2s, border-color 0.2s;
}

#account-btn:hover {
  background: rgba(30, 33, 50, 0.85);
  border-color: var(--border-strong);
}

.avatar {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), #9b5cff);
  color: #fff;
  font-weight: 700;
  font-size: 14px;
  text-transform: uppercase;
}

/* ============================= SIDE PANEL ============================= */
#panel {
  position: absolute;
  top: 84px;
  left: 16px;
  width: 312px;
  max-height: calc(100vh - 100px);
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  backdrop-filter: blur(16px);
  box-shadow: var(--shadow);
  z-index: 10;
  overflow: hidden;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px 4px;
}

.panel-heading {
  display: flex;
  align-items: baseline;
  gap: 8px;
  min-width: 0;
}

.panel-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--muted);
  cursor: pointer;
  transition: color 0.2s, background 0.2s, border-color 0.2s;
}

.icon-btn:hover {
  color: var(--text);
  background: #23263a;
  border-color: var(--border-strong);
}

.icon-btn svg {
  width: 16px;
  height: 16px;
}

#panel-toggle svg {
  transition: transform 0.25s;
}

#panel.collapsed #panel-toggle svg {
  transform: rotate(180deg);
}

#panel.collapsed .date-controls,
#panel.collapsed #device-list,
#panel.collapsed #empty-state,
#panel.collapsed .stats,
#panel.collapsed #status {
  display: none;
}

#theme-btn {
  background: var(--surface);
  backdrop-filter: blur(14px);
  box-shadow: var(--shadow);
  border-radius: 8px;
  width: 42px;
  height: 42px;
}

.panel-title {
  font-weight: 650;
  font-size: 15px;
}

.date-hint {
  font-size: 12px;
  color: var(--muted);
}

.date-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 18px 14px;
}

.date-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s;
  flex-shrink: 0;
}

.date-nav:hover {
  background: #23263a;
  border-color: var(--border-strong);
}

.date-nav svg {
  width: 16px;
  height: 16px;
}

#date-input {
  flex: 1;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 14px;
  color-scheme: dark;
  text-align: center;
}

#device-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 0 18px;
  overflow-y: auto;
  flex: 1;
}

.device {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.025);
  border: 1px solid var(--border);
  transition: background 0.2s, transform 0.15s;
}

.device:hover {
  background: rgba(255, 255, 255, 0.05);
}

.device-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  flex-shrink: 0;
}

.device-meta {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
  min-width: 0;
}

.device-name {
  font-size: 14px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.device-sub {
  font-size: 12px;
  color: var(--muted);
}

.device-focus {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  flex-shrink: 0;
  transition: color 0.2s, border-color 0.2s;
}

.device-focus:hover {
  color: var(--text);
  border-color: var(--border-strong);
}

.device-focus svg {
  width: 15px;
  height: 15px;
}

/* switch */
.switch {
  position: relative;
  width: 40px;
  height: 22px;
  flex-shrink: 0;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  inset: 0;
  border-radius: 22px;
  background: #262939;
  cursor: pointer;
  transition: background 0.25s;
}

.slider::before {
  content: "";
  position: absolute;
  height: 16px;
  width: 16px;
  left: 3px;
  top: 3px;
  border-radius: 50%;
  background: #8b8ea3;
  transition: transform 0.25s, background 0.25s;
}

.switch input:checked + .slider {
  background: var(--c, var(--accent));
  opacity: 0.9;
}

.switch input:checked + .slider::before {
  transform: translateX(18px);
  background: #fff;
}

/* empty state */
#empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 40px 0;
  color: var(--muted);
}

#empty-state svg {
  width: 40px;
  height: 40px;
  opacity: 0.5;
}

#empty-state p {
  margin: 0;
  font-size: 13px;
}

/* stats */
.stats {
  display: flex;
  border-top: 1px solid var(--border);
  margin-top: 12px;
}

.stat {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 12px 4px;
}

.stat span {
  font-size: 17px;
  font-weight: 650;
}

.stat label {
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

#status {
  padding: 0 18px 14px;
  font-size: 11px;
  color: var(--muted);
  text-align: center;
}

/* ============================= MAP MARKER ============================= */
.device-marker-wrapper {
  background: transparent;
  border: none;
}

.device-marker {
  position: relative;
}

.device-marker .dot {
  position: absolute;
  left: -8px;
  top: -8px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid #fff;
  box-shadow: 0 0 12px currentColor;
}

.device-marker .dot::after {
  content: "";
  position: absolute;
  inset: -2px;
  border-radius: 50%;
  border: 2px solid currentColor;
  opacity: 0;
}

.device-marker .dot.pulse::after {
  animation: ping 0.7s ease-out;
}

@keyframes ping {
  0% { transform: scale(0.8); opacity: 0.9; }
  100% { transform: scale(2.4); opacity: 0; }
}

.device-marker .label {
  position: absolute;
  left: 12px;
  top: -10px;
  background: rgba(15, 17, 26, 0.9);
  color: var(--text);
  font-size: 11px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 7px;
  white-space: nowrap;
  border: 1px solid var(--border);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
}

/* ============================= TOASTS ============================= */
#toast-container {
  position: absolute;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  z-index: 30;
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 10px 16px;
  background: rgba(18, 20, 32, 0.95);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
  box-shadow: var(--shadow);
  animation: toast-in 0.25s ease-out;
  backdrop-filter: blur(12px);
}

.toast.out {
  animation: toast-out 0.3s ease-in forwards;
}

.toast-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
}

@keyframes toast-in {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes toast-out {
  to { opacity: 0; transform: translateY(10px); }
}

/* ============================= AUTH ============================= */
#auth-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(900px 600px at 20% 10%, rgba(91, 140, 255, 0.14), transparent 60%),
    radial-gradient(800px 600px at 85% 90%, rgba(155, 92, 255, 0.12), transparent 60%),
    var(--bg);
  z-index: 100;
}

.auth-brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  margin-bottom: 18px;
}

.auth-brand svg {
  width: 40px;
  height: 40px;
  color: var(--accent);
  margin-bottom: 4px;
}

.auth-brand h1 {
  margin: 0;
  font-size: 22px;
  font-weight: 700;
}

.auth-brand p {
  margin: 0;
}

/* ============================= MODALS ============================= */
.modal {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(4px);
  z-index: 50;
}

/* ============================= CARDS ============================= */
.card {
  width: 340px;
  max-width: calc(100vw - 32px);
  max-height: calc(100vh - 32px);
  overflow-y: auto;
  background: var(--surface-solid);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
}

.card h1 {
  margin: 0 0 18px;
  font-size: 22px;
}

.card h2 {
  margin: 0 0 12px;
  font-size: 16px;
}

.card h3 {
  margin: 0 0 10px;
  font-size: 14px;
}

.card input {
  width: 100%;
  padding: 11px 13px;
  margin-bottom: 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 14px;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.card input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(91, 140, 255, 0.18);
}

.card button {
  width: 100%;
  padding: 11px 13px;
  margin-top: 4px;
  border-radius: 8px;
  border: none;
  background: var(--accent);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, transform 0.05s;
}

.card button:hover {
  background: #6a98ff;
}

.card button:active {
  transform: translateY(1px);
}

.card button.ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  font-weight: 500;
}

.card button.ghost:hover {
  background: rgba(255, 255, 255, 0.04);
}

.card button.danger {
  background: var(--danger);
}

.muted {
  color: var(--muted);
  font-size: 13px;
}

.small {
  font-size: 12px;
}

.error {
  margin-top: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  background: rgba(255, 92, 108, 0.15);
  color: #ff9aa6;
  font-size: 13px;
}

.row {
  display: flex;
  gap: 8px;
}

.row button {
  flex: 1;
}

#twofa-qr {
  display: block;
  width: 180px;
  height: 180px;
  margin: 8px auto 12px;
  background: #fff;
  border-radius: 8px;
  padding: 8px;
}

code {
  background: var(--surface-2);
  padding: 2px 6px;
  border-radius: 5px;
  font-size: 12px;
  word-break: break-all;
}

.profile-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  font-size: 14px;
}

.profile-row.api {
  flex-direction: column;
  align-items: stretch;
  gap: 6px;
}

.badge {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 3px 10px;
  font-size: 12px;
  color: var(--muted);
}

.badge.on {
  color: var(--ok);
  border-color: rgba(43, 214, 122, 0.4);
}

.api-box {
  display: flex;
  gap: 8px;
  align-items: center;
}

.api-box code {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.api-box button {
  width: auto;
  padding: 6px 10px;
  margin: 0;
  font-size: 12px;
}

#apikey-rotate {
  margin-top: 8px;
}

.card hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 16px 0;
}

/* ============================= ADMIN ACCOUNTS ============================= */
.accounts-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 4px;
}

.account-row {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  background: rgba(255, 255, 255, 0.02);
}

.account-head {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 6px;
}

.account-name {
  font-weight: 600;
  font-size: 14px;
}

.account-key {
  display: flex;
  align-items: center;
  gap: 6px;
}

.account-key code {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 11px;
  background: var(--surface-2);
  padding: 4px 6px;
  border-radius: 5px;
}

.account-key button {
  width: auto;
  margin: 0;
  padding: 5px 9px;
  font-size: 11px;
  font-weight: 500;
  flex-shrink: 0;
}

.account-key button.account-delete {
  background: transparent;
  border: 1px solid rgba(255, 92, 108, 0.4);
  color: #ff8a95;
}

.account-key button.account-delete:hover {
  background: rgba(255, 92, 108, 0.15);
}

/* ============================= RESPONSIVE ============================= */
@media (max-width: 560px) {
  #panel {
    width: calc(100vw - 32px);
    top: auto;
    bottom: 16px;
    left: 16px;
    max-height: 45vh;
  }
}
