/* Trackline dashboard — clean, Prey-inspired layout:
   dark sidebar with the device list, light map-centric main area. */

:root {
  --sidebar-bg: #0e1526;
  --sidebar-bg-2: #16203a;
  --sidebar-text: #dbe4f5;
  --sidebar-muted: #8494b3;
  --accent: #2fbf71;
  --accent-dark: #23a35e;
  --danger: #e5484d;
  --danger-dark: #c93a3e;
  --panel-bg: #ffffff;
  --panel-border: #e3e8f0;
  --text: #16202e;
  --muted: #68778c;
  --radius: 12px;
  --shadow: 0 10px 30px rgba(10, 20, 40, 0.18);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--text);
}

#app { display: flex; height: 100vh; height: 100dvh; }

/* --- Sidebar ------------------------------------------------------------- */

#sidebar {
  width: 330px;
  min-width: 290px;
  background: linear-gradient(180deg, var(--sidebar-bg), var(--sidebar-bg-2));
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  z-index: 800;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 18px 16px 12px;
}

.brand-mark {
  width: 40px; height: 40px;
  border-radius: 10px;
  background: rgba(47, 191, 113, 0.16);
  color: var(--accent);
  display: grid; place-items: center;
  flex: none;
}

.brand h1 { margin: 0; font-size: 19px; font-weight: 650; letter-spacing: 0.2px; }
.brand p { margin: 2px 0 0; font-size: 12px; color: var(--sidebar-muted); }
.brand .icon-btn { margin-left: auto; }

.icon-btn {
  background: transparent;
  border: 1px solid transparent;
  color: inherit;
  border-radius: 8px;
  padding: 6px 8px;
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
}
.icon-btn:hover { background: rgba(255, 255, 255, 0.08); }

.search-row {
  display: flex;
  gap: 8px;
  padding: 6px 16px 12px;
}

