/* Base styles */
:root {
  --bg: #0f0f12; /* neutral charcoal */
  --panel: #16161a; /* neutral dark */
  --panel-2: #121216; /* neutral darker */
  --text: #e5e7eb; /* gray-200 */
  --muted: #9ca3af; /* gray-400 */
  --primary: #8b5cf6; /* violet-500 */
  --primary-600: #7c3aed; /* violet-600 */
  --accent: #22d3ee; /* cyan-400 */
  --success: #10b981; /* emerald-500 */
  --warning: #f59e0b; /* amber-500 */
  --danger: #ef4444; /* red-500 */
  --card: #121216; /* slightly different panel, neutral */
  --border: rgba(148, 163, 184, 0.15);
  --ring: rgba(139, 92, 246, 0.35);
}

* { box-sizing: border-box; }
html, body { height: 100%; overflow: hidden; }
html { background: radial-gradient(1200px 600px at 10% -10%, rgba(34,211,238,0.05), transparent 50%),
               radial-gradient(900px 500px at 100% 0%, rgba(139,92,246,0.08), transparent 60%), var(--bg); }
body {
  margin: 0;
  color: var(--text);
  font: 14px/1.5 system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell, Noto Sans, "Helvetica Neue", Arial, "Apple Color Emoji", "Segoe UI Emoji";
}

/* Header */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: rgba(24,24,28,0.65);
  backdrop-filter: blur(8px);
  position: sticky;
  top: 0;
  z-index: 10;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand .logo { font-size: 22px; }
.brand .name { font-weight: 600; letter-spacing: .2px; }

/* Layout */
.layout {
  display: grid;
  grid-template-columns: 400px 1fr;
  gap: 0;
  height: calc(100vh - 58px);
  min-height: calc(100vh - 58px);
}

.sidebar {
  border-right: 1px solid var(--border);
  background: linear-gradient(180deg, rgba(24,24,28,0.7), rgba(24,24,28,0.45));
  padding: 16px;
  overflow: auto;
}
.sidebar-section { margin-bottom: 16px; }
.label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--panel-2);
  color: var(--text);
  outline: none;
}
.input:focus { border-color: var(--primary); box-shadow: 0 0 0 4px var(--ring); }

.section-title { font-weight: 600; margin-bottom: 8px; }
.device-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.device-item {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 10px 12px; border: 1px solid var(--border); border-radius: 12px; background: var(--card);
}
.device-name { font-weight: 600; }
.device-meta { color: var(--muted); font-size: 12px; }
.badge { font-size: 11px; padding: 4px 8px; border-radius: 999px; border: 1px solid var(--border); background: rgba(255,255,255,0.04); }
.badge-online { color: var(--success); border-color: rgba(16,185,129,0.35); }
.badge-offline { color: var(--danger); border-color: rgba(239,68,68,0.35); }
.badge-moving { color: var(--accent); border-color: rgba(34,211,238,0.35); }

/* Map area */
.map-area { display: grid; grid-template-rows: auto 1fr; min-height: 0; overflow: hidden; }
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px; border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, rgba(18,18,22,0.8), rgba(18,18,22,0.55));
}
.breadcrumbs { color: var(--muted); font-size: 13px; }
.toolbar { display: flex; align-items: center; gap: 8px; }

.btn {
  appearance: none; border: 1px solid var(--border); background: var(--panel-2); color: var(--text);
  padding: 8px 12px; border-radius: 10px; cursor: pointer; font-weight: 500;
}
.btn:hover { border-color: var(--primary); box-shadow: 0 0 0 3px var(--ring); }
.btn-primary { background: linear-gradient(180deg, var(--primary), var(--primary-600)); border-color: transparent; }
.btn-primary:hover { box-shadow: 0 0 0 4px var(--ring); filter: brightness(1.05); }
.btn-secondary { background: var(--panel-2); }

.map-card {
  padding: 16px;
  display: grid;
  align-items: stretch;
  min-height: 0;
}
.map-container {
  width: 100%; height: calc(90vh - 58px - 56px - 32px); /* viewport minus header, topbar, paddings */
  min-height: 420px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: radial-gradient(600px 300px at 100% 0%, rgba(34,211,238,0.08), transparent 60%), var(--panel-2);
  overflow: hidden;
}

/* Ensure Leaflet or Map renderer fills container */
.map-container > div, .map-container .map, .map-container .leaflet-container { width: 100% !important; height: 100% !important; }

