:root {
  --blue: #1a6bb5;
  --blue-dark: #0d3a6e;
  --blue-mid: #1565a8;
  --blue-soft: #e8f1fa;
  --yellow: #f5c518;
  --mute: #e67e22;
  --reset: #e74c6f;
  --text: #1a2b4a;
  --muted: #7a8aa0;
  --white: #fff;
  --nav-h: 64px;
  --top-h: 56px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; font-family: "Segoe UI", Roboto, system-ui, sans-serif; color: var(--text); background: var(--blue-soft); }
button { font: inherit; cursor: pointer; border: none; background: none; }
input, select, textarea { font: inherit; width: 100%; padding: 10px 12px; border: 1px solid #c5d4e8; border-radius: 8px; }

/* Login */
.loco-login-page {
  min-height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(160deg, #0d3a6e 0%, #1a6bb5 55%, #3d8fd4 100%);
  padding: 24px;
}
.login-wrap { width: 100%; max-width: 400px; }
.login-brand { text-align: center; color: #fff; margin-bottom: 24px; }
.login-logo { font-size: 48px; margin-bottom: 8px; }
.login-brand h1 { font-size: 28px; font-weight: 700; }
.login-brand p { opacity: 0.85; margin-top: 4px; }
.login-card {
  background: #fff;
  border-radius: 16px;
  padding: 28px 24px;
  box-shadow: 0 12px 40px rgba(0,0,0,0.2);
}
.login-card h2 { margin-bottom: 16px; color: var(--blue-dark); }
.login-card label { display: block; font-size: 13px; color: var(--muted); margin: 12px 0 6px; }
.login-card button {
  width: 100%;
  margin-top: 20px;
  padding: 12px;
  background: var(--blue-dark);
  color: #fff;
  border-radius: 10px;
  font-weight: 600;
}
.login-error { color: #c0392b; font-size: 13px; margin-top: 10px; }

/* App shell */
.loco-app { height: 100%; overflow: hidden; }
#app { height: 100%; display: flex; flex-direction: column; padding-bottom: var(--nav-h); }
.screen { display: none; flex: 1; flex-direction: column; min-height: 0; overflow: hidden; }
.screen.active { display: flex; }

.top-bar {
  height: var(--top-h);
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  border-bottom: 1px solid #dce6f2;
  flex-shrink: 0;
}
.top-brand { display: flex; align-items: center; gap: 10px; }
.brand-mark { font-size: 22px; }
.top-brand strong { display: block; color: var(--blue-dark); font-size: 15px; }
.top-brand .sub { font-size: 11px; color: var(--muted); }
.top-meta { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
.pill {
  background: var(--blue-soft);
  color: var(--blue-dark);
  font-size: 12px;
  padding: 6px 10px;
  border-radius: 999px;
  white-space: nowrap;
}
.site-pill.in-range { background: #d4edda; color: #1e7e34; }
.site-pill.out-range { background: #f8d7da; color: #a71d2a; }

.track-layout { flex: 1; display: flex; min-height: 0; }
.map-panel { flex: 1.8; position: relative; min-width: 0; }
#map { position: absolute; inset: 0; }
.map-legend {
  position: absolute;
  left: 12px;
  bottom: 12px;
  z-index: 500;
  background: rgba(232, 241, 250, 0.95);
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 12px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.12);
}
.map-legend strong { display: block; margin-bottom: 6px; color: var(--blue-dark); }
.map-legend div { display: flex; align-items: center; gap: 8px; margin: 4px 0; }
.dot { width: 12px; height: 12px; border-radius: 50%; display: inline-block; }
.dot.path { background: #f5c518; }
.dot.pole { background: #888; }
.dot.loco { background: var(--blue); }

.alerts-panel {
  flex: 1;
  min-width: 280px;
  max-width: 380px;
  background: #fff;
  border-left: 1px solid #dce6f2;
  display: flex;
  flex-direction: column;
}
.alerts-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid #eef2f7;
}
.alerts-head h2 { font-size: 16px; color: var(--blue-dark); }
.mute-btn {
  border: 1.5px solid var(--mute);
  color: var(--mute);
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}
.mute-btn.on { background: var(--mute); color: #fff; }
.alerts-list { flex: 1; overflow-y: auto; padding: 12px; }
.alerts-list .empty { text-align: center; color: var(--muted); margin-top: 40px; }
.alert-card {
  border: 1px solid #e0eaf5;
  border-radius: 10px;
  padding: 12px;
  margin-bottom: 10px;
  background: #fafcff;
}
.alert-card strong { color: var(--blue-dark); display: block; margin-bottom: 4px; }
.alert-card .meta { font-size: 12px; color: var(--muted); line-height: 1.5; }
.alert-card .badge {
  display: inline-block;
  margin-top: 8px;
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 6px;
  background: #fff3cd;
  color: #856404;
}
.alert-card .badge.ok { background: #d4edda; color: #155724; }

.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  background: #fff;
  border-bottom: 1px solid #dce6f2;
  flex-shrink: 0;
}
.page-head.light { background: #eef5fb; }
.page-head h1 { font-size: 18px; color: var(--blue-dark); }
.reset-btn { color: var(--reset); font-weight: 700; font-size: 14px; }

.table-wrap { flex: 1; overflow: auto; padding: 0; background: #f3f7fb; }
.data-table { width: 100%; border-collapse: collapse; min-width: 700px; }
.data-table th {
  background: var(--blue-dark);
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  text-align: left;
  padding: 12px 10px;
  position: sticky;
  top: 0;
  z-index: 1;
}
.data-table td {
  padding: 12px 10px;
  font-size: 13px;
  border-bottom: 1px solid #e3ebf5;
  background: #fff;
}
.empty-cell { text-align: center !important; color: var(--muted); padding: 48px 16px !important; background: transparent !important; }
.action-link { color: var(--blue); font-weight: 600; text-decoration: underline; cursor: pointer; }

/* Profile */
#screen-profile { background: var(--blue); overflow-y: auto; }
.profile-hero {
  padding: 36px 20px 48px;
  text-align: center;
  color: #fff;
}
.profile-logo { font-size: 52px; margin-bottom: 8px; }
.profile-hero h1 { font-size: 26px; font-weight: 700; }
.profile-card {
  background: #fff;
  margin-top: -24px;
  border-radius: 20px 20px 0 0;
  padding: 24px 20px 100px;
  min-height: 60%;
}
.profile-card h2 { color: var(--blue-dark); margin-bottom: 16px; }
.profile-row {
  display: flex;
  gap: 14px;
  align-items: center;
  padding: 16px 0;
  border-bottom: 1px solid #eef2f7;
}
.p-icon {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: #e8f1fa;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
}
.profile-row small { display: block; color: var(--muted); font-size: 12px; }
.profile-row strong { font-size: 16px; color: var(--blue-dark); }
.logout-btn {
  margin-top: 28px;
  width: 100%;
  padding: 12px;
  background: var(--blue-dark);
  color: #fff;
  border-radius: 10px;
  font-weight: 600;
}

/* Bottom nav */
.bottom-nav {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  height: var(--nav-h);
  background: var(--blue-dark);
  display: flex;
  z-index: 1000;
  padding-bottom: env(safe-area-inset-bottom);
}
.nav-item {
  flex: 1;
  color: rgba(255,255,255,0.75);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-size: 11px;
}
.nav-ico { font-size: 18px; line-height: 1; padding: 4px 10px; border-radius: 50%; }
.nav-item.active { color: var(--yellow); }
.nav-item.active .nav-ico { background: rgba(255,255,255,0.12); }

/* Modal */
.modal {
  position: fixed; inset: 0; z-index: 2000;
  background: rgba(0,0,0,0.45);
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
}
.modal[hidden] { display: none !important; }
.modal-card {
  background: #fff;
  border-radius: 14px;
  padding: 20px;
  width: 100%;
  max-width: 400px;
}
.modal-card h3 { margin-bottom: 12px; color: var(--blue-dark); }
.modal-card label { display: block; font-size: 12px; color: var(--muted); margin: 10px 0 4px; }
.modal-actions { display: flex; gap: 10px; margin-top: 16px; justify-content: flex-end; }
.btn-ghost { padding: 8px 14px; color: var(--muted); }
.btn-primary { padding: 8px 16px; background: var(--blue-dark); color: #fff; border-radius: 8px; }

@media (max-width: 900px) {
  .track-layout { flex-direction: column; }
  .alerts-panel { max-width: none; min-height: 220px; border-left: none; border-top: 1px solid #dce6f2; }
  .map-panel { min-height: 45vh; }
}
