:root {
  --bg:    #161412;
  --panel: #1f1c19;
  --panel2:#272320;
  --line:  #3a342c;
  --line2: #2c2823;
  --tx:    #efebe3;
  --mut:   #a89f92;
  --dim:   #7d766b;
  --amb:   #f2a33c;
  --amb2:  #ffc26b;
  --grn:   #5cbb8a;
  --red:   #e2604f;
  --stl:   #7fa8c4;
  --sage:  #9bb07c;
  --lav:   #a392c9;

  --r: 6px;
  --r2: 10px;
  --shadow: 0 2px 12px rgba(0,0,0,.45);
  --shadow2: 0 4px 24px rgba(0,0,0,.55);
}

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

html { scroll-behavior: smooth; }

body {
  background: var(--bg);
  color: var(--tx);
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  min-height: 100vh;
}

/* ─── Scrollbar ─────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--panel); }
::-webkit-scrollbar-thumb { background: var(--line); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--mut); }

/* ─── Typography ─────────────────────────────────────── */
h1 { font-size: 1.5rem; font-weight: 700; }
h2 { font-size: 1.15rem; font-weight: 600; }
h3 { font-size: .95rem; font-weight: 600; }
small { font-size: .78rem; color: var(--mut); }

a { color: var(--amb); text-decoration: none; }
a:hover { color: var(--amb2); }

/* ─── Layout ─────────────────────────────────────── */
.container { max-width: 1440px; margin: 0 auto; padding: 0 1rem; }
.page-wrap { padding: 0 1.5rem 2rem; max-width: 1440px; margin: 0 auto; }

/* ─── Navbar ─────────────────────────────────────── */
.navbar {
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow);
}
.navbar-inner {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .6rem 1.5rem;
  max-width: 1440px;
  margin: 0 auto;
}
.navbar-brand {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--amb);
  letter-spacing: -.01em;
  white-space: nowrap;
}
.navbar-brand span { color: var(--tx); font-weight: 400; }

.nav-tabs {
  display: flex;
  gap: .25rem;
  overflow-x: auto;
  flex: 1;
  scrollbar-width: none;
}
.nav-tabs::-webkit-scrollbar { display: none; }
.nav-tab {
  padding: .4rem .85rem;
  border-radius: var(--r);
  cursor: pointer;
  color: var(--mut);
  font-weight: 500;
  font-size: .85rem;
  white-space: nowrap;
  transition: background .15s, color .15s;
  border: none;
  background: transparent;
}
.nav-tab:hover { background: var(--panel2); color: var(--tx); }
.nav-tab.active { background: var(--panel2); color: var(--amb); }

.navbar-right {
  display: flex;
  align-items: center;
  gap: .75rem;
  margin-left: auto;
  white-space: nowrap;
}
.months-badge {
  background: var(--panel2);
  border: 1px solid var(--line);
  padding: .25rem .6rem;
  border-radius: 99px;
  font-size: .75rem;
  color: var(--mut);
}
.months-badge span { color: var(--amb); font-weight: 600; }
.btn-icon {
  background: var(--panel2);
  border: 1px solid var(--line);
  color: var(--mut);
  padding: .35rem .65rem;
  border-radius: var(--r);
  cursor: pointer;
  font-size: .8rem;
  transition: .15s;
}
.btn-icon:hover { color: var(--tx); border-color: var(--amb); }

/* ─── Tab panels ─────────────────────────────────── */
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ─── Cards ─────────────────────────────────────── */
.card {
  background: var(--panel);
  border: 1px solid var(--line2);
  border-radius: var(--r2);
  padding: 1.25rem;
}
.card-title {
  font-size: .8rem;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--mut);
  margin-bottom: .75rem;
}
.card-title .hl { color: var(--amb); }

/* ─── KPI grid ─────────────────────────────────── */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: .9rem;
  margin-bottom: 1.25rem;
}
.kpi-card {
  background: var(--panel);
  border: 1px solid var(--line2);
  border-radius: var(--r2);
  padding: 1rem 1.25rem;
  position: relative;
}
.kpi-label { font-size: .72rem; color: var(--mut); text-transform: uppercase; letter-spacing: .06em; margin-bottom: .3rem; }
.kpi-value { font-size: 1.7rem; font-weight: 700; line-height: 1.1; }
.kpi-sub { font-size: .75rem; color: var(--mut); margin-top: .25rem; }
.kpi-card.accent-amb .kpi-value { color: var(--amb); }
.kpi-card.accent-grn .kpi-value { color: var(--grn); }
.kpi-card.accent-red .kpi-value { color: var(--red); }
.kpi-card.accent-stl .kpi-value { color: var(--stl); }

/* ─── Chart grid ─────────────────────────────────── */
.chart-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .9rem;
  margin-bottom: .9rem;
}
.chart-grid.wide { grid-template-columns: 2fr 1fr; }
.chart-grid.triple { grid-template-columns: 1fr 1fr 1fr; }
.chart-wrap { position: relative; min-height: 240px; max-height: 320px; }
.chart-wrap canvas { width: 100% !important; }

