:root {
  /* Paleta institucional Tec de Monterrey (Azul TEC #0039A6) */
  --bg: #f0f8fe;
  --bg-deep: #0039a6;
  --bg-mid: #0052cc;
  --surface: #ffffff;
  --ink: #0a0a0a;
  --muted: #5a6b7d;
  --accent: #4d8dff;
  --accent-ink: #ffffff;
  --danger: #b42318;
  --line: rgba(0, 57, 166, 0.14);
  --shadow: 0 12px 40px rgba(0, 57, 166, 0.18);
  --radius: 16px;
  --font: "DM Sans", system-ui, sans-serif;
  --display: "Fraunces", Georgia, serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg);
}

body {
  min-height: 100dvh;
}

#app {
  min-height: 100dvh;
  position: relative;
}

.screen {
  display: none;
  min-height: 100dvh;
  flex-direction: column;
}

.screen.active {
  display: flex;
}

/* Welcome */
.welcome-bg {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse 70% 45% at 85% 15%, rgba(77, 141, 255, 0.45), transparent 55%),
    linear-gradient(160deg, #001f5c 0%, #0039a6 42%, #0052cc 100%),
    url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23ffffff' fill-opacity='0.04'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
  z-index: 0;
  animation: wash 12s ease-in-out infinite alternate;
}

@keyframes wash {
  from { filter: saturate(1) brightness(1); }
  to { filter: saturate(1.08) brightness(1.05); }
}

.welcome-content {
  position: relative;
  z-index: 1;
  margin: auto;
  width: min(420px, calc(100% - 2rem));
  padding: 2rem 0 3rem;
  color: #ffffff;
  animation: rise 0.7s ease-out both;
}

@keyframes rise {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: translateY(0); }
}

.brand-lockup {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  margin-bottom: 1rem;
}

.brand-mark {
  flex: 0 0 auto;
  width: 56px;
  height: 56px;
  border-radius: 14px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.22);
}

.brand {
  font-family: var(--display);
  font-size: clamp(1.85rem, 7vw, 2.5rem);
  font-weight: 700;
  margin: 0;
  letter-spacing: -0.02em;
  line-height: 1.05;
}

.brand-eyebrow {
  margin: 0 0 0.2rem;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.7);
}

.members-block {
  display: grid;
  gap: 0.55rem;
  margin-top: 0.35rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--line);
}

.members-block h3 {
  margin: 0;
  font-size: 0.9rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.member-add-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.45rem;
  align-items: center;
}

.member-add-row select {
  font: inherit;
  padding: 0.55rem 0.65rem;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  min-width: 0;
}

.members-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.4rem;
}

.members-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  padding: 0.55rem 0.7rem;
  border-radius: 10px;
  background: #eef4fc;
  font-size: 0.9rem;
  color: var(--ink);
}

.members-list li strong {
  color: var(--ink);
}

.welcome-content h1 {
  font-family: var(--font);
  font-size: 1.1rem;
  font-weight: 500;
  margin: 0 0 0.5rem;
  color: rgba(255, 255, 255, 0.94);
  line-height: 1.35;
}

.lead {
  margin: 0 0 1.35rem;
  color: rgba(255, 255, 255, 0.72);
  line-height: 1.45;
}

.login-form {
  display: grid;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.login-error {
  margin: 0;
  padding: 0.65rem 0.75rem;
  border-radius: 10px;
  background: rgba(180, 35, 24, 0.9);
  color: #fff;
  font-size: 0.88rem;
  line-height: 1.35;
}

.login-hint {
  color: rgba(255, 255, 255, 0.65) !important;
  font-size: 0.8rem;
}

.user-form {
  display: grid;
  gap: 0.75rem;
  margin-bottom: 1.5rem;
  padding-bottom: 1.25rem;
  border-bottom: 1px solid var(--line);
}

.user-form h2,
.users-block h2 {
  margin: 0;
  font-size: 1.1rem;
}

.field select {
  font: inherit;
  padding: 0.7rem 0.8rem;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
}

.users-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.55rem;
}

.users-list li {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  align-items: center;
  padding: 0.85rem 0.95rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.user-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  justify-content: flex-end;
}

.name-field {
  margin-top: 0;
}

.name-field span {
  color: rgba(255, 255, 255, 0.75);
}

