﻿/* 
   GPS Monitor  Design System v3
    */

/*  Variables  */
:root {
  --bg:           #0c1a2e;
  --surface:      #1e3658;
  --surface-2:    #243f68;
  --surface-3:    #2c4d7a;
  --surface-4:    #35598a;
  --border:       rgba(255,255,255,0.1);
  --border-hover: rgba(255,255,255,0.22);
  --text:         #e8eef8;
  --text-muted:   #8fa3c4;
  --text-dim:     #4d6585;

  --accent:       #ec483b;
  --accent-glow:  rgba(236,72,59,0.3);
  --accent-2:     #f0a500;
  --accent-2-glow:rgba(240,165,0,0.25);
  --danger:       #ff4135;
  --warning:      #f59e0b;
  --success:      #22c55e;

  --sidebar-w:    300px;
  --navbar-h:     56px;
  --radius:       12px;
  --radius-sm:    8px;
  --radius-xs:    5px;
  --transition:   0.2s ease;

  --c0:#ec483b; --c1:#f0a500; --c2:#22c55e; --c3:#4fd8f7;
  --c4:#c84ff7; --c5:#4285f4; --c6:#f74fa3; --c7:#fb7c3c;
  --c8:#a3e635; --c9:#10c9a3; --c10:#f96262; --c11:#8b5cf6;
}

/*  Light mode  */
body.light {
  --bg:           #edf1f7;
  --surface:      #ffffff;
  --surface-2:    #e4ebf5;
  --surface-3:    #cdd9ed;
  --surface-4:    #b8cadf;
  --border:       rgba(30,54,88,0.12);
  --border-hover: rgba(30,54,88,0.25);
  --text:         #0f1e30;
  --text-muted:   #3a5070;
  --text-dim:     #7a96b4;
  --accent:       #ec483b;
  --accent-glow:  rgba(236,72,59,0.2);
  --accent-2:     #c47800;
  --accent-2-glow:rgba(196,120,0,0.18);
  --danger:       #dc2626;
  --warning:      #d97706;
  --success:      #16a34a;
}

/*  Reset  */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; }
body {
  font-family: 'Inter', 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  transition: background 0.3s ease, color 0.3s ease;
}

/*  Scrollbar  */
::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--surface-4); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-dim); }


/* 
     NAVBAR                      
    */
.navbar {
  height: var(--navbar-h);
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0 1.1rem;
  background: #1e3658;
  border-bottom: 1px solid rgba(255,255,255,0.1);
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 1000;
  box-shadow: 0 2px 16px rgba(0,0,0,0.4);
}
body.light .navbar {
  background: #1e3658;
  box-shadow: 0 2px 16px rgba(0,0,0,0.3);
}
.navbar-brand {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  font-weight: 700;
  font-size: 0.98rem;
  letter-spacing: 0.2px;
  flex-shrink: 0;
}
.brand-logo {
  height: 34px;
  width: auto;
  object-fit: contain;
  flex-shrink: 0;
  filter: drop-shadow(0 1px 4px rgba(0,0,0,0.6)) brightness(1.08);
}
.brand-text { color: #ffffff; white-space: nowrap; letter-spacing: 0.1px; }
.navbar-spacer { flex: 1; }
.navbar-status {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.78rem;
  color: rgba(232,238,248,0.75);
  white-space: nowrap;
  overflow: hidden;
  min-width: 0;
}
.navbar-status-text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
  transition: background 0.4s ease;
}
.dot--idle    { background: var(--text-dim); }
.dot--loading { background: var(--warning); animation: pulse 1.2s ease-in-out infinite; }
.dot--ok      { background: var(--success); }
.dot--error   { background: var(--danger); animation: pulse 1s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.3; } }

.sync-bar {
  position: absolute;
  bottom: 0; left: 0;
  height: 2px; width: 0;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  border-radius: 0 2px 2px 0;
  opacity: 0;
  pointer-events: none;
}
.sync-bar.syncing { opacity: 1; animation: syncProgress 1.8s ease-in-out infinite; }
@keyframes syncProgress {
  0%   { width: 0;    left: 0;    opacity: 1; }
  60%  { width: 75%;  left: 0;    opacity: 1; }
  80%  { width: 100%; left: 0;    opacity: 1; }
  100% { width: 0;    left: 100%; opacity: 0; }
}

/* Navbar hamburger — mobile only */
.navbar-menu-btn {
  display: flex;
  background: rgba(255,255,255,0.12);
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 8px;
  color: #ffffff;
  font-size: 1.1rem;
  width: 36px;
  height: 36px;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: background var(--transition);
}
.navbar-menu-btn:hover { background: rgba(255,255,255,0.22); }
.navbar-menu-btn:active { background: rgba(255,255,255,0.1); }

