:root {
  color-scheme: dark;
  --bg: #060606;
  --panel: rgba(16, 16, 15, 0.88);
  --panel-strong: rgba(14, 14, 13, 0.96);
  --line: rgba(194, 158, 79, 0.24);
  --gold: #cfa64f;
  --gold-soft: #ecd083;
  --text: #f2efe8;
  --muted: #aaa28f;
  --danger: #ef7c72;
  --ok: #78d09b;
  --radius: 8px;
  font-family: Inter, Segoe UI, Arial, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 22% 10%, rgba(207, 166, 79, 0.13), transparent 28rem),
    radial-gradient(circle at 82% 18%, rgba(101, 132, 124, 0.11), transparent 26rem),
    linear-gradient(135deg, #050505, #11100d 52%, #070707);
  color: var(--text);
  overflow-x: hidden;
}

.bg {
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  opacity: 1;
}

.bg::before {
  content: "";
  position: absolute;
  inset: -35%;
  background:
    radial-gradient(circle at 30% 35%, rgba(236, 208, 131, 0.10), transparent 18rem),
    radial-gradient(circle at 70% 55%, rgba(118, 133, 126, 0.08), transparent 20rem),
    repeating-linear-gradient(118deg, rgba(207, 166, 79, 0.055) 0 1px, transparent 1px 82px);
  animation: atmosphere 28s ease-in-out infinite alternate;
}

.bg span {
  position: absolute;
  width: 32rem;
  height: 32rem;
  border-radius: 50%;
  filter: blur(56px);
  opacity: 0.24;
  transform: translate3d(0, 0, 0);
  animation: floatGlow 24s ease-in-out infinite alternate;
}

.bg span:nth-child(1) { top: -8rem; left: -8rem; background: #cfa64f; animation-delay: 0s; }
.bg span:nth-child(2) { top: 18%; right: -12rem; background: #44514d; animation-delay: -6s; }
.bg span:nth-child(3) { bottom: -14rem; left: 18%; background: #8f7438; animation-delay: -12s; }
.bg span:nth-child(4) { bottom: 8%; right: 12%; background: #1f2d2a; animation-delay: -18s; }

@keyframes atmosphere {
  from { transform: translate3d(-1.5%, -1%, 0) rotate(0deg); }
  to { transform: translate3d(1.5%, 1%, 0) rotate(2deg); }
}

@keyframes floatGlow {
  from { transform: translate3d(-2rem, -1rem, 0) scale(0.96); }
  to { transform: translate3d(2rem, 1.5rem, 0) scale(1.06); }
}

button, input, select, textarea {
  font: inherit;
}

button {
  border: 1px solid rgba(245, 213, 122, 0.36);
  border-radius: var(--radius);
  background: linear-gradient(180deg, #e2c276, #b28637);
  color: #16120a;
  font-weight: 800;
  min-height: 38px;
  padding: 0 14px;
  cursor: pointer;
}

button.secondary {
  background: rgba(255, 255, 255, 0.055);
  color: var(--gold-soft);
}

button.danger {
  border-color: rgba(255, 112, 104, 0.4);
  color: #ffd9d7;
}

button.compact {
  padding: 9px 12px;
}

button:disabled {
  opacity: 0.48;
  cursor: not-allowed;
}

input, select, textarea {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(0, 0, 0, 0.44);
  color: var(--text);
  padding: 9px 10px;
  outline: none;
}

textarea { min-height: 74px; resize: vertical; }

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

.shell {
  position: relative;
  z-index: 1;
  max-width: none;
  margin: 0 auto;
  padding: clamp(10px, 1.4vw, 24px);
  width: 100%;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 14px 0 20px;
}

.brand h1 {
  margin: 0;
  color: var(--gold-soft);
  font-size: clamp(24px, 4vw, 44px);
  letter-spacing: 0;
}

.brand p {
  margin: 5px 0 0;
  color: var(--muted);
}

.userbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
  min-width: 0;
}

.tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.top-tabs {
  margin-bottom: 0;
}

.top-tabs .tab {
  padding: 9px 12px;
}

.cars-panel {
  margin-bottom: 18px;
}

.tab.active {
  box-shadow: 0 0 0 2px rgba(245, 213, 122, 0.16);
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(360px, 100%), 1fr));
  gap: 18px;
}

.ops-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(330px, 100%), 1fr));
  gap: 18px;
}

.panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  backdrop-filter: blur(14px);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.34);
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px;
  border-bottom: 1px solid var(--line);
}

.panel-head h2, .panel-head h3 {
  margin: 0;
  color: var(--gold-soft);
  font-size: 18px;
}

.panel-body {
  padding: 16px;
  min-width: 0;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(220px, 100%), 1fr));
  gap: 12px;
}

.form-grid .wide { grid-column: 1 / -1; }

.export-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(180px, 100%), 1fr));
  gap: 12px;
  align-items: end;
}

.journal-filters {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(170px, 100%), 1fr));
  gap: 12px;
  align-items: end;
  margin-bottom: 14px;
}

