@import url('https://fonts.googleapis.com/css2?family=Sora:wght@600;700&family=Plus+Jakarta+Sans:wght@400;500;600;700&display=swap');

/* ── Tokens ──────────────────────────────────────────────────────────────────── */
:root {
  /* Marca */
  --rojo:        #C9040B;
  --rojo-osc:    #8F0307;
  --rojo-lite:   #FDECED;
  --rojo-line:   #F0C8CA;
  --rojo-alt:    #FEF6F4;
  --verde:       #27A645;
  --verde-bg:    #E6F7EC;

  /* Semáforo financiero */
  --success:     #27A645;
  --success-bg:  #E6F7EC;
  --warning:     #CC8008;
  --warning-bg:  #FDF3E3;
  --danger:      #C9040B;
  --danger-bg:   #FDECED;

  /* Neutros */
  --ink:         #1B1512;
  --muted:       #7A5252;
  --bg:          #FAF8F7;
  --surface:     #FFFFFF;
  --border:      #F0C8CA;
  --border-mid:  #DEC8C8;

  /* Sidebar */
  --nav-bg:      #8F0307;
  --nav-active:  #C9040B;
  --nav-text:    rgba(255,255,255,0.80);
  --nav-active-text: #FFFFFF;
  --nav-width:   220px;

  /* Espaciado */
  --radius:      6px;
  --radius-sm:   4px;
  --shadow:      0 1px 4px rgba(27,21,18,0.10);
  --shadow-md:   0 3px 12px rgba(27,21,18,0.12);
}


/* ── Reset y base ────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 16px; -webkit-text-size-adjust: 100%; }

body {
  font-family: 'Plus Jakarta Sans', system-ui, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.5;
  min-height: 100vh;
}

h1, h2, h3,
.page-title, .auth-title, .card-value, .section-title {
  font-family: 'Sora', 'Plus Jakarta Sans', system-ui, sans-serif;
}

a { color: var(--rojo); text-decoration: none; }
a:hover { text-decoration: underline; }
a:focus-visible { outline: 2px solid var(--rojo); outline-offset: 2px; border-radius: 2px; }

img { max-width: 100%; display: block; }

/* ── Tipografía ──────────────────────────────────────────────────────────────── */
h1 { font-size: 1.5rem; font-weight: 700; line-height: 1.25; }
h2 { font-size: 1.25rem; font-weight: 700; line-height: 1.3; }
h3 { font-size: 1rem; font-weight: 600; line-height: 1.4; }

.page-title {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--ink);
  margin-bottom: 1.25rem;
  padding: 0.75rem 1rem;
  background: var(--rojo-alt);
  border-left: 4px solid var(--rojo);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

/* ── Logo INGESAM ────────────────────────────────────────────────────────────── */
.auth-logo, .header-brand {
  display: flex;
  align-items: center;
  gap: 0.625rem;
}

.header-logo-wrap {
  width: 34px;
  height: 34px;
  min-width: 34px;
  max-width: 34px;
  flex-shrink: 0;
  background: url('/static/logo-ingesam.png') center / contain no-repeat;
}

.auth-logo-wrap {
  width: 44px;
  height: 44px;
  min-width: 44px;
  max-width: 44px;
  flex-shrink: 0;
  background: url('/static/logo-ingesam.png') center / contain no-repeat;
}

.logo-name {
  font-size: 0.875rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: inherit;
  line-height: 1.2;
}

/* ── Páginas de autenticación ────────────────────────────────────────────────── */
.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem 1rem;
  background: var(--bg);
}

.auth-card {
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem 2rem 1.75rem;
  box-shadow: var(--shadow-md);
}

.auth-card .auth-logo {
  margin-bottom: 1.5rem;
}

.auth-card .logo-name {
  color: var(--rojo-osc);
  font-size: 0.9375rem;
}

.auth-title {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--ink);
  margin-bottom: 0.25rem;
}

.auth-subtitle {
  font-size: 0.875rem;
  color: var(--muted);
  margin-bottom: 1.5rem;
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  margin-bottom: 1.25rem;
}

.auth-form label {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--ink);
  margin-top: 0.75rem;
  margin-bottom: 0.3rem;
  display: block;
}

.auth-form label:first-child { margin-top: 0; }

