/*
 * Aceleași culori, raze și spațieri ca în aplicația de admin
 * (admin-app/src/utils/theme.ts). Culorile de brand vin din configurația
 * societății și sunt puse pe :root din js/main.js — niciuna nu e scrisă aici.
 */
:root {
  --primary: #111827;
  --primary-dark: #000000;
  --primary-light: #e5e7eb;
  --brand: #ffffff;
  --on-brand: #111827;

  --background: #f5f6f8;
  --surface: #ffffff;
  --border: #e5e7eb;
  --text: #111827;
  --text-muted: #6b7280;
  --success: #16a34a;
  --success-light: #dcfce7;
  --warning: #d97706;
  --warning-light: #fef3c7;
  --danger: #dc2626;
  --danger-light: #fee2e2;
  --offline: #9ca3af;
  --neutral-light: #f3f4f6;

  --xs: 4px;
  --sm: 8px;
  --md: 12px;
  --lg: 16px;
  --xl: 24px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --float: 0 2px 4px rgba(0, 0, 0, 0.15);
  --raised: 0 3px 8px rgba(0, 0, 0, 0.2);

  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  font-size: 15px;
  line-height: 1.4;
  color: var(--text);
  -webkit-text-size-adjust: 100%;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}
html,
body {
  height: 100%;
  margin: 0;
}
body {
  background: var(--background);
}
h1,
h2,
p {
  margin: 0;
}
button,
input {
  font: inherit;
  color: inherit;
}
button {
  cursor: pointer;
}
[hidden] {
  display: none !important;
}
:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}
.sprite {
  position: absolute;
  width: 0;
  height: 0;
}
.icon {
  flex: none;
  width: 20px;
  height: 20px;
  fill: currentColor;
}
.noscript {
  padding: var(--xl);
  text-align: center;
}

/* ---------- Componente comune ---------- */

.button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--sm);
  width: 100%;
  min-height: 46px;
  padding: var(--md) var(--lg);
  border: 1px solid var(--primary);
  border-radius: var(--radius-md);
  background: var(--primary);
  font-weight: 700;
  color: #fff;
  transition: background 0.15s ease, opacity 0.15s ease;
}
.button:hover {
  border-color: var(--primary-dark);
  background: var(--primary-dark);
}
.button:disabled {
  opacity: 0.5;
  cursor: default;
}
.button .icon {
  width: 18px;
  height: 18px;
}
.button--secondary {
  background: var(--surface);
  color: var(--primary);
}
.button--secondary:hover {
  border-color: var(--primary);
  background: var(--primary-light);
}

.badge {
  flex: none;
  padding: 2px var(--sm);
  border-radius: 999px;
  background: var(--neutral-light);
  font-weight: 600;
  font-size: 12px;
  color: var(--text-muted);
}
.badge--success {
  background: var(--success-light);
  color: var(--success);
}

.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--primary-light);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ---------- Autentificare ---------- */

/* Logo-ul stă doar pe culoarea `brand` a societății. */
.login {
  display: flex;
  flex-direction: column;
  min-height: 100%;
  background: var(--brand);
}
.login__brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 48px var(--xl);
}
.login__tagline {
  margin-top: var(--md);
  font-weight: 600;
  font-size: 14px;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--on-brand);
}
.login__form {
  flex: 1;
  width: 100%;
  padding: 36px var(--xl) var(--xl);
  border-radius: var(--xl) var(--xl) 0 0;
  background: var(--surface);
}
.login__form h1 {
  font-weight: 800;
  font-size: 24px;
}
.login__sub {
  margin: var(--xs) 0 var(--xl);
  font-size: 14px;
  color: var(--text-muted);
}
.login__note {
  margin-top: var(--lg);
  font-size: 12px;
  text-align: center;
  color: var(--text-muted);
}
.alert {
  margin-bottom: var(--lg);
  padding: var(--md);
  border-radius: var(--radius-md);
  background: var(--danger-light);
  font-weight: 600;
  font-size: 14px;
  color: var(--danger);
}
.field {
  position: relative;
  display: block;
  margin-bottom: var(--md);
}
.field > span {
  display: block;
  margin-bottom: var(--xs);
  font-weight: 600;
  font-size: 13px;
  color: var(--text-muted);
}
.field input {
  width: 100%;
  padding: var(--md);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
  /* 16px: sub atât, iOS mărește pagina când câmpul primește focus. */
  font-size: 16px;
}
.field input::placeholder {
  color: var(--text-muted);
}
.field input:focus {
  border-color: var(--primary);
  outline: none;
}
.field__eye {
  position: absolute;
  right: var(--xs);
  bottom: 3px;
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border: 0;
  background: none;
  color: var(--text-muted);
}
.field:has(.field__eye) input {
  padding-right: 48px;
}

