/* Reset */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  line-height: 1.6;
  color: #333;
  background-color: #f5f5f5;
}

/* Navbar */
.navbar {
  background: #fff;
  border-bottom: 1px solid #ddd;
  padding: 0;
}

.nav-container {
  display: flex;
  align-items: center;
}

.nav-brand {
  width: 220px;
  flex-shrink: 0;
  text-align: center;
  padding: 0.75rem 1.25rem;
}

.nav-links-wrapper {
  flex: 1;
  display: flex;
  justify-content: flex-end;
  padding: 0.75rem 1.5rem;
}

.nav-container a {
  color: #333;
  text-decoration: none;
}

.nav-links {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.nav-links span {
  color: #666;
  font-size: 0.9rem;
}

/* Layout with sidebar */
.layout-with-sidebar {
  display: flex;
  min-height: calc(100vh - 56px);
}

.sidebar {
  width: 220px;
  background: #fff;
  border-right: 1px solid #eee;
  padding: 1rem 0;
  flex-shrink: 0;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
}

.sidebar-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1.25rem;
  color: #555;
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 500;
  border-left: 3px solid transparent;
  transition: background 0.15s, color 0.15s;
}

.sidebar-item:hover {
  background: #f5f5f5;
  color: #4a90d9;
}

.sidebar-item.active {
  background: #f0f7ff;
  color: #4a90d9;
  border-left-color: #4a90d9;
  font-weight: 600;
}

.sidebar-item i {
  font-size: 1.1rem;
}

.main-content {
  flex: 1;
  overflow-x: auto;
}

/* Container */
.container {
  max-width: 1100px;
  margin: 2rem auto;
  padding: 0 1.5rem;
}

@media (max-width: 768px) {
  .nav-brand {
    width: auto;
  }
  .nav-links-wrapper {
    padding: 0.75rem 0.5rem;
  }
  .layout-with-sidebar {
    flex-direction: column;
  }
  .sidebar {
    width: 100%;
    border-right: none;
    border-bottom: 1px solid #eee;
    padding: 0.5rem 0;
  }
  .sidebar-nav {
    flex-direction: row;
    overflow-x: auto;
  }
  .sidebar-item {
    border-left: none;
    border-bottom: 3px solid transparent;
    padding: 0.5rem 1rem;
    white-space: nowrap;
  }
  .sidebar-item.active {
    border-left-color: transparent;
    border-bottom-color: #4a90d9;
  }
}

/* Dropdown */
.dropdown {
  position: relative;
}

.dropdown-toggle {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  cursor: pointer;
  background: #fff;
}

.dropdown-arrow {
  font-size: 0.7rem;
  transition: transform 0.2s;
}

.dropdown.open .dropdown-arrow {
  transform: rotate(180deg);
}

.dropdown-menu {
  display: none;
  position: absolute;
  right: 0;
  top: calc(100% + 0.5rem);
  background: #fff;
  border: 1px solid #ddd;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  min-width: 220px;
  z-index: 100;
  padding: 0.4rem 0;
  overflow: hidden;
}

.dropdown.open .dropdown-menu {
  display: block;
}

.dropdown-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.6rem 1rem;
  color: #333;
  text-decoration: none;
  font-size: 0.9rem;
  border: none;
  background: none;
  width: 100%;
  cursor: pointer;
  text-align: left;
}

.dropdown-item:hover {
  background: #f5f5f5;
}

.dropdown-item-danger {
  color: #dc3545;
}

.dropdown-item-danger:hover {
  background: #f8d7da;
}

.dropdown-divider {
  height: 1px;
  background: #eee;
  margin: 0.25rem 0;
}

.dropdown-lang {
  display: flex;
  gap: 0.5rem;
  padding: 0.6rem 1rem;
  justify-content: center;
}

/* Headings */
h1 {
  margin-bottom: 1.5rem;
  font-size: 1.75rem;
}

/* Forms */
.field {
  margin-bottom: 1rem;
}

.field label {
  display: block;
  margin-bottom: 0.25rem;
  font-weight: 600;
}

.field input[type="text"],
.field input[type="email"],
.field input[type="password"],
.field input[type="number"],
.field select {
  width: 100%;
  max-width: 400px;
  padding: 0.5rem 0.75rem;
  border: 1px solid #ccc;
  border-radius: 4px;
  font-size: 1rem;
  background: #fff;
}