.auth-form input,
.auth-form select,
.auth-form textarea {
  width: 100%;
  padding: 0.625rem 0.75rem;
  font-family: inherit;
  font-size: 0.9375rem;
  color: var(--ink);
  background: var(--surface);
  border: 1.5px solid var(--border-mid);
  border-radius: var(--radius-sm);
  transition: border-color 0.15s, box-shadow 0.15s;
  outline: none;
  appearance: none;
}

.auth-form input:focus,
.auth-form select:focus,
.auth-form textarea:focus {
  border-color: var(--rojo);
  box-shadow: 0 0 0 3px rgba(201,4,11,0.12);
}

.field-hint {
  font-size: 0.75rem;
  color: var(--muted);
  margin-top: 0.25rem;
  display: block;
}

.optional {
  font-size: 0.75rem;
  font-weight: 400;
  color: var(--muted);
}

.auth-footer {
  font-size: 0.8125rem;
  color: var(--muted);
  text-align: center;
  margin-top: 1.25rem;
}

/* Bloque de bienvenida en completar-perfil */
.bienvenido-block {
  background: var(--rojo-alt);
  border: 1px solid var(--rojo-line);
  border-radius: var(--radius-sm);
  padding: 0.75rem 1rem;
  margin-bottom: 1.25rem;
}

.bienvenido-nombre {
  font-size: 0.9375rem;
  color: var(--ink);
  margin-bottom: 0.15rem;
}

.bienvenido-dir {
  font-size: 0.8125rem;
  color: var(--muted);
}

/* ── Alertas ─────────────────────────────────────────────────────────────────── */
.alert {
  padding: 0.625rem 0.875rem;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  font-weight: 500;
  margin-bottom: 1rem;
  border-left: 3px solid;
}

.alert-error {
  background: var(--danger-bg);
  color: var(--danger);
  border-color: var(--danger);
}

.alert-success {
  background: var(--success-bg);
  color: var(--success);
  border-color: var(--success);
}

/* ── Botones ─────────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.625rem 1.25rem;
  font-family: inherit;
  font-size: 0.9375rem;
  font-weight: 600;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.15s, opacity 0.15s;
  text-decoration: none;
}

.btn:focus-visible { outline: 2px solid var(--rojo); outline-offset: 2px; }

.btn-primary {
  background: var(--rojo);
  color: #fff;
}

.btn-primary:hover { background: var(--rojo-osc); }
.btn-primary:disabled { opacity: 0.55; cursor: not-allowed; }

.btn-block {
  width: 100%;
  margin-top: 1rem;
}

.btn-logout {
  background: rgba(255,255,255,0.12);
  color: rgba(255,255,255,0.90);
  border: 1px solid rgba(255,255,255,0.25);
  padding: 0.4rem 0.875rem;
  font-family: inherit;
  font-size: 0.8125rem;
  font-weight: 500;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.15s;
}

.btn-logout:hover { background: rgba(255,255,255,0.22); }

.btn-link {
  background: none;
  border: none;
  color: var(--rojo);
  font-family: inherit;
  font-size: 0.8125rem;
  font-weight: 600;
  cursor: pointer;
  padding: 0;
  text-decoration: underline;
}

.btn-link:hover { color: var(--rojo-osc); }

/* ── Layout portal ───────────────────────────────────────────────────────────── */
.portal-layout {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* Header */
.portal-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  background: var(--rojo-osc);
  color: #fff;
  padding: 0 1.25rem;
  height: 56px;
  overflow: hidden;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 6px rgba(0,0,0,0.25);
}

.portal-header .logo-name { color: rgba(255,255,255,0.90); font-size: 0.875rem; }
.portal-header .logo-initials { background: rgba(255,255,255,0.18); }

.header-user {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 0.875rem;
}

.header-nombre {
  font-size: 0.8125rem;
  font-weight: 500;
  color: rgba(255,255,255,0.80);
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.nav-toggle {
  display: none;
  background: none;
  border: none;
  color: rgba(255,255,255,0.85);
  font-size: 1.25rem;
  cursor: pointer;
  padding: 0.25rem;
  margin-left: auto;
}

/* Body — sidebar + main */
.portal-body {
  display: flex;
  flex: 1;
}

/* Sidebar nav */
.portal-nav {
  width: var(--nav-width);
  background: var(--nav-bg);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  padding: 1.25rem 0;
  min-height: calc(100vh - 56px);
  position: sticky;
  top: 56px;
  align-self: flex-start;
  height: calc(100vh - 56px);
  overflow-y: auto;
}

.nav-item {
  display: block;
  padding: 0.75rem 1.25rem;
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--nav-text);
  text-decoration: none;
  border-left: 3px solid transparent;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
}