/* Pe ecrane late: același formular, ca o fișă în mijloc. */
@media (min-width: 720px) {
  .login {
    align-items: center;
    justify-content: center;
    padding: var(--xl);
  }
  .login__brand {
    padding: 0 var(--xl) 32px;
  }
  .login__form {
    flex: none;
    max-width: 420px;
    padding: 32px;
    border-radius: var(--xl);
    box-shadow: var(--raised);
  }
}

/* ---------- Aplicația ---------- */

.app {
  display: grid;
  grid-template-columns: 380px minmax(0, 1fr);
  height: 100vh;
  height: 100dvh;
}

.panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  border-right: 1px solid var(--border);
  background: var(--background);
}
.panel__brand {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: var(--xl) var(--lg);
  background: var(--brand);
  color: var(--on-brand);
}
.panel__brand .logo {
  /* Ceva mai mic decât la autentificare. */
  width: auto;
  height: auto;
  max-height: 64px;
}
.panel__brand p {
  margin-top: var(--md);
  font-weight: 600;
  font-size: 12px;
  letter-spacing: 2px;
  text-transform: uppercase;
}
.panel__close {
  display: none;
}
.search {
  display: flex;
  align-items: center;
  gap: var(--sm);
  margin: var(--lg) var(--lg) 0;
  padding: 0 var(--md);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
  color: var(--text-muted);
}
.search:focus-within {
  border-color: var(--primary);
}
.search input {
  flex: 1;
  min-width: 0;
  padding: var(--md) 0;
  border: 0;
  background: none;
  font-size: 16px;
  color: var(--text);
  outline: none;
}
.panel__list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: var(--lg);
}
.panel__empty {
  padding: var(--xl) var(--lg);
  text-align: center;
  color: var(--text-muted);
}

.group + .group {
  margin-top: var(--lg);
}
.group__head {
  display: flex;
  align-items: center;
  gap: var(--sm);
  margin-bottom: var(--sm);
  font-weight: 800;
  font-size: 12px;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  color: var(--text-muted);
}
.group__head::before {
  content: '';
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--offline);
}
.group--moving .group__head::before {
  background: var(--success);
}
.group--stopped .group__head::before {
  background: var(--warning);
}
.group__head span {
  flex: 1;
}
.group__head b {
  min-width: 22px;
  padding: 1px 6px;
  border-radius: 999px;
  background: var(--surface);
  font-weight: 700;
  text-align: center;
}
.group__rows {
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
}

