:root {
  --bg: #0f1115;
  --bg-panel: #161922;
  --bg-panel-hover: #1e222d;
  --border: #262b38;
  --text: #e8eaed;
  --text-dim: #8b8f9c;
  --accent: #3d7eff;
  --accent-hover: #5a8fff;
  --danger: #ff5c5c;
  --success: #34c77b;
  --radius: 10px;
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

/* ---------- Login ---------- */

.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.login-card {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 40px 36px;
  width: 100%;
  max-width: 380px;
}

.login-card .brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 32px;
}

.login-card .brand-icon {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 18px;
}

.login-card .brand-name {
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.login-card h1 {
  font-size: 22px;
  font-weight: 600;
  margin-bottom: 6px;
}

.login-card p.sub {
  color: var(--text-dim);
  font-size: 14px;
  margin-bottom: 28px;
}

label {
  display: block;
  font-size: 13px;
  color: var(--text-dim);
  margin-bottom: 6px;
  margin-top: 16px;
}

label:first-of-type {
  margin-top: 0;
}

input[type="email"],
input[type="password"],
input[type="text"] {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 11px 12px;
  color: var(--text);
  font-size: 14px;
  font-family: var(--font);
}

input:focus {
  outline: none;
  border-color: var(--accent);
}

button.primary {
  width: 100%;
  margin-top: 24px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 8px;
  padding: 12px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  font-family: var(--font);
  transition: background 0.15s;
}

button.primary:hover {
  background: var(--accent-hover);
}

button.primary:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.error-msg {
  background: rgba(255, 92, 92, 0.1);
  border: 1px solid rgba(255, 92, 92, 0.3);
  color: var(--danger);
  font-size: 13px;
  padding: 10px 12px;
  border-radius: 8px;
  margin-top: 16px;
  display: none;
}

.error-msg.show {
  display: block;
}

/* ---------- Dashboard ---------- */

.app {
  display: grid;
  grid-template-columns: 320px 1fr;
  height: 100vh;
}

.sidebar {
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar-header {
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.sidebar-header .brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-icon {
  width: 30px;
  height: 30px;
  border-radius: 7px;
  background: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 15px;
  flex-shrink: 0;
}

.brand-name {
  font-size: 15px;
  font-weight: 600;
}

.logout-btn {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 13px;
  font-family: var(--font);
}

.logout-btn:hover {
  color: var(--text);
}

.device-search {
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
}

.device-search input {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 12px;
  color: var(--text);
  font-size: 13px;
  font-family: var(--font);
}

.device-list {
  flex: 1;
  overflow-y: auto;
  padding: 10px;
}

.device-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s;
  margin-bottom: 4px;
}

.device-item:hover,
.device-item.active {
  background: var(--bg-panel-hover);
}

.device-status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
  background: var(--text-dim);
}

.device-status-dot.online {
  background: var(--success);
}

.device-status-dot.offline {
  background: var(--danger);
}

.device-info {
  flex: 1;
  min-width: 0;
}

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

.device-meta {
  font-size: 12px;
  color: var(--text-dim);
  margin-top: 2px;
}

.empty-state {
  padding: 40px 20px;
  text-align: center;
  color: var(--text-dim);
  font-size: 13px;
}

.map-area {
  position: relative;
}

#map {
  width: 100%;
  height: 100%;
}

.map-loading {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  color: var(--text-dim);
  font-size: 14px;
  z-index: 500;
}

/* Popup de Leaflet, override para tema oscuro */
.leaflet-popup-content-wrapper {
  background: var(--bg-panel);
  color: var(--text);
  border-radius: 8px;
}

.leaflet-popup-tip {
  background: var(--bg-panel);
}

.popup-title {
  font-weight: 600;
  font-size: 14px;
  margin-bottom: 6px;
}

.popup-row {
  font-size: 12px;
  color: var(--text-dim);
  margin-top: 2px;
}

@media (max-width: 720px) {
  .app {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
  }
  .sidebar {
    max-height: 40vh;
  }
}

/* ---------- Panel admin ---------- */

.sidebar-header-actions {
  display: flex;
  align-items: center;
  gap: 14px;
}

.link-btn {
  color: var(--text-dim);
  font-size: 13px;
  text-decoration: none;
}

.link-btn:hover {
  color: var(--text);
}

.admin-wrap {
  min-height: 100vh;
  max-width: 960px;
  margin: 0 auto;
  padding: 0 24px 60px;
}

.admin-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 24px 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 28px;
}

.admin-header .brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.admin-header-actions {
  display: flex;
  align-items: center;
  gap: 18px;
}

.admin-section {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 24px;
}

.admin-section h2 {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 16px;
}

.inline-form {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 12px;
}

.inline-form input,
.inline-form select {
  flex: 1;
  min-width: 160px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  color: var(--text);
  font-size: 14px;
  font-family: var(--font);
}

.inline-form input:focus,
.inline-form select:focus {
  outline: none;
  border-color: var(--accent);
}

.inline-form button.primary {
  width: auto;
  margin-top: 0;
  white-space: nowrap;
}

.form-msg {
  display: none;
  font-size: 13px;
  padding: 10px 12px;
  border-radius: 8px;
  margin-bottom: 16px;
  word-break: break-word;
}

.form-msg.show {
  display: block;
  background: rgba(255, 92, 92, 0.1);
  border: 1px solid rgba(255, 92, 92, 0.3);
  color: var(--danger);
}

.form-msg.show.success {
  background: rgba(52, 199, 123, 0.1);
  border: 1px solid rgba(52, 199, 123, 0.3);
  color: var(--success);
}

.admin-table {
  width: 100%;
  border-collapse: collapse;
}

.admin-table th,
.admin-table td {
  text-align: left;
  padding: 10px 8px;
  font-size: 13px;
  border-bottom: 1px solid var(--border);
}

.admin-table th {
  color: var(--text-dim);
  font-weight: 500;
}

.admin-table .empty-state {
  text-align: center;
  color: var(--text-dim);
  padding: 24px 8px;
}

/* ---------- Acciones sobre vehículo (dashboard) ---------- */

.sidebar .form-msg {
  margin: 0 14px 10px;
}

.device-menu {
  margin-top: 6px;
}

.device-menu summary {
  list-style: none;
  cursor: pointer;
  font-size: 11px;
  color: var(--text-dim);
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.device-menu summary::-webkit-details-marker {
  display: none;
}

.device-menu summary::after {
  content: '⌄';
}

.device-menu[open] summary::after {
  content: '⌃';
}

.device-menu summary:hover {
  color: var(--text);
}

.device-actions {
  display: flex;
  gap: 6px;
  margin-top: 8px;
}

.device-subsection {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}

.device-subsection-title {
  font-size: 11px;
  color: var(--text-dim);
  margin-bottom: 6px;
}

.mini-form {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.mini-form input {
  flex: 1;
  min-width: 90px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 8px;
  color: var(--text);
  font-size: 11px;
  font-family: var(--font);
}

.mini-form button {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 8px;
  font-size: 11px;
  font-family: var(--font);
  cursor: pointer;
  background: var(--bg);
  color: var(--text);
}

.mini-form button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.device-actions button {
  flex: 1;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 8px;
  font-size: 11px;
  font-family: var(--font);
  cursor: pointer;
  background: var(--bg);
  color: var(--text);
}

.device-actions button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.device-actions .btn-cut {
  color: var(--danger);
  border-color: rgba(255, 92, 92, 0.4);
}

.device-actions .btn-resume {
  color: var(--success);
  border-color: rgba(52, 199, 123, 0.4);
}
