:root {
  --bg-main: #0b1220;
  --bg-panel: #111a2b;
  --bg-panel-soft: #172238;
  --border: rgba(255, 255, 255, 0.08);
  --text-main: #f3f6fb;
  --text-soft: #91a0b8;
  --primary: #32d583;
  --primary-dark: #1eb66b;
  --warning: #f5b942;
  --danger: #f97066;
  --info: #47b5ff;
  --shadow: 0 18px 45px rgba(0, 0, 0, 0.22);
  --radius-lg: 22px;
  --radius-md: 14px;
  --radius-sm: 9px;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family:
    Inter,
    ui-sans-serif,
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    sans-serif;
  color: var(--text-main);
  background:
    radial-gradient(
      circle at top left,
      rgba(50, 213, 131, 0.11),
      transparent 32%
    ),
    radial-gradient(
      circle at top right,
      rgba(71, 181, 255, 0.10),
      transparent 28%
    ),
    var(--bg-main);
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  width: min(1600px, 100%);
  margin: 0 auto;
  padding: 28px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 28px;
  align-items: center;
  margin-bottom: 28px;
  padding: 26px 28px;
  background:
    linear-gradient(
      135deg,
      rgba(255, 255, 255, 0.05),
      rgba(255, 255, 255, 0.02)
    );
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--primary);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 7px;
  font-size: clamp(1.8rem, 3vw, 2.7rem);
  line-height: 1.05;
}

.subtitle {
  margin-bottom: 0;
  color: var(--text-soft);
}

.topbar-status {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 330px;
  justify-content: flex-end;
}

.topbar-status > div {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.topbar-status small {
  color: var(--text-soft);
}

.status-dot {
  width: 12px;
  height: 12px;
  flex: 0 0 auto;
  border-radius: 50%;
  box-shadow: 0 0 0 6px rgba(255, 255, 255, 0.04);
}

.status-loading {
  background: var(--warning);
  animation: pulse 1.4s infinite;
}

.status-online {
  background: var(--primary);
}

.status-offline {
  background: var(--danger);
}

@keyframes pulse {
  0%,
  100% {
    opacity: 1;
    transform: scale(1);
  }

  50% {
    opacity: 0.55;
    transform: scale(0.85);
  }
}

.button {
  border: 0;
  border-radius: 11px;
  padding: 11px 17px;
  font-weight: 800;
  transition:
    transform 0.18s ease,
    opacity 0.18s ease,
    background 0.18s ease;
}

.button:hover {
  transform: translateY(-1px);
}

.button:disabled {
  cursor: wait;
  opacity: 0.65;
  transform: none;
}

.button-primary {
  color: #062114;
  background: var(--primary);
}

.button-primary:hover {
  background: var(--primary-dark);
}

.dashboard {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.kpi-grid {
  display: grid;
  grid-template-columns:
    repeat(6, minmax(150px, 1fr));
  gap: 16px;
}

.kpi-card {
  position: relative;
  overflow: hidden;
  min-height: 135px;
  padding: 22px;
  background:
    linear-gradient(
      145deg,
      rgba(255, 255, 255, 0.045),
      rgba(255, 255, 255, 0.018)
    ),
    var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow);
}

.kpi-card::after {
  content: "";
  position: absolute;
  right: -28px;
  bottom: -35px;
  width: 95px;
  height: 95px;
  border-radius: 50%;
  background: rgba(50, 213, 131, 0.08);
}

.kpi-label {
  position: relative;
  z-index: 1;
  display: block;
  min-height: 42px;
  color: var(--text-soft);
  font-size: 0.86rem;
  line-height: 1.35;
}

.kpi-value {
  position: relative;
  z-index: 1;
  display: block;
  margin-top: 12px;
  font-size: 2rem;
  line-height: 1;
}

.content-grid {
  display: grid;
  grid-template-columns:
    minmax(0, 2.1fr)
    minmax(320px, 0.9fr);
  gap: 24px;
}

.panel {
  overflow: hidden;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 18px;
  padding: 22px 24px;
  border-bottom: 1px solid var(--border);
}

.panel-header h2 {
  margin-bottom: 5px;
  font-size: 1.08rem;
}

.panel-header p {
  margin-bottom: 0;
  color: var(--text-soft);
  font-size: 0.88rem;
}

.search-input {
  width: min(260px, 100%);
  color: var(--text-main);
  background: var(--bg-panel-soft);
  border: 1px solid var(--border);
  border-radius: 11px;
  outline: none;
  padding: 11px 13px;
}

.search-input::placeholder {
  color: #6f7e96;
}

.search-input:focus {
  border-color: rgba(50, 213, 131, 0.55);
  box-shadow: 0 0 0 3px rgba(50, 213, 131, 0.08);
}

.table-wrapper {
  overflow-x: auto;
}

table {
  width: 100%;
  min-width: 980px;
  border-collapse: collapse;
}

th,
td {
  padding: 15px 17px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

th {
  color: var(--text-soft);
  background: rgba(255, 255, 255, 0.018);
  font-size: 0.75rem;
  letter-spacing: 0.055em;
  text-transform: uppercase;
}

td {
  color: #dbe4f1;
  font-size: 0.88rem;
}

tbody tr {
  transition: background 0.16s ease;
}

tbody tr:hover {
  background: rgba(255, 255, 255, 0.026);
}

tbody tr:last-child td {
  border-bottom: 0;
}

.unit-name {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.unit-name strong {
  color: var(--text-main);
}

.unit-name small {
  color: var(--text-soft);
}

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 76px;
  border-radius: 999px;
  padding: 6px 9px;
  font-size: 0.74rem;
  font-weight: 800;
}

.badge-success {
  color: #69efae;
  background: rgba(50, 213, 131, 0.12);
}

.badge-warning {
  color: #ffd173;
  background: rgba(245, 185, 66, 0.13);
}

.badge-danger {
  color: #ff938b;
  background: rgba(249, 112, 102, 0.13);
}

.badge-muted {
  color: #aab5c7;
  background: rgba(145, 160, 184, 0.12);
}

.fuel-meter {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 150px;
}

.fuel-track {
  width: 85px;
  height: 8px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 999px;
}

.fuel-fill {
  height: 100%;
  border-radius: inherit;
  background:
    linear-gradient(
      90deg,
      var(--primary-dark),
      var(--primary)
    );
}

.alerts-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-height: 530px;
  overflow-y: auto;
  padding: 18px;
}

.alert-card {
  padding: 16px;
  background: var(--bg-panel-soft);
  border: 1px solid var(--border);
  border-left: 4px solid var(--warning);
  border-radius: 12px;
}

.alert-card.alert-danger {
  border-left-color: var(--danger);
}

.alert-card.alert-success {
  border-left-color: var(--primary);
}

.alert-card h3 {
  margin: 0 0 7px;
  font-size: 0.93rem;
}

.alert-card p {
  margin-bottom: 7px;
  color: var(--text-soft);
  font-size: 0.82rem;
  line-height: 1.45;
}

.alert-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  color: #b7c2d2;
  font-size: 0.75rem;
}