.name-field input {
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(255, 255, 255, 0.22);
  color: #fff;
}

.name-field input::placeholder {
  color: rgba(255, 255, 255, 0.45);
}

.panel-sub {
  margin: 0.2rem 0 0;
  font-size: 0.85rem;
  color: var(--muted);
  font-weight: 400;
}

.role-tip {
  margin: 0;
  padding: 0.7rem 0.85rem;
  border-radius: 12px;
  background: #e8f2fe;
  color: var(--bg-deep);
  font-size: 0.88rem;
  line-height: 1.4;
}

.role-tip:empty {
  display: none;
}

.map-wrap {
  position: relative;
  flex: 1;
  min-height: 42vh;
  display: flex;
  flex-direction: column;
}

.map-wrap .map {
  flex: 1;
  min-height: 42vh;
}

.campus-chips {
  position: absolute;
  top: 0.65rem;
  left: 0.65rem;
  right: 0.65rem;
  z-index: 500;
  display: flex;
  gap: 0.4rem;
  overflow-x: auto;
  padding-bottom: 0.15rem;
  scrollbar-width: none;
}

.map-crosshair {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 22px;
  height: 22px;
  margin: -11px 0 0 -11px;
  z-index: 450;
  pointer-events: none;
  border: 2px solid #0039a6;
  border-radius: 50%;
  box-shadow: 0 0 0 2px #fff, 0 2px 8px rgba(0, 57, 166, 0.35);
}

.map-crosshair::before,
.map-crosshair::after {
  content: '';
  position: absolute;
  background: #0039a6;
}

.map-crosshair::before {
  left: 50%;
  top: -8px;
  bottom: -8px;
  width: 2px;
  margin-left: -1px;
}

.map-crosshair::after {
  top: 50%;
  left: -8px;
  right: -8px;
  height: 2px;
  margin-top: -1px;
}

.map-drop-btn {
  position: absolute;
  left: 50%;
  bottom: 0.7rem;
  transform: translateX(-50%);
  z-index: 600;
  appearance: none;
  border: none;
  border-radius: 999px;
  padding: 0.7rem 1.1rem;
  font: inherit;
  font-size: 0.88rem;
  font-weight: 700;
  background: var(--bg-deep);
  color: #fff;
  box-shadow: 0 6px 18px rgba(0, 57, 166, 0.35);
  cursor: pointer;
  white-space: nowrap;
}

.campus-chips::-webkit-scrollbar {
  display: none;
}

.campus-chip {
  appearance: none;
  flex: 0 0 auto;
  border: none;
  border-radius: 999px;
  padding: 0.4rem 0.75rem;
  font: inherit;
  font-size: 0.78rem;
  font-weight: 600;
  background: rgba(255, 255, 255, 0.94);
  color: var(--bg-deep);
  box-shadow: 0 4px 14px rgba(0, 57, 166, 0.18);
  cursor: pointer;
}

.campus-chip.active {
  background: var(--bg-deep);
  color: #fff;
}

.map-legend {
  position: absolute;
  left: 0.65rem;
  bottom: 0.65rem;
  z-index: 500;
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem 0.7rem;
  padding: 0.45rem 0.65rem;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: 0 4px 14px rgba(0, 57, 166, 0.15);
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--ink);
}

.map-legend .dot {
  display: inline-block;
  width: 0.55rem;
  height: 0.55rem;
  border-radius: 50%;
  margin-right: 0.25rem;
  vertical-align: middle;
}

.dot-start { background: var(--bg-deep); }
.dot-stop { background: #f59e0b; }
.dot-end { background: var(--danger); }
.dot-driver { background: var(--accent); }
.dot-parent { background: #00a3e0; }

.steps {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.35rem;
}

.steps li {
  text-align: center;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.4rem 0.25rem;
  border-radius: 8px;
  background: #eef4fc;
  color: var(--muted);
}

.steps li.active {
  background: var(--bg-deep);
  color: #fff;
}

.steps li.done {
  background: #cfe0fb;
  color: var(--bg-deep);
}

/* Buttons */
.btn {
  appearance: none;
  border: none;
  border-radius: 12px;
  padding: 0.85rem 1.1rem;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}

.btn:active {
  transform: scale(0.98);
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--bg-deep);
  color: #ffffff;
  box-shadow: 0 8px 24px rgba(0, 57, 166, 0.35);
}

.welcome-content .btn-primary {
  background: #ffffff;
  color: var(--bg-deep);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
  width: 100%;
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.2);
}

