/* ============================================
   SISMEG - Modern Green Theme
   ============================================ */

:root {
  --primary: #005225;
  --primary-light: #047857;
  --primary-dark: #003616;
  --accent: #10b981;
  --accent-light: #34d399;
  --accent-dark: #059669;
  --white: #ffffff;
  --gray-50: #f9fafb;
  --gray-100: #f3f4f6;
  --gray-200: #e5e7eb;
  --gray-300: #d1d5db;
  --gray-400: #9ca3af;
  --gray-500: #6b7280;
  --gray-600: #4b5563;
  --gray-700: #374151;
  --gray-800: #1f2937;
  --gray-900: #111827;
  --green-50: #f0fdf4;
  --green-100: #dcfce7;
  --green-200: #bbf7d0;
  --green-500: #22c55e;
  --green-600: #16a34a;
  --red-50: #fef2f2;
  --red-500: #ef4444;
  --red-600: #dc2626;
  --yellow-50: #fffbeb;
  --yellow-500: #eab308;
  --orange-500: #f97316;
  --blue-500: #3b82f6;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
  --shadow: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.1), 0 2px 4px -1px rgba(0,0,0,0.06);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -2px rgba(0,0,0,0.05);
  --radius: 0.5rem;
  --radius-lg: 0.75rem;
}

/* ---------- Reset & Base ---------- */
* { box-sizing: border-box; }
html, body {
  height: 100%;
  margin: 0;
  padding: 0;
  font-family: 'Inter', 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--gray-100);
  color: var(--gray-800);
  -webkit-font-smoothing: antialiased;
}

/* ---------- Layout ---------- */
#wrapper {
  display: flex;
  min-height: 100vh;
}

/* Sidebar */
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: 260px;
  height: 100vh;
  background: linear-gradient(180deg, var(--primary-dark) 0%, var(--primary) 40%, var(--primary-light) 100%);
  z-index: 1000;
  display: flex;
  flex-direction: column;
  transition: all 0.3s ease;
  box-shadow: 2px 0 12px rgba(0,0,0,0.15);
}

.sidebar-brand {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem 1rem;
  border-bottom: 1px solid rgba(255,255,255,0.1);
}

.sidebar-brand img {
  width: 130px;
  height: auto;
  filter: brightness(1.1);
}

.sidebar-divider {
  margin: 0.5rem 1rem;
  border: none;
  border-top: 1px solid rgba(255,255,255,0.1);
}

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 0.5rem 0;
}

.sidebar-nav::-webkit-scrollbar { width: 4px; }
.sidebar-nav::-webkit-scrollbar-track { background: transparent; }
.sidebar-nav::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.2); border-radius: 2px; }

.nav-item {
  list-style: none;
}

.nav-link {
  display: flex;
  align-items: center;
  padding: 0.75rem 1.25rem;
  color: rgba(255,255,255,0.8);
  text-decoration: none;
  transition: all 0.2s ease;
  border-left: 3px solid transparent;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
}

.nav-link:hover {
  color: var(--white);
  background: rgba(255,255,255,0.1);
  border-left-color: var(--accent-light);
}

.nav-link.active {
  color: var(--white);
  background: rgba(255,255,255,0.12);
  border-left-color: var(--accent);
}

.nav-link i {
  width: 1.75rem;
  font-size: 1.1rem;
  text-align: center;
  margin-right: 0.75rem;
}

.nav-link .nav-text {
  flex: 1;
}

.nav-link .collapse-icon {
  transition: transform 0.3s ease;
  font-size: 0.75rem;
}

.nav-link[aria-expanded="true"] .collapse-icon {
  transform: rotate(90deg);
}

.sub-nav {
  padding-left: 0;
  list-style: none;
  background: rgba(0,0,0,0.15);
  overflow: hidden;
  max-height: 0;
  transition: max-height 0.3s ease;
}

.sub-nav.show {
  max-height: 500px;
}

.sub-nav .nav-link {
  padding-left: 3.5rem;
  font-size: 0.85rem;
}

/* Content Wrapper */
#content-wrapper {
  flex: 1;
  margin-left: 260px;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  transition: margin-left 0.3s ease;
}

/* Topbar */
.topbar {
  background: var(--white);
  box-shadow: var(--shadow-sm);
  padding: 0 1.5rem;
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 999;
}

