/* ============================================================
   Sistema Cooperativa — CSS v2.1
   Fuentes: IBM Plex Sans + IBM Plex Mono
   Paleta: Identidad COOPFUNA LTDA — verde institucional + dorado
           (derivada del logo oficial) + rojo semáforo accesible
   ============================================================ */

:root {
  /* ---- Superficies / fondos ---- */
  --bg:         #eef3ec;   /* gris muy claro con matiz verde */
  --surface:    #ffffff;
  --surface-2:  #f3f7f1;   /* tinte verde claro (headers de card, th) */
  --border:     #dce6da;   /* borde con matiz verde */

  /* ---- Texto ---- */
  --text:       #14241a;   /* verde-carbón muy oscuro */
  --text-muted: #5d6b60;   /* verde-gris atenuado */

  /* ---- Primario: verde institucional (AA sobre blanco, 4.5:1) ---- */
  --accent:     #15803d;
  --accent-h:   #166534;
  --accent-lt:  #e7f5ec;

  /* ---- Marca secundaria: verde hoja (lima) + dorado del logo ---- */
  --brand-green-deep: #14532d;  /* verde bosque (sidebar / login) */
  --lime:       #4d7c0f;        /* verde hoja oscuro (AA en botón) */
  --lime-lt:    #f0fbe2;
  --gold:       #f59e0b;        /* dorado "ltda." / círculos del logo */
  --gold-h:     #d97706;
  --gold-lt:    #fff8e7;

  /* ---- Estados semáforo ---- */
  --success:    #16a34a;
  --success-lt: #f0fdf4;
  --warning:    #b45309;   /* ámbar accesible (texto sobre claro) */
  --warning-lt: #fffbeb;
  --danger:     #dc2626;   /* rojo: se mantiene por convención/accesibilidad */
  --danger-lt:  #fef2f2;

  /* ---- Navegación (sidebar verde) ---- */
  --nav-bg:     #14532d;
  --nav-bg-2:   #166534;
  --nav-text:   #bcd6c1;
  --nav-active: #ffffff;

  /* ---- Otros ---- */
  --radius:     6px;
  --radius-lg:  10px;
  --shadow:     0 1px 3px rgba(20,40,26,.08), 0 1px 2px rgba(20,40,26,.04);
  --shadow-md:  0 6px 18px rgba(20,40,26,.12), 0 2px 6px rgba(20,40,26,.06);
  --font:       'IBM Plex Sans', sans-serif;
  --mono:       'IBM Plex Mono', monospace;
  --nav-w:      220px;
  --transition: .15s ease;
  --focus-ring: 0 0 0 3px rgba(21,128,61,.18);
}

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

html { font-size: 15px; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}

/* ---- NAVBAR ------------------------------------------------ */

.navbar {
  position: fixed;
  top: 0; left: 0;
  width: var(--nav-w);
  height: 100vh;
  background: linear-gradient(180deg, var(--nav-bg) 0%, var(--nav-bg-2) 100%);
  display: flex;
  flex-direction: column;
  padding: 0;
  z-index: 100;
  overflow-y: auto;
}

.navbar-brand {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .5rem;
  color: #fff;
  text-decoration: none;
  font-weight: 600;
  font-size: .95rem;
  padding: 1rem 1rem .9rem;
  border-bottom: 1px solid rgba(255,255,255,.10);
}

.navbar-brand img {
  display: block;
  width: 100%;
  max-width: 168px;
  height: auto;
  border-radius: 8px;
  box-shadow: 0 2px 6px rgba(0,0,0,.18);
}

.navbar-brand i { color: var(--gold); font-size: 1.1rem; }

.navbar-nav {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: .75rem 0;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: .625rem;
  color: var(--nav-text);
  text-decoration: none;
  font-size: .875rem;
  padding: .55rem 1.25rem;
  transition: background var(--transition), color var(--transition);
  border-left: 3px solid transparent;
}

