/* ============================================================
   SDM WORKFLOW — GLOBAL STYLES
   Palette: deep forest dark + nature green accent + warm sand
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Playfair+Display:wght@400;600;700&family=DM+Sans:wght@300;400;500;600&family=DM+Mono:wght@400;500&display=swap');

/* ── CSS Variables ─────────────────────────────────────── */
:root {
  --bg-dark:       #0d1f1a;
  --bg-card:       #132318;
  --bg-card2:      #1a2e22;
  --accent-green:  #4ade80;
  --accent-green2: #22c55e;
  --accent-sand:   #e8d5a3;
  --accent-red:    #e05252;
  --text-primary:  #f0ede6;
  --text-muted:    #8faa96;
  --border:        #2a4030;
  --border-light:  #3a5540;
  --shadow:        0 4px 24px rgba(0,0,0,0.4);
  --radius:        10px;
  --radius-lg:     16px;
}

/* ── Reset & Base ──────────────────────────────────────── */
* { box-sizing: border-box; }

body {
  background-color: var(--bg-dark) !important;
  color: var(--text-primary) !important;
  font-family: 'DM Sans', sans-serif !important;
  font-weight: 400;
  margin: 0;
  min-height: 100vh;
}

/* ── Shiny container overrides ─────────────────────────── */
.container-fluid {
  padding: 0 !important;
}

/* ── LANDING PAGE ──────────────────────────────────────── */
.landing-page {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
}

.landing-bg {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse 80% 60% at 60% 40%, #1a4a2e 0%, transparent 60%),
    radial-gradient(ellipse 50% 40% at 20% 80%, #0a2e1a 0%, transparent 50%),
    radial-gradient(ellipse 60% 50% at 80% 10%, #0d2e20 0%, transparent 55%),
    linear-gradient(160deg, #061510 0%, #0d2218 40%, #071a10 100%);
  z-index: 0;
}

/* Organic floating shapes */
.landing-bg::before {
  content: '';
  position: absolute;
  width: 600px; height: 600px;
  border-radius: 40% 60% 70% 30% / 40% 50% 60% 50%;
  background: rgba(74, 222, 128, 0.04);
  top: -100px; right: -100px;
  animation: morph 12s ease-in-out infinite;
}
.landing-bg::after {
  content: '';
  position: absolute;
  width: 400px; height: 400px;
  border-radius: 60% 40% 30% 70% / 60% 30% 70% 40%;
  background: rgba(74, 222, 128, 0.03);
  bottom: -50px; left: -50px;
  animation: morph 16s ease-in-out infinite reverse;
}

@keyframes morph {
  0%,100% { border-radius: 40% 60% 70% 30% / 40% 50% 60% 50%; }
  33%      { border-radius: 70% 30% 50% 50% / 30% 60% 40% 70%; }
  66%      { border-radius: 30% 70% 30% 70% / 50% 40% 60% 30%; }
}

.landing-content {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.landing-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 28px 48px;
  border-bottom: 1px solid rgba(74,222,128,0.1);
}

.landing-logos {
  display: flex;
  align-items: center;
  gap: 32px;
}

.landing-logos img {
  height: 40px;
  filter: brightness(0) invert(1);
  opacity: 0.85;
  transition: opacity 0.2s;
}
.landing-logos img:first-child {
  height: 36px;
}
.landing-logos img:hover { opacity: 1; }

.landing-logos .logo-divider {
  width: 1px; height: 32px;
  background: var(--border-light);
}

.landing-badge {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--accent-green);
  border: 1px solid rgba(74,222,128,0.3);
  padding: 5px 12px;
  border-radius: 20px;
}

.landing-hero {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 80px 48px 60px;
  max-width: 800px;
}

.landing-eyebrow {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 3px;
  text-transform: uppercase;
  color: var(--accent-green);
  margin-bottom: 20px;
  opacity: 0;
  animation: fadeUp 0.6s ease forwards 0.2s;
}

.landing-title {
  font-family: 'Playfair Display', serif;
  font-size: clamp(42px, 6vw, 72px);
  font-weight: 700;
  line-height: 1.1;
  color: var(--text-primary);
  margin: 0 0 24px;
  opacity: 0;
  animation: fadeUp 0.7s ease forwards 0.4s;
}

.landing-title em {
  font-style: italic;
  color: var(--accent-green);
}

.landing-desc {
  font-size: 17px;
  line-height: 1.7;
  color: var(--text-muted);
  max-width: 560px;
  margin-bottom: 48px;
  opacity: 0;
  animation: fadeUp 0.7s ease forwards 0.6s;
}

.landing-steps-preview {
  display: flex;
  gap: 12px;
  margin-bottom: 48px;
  flex-wrap: wrap;
  opacity: 0;
  animation: fadeUp 0.7s ease forwards 0.7s;
}

.step-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(74,222,128,0.07);
  border: 1px solid rgba(74,222,128,0.15);
  border-radius: 20px;
  padding: 6px 14px;
  font-size: 13px;
  color: var(--text-muted);
}

.step-pill-num {
  width: 20px; height: 20px;
  border-radius: 50%;
  background: var(--accent-green);
  color: var(--bg-dark);
  font-size: 11px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}

.landing-cta {
  opacity: 0;
  animation: fadeUp 0.7s ease forwards 0.9s;
}

.btn-start {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  background: var(--accent-green);
  color: var(--bg-dark) !important;
  font-family: 'DM Sans', sans-serif !important;
  font-size: 15px !important;
  font-weight: 600 !important;
  padding: 14px 32px !important;
  border-radius: 50px !important;
  border: none !important;
  cursor: pointer;
  transition: all 0.25s ease;
  box-shadow: 0 0 0 0 rgba(74,222,128,0.4);
}

.btn-start:hover {
  background: var(--accent-green2) !important;
  transform: translateY(-2px);
  box-shadow: 0 8px 30px rgba(74,222,128,0.25), 0 0 0 0 rgba(74,222,128,0) !important;
}

.btn-start .arrow {
  transition: transform 0.2s;
}
.btn-start:hover .arrow { transform: translateX(4px); }

.landing-footer {
  padding: 24px 48px;
  border-top: 1px solid rgba(74,222,128,0.08);
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
  color: var(--text-muted);
}

/* ── APP SHELL (módulos) ───────────────────────────────── */
.app-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Top navbar */
.app-navbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 32px;
  height: 60px;
  background: rgba(13,31,26,0.95);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 1000;
  backdrop-filter: blur(10px);
}

