@import url("https://fonts.googleapis.com/css2?family=Vazirmatn:wght@400;500;600;700&display=swap");

:root {
  --tp-bg: #07070d;
  --tp-elevated: #12121c;
  --tp-pink: #ff2d95;
  --tp-pink-soft: #ff6bb5;
  --tp-cyan: #5ce1ff;
  --tp-text: #f5f5fa;
  --tp-muted: #b8b8c8;
  --tp-glass: rgba(255, 255, 255, 0.12);
  --tp-glass-stroke: rgba(255, 255, 255, 0.33);
  --tp-danger: #ff5c5c;
  --tp-radius: 14px;
  --tp-card: 20px;
  --font: "Vazirmatn", "Segoe UI", Tahoma, system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: #030308;
  color: var(--tp-text);
  font-family: var(--font);
}

.hidden { display: none !important; }

.desktop-chrome {
  text-align: center;
  padding: 0.5rem;
  color: var(--tp-muted);
  font-size: 0.75rem;
}
@media (max-width: 480px) {
  .desktop-chrome { display: none; }
}

.phone {
  position: relative;
  max-width: 430px;
  min-height: 100dvh;
  margin: 0 auto;
  background: var(--tp-bg);
  overflow: hidden;
  box-shadow: 0 0 0 1px rgba(255,255,255,0.06), 0 24px 80px rgba(0,0,0,0.55);
}
@media (min-width: 481px) {
  .phone {
    min-height: calc(100dvh - 2rem);
    margin: 1rem auto;
    border-radius: 28px;
  }
}

.view { min-height: 100dvh; }
.view--shell {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  padding-bottom: env(safe-area-inset-bottom, 0);
}

/* Login */
.view--login { position: relative; }
.login-bg {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse 80% 60% at 20% 30%, rgba(255,45,149,0.12), transparent),
    radial-gradient(ellipse 70% 50% at 80% 70%, rgba(92,225,255,0.1), transparent),
    var(--tp-bg);
}
.login-scroll {
  position: relative;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.25rem 1rem 2rem;
}
.glass-card {
  background: rgba(18, 18, 28, 0.72);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: var(--tp-card);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.45);
}
.login-card {
  width: 100%;
  max-width: 380px;
  padding: 1.75rem 1.5rem 1.5rem;
  text-align: center;
}
.sana-logo { display: block; margin: 0 auto 0.75rem; height: 56px; width: auto; }
.sana-logo--sm { height: 44px; margin: 0 0 0.5rem; }
.title-gradient {
  margin: 0;
  font-size: 1.65rem;
  font-weight: 700;
  background: linear-gradient(90deg, var(--tp-pink), var(--tp-cyan));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.login-hint { margin: 0.5rem 0 0; font-size: 0.8rem; color: var(--tp-muted); }
.login-server { margin: 0.25rem 0 1rem; font-size: 0.68rem; color: rgba(184,184,200,0.65); word-break: break-all; }

.mode-tabs {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
}
.mode-tab {
  flex: 1;
  height: 40px;
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,0.1);
  background: rgba(0,0,0,0.35);
  color: var(--tp-muted);
  font: inherit;
  font-size: 0.82rem;
  cursor: pointer;
  transition: background 0.2s, color 0.2s, border-color 0.2s;
}
.mode-tab.is-active {
  background: rgba(255, 45, 149, 0.22);
  border-color: rgba(255, 45, 149, 0.45);
  color: var(--tp-text);
  font-weight: 600;
}

.field-dark {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-bottom: 0.85rem;
  text-align: right;
  font-size: 0.78rem;
  color: var(--tp-muted);
}
.field-dark input {
  padding: 0.7rem 0.85rem;
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,0.1);
  background: rgba(0,0,0,0.35);
  color: var(--tp-text);
  font: inherit;
  font-size: 0.95rem;
}
.field-dark input:focus {
  outline: 2px solid rgba(92, 225, 255, 0.45);
  border-color: rgba(92, 225, 255, 0.35);
}
.remember-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 1rem;
  font-size: 0.82rem;
  color: var(--tp-muted);
  cursor: pointer;
}