.theme-toggle {
  background: rgba(255,255,255,0.1);
  border: 1px solid rgba(255,255,255,0.18);
  border-radius: 20px;
  color: rgba(232,238,248,0.85);
  cursor: pointer;
  font-size: 0.85rem;
  padding: 5px 11px;
  transition: all var(--transition);
  display: flex;
  align-items: center;
  gap: 5px;
  flex-shrink: 0;
  white-space: nowrap;
}
.theme-toggle:hover { background: rgba(255,255,255,0.18); color: #ffffff; border-color: rgba(255,255,255,0.3); }
.toggle-label { font-size: 0.7rem; font-weight: 600; letter-spacing: 0.3px; }


/* 
     APP LAYOUT                  
    */
.app-layout {
  display: flex;
  height: calc(100vh - var(--navbar-h));
  margin-top: var(--navbar-h);
  overflow: hidden;
  position: relative;
}

/* Sidebar overlay */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: var(--navbar-h) 0 0 0;
  background: rgba(0, 0, 0, 0.65);
  z-index: 200;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.26s ease;
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}
.sidebar-overlay.active { opacity: 1; pointer-events: all; }

/* Sidebar FAB — removed */


/* 
     SIDEBAR                     
    */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  padding: 0.7rem;
  overflow-y: auto;
  overflow-x: hidden;
  min-height: 0;
  transition: width 0.22s ease, padding 0.22s ease, transform 0.26s cubic-bezier(0.4,0,0.2,1);
  position: relative;
  z-index: 201;
}
.sidebar.collapsed {
  width: 0;
  padding-left: 0;
  padding-right: 0;
  overflow: hidden;
}

.sidebar-toggle {
  align-self: flex-end;
  background: rgba(236,72,59,0.12);
  border: 1px solid rgba(236,72,59,0.3);
  color: #ec483b;
  font-size: 0.7rem;
  font-weight: 700;
  cursor: pointer;
  padding: 4px 10px;
  border-radius: var(--radius-xs);
  transition: all var(--transition);
  flex-shrink: 0;
  letter-spacing: 0.3px;
}
.sidebar-toggle:hover { background: rgba(236,72,59,0.22); border-color: rgba(236,72,59,0.5); color: #ff6b5e; }

/* Routes panel */
#routesPanel {
  display: flex;
  flex-direction: column;
  min-height: 200px;
  flex: 1 1 auto;
  overflow: hidden;
}
#routesPanel .panel-body { flex: 1 1 auto; min-height: 0; overflow: hidden; }
#legendPanel .panel-body { max-height: 160px; overflow-y: auto; }


/*  Stats bar  */
.stats-bar { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.4rem; }
.stat-card {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.6rem 0.35rem;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 2px;
  position: relative;
  overflow: hidden;
}
.stat-card::after {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: linear-gradient(90deg, #ec483b, #f0a500);
  border-radius: 2px 2px 0 0;
}
.stat-value { font-size: 1.4rem; font-weight: 700; color: var(--accent); line-height: 1; }
.stat-label { font-size: 0.62rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; }


/*  Panel  */
.panel {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  flex-shrink: 0;
}
.panel-header {
  padding: 0.6rem 0.8rem;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.65px;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}
.panel-actions { display: inline-flex; align-items: center; gap: 0.3rem; }
.panel-collapse-btn {
  width: 22px; height: 22px;
  border: 1px solid var(--border);
  border-radius: 5px;
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
  flex-shrink: 0;
}
.panel-collapse-btn:hover { border-color: var(--border-hover); color: var(--text-muted); background: var(--surface-3); }
.panel-collapse-icon { font-size: 0.72rem; line-height: 1; transition: transform 0.2s ease; }
.panel.is-collapsed .panel-collapse-icon { transform: rotate(-90deg); }
.panel.is-collapsed .panel-body { display: none; }
.panel-body { padding: 0.7rem; display: flex; flex-direction: column; gap: 0.45rem; min-height: 0; }
.badge {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff;
  font-size: 0.67rem;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 20px;
  line-height: 1.4;
}


/*  Search input  */
.search-input {
  width: 100%;
  background: var(--surface-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 0.83rem;
  padding: 0.48rem 0.65rem;
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
}
.search-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-glow); }
.search-input::placeholder { color: var(--text-dim); }