.navbar-logos {
  display: flex;
  align-items: center;
  gap: 20px;
}

.navbar-logos img {
  height: 26px;
  filter: brightness(0) invert(1);
  opacity: 0.75;
}
.navbar-logos img:hover { opacity: 1; }

.navbar-logos .logo-sep {
  width: 1px; height: 22px;
  background: var(--border-light);
}

.navbar-brand {
  font-family: 'Playfair Display', serif;
  font-size: 15px;
  color: var(--text-primary);
  letter-spacing: 0.5px;
}

/* Step progress bar */
.step-progress {
  display: flex;
  align-items: center;
  gap: 0;
}

.step-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 14px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  transition: all 0.2s;
  white-space: nowrap;
}

.step-item.active {
  color: var(--accent-green);
  background: rgba(74,222,128,0.08);
}

.step-item.done {
  color: var(--accent-green2);
  opacity: 0.7;
}

.step-num {
  width: 22px; height: 22px;
  border-radius: 50%;
  border: 1.5px solid currentColor;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  flex-shrink: 0;
}

.step-item.active .step-num {
  background: var(--accent-green);
  border-color: var(--accent-green);
  color: var(--bg-dark);
}

.step-item.done .step-num {
  background: var(--accent-green2);
  border-color: var(--accent-green2);
  color: var(--bg-dark);
}

.step-connector {
  width: 20px;
  height: 1px;
  background: var(--border);
}

/* Main content area */
.app-body {
  flex: 1;
  padding: 32px;
  max-width: 1200px;
  width: 100%;
  margin: 0 auto;
}

/* ── MODULE CARD ───────────────────────────────────────── */
.module-header {
  margin-bottom: 28px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--border);
}

.module-eyebrow {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 2.5px;
  text-transform: uppercase;
  color: var(--accent-green);
  margin-bottom: 8px;
}

.module-title {
  font-family: 'Playfair Display', serif !important;
  font-size: 28px !important;
  font-weight: 600 !important;
  color: var(--text-primary) !important;
  margin: 0 0 8px !important;
}

.module-desc {
  font-size: 14px;
  color: var(--text-muted);
  line-height: 1.6;
  max-width: 600px;
  margin: 0;
}

/* Cards */
.sdm-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  margin-bottom: 20px;
  transition: border-color 0.2s;
}

.sdm-card:hover {
  border-color: var(--border-light);
}

.sdm-card-title {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 16px;
}