.journal-period {
  display: grid;
  gap: 10px;
}

.journal-period + .journal-period {
  margin-top: 16px;
}

.journal-period-title {
  color: var(--gold-soft);
  font-weight: 700;
}

.journal-period-older {
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.journal-more {
  width: 100%;
  margin-top: 14px;
}

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 12px;
}

.segmented button {
  background: rgba(255, 255, 255, 0.05);
  color: var(--muted);
}

.segmented button.active {
  background: linear-gradient(180deg, #e2c276, #b28637);
  color: #130f08;
}

.car-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(190px, 100%), 1fr));
  gap: 12px;
}

.car-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.035);
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.18s ease, border-color 0.18s ease;
}

.car-card.busy {
  border-color: rgba(239, 124, 114, 0.48);
}

.car-card:hover, .car-card.active {
  transform: translateY(-2px);
  border-color: rgba(245, 213, 122, 0.72);
}

.car-img {
  position: relative;
  aspect-ratio: 16 / 9;
  display: grid;
  place-items: center;
  background:
    linear-gradient(135deg, rgba(217, 169, 58, 0.18), rgba(0, 0, 0, 0.4)),
    radial-gradient(circle at 55% 25%, rgba(245, 213, 122, 0.2), transparent 40%);
  color: var(--gold-soft);
  font-weight: 900;
  font-size: 32px;
}

.car-title {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.plate-badge {
  display: inline-flex;
  align-items: center;
  border: 1px solid rgba(0, 0, 0, 0.42);
  border-radius: 6px;
  background: rgba(242, 239, 232, 0.92);
  color: #111;
  font-size: 12px;
  font-weight: 900;
  line-height: 1;
  padding: 4px 7px;
}

.car-img img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.radar-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 2;
  width: 34px;
  height: 34px;
  min-height: 34px;
  padding: 0;
  border-radius: 50%;
  display: grid;
  place-items: center;
  border: 1px solid rgba(245, 213, 122, 0.9);
  background: radial-gradient(circle, rgba(245, 213, 122, 0.96), rgba(179, 126, 26, 0.92));
  color: #14100a;
  font-size: 22px;
  font-weight: 900;
  line-height: 1;
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.42), 0 0 0 3px rgba(0, 0, 0, 0.3);
}

.radar-btn:hover {
  transform: translateY(-1px) scale(1.04);
}

.radar-btn:disabled {
  opacity: 0.45;
  filter: grayscale(0.85);
  cursor: not-allowed;
}

.car-meta {
  padding: 10px;
  display: grid;
  gap: 4px;
}

.map-modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: none;
  place-items: center;
  padding: 16px;
  background: rgba(0, 0, 0, 0.72);
  backdrop-filter: blur(8px);
}

.map-modal.open {
  display: grid;
}

.map-dialog {
  width: min(980px, 100%);
  max-height: min(760px, calc(100vh - 32px));
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  border: 1px solid rgba(245, 213, 122, 0.28);
  border-radius: var(--radius);
  background: rgba(14, 14, 14, 0.96);
  box-shadow: 0 28px 70px rgba(0, 0, 0, 0.62);
  overflow: hidden;
}

.map-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}

.map-head h2 {
  margin: 0;
}

.map-close {
  width: 38px;
  height: 38px;
  min-height: 38px;
  padding: 0;
  font-size: 24px;
}

.map-body {
  min-height: 360px;
  display: grid;
  grid-template-rows: minmax(300px, 1fr) auto;
  gap: 10px;
  padding: 12px;
}

.map-frame {
  width: 100%;
  min-height: 430px;
  height: min(58vh, 560px);
  border: 0;
  border-radius: 8px;
  background: #111;
}

.map-empty {
  min-height: 300px;
  display: grid;
  place-items: center;
  color: var(--muted);
}

.map-meta {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  color: var(--muted);
}

.map-meta a {
  color: var(--gold-soft);
  font-weight: 800;
}

.person-picker {
  position: relative;
}

.person-menu {
  position: absolute;
  z-index: 20;
  left: 0;
  right: 0;
  top: calc(100% + 6px);
  display: none;
  max-height: 238px;
  overflow: auto;
  padding: 8px;
  border: 1px solid rgba(245, 213, 122, 0.34);
  border-radius: var(--radius);
  background: rgba(12, 12, 11, 0.98);
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.48);
}

.person-picker.open .person-menu {
  display: grid;
  gap: 8px;
}

.person-option {
  display: grid;
  grid-template-columns: 38px 1fr;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 46px;
  padding: 7px;
  border-color: rgba(207, 166, 79, 0.22);
  background: rgba(255, 255, 255, 0.045);
  color: var(--text);
  text-align: left;
  font-weight: 800;
}

.person-option:hover {
  border-color: rgba(245, 213, 122, 0.72);
  background: rgba(207, 166, 79, 0.16);
}

.person-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(190px, 100%), 1fr));
  gap: 12px;
  margin-top: 12px;
}

