:root {
  color-scheme: light;
  --bg: #f5f7f8;
  --surface: #ffffff;
  --surface-soft: #eef3f4;
  --ink: #172126;
  --muted: #65737a;
  --line: #dbe3e6;
  --green: #16824a;
  --red: #c7352d;
  --amber: #be7416;
  --gray: #7d878c;
  --purple: #7c3bb4;
  --blue: #2867a8;
  --teal: #167b85;
  --shadow: 0 16px 38px rgba(20, 42, 52, 0.11);
  font-family: Arial, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(rgba(10, 28, 36, 0.22), rgba(10, 28, 36, 0.34)),
    url("assets/backgraund.png") center/cover;
}

.login-panel {
  width: min(420px, 100%);
  background: rgba(255, 255, 255, 0.88);
  border: 1px solid rgba(255, 255, 255, 0.72);
  border-radius: 8px;
  padding: 28px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
}

.login-panel h1,
.login-panel p {
  margin: 0;
}

.login-panel h1 {
  font-size: 28px;
}

.login-panel p {
  margin-top: 8px;
  color: var(--muted);
}

.login-form {
  display: grid;
  gap: 14px;
  margin-top: 28px;
}

.login-error {
  min-height: 18px;
  margin: 0;
  color: var(--red);
  font-size: 13px;
}

.field {
  display: grid;
  gap: 7px;
}

.field span {
  color: var(--muted);
  font-size: 14px;
}

.field input,
.field select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  padding: 11px 12px;
}

.primary-btn,
.secondary-btn,
.ghost-btn,
.icon-btn {
  border: 0;
  border-radius: 6px;
  min-height: 40px;
  padding: 0 14px;
}

.primary-btn {
  background: var(--teal);
  color: white;
  font-weight: 700;
}

.secondary-btn {
  background: var(--surface-soft);
  color: var(--ink);
  border: 1px solid var(--line);
}

.ghost-btn {
  background: transparent;
  color: var(--muted);
}

.icon-btn {
  width: 40px;
  padding: 0;
  background: var(--surface-soft);
  border: 1px solid var(--line);
  color: var(--ink);
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 264px 1fr;
}

.sidebar {
  background: #10252b;
  color: #eef8fa;
  padding: 22px 16px;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.brand {
  display: grid;
  gap: 10px;
  padding: 0 6px;
}

.brand strong {
  font-size: 21px;
}

.brand span {
  color: #a9c4ca;
  font-size: 13px;
}

.brand img {
  width: 76px;
  height: 76px;
  object-fit: contain;
}

.nav {
  display: grid;
  gap: 8px;
}

.nav button {
  display: flex;
  align-items: center;
  gap: 10px;
  justify-content: flex-start;
  min-height: 44px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: #d6e7ea;
  padding: 0 12px;
  text-align: right;
}

.nav button.active,
.nav button:hover {
  background: #1e444d;
  color: #fff;
}

.sidebar-footer {
  margin-top: auto;
  display: grid;
  gap: 8px;
  color: #a9c4ca;
  font-size: 13px;
  padding: 0 6px;
}

.content {
  min-width: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 22px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.company-switcher {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}

.company-switcher select {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  padding: 0 10px;
}

.topbar h2 {
  margin: 0;
  font-size: 25px;
}

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

.status-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.metric,
.panel,
.table-wrap,
.event-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 8px 22px rgba(22, 43, 52, 0.06);
}

.metric {
  padding: 15px;
}

.metric span {
  color: var(--muted);
  font-size: 13px;
}

.metric strong {
  display: block;
  margin-top: 8px;
  font-size: 28px;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: minmax(320px, 1fr);
  gap: 16px;
  flex: 1;
}

.panel {
  padding: 16px;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.panel-head h3 {
  margin: 0;
  font-size: 18px;
}

.map-layout {
  position: relative;
  height: calc(100vh - 192px);
  min-height: 820px;
  overflow: hidden;
  padding: 0;
  background: #dfe7e3;
}

.map-canvas {
  position: absolute;
  inset: 0;
  z-index: 1;
}

.map-layout .panel-head {
  position: absolute;
  top: 14px;
  right: 14px;
  left: 14px;
  z-index: 3;
  margin: 0;
  padding: 10px 12px;
  background: rgba(255, 255, 255, 0.9);
  border: 1px solid rgba(219, 227, 230, 0.82);
  border-radius: 8px;
  backdrop-filter: blur(8px);
}

.leaflet-container {
  width: 100%;
  height: 100%;
  font-family: Arial, "Segoe UI", sans-serif;
  direction: rtl;
}

.map-loading {
  height: 100%;
  display: grid;
  place-items: center;
  color: var(--muted);
  background: var(--surface-soft);
}

.leaflet-sensor-marker {
  border-radius: 50%;
  display: grid;
  place-items: center;
  box-shadow: 0 0 0 4px rgba(255, 255, 255, 0.84), 0 10px 24px rgba(0, 0, 0, 0.24);
}

.leaflet-sensor-marker span {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #fff;
}

.leaflet-sensor-marker.online {
  background: var(--green);
}

.leaflet-sensor-marker.offline {
  background: var(--gray);
}

.leaflet-sensor-marker.impact {
  background: var(--red);
  animation: pulse-red 1.5s infinite;
}

.leaflet-sensor-marker.warning {
  background: var(--amber);
  animation: pulse 1.5s infinite;
}

.leaflet-sensor-marker.picker {
  background: var(--teal);
}

.map-popup {
  display: grid;
  gap: 4px;
  min-width: 170px;
  text-align: right;
}

.map-popup strong,
.map-popup span {
  display: block;
}

.waze-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  width: fit-content;
  margin-top: 8px;
  padding: 7px 10px;
  border-radius: 6px;
  background: #e3effb;
  color: var(--blue);
  font-weight: 700;
  text-decoration: none;
}

.waze-link:hover {
  background: #d7eef1;
  color: var(--teal);
}

.map-popup .waze-link span,
.map-popup .waze-link strong {
  display: inline;
}

.map-events {
  position: absolute;
  top: 16px;
  left: 16px;
  z-index: 4;
  width: min(330px, calc(100% - 32px));
  max-height: calc(100% - 32px);
  overflow: auto;
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid rgba(219, 227, 230, 0.86);
  border-radius: 8px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(8px);
}

.map-events-head {
  padding: 12px 13px;
  border-bottom: 1px solid var(--line);
}

.map-events-list {
  display: grid;
  gap: 8px;
  padding: 10px;
}

.map-event {
  display: grid;
  gap: 6px;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  padding: 10px;
  color: var(--ink);
  text-align: right;
}

.map-event:hover {
  border-color: #a7c8cf;
  background: #f7fbfc;
}

.map-event strong,
.map-event span {
  display: block;
}

.map-event > span:last-child {
  color: var(--muted);
  font-size: 13px;
}

.map-home-btn {
  position: absolute;
  top: 16px;
  right: 16px;
  z-index: 4;
  width: 42px;
  height: 42px;
  border: 1px solid rgba(219, 227, 230, 0.9);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.94);
  color: var(--ink);
  font-size: 24px;
  line-height: 1;
  box-shadow: var(--shadow);
  backdrop-filter: blur(8px);
}