/* ── SHINY INPUTS OVERRIDE ─────────────────────────────── */
.form-control,
.selectize-input,
input[type="number"],
input[type="text"] {
  background: var(--bg-card2) !important;
  border: 1px solid var(--border) !important;
  color: var(--text-primary) !important;
  border-radius: 8px !important;
  font-family: 'DM Sans', sans-serif !important;
  transition: border-color 0.2s !important;
}

.form-control:focus,
.selectize-input.focus,
input[type="number"]:focus,
input[type="text"]:focus {
  border-color: var(--accent-green) !important;
  box-shadow: 0 0 0 3px rgba(74,222,128,0.1) !important;
  outline: none !important;
}

label, .control-label {
  color: var(--text-muted) !important;
  font-size: 13px !important;
  font-weight: 500 !important;
  letter-spacing: 0.3px;
}

/* Radio buttons */
.radio label, .checkbox label {
  color: var(--text-primary) !important;
  font-size: 14px !important;
}

/* ── BUTTONS ───────────────────────────────────────────── */
.btn-primary, .btn.btn-primary {
  background: var(--accent-green) !important;
  border: none !important;
  color: var(--bg-dark) !important;
  font-family: 'DM Sans', sans-serif !important;
  font-weight: 600 !important;
  border-radius: 8px !important;
  padding: 8px 20px !important;
  transition: all 0.2s !important;
}

.btn-primary:hover {
  background: var(--accent-green2) !important;
  transform: translateY(-1px);
  box-shadow: 0 4px 16px rgba(74,222,128,0.2) !important;
}

.btn-default, .btn.btn-default {
  background: var(--bg-card2) !important;
  border: 1px solid var(--border-light) !important;
  color: var(--text-primary) !important;
  font-family: 'DM Sans', sans-serif !important;
  font-weight: 500 !important;
  border-radius: 8px !important;
  padding: 8px 20px !important;
  transition: all 0.2s !important;
}

.btn-default:hover {
  border-color: var(--accent-green) !important;
  color: var(--accent-green) !important;
}

/* ── LEAFLET map container ─────────────────────────────── */
.leaflet-container {
  border-radius: var(--radius) !important;
  border: 1px solid var(--border) !important;
}

/* ── DT tables ─────────────────────────────────────────── */
.dataTables_wrapper {
  color: var(--text-primary) !important;
}

table.dataTable {
  background: var(--bg-card) !important;
  color: var(--text-primary) !important;
  border-collapse: collapse !important;
}

table.dataTable thead th {
  background: var(--bg-card2) !important;
  color: var(--text-muted) !important;
  border-bottom: 1px solid var(--border) !important;
  font-size: 12px !important;
  letter-spacing: 0.5px !important;
  text-transform: uppercase !important;
}

table.dataTable tbody tr {
  background: transparent !important;
}

table.dataTable tbody tr:hover td {
  background: rgba(74,222,128,0.05) !important;
}

table.dataTable tbody td {
  border-bottom: 1px solid var(--border) !important;
  font-family: 'DM Mono', monospace !important;
  font-size: 13px !important;
}

.dataTables_filter input,
.dataTables_length select {
  background: var(--bg-card2) !important;
  border: 1px solid var(--border) !important;
  color: var(--text-primary) !important;
  border-radius: 6px !important;
}

.dataTables_info,
.dataTables_paginate {
  color: var(--text-muted) !important;
  font-size: 12px !important;
}

.paginate_button {
  color: var(--text-muted) !important;
}

.paginate_button.current {
  background: var(--accent-green) !important;
  color: var(--bg-dark) !important;
  border-radius: 4px !important;
  border: none !important;
}

/* ── NOTIFICATIONS ─────────────────────────────────────── */
.shiny-notification {
  background: var(--bg-card2) !important;
  border: 1px solid var(--border-light) !important;
  color: var(--text-primary) !important;
  border-radius: var(--radius) !important;
  font-family: 'DM Sans', sans-serif !important;
}

/* ── PLOTS (ggplot background) ─────────────────────────── */
.shiny-plot-output {
  border-radius: var(--radius) !important;
  overflow: hidden;
}

/* ── HELPERS ───────────────────────────────────────────── */
hr {
  border-color: var(--border) !important;
  margin: 24px 0 !important;
}

h2, h3, h4 {
  font-family: 'Playfair Display', serif !important;
  color: var(--text-primary) !important;
}

h4 {
  font-size: 18px !important;
  font-weight: 600 !important;
  margin: 24px 0 12px !important;
}

.text-muted { color: var(--text-muted) !important; }

