/* ─── Variables ─── */
:root {
  --primary: #0f6b65;
  --primary-light: #1a9e96;
  --primary-dark: #0a4d49;
  --sidebar-bg: #1e293b;
  --sidebar-text: #cbd5e1;
  --sidebar-active: #0f6b65;
  --bg: #f1f5f9;
  --surface: #ffffff;
  --text: #1e293b;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --danger: #ef4444;
  --warning: #f59e0b;
  --success: #10b981;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,.1), 0 1px 2px rgba(0,0,0,.06);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,.1), 0 2px 4px -1px rgba(0,0,0,.06);
}

/* ─── Reset ─── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; font-family: system-ui, -apple-system, sans-serif; color: var(--text); background: var(--bg); }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; height: auto; }

/* ─── Navbar ─── */
.navbar {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--surface); border-bottom: 2px solid var(--primary);
  padding: 0 1.5rem; height: 56px; position: sticky; top: 0; z-index: 1000;
  box-shadow: var(--shadow);
}
.nav-logo { font-size: 1.4rem; font-weight: 800; color: var(--primary); letter-spacing: -0.5px; }
.nav-links { display: flex; align-items: center; gap: 1.25rem; }
.nav-links a { color: var(--text-muted); font-weight: 500; transition: color .2s; font-size: .95rem; }
.nav-links a:hover, .nav-links a.active { color: var(--primary); text-decoration: none; }
.btn-login {
  background: var(--primary); color: #fff !important; padding: .35rem .9rem;
  border-radius: var(--radius); font-size: .9rem;
}
.btn-login:hover { background: var(--primary-dark); }

/* ─── Map Layout ─── */
.map-layout {
  display: flex; height: calc(100vh - 56px); overflow: hidden;
}

/* ─── Side Panel ─── */
.side-panel {
  width: 300px; min-width: 300px; background: var(--surface);
  border-right: 1px solid var(--border); display: flex; flex-direction: column;
  transition: width .25s ease, min-width .25s ease; position: relative; overflow: hidden;
}
.side-panel.collapsed { width: 32px; min-width: 32px; }
.side-panel.collapsed .panel-content { display: none; }
.panel-toggle {
  position: absolute; top: 50%; right: 4px; transform: translateY(-50%);
  background: var(--primary); color: #fff; border: none; border-radius: 50%;
  width: 22px; height: 22px; cursor: pointer; font-size: 10px; z-index: 10;
  display: flex; align-items: center; justify-content: center;
}
.panel-content { flex: 1; overflow-y: auto; padding: 1rem .75rem; }
.panel-title { font-size: 1rem; font-weight: 700; color: var(--primary); margin-bottom: .75rem; }