/* Auth page */
.auth-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.auth-card {
  width: 100%;
  max-width: 480px;
  min-height: 420px;
  background: linear-gradient(180deg, rgba(18,18,22,0.9), rgba(18,18,22,0.75)), var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 28px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.35);
}
.auth-header { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.auth-header .logo { font-size: 28px; }
.auth-title { margin: 0; font-size: 20px; font-weight: 700; }
.auth-subtitle { margin: 2px 0 0; color: var(--muted); font-size: 13px; }

.form-row { margin: 12px 0; }
.form-meta { margin: 6px 0 16px; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.checkbox { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.link { color: var(--accent); text-decoration: none; font-size: 13px; }
.link:hover { text-decoration: underline; }
.btn-full { width: 100%; padding: 12px 14px; border-radius: 12px; font-weight: 600; }
.info-row { margin: 8px 0 16px; color: var(--muted); font-size: 13px; }

.alert { padding: 10px 12px; border-radius: 12px; border: 1px solid var(--border); margin: 8px 0 12px; font-size: 13px; }
.alert-danger { color: #fecaca; background: rgba(239,68,68,0.1); border-color: rgba(239,68,68,0.35); }

/* Responsive */
@media (max-width: 960px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { order: 2; }
  .map-area { order: 1; }
  .map-container { height: calc(90vh - 58px - 56px - 32px); }
}

.session {
    padding: 12px 16px;
    margin-bottom: 8px;
    border-radius: 8px;
    background: #f8f9fa;
    border-left: 3px solid transparent;
    transition: all 0.3s ease;
    cursor: pointer;
}

.session:hover {
    background: #e9ecef;
}

.active-session {
    border-left-color: #28a745;
    background: #f1f9f4;
}

.session-content {
    display: flex;
    align-items: center;
    gap: 12px;
}

.session-info {
    display: flex;
    align-items: center;
    flex-wrap: nowrap;
    white-space: nowrap;
}

.status-indicator {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}

.active-indicator {
    background: #28a745;
    box-shadow: 0 0 0 0 rgba(40, 167, 69, 0.7);
    animation: pulse 2s ease-in-out infinite;
}

.inactive-indicator {
    background: #6c757d;
}

@keyframes pulse {
    0%, 100% {
        box-shadow: 0 0 0 0 rgba(40, 167, 69, 0.7);
    }
    50% {
        box-shadow: 0 0 0 8px rgba(40, 167, 69, 0);
    }
}

.time-label {
    font-weight: 600;
    color: #495057;
    font-size: 0.9em;
    margin-right: 4px;
}

.session-time {
    color: #212529;
    font-family: 'Segoe UI', system-ui, sans-serif;
    margin-right: 8px;
}

.time-separator {
    color: #6c757d;
    margin: 0 8px;
    font-weight: bold;
}

.active-label {
    color: #28a745;
    font-weight: 600;
    margin-left: 8px;
}

.end-reason {
    color: #6c757d;
    font-style: italic;
    font-size: 0.9em;
    margin-left: 8px;
}

.session:hover {
    background: #e9ecef;
    transform: translateX(2px);
}

.active-session:hover {
    background: #e8f5e9;
}

.session {
    padding: 12px 16px;
    margin-bottom: 8px;
    border-radius: 8px;
    background: #f8f9fa;
    border-left: 3px solid transparent;
    transition: all 0.3s ease;
    cursor: pointer;
}

.session:hover {
    background: #e9ecef;
    transform: translateX(2px);
}

.active-session {
    border-left-color: #28a745;
    background: #f1f9f4;
}

.active-session:hover {
    background: #e8f5e9;
}

.session-selected {
    border-left-color: #007bff !important;
    background: #e7f3ff !important;
    box-shadow: 0 2px 8px rgba(0, 123, 255, 0.2);
}

.session-content {
    display: flex;
    align-items: center;
    gap: 12px;
}

.session-info {
    display: flex;
    align-items: center;
    flex-wrap: nowrap;
    white-space: nowrap;
}

.status-indicator {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}

.active-indicator {
    background: #28a745;
    box-shadow: 0 0 0 0 rgba(40, 167, 69, 0.7);
    animation: pulse 2s ease-in-out infinite;
}

.inactive-indicator {
    background: #6c757d;
}

@keyframes pulse {
    0%, 100% {
        box-shadow: 0 0 0 0 rgba(40, 167, 69, 0.7);
    }
    50% {
        box-shadow: 0 0 0 8px rgba(40, 167, 69, 0);
    }
}

.time-label {
    font-weight: 600;
    color: #495057;
    font-size: 0.9em;
    margin-right: 4px;
}

.session-time {
    color: #212529;
    font-family: 'Segoe UI', system-ui, sans-serif;
    margin-right: 8px;
}

.time-separator {
    color: #6c757d;
    margin: 0 8px;
    font-weight: bold;
}

.active-label {
    color: #28a745;
    font-weight: 600;
    margin-left: 8px;
}

.end-reason {
    color: #6c757d;
    font-style: italic;
    font-size: 0.9em;
    margin-left: 8px;
}

/* marker */

.device-marker {
    width: 20px;
    height: 20px;
    background: rgba(44, 42, 42, 0.63);  /* Red color */
    border: 3px solid white;
    border-radius: 50%;
    box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}

.first-device-marker {
    width: 20px;
    height: 20px;
    background: rgba(221, 189, 83, 0.73);  /* Red color */
    border: 3px solid white;
    border-radius: 50%;
    box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}

.last-device-marker {
    width: 20px;
    height: 20px;
    background: rgba(83, 137, 255, 0.71);  /* Red color */
    border: 3px solid white;
    border-radius: 50%;
    box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}


.active-device-marker {
    width: 24px;
    height: 24px;
    background: #10b981; /* Solid emerald green */
    border: 3px solid white;
    border-radius: 50%;
    box-shadow: 0 0 0 2px rgba(16, 185, 129, 0.3),
    0 4px 12px rgba(0, 0, 0, 0.4);
    position: relative;
    z-index: 1000;
}

/* Inner dot for depth */
.active-device-marker::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 8px;
    height: 8px;
    background: white;
    border-radius: 50%;
    z-index: 2;
}

/* Pulsing ripple effect */
.active-device-marker::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 100%;
    height: 100%;
    background: rgba(16, 185, 129, 0.4);
    border: 2px solid rgba(16, 185, 129, 0.6);
    border-radius: 50%;
    animation: ripple-pulse 2s ease-out infinite;
    z-index: -1;
}

@keyframes ripple-pulse {
    0% {
        transform: translate(-50%, -50%) scale(1);
        opacity: 1;
    }
    100% {
        transform: translate(-50%, -50%) scale(2.5);
        opacity: 0;
    }
}