.search-row input, .search-row select {
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: var(--sidebar-text);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 13px;
  outline: none;
}
.search-row input { flex: 1; min-width: 0; }
.search-row input::placeholder { color: var(--sidebar-muted); }
.search-row select option { color: #16202e; }
.search-row input:focus, .search-row select:focus { border-color: var(--accent); }

.device-list {
  list-style: none;
  margin: 0;
  padding: 4px 10px;
  overflow-y: auto;
  flex: 1;
}

.device-item {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 11px 10px;
  border-radius: 10px;
  cursor: pointer;
  border: 1px solid transparent;
}
.device-item:hover { background: rgba(255, 255, 255, 0.05); }
.device-item.selected { background: rgba(47, 191, 113, 0.12); border-color: rgba(47, 191, 113, 0.35); }

.status-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  margin-top: 5px;
  flex: none;
  background: #5b6b84;
}
.status-dot.online { background: var(--accent); box-shadow: 0 0 0 3px rgba(47, 191, 113, 0.22); }
.status-dot.offline { background: #5b6b84; }

.device-meta { min-width: 0; flex: 1; }
.device-name { font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.device-sub { font-size: 12px; color: var(--sidebar-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }

.empty-note { padding: 12px 18px; color: var(--sidebar-muted); font-size: 13px; }

.sidebar-footer {
  padding: 10px 16px 14px;
  font-size: 12px;
  color: var(--sidebar-muted);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.link-btn {
  background: none; border: none; padding: 0;
  color: var(--sidebar-muted); font-size: 12px; cursor: pointer; text-decoration: underline;
}

/* --- Main / map ------------------------------------------------------------ */

#main { position: relative; flex: 1; min-width: 0; }
#map { position: absolute; inset: 0; background: #e8eef4; }

.sidebar-toggle {
  position: absolute;
  top: 12px; left: 12px;
  z-index: 900;
  display: none;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 13px;
  box-shadow: var(--shadow);
  cursor: pointer;
}

/* --- Detail panel ------------------------------------------------------------ */

.detail {
  position: absolute;
  top: 12px; right: 12px;
  width: min(380px, calc(100vw - 24px));
  max-height: calc(100% - 24px);
  overflow-y: auto;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  z-index: 900;
}

.detail-close { position: absolute; top: 8px; right: 8px; color: var(--muted); }
.detail-close:hover { background: #f0f3f8; }

.detail h2 { margin: 0 28px 2px 0; font-size: 18px; word-break: break-word; }
.detail .status-line { font-size: 13px; color: var(--muted); margin-bottom: 12px; }
.detail .status-line .online { color: var(--accent-dark); font-weight: 600; }
.detail .status-line .offline { color: var(--muted); font-weight: 600; }

.kv { display: grid; grid-template-columns: 110px 1fr; gap: 6px 10px; font-size: 13px; margin: 10px 0 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; word-break: break-word; }

.command-buttons { display: flex; gap: 10px; margin: 14px 0 6px; }

.btn {
  appearance: none;
  border: 1px solid var(--panel-border);
  background: #f6f8fb;
  color: var(--text);
  padding: 9px 16px;
  border-radius: 9px;
  font-size: 14px;
  cursor: pointer;
}
.btn:hover { background: #edf1f7; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; flex: 1; }
.btn-primary:hover { background: var(--accent-dark); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; flex: 1; }
.btn-danger:hover { background: var(--danger-dark); }
.btn-neutral { flex: 1; }

.detail h3 { margin: 18px 0 8px; font-size: 13px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }

.history-list, .command-list { list-style: none; margin: 0; padding: 0; font-size: 13px; }
.history-list li, .command-list li {
  display: flex; justify-content: space-between; gap: 10px;
  padding: 7px 0; border-bottom: 1px solid #eef1f6;
}
.history-list li:last-child, .command-list li:last-child { border-bottom: none; }
.history-list .when, .command-list .when { color: var(--muted); white-space: nowrap; }
.command-list .cmd-type { font-weight: 600; text-transform: capitalize; }
.badge {
  font-size: 11px; font-weight: 600;
  padding: 2px 8px; border-radius: 999px;
  background: #eef1f6; color: var(--muted);
  white-space: nowrap;
}
.badge.executed { background: rgba(47, 191, 113, 0.15); color: var(--accent-dark); }
.badge.failed { background: rgba(229, 72, 77, 0.13); color: var(--danger-dark); }
.badge.sent { background: rgba(240, 178, 62, 0.18); color: #946a12; }

/* --- Dialogs & toast --------------------------------------------------------- */

dialog {
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px;
  width: min(440px, calc(100vw - 32px));
}
dialog::backdrop { background: rgba(10, 18, 32, 0.45); }
dialog h2 { margin: 0 0 8px; font-size: 17px; }
dialog p { font-size: 13.5px; color: var(--muted); line-height: 1.5; }
dialog input[type="password"] {
  width: 100%; padding: 10px 12px; font-size: 14px;
  border: 1px solid var(--panel-border); border-radius: 9px; margin: 8px 0 4px;
}
dialog label { display: block; font-size: 13px; color: var(--muted); margin-top: 10px; }
dialog textarea {
  width: 100%; margin-top: 6px; padding: 10px 12px; font-size: 14px; font-family: inherit;
  border: 1px solid var(--panel-border); border-radius: 9px; resize: vertical;
}
.dialog-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 16px; }
.error-note { color: var(--danger-dark) !important; }

.toast {
  position: fixed;
  left: 50%; bottom: 22px;
  transform: translateX(-50%);
  background: #16202e; color: #fff;
  padding: 10px 18px; border-radius: 999px;
  font-size: 13.5px;
  box-shadow: var(--shadow);
  z-index: 1200;
}

/* --- Responsive --------------------------------------------------------------- */

@media (max-width: 820px) {
  #sidebar {
    position: absolute;
    top: 0; bottom: 0; left: 0;
    transform: translateX(-105%);
    transition: transform 0.22s ease;
    box-shadow: var(--shadow);
  }
  #sidebar.open { transform: translateX(0); }
  .sidebar-toggle { display: block; }
  .detail { top: auto; bottom: 12px; max-height: 62%; }
}
