/* ============================
   SAV Baudiment — Base Styles
   ============================ */

/* ---------- RESET & BASE ---------- */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: 'Open Sans', system-ui, -apple-system, sans-serif;
  font-size: 14px;
  line-height: 1.6;
  color: #334155;
  background: #f1f5f9;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

a { color: #3A5083; text-decoration: none; transition: opacity .15s; }
a:hover { text-decoration: underline; opacity: .85; }

h1, h2, h3, h4 { font-family: 'Poppins', system-ui, sans-serif; margin: 0 0 .5em; font-weight: 600; color: #1e293b; }
h1 { font-size: 1.75em; }
h2 { font-size: 1.35em; }
h3 { font-size: 1.1em; }
h4 { font-size: .95em; text-transform: uppercase; letter-spacing: .05em; color: #64748b; }

p { margin: 0 0 .8em; }

img { max-width: 100%; height: auto; }

/* ---------- TOPBAR ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  padding: 0 1.5rem;
  height: 64px;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,.08);
  border-bottom: 1px solid #e2e8f0;
  position: relative;
  z-index: 50;
}
.topbar .brand {
  display: flex;
  align-items: center;
  gap: .75rem;
  color: #1e293b;
  font-weight: 600;
  flex-shrink: 0;
}
.topbar .brand:hover { text-decoration: none; opacity: .85; }
.topbar .brand-logo { height: 34px; width: auto; display: block; border-radius: 6px; background: #fff; padding: 2px; }
.topbar .brand-text { display: flex; flex-direction: column; }
.topbar .brand-title { font-family: 'Poppins', sans-serif; font-size: 1.15em; color: #3A5083; line-height: 1.2; }
.topbar .brand-subtitle { font-size: .68em; color: #94a3b8; font-weight: 400; line-height: 1.2; }

.topbar-nav {
  display: flex;
  align-items: center;
  gap: .25rem;
  flex: 1;
  overflow-x: auto;
  white-space: nowrap;
  -webkit-overflow-scrolling: touch;
}
.topbar-nav::-webkit-scrollbar { height: 3px; }
.topbar-nav::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 3px; }

.nav-link {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  padding: .4rem .7rem;
  border-radius: 6px;
  color: #475569 !important;
  font-size: 13px;
  font-weight: 600;
  transition: all .15s;
  white-space: nowrap;
  background: none;
  border: none;
  cursor: pointer;
  font-family: inherit;
}
.nav-link:hover { background: #f1f5f9; color: #3A5083 !important; text-decoration: none; }
.nav-link.active { background: #eef2ff; color: #3A5083 !important; }
.nav-link i { width: 16px; height: 16px; flex-shrink: 0; }

.topbar-right {
  display: flex;
  align-items: center;
  gap: .6rem;
  flex-shrink: 0;
  margin-left: auto;
}
.topbar-user {
  font-size: 13px;
  color: #3A5083;
  font-weight: 500;
}
.topbar-user.email { font-size: 12px; color: #64748b; font-weight: 400; }

.btn-logout {
  display: inline-flex;
  align-items: center;
  gap: .3rem;
  padding: .35rem .65rem;
  border-radius: 6px;
  background: #fee2e2;
  color: #dc2626;
  border: none;
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  font-family: inherit;
  transition: all .15s;
}
.btn-logout:hover { background: #fecaca; color: #b91c1c; }
.btn-logout i { width: 14px; height: 14px; }

/* ---------- BUTTONS ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  padding: .45rem .9rem;
  font-size: 13px;
  font-weight: 600;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  background: #fff;
  color: #334155;
  cursor: pointer;
  transition: all .15s;
  text-decoration: none;
  font-family: inherit;
  line-height: 1.4;
}
.btn:hover { background: #f8fafc; text-decoration: none; border-color: #cbd5e1; }
.btn-primary { background: #FF9900; color: #fff; border-color: #FF9900; }
.btn-primary:hover { background: #e68a00; border-color: #e68a00; }
.btn-secondary { background: #3A5083; color: #fff; border-color: #3A5083; }
.btn-secondary:hover { background: #2d4069; border-color: #2d4069; }
.btn-danger { color: #dc2626; border-color: #fecaca; }
.btn-danger:hover { background: #fef2f2; }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: #f1f5f9; }
.btn-sm { padding: .3rem .6rem; font-size: 12px; }
.btn-lg { padding: .6rem 1.2rem; font-size: 14px; }
.btn i { width: 16px; height: 16px; flex-shrink: 0; }

/* ---------- HERO ---------- */
.hero {
  text-align: center;
  padding: 3rem 1.5rem 2.5rem;
  background: linear-gradient(135deg, #3A5083 0%, #2d4069 100%);
  color: #fff;
  border-radius: 0 0 2rem 2rem;
  margin: -1.5rem -1.5rem 2rem;
}
.hero h1 { font-size: 2em; color: #fff; margin-bottom: .35rem; font-weight: 700; }
.hero p { font-size: 1.05em; color: rgba(255,255,255,.7); max-width: 560px; margin: 0 auto; }

/* ---------- CARDS ---------- */
.card-grid {
  display: grid;
  gap: 1rem;
  grid-template-columns: repeat(auto-fill, minmax(270px, 1fr));
}
.card {
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  padding: 1.25rem;
  box-shadow: 0 1px 3px rgba(0,0,0,.04);
  transition: all .2s;
  display: flex;
  flex-direction: column;
  gap: .5rem;
}
.card:hover { box-shadow: 0 4px 12px rgba(0,0,0,.08); border-color: #cbd5e1; }
.card-icon {
  width: 48px; height: 48px;
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 24px;
  margin-bottom: .25rem;
  flex-shrink: 0;
}
.card-icon.blue { background: #eef2ff; color: #3A5083; }
.card-icon.orange { background: #fff7ed; color: #FF9900; }
.card-icon.green { background: #f0fdf4; color: #16a34a; }
.card-icon.red { background: #fef2f2; color: #dc2626; }
.card-icon.purple { background: #faf5ff; color: #9333ea; }
.card-icon.teal { background: #f0fdfa; color: #0d9488; }
.card-icon.sky { background: #f0f9ff; color: #0284c7; }
.card-title { font-size: 1.05em; color: #1e293b; font-weight: 600; font-family: 'Poppins', sans-serif; }
.card-desc { font-size: .85em; color: #64748b; line-height: 1.5; margin: 0; }
.card-link { text-decoration: none; display: block; }
.card-link:hover { text-decoration: none; }
.card-link:hover .card { border-color: #FF9900; box-shadow: 0 4px 16px rgba(255,153,0,.12); transform: translateY(-2px); }
.card-link:hover .card-title { color: #3A5083; }

/* ---------- PAGE ---------- */
.page-content { padding: 1.5rem; flex: 1; }
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
  gap: .75rem;
}
.page-header h1 { margin: 0; }
.actions-bar { display: flex; gap: .5rem; align-items: center; }

/* ---------- FORMS ---------- */
.form-group { margin-bottom: 1rem; }
.form-group label { display: block; font-size: 13px; font-weight: 600; color: #475569; margin-bottom: .35rem; }
.form-control {
  width: 100%;
  padding: .5rem .75rem;
  font-size: 14px;
  font-family: inherit;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  background: #fff;
  color: #1e293b;
  transition: border-color .15s, box-shadow .15s;
}
.form-control:focus { outline: none; border-color: #3A5083; box-shadow: 0 0 0 3px rgba(58,80,131,.15); }
.form-control.error { border-color: #dc2626; }
select.form-control { appearance: auto; }
textarea.form-control { resize: vertical; min-height: 80px; }

/* ---------- LOGIN CARD ---------- */
.login-card {
  width: 100%;
  max-width: 420px;
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 4px 24px rgba(0,0,0,.1);
  border: 1px solid #e2e8f0;
  padding: 2.5rem;
}
.login-card h2 { text-align: center; margin-bottom: .35rem; font-size: 1.5em; }
.login-card .subtitle { text-align: center; color: #64748b; font-size: 14px; margin-bottom: 1.5rem; }

/* ---------- FOOTER ---------- */
.footer {
  background: #1e293b;
  color: rgba(255,255,255,.55);
  text-align: center;
  padding: 1.25rem 1.5rem;
  font-size: 13px;
  margin-top: auto;
}
.footer a { color: #FF9900; }
.footer a:hover { color: #fff; text-decoration: none; }

/* ---------- ADMIN SIDEBAR ---------- */
.admin-layout { display: flex; min-height: 100vh; }
.admin-sidebar {
  width: 240px;
  background: #1e293b;
  color: #fff;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
}
.admin-sidebar .sidebar-header {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid rgba(255,255,255,.1);
}
.admin-sidebar .sidebar-brand {
  display: flex;
  align-items: center;
  gap: .75rem;
  color: #fff;
  font-weight: 600;
  font-family: 'Poppins', sans-serif;
  font-size: 1.05em;
}
.admin-sidebar .sidebar-brand:hover { text-decoration: none; opacity: .85; }
.admin-sidebar .sidebar-brand img { height: 30px; width: auto; border-radius: 4px; background: #fff; padding: 4px; }
.admin-sidebar .sidebar-nav { flex: 1; padding: .5rem 0; }
.admin-sidebar .sidebar-link {
  display: flex;
  align-items: center;
  gap: .6rem;
  padding: .6rem 1.25rem;
  color: rgba(255,255,255,.6);
  font-size: 13px;
  font-weight: 500;
  transition: all .15s;
  border: none;
  background: none;
  cursor: pointer;
  width: 100%;
  font-family: inherit;
  text-align: left;
}
.admin-sidebar .sidebar-link:hover { background: rgba(255,255,255,.08); color: #fff; text-decoration: none; }
.admin-sidebar .sidebar-link.active { background: rgba(255,255,255,.12); color: #FF9900; }
.admin-sidebar .sidebar-link i { width: 18px; height: 18px; flex-shrink: 0; }
.admin-sidebar .sidebar-footer {
  padding: .75rem 1.25rem;
  border-top: 1px solid rgba(255,255,255,.1);
  font-size: 12px;
  color: rgba(255,255,255,.4);
}
.admin-sidebar .sidebar-user { font-size: 12px; color: rgba(255,255,255,.6); margin-bottom: .35rem; }
.admin-main { flex: 1; display: flex; flex-direction: column; background: #f1f5f9; min-width: 0; }
.admin-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .75rem 1.5rem;
  background: #fff;
  border-bottom: 1px solid #e2e8f0;
  gap: 1rem;
}
.admin-topbar .admin-breadcrumb { font-size: 13px; color: #64748b; }
.admin-topbar .admin-breadcrumb span { color: #1e293b; font-weight: 600; }
.admin-topbar .admin-actions { display: flex; align-items: center; gap: .5rem; }
.admin-content { flex: 1; padding: 1.5rem; }

/* ---------- MODALS ---------- */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.4);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
  backdrop-filter: blur(2px);
}
.modal-overlay[hidden] { display: none; }
.modal-box {
  background: #fff; border-radius: 12px;
  min-width: 380px; max-width: 90vw;
  box-shadow: 0 10px 40px rgba(0,0,0,.2);
  overflow: hidden;
}
.modal-box h3 {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid #e2e8f0;
  margin: 0;
  font-size: 1.05em;
}
.modal-body { padding: 1.25rem; }
.modal-actions {
  padding: .75rem 1.25rem;
  border-top: 1px solid #e2e8f0;
  display: flex;
  justify-content: flex-end;
  gap: .5rem;
}

/* ---------- TOASTS ---------- */
#toasts {
  position: fixed; bottom: 1.5rem; right: 1.5rem;
  display: flex; flex-direction: column; gap: .5rem;
  z-index: 200;
  pointer-events: none;
}
.toast {
  padding: .6rem 1rem;
  background: #1e293b; color: #fff;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0,0,0,.15);
  font-size: 13px;
  pointer-events: auto;
  animation: toast-in .3s ease;
}
.toast.success { background: #16a34a; }
.toast.error { background: #dc2626; }
.toast.info { background: #3A5083; }
@keyframes toast-in {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ---------- ALERT / ERROR PANEL ---------- */
.alert {
  padding: .75rem 1rem;
  border-radius: 8px;
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: .5rem;
}
.alert-error { background: #fef2f2; border: 1px solid #fecaca; color: #991b1b; }
.alert-success { background: #f0fdf4; border: 1px solid #bbf7d0; color: #166534; }
.alert-info { background: #eff6ff; border: 1px solid #bfdbfe; color: #1e40af; }
.alert i { width: 18px; height: 18px; flex-shrink: 0; }

/* ---------- TABLE ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
table th, table td { padding: .6rem .75rem; text-align: left; border-bottom: 1px solid #e2e8f0; }
table th { background: #f8fafc; font-weight: 600; color: #475569; white-space: nowrap; }
table tr:hover td { background: #fafbfc; }

.table-admin { width: 100%; border-collapse: collapse; font-size: 13px; }
.table-admin thead th { padding: .65rem .75rem; background: #f1f5f9; font-weight: 600; color: #475569; border-bottom: 2px solid #cbd5e1; text-align: left; white-space: nowrap; }
.table-admin tbody td { padding: .5rem .75rem; border-bottom: 1px solid #f1f5f9; vertical-align: middle; }
.table-admin tbody tr:hover td { background: #eef2ff; }

/* ---------- BADGE ---------- */
.badge {
  display: inline-flex;
  align-items: center;
  padding: .15rem .55rem;
  border-radius: 9999px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .03em;
}
.badge-blue { background: #eef2ff; color: #3A5083; }
.badge-orange { background: #fff7ed; color: #c2410c; }
.badge-green { background: #f0fdf4; color: #16a34a; }
.badge-red { background: #fef2f2; color: #dc2626; }
.badge-gray { background: #f1f5f9; color: #475569; }

/* ---------- UTILITIES ---------- */
.container { max-width: 1200px; margin: 0 auto; padding: 0 1rem; }
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-center { justify-content: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: .5rem; }
.gap-3 { gap: .75rem; }
.gap-4 { gap: 1rem; }
.mt-4 { margin-top: 1rem; }
.mt-8 { margin-top: 2rem; }
.mb-4 { margin-bottom: 1rem; }
.text-center { text-align: center; }
.text-sm { font-size: 13px; }
.text-xs { font-size: 12px; }
.font-bold { font-weight: 700; }
.font-medium { font-weight: 500; }
.text-muted { color: #64748b; }
.text-white { color: #fff; }
.min-h-screen { min-height: 100vh; }
.flex-1 { flex: 1; }
.w-full { width: 100%; }
.max-w-md { max-width: 28rem; }
.max-w-lg { max-width: 32rem; }
.mx-auto { margin-left: auto; margin-right: auto; }
.py-4 { padding-top: 1rem; padding-bottom: 1rem; }
.py-8 { padding-top: 2rem; padding-bottom: 2rem; }
.px-4 { padding-left: 1rem; padding-right: 1rem; }

/* ---------- RESPONSIVE ---------- */
@media (max-width: 768px) {
  .hero h1 { font-size: 1.5em; }
  .hero p { font-size: .95em; }
  .card-grid { grid-template-columns: 1fr; }
  .topbar { padding: 0 .75rem; gap: .5rem; }
  .topbar .brand-text { display: none; }
  .topbar-user.email { display: none; }
  .topbar .brand-logo { height: 28px; }
  .page-content { padding: .75rem; }
  .hero { margin: -.75rem -.75rem 1.25rem; padding: 1.5rem .75rem; border-radius: 0 0 1.5rem 1.5rem; }
  .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .table-wrap table { min-width: 600px; }
  .modal-box { max-width: 96vw !important; width: 96vw !important; margin: .5rem; border-radius: 12px !important; max-height: 90vh !important; }
  .modal-detail-grid { grid-template-columns: 1fr !important; }
  .info-grid { grid-template-columns: 1fr !important; }
  .alarmes-controls { flex-direction: column; }
  .alarmes-select { min-width: 100%; }
  .contacts-layout { flex-direction: column; }
  .contacts-sidebar { width: 100% !important; position: static !important; }
  .contacts-main { width: 100% !important; }
  .contacts-main .contacts-hero,
  .contacts-main .contacts-toolbar,
  .contacts-main .region-selected,
  .contacts-main .contacts-list,
  .contacts-main .contacts-empty,
  .contacts-main .contacts-central { max-width:100%; }
  .contacts-map-col { width: 100% !important; position: static !important; }
  .contacts-content-col { width: 100% !important; }
  .page-header { flex-direction: column; align-items: flex-start; }
  .actions-bar { width: 100%; }
  .card-item { flex-wrap: wrap; }
  .card-item .card-actions { width: 100%; justify-content: flex-end; }
  .login-card { padding: 1.5rem; }
  body .admin-table { min-width: 500px; }
  .faq-categories { overflow-x: auto; flex-wrap: nowrap; -webkit-overflow-scrolling: touch; }
  .admin-content { padding: 1rem; }
  .admin-topbar { padding: .5rem 1rem; flex-wrap: wrap; gap: .5rem; }
  .region-group .region-header { flex-direction: column; gap: .5rem; }
  .region-group .region-info { width: 100%; display: flex; justify-content: space-between; }
}