.row {
  display: flex;
  align-items: center;
  gap: var(--md);
  width: 100%;
  padding: var(--md);
  border: 0;
  background: none;
  text-align: left;
}
.row + .row {
  border-top: 1px solid var(--border);
}
.row:hover {
  background: var(--background);
}
.row.is-active {
  background: var(--primary-light);
}
.row__icon {
  display: grid;
  flex: none;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: var(--radius-md);
  background: var(--neutral-light);
  color: var(--offline);
}
.group--moving .row__icon {
  background: var(--success-light);
  color: var(--success);
}
.group--stopped .row__icon {
  background: var(--warning-light);
  color: var(--warning);
}
.row__icon .icon {
  width: 18px;
  height: 18px;
}
.row__text {
  flex: 1;
  min-width: 0;
}
.row__text strong,
.row__text small {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.row__text strong {
  font-weight: 800;
  font-size: 18px;
  line-height: 1.25;
}
.row__text small {
  font-weight: 600;
  font-size: 12px;
  color: var(--text-muted);
}
.row__right {
  flex: none;
  font-size: 12px;
  color: var(--text-muted);
}
.group--moving .row__right {
  font-weight: 700;
  font-size: 13px;
  color: var(--primary);
}
.row > .icon {
  width: 18px;
  height: 18px;
  color: var(--text-muted);
}

.account {
  padding: var(--lg);
  border-top: 1px solid var(--border);
  background: var(--surface);
}
.account__who {
  display: flex;
  align-items: center;
  gap: var(--md);
  margin-bottom: var(--md);
  color: var(--text-muted);
}
.account__who p {
  min-width: 0;
}
.account__who strong,
.account__who span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.account__who strong {
  color: var(--text);
}
.account__who span {
  font-size: 13px;
}

/* ---------- Harta ---------- */

.stage {
  position: relative;
  min-width: 0;
}
.map {
  position: absolute;
  inset: 0;
}
.state {
  position: absolute;
  inset: 0;
  z-index: 4;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--md);
  padding: var(--xl);
  background: var(--background);
  text-align: center;
  color: var(--text-muted);
}
.state__icon {
  width: 40px;
  height: 40px;
  color: var(--danger);
}
.state .button {
  width: auto;
}

/* Bara de comenzi plutește deasupra fișei vehiculului, ca în aplicație. */
.dock {
  position: absolute;
  left: var(--md);
  bottom: calc(var(--md) + env(safe-area-inset-bottom));
  z-index: 3;
  display: grid;
  gap: var(--md);
  width: min(420px, calc(100% - 2 * var(--md)));
  pointer-events: none;
}
.dock > * {
  pointer-events: auto;
}
.toolbar {
  display: flex;
  align-items: center;
  gap: var(--sm);
  /* Doar butoanele prind clicul; printre ele harta rămâne liberă. */
  pointer-events: none;
}
.toolbar > * {
  pointer-events: auto;
}
.toolbar__buttons {
  display: flex;
  gap: var(--sm);
  margin-left: auto;
}
.pill,
.live,
.round {
  border: 0;
  border-radius: 999px;
  background: var(--surface);
  box-shadow: var(--float);
}
.pill {
  display: flex;
  align-items: center;
  gap: var(--xs);
  min-height: 38px;
  padding: var(--sm) var(--md);
  font-weight: 600;
  font-size: 13px;
  white-space: nowrap;
  /* Pe ecrane late lista e deja deschisă alături: contorul doar informează. */
  pointer-events: none;
}
.pill .icon {
  width: 16px;
  height: 16px;
  color: var(--primary);
}
.pill .pill__more {
  display: none;
  color: var(--text-muted);
}
.live {
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 38px;
  padding: var(--sm) var(--md);
  font-weight: 600;
  font-size: 13px;
  white-space: nowrap;
  color: var(--text-muted);
}
.live::before {
  content: '';
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--warning);
}
.live.is-on {
  color: var(--success);
}
.live.is-on::before {
  background: var(--success);
}
.round {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  color: var(--primary);
}
.round .icon {
  width: 22px;
  height: 22px;
}
.round[aria-pressed='true'] {
  background: var(--primary);
  color: #fff;
}

.card {
  padding: var(--lg);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--raised);
}
.card__head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--md);
}
.card h2 {
  font-weight: 800;
  font-size: 18px;
  line-height: 1.3;
}
.card h2 small {
  font-weight: 500;
  font-size: 13px;
  color: var(--text-muted);
}
.card__close {
  display: grid;
  flex: none;
  place-items: center;
  width: 32px;
  height: 32px;
  margin: -6px -8px 0 0;
  border: 0;
  border-radius: 50%;
  background: none;
  color: var(--text-muted);
}
.card__close:hover {
  background: var(--background);
}
.card__status {
  display: flex;
  align-items: center;
  gap: var(--sm);
  margin-top: var(--xs);
  font-size: 13px;
  color: var(--text-muted);
}
.card__line {
  display: flex;
  align-items: flex-start;
  gap: var(--xs);
  margin-top: 6px;
  font-size: 13px;
}
.card__line .icon {
  width: 14px;
  height: 14px;
  margin-top: 2px;
  color: var(--primary);
}