.nav-item:hover {
  background: rgba(255,255,255,0.08);
  color: #fff;
  text-decoration: none;
}

.nav-item.active {
  background: rgba(255,255,255,0.12);
  color: var(--nav-active-text);
  border-left-color: var(--verde);
  font-weight: 600;
}

/* Main content */
.portal-main {
  flex: 1;
  padding: 1.75rem 1.5rem;
  max-width: 900px;
  min-width: 0;
}

/* ── Cards de métricas ───────────────────────────────────────────────────────── */
.cards-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.875rem;
  margin-bottom: 1.75rem;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.125rem 1.25rem;
  border-top: 3px solid var(--border-mid);
  box-shadow: var(--shadow);
}

.card-success { border-top-color: var(--success); }
.card-danger  { border-top-color: var(--danger); }
.card-warning { border-top-color: var(--warning); }

.card-value {
  font-size: 1.625rem;
  font-weight: 700;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
  margin-bottom: 0.25rem;
}

.card-danger  .card-value { color: var(--danger); }
.card-success .card-value { color: var(--success); }
.card-warning .card-value { color: var(--warning); }

.card-label {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* ── Sección predio ──────────────────────────────────────────────────────────── */
.section-block {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-bottom: 1.25rem;
  box-shadow: var(--shadow);
}

.section-title {
  font-size: 0.8125rem;
  font-weight: 700;
  color: #fff;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  background: var(--rojo);
  margin: -1.25rem -1.25rem 1rem -1.25rem;
  padding: 0.5rem 1rem;
  border-radius: var(--radius) var(--radius) 0 0;
}

.predio-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.625rem 1.25rem;
}

