/* ============================================================
   RoutePilot dashboard. Styles for the simulated app shell,
   login gate, KPIs, live map, data tables, and admin panel.
   Loaded after styles.css, reuses the same brand tokens.
   ============================================================ */

.app-body { background: var(--grey); }
.is-hidden { display: none !important; }

/* ---------- Login gate ---------- */
.login {
  min-height: 100vh; display: grid; place-items: center; padding: 1.5rem;
  background:
    radial-gradient(60% 50% at 80% 0%, rgba(45,127,249,.18), transparent 60%),
    linear-gradient(160deg, #0B1F3A 0%, #0c2547 100%);
}
.login__card {
  width: min(100%, 420px); background: #fff; border-radius: var(--r-lg);
  padding: clamp(1.6rem, 4vw, 2.4rem); box-shadow: var(--shadow-lg);
}
.login__card .brand { margin-bottom: 1.4rem; }
.login__title { font-size: 1.6rem; margin-bottom: .3rem; }
.login__sub { color: var(--ink-soft); margin-bottom: 1.6rem; }
.login__demo { margin-top: 1rem; font-size: .85rem; color: var(--ink-faint); line-height: 1.5; }
.login__back { display: inline-block; margin-top: 1.2rem; font-size: .9rem; color: var(--blue); font-weight: 500; }
.login__back:hover { text-decoration: underline; }

/* ---------- Form fields ---------- */
.field { margin-bottom: 1.1rem; }
.field label { display: block; font-size: .9rem; font-weight: 500; margin-bottom: .4rem; color: var(--ink); }
.field input, .field textarea, .field select {
  width: 100%; padding: .8rem .9rem; font: inherit; color: var(--ink);
  background: var(--grey); border: 1.5px solid var(--grey-200); border-radius: var(--r-sm);
  transition: border-color .2s var(--ease), box-shadow .2s var(--ease), background .2s var(--ease);
}
.field input:focus, .field textarea:focus, .field select:focus {
  outline: none; border-color: var(--blue); background: #fff; box-shadow: 0 0 0 4px rgba(45,127,249,.14);
}
.field input.is-invalid, .field textarea.is-invalid, .field select.is-invalid { border-color: #E5484D; box-shadow: 0 0 0 4px rgba(229,72,77,.12); }
.field__error { display: block; min-height: 1rem; margin-top: .35rem; font-size: .82rem; color: #C62A2F; }
.field--ok { color: #1F8A4C; }

/* ---------- App shell ---------- */
.app { display: grid; grid-template-columns: 248px 1fr; min-height: 100vh; }
.app__side { background: #0B1F3A; color: #aebfe0; padding: 1.4rem 1.1rem; display: flex; flex-direction: column; gap: 1.4rem; position: sticky; top: 0; height: 100vh; }
.app__brand { margin-bottom: .6rem; }
.app__nav { display: flex; flex-direction: column; gap: .15rem; }
.app__nav a { display: flex; align-items: center; gap: .6rem; padding: .7rem .8rem; border-radius: var(--r-sm); color: #aebfe0; font-weight: 500; font-size: .96rem; transition: background .2s var(--ease), color .2s var(--ease); }
.app__nav a:hover { background: rgba(255,255,255,.06); color: #fff; }
.app__nav a.is-active { background: rgba(45,127,249,.18); color: #fff; }
.dotnav { width: 8px; height: 8px; border-radius: 50%; background: var(--amber); }
.app__signout { margin-top: auto; background: rgba(255,255,255,.06); color: #cfe0ff; border: 1px solid rgba(255,255,255,.12); padding: .7rem; border-radius: var(--r-sm); font-weight: 500; transition: background .2s var(--ease); }
.app__signout:hover { background: rgba(255,255,255,.12); }

.app__main { padding: clamp(1.2rem, 3vw, 2.2rem); display: flex; flex-direction: column; gap: 1.4rem; min-width: 0; max-width: 100%; }
.app__top { display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.app__crumb { font-family: var(--font-mono); font-size: .74rem; letter-spacing: .1em; text-transform: uppercase; color: var(--ink-faint); }
.app__h1 { font-size: clamp(1.6rem, 3vw, 2.1rem); }
.app__topright { display: flex; align-items: center; gap: 1rem; }
.app__live { display: inline-flex; align-items: center; gap: .45rem; font-size: .85rem; font-weight: 500; color: #1F8A4C; }
.app__live i { width: 8px; height: 8px; border-radius: 50%; background: #36D399; }
.app__user { font-family: var(--font-mono); font-size: .85rem; color: var(--ink-soft); background: #fff; border: 1px solid var(--grey-200); padding: .4rem .7rem; border-radius: var(--r-pill); }

/* ---------- KPI cards ---------- */
.kpis { display: grid; grid-template-columns: repeat(4,1fr); gap: 1rem; }
.kpi { background: #fff; border: 1px solid var(--grey-200); border-radius: var(--r-md); padding: 1.1rem 1.2rem; box-shadow: var(--shadow-sm); display: grid; gap: .3rem; min-width: 0; }
.kpi__label { font-size: .8rem; color: var(--ink-faint); letter-spacing: .02em; }
.kpi__val { font-family: var(--font-mono); font-weight: 700; font-size: 1.9rem; color: var(--navy); font-variant-numeric: tabular-nums; line-height: 1; }
.kpi__unit { font-size: 1rem; color: var(--ink-faint); }
.kpi__delta { font-family: var(--font-mono); font-size: .78rem; }
.kpi__delta.up { color: #1F8A4C; }
.kpi__delta.down { color: #1F6BE0; }

/* ---------- Panels grid ---------- */
.app__grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 1.2rem; min-width: 0; }
.panel { background: #fff; border: 1px solid var(--grey-200); border-radius: var(--r-lg); padding: 1.3rem; box-shadow: var(--shadow-sm); min-width: 0; overflow-x: auto; }
.panel--map, .panel--admin { grid-column: 1 / -1; }
.panel__head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 1rem; }
.panel__head h2 { font-size: 1.15rem; }
.panel__meta { font-family: var(--font-mono); font-size: .76rem; color: var(--ink-faint); letter-spacing: .04em; }

/* ---------- Live map ---------- */
.livemap { border-radius: var(--r-md); overflow: hidden; position: relative; }
.livemap svg { width: 100%; height: auto; display: block; }
.livemap__legend { display: flex; gap: 1.2rem; flex-wrap: wrap; padding: .8rem .2rem 0; font-size: .82rem; color: var(--ink-soft); }
.livemap__legend i { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: .4rem; vertical-align: middle; }
@media (prefers-reduced-motion: no-preference) {
  .lm-route { stroke-dasharray: 1100; stroke-dashoffset: 1100; animation: lmdraw 3s var(--ease) forwards; }
  .lm-route--b { animation-delay: .4s; }
  .lm-route--c { animation-delay: .8s; }
  .lm-van--a { offset-path: path('M70 350 C 180 300, 200 180, 320 170 S 520 150, 640 70'); animation: lmdrive 7s var(--ease) infinite; }
  .lm-van--b { offset-path: path('M80 90 C 200 120, 240 250, 380 250 S 560 320, 650 330'); animation: lmdrive 8s var(--ease) infinite .6s; }
  .lm-van--c { offset-path: path('M120 380 C 260 360, 300 300, 440 320 S 600 380, 660 360'); animation: lmdrive 9s var(--ease) infinite 1.1s; }
}
@keyframes lmdraw { to { stroke-dashoffset: 0; } }
@keyframes lmdrive { 0% { offset-distance: 0%; } 100% { offset-distance: 100%; } }

/* ---------- Data tables ---------- */
.datatable { width: 100%; min-width: 440px; border-collapse: collapse; }
.datatable th, .datatable td { text-align: left; padding: .7rem .8rem; border-bottom: 1px solid var(--grey-200); font-size: .92rem; }
.datatable thead th { font-family: var(--font-mono); font-size: .72rem; letter-spacing: .06em; text-transform: uppercase; color: var(--ink-faint); font-weight: 500; }
.datatable tbody th { font-family: var(--font-mono); font-weight: 700; color: var(--navy); }
.datatable td { color: var(--ink-soft); font-variant-numeric: tabular-nums; }
.datatable tbody tr:last-child th, .datatable tbody tr:last-child td { border-bottom: 0; }
.pill { font-family: var(--font-mono); font-size: .72rem; font-weight: 700; padding: .2rem .6rem; border-radius: var(--r-pill); letter-spacing: .03em; }
.pill--ok { background: rgba(54,211,153,.16); color: #1F8A4C; }
.pill--warn { background: rgba(255,176,32,.18); color: #B5790A; }
.pill--idle { background: var(--grey-200); color: var(--ink-soft); }

/* ---------- Mini bar chart ---------- */
.bars { display: grid; grid-template-columns: repeat(7,1fr); gap: .6rem; align-items: end; height: 200px; padding-top: .5rem; }
.bar { position: relative; height: 100%; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: .5rem; }
.bar::before { content: ''; width: 100%; height: var(--h, 50%); background: linear-gradient(180deg, #4C92FA, #2D7FF9); border-radius: 6px 6px 0 0; transition: height .8s var(--ease); }
.bar--peak::before { background: linear-gradient(180deg, #FFC658, #FFB020); }
.bar span { font-family: var(--font-mono); font-size: .72rem; color: var(--ink-faint); }
@media (prefers-reduced-motion: no-preference) {
  .bar::before { height: 0; animation: grow .9s var(--ease) forwards; }
}
@keyframes grow { to { height: var(--h, 50%); } }

/* ---------- Admin ---------- */
.admin__actions { display: flex; gap: .7rem; flex-wrap: wrap; margin-top: 1.2rem; }
.app__foot { font-size: .82rem; color: var(--ink-faint); padding-top: .5rem; }

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .app__side { position: static; height: auto; flex-direction: row; align-items: center; flex-wrap: wrap; gap: .8rem; }
  .app__nav { flex-direction: row; flex-wrap: wrap; flex: 1; }
  .app__signout { margin: 0; }
  .kpis { grid-template-columns: repeat(2,1fr); }
  .app__grid { grid-template-columns: 1fr; }
}
@media (max-width: 520px) {
  .kpis { grid-template-columns: 1fr 1fr; }
  .app__nav a { padding: .5rem .6rem; font-size: .88rem; }
}