.topbar-branding {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.topbar-branding h5 {
  margin: 0;
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--gray-900);
  letter-spacing: 0.02em;
}

.topbar-branding small {
  display: block;
  font-size: 0.75rem;
  color: var(--gray-500);
  font-weight: 500;
}

.topbar-branding-divider {
  width: 1px;
  height: 32px;
  background: var(--gray-200);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.btn-logout {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--gray-600);
  background: var(--gray-100);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  text-decoration: none;
  transition: all 0.2s ease;
  cursor: pointer;
}

.btn-logout:hover {
  color: var(--red-600);
  background: var(--red-50);
  border-color: var(--red-500);
}

/* Main Content */
#content {
  flex: 1;
  padding: 1.5rem;
}

/* Footer */
.sticky-footer {
  background: var(--white);
  border-top: 1px solid var(--gray-200);
  padding: 0.75rem 1.5rem;
  font-size: 0.8rem;
  color: var(--gray-500);
}

.sticky-footer a {
  color: var(--primary);
  text-decoration: none;
}

/* ---------- Cards ---------- */
.card {
  background: var(--white);
  border: none;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.card-header {
  padding: 1rem 1.5rem;
  background: var(--white);
  border-bottom: 1px solid var(--gray-200);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.card-title {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--gray-800);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.card-body {
  padding: 1.5rem;
}

/* ---------- Tables ---------- */
.table-container {
  overflow-x: auto;
}

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

.table thead th {
  background: var(--gray-50);
  padding: 0.75rem 1rem;
  font-weight: 600;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--gray-600);
  border-bottom: 2px solid var(--gray-200);
  text-align: left;
  white-space: nowrap;
}

.table tbody td {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--gray-100);
  vertical-align: middle;
  color: var(--gray-700);
}

.table tbody tr:hover {
  background: var(--green-50);
}

.table tbody tr.finalizado {
  background: var(--green-50);
}

.table-actions {
  display: flex;
  gap: 0.375rem;
  flex-wrap: nowrap;
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.375rem;
  padding: 0.5rem 1rem;
  font-size: 0.85rem;
  font-weight: 500;
  line-height: 1.4;
  border-radius: var(--radius);
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.2s ease;
  text-decoration: none;
  white-space: nowrap;
}

.btn:focus { outline: none; box-shadow: 0 0 0 3px rgba(0,82,37,0.2); }

.btn-sm { padding: 0.375rem 0.75rem; font-size: 0.8rem; }
.btn-xs { padding: 0.25rem 0.5rem; font-size: 0.75rem; }

.btn-primary {
  background: var(--primary);
  color: var(--white);
  border-color: var(--primary);
}
.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }

.btn-success {
  background: var(--accent);
  color: var(--white);
  border-color: var(--accent);
}
.btn-success:hover { background: var(--accent-dark); border-color: var(--accent-dark); }

.btn-warning {
  background: var(--yellow-500);
  color: var(--white);
  border-color: var(--yellow-500);
}
.btn-warning:hover { background: #d97706; border-color: #d97706; }

.btn-danger {
  background: var(--red-500);
  color: var(--white);
  border-color: var(--red-500);
}
.btn-danger:hover { background: var(--red-600); border-color: var(--red-600); }

.btn-info {
  background: var(--blue-500);
  color: var(--white);
  border-color: var(--blue-500);
}
.btn-info:hover { background: #2563eb; border-color: #2563eb; }

.btn-outline-primary {
  background: transparent;
  color: var(--primary);
  border-color: var(--primary);
}
.btn-outline-primary:hover { background: var(--primary); color: var(--white); }

.btn-light {
  background: var(--gray-100);
  color: var(--gray-700);
  border-color: var(--gray-200);
}
.btn-light:hover { background: var(--gray-200); }

.btn-group {
  display: inline-flex;
  gap: 1px;
}

.dropdown-menu {
  background: var(--white);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 0.375rem 0;
  min-width: 200px;
}

.dropdown-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  color: var(--gray-700);
  text-decoration: none;
  font-size: 0.85rem;
  transition: background 0.15s ease;
}

.dropdown-item:hover {
  background: var(--green-50);
  color: var(--primary);
}

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

.form-label {
  display: block;
  margin-bottom: 0.375rem;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--gray-700);
}