.nav-link i { width: 1rem; text-align: center; font-size: .875rem; }
.nav-link:hover  { background: rgba(255,255,255,.08); color: #fff; }
.nav-link.active { background: rgba(255,255,255,.10); color: var(--nav-active); border-left-color: var(--gold); }

.navbar-user {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: 1rem 1.25rem;
  border-top: 1px solid rgba(255,255,255,.08);
  font-size: .8rem;
  color: var(--nav-text);
  flex-wrap: wrap;
}

.btn-logout {
  color: var(--nav-text);
  text-decoration: none;
  margin-left: auto;
  font-size: 1rem;
  transition: color var(--transition);
}
.btn-logout:hover { color: var(--danger); }

/* ---- MAIN CONTENT ----------------------------------------- */

.main-content {
  margin-left: var(--nav-w);
  min-height: 100vh;
  padding: 2rem;
}

.main-content.no-nav { margin-left: 0; }

/* ---- PAGE HEADER ------------------------------------------ */

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.5rem;
  gap: 1rem;
  flex-wrap: wrap;
}

.page-title {
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--text);
}

.page-title small {
  display: block;
  font-size: .8rem;
  font-weight: 400;
  color: var(--text-muted);
  margin-top: .1rem;
}

/* ---- CARDS ------------------------------------------------ */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  font-size: .9rem;
  background: var(--surface-2);
  gap: .75rem;
}

.card-body { padding: 1.25rem; }

/* ---- STAT CARDS ------------------------------------------- */

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: .4rem;
}

.stat-label {
  font-size: .75rem;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--text-muted);
  font-weight: 500;
}

.stat-value {
  font-size: 1.65rem;
  font-weight: 600;
  line-height: 1;
  font-family: var(--mono);
}

.stat-sub {
  font-size: .78rem;
  color: var(--text-muted);
}

.stat-icon {
  width: 2.25rem;
  height: 2.25rem;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .9rem;
  margin-bottom: .25rem;
}

.icon-blue   { background: var(--accent-lt); color: var(--accent); }
.icon-green  { background: var(--success-lt); color: var(--success); }
.icon-red    { background: var(--danger-lt);  color: var(--danger); }
.icon-yellow { background: var(--warning-lt); color: var(--warning); }

/* ---- TABLA ------------------------------------------------ */

.table-wrap { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: .875rem;
}

th {
  text-align: left;
  padding: .6rem .875rem;
  font-size: .75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--text-muted);
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

td {
  padding: .65rem .875rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--accent-lt); }

.money {
  font-family: var(--mono);
  font-size: .84rem;
  white-space: nowrap;
  text-align: right;
}

.text-right { text-align: right; }
.text-center { text-align: center; }

/* ---- BADGES ----------------------------------------------- */

.badge {
  display: inline-flex;
  align-items: center;
  padding: .2rem .55rem;
  border-radius: 99px;
  font-size: .72rem;
  font-weight: 600;
  letter-spacing: .02em;
  white-space: nowrap;
}