@media (max-width: 900px) {
  .chart-grid, .chart-grid.wide, .chart-grid.triple { grid-template-columns: 1fr; }
}

/* ─── Tables ─────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .84rem; }
thead th {
  background: var(--panel2);
  color: var(--mut);
  font-size: .72rem;
  text-transform: uppercase;
  letter-spacing: .06em;
  padding: .5rem .75rem;
  text-align: left;
  white-space: nowrap;
  border-bottom: 1px solid var(--line);
}
thead th.r { text-align: right; }
tbody tr { border-bottom: 1px solid var(--line2); transition: background .1s; }
tbody tr:hover { background: var(--panel2); }
tbody td { padding: .5rem .75rem; }
tbody td.r { text-align: right; font-variant-numeric: tabular-nums; }
tbody td.mono { font-size: .78rem; color: var(--mut); font-family: monospace; }

/* ─── Badges / Pills ─────────────────────────────── */
.badge {
  display: inline-block;
  padding: .15rem .55rem;
  border-radius: 99px;
  font-size: .7rem;
  font-weight: 600;
  letter-spacing: .03em;
}
.badge-camp { background: rgba(242,163,60,.18); color: var(--amb); }
.badge-leal { background: rgba(92,187,138,.18); color: var(--grn); }
.badge-pot  { background: rgba(163,146,201,.18); color: var(--lav); }
.badge-nuevo{ background: rgba(127,168,196,.18); color: var(--stl); }
.badge-riesgo{ background: rgba(226,96,79,.18); color: var(--red); }
.badge-ocas { background: rgba(168,159,146,.18); color: var(--mut); }
.badge-dorm { background: rgba(61,52,44,.6); color: var(--dim); }
.badge-rev  { background: rgba(226,96,79,.1); color: var(--red); }

/* ─── Segment chips ─────────────────────────────── */
.seg-chips { display: flex; gap: .45rem; flex-wrap: wrap; margin-bottom: 1rem; }
.seg-chip {
  padding: .3rem .85rem;
  border-radius: 99px;
  border: 1px solid var(--line);
  cursor: pointer;
  font-size: .78rem;
  font-weight: 500;
  color: var(--mut);
  transition: .15s;
  background: transparent;
}
.seg-chip:hover { border-color: var(--amb); color: var(--tx); }
.seg-chip.active { border-color: var(--amb); background: rgba(242,163,60,.12); color: var(--amb); }

/* ─── Search ─────────────────────────────────────── */
.search-wrap { position: relative; margin-bottom: .85rem; }
.search-input {
  width: 100%;
  background: var(--panel2);
  border: 1px solid var(--line);
  color: var(--tx);
  padding: .5rem .85rem .5rem 2.2rem;
  border-radius: var(--r);
  font-size: .87rem;
  outline: none;
  transition: border-color .15s;
}
.search-input:focus { border-color: var(--amb); }
.search-icon { position: absolute; left: .7rem; top: 50%; transform: translateY(-50%); color: var(--dim); pointer-events: none; }

/* ─── Section header ─────────────────────────────── */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: .85rem;
}
.section-header h2 { font-size: 1rem; }

/* ─── Buttons ─────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  padding: .45rem 1rem;
  border-radius: var(--r);
  border: 1px solid transparent;
  cursor: pointer;
  font-size: .84rem;
  font-weight: 500;
  transition: .15s;
}
.btn-primary { background: var(--amb); color: #1a1000; border-color: var(--amb); }
.btn-primary:hover { background: var(--amb2); }
.btn-outline { background: transparent; border-color: var(--line); color: var(--mut); }
.btn-outline:hover { border-color: var(--amb); color: var(--amb); }
.btn-danger { background: rgba(226,96,79,.15); border-color: var(--red); color: var(--red); }
.btn-danger:hover { background: rgba(226,96,79,.25); }
.btn-sm { padding: .3rem .7rem; font-size: .78rem; }

/* ─── Insight box ─────────────────────────────────── */
.insight-box {
  background: var(--panel2);
  border-left: 3px solid var(--amb);
  border-radius: 0 var(--r) var(--r) 0;
  padding: .65rem 1rem;
  margin-bottom: .6rem;
  font-size: .82rem;
  color: var(--mut);
  line-height: 1.55;
}
.insight-box.warn { border-color: var(--red); }
.insight-box.good { border-color: var(--grn); }
.insight-box strong { color: var(--tx); }

/* ─── Progress bar ─────────────────────────────────── */
.progress-bar-wrap { height: 6px; background: var(--line2); border-radius: 3px; overflow: hidden; margin-top: .4rem; }
.progress-bar-fill { height: 100%; border-radius: 3px; transition: width .5s; }