.predio-item {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.predio-label {
  font-size: 0.6875rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.predio-item > span:last-child {
  font-size: 0.9375rem;
  color: var(--ink);
  font-weight: 500;
}

/* ── Tablas ──────────────────────────────────────────────────────────────────── */
.table-wrap {
  overflow-x: auto;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  background: var(--surface);
}

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

.data-table thead th {
  background: var(--rojo);
  color: #fff;
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 0.625rem 0.875rem;
  text-align: left;
  white-space: nowrap;
}

.data-table thead th.num,
.data-table thead th.center { text-align: center; }

.data-table tbody tr:nth-child(odd)  { background: var(--surface); }
.data-table tbody tr:nth-child(even) { background: var(--rojo-alt); }

.data-table tbody tr:hover { background: var(--rojo-lite); }

.data-table td {
  padding: 0.5625rem 0.875rem;
  color: var(--ink);
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.data-table tbody tr:last-child td { border-bottom: none; }

.data-table tfoot td {
  padding: 0.625rem 0.875rem;
  background: var(--rojo-alt);
  border-top: 2px solid var(--border-mid);
  font-size: 0.875rem;
}

.data-table .num    { text-align: right; font-variant-numeric: tabular-nums; }
.data-table .center { text-align: center; }

.data-table .empty {
  text-align: center;
  color: var(--muted);
  padding: 2rem;
  font-style: italic;
  font-size: 0.875rem;
}

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

/* ── Chips / badges ──────────────────────────────────────────────────────────── */
.chip {
  display: inline-block;
  padding: 0.2rem 0.625rem;
  border-radius: 3px;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

/* Facturas */
.chip-pagado      { background: var(--success-bg); color: var(--success); }
.chip-pendiente   { background: var(--danger-bg);  color: var(--danger);  }
.chip-sin_factura { background: var(--rojo-alt);   color: var(--muted);   }

/* PQR */
.chip-pqr-abierto    { background: var(--danger-bg);  color: var(--danger);  }
.chip-pqr-en_proceso { background: var(--warning-bg); color: var(--warning); }
.chip-pqr-cerrado    { background: var(--success-bg); color: var(--success); }

/* Estado suministro (basado en volcado RECIVA) */
.chip-activo   { background: var(--success-bg); color: var(--success); }
.chip-inactivo { background: var(--rojo-alt);   color: var(--muted);   }

/* ── Formulario PQR ──────────────────────────────────────────────────────────── */
.pqr-form {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  max-width: 560px;
}

.pqr-form label {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--ink);
  margin-top: 0.75rem;
  margin-bottom: 0.3rem;
  display: block;
}

.pqr-form label:first-child { margin-top: 0; }

.pqr-form select,
.pqr-form textarea {
  width: 100%;
  padding: 0.625rem 0.75rem;
  font-family: inherit;
  font-size: 0.9375rem;
  color: var(--ink);
  background: var(--surface);
  border: 1.5px solid var(--border-mid);
  border-radius: var(--radius-sm);
  transition: border-color 0.15s, box-shadow 0.15s;
  outline: none;
  appearance: none;
  resize: vertical;
}

.pqr-form select:focus,
.pqr-form textarea:focus {
  border-color: var(--rojo);
  box-shadow: 0 0 0 3px rgba(201,4,11,0.12);
}

.pqr-form .btn { margin-top: 1rem; align-self: flex-start; }

/* Panel de respuesta */
.respuesta-panel {
  margin-top: 0.625rem;
  background: var(--rojo-alt);
  border: 1px solid var(--rojo-line);
  border-radius: var(--radius-sm);
  padding: 0.75rem 1rem;
  font-size: 0.8125rem;
  color: var(--ink);
  line-height: 1.5;
}

/* ── Responsive ──────────────────────────────────────────────────────────────── */
@media (max-width: 720px) {
  /* Header mobile */
  .header-nombre { display: none; }
  .nav-toggle { display: block; }
  .header-user { gap: 0.5rem; }

  /* Sidebar oculto por defecto en mobile */
  .portal-body { flex-direction: column; }

  .portal-nav {
    position: fixed;
    top: 56px;
    left: 0;
    width: 100%;
    min-height: unset;
    height: auto;
    flex-direction: row;
    padding: 0;
    z-index: 99;
    transform: translateY(-110%);
    transition: transform 0.22s ease;
    box-shadow: 0 4px 12px rgba(0,0,0,0.25);
  }

  .portal-nav.open {
    transform: translateY(0);
  }

  .nav-item {
    flex: 1;
    padding: 0.875rem 0.5rem;
    font-size: 0.75rem;
    text-align: center;
    border-left: none;
    border-bottom: 3px solid transparent;
  }

  .nav-item.active {
    border-left: none;
    border-bottom-color: rgba(255,255,255,0.70);
  }

  .portal-main { padding: 1.25rem 1rem; }

  .cards-grid { grid-template-columns: repeat(2, 1fr); gap: 0.625rem; }
  .card { padding: 0.875rem 1rem; }
  .card-value { font-size: 1.25rem; }

  .predio-grid { grid-template-columns: 1fr; }

  .auth-card { padding: 1.5rem 1.25rem; }
}

@media (max-width: 420px) {
  .cards-grid { grid-template-columns: 1fr 1fr; gap: 0.5rem; }
  .card-value { font-size: 1.125rem; }
}

/* ── Footer ──────────────────────────────────────────────────────────────────── */
.portal-footer {
  border-top: 2px solid var(--rojo);
  padding: 1.25rem 1.5rem 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.footer-brand {
  display: flex;
  align-items: center;
  gap: 0.625rem;
}

.footer-logo-wrap {
  width: 28px;
  height: 28px;
  min-width: 28px;
  flex-shrink: 0;
  background: url('/static/logo-ingesam.png') center / contain no-repeat;
}

.footer-nombre {
  font-size: 0.8125rem;
  font-weight: 700;
  color: var(--rojo-osc);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.footer-info {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem 1.25rem;
}

.footer-info span {
  font-size: 0.75rem;
  color: var(--muted);
}

.footer-copy {
  font-size: 0.6875rem;
  color: var(--muted);
  opacity: 0.7;
}

.footer-link {
  color: var(--verde);
  font-weight: 600;
  text-decoration: none;
}

.footer-link:hover { text-decoration: underline; }

/* ── Reducción de movimiento ─────────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}