.empty-state {
  padding: 30px;
  color: var(--text-soft);
  text-align: center;
}

.map-panel {
  min-height: 520px;
}

#map {
  width: 100%;
  height: 455px;
  background: #0c1523;
}

.leaflet-container {
  font-family: inherit;
}

.leaflet-popup-content-wrapper,
.leaflet-popup-tip {
  color: #162032;
  background: #f7f9fc;
}

.map-popup {
  min-width: 210px;
}

.map-popup strong {
  display: block;
  margin-bottom: 8px;
  font-size: 0.95rem;
}

.map-popup span {
  display: block;
  margin: 4px 0;
  font-size: 0.8rem;
}

.loading-row {
  opacity: 0.72;
}

@media (max-width: 1250px) {
  .kpi-grid {
    grid-template-columns:
      repeat(3, minmax(180px, 1fr));
  }

  .content-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 760px) {
  .app-shell {
    padding: 14px;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
    padding: 21px;
  }

  .topbar-status {
    width: 100%;
    min-width: 0;
    justify-content: flex-start;
    flex-wrap: wrap;
  }

  .kpi-grid {
    grid-template-columns:
      repeat(2, minmax(130px, 1fr));
  }

  .panel-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .search-input {
    width: 100%;
  }
}

@media (max-width: 480px) {
  .kpi-grid {
    grid-template-columns: 1fr;
  }

  .button-primary {
    margin-left: auto;
  }
}
body.modal-open {
  overflow: hidden;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: none;
}

.modal.is-open {
  display: block;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(3, 8, 18, 0.78);
  backdrop-filter: blur(8px);
}

.modal-dialog {
  position: relative;
  z-index: 1;
  width: min(1280px, calc(100% - 32px));
  max-height: calc(100vh - 32px);
  margin: 16px auto;
  overflow-y: auto;
  background: var(--bg-main);
  border: 1px solid var(--border);
  border-radius: 24px;
  box-shadow: 0 28px 80px rgba(0, 0, 0, 0.52);
}

.modal-header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  padding: 24px 26px;
  background: rgba(11, 18, 32, 0.96);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(14px);
}

.modal-header h2 {
  margin-bottom: 6px;
  font-size: 1.45rem;
}

.modal-header p:last-child {
  margin-bottom: 0;
  color: var(--text-soft);
}

.modal-close-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  flex: 0 0 auto;
  color: var(--text-main);
  background: var(--bg-panel-soft);
  border: 1px solid var(--border);
  border-radius: 12px;
  font-size: 1.75rem;
  line-height: 1;
}