.badge-success  { background: var(--success-lt); color: var(--success); }
.badge-warning  { background: var(--warning-lt); color: var(--warning); }
.badge-danger   { background: var(--danger-lt);  color: var(--danger);  }
.badge-info     { background: var(--accent-lt);  color: var(--accent);  }
.badge-muted    { background: #f1f5f9;            color: var(--text-muted); }
.badge-admin    { background: #1e1b4b; color: #a5b4fc; }
.badge-operador { background: #0c4a6e; color: #7dd3fc; }
.badge-consulta { background: #f0fdf4; color: #15803d; }

/* ---- BOTONES ---------------------------------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  padding: .45rem .9rem;
  border-radius: var(--radius);
  font-size: .875rem;
  font-weight: 500;
  font-family: var(--font);
  cursor: pointer;
  border: 1px solid transparent;
  text-decoration: none;
  transition: background var(--transition), border-color var(--transition), box-shadow var(--transition);
  white-space: nowrap;
}

.btn-primary  { background: var(--accent);  color: #fff; }
.btn-primary:hover { background: var(--accent-h); }

.btn-success  { background: var(--success); color: #fff; }
.btn-success:hover { background: #15803d; }

.btn-danger   { background: var(--danger);  color: #fff; }
.btn-danger:hover  { background: #b91c1c; }

.btn-outline  {
  background: transparent;
  color: var(--accent);
  border-color: var(--accent);
}
.btn-outline:hover { background: var(--accent-lt); }

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border-color: var(--border);
}
.btn-ghost:hover { background: var(--surface-2); }

/* Secundario: verde hoja */
.btn-secondary { background: var(--lime); color: #fff; }
.btn-secondary:hover { background: #3f6212; }

/* Acento dorado del logo (CTA "asociarse"). Texto verde oscuro = AA sobre dorado */
.btn-warning { background: var(--gold); color: var(--brand-green-deep); font-weight: 600; }
.btn-warning:hover { background: var(--gold-h); color: var(--brand-green-deep); }

.btn-sm  { padding: .3rem .65rem; font-size: .8rem; }
.btn-block { width: 100%; justify-content: center; }

/* ---- FORMULARIOS ------------------------------------------ */

.form-group { margin-bottom: 1rem; }

.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 1rem;
}

label {
  display: block;
  font-size: .82rem;
  font-weight: 500;
  margin-bottom: .35rem;
  color: var(--text);
}

input, select, textarea {
  width: 100%;
  padding: .5rem .75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: var(--font);
  font-size: .875rem;
  background: var(--surface);
  color: var(--text);
  transition: border-color var(--transition), box-shadow var(--transition);
  appearance: none;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: var(--focus-ring);
}

input[readonly] { background: var(--surface-2); color: var(--text-muted); }
textarea { resize: vertical; min-height: 80px; }

.form-hint {
  font-size: .77rem;
  color: var(--text-muted);
  margin-top: .25rem;
}

.form-actions {
  display: flex;
  gap: .75rem;
  margin-top: 1.5rem;
  flex-wrap: wrap;
}

/* ---- ALERTAS ---------------------------------------------- */

.alert {
  display: flex;
  align-items: flex-start;
  gap: .6rem;
  padding: .75rem 1rem;
  border-radius: var(--radius);
  font-size: .875rem;
  margin-bottom: 1rem;
  border: 1px solid transparent;
  position: relative;
}

.alert-success { background: var(--success-lt); color: #166534; border-color: #bbf7d0; }
.alert-error   { background: var(--danger-lt);  color: #991b1b; border-color: #fecaca; }
.alert-warning { background: var(--warning-lt); color: #92400e; border-color: #fde68a; }

.alert-close {
  background: none; border: none; cursor: pointer;
  position: absolute; right: .75rem; top: .5rem;
  font-size: 1.1rem; opacity: .5; color: inherit;
}
.alert-close:hover { opacity: 1; }

/* ---- PROGRESS BAR ----------------------------------------- */

.progress {
  height: 6px;
  background: var(--border);
  border-radius: 99px;
  overflow: hidden;
}
.progress-bar {
  height: 100%;
  border-radius: 99px;
  background: var(--accent);
  transition: width .4s ease;
}
.progress-bar.success { background: var(--success); }
.progress-bar.danger  { background: var(--danger); }

/* ---- ESTADO BADGE HELPERS --------------------------------- */

.estado-PENDIENTE   { }
.estado-CONCILIACION { }
.estado-CERRADO     { }

/* ---- LOGIN PAGE ------------------------------------------- */

.login-page {
  background: var(--nav-bg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 1rem;
}

.login-wrap { width: 100%; max-width: 400px; }

.login-card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 2rem;
  box-shadow: var(--shadow-md);
  border-top: 4px solid var(--gold);
}

.login-header {
  text-align: center;
  margin-bottom: 1.75rem;
}

.login-logo {
  margin-bottom: .85rem;
}
.login-logo img {
  display: block;
  width: 100%;
  max-width: 240px;
  height: auto;
  margin: 0 auto;
  border-radius: 10px;
  box-shadow: var(--shadow);
}

.login-header h1 {
  font-size: 1.35rem;
  font-weight: 600;
  margin-top: .75rem;
}

.login-header p {
  color: var(--text-muted);
  font-size: .85rem;
  margin-top: .25rem;
}

.login-footer {
  text-align: center;
  color: rgba(255,255,255,.3);
  font-size: .75rem;
  margin-top: 1rem;
}

.login-divider {
  display: flex;
  align-items: center;
  text-align: center;
  margin: 1.25rem 0 1rem;
  color: var(--text-muted);
  font-size: .8rem;
}
.login-divider::before,
.login-divider::after {
  content: '';
  flex: 1;
  border-bottom: 1px solid var(--border);
}
.login-divider span { padding: 0 .65rem; }

/* ---- PUBLIC LAYOUT (form de solicitud público) ----------- */

.public-page {
  background: linear-gradient(180deg, #f3f4f6 0%, #e5e7eb 100%);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.public-header {
  background: var(--nav-bg, #166534);
  color: #fff;
  padding: .85rem 1rem;
  box-shadow: 0 2px 8px rgba(0,0,0,.08);
}
.public-header-inner {
  max-width: 1100px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}
.public-brand {
  display: flex;
  align-items: center;
  gap: .75rem;
}
.public-brand i {
  font-size: 1.5rem;
}
.public-brand img {
  height: 42px;
  width: auto;
  display: block;
  border-radius: 7px;
  box-shadow: 0 2px 6px rgba(0,0,0,.18);
}
.public-brand-name { font-weight: 700; font-size: 1rem; line-height: 1.15; }
.public-brand-sub  { font-size: .72rem; opacity: .85; }

.public-main {
  flex: 1;
  padding: 1.5rem 1rem;
  max-width: 1100px;
  width: 100%;
  margin: 0 auto;
}

.public-flash-wrap { max-width: 900px; margin: 0 auto 1rem; }

.public-footer {
  text-align: center;
  padding: 1rem;
  color: var(--text-muted);
  background: var(--surface, #fff);
  border-top: 1px solid var(--border, #e5e7eb);
}

.public-page .btn-ghost {
  background: rgba(255,255,255,.15);
  color: #fff;
  border: 1px solid rgba(255,255,255,.3);
}
.public-page .public-header .btn-ghost:hover {
  background: rgba(255,255,255,.25);
}

/* ---- MODAL ------------------------------------------------ */

.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 200;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.modal-overlay.open { display: flex; }

.modal {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  width: 100%;
  max-width: 680px;
  max-height: 90vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
}

.modal-body    { padding: 1.25rem; flex: 1; }
.modal-footer  { padding: 1rem 1.25rem; border-top: 1px solid var(--border); display: flex; gap: .75rem; justify-content: flex-end; }

.btn-modal-close {
  background: none; border: none; cursor: pointer;
  font-size: 1.1rem; color: var(--text-muted);
  transition: color var(--transition);
}
.btn-modal-close:hover { color: var(--danger); }

/* ---- LOADING --------------------------------------------- */

.loading-overlay {
  position: fixed; inset: 0;
  background: rgba(255,255,255,.65);
  z-index: 999;
  display: flex;
  align-items: center;
  justify-content: center;
}

.spinner {
  width: 36px; height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}

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

/* ---- SEARCH BAR ------------------------------------------ */

.search-bar {
  display: flex;
  gap: .5rem;
  align-items: center;
  flex-wrap: wrap;
}

.search-bar input {
  max-width: 280px;
}

/* ---- GRID UTILITARIOS ------------------------------------ */

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; }
.flex   { display: flex; gap: .75rem; align-items: center; flex-wrap: wrap; }
.ml-auto { margin-left: auto; }
.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; }

/* ---- CUOTA ROWS ------------------------------------------ */
.cuota-PAGADA      td { color: var(--text-muted); }
.cuota-EN_MORA     td:first-child { border-left: 3px solid var(--danger); }
.cuota-VENCIDA     td:first-child { border-left: 3px solid var(--warning); }
.cuota-PENDIENTE   td:first-child { border-left: 3px solid var(--border); }

/* ---- RESPONSIVE ------------------------------------------ */

@media (max-width: 768px) {
  :root { --nav-w: 0px; }
  .navbar {
    position: static;
    width: 100%;
    height: auto;
    flex-direction: row;
    flex-wrap: wrap;
  }
  .navbar-nav {
    flex-direction: row;
    flex-wrap: wrap;
    gap: 0;
    padding: .25rem;
  }
  .main-content { margin-left: 0; padding: 1rem; }
  .stats-grid   { grid-template-columns: 1fr 1fr; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
}
