:root {
  color-scheme: light;
  --paper: #faf8f4;
  --surface: #fffdfa;
  --ink: #233746;
  --muted: #536671;
  --primary: #294e62;
  --border: #d6dcd9;
  --brand: #9f4037;
  font-family: system-ui, -apple-system, sans-serif;
  color: var(--ink);
  background: var(--paper);
}

* { box-sizing: border-box; }
body { margin: 0; font-size: 1rem; line-height: 1.5; }
a { color: var(--primary); }
button, input { font: inherit; }
button { cursor: pointer; }
a:focus-visible, button:focus-visible, input:focus-visible { outline: 3px solid #315f7a; outline-offset: 3px; }
h1, h2, h3, p { margin: 0; }
h1 { font-size: clamp(2.15rem, 4.5vw, 3.5rem); line-height: 1.08; letter-spacing: -.05em; }
h2 { font-size: 1.3rem; line-height: 1.25; letter-spacing: -.025em; }

.topbar { background: var(--surface); border-bottom: 1px solid var(--border); }
.topbar-inner {
  width: min(1120px, calc(100% - 3rem));
  margin-inline: auto;
}
.topbar-inner { min-height: 68px; display: flex; align-items: center; justify-content: space-between; }
.wordmark { color: var(--ink); font: 700 2.25rem/1 Georgia, serif; letter-spacing: -.095em; text-decoration: none; }
.wordmark span { color: var(--brand); }
.logout, .refresh {
  display: inline-flex; align-items: center; min-height: 44px;
  padding: .4rem .9rem; border: 1px solid var(--border); border-radius: .55rem;
  background: var(--surface); color: var(--primary); font-weight: 650; text-decoration: none;
}
.logout:hover, .refresh:hover { background: #edf4f8; }
.panel { border: 1px solid var(--border); background: var(--surface); border-radius: 1rem; }

.signin-form { align-self: center; padding: clamp(1.5rem, 5vw, 3rem); display: grid; gap: .55rem; }
.signin-form label { font-weight: 650; }
.signin-form input {
  width: 100%; min-height: 48px; padding: .65rem .75rem; border: 1px solid #a0aeb1; border-radius: .55rem;
  color: var(--ink); background: #fff;
}
.signin-form input + label { margin-top: .45rem; }
.primary { margin-top: .8rem; min-height: 48px; border: 0; border-radius: .55rem; background: var(--primary); color: #fff; font-weight: 700; }
.primary:hover { background: #203d4e; }
.error { border-left: 3px solid var(--brand); padding-left: .65rem; color: #803328; }

.dashboard-shell {
  display: grid;
  grid-template-columns: clamp(12.5rem, 20vw, 16rem) minmax(0, 1fr);
  min-height: 100dvh;
  background: #f5f6f5;
}
.rail {
  align-self: start;
  position: sticky;
  top: 0;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: #162632;
  color: #f5f8fa;
  padding: 1.45rem 1rem 1rem;
}
.rail-brand { padding: .35rem .75rem 2.3rem; }
.rail .wordmark { color: #fff8f0; font-size: 2.55rem; }
.rail .wordmark span { color: #ef988b; }
.devices { display: grid; gap: .4rem; }
.devices h2 {
  padding: 0 .75rem .4rem;
  color: #bbcbd4;
  font-size: .875rem;
  letter-spacing: .02em;
}
.device-link {
  display: grid;
  gap: .12rem;
  min-width: 0;
  padding: .65rem .75rem;
  border: 1px solid transparent;
  border-radius: .75rem;
  text-decoration: none;
  color: #f6f8fa;
  overflow-wrap: anywhere;
}
.device-link:hover { background: #223746; }
.device-link[aria-current] { background: #294354; border-color: #496678; box-shadow: inset 3px 0 #9ebfdd; }
.device-link strong { font-size: .925rem; }
.device-link span { font-size: .875rem; color: #c3d1da; font-variant-numeric: tabular-nums; }
.account {
  margin-top: auto;
  padding: 1rem 0 0;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: .5rem;
}
.account::before { content: ""; grid-column: 1 / -1; height: 1px; background: #40515e; margin-bottom: .5rem; }
.account form { grid-column: 1 / -1; }
.initials {
  display: grid;
  place-items: center;
  width: 2rem;
  height: 2rem;
  border-radius: .6rem;
  background: #c3ddf1;
  color: #203d4e;
  font-size: .875rem;
  font-weight: 750;
}
.account-name { font-size: .875rem; font-weight: 600; overflow-wrap: anywhere; }
.account .logout {
  background: transparent;
  color: #e1ebf1;
  border-color: #526674;
  min-height: 38px;
  padding: .3rem .6rem;
  font-size: .875rem;
  width: 100%;
}
.account .logout:hover { background: #294354; }
.rail :focus-visible { outline-color: #b6def2; }

.dashboard {
  width: min(100%, 90rem);
  margin-inline: auto;
  padding: 0 clamp(1rem, 3vw, 3rem) 3rem;
  min-width: 0;
}
.dashboard-top {
  height: 72px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .75rem;
  border-bottom: 1px solid #dbe1df;
  color: #455966;
  font-weight: 650;
}
.refresh { min-height: 40px; border-color: #cdd8da; font-size: .875rem; }
.device-head { padding: clamp(1.35rem, 3.5vw, 2.2rem) 0 1.6rem; }
.device-head h1 { font-size: clamp(1.9rem, 3.8vw, 3rem); overflow-wrap: anywhere; }
.device-details {
  margin-top: .65rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .55rem .75rem;
  color: #536671;
  font-size: .925rem;
  font-variant-numeric: tabular-nums;
}
.model {
  border: 1px solid #d3dedd;
  border-radius: .38rem;
  padding: .07rem .4rem;
  font-size: .875rem;
  background: #fcfdfa;
}
.metrics { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .8rem; margin-bottom: 1.2rem; }
.metric, .dashboard .panel { border: 1px solid #d6dfdf; background: #fffdfa; border-radius: .9rem; }
.metric { padding: clamp(.75rem, 1.9vw, 1.15rem); min-width: 0; }
.metric-head { display: flex; align-items: center; gap: .55rem; }
.metric-head h2 { color: #455966; font-size: .9rem; letter-spacing: 0; }
.metric-value { font-size: clamp(1.2rem, 2.4vw, 1.6rem); font-weight: 750; letter-spacing: -.035em; margin-top: .55rem; overflow-wrap: anywhere; }
.metric-detail { color: #526572; font-size: .875rem; margin-top: .15rem; }
.metric-value time, .metric-detail time { font-variant-numeric: tabular-nums; }
.metric.good .metric-value { color: #2b593f; }
.metric.caution .metric-value { color: #843929; }
.metric-icon {
  display: grid;
  flex: 0 0 2rem;
  height: 2rem;
  place-items: center;
  position: relative;
  border-radius: .58rem;
  color: #365e76;
  background: #e5eef5;
}
.good .metric-icon { color: #2b593f; background: #e6f0e8; }
.caution .metric-icon { color: #843929; background: #f8e8dc; }
.battery-icon::before {
  content: "";
  width: .85rem;
  height: .46rem;
  border: 1.5px solid currentColor;
  border-radius: .12rem;
  background: linear-gradient(currentColor, currentColor) .13rem center / .52rem .24rem no-repeat;
}
.caution .battery-icon::before { background-size: .18rem .24rem; }
.battery-icon::after { content: ""; position: absolute; width: .11rem; height: .24rem; top: .88rem; right: .38rem; background: currentColor; border-radius: 0 .08rem .08rem 0; }
.shield-icon::before {
  content: "";
  width: .84rem;
  height: 1rem;
  background: currentColor;
  clip-path: polygon(50% 0, 100% 18%, 92% 70%, 68% 93%, 50% 100%, 32% 93%, 8% 70%, 0 18%);
}
.shield-icon::after { content: ""; position: absolute; width: .22rem; height: .42rem; border: solid #fff; border-width: 0 1.4px 1.4px 0; transform: rotate(42deg); top: .64rem; }
.signal-icon::before {
  content: "";
  width: .9rem;
  height: .92rem;
  background: linear-gradient(currentColor 0 0) left bottom / .16rem .38rem no-repeat,
              linear-gradient(currentColor 0 0) center bottom / .16rem .62rem no-repeat,
              linear-gradient(currentColor 0 0) right bottom / .16rem .86rem no-repeat;
}

.workspace { display: grid; grid-template-columns: minmax(0, 1fr) minmax(13rem, .52fr); gap: 1.15rem; align-items: start; }
.section-head { padding: .95rem clamp(.8rem, 2vw, 1.25rem); border-bottom: 1px solid #e0e6e4; }
.section-head h2, .location h2 { font-size: 1.125rem; letter-spacing: -.02em; }
.filters {
  display: flex;
  flex-wrap: wrap;
  gap: .2rem;
  width: fit-content;
  margin-top: .65rem;
  padding: .2rem;
  border-radius: .6rem;
  background: #eef2f2;
}
.filters a {
  min-height: 36px;
  display: grid;
  place-items: center;
  padding: .25rem .75rem;
  border: 1px solid transparent;
  border-radius: .45rem;
  text-decoration: none;
  color: #455966;
  font-size: .875rem;
  font-weight: 650;
}
.filters a[aria-current] { background: #fff; border-color: #d6dfdf; color: #203d4e; }
.filters a:hover { color: #1b3f58; text-decoration: underline; text-underline-offset: .16em; }
.timeline { margin: 0; padding: 0; list-style: none; }
.event {
  padding: .8rem clamp(.8rem, 2vw, 1.25rem);
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: .7rem;
  align-items: start;
}
.event + .event { border-top: 1px solid #e4e8e5; }
.event-symbol { display: grid; width: 2rem; height: 2rem; border-radius: .55rem; place-items: center; background: #edf1f3; color: #516977; }
.event-symbol::before { content: ""; width: .45rem; height: .45rem; border-radius: 50%; background: currentColor; }
.event-symbol.battery { background: #e5f1e8; color: #366a4c; }
.event-symbol.warning { background: #f8e8dc; color: #9f4037; }
.event-symbol.gps { background: #e6f0f7; color: #2b6388; }
.event-symbol.gps::before { width: .55rem; height: .55rem; border: 1.5px solid currentColor; background: transparent; }
.event-main { min-width: 0; overflow-wrap: anywhere; }
.event-main strong { font-weight: 700; }
.event-category, .event-detail, .event-side time { color: #536671; font-size: .875rem; }
.event-category { display: block; }
.event-detail { margin-top: .12rem; }
.event-side { display: grid; gap: .1rem; text-align: right; }
.event-side time { font-variant-numeric: tabular-nums; }
.map-link { font-size: .875rem; font-weight: 650; text-underline-offset: .16em; }

.location { padding: clamp(.85rem, 2vw, 1.25rem); min-width: 0; }
.location-figure {
  position: relative;
  height: clamp(5rem, 12vw, 8.6rem);
  margin-top: .85rem;
  border: 1px solid #d0e1ed;
  border-radius: .65rem;
  overflow: hidden;
  background:
    radial-gradient(circle at center, transparent 0 1.2rem, #c4dceb 1.24rem 1.33rem, transparent 1.38rem 2.35rem, #c4dceb 2.39rem 2.48rem, transparent 2.53rem),
    repeating-linear-gradient(0deg, transparent 0 1.15rem, rgb(44 98 132 / .09) 1.15rem 1.22rem),
    repeating-linear-gradient(90deg, transparent 0 1.15rem, rgb(44 98 132 / .09) 1.15rem 1.22rem),
    #eaf3f9;
}
.location-pin {
  display: block;
  position: absolute;
  top: 50%;
  left: 50%;
  width: 1.17rem;
  height: 1.17rem;
  transform: translate(-50%, -64%) rotate(-45deg);
  background: #264f6b;
  border-radius: 55% 55% 55% 0;
  box-shadow: 0 0 0 .18rem #fffdfa;
}
.location-pin::after { content: ""; position: absolute; inset: .39rem; background: #fff; border-radius: 50%; }
.coordinates { font-weight: 750; font-size: clamp(.95rem, 1.7vw, 1.15rem); margin: .7rem 0 .1rem; font-variant-numeric: tabular-nums; }
.location-date, .location-empty { color: #536671; font-size: .875rem; }
.location-empty { margin-top: .5rem; }
.map-action {
  margin-top: .85rem;
  min-height: 44px;
  padding: .4rem .6rem;
  display: grid;
  place-items: center;
  border-radius: .55rem;
  background: #254e65;
  color: #fff;
  font-size: .875rem;
  font-weight: 700;
  text-align: center;
  text-decoration: none;
}
.map-action:hover { background: #203d4e; }
.empty { padding: 1.4rem; }
.empty p { color: #536671; }
.dashboard > .empty { margin-top: 1.5rem; }
.centered { width: min(100% - 2rem, 42rem); margin: 3rem auto; }
.centered a { display: inline-block; margin-top: 1rem; }

.admin-filters {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: .7rem;
  padding: .9rem 1.05rem;
  margin-bottom: 1rem;
}
.admin-filters label { display: grid; flex: 1 1 9rem; gap: .3rem; color: #455966; font-size: .875rem; font-weight: 650; }
.admin-filters input, .admin-filters select {
  min-width: 0;
  min-height: 42px;
  padding: .45rem .55rem;
  border: 1px solid #aebdbe;
  border-radius: .5rem;
  background: #fff;
  color: var(--ink);
}
.admin-filters .primary { min-height: 42px; margin: 0; padding: .4rem .9rem; }
.admin-filters .error { flex-basis: 100%; }

@media (max-width: 830px) {
  .event { grid-template-columns: auto minmax(0, 1fr); gap: .25rem .55rem; }
  .event-side { grid-column: 2; text-align: left; }
}

@media (max-width: 760px) {
  .dashboard-shell { display: block; }
  .rail { position: static; min-height: 0; padding: .8rem 1rem .95rem; display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: .65rem .8rem; }
  .rail-brand { padding: .1rem 0; }
  .rail .wordmark { font-size: 2.15rem; }
  .account { padding: 0; grid-template-columns: minmax(0, 1fr) auto; grid-column: 2; grid-row: 1; gap: .45rem; }
  .account::before, .initials { display: none; }
  .account form { grid-column: auto; }
  .devices { grid-column: 1 / -1; grid-template-columns: repeat(auto-fit, minmax(min(100%, 10rem), 1fr)); }
  .devices h2 { grid-column: 1 / -1; padding-left: 0; }
  .device-link { padding: .55rem; }
  .dashboard-top { height: 55px; }
}

@media (max-width: 620px) {
  .topbar-inner { width: calc(100% - 2rem); }
  .workspace { grid-template-columns: 1fr; }
  .location { grid-row: 1; }
}

@media (max-width: 420px) {
  .metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .5rem; }
  .metric:last-child { grid-column: 1 / -1; }
  .metric-head { gap: .4rem; }
  .metric-head h2 { font-size: .875rem; }
  .event { padding-block: .65rem; }
  .map-action { width: 100%; }
}

.login-screen {
  min-height: 100dvh;
  background: #f1f3f6;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1.2rem;
  padding: 2rem 1rem;
}
.login-brand { font-size: 2.9rem; }
.login-card {
  width: min(100%, 25rem);
  padding: clamp(1.15rem, 5vw, 1.8rem);
  background: #fff;
  border: 1px solid #d8dfe7;
  border-radius: .5rem;
  box-shadow: 0 3px 9px #1b283015;
}
.login-card h1 { font-size: 1.6rem; letter-spacing: -.035em; margin-bottom: .9rem; }
.login-card .signin-form { padding: 0; }
.login-card .signin-form input { border-color: #b8c4d0; border-radius: .4rem; }
.login-card .primary, .admin-shell .primary { background: #245fb4; border-radius: .38rem; }
.login-card .primary:hover, .admin-shell .primary:hover { background: #1c4d95; }

.admin-shell {
  grid-template-columns: clamp(12rem, 17vw, 15rem) minmax(0, 1fr);
  color: #253445;
  background: #f1f3f6;
}
.admin-shell .rail { background: #2a343f; padding: 0 .65rem .9rem; }
.admin-shell .rail-brand {
  height: 62px;
  display: flex;
  align-items: center;
  padding: 0 .75rem;
  border-bottom: 1px solid #495562;
  margin-bottom: .85rem;
}
.admin-shell .rail .wordmark { font-size: 2rem; color: #fff; }
.admin-shell .rail .wordmark span { color: #a8c9f3; }
.admin-shell .devices { gap: .25rem; }
.admin-shell .device-link {
  min-height: 43px;
  display: flex;
  align-items: center;
  border-radius: .32rem;
  color: #e8edf3;
}
.admin-shell .device-link[aria-current] { background: #344d69; border-color: #58799d; box-shadow: inset 3px 0 #8bb8f4; color: #fff; }
.admin-main { min-width: 0; }
.admin-bar {
  height: 62px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .65rem;
  padding-inline: clamp(.9rem, 3vw, 1.8rem);
  background: #fff;
  border-bottom: 1px solid #d9e0e8;
  color: #3d4b5b;
  font-size: .9375rem;
  font-weight: 650;
}
.admin-profile { display: flex; gap: .7rem; align-items: center; }
.admin-profile span { min-width: 0; overflow-wrap: anywhere; }
.admin-profile .logout { min-height: 37px; border-radius: .33rem; background: #fff; font-size: .875rem; }
.admin-dashboard { max-width: 100%; padding-inline: clamp(.9rem, 3vw, 1.8rem); }
.admin-heading { display: flex; align-items: center; justify-content: space-between; gap: .85rem; margin-block: 1.3rem 1rem; }
.admin-heading h1 { font-size: clamp(1.65rem, 2.7vw, 2rem); letter-spacing: -.035em; }
.admin-shell .admin-heading .admin-filters { background: transparent; padding: 0; margin: 0; border: 0; box-shadow: none; }
.admin-heading .admin-filters label { display: flex; align-items: center; flex: 0 1 auto; gap: .45rem; }
.admin-shell .panel { border-radius: .42rem; border-color: #d8dfe7; background: #fff; box-shadow: 0 2px 5px #1b28300c; overflow: hidden; }
.overview-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .95rem; align-items: start; }
.admin-card-header {
  min-height: 50px; padding: .7rem .95rem; display: flex; align-items: center;
  justify-content: space-between; gap: .6rem; border-bottom: 1px solid #e5eaf0;
}
.admin-card-header h2 { font-size: 1.04rem; letter-spacing: 0; }
.admin-card-header a { color: #255ca7; font-size: .875rem; font-weight: 650; text-underline-offset: .16em; }
.chart-body { padding: .8rem .9rem .55rem; }
.overview-total { font-weight: 750; font-size: 1.4rem; font-variant-numeric: tabular-nums; }
.trend-chart { display: block; width: 100%; height: clamp(9.5rem, 19vw, 13rem); margin-top: .3rem; }
.chart-empty { display: grid; place-items: center; text-align: center; min-height: clamp(9.5rem, 19vw, 13rem); color: #52606e; font-size: .875rem; }
.chart-legend {
  display: flex; flex-wrap: wrap; justify-content: flex-end; gap: .4rem 1rem;
  padding-top: .35rem; color: #52606e; font-size: .875rem;
}
.chart-legend span::before {
  content: ""; display: inline-block; width: .58rem; height: .58rem;
  margin-right: .32rem; border-radius: .1rem; background: #2869c4;
}
.chart-legend .legend-1::before { background: #338776; }
.chart-values { padding: .15rem .9rem .6rem; color: #45586d; font-size: .875rem; }
.chart-values summary { width: fit-content; cursor: pointer; }
.overview-table { width: 100%; border-collapse: collapse; table-layout: fixed; text-align: left; font-size: .875rem; }
.overview-table th, .overview-table td { padding: .6rem .8rem; border-bottom: 1px solid #edf0f4; overflow-wrap: anywhere; }
.overview-table thead th { background: #f7f9fc; color: #45586d; }
.overview-table tbody tr:last-child > * { border-bottom: 0; }
.overview-table time { color: #52606e; font-variant-numeric: tabular-nums; }
.overview-status { padding: 0 .95rem; margin: 0; }
.overview-status div { display: flex; justify-content: space-between; align-items: center; gap: .6rem; padding: .85rem 0; }
.overview-status div + div { border-top: 1px solid #edf0f4; }
.overview-status dt { color: #52606e; }
.overview-status dd { margin: 0; font-weight: 750; font-variant-numeric: tabular-nums; }

@media (max-width: 850px) {
  .overview-grid { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
  .admin-shell .rail { display: block; }
  .admin-shell .rail-brand { height: 50px; margin-bottom: .35rem; }
  .admin-shell .devices { display: flex; flex-wrap: wrap; padding: 0 .15rem; }
  .admin-shell .device-link { min-height: 38px; }
  .admin-bar { height: 52px; }
}
@media (max-width: 420px) {
  .admin-heading { align-items: flex-start; flex-direction: column; }
  .chart-legend { justify-content: flex-start; }
  .overview-table th, .overview-table td { padding: .5rem .35rem; }
}