#screen-routes .btn-secondary,
#screen-create .btn-secondary,
#screen-trip .btn-secondary,
#screen-users .btn-secondary,
#screen-password .btn-secondary {
  background: #e8f2fe;
  color: var(--bg-deep);
  border: 1px solid var(--line);
}

.btn-danger {
  background: var(--danger);
  color: #fff;
}

.btn-small {
  padding: 0.45rem 0.75rem;
  font-size: 0.875rem;
  background: var(--bg-deep);
  color: #fff;
}

.btn-block {
  width: 100%;
}

.btn-icon {
  appearance: none;
  border: none;
  background: transparent;
  font-size: 1.35rem;
  line-height: 1;
  padding: 0.35rem 0.5rem;
  cursor: pointer;
  color: inherit;
}

/* Topbar */
.topbar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 20;
}

.topbar-brand {
  margin: 0;
  font-family: var(--display);
  font-weight: 700;
  font-size: 1.05rem;
}

.topbar-meta {
  margin: 0;
  font-size: 0.8rem;
  color: var(--muted);
}

.topbar-grow {
  flex: 1;
  min-width: 0;
}

.user-chip {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.05rem;
  max-width: 9.5rem;
  line-height: 1.15;
  text-align: right;
}

.user-chip[hidden] {
  display: none !important;
}

.user-chip-name {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.user-chip-role {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--bg-deep);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.badge {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 0.35rem 0.55rem;
  border-radius: 999px;
  background: #e8f2fe;
  color: var(--bg-deep);
}

.badge.live {
  background: var(--accent);
  color: #ffffff;
  animation: pulse 1.6s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.7; }
}

/* Panels */
.panel {
  padding: 1rem 1.1rem 2rem;
  width: min(560px, 100%);
  margin: 0 auto;
  color: var(--ink);
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.75rem;
}

.panel-head h2 {
  margin: 0;
  font-size: 1.25rem;
}

.routes-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.65rem;
}

.routes-list li button {
  width: 100%;
  text-align: left;
  appearance: none;
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  font: inherit;
  cursor: pointer;
  transition: border-color 0.15s ease, transform 0.15s ease;
}

.routes-list li button:hover {
  border-color: var(--bg-mid);
}

.route-name {
  display: block;
  font-weight: 600;
  margin-bottom: 0.2rem;
}

.route-meta {
  display: block;
  font-size: 0.85rem;
  color: var(--muted);
}

.empty {
  color: var(--muted);
  text-align: center;
  padding: 2rem 1rem;
}

/* Map + sheet */
.map {
  flex: 1;
  min-height: 42vh;
  background: #d6e6f7;
  z-index: 1;
}

.sheet {
  background: var(--surface);
  border-radius: 20px 20px 0 0;
  box-shadow: var(--shadow);
  padding: 1.1rem 1.1rem calc(1.1rem + env(safe-area-inset-bottom));
  display: grid;
  gap: 0.85rem;
  z-index: 10;
  color: var(--ink);
}

.sheet-trip {
  max-height: 48vh;
  overflow: auto;
}

.field {
  display: grid;
  gap: 0.35rem;
  font-size: 0.85rem;
}

.field span {
  color: var(--muted);
  font-weight: 500;
}

.field input {
  font: inherit;
  padding: 0.7rem 0.8rem;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
}

.hint {
  margin: 0;
  font-size: 0.85rem;
  color: var(--muted);
  line-height: 1.4;
}

.schedule-row {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 0.5rem;
  align-items: end;
}

.schedule-row-create {
  grid-template-columns: 1fr 1fr;
}

.route-schedule {
  color: var(--bg-deep) !important;
  font-weight: 600;
}

.place-modes {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.4rem;
}

.place-mode {
  appearance: none;
  border: 1px solid var(--line);
  background: #eef4fc;
  color: var(--muted);
  border-radius: 10px;
  padding: 0.55rem 0.35rem;
  font: inherit;
  font-size: 0.8rem;
  font-weight: 700;
  cursor: pointer;
}

.place-mode.active {
  background: var(--bg-deep);
  color: #fff;
  border-color: var(--bg-deep);
}

