/* =====================================================
   BASE.CSS — Paleta de Obra (modo claro, alta visibilidad)
   =====================================================
   Diseñado para legibilidad bajo sol caribeño, pantallas
   sucias, y reflejos típicos de uso en exteriores.

   Inspiración visual:
   - Planos de ingeniería (blueprint blue #0F172A)
   - Maquinaria pesada (Caterpillar yellow #EAB308)
   - Materiales base (gris cemento #F8FAFC)

   Reglas de oro:
   - Modo claro por default. Dark NO es opción para obra.
   - Tipografía bold (500+ base, 700 para títulos).
   - Contraste WCAG AA mínimo en todo texto crítico.
   - Cero glass / blur que se pierde bajo sol directo.
   - Shadows sutiles + borders nítidos para definición.
   ===================================================== */

:root {
  /* ===== FONDOS — gris cemento, NO blanco puro ===== */
  --bg: #F8FAFC;              /* Fondo base — gris cemento suave */
  --bg-elev: #FFFFFF;          /* Cards, modals, surfaces elevadas */
  --bg-soft: #F1F5F9;          /* Hover de inputs, secciones secundarias */
  --bg-input: #FFFFFF;
  --bg-input-hover: #F8FAFC;

  /* ===== TEXTO — azul plano profundo dominante ===== */
  --text: #0F172A;             /* Azul plano (blueprint) — títulos y montos */
  --text2: #334155;            /* Gris acero — texto secundario importante */
  --text3: #64748B;            /* Gris acero claro — meta, fechas, códigos */
  --text-soft: #94A3B8;        /* Placeholders, deshabilitado */

  /* ===== BORDERS — gris cemento medio ===== */
  --border: #E2E8F0;           /* Border default — cards, inputs */
  --border-strong: #CBD5E1;    /* Border más visible para énfasis */
  --border-hover: #94A3B8;     /* Hover de inputs */

  /* ===== ACENTOS — paleta de obra ===== */
  --amber: #EAB308;            /* Amarillo Caterpillar — acciones primarias */
  --amber-deep: #CA8A04;       /* Amarillo más oscuro para hover */
  --amber-soft: #FEF3C7;       /* Background suave para alerts amber */
  --amber-glow: rgba(234, 179, 8, 0.25);

  --orange: #EA580C;           /* Naranja vial — acciones críticas alternas */
  --orange-soft: #FFEDD5;

  --red: #DC2626;              /* Rojo seguridad — alertas críticas */
  --red-soft: #FEE2E2;
  --red-deep: #991B1B;

  --green: #15803D;            /* Verde aprobado — confirmaciones */
  --green-soft: #DCFCE7;
  --green-deep: #14532D;

  --blue: #0F172A;             /* Azul plano (mismo que text para coherencia) */

  /* ===== BRAND (override por org via JS si quieren branding propio) ===== */
  --brand-primary: var(--amber);
  --brand-text: var(--text);

  /* ===== RADIUS + TIPOGRAFÍA ===== */
  --r: 12px;                   /* Radius default — cards, inputs, botones */
  --r-sm: 8px;                 /* Botones secundarios, badges */
  --r-lg: 16px;                /* Modals, large cards */
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, monospace;

  /* ===== SHADOWS — sutiles pero presentes ===== */
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow: 0 2px 4px rgba(15, 23, 42, 0.06), 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow-md: 0 4px 8px rgba(15, 23, 42, 0.06), 0 2px 4px rgba(15, 23, 42, 0.04);
  --shadow-lg: 0 12px 24px rgba(15, 23, 42, 0.08), 0 4px 8px rgba(15, 23, 42, 0.04);
  --shadow-amber: 0 4px 12px rgba(234, 179, 8, 0.3), 0 1px 2px rgba(234, 179, 8, 0.2);

  /* ===== SPACING ===== */
  --sp1: 4px;
  --sp2: 8px;
  --sp3: 12px;
  --sp4: 16px;
  --sp5: 24px;
  --sp6: 32px;
  --sp7: 48px;
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }
html { background: var(--bg); }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  font-size: 15px;
  font-weight: 500;            /* BOLD por default para legibilidad en obra */
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  position: relative;
}

/* =====================================================
   TIPOGRAFÍA — bold dominante, jerarquía clara
   ===================================================== */
h1, h2, h3, h4 {
  font-weight: 700;
  color: var(--text);
  margin: 0 0 var(--sp3);
  letter-spacing: -0.02em;
}
h1 { font-size: 28px; line-height: 1.15; }
h2 { font-size: 20px; line-height: 1.2; }
h3 {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text3);
  font-weight: 700;
}
h4 { font-size: 14px; font-weight: 600; }