.form-control {
  display: block;
  width: 100%;
  padding: 0.5rem 0.75rem;
  font-size: 0.875rem;
  line-height: 1.5;
  color: var(--gray-800);
  background: var(--white);
  border: 1px solid var(--gray-300);
  border-radius: var(--radius);
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.form-control:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(16,185,129,0.15);
}

.form-control::placeholder { color: var(--gray-400); }

select.form-control {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%236b7280' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.75rem center;
  padding-right: 2.25rem;
}

textarea.form-control {
  min-height: 80px;
  resize: vertical;
}

.form-check {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  margin-right: 1rem;
  margin-bottom: 0.5rem;
}

.form-check-input {
  width: 1rem;
  height: 1rem;
  accent-color: var(--primary);
}

.form-check-label {
  font-size: 0.85rem;
  color: var(--gray-700);
}

.form-text {
  font-size: 0.75rem;
  color: var(--gray-500);
  margin-top: 0.25rem;
}

/* Radio colors by level */
#nivel1, input[value="1"][name="nivel"] { accent-color: var(--yellow-500); }
#nivel2, input[value="2"][name="nivel"] { accent-color: var(--orange-500); }
#nivel3, input[value="3"][name="nivel"] { accent-color: var(--red-500); }

/* ---------- Modals ---------- */
.modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0,0,0,0.5);
  z-index: 1050;
  overflow-y: auto;
  padding: 2rem 1rem;
}

.modal.show { display: block; }

.modal-dialog {
  max-width: 600px;
  margin: 0 auto;
  position: relative;
}

.modal-dialog.modal-lg { max-width: 800px; }
.modal-dialog.modal-xl { max-width: 1000px; }

.modal-content {
  background: var(--white);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--gray-200);
}

.modal-title {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--gray-800);
}

.modal-body {
  padding: 1.5rem;
}

.modal-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.5rem;
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--gray-200);
}

.close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  font-size: 1.25rem;
  color: var(--gray-400);
  background: transparent;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  transition: all 0.2s ease;
}

.close:hover {
  background: var(--gray-100);
  color: var(--gray-600);
}