.person-card {
  display: grid;
  grid-template-columns: 44px 1fr;
  align-items: center;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background:
    linear-gradient(135deg, rgba(207, 166, 79, 0.12), rgba(255, 255, 255, 0.035)),
    rgba(255, 255, 255, 0.035);
}

.person-card .actions {
  grid-column: 1 / -1;
}

.person-avatar {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border: 1px solid rgba(245, 213, 122, 0.34);
  border-radius: 50%;
  background: radial-gradient(circle at 35% 28%, rgba(245, 213, 122, 0.34), rgba(207, 166, 79, 0.12));
  color: var(--gold-soft);
  font-size: 13px;
  font-weight: 900;
}

.plate {
  color: var(--gold-soft);
  font-weight: 900;
}

.muted { color: var(--muted); }

.status-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(150px, 100%), 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.stat {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(0, 0, 0, 0.28);
}

.stat b {
  display: block;
  color: var(--gold-soft);
  font-size: 26px;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 0;
  table-layout: auto;
}

.journal-table {
  min-width: 0;
}

th, td {
  border-bottom: 1px solid rgba(215, 171, 71, 0.16);
  padding: 10px 8px;
  text-align: left;
  vertical-align: top;
  overflow-wrap: anywhere;
}

th {
  color: var(--gold-soft);
  font-size: 12px;
  text-transform: uppercase;
}

.actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  flex-wrap: wrap;
}

.login {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 20px;
}

.login-card {
  width: min(440px, 100%);
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-strong);
  box-shadow: 0 30px 100px rgba(0, 0, 0, 0.52);
}

.login-card h1 {
  margin: 0 0 8px;
  color: var(--gold-soft);
}

.login-card form {
  display: grid;
  gap: 12px;
  margin-top: 18px;
}

.hint {
  border: 1px dashed rgba(245, 213, 122, 0.3);
  border-radius: var(--radius);
  padding: 10px;
  color: var(--muted);
  font-size: 13px;
}

.message {
  min-height: 22px;
  color: var(--gold-soft);
}

.error { color: var(--danger); }
.ok { color: var(--ok); }

.admin-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.admin-grid.single {
  grid-template-columns: minmax(0, 1fr);
}

.check-row {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
}

.check-row input {
  width: 18px;
  min-height: 18px;
}

.backup-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.backup-upload {
  align-items: center;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--gold-soft);
  cursor: pointer;
  display: inline-flex;
  min-height: 40px;
  padding: 9px 14px;
}

.backup-upload input {
  display: none;
}

@media (max-width: 980px) {
  .grid, .admin-grid, .ops-grid { grid-template-columns: 1fr; }
  .status-row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .export-grid, .journal-filters {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 620px) {
  .shell {
    max-width: 100vw;
    padding: 10px;
  }
  .topbar {
    align-items: stretch;
    flex-direction: column;
    gap: 10px;
    padding-top: 8px;
  }
  .brand h1 { font-size: 24px; }
  .brand p { font-size: 13px; }
  .userbar {
    justify-content: stretch;
    width: 100%;
  }
  .userbar .muted {
    flex-basis: 100%;
  }
  .userbar button {
    flex: 1 1 120px;
  }
  .top-tabs {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    width: 100%;
  }
  .top-tabs button {
    min-width: 0;
    padding-left: 6px;
    padding-right: 6px;
    width: 100%;
  }
  .form-grid, .status-row, .export-grid, .journal-filters, .segmented {
    grid-template-columns: 1fr;
  }
  .car-grid, .person-grid {
    grid-template-columns: repeat(auto-fit, minmax(min(150px, 100%), 1fr));
  }
  .panel {
    border-radius: 7px;
  }
  .panel-head {
    align-items: stretch;
    flex-direction: column;
    padding: 12px;
  }
  .panel-body {
    padding: 12px;
  }
  .panel-head button,
  .actions button {
    width: 100%;
  }
  .actions {
    justify-content: stretch;
  }
  input, select, textarea, button {
    min-width: 0;
  }
  table {
    display: table;
    min-width: 0;
    overflow-x: visible;
  }
  .journal-table,
  .journal-table thead,
  .journal-table tbody,
  .journal-table tr,
  .journal-table td {
    display: block;
    width: 100%;
  }
  .journal-table {
    border-collapse: separate;
    border-spacing: 0;
  }
  .journal-table thead {
    display: none;
  }
  .journal-table tr {
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: rgba(0, 0, 0, 0.22);
    margin-bottom: 10px;
    overflow: hidden;
  }
  .journal-table td {
    align-items: start;
    border-bottom: 1px solid rgba(215, 171, 71, 0.12);
    display: grid;
    gap: 8px;
    grid-template-columns: 88px minmax(0, 1fr);
    padding: 8px 10px;
    word-break: break-word;
  }
  .journal-table td:last-child {
    border-bottom: 0;
  }
  .journal-table td::before {
    color: var(--gold-soft);
    content: attr(data-label);
    font-size: 12px;
    font-weight: 800;
  }
}