.btn-primary {
  width: 100%;
  padding: 0.85rem;
  border: none;
  border-radius: 14px;
  font: inherit;
  font-weight: 600;
  font-size: 1rem;
  color: #fff;
  cursor: pointer;
  background: linear-gradient(135deg, var(--tp-pink), #c2186b);
  box-shadow: 0 8px 24px rgba(255, 45, 149, 0.35);
  transition: transform 0.15s, opacity 0.15s;
}
.btn-primary:disabled { opacity: 0.55; cursor: wait; }
.btn-primary:hover:not(:disabled) { transform: translateY(-1px); }

.btn-secondary {
  width: 100%;
  margin-bottom: 0.75rem;
  padding: 0.65rem;
  border-radius: 12px;
  border: 1px solid var(--tp-glass-stroke);
  background: rgba(255,255,255,0.06);
  color: var(--tp-text);
  font: inherit;
  cursor: pointer;
}

.error-banner {
  margin-bottom: 0.75rem;
  padding: 0.65rem 0.75rem;
  border-radius: 12px;
  background: rgba(255, 92, 92, 0.15);
  border: 1px solid rgba(255, 92, 92, 0.35);
  color: #ffb4b4;
  font-size: 0.85rem;
  text-align: right;
}
.login-status { min-height: 1.2rem; font-size: 0.8rem; color: var(--tp-cyan); margin-top: 0.5rem; }

/* Shell */
.shell-main {
  flex: 1;
  position: relative;
  min-height: 0;
  background: var(--tp-bg);
}
.screen {
  display: none;
  position: absolute;
  inset: 0;
  flex-direction: column;
}
.screen--active { display: flex; }
.screen--active[data-screen="home"] { display: block; }

.map-topbar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.35rem 0.5rem;
  padding-top: max(0.35rem, env(safe-area-inset-top));
  pointer-events: none;
}
.map-topbar > * { pointer-events: auto; }
.map-title {
  flex: 1;
  margin: 0;
  text-align: center;
  font-size: 1rem;
  font-weight: 600;
  color: #222;
  text-shadow: 0 0 12px rgba(255,255,255,0.85);
}

.icon-glass {
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255,255,255,0.25);
  backdrop-filter: blur(12px);
  color: #2a2a2a;
  cursor: pointer;
  position: relative;
}
.icon-glass svg { width: 22px; height: 22px; }
.icon-glass--pink { color: var(--tp-pink); }
.badge-dot {
  position: absolute;
  top: 4px;
  inset-inline-end: 4px;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: 8px;
  background: var(--tp-pink);
  color: #fff;
  font-size: 10px;
  line-height: 16px;
}

.map-stack {
  position: absolute;
  inset: 0;
  z-index: 1;
}
.maplibre-basemap {
  position: absolute;
  inset: 0;
  z-index: 0;
}
.map {
  position: absolute;
  inset: 0;
  z-index: 2;
  background: #1a2030;
}
.map.map--over-sana {
  background: transparent;
}
.map.map--over-sana .leaflet-tile-pane {
  display: none;
}
.map.map--over-sana .leaflet-container {
  background: transparent;
}
.history-map-wrap {
  position: absolute;
  inset: 0;
  top: 3.25rem;
  bottom: 5.5rem;
  z-index: 1;
}
.history-map {
  width: 100%;
  height: 100%;
  background: #1a2030;
}
.history-panel {
  position: absolute;
  left: 10px;
  right: 10px;
  bottom: 0.65rem;
  z-index: 400;
  padding: 0.65rem 0.75rem;
  border-radius: 18px;
  background: rgba(18, 18, 24, 0.94);
  border: 1px solid rgba(255, 255, 255, 0.08);
}
.history-panel input[type="range"] {
  width: 100%;
  accent-color: var(--tp-pink);
}
.history-meta {
  margin: 0.35rem 0 0;
  font-size: 0.72rem;
  color: var(--tp-muted);
  text-align: center;
}
.map-empty {
  position: absolute;
  z-index: 450;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  text-align: center;
  font-size: 0.85rem;
  color: var(--tp-muted);
  pointer-events: none;
  background: rgba(7, 7, 13, 0.55);
}
.fleet-map-marker {
  background: transparent;
  border: none;
}
.leaflet-marker-icon.fleet-map-marker {
  object-fit: contain;
}

.map-hint {
  position: absolute;
  z-index: 500;
  top: 3.5rem;
  left: 50%;
  transform: translateX(-50%);
  max-width: 90%;
  padding: 0.4rem 0.75rem;
  border-radius: 10px;
  background: rgba(18, 18, 28, 0.92);
  border: 1px solid rgba(255, 45, 149, 0.35);
  color: var(--tp-text);
  font-size: 0.75rem;
  text-align: center;
  pointer-events: none;
}
.map-controls--layers {
  position: absolute;
  z-index: 400;
  inset-inline-end: 12px;
  bottom: 7.5rem;
}
.map-controls .icon-glass { color: var(--tp-pink); }

.home-control-bar {
  position: absolute;
  z-index: 400;
  left: 10px;
  right: 10px;
  bottom: 0.65rem;
  height: 62px;
  display: flex;
  align-items: center;
  justify-content: space-evenly;
  border-radius: 22px;
  background: rgba(18, 18, 24, 0.92);
  box-shadow: 0 8px 32px rgba(0,0,0,0.4);
}
.control-tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  border: none;
  background: none;
  color: var(--tp-muted);
  font: inherit;
  font-size: 0.62rem;
  cursor: pointer;
  opacity: 0.85;
  min-width: 52px;
}
.control-tab:disabled { opacity: 0.35; cursor: default; }
.control-tab__icon svg { width: 20px; height: 20px; }
.control-tab--fab {
  width: 56px;
  height: 56px;
  margin-top: -28px;
  border-radius: 50%;
  background: var(--tp-pink);
  color: #fff;
  box-shadow: 0 8px 24px rgba(255,45,149,0.45);
  justify-content: center;
}
.control-tab--fab svg { width: 28px; height: 28px; }