/* ---------- Badges ---------- */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.25rem 0.625rem;
  font-size: 0.75rem;
  font-weight: 600;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.badge-success { background: var(--green-100); color: #166534; }
.badge-warning { background: var(--yellow-50); color: #92400e; }
.badge-danger { background: var(--red-50); color: #991b1b; }
.badge-info { background: #eff6ff; color: #1e40af; }

/* ---------- Page Header ---------- */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.page-header h4 {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--gray-800);
}

.page-header h4 i {
  color: var(--primary);
  margin-right: 0.5rem;
}

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

/* ---------- Alert ---------- */
.alert {
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  margin-bottom: 1rem;
  font-size: 0.875rem;
}

.alert-success { background: var(--green-100); color: #166534; border: 1px solid var(--green-200); }
.alert-danger { background: var(--red-50); color: #991b1b; border: 1px solid #fecaca; }
.alert-info { background: #eff6ff; color: #1e40af; border: 1px solid #bfdbfe; }

/* ---------- Map ---------- */
.map-container {
  width: 100%;
  height: 100%;
  position: relative;
}

#map {
  width: 100%;
  height: 45rem;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}

#map.fullscreen {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  z-index: 9999;
  border-radius: 0;
}

#fullscreen-toggle {
  position: absolute;
  top: 1rem;
  right: 1rem;
  z-index: 1100;
}

/* ---------- Popup Custom ---------- */
.custom-popup .leaflet-popup-content-wrapper {
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
}

.img-emerg {
  height: 200px;
  object-fit: cover;
  border-radius: var(--radius);
}

/* ---------- Image Grid ---------- */
.image-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 0.75rem;
}

.image-grid img {
  width: 100%;
  height: 180px;
  object-fit: cover;
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}

/* ---------- Utilities ---------- */
.d-flex { display: flex; }
.align-items-center { align-items: center; }
.justify-content-between { justify-content: space-between; }
.justify-content-end { justify-content: flex-end; }
.flex-wrap { flex-wrap: wrap; }
.gap-1 { gap: 0.25rem; }
.gap-2 { gap: 0.5rem; }
.gap-3 { gap: 0.75rem; }
.gap-4 { gap: 1rem; }
.text-center { text-align: center; }
.text-right { text-align: right; }
.text-uppercase { text-transform: uppercase; }
.font-bold { font-weight: 700; }
.text-muted { color: var(--gray-500); }
.text-primary { color: var(--primary); }
.text-success { color: var(--accent); }
.text-danger { color: var(--red-500); }
.mb-2 { margin-bottom: 0.5rem; }
.mb-3 { margin-bottom: 0.75rem; }
.mb-4 { margin-bottom: 1rem; }
.mt-2 { margin-top: 0.5rem; }
.mt-3 { margin-top: 0.75rem; }
.mt-4 { margin-top: 1rem; }
.p-0 { padding: 0; }
.p-2 { padding: 0.5rem; }
.p-3 { padding: 0.75rem; }
.p-4 { padding: 1rem; }
.p-5 { padding: 1.5rem; }
.w-100 { width: 100%; }

.row {
  display: flex;
  flex-wrap: wrap;
  margin: -0.5rem;
}

.row > [class*="col-"] {
  padding: 0.5rem;
}

.col-md-2 { width: 16.6667%; }
.col-md-3 { width: 25%; }
.col-md-4 { width: 33.3333%; }
.col-md-5 { width: 41.6667%; }
.col-md-6 { width: 50%; }
.col-md-7 { width: 58.3333%; }
.col-md-8 { width: 66.6667%; }
.col-md-12 { width: 100%; }

/* ---------- Responsive ---------- */
@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
  }
  .sidebar.open {
    transform: translateX(0);
  }
  #content-wrapper {
    margin-left: 0;
  }
  .col-md-2, .col-md-3, .col-md-4, .col-md-5, .col-md-6, .col-md-7, .col-md-8 {
    width: 100%;
  }
  .page-header {
    flex-direction: column;
    align-items: flex-start;
  }
  .topbar-branding h5 {
    font-size: 0.8rem;
  }
  .table-actions {
    flex-direction: column;
  }
  #map {
    height: 20rem;
  }
  .modal-dialog {
    margin: 0.5rem;
  }
}

/* ---------- DataTables overrides ---------- */
.dataTables_wrapper .dataTables_filter input {
  border: 1px solid var(--gray-300);
  border-radius: var(--radius);
  padding: 0.375rem 0.75rem;
  font-size: 0.85rem;
  margin-left: 0.5rem;
}

.dataTables_wrapper .dataTables_length select {
  border: 1px solid var(--gray-300);
  border-radius: var(--radius);
  padding: 0.25rem 1.5rem 0.25rem 0.5rem;
  font-size: 0.85rem;
}

.dataTables_wrapper .dataTables_paginate {
  display: flex;
  gap: 0.25rem;
  align-items: center;
}

.dataTables_wrapper .dataTables_paginate .paginate_button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 2rem;
  height: 2rem;
  padding: 0.25rem 0.5rem;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  background: var(--white);
  color: var(--gray-600);
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.2s ease;
}

.dataTables_wrapper .dataTables_paginate .paginate_button:hover {
  background: var(--green-50);
  border-color: var(--accent);
  color: var(--primary);
}

.dataTables_wrapper .dataTables_paginate .paginate_button.current {
  background: var(--primary);
  border-color: var(--primary);
  color: var(--white);
}

.dataTables_wrapper .dataTables_info {
  font-size: 0.85rem;
  color: var(--gray-500);
  padding-top: 0.5rem;
}

/* ---------- Sidebar Toggle (mobile) ---------- */
.sidebar-toggle {
  display: none;
  background: none;
  border: none;
  font-size: 1.25rem;
  color: var(--gray-600);
  cursor: pointer;
  padding: 0.25rem;
}

.sidebar-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0,0,0,0.3);
  z-index: 999;
}

@media (max-width: 768px) {
  .sidebar-toggle {
    display: block;
  }
  .sidebar-overlay.active {
    display: block;
  }
}

/* ---------- Smooth scroll ---------- */
html {
  scroll-behavior: smooth;
}

/* ---------- Table striped ---------- */
.table-striped tbody tr:nth-of-type(odd) {
  background: var(--gray-50);
}
