*{margin:0;padding:0;box-sizing:border-box}
body{font-family:'Segoe UI',sans-serif;height:100vh;display:flex;flex-direction:column;overflow:hidden}
#header{background:#1a1a2e;color:white;padding:8px 16px;z-index:1000;box-shadow:0 2px 10px rgba(0,0,0,.4);flex-shrink:0}
#header-top{display:flex;align-items:center;gap:12px;margin-bottom:8px;position:relative}
#header-top h1{flex:1;font-size:1.1rem}
#status-bar{display:flex;align-items:center;gap:8px;font-size:.8rem;color:#ccc;position:absolute;left:50%;transform:translateX(-50%);white-space:nowrap}
.dot{width:9px;height:9px;border-radius:50%;display:inline-block;flex-shrink:0}
.dot.online{background:#4CAF50;animation:pulse 2s infinite}
.dot.offline{background:#f44336}
.dot.warning{background:#FF9800}
@keyframes pulse{0%,100%{opacity:1}50%{opacity:.3}}
#route-tabs{display:flex;gap:6px;overflow-x:auto;padding-bottom:2px}
.route-tab{background:rgba(255,255,255,.1);color:white;border:2px solid transparent;padding:5px 14px;border-radius:20px;cursor:pointer;font-size:.8rem;white-space:nowrap;transition:all .2s}
.route-tab:hover{background:rgba(255,255,255,.2)}
.route-tab.active{background:rgba(255,255,255,.25);border-color:white;font-weight:bold}
#map{flex:1;z-index:1}
.bus-icon-wrapper{background:none!important;border:none!important}
.bus-wrapper{position:relative;width:52px;display:flex;flex-direction:column;align-items:center}
.bus-body{width:40px;height:40px;border-radius:50%;border:3px solid white;display:flex;align-items:center;justify-content:center;font-size:20px;box-shadow:0 3px 10px rgba(0,0,0,.4)}
.bus-label{background:white;border:2px solid;border-radius:8px;font-size:9px;font-weight:bold;padding:1px 5px;margin-top:2px;white-space:nowrap;max-width:52px;overflow:hidden;text-overflow:ellipsis}
.bus-speed-badge{position:absolute;top:-6px;right:-2px;color:white;font-size:9px;font-weight:bold;padding:1px 4px;border-radius:8px;border:1px solid white}
.vehicle-popup{min-width:180px}
.vp-header{padding:8px 12px;color:white;border-radius:6px 6px 0 0;font-size:.85rem;text-align:center}
.vp-header strong{display:block;font-size:.95rem}
.vp-body{padding:8px 12px}
.vp-row{display:flex;justify-content:space-between;align-items:center;padding:4px 0;font-size:.82rem}
.vp-btn{color:white;border:none;padding:4px 10px;border-radius:10px;cursor:pointer;font-size:.75rem}
.sp-header{padding:6px 10px;color:white;border-radius:4px 4px 0 0;font-weight:bold;font-size:.85rem}
.sp-body{padding:8px 10px;font-size:.85rem}
#vehicle-panel{position:fixed;top:110px;right:12px;background:white;border-radius:14px;box-shadow:0 6px 24px rgba(0,0,0,.2);width:270px;z-index:1000;overflow:hidden}
#vehicle-panel.hidden{display:none}
#panel-header{padding:12px 14px;color:white;display:flex;justify-content:space-between;align-items:flex-start}
#panel-route-badge{font-size:.72rem;opacity:.9;display:block;margin-bottom:2px}
#panel-vehicle-name{font-size:1rem;font-weight:bold;display:block}
#panel-close{background:rgba(255,255,255,.25);border:none;color:white;width:26px;height:26px;border-radius:50%;cursor:pointer;font-size:.8rem;flex-shrink:0}
#panel-body{padding:12px}
.info-row{display:flex;justify-content:space-between;align-items:center;padding:7px 0;border-bottom:1px solid #f5f5f5;font-size:.85rem}
.info-row:last-child{border-bottom:none}
.info-label{color:#888}
.info-value{font-weight:600;color:#333}
#stops-panel{position:fixed;bottom:0;left:0;right:0;background:white;border-radius:16px 16px 0 0;box-shadow:0 -4px 20px rgba(0,0,0,.12);z-index:1000;max-height:45vh;transition:max-height .3s;display:flex;flex-direction:column}
#stops-panel.collapsed{max-height:44px}
#stops-header{padding:12px 18px;font-weight:bold;color:#333;cursor:pointer;display:flex;justify-content:space-between;background:#f8f8f8;border-radius:16px 16px 0 0;border-bottom:1px solid #eee;flex-shrink:0}
#stops-list{overflow-y:auto;flex:1;padding:8px}
.stops-route-header{font-size:.8rem;font-weight:bold;padding:8px 10px 4px;border-left:4px solid;margin:8px 0 4px;border-radius:0 4px 4px 0;background:#fafafa;display:flex;justify-content:space-between}
.stop-item{display:flex;align-items:center;gap:8px;padding:8px 10px;border-radius:8px;cursor:pointer;transition:background .15s}
.stop-item:hover{background:#f5f5f5}
.stop-item.active{background:#fff8e1}
.stop-item.next-stop{background:rgba(25,118,210,.07);border-left:3px solid #1976d2;padding-left:7px}
body.dark-mode .stop-item.next-stop{background:rgba(25,118,210,.15);border-left-color:#42a5f5}
.stop-item.passed{opacity:.45}
.stop-item.skipped{background:rgba(224,123,0,.07);border-left:3px solid #e07b00;padding-left:7px}
.stop-item.passed-no-stop{background:rgba(245,124,0,.1);border-left:3px solid #f57c00;padding-left:7px;opacity:.75}
body.dark-mode .stop-item.passed{opacity:.3}
body.dark-mode .stop-item.skipped{background:rgba(224,123,0,.13);border-left-color:#ffb74d}
body.dark-mode .stop-item.passed-no-stop{background:rgba(245,124,0,.15);border-left-color:#ffa726;opacity:.65}
.stop-item.suspended{background:rgba(229,57,53,.08);border-left:3px solid #e53935;padding-left:7px;opacity:.7}
body.dark-mode .stop-item.suspended{background:rgba(229,57,53,.15);border-left-color:#ef5350}
.stop-connector{display:flex;flex-direction:column;align-items:center;width:16px;flex-shrink:0}
.stop-line{width:2px;height:12px;margin-bottom:2px}
.stop-dot{width:10px;height:10px;border-radius:50%}
.stop-info{flex:1}
.stop-icon-col{display:flex;flex-direction:column;align-items:center;flex-shrink:0;width:26px;gap:1px}
.stop-icon-emoji{font-size:1rem;line-height:1}
.stop-icon-num{font-size:.62rem;font-weight:700;line-height:1}
body.dark-mode .stop-icon-num{opacity:.8}
.stop-name-wrap{flex:1;display:flex;flex-direction:column}
.stop-name{font-size:.85rem;font-weight:600;color:#333}
.stop-dist{font-size:.72rem;color:#999;margin-top:1px}
.stop-arrow-below{font-size:1.3rem;font-weight:bold;color:#1976d2;display:none;line-height:1.2;animation:bounce-arrow .9s infinite}
.stop-arrow-below.visible{display:block}
body.dark-mode .stop-arrow-below{color:#42a5f5}
@keyframes bounce-arrow{0%,100%{transform:translateY(0)}50%{transform:translateY(4px)}}
.stop-eta{font-size:.8rem;font-weight:bold;margin-left:auto;white-space:nowrap}
#admin-link{position:fixed;bottom:60px;right:12px;background:#1a1a2e;color:white;width:40px;height:40px;border-radius:50%;display:flex;align-items:center;justify-content:center;text-decoration:none;font-size:18px;box-shadow:0 2px 8px rgba(0,0,0,.3);z-index:999;opacity:.5;transition:opacity .2s}
#admin-link:hover{opacity:1}
@media(max-width:600px){#vehicle-panel{width:calc(100% - 24px);top:auto;bottom:200px;right:12px}}

/* Bolinha de conexão no canto inferior direito */
#status-dot-fixed {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 9999;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: #ccc;
    box-shadow: 0 2px 6px rgba(0,0,0,0.3);
}
#status-dot-fixed.online { background: #43a047; }
#status-dot-fixed.warning { background: #fb8c00; animation: pulse 1s infinite; }
#status-dot-fixed.offline { background: #e53935; }

/* ============================================================
   DARK MODE — ativo quando serviço encerrado
   ============================================================ */
body.dark-mode {
    background: #0a0a0a;
}
body.dark-mode #header {
    background: #0d0d1a;
    border-bottom: 1px solid #222;
}
body.dark-mode #map {
    filter: brightness(0.5) saturate(0.3);
}
body.dark-mode #stops-panel {
    background: #111;
    color: #aaa;
    border-top: 1px solid #222;
}
body.dark-mode #stops-header {
    background: #1a1a1a;
    color: #aaa;
    border-bottom: 1px solid #222;
}
body.dark-mode .stop-item {
    border-bottom-color: #222;
    color: #888;
}
body.dark-mode .stop-item.terminal {
    background: #1a1a1a;
}
body.dark-mode .route-tab {
    background: #1a1a1a;
    color: #666;
    border-color: #333 !important;
}
body.dark-mode #service-title {
    color: #444;
}
body.dark-mode #status-bar {
    color: #444;
}

/* Mensagem de serviço encerrado maior e mais visível */
body.dark-mode #status-text {
    font-size: 15px !important;
    color: #ffffff !important;
    font-weight: bold !important;
    line-height: 1.8 !important;
    text-shadow: 0 0 10px rgba(255,255,255,0.3);
    letter-spacing: 0.5px;
}

body.dark-mode #status-dot {
    display: none;
}

/* Rodapé discreto */
#footer-credit {
    position: fixed;
    bottom: 6px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 10px;
    color: rgba(255,255,255,0.35);
    z-index: 999;
    pointer-events: none;
    white-space: nowrap;
    letter-spacing: 0.4px;
}
body.dark-mode #footer-credit {
    color: rgba(255,255,255,0.2);
}


/* ─── OPS/ADMIN CONTROLS ─────────────────────────────────────────────────── */
#ops-controls {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-left: auto;
    padding-right: 4px;
}

#ops-login-btn {
    background: none;
    border: none;
    font-size: 18px;
    cursor: pointer;
    padding: 2px 4px;
    border-radius: 4px;
    opacity: 0.6;
    transition: opacity 0.2s;
    line-height: 1;
}
#ops-login-btn:hover { opacity: 1; }

#ops-badge {
    font-size: 11px;
    font-weight: 600;
    background: #e65100;
    color: #fff;
    padding: 2px 8px;
    border-radius: 10px;
    white-space: nowrap;
}

/* Bus ops tag (🏁 / 🌅) */
.bus-ops-tag {
    position: absolute;
    top: -8px;
    right: -8px;
    font-size: 13px;
    line-height: 1;
    filter: drop-shadow(0 1px 2px rgba(0,0,0,0.5));
}

/* TUI badge — só visível para ops/admin, discreto no canto superior esquerdo */
.bus-tui-tag {
    position: absolute;
    top: -6px;
    left: -6px;
    opacity: 0.82;
    filter: drop-shadow(0 1px 2px rgba(0,0,0,0.4));
    line-height: 1;
}

/* ─── OPS LOGIN MODAL ────────────────────────────────────────────────────── */
#ops-login-modal {
    position: fixed;
    inset: 0;
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
}
#ops-login-modal.hidden { display: none; }

.ops-modal-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.55);
}

.ops-modal-box {
    position: relative;
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.3);
    width: 320px;
    overflow: hidden;
    z-index: 1;
}

.ops-modal-header {
    background: #1565C0;
    color: #fff;
    font-size: 15px;
    font-weight: 700;
    padding: 14px 18px;
}

.ops-modal-body {
    padding: 18px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.ops-modal-body input {
    border: 1px solid #ccc;
    border-radius: 6px;
    padding: 9px 12px;
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s;
}
.ops-modal-body input:focus { border-color: #1565C0; }

.ops-error {
    font-size: 12px;
    color: #d32f2f;
    min-height: 16px;
}

.ops-modal-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    margin-top: 4px;
}
.ops-btn-cancel {
    background: #f5f5f5;
    color: #555;
    border: none;
    border-radius: 6px;
    padding: 8px 16px;
    font-size: 13px;
    cursor: pointer;
}
.ops-btn-cancel:hover { background: #e0e0e0; }
.ops-btn-login {
    background: #1565C0;
    color: #fff;
    border: none;
    border-radius: 6px;
    padding: 8px 18px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
}
.ops-btn-login:hover { background: #0d47a1; }
#ops-vehicles-btn {
    background: none;
    border: none;
    font-size: 16px;
    cursor: pointer;
    padding: 2px 4px;
    border-radius: 4px;
    opacity: 0.7;
    transition: opacity 0.2s;
    line-height: 1;
    display: inline-flex;
    align-items: center;
}
#ops-vehicles-btn:hover { opacity: 1; }
#ops-vehicles-btn.ops-vehicles-off { opacity: 0.3; filter: grayscale(1); }

#ops-report-btn {
    background: none;
    border: none;
    font-size: 16px;
    cursor: pointer;
    padding: 2px 4px;
    border-radius: 4px;
    opacity: 0.7;
    transition: opacity 0.2s;
    line-height: 1;
    display: inline-flex;
    align-items: center;
}
#ops-report-btn:hover { opacity: 1; }


/* --- USER GEOLOCATION ------------------------------------------------------- */
#locate-btn {
  background: none;
  border: none;
  font-size: 18px;
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 4px;
  opacity: 0.75;
  transition: opacity 0.2s;
  line-height: 1;
}
#locate-btn:hover { opacity: 1; }

.user-loc-marker {
  width: 18px; height: 18px;
  background: #2196F3;
  border: 3px solid white;
  border-radius: 50%;
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
  animation: loc-pulse 2s infinite;
}
@keyframes loc-pulse {
  0%   { box-shadow: 0 0 0 0 rgba(33,150,243,0.5); }
  70%  { box-shadow: 0 0 0 12px rgba(33,150,243,0); }
  100% { box-shadow: 0 0 0 0 rgba(33,150,243,0); }
}

#nearest-stop-bar {
  position: fixed;
  bottom: 44px;
  left: 12px; right: 12px;
  background: white;
  border-radius: 12px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.18);
  padding: 10px 14px;
  z-index: 1002;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  border-left: 5px solid #1565C0;
  animation: slide-up 0.3s ease;
}
#nearest-stop-bar.hidden { display: none; }
#nsb-left { display: flex; flex-direction: column; gap: 2px; flex: 1; min-width: 0; }
#nsb-label { font-size: 0.72rem; color: #888; }
#nsb-name { font-size: 0.95rem; font-weight: 700; color: #222; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#nsb-route { font-size: 0.78rem; color: #555; }
#nsb-right { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
#nsb-dist { font-size: 0.9rem; font-weight: 600; color: #1565C0; white-space: nowrap; }
#nsb-close { background: none; border: none; font-size: 1rem; cursor: pointer; color: #999; padding: 4px; line-height: 1; }
@keyframes slide-up { from { transform: translateY(16px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }


/* --- ANDROID: letras maiores para melhor legibilidade ----------------------- */
body.android .bus-body { width:50px; height:50px; font-size:26px; }
body.android .bus-label { font-size:12px; max-width:64px; padding:2px 6px; }
body.android .bus-speed-badge { font-size:11px; }
body.android .bus-wrapper { width:64px; }

body.android .stop-icon-num { font-size:.82rem; }
body.android .stop-name { font-size:1rem; }
body.android .stop-eta { font-size:.92rem; }
body.android .info-row { font-size:.95rem; }
body.android .stop-item { padding:10px 12px; }