/* ---------- Markerele ---------- */

.bus {
  --tint: var(--success);
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 0;
  background: none;
}
.bus.is-offline {
  --tint: var(--offline);
}
.bus.is-active {
  --tint: var(--primary);
  width: 54px;
  height: 54px;
}
.bus__dot {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border: 2px solid #fff;
  border-radius: 50%;
  background: var(--tint);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
  color: #fff;
}
.bus__dot .icon {
  width: 18px;
  height: 18px;
}
.bus.is-active .bus__dot {
  width: 38px;
  height: 38px;
  border-width: 3px;
}
.bus.is-active .bus__dot .icon {
  width: 22px;
  height: 22px;
}
/* Săgeata de direcție: un pătrat cât markerul, rotit după direcția de mers,
   cu vârful ieșind din cerc. Doar când vehiculul e în mișcare. */
.bus__arrow {
  position: absolute;
  inset: 0;
  display: none;
  justify-content: center;
}
.bus.is-moving .bus__arrow {
  display: flex;
}
.bus__arrow::before {
  content: '';
  border: solid transparent;
  border-width: 0 6px 9px;
  border-bottom-color: var(--tint);
  height: 0;
}
.bus.is-active .bus__arrow::before {
  border-width: 0 8px 12px;
}
.bus__plate {
  position: absolute;
  top: 100%;
  left: 50%;
  margin-top: -3px;
  padding: 1px 6px;
  border-radius: 999px;
  background: var(--surface);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
  font-weight: 700;
  font-size: 11px;
  line-height: 1.4;
  white-space: nowrap;
  color: var(--text);
  transform: translateX(-50%);
}
.bus.is-active .bus__plate {
  background: var(--primary);
  color: #fff;
}

/* Comenzile hărții, în stilul butoanelor rotunde. */
.maplibregl-ctrl-group {
  overflow: hidden;
  border-radius: var(--radius-md);
  box-shadow: var(--float) !important;
}
.maplibregl-ctrl-top-right {
  top: env(safe-area-inset-top);
}

/* ---------- Telefon: harta pe tot ecranul, lista ca panou deasupra ---------- */

@media (max-width: 899px) {
  .app {
    display: block;
  }
  .stage {
    height: 100%;
  }
  .dock {
    width: auto;
    right: var(--md);
  }
  .pill {
    flex-shrink: 1;
    min-width: 0;
    pointer-events: auto;
  }
  .pill .pill__more {
    display: block;
  }
  .live span {
    display: none;
  }
  .panel {
    position: fixed;
    inset: calc(var(--sm) + env(safe-area-inset-top)) var(--md) calc(var(--md) + env(safe-area-inset-bottom));
    z-index: 10;
    overflow: hidden;
    border: 0;
    border-radius: var(--radius-lg);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2), 0 0 0 100vmax rgba(17, 24, 39, 0.35);
    opacity: 0;
    visibility: hidden;
    transform: translateY(16px);
    transition: opacity 0.18s ease, transform 0.18s ease, visibility 0.18s;
  }
  .app.is-panel-open .panel {
    opacity: 1;
    visibility: visible;
    transform: none;
  }
  .panel__brand {
    padding: var(--lg);
  }
  .panel__brand .logo {
    max-height: 44px;
  }
  .panel__close {
    position: absolute;
    top: var(--sm);
    right: var(--sm);
    display: grid;
    place-items: center;
    width: 40px;
    height: 40px;
    border: 0;
    border-radius: 50%;
    background: none;
    color: inherit;
  }
}

@media (prefers-reduced-motion: reduce) {
  .panel {
    transition: none;
  }
  .spinner {
    animation-duration: 2.4s;
  }
}