.modal-close-button:hover {
  background: rgba(249, 112, 102, 0.14);
  border-color: rgba(249, 112, 102, 0.35);
}

.modal-loading,
.modal-error {
  margin: 22px;
  padding: 24px;
  color: var(--text-soft);
  text-align: center;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 16px;
}

.modal-error {
  color: #ffaaa4;
  background: rgba(249, 112, 102, 0.08);
  border-color: rgba(249, 112, 102, 0.25);
}

.modal-content {
  display: flex;
  flex-direction: column;
  gap: 20px;
  padding: 22px;
}

.detail-kpi-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(140px, 1fr));
  gap: 14px;
}

.detail-kpi {
  min-height: 112px;
  padding: 18px;
  background:
    linear-gradient(
      145deg,
      rgba(255, 255, 255, 0.04),
      rgba(255, 255, 255, 0.012)
    ),
    var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 16px;
}

.detail-kpi span {
  display: block;
  min-height: 36px;
  color: var(--text-soft);
  font-size: 0.82rem;
  line-height: 1.35;
}

.detail-kpi strong {
  display: block;
  margin-top: 10px;
  color: var(--text-main);
  font-size: 1.38rem;
}

.detail-section {
  padding: 20px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 18px;
}

.detail-section h3 {
  margin: 0 0 14px;
  font-size: 1rem;
}

.detail-section-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
}

.detail-section-header h3 {
  margin-bottom: 5px;
}

.detail-section-header p {
  margin-bottom: 0;
  color: var(--text-soft);
  font-size: 0.84rem;
}

.detail-select {
  min-width: 180px;
  color: var(--text-main);
  background: var(--bg-panel-soft);
  border: 1px solid var(--border);
  border-radius: 11px;
  padding: 10px 12px;
  outline: none;
}

.detail-select:focus {
  border-color: rgba(50, 213, 131, 0.55);
  box-shadow: 0 0 0 3px rgba(50, 213, 131, 0.08);
}

.chart-container {
  position: relative;
  width: 100%;
  height: 360px;
}

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

.detail-list {
  margin: 0;
}

.detail-list > div {
  display: grid;
  grid-template-columns: minmax(160px, 0.8fr) minmax(0, 1.2fr);
  gap: 16px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}

.detail-list > div:last-child {
  border-bottom: 0;
}

.detail-list dt {
  color: var(--text-soft);
  font-size: 0.84rem;
}

.detail-list dd {
  margin: 0;
  color: var(--text-main);
  font-size: 0.86rem;
  text-align: right;
  overflow-wrap: anywhere;
}

.detail-table {
  min-width: 820px;
}

.detail-events-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.detail-event-card {
  display: grid;
  grid-template-columns: minmax(160px, 0.7fr) minmax(0, 1.8fr) auto;
  gap: 18px;
  align-items: center;
  padding: 15px 16px;
  background: var(--bg-panel-soft);
  border: 1px solid var(--border);
  border-left: 4px solid var(--warning);
  border-radius: 12px;
}

.detail-event-card.event-danger {
  border-left-color: var(--danger);
}

.detail-event-card.event-success {
  border-left-color: var(--primary);
}

.detail-event-type {
  font-weight: 800;
}

.detail-event-description {
  color: var(--text-soft);
  font-size: 0.83rem;
  line-height: 1.4;
}

.detail-event-time {
  color: #b9c4d3;
  font-size: 0.78rem;
  text-align: right;
}

.unit-row {
  cursor: pointer;
}

.unit-row:focus {
  outline: 2px solid rgba(50, 213, 131, 0.5);
  outline-offset: -2px;
}

.unit-row:hover td:first-child strong {
  color: var(--primary);
}

@media (max-width: 1100px) {
  .detail-kpi-grid {
    grid-template-columns: repeat(3, minmax(150px, 1fr));
  }
}

@media (max-width: 760px) {
  .modal-dialog {
    width: 100%;
    max-height: 100vh;
    min-height: 100vh;
    margin: 0;
    border-radius: 0;
  }

  .modal-header {
    padding: 18px;
  }

  .modal-content {
    padding: 14px;
  }

  .detail-kpi-grid {
    grid-template-columns: repeat(2, minmax(130px, 1fr));
  }

  .detail-columns {
    grid-template-columns: 1fr;
  }

  .detail-section-header {
    flex-direction: column;
  }

  .detail-select {
    width: 100%;
  }

  .chart-container {
    height: 300px;
  }

  .detail-event-card {
    grid-template-columns: 1fr;
    gap: 7px;
  }

  .detail-event-time {
    text-align: left;
  }
}

@media (max-width: 460px) {
  .detail-kpi-grid {
    grid-template-columns: 1fr;
  }

  .detail-list > div {
    grid-template-columns: 1fr;
    gap: 5px;
  }

  .detail-list dd {
    text-align: left;
  }
}