.map-home-btn:hover {
  background: #f7fbfc;
  border-color: #a7c8cf;
}

@keyframes pulse {
  0% { box-shadow: 0 0 0 4px rgba(255, 255, 255, 0.78), 0 0 0 0 rgba(190, 116, 22, 0.36); }
  100% { box-shadow: 0 0 0 4px rgba(255, 255, 255, 0.78), 0 0 0 18px rgba(190, 116, 22, 0); }
}

@keyframes pulse-red {
  0% { box-shadow: 0 0 0 4px rgba(255, 255, 255, 0.78), 0 0 0 0 rgba(199, 53, 45, 0.36); }
  100% { box-shadow: 0 0 0 4px rgba(255, 255, 255, 0.78), 0 0 0 18px rgba(199, 53, 45, 0); }
}

.sensor-popover {
  position: absolute;
  min-width: 230px;
  max-width: 270px;
  transform: translate(50%, 12px);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  box-shadow: var(--shadow);
  z-index: 3;
}

.sensor-popover h4,
.sensor-popover p {
  margin: 0;
}

.sensor-popover h4 {
  font-size: 16px;
}

.sensor-popover p {
  color: var(--muted);
  margin-top: 5px;
  font-size: 13px;
}

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 26px;
  border-radius: 999px;
  padding: 0 10px;
  font-size: 13px;
  font-weight: 700;
}

.badge.green {
  background: #e0f3e9;
  color: var(--green);
}

.badge.red {
  background: #ffe8e6;
  color: var(--red);
}

.badge.gray {
  background: #edf0f1;
  color: #566168;
}

.badge.amber {
  background: #fff0d9;
  color: var(--amber);
}

.badge.purple {
  background: #f0e5fb;
  color: var(--purple);
}

.badge.blue {
  background: #e3effb;
  color: var(--blue);
}

.event-list,
.sensor-list {
  display: grid;
  gap: 10px;
}

.event-card {
  padding: 12px;
}

.event-card strong,
.event-card span {
  display: block;
}

.event-card span {
  color: var(--muted);
  font-size: 13px;
  margin-top: 4px;
}

.management-grid {
  display: grid;
  grid-template-columns: 340px minmax(520px, 1fr);
  gap: 16px;
}

.users-grid {
  display: grid;
  grid-template-columns: 340px minmax(520px, 1fr);
  gap: 16px;
}

.settings-grid {
  display: grid;
  grid-template-columns: minmax(320px, 520px);
  gap: 16px;
}

.form-grid {
  display: grid;
  gap: 13px;
}