a {
  color: var(--text);
  text-decoration: underline;
  text-decoration-color: var(--amber);
  text-decoration-thickness: 2px;
  text-underline-offset: 3px;
  transition: opacity 0.15s;
  font-weight: 600;
}
a:hover { opacity: 0.75; }

.muted { color: var(--text3); font-weight: 500; }
.mono { font-family: var(--mono); font-weight: 600; }
.text-sm { font-size: 13px; }
.text-xs { font-size: 11px; }
.text-bold { font-weight: 700; }

/* Códigos de proyecto / referencias en mono */
.code-ref {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text2);
  background: var(--bg-soft);
  padding: 2px 7px;
  border-radius: 4px;
  font-weight: 600;
  letter-spacing: 0.02em;
}

/* =====================================================
   INPUTS — blanco con border fuerte, focus amarillo
   ===================================================== */
input:not([type=checkbox]):not([type=radio]),
select,
textarea {
  font-family: var(--font);
  font-size: 15px;
  font-weight: 500;
  background: var(--bg-input);
  color: var(--text);
  border: 1.5px solid var(--border-strong);
  border-radius: var(--r-sm);
  padding: 11px 14px;
  width: 100%;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
  transition: border-color 0.12s, box-shadow 0.12s, background 0.12s;
}
input:hover:not(:focus), select:hover:not(:focus), textarea:hover:not(:focus) {
  border-color: var(--border-hover);
}
input:focus, select:focus, textarea:focus {
  border-color: var(--amber);
  box-shadow: 0 0 0 3px var(--amber-glow);
}
input::placeholder, textarea::placeholder {
  color: var(--text-soft);
  font-weight: 500;
}

/* =====================================================
   FIELDS
   ===================================================== */
.field {
  display: flex;
  flex-direction: column;
  gap: 7px;
  margin-bottom: var(--sp4);
}
.field:last-child { margin-bottom: 0; }

.lbl {
  font-size: 11px;
  font-weight: 700;
  color: var(--text2);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.grid2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.grid2 .field { margin-bottom: 0; }

/* =====================================================
   BUTTONS — primarios amarillo Caterpillar, texto azul plano
   Acción visible incluso con pantalla sucia.
   ===================================================== */
.btn {
  font-family: var(--font);
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.01em;
  padding: 12px 18px;
  border-radius: var(--r-sm);
  border: 1.5px solid var(--border-strong);
  background: var(--bg-elev);
  color: var(--text);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  transition: all 0.12s ease;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
  min-height: 44px;            /* Apple HIG mínimo touch */
}
.btn:hover {
  background: var(--bg-soft);
  border-color: var(--border-hover);
}
.btn:active { transform: scale(0.98); }
.btn[disabled] {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
}

/* Primario — Amarillo Caterpillar con texto azul plano */
.btn-primary {
  background: var(--amber);
  color: var(--text);
  border-color: var(--amber);
  box-shadow: var(--shadow-amber);
}
.btn-primary:hover {
  background: var(--amber);
  border-color: var(--amber-deep);
  box-shadow: 0 6px 16px rgba(234, 179, 8, 0.4), 0 2px 4px rgba(234, 179, 8, 0.2);
  transform: translateY(-1px);
}
.btn-primary:active {
  transform: translateY(0) scale(0.98);
  box-shadow: 0 2px 4px rgba(234, 179, 8, 0.25);
}

/* Naranja vial — alternativa de acción crítica */
.btn-orange {
  background: var(--orange);
  color: #FFFFFF;
  border-color: var(--orange);
  box-shadow: 0 4px 12px rgba(234, 88, 12, 0.3);
}
.btn-orange:hover {
  background: #C2410C;
  border-color: #C2410C;
}

/* Verde — confirmaciones (aprobar, guardar) */
.btn-green {
  background: var(--green);
  color: #FFFFFF;
  border-color: var(--green);
  box-shadow: 0 4px 12px rgba(21, 128, 61, 0.25);
}
.btn-green:hover {
  background: var(--green-deep);
  border-color: var(--green-deep);
}

/* Rojo — acciones destructivas */
.btn-red {
  background: var(--bg-elev);
  color: var(--red);
  border-color: var(--red);
}
.btn-red:hover {
  background: var(--red-soft);
}

.btn-ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--text2);
}
.btn-ghost:hover {
  background: var(--bg-soft);
  color: var(--text);
}

/* Botón flotante (FAB) — para "Añadir gasto rápido" en obra */
.btn-fab {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: var(--amber);
  border: 0;
  color: var(--text);
  box-shadow: 0 8px 24px rgba(234, 179, 8, 0.4), 0 2px 6px rgba(0, 0, 0, 0.15);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 30;
  transition: all 0.15s ease;
}
.btn-fab:hover {
  transform: scale(1.08);
  box-shadow: 0 12px 32px rgba(234, 179, 8, 0.5), 0 4px 8px rgba(0, 0, 0, 0.18);
}
.btn-fab:active { transform: scale(0.95); }