/* Level toggle */
.level-toggle { display: flex; gap: .5rem; margin-bottom: .75rem; }
.level-btn {
  flex: 1; padding: .3rem .5rem; border: 1.5px solid var(--border);
  border-radius: var(--radius); background: var(--surface); cursor: pointer;
  font-size: .85rem; font-weight: 500; transition: all .15s;
}
.level-btn.active { background: var(--primary); color: #fff; border-color: var(--primary); }

/* Year selector */
.year-selector { margin-bottom: .75rem; font-size: .85rem; }
.year-selector select { margin-left: .3rem; }

/* Accordion */
.accordion-section { margin-bottom: .25rem; }
.accordion-header {
  width: 100%; text-align: left; background: var(--bg); border: none;
  padding: .5rem .6rem; border-radius: var(--radius); cursor: pointer;
  display: flex; justify-content: space-between; align-items: center;
  font-size: .85rem; font-weight: 600; color: var(--text); transition: background .15s;
}
.accordion-header:hover { background: var(--border); }
.cat-arrow { font-size: .7rem; color: var(--text-muted); }
.accordion-body { display: none; padding: .25rem 0 .25rem .5rem; }
.indicator-item {
  padding: .35rem .5rem; border-radius: 6px; cursor: pointer;
  transition: background .15s; display: flex; flex-direction: column;
  margin-bottom: .15rem;
}
.indicator-item:hover { background: var(--bg); }
.indicator-item.active { background: var(--primary); }
.indicator-item.active .ind-label, .indicator-item.active .ind-unit { color: #fff; }
.ind-label { font-size: .8rem; font-weight: 500; }
.ind-unit { font-size: .7rem; color: var(--text-muted); }

/* ─── Map Container ─── */
.map-container { flex: 1; position: relative; }
#map { width: 100%; height: 100%; }
.map-overlay-top {
  position: absolute; top: 10px; left: 50%; transform: translateX(-50%);
  z-index: 500; pointer-events: none;
}
.current-indicator-badge {
  background: rgba(255,255,255,.92); backdrop-filter: blur(4px);
  padding: .35rem .9rem; border-radius: 20px; font-size: .85rem;
  font-weight: 600; color: var(--primary); box-shadow: var(--shadow-md);
  white-space: nowrap; max-width: 500px; overflow: hidden; text-overflow: ellipsis;
}
.map-legend {
  position: absolute; bottom: 30px; left: 10px; background: rgba(255,255,255,.92);
  backdrop-filter: blur(4px); border-radius: var(--radius); padding: .6rem .8rem;
  z-index: 500; box-shadow: var(--shadow-md); min-width: 160px;
}
.legend-title { font-size: .75rem; font-weight: 700; margin-bottom: .4rem; color: var(--text-muted); }
.legend-gradient { display: flex; flex-direction: column; gap: .2rem; }
.legend-item { display: flex; align-items: center; gap: .4rem; font-size: .72rem; }
.legend-color { width: 14px; height: 14px; border-radius: 3px; flex-shrink: 0; }
.legend-note { font-size: .68rem; color: var(--text-muted); margin-top: .3rem; }
.map-source-badge {
  position: absolute; bottom: 8px; right: 10px; background: rgba(255,255,255,.8);
  font-size: .68rem; padding: .2rem .5rem; border-radius: 4px; color: var(--text-muted);
  z-index: 500;
}
.map-loading {
  position: absolute; inset: 0; background: rgba(255,255,255,.5);
  display: flex; align-items: center; justify-content: center; z-index: 600;
}
.spinner {
  width: 40px; height: 40px; border: 4px solid var(--border);
  border-top-color: var(--primary); border-radius: 50%; animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Tooltip carte */
.map-tooltip {
  position: fixed; background: rgba(30,41,59,.92); color: #fff;
  padding: .5rem .75rem; border-radius: var(--radius); font-size: .82rem;
  pointer-events: none; z-index: 9999; max-width: 250px; line-height: 1.5;
  display: none; box-shadow: var(--shadow-md);
}
.tooltip-bad { color: #fca5a5; }
.tooltip-good { color: #6ee7b7; }

/* ─── Page content ─── */
.page-content { max-width: 1200px; margin: 0 auto; padding: 2rem 1.5rem; }
.page-content h1 { font-size: 1.8rem; font-weight: 700; color: var(--primary); margin-bottom: .5rem; }
.page-subtitle { color: var(--text-muted); margin-bottom: 1.5rem; }

/* ─── Region Page ─── */
.region-page { max-width: 1200px; margin: 0 auto; padding: 1.5rem; }
.region-header { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.5rem; }
.region-header h1 { font-size: 2rem; font-weight: 800; color: var(--primary); }
.region-meta { display: flex; align-items: center; gap: .75rem; margin-left: auto; }
.btn-back { color: var(--text-muted); font-size: .9rem; white-space: nowrap; }

.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 1rem; margin-bottom: 2rem; }
.kpi-card {
  background: var(--surface); border-radius: var(--radius); padding: 1.25rem;
  box-shadow: var(--shadow); border-left: 4px solid var(--primary);
}
.kpi-label { font-size: .8rem; color: var(--text-muted); font-weight: 600; text-transform: uppercase; margin-bottom: .3rem; }
.kpi-value { font-size: 2rem; font-weight: 800; color: var(--text); }
.kpi-unit { font-size: .9rem; font-weight: 400; color: var(--text-muted); }
.kpi-vs { font-size: .8rem; font-weight: 600; margin-top: .2rem; }
.kpi-bad { color: var(--danger); }
.kpi-good { color: var(--success); }
.kpi-year { font-size: .72rem; color: var(--text-muted); }
.kpi-na { color: var(--text-muted); font-size: 1.5rem; }

.region-indicators h2 { font-size: 1.3rem; font-weight: 700; margin-bottom: 1rem; color: var(--text); }
.indicator-category { margin-bottom: 2rem; }
.cat-title { font-size: 1rem; font-weight: 700; color: var(--primary); padding: .5rem 0; border-bottom: 2px solid var(--primary); margin-bottom: .75rem; text-transform: capitalize; }

.indicator-table { width: 100%; border-collapse: collapse; background: var(--surface); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.indicator-table th { background: var(--bg); font-size: .8rem; text-transform: uppercase; color: var(--text-muted); padding: .6rem 1rem; text-align: left; border-bottom: 1px solid var(--border); }
.indicator-table td { padding: .6rem 1rem; border-bottom: 1px solid var(--border); font-size: .9rem; }
.indicator-table tr:last-child td { border-bottom: none; }
.indicator-table tr:hover { background: #f8fafc; }

.vs-badge { padding: .15rem .4rem; border-radius: 4px; font-size: .8rem; font-weight: 600; }
.vs-bad { background: #fee2e2; color: var(--danger); }
.vs-good { background: #d1fae5; color: #059669; }

.btn-chart-toggle { background: none; border: 1px solid var(--border); border-radius: 4px; padding: .2rem .4rem; cursor: pointer; font-size: .85rem; }
.btn-chart-toggle:hover { background: var(--bg); }
.chart-row td { padding: .5rem 1rem 1rem; }

.content-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 1rem; margin-top: 1rem; }
.content-card { background: var(--surface); border-radius: var(--radius); padding: 1.25rem; box-shadow: var(--shadow); }
.content-card h4 { font-size: 1rem; font-weight: 700; margin-bottom: .5rem; color: var(--primary); }
.content-desc { font-size: .85rem; color: var(--text-muted); margin-bottom: .75rem; }
.content-img { width: 100%; border-radius: var(--radius); }

/* ─── Admin Layout ─── */
.admin-layout { display: flex; min-height: 100vh; }
.admin-sidebar {
  width: 240px; background: var(--sidebar-bg); color: var(--sidebar-text);
  display: flex; flex-direction: column; position: fixed; top: 0; left: 0;
  height: 100vh; z-index: 100; overflow-y: auto;
}
.sidebar-logo {
  padding: 1.5rem 1.25rem 1rem;
  font-size: 1.4rem; font-weight: 800;
}
.sidebar-logo a { color: var(--primary-light); text-decoration: none; }
.sidebar-nav { display: flex; flex-direction: column; gap: .15rem; padding: .5rem .75rem; }
.sidebar-nav a {
  display: flex; align-items: center; gap: .6rem; padding: .6rem .75rem;
  border-radius: var(--radius); color: var(--sidebar-text); font-size: .9rem;
  transition: all .15s; font-weight: 500; text-decoration: none;
}
.sidebar-nav a:hover, .sidebar-nav a.active { background: var(--sidebar-active); color: #fff; }
.sidebar-nav hr { border: none; border-top: 1px solid rgba(255,255,255,.1); margin: .5rem 0; }

.admin-main { margin-left: 240px; flex: 1; padding: 1.5rem 2rem; background: var(--bg); min-height: 100vh; }
.admin-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1.5rem; }
.admin-header h1 { font-size: 1.6rem; font-weight: 800; color: var(--text); }
.admin-user { color: var(--text-muted); font-size: .9rem; }

.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 1rem; margin-bottom: 1.5rem; }
.stat-card { background: var(--surface); border-radius: var(--radius); padding: 1.25rem; box-shadow: var(--shadow); text-align: center; }
.stat-value { font-size: 2.2rem; font-weight: 800; color: var(--primary); }
.stat-label { font-size: .8rem; color: var(--text-muted); text-transform: uppercase; font-weight: 600; }

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

/* ─── Cards ─── */
.card { background: var(--surface); border-radius: var(--radius); padding: 1.5rem; box-shadow: var(--shadow); margin-bottom: 1.5rem; }
.card h3 { font-size: 1.05rem; font-weight: 700; margin-bottom: 1rem; color: var(--text); }
.card h4 { font-size: .95rem; font-weight: 600; margin-bottom: .75rem; color: var(--text); }

/* ─── Tables ─── */
.data-table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.data-table th { background: var(--bg); font-size: .78rem; text-transform: uppercase; color: var(--text-muted); padding: .6rem 1rem; text-align: left; border-bottom: 2px solid var(--border); font-weight: 700; white-space: nowrap; }
.data-table td { padding: .65rem 1rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover { background: #f8fafc; }
.data-table.compact td, .data-table.compact th { padding: .4rem .75rem; font-size: .82rem; }

/* ─── Buttons ─── */
.btn {
  display: inline-flex; align-items: center; gap: .35rem;
  padding: .45rem 1rem; border-radius: var(--radius); font-size: .9rem;
  font-weight: 600; cursor: pointer; border: none; transition: all .15s;
  text-decoration: none;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); text-decoration: none; color: #fff; }
.btn-outline { background: transparent; color: var(--primary); border: 1.5px solid var(--primary); }
.btn-outline:hover { background: var(--primary); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #dc2626; }
.btn-sm { padding: .25rem .6rem; font-size: .8rem; }
.btn-full { width: 100%; justify-content: center; }
.btn-edit { background: var(--bg); color: var(--text); border: 1.5px solid var(--border); }
.btn-edit:hover { background: var(--border); }
.btn:disabled { opacity: .6; cursor: not-allowed; }

/* ─── Forms ─── */
.form-group { margin-bottom: 1rem; }
.form-group label { display: block; font-size: .875rem; font-weight: 600; margin-bottom: .35rem; color: var(--text); }
.form-control {
  width: 100%; padding: .5rem .75rem; border: 1.5px solid var(--border);
  border-radius: var(--radius); font-size: .9rem; background: var(--surface);
  transition: border-color .15s; color: var(--text);
}
.form-control:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(15,107,101,.15); }
textarea.form-control { resize: vertical; }
.inline-form { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.inline-form input, .inline-form select { padding: .4rem .6rem; border: 1.5px solid var(--border); border-radius: var(--radius); font-size: .875rem; background: var(--surface); }
.checkbox-group { display: flex; align-items: center; gap: .5rem; }

/* ─── Badges ─── */
.badge { display: inline-block; padding: .15rem .5rem; border-radius: 20px; font-size: .75rem; font-weight: 600; }
.badge-level { background: var(--bg); color: var(--text-muted); }
.badge-admin { background: #fef3c7; color: #92400e; }
.badge-editor { background: #dbeafe; color: #1e40af; }
.badge-viewer { background: #f1f5f9; color: var(--text-muted); }
.badge-api_live { background: #d1fae5; color: #065f46; }
.badge-csv_auto { background: #dbeafe; color: #1e40af; }
.badge-manual { background: #fef3c7; color: #92400e; }

/* Status */
.status-ok { color: var(--success); font-weight: 700; }
.status-error { color: var(--danger); font-weight: 700; }
.status-pending { color: var(--warning); font-weight: 700; }

/* ─── Login ─── */
.login-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: linear-gradient(135deg, var(--primary-dark), var(--primary)); }
.login-card { background: var(--surface); border-radius: 12px; padding: 2.5rem; width: 100%; max-width: 420px; box-shadow: 0 20px 60px rgba(0,0,0,.2); }
.login-logo { text-align: center; margin-bottom: 1.5rem; }
.login-logo a { font-size: 2rem; font-weight: 800; color: var(--primary); }
.login-card h2 { text-align: center; margin-bottom: 1.5rem; color: var(--text); }
.login-form .form-group { margin-bottom: 1.25rem; }
.login-back { text-align: center; margin-top: 1rem; font-size: .875rem; color: var(--text-muted); }

/* ─── Alerts ─── */
.alert { padding: .75rem 1rem; border-radius: var(--radius); margin-bottom: 1rem; font-size: .9rem; font-weight: 500; transition: opacity .4s; }
.alert-error { background: #fee2e2; color: #991b1b; border: 1px solid #fca5a5; }
.alert-success { background: #d1fae5; color: #065f46; border: 1px solid #6ee7b7; }

/* ─── Editor ─── */
.editor-layout { display: grid; grid-template-columns: 400px 1fr; gap: 1.5rem; }
.editor-form { }
.editor-list { }
.content-list { list-style: none; display: flex; flex-direction: column; gap: .75rem; }
.content-list-item { background: var(--bg); border-radius: var(--radius); padding: .75rem; border: 1px solid var(--border); cursor: grab; }
.content-item-header { display: flex; align-items: center; gap: .5rem; margin-bottom: .25rem; }
.drag-handle { color: var(--text-muted); cursor: grab; font-size: 1.1rem; }
.content-type-badge { font-size: .7rem; padding: .1rem .4rem; border-radius: 4px; background: var(--surface); border: 1px solid var(--border); }
.content-public-badge { margin-left: auto; font-size: .9rem; }
.content-item-desc { font-size: .8rem; color: var(--text-muted); margin: .25rem 0 .5rem; }
.content-item-actions { display: flex; gap: .5rem; }

/* ─── ETL Toast ─── */
.etl-toast {
  position: fixed; bottom: 1.5rem; right: 1.5rem; z-index: 9999;
  background: var(--sidebar-bg); color: #fff; padding: .75rem 1.25rem;
  border-radius: var(--radius); font-size: .9rem; box-shadow: var(--shadow-md);
  opacity: 0; transform: translateY(10px); transition: all .3s;
}
.etl-toast.visible { opacity: 1; transform: translateY(0); }
.etl-toast-success { background: var(--success); }
.etl-toast-info { background: var(--sidebar-bg); }

/* ─── Misc ─── */
.text-muted { color: var(--text-muted); }
.text-danger { color: var(--danger); }
.actions { display: flex; gap: .4rem; flex-wrap: wrap; }
code { background: var(--bg); padding: .1rem .35rem; border-radius: 4px; font-size: .82rem; color: var(--primary-dark); }
hr { border: none; border-top: 1px solid var(--border); margin: 1rem 0; }
small { font-size: .78rem; color: var(--text-muted); }

/* Responsive */
@media (max-width: 768px) {
  .admin-sidebar { transform: translateX(-100%); }
  .admin-main { margin-left: 0; }
  .map-layout { flex-direction: column; }
  .side-panel { width: 100% !important; min-width: 100% !important; height: 200px; border-right: none; border-bottom: 1px solid var(--border); }
  .map-container { flex: 1; }
  .editor-layout { grid-template-columns: 1fr; }
  .dashboard-grid { grid-template-columns: 1fr; }
}