.sheet-editor {
  max-height: 52vh;
  overflow: auto;
}

.stops-block {
  display: grid;
  gap: 0.5rem;
}

.stops-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.75rem;
}

.stops-head h3 {
  margin: 0;
  font-size: 0.9rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.stops-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.4rem;
}

.stops-list li {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 0.45rem;
  align-items: center;
  padding: 0.35rem 0.45rem;
  border-radius: 10px;
  background: #eef4fc;
}

.stop-num {
  width: 1.5rem;
  height: 1.5rem;
  border-radius: 50%;
  background: #f59e0b;
  color: #fff;
  font-size: 0.75rem;
  font-weight: 700;
  display: grid;
  place-items: center;
}

.stop-name {
  font: inherit;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.4rem 0.55rem;
  background: #fff;
  color: var(--ink);
  min-width: 0;
}

.stop-remove {
  color: var(--danger);
  font-size: 1.25rem;
}

.actions-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
}

.hint-warn {
  color: #9a3412 !important;
  background: #ffedd5;
  padding: 0.55rem 0.7rem;
  border-radius: 10px;
}

#btn-share-location.share-active {
  background: var(--bg-deep) !important;
  color: #fff !important;
  border-color: var(--bg-deep) !important;
}

.events h3 {
  margin: 0 0 0.5rem;
  font-size: 0.9rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.events-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.4rem;
}

.events-list li {
  font-size: 0.9rem;
  padding: 0.55rem 0.7rem;
  border-radius: 10px;
  background: #eef4fc;
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  color: var(--ink);
}

.events-list li.event-near {
  background: #fff4d6;
  border: 1px solid #f0c14b;
}

.events-list .ts {
  color: var(--muted);
  font-size: 0.75rem;
  white-space: nowrap;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 1.5rem;
  transform: translateX(-50%) translateY(20px);
  background: var(--bg-deep);
  color: #fff;
  padding: 0.75rem 1.1rem;
  border-radius: 12px;
  font-size: 0.9rem;
  z-index: 100;
  opacity: 0;
  transition: opacity 0.25s ease, transform 0.25s ease;
  max-width: min(90vw, 360px);
  text-align: center;
  box-shadow: var(--shadow);
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* Leaflet markers */
.marker-pin {
  width: 28px;
  height: 28px;
  border-radius: 50% 50% 50% 0;
  transform: rotate(-45deg);
  border: 2px solid #fff;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
}

.marker-pin span {
  display: block;
  width: 100%;
  height: 100%;
  transform: rotate(45deg);
  font-size: 11px;
  line-height: 24px;
  text-align: center;
  color: #fff;
  font-weight: 700;
}

.pin-start { background: var(--bg-deep); }
.pin-stop { background: #f59e0b; }
.pin-end { background: var(--danger); }
.pin-driver { background: var(--accent); }
.pin-parent { background: #00a3e0; }

@media (min-width: 768px) {
  #screen-create,
  #screen-trip {
    display: none;
  }

  #screen-create.active,
  #screen-trip.active {
    display: grid;
    grid-template-columns: 1fr min(380px, 40vw);
    grid-template-rows: auto 1fr;
  }

  #screen-create.active .topbar,
  #screen-trip.active .topbar {
    grid-column: 1 / -1;
  }

  #screen-create.active .map-wrap,
  #screen-trip.active .map-wrap,
  #screen-create.active .map,
  #screen-trip.active .map {
    min-height: 0;
    height: 100%;
  }

  #screen-create.active .sheet,
  #screen-trip.active .sheet {
    border-radius: 0;
    max-height: none;
    overflow: auto;
  }
}

.telegram-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin: 0 0 1rem;
  padding: 0.7rem 0.85rem;
  border-radius: 12px;
  background: #e8f1ff;
  border: 1px solid var(--line);
}

.telegram-banner p {
  margin: 0;
  font-size: 0.88rem;
  color: var(--ink);
}

.telegram-form {
  border-bottom: 0;
}

.telegram-form .telegram-code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 1.4rem;
  letter-spacing: 0.12em;
  font-weight: 700;
  margin: 0;
  padding: 0.6rem 0.8rem;
  border-radius: 10px;
  background: #eef4fc;
  text-align: center;
}