.ibtn {
  width: 44px;
  height: 44px;
  border-radius: var(--r-sm);
  background: var(--bg-elev);
  border: 1.5px solid var(--border);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  color: var(--text);
  user-select: none;
  transition: all 0.12s ease;
}
.ibtn:hover {
  background: var(--bg-soft);
  border-color: var(--border-strong);
}

/* =====================================================
   CARDS — blanco con border + shadow sutil
   ===================================================== */
.card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 16px 18px;
  box-shadow: var(--shadow-sm);
  transition: all 0.15s ease;
}
.card-interactive {
  cursor: pointer;
}
.card-interactive:hover {
  border-color: var(--border-strong);
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

/* Card con accent amarillo a la izquierda — para destacar */
.card-accent {
  border-left: 4px solid var(--amber);
}
.card-accent-red { border-left: 4px solid var(--red); }
.card-accent-green { border-left: 4px solid var(--green); }

.section-label {
  font-size: 11px;
  font-weight: 700;
  color: var(--text3);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  padding: 6px 4px 8px;
  margin-top: 4px;
}

/* =====================================================
   ALERTS — semánticos por color
   ===================================================== */
.alert {
  padding: 12px 14px;
  border-radius: var(--r-sm);
  font-size: 13px;
  font-weight: 600;
  line-height: 1.5;
  border: 1px solid;
  display: flex;
  align-items: flex-start;
  gap: 10px;
}
.alert-red {
  background: var(--red-soft);
  border-color: rgba(220, 38, 38, 0.35);
  color: var(--red-deep);
}
.alert-green {
  background: var(--green-soft);
  border-color: rgba(21, 128, 61, 0.35);
  color: var(--green-deep);
}
.alert-amber {
  background: var(--amber-soft);
  border-color: rgba(234, 179, 8, 0.45);
  color: #854D0E;
}
.alert-blue {
  background: #DBEAFE;
  border-color: rgba(59, 130, 246, 0.35);
  color: #1E40AF;
}

/* =====================================================
   BADGES — para estado de factura, status de obra
   ===================================================== */
.badge {
  display: inline-flex;
  align-items: center;
  font-size: 11px;
  font-weight: 700;
  padding: 3px 9px;
  border-radius: 100px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border: 1px solid;
}
.badge-amber { background: var(--amber-soft); color: #854D0E; border-color: rgba(234, 179, 8, 0.4); }
.badge-green { background: var(--green-soft); color: var(--green-deep); border-color: rgba(21, 128, 61, 0.3); }
.badge-red { background: var(--red-soft); color: var(--red-deep); border-color: rgba(220, 38, 38, 0.3); }
.badge-gray { background: var(--bg-soft); color: var(--text2); border-color: var(--border); }

/* =====================================================
   TOAST + LOADING + MODAL
   ===================================================== */
#toast {
  position: fixed;
  bottom: 34px;
  left: 50%;
  transform: translateX(-50%) translateY(12px);
  background: var(--text);          /* Fondo azul plano para alto contraste */
  color: #FFFFFF;
  padding: 12px 22px;
  border-radius: 100px;
  font-size: 13px;
  font-weight: 600;
  opacity: 0;
  transition: all 0.25s ease;
  z-index: 100;
  box-shadow: 0 12px 32px rgba(15, 23, 42, 0.25);
  max-width: 88vw;
  text-align: center;
  pointer-events: none;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.err { background: var(--red); }
#toast.ok { background: var(--green); }

#loader {
  background: rgba(248, 250, 252, 0.92);
  position: fixed;
  inset: 0;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  padding: 40px;
  z-index: 50;
}
#loader.show { display: flex; }
.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--amber);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.modal-bg {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.4);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 80;
  padding: 16px;
}
.modal-bg.show { display: flex; }
.modal {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 24px;
  width: 100%;
  max-width: 420px;
  max-height: 85vh;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  box-shadow: var(--shadow-lg);
}

/* =====================================================
   UTILS
   ===================================================== */
.hidden { display: none !important; }
.flex { display: flex; }
.flex-col { flex-direction: column; }
.flex-1 { flex: 1; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.gap-4 { gap: 16px; }
.mt-2 { margin-top: 8px; }
.mt-3 { margin-top: 12px; }
.mt-4 { margin-top: 16px; }
.center { text-align: center; }

/* Highlight para mostrar montos importantes en azul plano bold */
.amount {
  font-family: var(--mono);
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.01em;
}
.amount-lg { font-size: 24px; }
.amount-positive { color: var(--green); }
.amount-negative { color: var(--red); }