/*  Route list  */
.route-list {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  flex: 1 1 auto;
  min-height: 0;
  max-height: none;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding-right: 2px;
}
.route-item {
  display: flex;
  width: 100%;
  align-items: center;
  gap: 0.5rem;
  padding: 0.52rem 0.65rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition);
  user-select: none;
  border: 1px solid transparent;
  border-left: 3px solid transparent;
}
.route-item:hover { background: var(--surface-3); border-left-color: var(--border-hover); }
.route-item.active {
  background: var(--surface-3);
  border-color: var(--border);
  border-left-color: var(--route-color, var(--accent));
}
.route-color-dot { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; }
.route-item input[type="checkbox"] {
  width: 14px; height: 14px;
  accent-color: var(--accent);
  flex-shrink: 0; margin: 0;
  pointer-events: none; cursor: pointer;
}
.route-item-name { font-size: 0.82rem; color: var(--text); flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.route-item-count {
  font-size: 0.69rem;
  color: var(--accent-2);
  font-weight: 700;
  background: var(--surface-4);
  padding: 1px 6px;
  border-radius: 10px;
  flex-shrink: 0;
  min-width: 18px;
  text-align: center;
  line-height: 1.6;
}
.route-item-count:empty { display: none; }
.loading-placeholder { color: var(--text-dim); font-size: 0.82rem; text-align: center; padding: 1.5rem 0; }


/*  Controls  */
.controls-grid { display: flex; flex-direction: column; gap: 0.45rem; }
.control-label { font-size: 0.74rem; color: var(--text-muted); }
.input-row { display: flex; gap: 0.4rem; }
.ctrl-input {
  flex: 1;
  background: var(--surface-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 0.88rem;
  padding: 0.44rem 0.6rem;
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
}
.ctrl-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-glow); }
.controls-divider { height: 1px; background: var(--border); margin: 0.1rem 0; }