/* ─── Overlay / drawer ─────────────────────────────── */
.overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,.6);
  z-index: 200;
  align-items: flex-start;
  justify-content: flex-end;
}
.overlay.open { display: flex; }
.drawer {
  background: var(--panel);
  width: min(520px, 100vw);
  height: 100vh;
  overflow-y: auto;
  padding: 1.5rem;
  border-left: 1px solid var(--line);
  animation: slideIn .2s ease;
}
@keyframes slideIn { from { transform: translateX(100%); } to { transform: translateX(0); } }
.drawer-close {
  float: right;
  background: transparent;
  border: none;
  color: var(--mut);
  font-size: 1.2rem;
  cursor: pointer;
  padding: .25rem;
}
.drawer-close:hover { color: var(--tx); }

/* ─── Loading ─────────────────────────────────────── */
#loading-overlay {
  display: none;
  position: fixed; inset: 0;
  background: var(--bg);
  z-index: 500;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 1rem;
}
#loading-overlay.show { display: flex; }
.spinner {
  width: 36px; height: 36px;
  border: 3px solid var(--line);
  border-top-color: var(--amb);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
#loading-text { color: var(--mut); font-size: .9rem; }

/* ─── Login page ─────────────────────────────────── */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(ellipse at 60% 40%, rgba(242,163,60,.07) 0%, transparent 70%), var(--bg);
}
.login-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 2.5rem;
  width: min(420px, 95vw);
  box-shadow: var(--shadow2);
}
.login-logo { font-size: 1.4rem; font-weight: 800; color: var(--amb); margin-bottom: .25rem; }
.login-sub { color: var(--mut); font-size: .85rem; margin-bottom: 2rem; }
.form-group { margin-bottom: 1rem; }
.form-label { display: block; font-size: .8rem; color: var(--mut); margin-bottom: .35rem; }
.form-input {
  width: 100%;
  background: var(--panel2);
  border: 1px solid var(--line);
  color: var(--tx);
  padding: .6rem .9rem;
  border-radius: var(--r);
  font-size: .9rem;
  outline: none;
  transition: border-color .15s;
}
.form-input:focus { border-color: var(--amb); }
.form-error { color: var(--red); font-size: .8rem; margin-top: .5rem; min-height: 1em; }
.form-submit { width: 100%; padding: .7rem; font-size: .95rem; margin-top: .5rem; }

/* ─── Map ─────────────────────────────────────────── */
#map-container {
  height: 480px;
  border-radius: var(--r2);
  overflow: hidden;
  border: 1px solid var(--line2);
}
.leaflet-popup-content-wrapper {
  background: var(--panel) !important;
  color: var(--tx) !important;
  border: 1px solid var(--line) !important;
  box-shadow: var(--shadow2) !important;
}
.leaflet-popup-tip { background: var(--panel) !important; }

/* ─── Drag & drop zone ─────────────────────────────── */
.drop-zone {
  border: 2px dashed var(--line);
  border-radius: var(--r2);
  padding: 2.5rem;
  text-align: center;
  cursor: pointer;
  transition: .2s;
  color: var(--mut);
}
.drop-zone:hover, .drop-zone.drag-over { border-color: var(--amb); color: var(--amb); background: rgba(242,163,60,.04); }
.drop-icon { font-size: 2rem; margin-bottom: .5rem; }

/* ─── Month chips ─────────────────────────────────── */
.month-chips { display: flex; gap: .5rem; flex-wrap: wrap; }
.month-chip {
  background: var(--panel2);
  border: 1px solid var(--line);
  border-radius: 99px;
  padding: .25rem .75rem;
  font-size: .78rem;
  display: flex;
  align-items: center;
  gap: .4rem;
}
.month-chip .rm { cursor: pointer; color: var(--dim); }
.month-chip .rm:hover { color: var(--red); }
.month-chip.loaded { border-color: var(--grn); color: var(--grn); }

/* ─── Toast ─────────────────────────────────────────── */
#toast-container { position: fixed; bottom: 1.5rem; right: 1.5rem; z-index: 999; display: flex; flex-direction: column; gap: .5rem; }
.toast {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: .65rem 1.1rem;
  font-size: .84rem;
  box-shadow: var(--shadow);
  animation: toastIn .2s ease;
  max-width: 320px;
}
.toast.ok { border-color: var(--grn); }
.toast.err { border-color: var(--red); }
@keyframes toastIn { from { opacity:0; transform: translateY(10px); } to { opacity:1; transform: none; } }

/* ─── Utility ─────────────────────────────────────── */
.mt-1 { margin-top: .5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.mb-1 { margin-bottom: .5rem; }
.mb-2 { margin-bottom: 1rem; }
.gap-row { display: flex; flex-wrap: wrap; gap: .9rem; align-items: stretch; }
.gap-row > * { flex: 1 1 300px; }
.text-amt { color: var(--amb); font-weight: 600; }
.text-green { color: var(--grn); }
.text-red { color: var(--red); }
.text-muted { color: var(--mut); }
.text-dim { color: var(--dim); }
.text-right { text-align: right; }
.mono { font-family: monospace; }
.truncate { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.no-data { text-align: center; padding: 3rem 1rem; color: var(--dim); }
.no-data p { margin-top: .5rem; font-size: .85rem; }