/* ── ANIMATIONS ────────────────────────────────────────── */
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(16px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.fade-in {
  animation: fadeIn 0.4s ease forwards;
}

/* fileInput override */
.input-group {
    display: flex !important;
    flex-direction: row !important;
    flex-wrap: nowrap !important;
    align-items: center !important;
    gap: 15px !important;
    width: 100% !important;
}

.input-group-btn {
    width: auto !important;
    display: block !important;
    margin: 0 !important;
}

.btn-file {
    height: 38px !important;
    display: flex !important;
    align-items: center !important;
    padding: 0 20px !important;
    margin: 0 !important;
}

.input-group .form-control {
    flex: 1 !important;
    height: 38px !important;
    margin: 0 !important;
    display: block !important;
}

/* 5. Hack para limpiar estilos de Bootstrap que estorban */
.input-group-btn:last-child>.btn,
.input-group-btn:last-child>.btn-group {
    margin-left: 0 !important;
}

/* conditional panel fade */
.shiny-bound-input { transition: opacity 0.2s; }

/* scrollbar */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg-dark); }
::-webkit-scrollbar-thumb { background: var(--border-light); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--accent-green); }

/* ============================================================
   SPACING, LOADER, LEAFLET Z-INDEX FIXES — v2
   ============================================================ */

/* ── Breathing room between all form elements ── */
.form-group          { margin-bottom: 18px !important; }
.shiny-input-container { margin-bottom: 18px !important; }
.sdm-card > *  + *   { margin-top: 16px; }

/* Spacing between action buttons */
.btn + .btn,
.action-button + .action-button { margin-left: 10px; }

/* Gap between sections/cards */
.sdm-card            { margin-bottom: 24px !important; }
.module-header        { margin-bottom: 32px !important; }
.sdm-row-gap > *     { margin-bottom: 20px; }

/* ── Leaflet z-index: keep navbar on top ── */
.leaflet-top,
.leaflet-bottom       { z-index: 400 !important; }   /* controls inside map */
.app-navbar           { z-index: 9000 !important; }  /* always above leaflet */

/* ── Map loader overlay ── */
.map-wrap {
  position: relative;
  border-radius: 10px;
  overflow: hidden;
}

.map-loader {
  position: absolute;
  inset: 0;
  background: rgba(13,31,26,0.82);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 500;
  border-radius: 10px;
  backdrop-filter: blur(4px);
  gap: 14px;
  pointer-events: none;
  transition: opacity 0.3s;
}

.map-loader.hidden { opacity: 0; pointer-events: none; }

.loader-spinner {
  width: 40px; height: 40px;
  border: 3px solid rgba(74,222,128,0.15);
  border-top-color: #4ade80;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.loader-text {
  font-size: 13px;
  color: #8faa96;
  font-family: 'DM Sans', sans-serif;
  letter-spacing: 0.5px;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ── Reset button (danger-subtle) ── */
.btn-reset {
  background: transparent !important;
  border: 1px solid rgba(224,82,82,0.35) !important;
  color: #e05252 !important;
  font-size: 13px !important;
  padding: 6px 14px !important;
  border-radius: 8px !important;
  transition: all 0.2s !important;
}

.btn-reset:hover {
  background: rgba(224,82,82,0.08) !important;
  border-color: #e05252 !important;
}

/* ── Probability threshold section (Markov) ── */
.threshold-panel {
  background: var(--bg-card2);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  padding: 24px;
  margin-top: 24px;
}

.threshold-panel .tp-title {
  font-family: 'Playfair Display', serif;
  font-size: 18px;
  color: var(--text-primary);
  margin: 0 0 6px;
}

.threshold-panel .tp-desc {
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.6;
  margin-bottom: 20px;
}

.threshold-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
}

.threshold-badge.presence {
  background: rgba(74,222,128,0.12);
  border: 1px solid rgba(74,222,128,0.25);
  color: #4ade80;
}

.threshold-badge.absence {
  background: rgba(224,82,82,0.1);
  border: 1px solid rgba(224,82,82,0.25);
  color: #e05252;
}

.summary-counts {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  margin-top: 16px;
}

.count-box {
  flex: 1;
  min-width: 120px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  text-align: center;
}

.count-box .count-num {
  font-family: 'DM Mono', monospace;
  font-size: 26px;
  font-weight: 500;
  line-height: 1;
  margin-bottom: 4px;
}

.count-box .count-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-muted);
}

.count-box.presence .count-num { color: #4ade80; }
.count-box.absence  .count-num { color: #e05252; }
.count-box.total    .count-num { color: var(--accent-sand); }