.field input:focus {
  outline: none;
  border-color: #4a90d9;
  box-shadow: 0 0 0 2px rgba(74, 144, 217, 0.2);
}

.actions {
  margin-top: 1.5rem;
}

/* Buttons */
.btn {
  display: inline-block;
  padding: 0.5rem 1rem;
  border: 1px solid #ccc;
  border-radius: 4px;
  background: #fff;
  color: #333;
  text-decoration: none;
  font-size: 0.9rem;
  cursor: pointer;
  line-height: 1.4;
}

.btn:hover {
  background: #f0f0f0;
}

.btn-primary {
  background: #4a90d9;
  color: #fff;
  border-color: #4a90d9;
}

.btn-primary:hover {
  background: #3a7bc8;
}

.btn-danger {
  background: #d9534f;
  color: #fff;
  border-color: #d9534f;
}

.btn-danger:hover {
  background: #c9302c;
}

.btn-small {
  padding: 0.25rem 0.6rem;
  font-size: 0.85rem;
}

/* Tables */
table {
  width: 100%;
  border-collapse: collapse;
  background: #fff;
  border-radius: 4px;
  overflow: hidden;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

th, td {
  padding: 0.75rem 1rem;
  text-align: left;
  border-bottom: 1px solid #eee;
}

th {
  background: #fafafa;
  font-weight: 600;
}

.actions-cell {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

/* Alerts */
.alert {
  padding: 0.75rem 1rem;
  border-radius: 4px;
  margin-bottom: 1rem;
}

.alert-success {
  background: #d4edda;
  color: #155724;
  border: 1px solid #c3e6cb;
}

.alert-error {
  background: #f8d7da;
  color: #721c24;
  border: 1px solid #f5c6cb;
}

.alert-error ul {
  margin-top: 0.5rem;
  padding-left: 1.25rem;
}

/* Header row */
.header-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
}

.header-row h1 {
  margin-bottom: 0;
}

/* Empty state */
.empty-state {
  text-align: center;
  color: #999;
  padding: 3rem;
  background: #fff;
  border-radius: 4px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

/* Badges */
.badge {
  display: inline-block;
  padding: 0.2rem 0.6rem;
  border-radius: 12px;
  font-size: 0.8rem;
  font-weight: 600;
}

.badge-active {
  background: #d4edda;
  color: #155724;
}

.badge-inactive {
  background: #f8d7da;
  color: #721c24;
}

.badge-admin {
  background: #fff3cd;
  color: #856404;
}

.badge-user {
  background: #d1ecf1;
  color: #0c5460;
}

.badge-reseller {
  background: #e2d5f1;
  color: #563d7c;
}

.badge-severity-low {
  background: #e8f5e9;
  color: #2e7d32;
  border: 1px solid #a5d6a7;
}

.badge-severity-medium {
  background: #fff8e1;
  color: #f57f17;
  border: 1px solid #ffe082;
}

.badge-severity-high {
  background: #fce4ec;
  color: #c62828;
  border: 1px solid #ef9a9a;
}

.badge-severity-critical {
  background: #b71c1c;
  color: #fff;
  border: 1px solid #b71c1c;
}

.badge-type {
  background: #e3f2fd;
  color: #1565c0;
  border: 1px solid #90caf9;
}

/* Pagination */
.pagination {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 0.4rem;
  margin-top: 1.5rem;
}

/* Dashboard */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.stat-card {
  background: #fff;
  border-radius: 8px;
  padding: 1.25rem;
  text-align: center;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
  border-left: 4px solid #4a90d9;
}

.stat-card.stat-active {
  border-left-color: #28a745;
}

.stat-card.stat-inactive {
  border-left-color: #dc3545;
}

.stat-icon {
  font-size: 1.5rem;
  color: #4a90d9;
  margin-bottom: 0.5rem;
}

.stat-active .stat-icon { color: #28a745; }
.stat-inactive .stat-icon { color: #dc3545; }

.stat-value {
  font-size: 1.5rem;
  font-weight: 700;
  color: #333;
}

.stat-label {
  font-size: 0.85rem;
  color: #777;
  margin-top: 0.25rem;
}

.charts-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
}

.chart-card {
  background: #fff;
  border-radius: 8px;
  padding: 1.5rem;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.chart-card h3 {
  margin: 0 0 1rem 0;
  font-size: 1rem;
  color: #555;
}

.chart-tabs {
  display: inline-flex;
  border: 1px solid #ddd;
  border-radius: 6px;
  overflow: hidden;
  margin-bottom: 1rem;
}

/* Multiselect */
.multiselect {
  position: relative;
}

.multiselect-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 0.8rem;
  border: 1px solid #ddd;
  border-radius: 6px;
  background: #fff;
  cursor: pointer;
  font-size: 0.9rem;
  min-height: 38px;
}

.multiselect-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 220px;
  color: #555;
}

.multiselect-clear {
  font-size: 1.1rem;
  color: #888;
  cursor: pointer;
  line-height: 1;
}

.multiselect-clear:hover {
  color: #333;
}

.multiselect-dropdown {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: #fff;
  border: 1px solid #ddd;
  border-radius: 6px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
  z-index: 100;
  max-height: 250px;
  overflow-y: auto;
  margin-top: 2px;
}

.multiselect.open .multiselect-dropdown {
  display: block;
}

.multiselect-option {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.8rem;
  cursor: pointer;
  font-size: 0.9rem;
  color: #333;
}

.multiselect-option:hover {
  background: #f5f5f5;
}

.chart-tab {
  padding: 0.4rem 1rem;
  border: none;
  background: #fff;
  color: #555;
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  border-right: 1px solid #ddd;
  transition: background 0.15s, color 0.15s;
}

.chart-tab:last-child {
  border-right: none;
}

.chart-tab.active {
  background: #333;
  color: #fff;
}

.chart-tab:hover:not(.active) {
  background: #f5f5f5;
}

@media (max-width: 768px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .charts-grid { grid-template-columns: 1fr; }
}

/* BackOffice Tabs */
.backoffice-header {
  margin-bottom: 1rem;
}

.backoffice-header h1 {
  margin-bottom: 0.5rem;
}

.backoffice-tabs {
  display: flex;
  gap: 0;
  border-bottom: 2px solid #ddd;
  margin-bottom: 1.5rem;
}

.backoffice-tab {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.75rem 1.25rem;
  text-decoration: none;
  color: #666;
  font-weight: 600;
  font-size: 0.95rem;
  border-bottom: 3px solid transparent;
  margin-bottom: -2px;
  transition: color 0.2s, border-color 0.2s;
}

.backoffice-tab:hover {
  color: #4a90d9;
}

.backoffice-tab.active {
  color: #4a90d9;
  border-bottom-color: #4a90d9;
}

.backoffice-content {
  margin-top: 0;
}

/* Location show */
.location-details {
  margin-top: 1rem;
}

.location-info {
  background: #fff;
  border-radius: 8px;
  padding: 1rem 1.5rem;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
  margin-bottom: 1.5rem;
}

.location-info table {
  box-shadow: none;
}

.location-map-container {
  margin-bottom: 1.5rem;
}

.location-map-container h3,
.location-geojson h3 {
  margin: 0 0 0.75rem 0;
  font-size: 1rem;
  color: #555;
}

/* KMZ Upload */
.kmz-upload-card {
  background: #fff;
  border-radius: 8px;
  padding: 2rem;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
  text-align: center;
  margin-top: 1rem;
  border: 2px dashed #ddd;
}

.kmz-upload-icon {
  font-size: 3rem;
  color: #4a90d9;
  margin-bottom: 1rem;
}

.kmz-upload-card h3 {
  margin: 0 0 0.5rem;
  font-size: 1.1rem;
  color: #333;
}

.kmz-upload-card p {
  color: #888;
  margin: 0 0 1.5rem;
  font-size: 0.9rem;
}

.kmz-upload-form {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
}

.form-file {
  padding: 0.5rem;
  border: 1px solid #ccc;
  border-radius: 4px;
  font-size: 0.9rem;
}

/* Search bar */
.search-bar {
  margin-bottom: 1.5rem;
}

.search-input-group {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: #fff;
  padding: 0.5rem 0.75rem;
  border-radius: 8px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.search-icon {
  color: #999;
  font-size: 1.1rem;
}

.search-input {
  flex: 1;
  border: none;
  outline: none;
  font-size: 1rem;
  padding: 0.4rem 0;
}

/* Company groups */
.company-group {
  margin-bottom: 2rem;
}

.company-group-title {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 1.15rem;
  margin-bottom: 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 2px solid #eee;
}

/* Location cards */
.locations-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1rem;
}

.location-card {
  display: block;
  background: #fff;
  border-radius: 8px;
  padding: 1.25rem;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
  text-decoration: none;
  color: #333;
  border-left: 4px solid #4a90d9;
  transition: box-shadow 0.2s, transform 0.2s;
}

.location-card:hover {
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

.location-card-link {
  text-decoration: none;
  color: #333;
  display: block;
}

.location-card-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 600;
  font-size: 1.05rem;
  margin-bottom: 0.75rem;
}

.location-card-header i {
  color: #4a90d9;
  font-size: 1.2rem;
}

.location-card-meta {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.4rem;
  flex-wrap: wrap;
}

.location-card-coords {
  font-size: 0.78rem;
  color: #888;
  margin-bottom: 0.4rem;
}

/* Collapsible sections */
.collapsible-section {
  margin-top: 0.75rem;
  padding-top: 0.75rem;
  border-top: 1px solid #eee;
}

.collapsible-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
  font-size: 0.8rem;
  font-weight: 600;
  color: #555;
  padding: 0.25rem 0;
  user-select: none;
}

.collapsible-header:hover {
  color: #4a90d9;
}

.collapsible-arrow {
  font-size: 0.7rem;
  transition: transform 0.2s;
}

.collapsible-section.open .collapsible-arrow {
  transform: rotate(180deg);
}

.collapsible-action {
  margin-top: 0.5rem;
  text-align: right;
}

.collapsible-body {
  display: none;
  margin-top: 0.4rem;
}

.collapsible-section.open .collapsible-body {
  display: block;
}

.notes-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.note-item {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.2rem 0;
  font-size: 0.8rem;
  color: #555;
}

.note-status {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.note-active {
  background: #28a745;
}

.note-inactive {
  background: #dc3545;
}

.note-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.note-date {
  color: #999;
  font-size: 0.75rem;
  flex-shrink: 0;
}

.location-card-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 0.75rem;
  padding-top: 0.75rem;
  border-top: 1px solid #eee;
}

.location-card-date {
  font-size: 0.8rem;
  color: #999;
}

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

@media (min-width: 769px) and (max-width: 1024px) {
  .locations-grid { grid-template-columns: repeat(2, 1fr); }
}

/* Alerts view */
.alerts-grid {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.alert-card {
  background: #fff;
  border-radius: 8px;
  padding: 1.25rem;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
  border-left: 4px solid #ccc;
}

.alert-card-low { border-left-color: #0c5460; }
.alert-card-medium { border-left-color: #856404; }
.alert-card-high { border-left-color: #721c24; }
.alert-card-critical { border-left-color: #721c24; background: #fff5f5; }

.alert-card-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
  flex-wrap: wrap;
}

.alert-card-date {
  margin-left: auto;
  font-size: 0.8rem;
  color: #999;
}

.alert-card-text {
  font-size: 0.95rem;
  color: #333;
  margin-bottom: 0.5rem;
}

.alert-card-location {
  font-size: 0.85rem;
  color: #666;
}

/* Switch toggle */
.switch-field {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.switch-track {
  position: relative;
  display: inline-block;
  width: 52px;
  height: 28px;
  flex-shrink: 0;
}

.switch-track input {
  opacity: 0;
  width: 0;
  height: 0;
  position: absolute;
}

.switch-track .slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: #ccc;
  border-radius: 28px;
  transition: background-color 0.25s ease;
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.15);
}

.switch-track .slider::after {
  content: "";
  position: absolute;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #fff;
  top: 3px;
  left: 3px;
  transition: transform 0.25s ease;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
}

.switch-track input:checked + .slider {
  background-color: #28a745;
}

.switch-track input:checked + .slider::after {
  transform: translateX(24px);
}

.switch-field .switch-label {
  font-size: 0.95rem;
  color: #333;
  cursor: pointer;
}

/* Links */
a {
  color: #4a90d9;
}

p {
  margin-top: 1rem;
}
