*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: #f5f5f5;
  color: #111111;
}

.app-header {
  padding: 1.5rem 1.5rem 1rem;
  border-bottom: 1px solid #e0e0e0;
  background: #ffffff;
}

.app-header h1 {
  margin: 0;
  font-size: 1.7rem;
}

.subtitle {
  margin: 0.3rem 0 0;
  color: #555555;
}

.subtitle.small {
  font-size: 0.85rem;
  opacity: 0.9;
}

.summary-bar {
  padding: 0.75rem 1.5rem;
  background: #fafafa;
  border-bottom: 1px solid #e0e0e0;
  font-size: 0.9rem;
  display: flex;
  align-items: center;
}

.summary-bar strong {
  color: #222222;
}

.devices-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 1rem;
  padding: 1rem 1.5rem 2rem;
}

.device-card {
  background: #ffffff;
  border-radius: 0.75rem;
  border: 1px solid #e0e0e0;
  box-shadow: 0 6px 12px rgba(0, 0, 0, 0.06);
  padding: 0.9rem 1rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.device-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.5rem;
}

.device-name {
  font-weight: 600;
  font-size: 1rem;
}

.device-imei {
  font-size: 0.8rem;
  color: #777777;
}

.device-header-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.25rem;
}

.last-updated {
  font-size: 0.75rem;
  color: #888888;
}

.status-badge {
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 500;
}

.status-ok {
  background: #f5f5f5;
  color: #333333;
  border: 1px solid #d0d0d0;
}

.status-outofsync {
  background: #fff5f5;
  color: #b71c1c;
  border: 1px solid #e57373;
}

.status-error {
  background: #fff5f5;
  color: #b71c1c;
  border: 1px solid #e57373;
}

.widgets-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.6rem;
}

.source-widget {
  border-radius: 0.7rem;
  padding: 0.55rem 0.6rem;
  background: #fafafa;
  border: 1px solid #e0e0e0;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.8rem;
}

.source-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.15rem;
}

.source-label {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.source-label.flespi {
  color: #333333;
}

.source-label.kafka {
  color: #333333;
}

.timestamp {
  font-size: 0.78rem;
  color: #222222;
}

.age {
  font-size: 0.75rem;
  color: #777777;
}

.age-alert {
  color: #b71c1c;
  font-weight: 600;
}

.error-text {
  font-size: 0.75rem;
  color: #b71c1c;
}

.widget-badge {
  padding: 0.05rem 0.5rem;
  border-radius: 999px;
  font-size: 0.7rem;
  border: 1px solid transparent;
}

.widget-badge-ok {
  border-color: #c0c0c0;
  color: #333333;
}

.widget-badge-missing {
  border-color: #d0d0d0;
  color: #777777;
}

.widget-badge-error {
  border-color: #e57373;
  color: #b71c1c;
}

.out-of-sync {
  background: #fff0f0;
  border-color: #e53935;
}

.out-of-sync .age {
  color: #b71c1c;
}

.footer-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.4rem;
  margin-top: 0.1rem;
}

.diff-text {
  font-size: 0.78rem;
  color: #555555;
}

.distance-normal {
  color: #555555;
}

.distance-alert {
  color: #b71c1c;
  font-weight: 600;
}

.events-button {
  border-radius: 999px;
  border: 1px solid #b0b0b0;
  background: #ffffff;
  color: #222222;
  padding: 0.25rem 0.7rem;
  font-size: 0.78rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
}

.events-button:hover {
  border-color: #888888;
  background: #f0f0f0;
}

.events-count-pill {
  min-width: 1.1rem;
  height: 1.1rem;
  border-radius: 999px;
  background: #f0f0f0;
  color: #222222;
  display: inline-flex;
  justify-content: center;
  align-items: center;
  font-size: 0.7rem;
}

.muted {
  opacity: 0.6;
}

.modal {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}

.modal.hidden {
  display: none;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.15);
  backdrop-filter: blur(2px);
}

.modal-content {
  position: relative;
  background: #ffffff;
  border-radius: 0.75rem;
  border: 1px solid #e0e0e0;
  padding: 0.75rem 0.85rem 0.9rem;
  width: min(420px, 100% - 2rem);
  max-height: min(70vh, 420px);
  display: flex;
  flex-direction: column;
  box-shadow: 0 18px 30px rgba(0, 0, 0, 0.15);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.5rem;
}

.modal-header h2 {
  font-size: 1rem;
  margin: 0;
}

.modal-header-actions {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}

.close-button {
  border-radius: 999px;
  width: 1.6rem;
  height: 1.6rem;
  border: 1px solid #c0c0c0;
  background: transparent;
  color: #333333;
  cursor: pointer;
  font-size: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

.close-button:hover {
  background: #f0f0f0;
}

.modal-body {
  flex: 1;
  overflow-y: auto;
  font-size: 0.82rem;
}

.event-item {
  padding: 0.35rem 0.15rem;
  border-bottom: 1px solid #e0e0e0;
}

.event-item:last-child {
  border-bottom: none;
}

.event-time {
  font-size: 0.78rem;
  color: #777777;
}

.event-desc {
  font-size: 0.85rem;
  color: #222222;
}

.empty-state {
  font-size: 0.85rem;
  color: #777777;
  padding: 0.4rem 0.1rem;
}

.log-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.78rem;
}

.log-table th,
.log-table td {
  border: 1px solid #e0e0e0;
  padding: 0.25rem 0.3rem;
  text-align: left;
  white-space: nowrap;
}

.log-table thead {
  background: #f5f5f5;
  position: sticky;
  top: 0;
}

@media (max-width: 600px) {
  .devices-grid {
    padding-inline: 0.75rem;
  }

  .app-header {
    padding-inline: 0.75rem;
  }

  .summary-bar {
    padding-inline: 0.75rem;
  }
}