.bottom-bar {
  display: flex;
  background: rgba(18, 18, 28, 0.96);
  border-top: 1px solid rgba(255,255,255,0.06);
  padding-bottom: env(safe-area-inset-bottom, 0);
  z-index: 600;
}
.bottom-bar__item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 0.45rem 0;
  border: none;
  background: none;
  color: var(--tp-muted);
  font: inherit;
  font-size: 0.68rem;
  cursor: pointer;
}
.bottom-bar__item svg { width: 22px; height: 22px; }
.bottom-bar__item.is-active { color: var(--tp-pink); }

.sub-header {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.65rem 0.5rem;
  background: rgba(18,18,28,0.95);
  border-bottom: 1px solid rgba(255,255,255,0.06);
  z-index: 2;
}
.sub-header h2 { flex: 1; margin: 0; font-size: 1.05rem; text-align: center; }
.icon-plain {
  width: 40px;
  height: 40px;
  border: none;
  background: none;
  color: var(--tp-text);
  cursor: pointer;
}
.icon-plain svg { width: 24px; height: 24px; }

.screen-body {
  flex: 1;
  overflow-y: auto;
  padding: 0.75rem;
}
.glass-scroll { background: linear-gradient(180deg, #0a0a12, var(--tp-bg)); }

.list-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.85rem 1rem;
  margin-bottom: 0.5rem;
  border-radius: var(--tp-radius);
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.08);
  cursor: pointer;
  transition: background 0.15s;
}
.list-row:hover { background: rgba(255,255,255,0.1); }
.list-row__title { font-weight: 600; font-size: 0.9rem; }
.list-row__sub { font-size: 0.75rem; color: var(--tp-muted); margin-top: 0.15rem; }

.device-list { list-style: none; margin: 0; padding: 0.5rem; overflow-y: auto; }
.device-list li button {
  width: 100%;
  text-align: right;
  padding: 0.75rem;
  margin-bottom: 0.35rem;
  border-radius: var(--tp-radius);
  border: 1px solid transparent;
  background: rgba(255,255,255,0.05);
  color: var(--tp-text);
  font: inherit;
  cursor: pointer;
}
.device-list li button.active {
  border-color: rgba(255,45,149,0.45);
  background: rgba(255,45,149,0.12);
}
.dot-online {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-inline-end: 0.35rem;
  vertical-align: middle;
}
.dot-online.on { background: #3ddc84; }
.dot-online.off { background: #64748b; }

.drawer { position: fixed; inset: 0; z-index: 900; pointer-events: none; }
.drawer.is-open { pointer-events: auto; }
.drawer__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.55);
  opacity: 0;
  transition: opacity 0.25s;
}
.drawer.is-open .drawer__backdrop { opacity: 1; }
.drawer__panel {
  position: absolute;
  top: 0;
  bottom: 0;
  right: 0;
  left: auto;
  width: min(88%, 320px);
  padding: 1.25rem 1rem;
  background: rgba(12, 12, 20, 0.96);
  border-left: 1px solid rgba(255,255,255,0.08);
  transform: translateX(100%);
  transition: transform 0.28s ease;
  overflow-y: auto;
}
.drawer.is-open .drawer__panel { transform: translateX(0); }
.drawer__title { margin: 0 0 1rem; font-weight: 600; }
.drawer__nav { display: flex; flex-direction: column; gap: 0.35rem; }
.drawer__item {
  padding: 0.7rem 0.85rem;
  border-radius: var(--tp-radius);
  border: 1px solid transparent;
  background: rgba(255,255,255,0.06);
  color: var(--tp-text);
  text-align: right;
  font: inherit;
  cursor: pointer;
}
.drawer__item.is-active { border-color: rgba(255,45,149,0.4); background: rgba(255,45,149,0.14); }
.drawer__logout {
  margin-top: 1rem;
  width: 100%;
  padding: 0.7rem;
  border-radius: 12px;
  border: 1px solid rgba(255,92,92,0.35);
  background: rgba(255,92,92,0.12);
  color: #ffb4b4;
  font: inherit;
  cursor: pointer;
}
.drawer__ver { margin-top: 1rem; font-size: 0.7rem; color: var(--tp-muted); opacity: 0.6; }

.muted { color: var(--tp-muted); }
.center { text-align: center; }

@media (prefers-reduced-motion: reduce) {
  .drawer__panel, .drawer__backdrop, .btn-primary, .mode-tab { transition: none; }
}