/*  Buttons  */
.btn {
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  padding: 0.5rem 0.85rem;
  transition: all var(--transition);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  white-space: nowrap;
  letter-spacing: 0.2px;
}
.btn:hover  { filter: brightness(1.13); transform: translateY(-1px); }
.btn:active { transform: translateY(0); filter: brightness(0.95); }
.btn--primary { background: #ec483b; color: #fff; box-shadow: 0 2px 12px rgba(236,72,59,0.4); }
.btn--accent  { background: var(--accent-2); color: #1a0a00; font-weight: 700; }
.btn--ghost   { background: var(--surface-3); color: var(--text-muted); border: 1px solid var(--border); }
.btn--ghost:hover { color: var(--text); border-color: var(--border-hover); }
.btn--danger  { background: rgba(239,68,68,0.12); color: var(--danger); border: 1px solid rgba(239,68,68,0.25); }
.btn--danger:hover { background: rgba(239,68,68,0.22); }
.full-width { width: 100%; }


/*  Legend  */
.legend-item { display: flex; align-items: center; gap: 0.5rem; font-size: 0.81rem; padding: 0.35rem 0; border-bottom: 1px solid var(--border); }
.legend-item:last-child { border-bottom: none; }
.legend-swatch { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.legend-name { flex: 1; color: var(--text-muted); font-size: 0.79rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.legend-count { color: var(--accent); font-weight: 700; font-size: 0.78rem; background: var(--surface-3); padding: 1px 6px; border-radius: 8px; flex-shrink: 0; }

.update-footer { font-size: 0.69rem; color: var(--text-dim); text-align: center; padding: 0.2rem 0; margin-top: auto; }


/* 
     MAP                         
    */
.map-container { flex: 1; position: relative; overflow: hidden; min-width: 0; }
#map { width: 100%; height: 100%; background: #091524; }
body:not(.light) .leaflet-tile { filter: brightness(0.85) saturate(0.8); }
body.light  .leaflet-tile { filter: brightness(1.02) saturate(1.05); }
body.light  #map { background: #c0d4e8; }

.toast {
  position: absolute;
  bottom: 1.1rem; left: 50%;
  transform: translateX(-50%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.6rem 1.1rem;
  font-size: 0.81rem;
  color: var(--text);
  max-width: min(90vw, 420px);
  z-index: 900;
  pointer-events: none;
  box-shadow: 0 6px 28px rgba(0,0,0,0.45);
  transition: opacity 0.3s ease;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.toast--hidden { opacity: 0; }
.toast--error  { border-color: var(--danger); color: var(--danger); }

.map-spinner {
  position: absolute; inset: 0;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 0.75rem;
  background: rgba(12,26,46,0.65);
  z-index: 800;
  font-size: 0.84rem;
  color: var(--text-muted);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}
body.light .map-spinner { background: rgba(237,241,247,0.75); }
.map-spinner.hidden { display: none; }
.spinner { width: 34px; height: 34px; border: 3px solid var(--surface-3); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.75s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Leaflet zoom controls */
.leaflet-control-zoom { border: 1px solid var(--border) !important; border-radius: var(--radius-sm) !important; overflow: hidden; box-shadow: 0 4px 16px rgba(0,0,0,0.3) !important; }
.leaflet-control-zoom a { background: var(--surface) !important; color: var(--text-muted) !important; border-bottom: 1px solid var(--border) !important; width: 32px !important; height: 32px !important; line-height: 32px !important; font-size: 1rem !important; transition: all var(--transition); }
.leaflet-control-zoom a:last-child { border-bottom: none !important; }
.leaflet-control-zoom a:hover { background: var(--surface-2) !important; color: var(--text) !important; }
body.light .leaflet-control-zoom a { background: #fff !important; }


/* 
     UNIT DETAIL DRAWER          
    */
.drawer {
  position: fixed;
  bottom: 0; right: 0;
  width: 320px; max-height: 55vh;
  background: var(--surface);
  border-top: 1px solid var(--border);
  border-left: 1px solid var(--border);
  border-radius: var(--radius) var(--radius) 0 0;
  z-index: 950;
  display: flex; flex-direction: column;
  box-shadow: -4px -4px 30px rgba(0,0,0,0.5);
  transition: transform 0.25s cubic-bezier(0.4,0,0.2,1);
}
.drawer--hidden { transform: translateY(100%); }
.drawer-header { display: flex; align-items: center; justify-content: space-between; padding: 0.78rem 1rem; border-bottom: 1px solid var(--border); flex-shrink: 0; gap: 0.5rem; }
.drawer-header h3 { font-size: 0.9rem; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.drawer-close { background: transparent; border: none; color: var(--text-muted); cursor: pointer; font-size: 1rem; padding: 3px 7px; border-radius: 5px; flex-shrink: 0; transition: all var(--transition); }
.drawer-close:hover { color: var(--text); background: var(--surface-2); }
.drawer-body { overflow-y: auto; padding: 0.9rem 1rem; display: grid; grid-template-columns: 1fr 1fr; gap: 0.8rem; }
.detail-item { display: flex; flex-direction: column; gap: 3px; }
.detail-label { font-size: 0.64rem; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.5px; }
.detail-value { font-size: 0.9rem; font-weight: 500; color: var(--text); }
.detail-item.full { grid-column: 1 / -1; }

/* Hide Leaflet popup */
.leaflet-popup, .leaflet-popup.leaflet-zoom-animated { display: none !important; }


/* 
     RESPONSIVE  TABLET         
    */
@media (max-width: 900px) {
  :root { --sidebar-w: 272px; }
}

/* 
     RESPONSIVE  MOBILE         
    */
@media (max-width: 680px) {
  :root { --navbar-h: 52px; }

  .sidebar {
    position: fixed !important;
    top: var(--navbar-h); left: 0; bottom: 0;
    width: min(310px, 85vw) !important;
    transform: translateX(-110%);
    box-shadow: 6px 0 32px rgba(0,0,0,0.55);
    z-index: 1200;
    max-height: none;
    overflow-y: auto;
    padding: 0.75rem;
    border-right: 1px solid var(--border);
  }
  /* sidebar--open: slide fully into view */
  .sidebar.sidebar--open {
    transform: translateX(0) !important;
  }
  /* collapsed on mobile = hidden (same as default, kept for JS compat) */
  .sidebar.collapsed {
    width: min(310px, 85vw) !important;
    padding: 0.75rem;
    overflow-y: auto;
    overflow-x: hidden;
    transform: translateX(-110%) !important;
  }

  .sidebar-overlay { display: block; pointer-events: none; z-index: 1100; }
  .sidebar-overlay.active { pointer-events: all; }
  .map-container { flex: 1; min-height: 100%; }
  #routesPanel { min-height: 160px; }
  .route-list { max-height: 38vh; }
  #legendPanel .panel-body { max-height: 130px; }
  .stat-value { font-size: 1.25rem; }
  .stat-label { font-size: 0.6rem; }
  .drawer { width: 100%; border-left: none; border-radius: var(--radius) var(--radius) 0 0; }
  .drawer-body { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 440px) {
  :root { --navbar-h: 50px; }
  .navbar { padding: 0 0.8rem; gap: 0.5rem; }
  .brand-logo { height: 27px; }
  .brand-text  { font-size: 0.88rem; }
  .toggle-label { display: none; }
  .navbar-status-text { display: none; }
  .stats-bar { gap: 0.3rem; }
  .sidebar { width: min(300px, 92vw) !important; }
}