.form-message {
  min-height: 18px;
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.form-message.success {
  color: var(--green);
}

.form-message.error {
  color: var(--red);
}

.settings-divider {
  height: 1px;
  background: var(--line);
  margin: 4px 0;
}

.toggle-row {
  display: flex;
  align-items: center;
  gap: 9px;
  color: var(--ink);
  font-weight: 700;
}

.toggle-row input {
  width: 17px;
  height: 17px;
  accent-color: var(--teal);
}

.form-note {
  margin: -2px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.region-picker,
.region-editor div {
  display: grid;
  gap: 8px;
}

.region-picker {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 12px 12px;
}

.region-picker legend {
  padding: 0 4px;
  color: var(--muted);
  font-size: 14px;
}

.region-picker label,
.region-editor label {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--ink);
  font-size: 14px;
}

.region-picker input,
.region-editor input {
  width: 16px;
  height: 16px;
  accent-color: var(--blue);
}

.region-editor {
  min-width: 170px;
}

.region-editor summary {
  color: var(--blue);
  font-weight: 700;
  cursor: pointer;
}

.region-editor div {
  margin-top: 8px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  box-shadow: 0 8px 20px rgba(22, 43, 52, 0.08);
}

.map-picker {
  height: 650px;
  min-height: 650px;
  position: relative;
}

.coord-readout {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-top: 10px;
  color: var(--muted);
  font-size: 13px;
}

.table-wrap {
  overflow: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 1120px;
  background: #fff;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 12px;
  text-align: right;
  vertical-align: middle;
}

th {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  background: #f8fafb;
}

.filters {
  display: grid;
  grid-template-columns: repeat(5, minmax(140px, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.sensor-directory-filters {
  grid-template-columns: repeat(4, minmax(150px, 1fr));
}

.sensors-directory-table {
  min-width: 1180px;
}

.table-link {
  border: 0;
  background: transparent;
  color: var(--blue);
  font: inherit;
  font-weight: 700;
  padding: 0;
  text-align: right;
  cursor: pointer;
}

.table-link:hover {
  color: var(--teal);
  text-decoration: underline;
}

.mono-link {
  direction: ltr;
  font-family: "Segoe UI", Arial, sans-serif;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 22px;
  background: rgba(7, 22, 30, 0.5);
}

.modal-card {
  width: min(900px, 100%);
  max-height: min(760px, calc(100vh - 44px));
  overflow: hidden;
  background: var(--surface);
  border: 1px solid rgba(219, 227, 230, 0.9);
  border-radius: 8px;
  box-shadow: 0 28px 70px rgba(0, 0, 0, 0.28);
}

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

.modal-head h3,
.modal-head p {
  margin: 0;
}

.modal-head h3 {
  font-size: 19px;
}

.modal-head p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

.status-alert-backdrop {
  z-index: 60;
  background: rgba(7, 22, 30, 0.62);
}

.status-alert-card {
  width: min(460px, 100%);
  padding-bottom: 18px;
  text-align: center;
}

.status-alert-body {
  display: grid;
  gap: 8px;
  padding: 22px 24px;
}

.status-alert-body strong {
  font-size: 24px;
}

.status-alert-body span {
  direction: ltr;
  color: var(--muted);
}

.status-alert-state {
  justify-self: center;
  margin-top: 8px;
  padding: 10px 18px;
  border-radius: 999px;
  background: #eef3f5;
  color: var(--ink);
  font-weight: 800;
}

.status-alert-state.green {
  background: rgba(43, 161, 92, 0.14);
  color: #167142;
}

.status-alert-state.amber {
  background: rgba(245, 158, 11, 0.16);
  color: #9a5b00;
}

.status-alert-state.red {
  background: rgba(220, 38, 38, 0.14);
  color: #b91c1c;
}

.status-alert-state.purple {
  background: rgba(126, 87, 194, 0.14);
  color: #5e35b1;
}

.status-alert-card .primary-btn {
  width: calc(100% - 48px);
  margin: 0 24px;
}

.history-map-canvas {
  position: relative;
  height: min(620px, calc(100vh - 160px));
  min-height: 420px;
}

.empty {
  padding: 22px;
  color: var(--muted);
  text-align: center;
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 10;
    padding: 12px;
  }

  .nav {
    grid-template-columns: repeat(3, 1fr);
  }

  .sidebar-footer {
    display: none;
  }

  .status-strip,
  .dashboard-grid,
  .management-grid,
  .users-grid,
  .settings-grid,
  .filters {
    grid-template-columns: 1fr;
  }

  .map-layout {
    height: calc(100vh - 250px);
    min-height: 720px;
  }
}

@media (max-width: 560px) {
  .content {
    padding: 14px;
  }

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

  .topbar-actions {
    width: 100%;
    align-items: stretch;
    flex-direction: column;
  }

  .modal-backdrop {
    padding: 12px;
  }

  .history-map-canvas {
    min-height: 360px;
  }

  .nav button {
    justify-content: center;
    padding: 0 6px;
    font-size: 14px;
  }

  .brand strong {
    font-size: 18px;
  }
}
