/* ============================================================
   Hosanna UK - Mini CRM - Estilos principales
   ============================================================ */

:root {
  --color-primary:      #4A90A4;
  --color-primary-dark: #357A8F;
  --color-primary-light:#EBF5F8;
  --color-accent:       #2C6E7F;
  --color-success:      #27AE60;
  --color-error:        #E74C3C;
  --color-warning:      #F39C12;
  --color-bg:           #F4F7F9;
  --color-surface:      #FFFFFF;
  --color-border:       #DDE3E8;
  --color-text:         #1A2733;
  --color-text-muted:   #6B7C8D;
  --color-text-faint:   #AAB5BF;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;

  --shadow-sm: 0 1px 3px rgba(0,0,0,.08);
  --shadow-md: 0 4px 16px rgba(0,0,0,.10);
  --shadow-lg: 0 8px 32px rgba(0,0,0,.12);

  --font-body: 'Inter', sans-serif;
  --transition: 160ms cubic-bezier(.16,1,.3,1);
}

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font-body);
  font-size: 15px;
  color: var(--color-text);
  background: var(--color-bg);
  min-height: 100dvh;
  line-height: 1.6;
  overflow-x: hidden;
}

img {
  display: block;
  max-width: 100%;
  height: auto;
}

input,
button,
textarea,
select {
  font: inherit;
  color: inherit;
}

a {
  color: var(--color-primary);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

/* ---- Navbar ---- */

.navbar {
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  padding: 0 1.5rem;
  min-height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow-sm);
}

.navbar-brand {
  display: flex;
  align-items: center;
  gap: .5rem;
  min-width: 0;
  font-weight: 700;
  font-size: 1rem;
  color: var(--color-text);
  text-decoration: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.navbar-brand svg {
  flex: 0 0 auto;
}

.navbar-links {
  display: flex;
  align-items: center;
  gap: .25rem;
}

.nav-link {
  padding: .4rem .75rem;
  border-radius: var(--radius-sm);
  font-size: .875rem;
  font-weight: 500;
  color: var(--color-text-muted);
  transition: background var(--transition), color var(--transition);
  text-decoration: none;
  white-space: nowrap;
}

.nav-link:hover {
  background: var(--color-bg);
  color: var(--color-text);
  text-decoration: none;
}

.nav-link.active {
  background: #D6EAF8 !important;
  color: var(--color-accent) !important;
  box-shadow: inset 0 0 0 1px rgba(74,144,164,.30);
}

.nav-link.active:hover {
  background: #D6EAF8 !important;
  color: var(--color-accent) !important;
  text-decoration: none;
}

.nav-link-primary {
  background: var(--color-primary);
  color: #fff !important;
  padding: .4rem .9rem;
  border-radius: var(--radius-sm);
}

.nav-link-primary:hover {
  background: var(--color-primary-dark);
  text-decoration: none;
}

.nav-link-logout {
  color: var(--color-error) !important;
}

.nav-user {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  min-width: 0;
  padding: 0 .5rem;
  border-left: 1px solid var(--color-border);
  margin-left: .25rem;
}

.nav-user-name,
.nav-user-rol {
  max-width: 150px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.nav-user-name {
  font-size: .8rem;
  font-weight: 600;
  line-height: 1.2;
}

.nav-user-rol {
  font-size: .7rem;
  color: var(--color-text-faint);
  line-height: 1.2;
}

.nav-toggle {
  display: none;
  flex: 0 0 auto;
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1.4rem;
  color: var(--color-text);
  padding: .35rem .5rem;
}

/* ---- Main ---- */

.main-content {
  width: 100%;
  max-width: 1100px;
  margin: 0 auto;
  padding: 2rem 1.5rem 4rem;
}

.footer {
  text-align: center;
  padding: 1.5rem;
  font-size: .8rem;
  color: var(--color-text-faint);
  border-top: 1px solid var(--color-border);
  background: var(--color-surface);
}

/* ---- Page header ---- */

.page-header {
  margin-bottom: 1.75rem;
}

.page-header h1 {
  font-size: 1.5rem;
  font-weight: 700;
  overflow-wrap: anywhere;
}

.page-header p {
  color: var(--color-text-muted);
  font-size: .9rem;
  margin-top: .25rem;
}

.page-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

/* ---- Cards ---- */

.card {
  min-width: 0;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  padding: 1.5rem;
  margin-bottom: 1.25rem;
}

.card-title {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: .75rem;
}

/* ---- KPI Row ---- */

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 1rem;
  margin-bottom: 1.75rem;
}

.kpi-card {
  min-width: 0;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 1.25rem 1.5rem;
  box-shadow: var(--shadow-sm);
}

.kpi-num {
  font-size: 2rem;
  font-weight: 700;
  color: var(--color-primary);
  line-height: 1;
}

.kpi-label {
  font-size: .8rem;
  color: var(--color-text-muted);
  margin-top: .3rem;
  overflow-wrap: anywhere;
}

/* ---- Formularios ---- */

.form-section {
  margin-bottom: 1.75rem;
}

.form-section-title {
  font-size: .75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--color-primary);
  margin-bottom: 1rem;
  padding-bottom: .5rem;
  border-bottom: 2px solid var(--color-primary-light);
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

.form-grid-full {
  grid-column: 1 / -1;
}

.form-group {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: .35rem;
}

.form-group label {
  font-size: .825rem;
  font-weight: 600;
  color: var(--color-text);
}

.form-group .hint {
  font-size: .75rem;
  color: var(--color-text-faint);
}

.form-control {
  min-width: 0;
  padding: .6rem .875rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  font-size: .9rem;
  transition: border-color var(--transition), box-shadow var(--transition);
  width: 100%;
}

.form-control:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(74,144,164,.15);
}

textarea.form-control {
  min-height: 110px;
  resize: vertical;
}

.radio-group {
  display: flex;
  gap: 1.25rem;
  align-items: center;
  flex-wrap: wrap;
  padding: .5rem 0;
}

.radio-group label {
  display: flex;
  align-items: center;
  gap: .4rem;
  font-size: .9rem;
  font-weight: 400;
  cursor: pointer;
}

/* ---- Botones ---- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .4rem;
  max-width: 100%;
  padding: .55rem 1.25rem;
  border-radius: var(--radius-sm);
  font-size: .875rem;
  font-weight: 600;
  border: none;
  cursor: pointer;
  transition: background var(--transition), box-shadow var(--transition);
  text-decoration: none;
  white-space: nowrap;
}

.btn-primary {
  background: var(--color-primary);
  color: #fff;
}

.btn-primary:hover {
  background: var(--color-primary-dark);
  text-decoration: none;
  color: #fff;
}

.btn-secondary {
  background: var(--color-bg);
  color: var(--color-text);
  border: 1px solid var(--color-border);
}

.btn-secondary:hover {
  background: var(--color-border);
  text-decoration: none;
}

.btn-danger {
  background: var(--color-error);
  color: #fff;
}

.btn-danger:hover {
  background: #c0392b;
  text-decoration: none;
  color: #fff;
}

.btn-sm {
  padding: .35rem .8rem;
  font-size: .8rem;
}

.btn-group {
  display: flex;
  gap: .625rem;
  flex-wrap: wrap;
  align-items: center;
}

/* ---- Tabla ---- */

.table-wrap {
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  border-radius: var(--radius-md);
  border: 1px solid var(--color-border);
  -webkit-overflow-scrolling: touch;
}

table {
  width: 100%;
  border-collapse: collapse;
  background: var(--color-surface);
}

thead {
  background: var(--color-bg);
}

th {
  padding: .75rem 1rem;
  font-size: .78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--color-text-muted);
  text-align: left;
  border-bottom: 1px solid var(--color-border);
  white-space: nowrap;
}

td {
  padding: .75rem 1rem;
  font-size: .875rem;
  border-bottom: 1px solid var(--color-border);
  vertical-align: middle;
}

tr:last-child td {
  border-bottom: none;
}

tr:hover td {
  background: var(--color-primary-light);
}

.td-actions {
  display: flex;
  gap: .4rem;
  flex-wrap: wrap;
}

/* Tablas utilizadas sin .table-wrap en algunos reportes */

.tabla-datos {
  display: block;
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.tabla-datos th,
.tabla-datos td {
  white-space: nowrap;
}

/* ---- Badges ---- */

.badge {
  display: inline-block;
  padding: .2rem .6rem;
  border-radius: 99px;
  font-size: .72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
}

.badge-admin {
  background: #E8F4F8;
  color: #2C6E7F;
}

.badge-pastor {
  background: #EEF7EE;
  color: #27AE60;
}

.badge-registrador {
  background: #F5F0FF;
  color: #7C5CBF;
}

.badge-si {
  background: #EEF7EE;
  color: #27AE60;
}

.badge-no {
  background: #FDF3F3;
  color: #E74C3C;
}

.badge-activo {
  background: #EEF7EE;
  color: #27AE60;
}

.badge-inactivo {
  background: #F5F5F5;
  color: #AAB5BF;
}

/* ---- Alertas ---- */

.alert {
  min-width: 0;
  padding: .875rem 1rem;
  border-radius: var(--radius-sm);
  margin-bottom: 1.25rem;
  font-size: .875rem;
  display: flex;
  align-items: flex-start;
  gap: .5rem;
  overflow-wrap: anywhere;
}

.alert-success {
  background: #EEF7EE;
  border: 1px solid #B2DFBC;
  color: #1e6e2e;
}

.alert-error {
  background: #FDF3F3;
  border: 1px solid #F1B5B0;
  color: #922b21;
}

.alert-info {
  background: var(--color-primary-light);
  border: 1px solid #B3D9E6;
  color: var(--color-accent);
}

/* ---- Buscador ---- */

.search-bar {
  display: flex;
  gap: .75rem;
  margin-bottom: 1.25rem;
  flex-wrap: wrap;
  align-items: flex-end;
}

.search-bar .form-control {
  max-width: 240px;
}

.search-bar select.form-control {
  max-width: 200px;
}

.filtro-form {
  display: flex;
  gap: .75rem;
  flex-wrap: wrap;
  align-items: flex-end;
  max-width: 100%;
}

.filtro-form label {
  min-width: 0;
}

.filtro-form input,
.filtro-form select {
  max-width: 100%;
}

/* ---- Ficha detalle ---- */

.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.25rem;
}

.detail-field {
  min-width: 0;
}

.detail-field label {
  font-size: .75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--color-text-faint);
  display: block;
  margin-bottom: .2rem;
}

.detail-field p {
  font-size: .925rem;
  color: var(--color-text);
  overflow-wrap: anywhere;
}

.detail-field-full {
  grid-column: 1 / -1;
}

.notes-box {
  background: var(--color-bg);
  border: 1px dashed var(--color-border);
  border-radius: var(--radius-sm);
  padding: 1rem;
  font-size: .9rem;
  white-space: pre-wrap;
  line-height: 1.7;
  overflow-wrap: anywhere;
}

.restricted-note {
  background: #FFF8E1;
  border: 1px solid #FFE082;
  border-radius: var(--radius-sm);
  padding: .75rem 1rem;
  font-size: .825rem;
  color: #856404;
  display: flex;
  align-items: center;
  gap: .5rem;
}

/* ---- Login ---- */

.login-wrap {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--color-primary-light) 0%, #D6EAF8 100%);
  padding: 1.5rem;
}

.login-card {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 2.5rem 2rem;
  width: 100%;
  max-width: 420px;
}

.login-logo {
  text-align: center;
  margin-bottom: 1.75rem;
}

.login-logo svg {
  margin: 0 auto .75rem;
}

.login-logo h1 {
  font-size: 1.25rem;
  font-weight: 700;
}

.login-logo p {
  font-size: .825rem;
  color: var(--color-text-muted);
  margin-top: .25rem;
}

/* ---- Empty state ---- */

.empty-state {
  text-align: center;
  padding: 3rem 2rem;
  color: var(--color-text-muted);
}

.empty-state-icon {
  font-size: 2.5rem;
  margin-bottom: .75rem;
}

.empty-state h3 {
  font-size: 1rem;
  font-weight: 600;
  color: var(--color-text);
  margin-bottom: .4rem;
}

/* ---- Responsive: tablets ---- */

@media (max-width: 900px) {
  .navbar {
    padding: 0 1rem;
  }

  .navbar-links {
    display: none;
    flex-direction: column;
    align-items: stretch;
    position: absolute;
    top: 60px;
    left: 0;
    right: 0;
    background: var(--color-surface);
    padding: 1rem;
    border-bottom: 1px solid var(--color-border);
    box-shadow: var(--shadow-md);
    gap: .5rem;
  }

  .navbar-links.open {
    display: flex;
  }

  .navbar-links .nav-link {
    width: 100%;
  }

  .navbar-links .nav-user {
    width: 100%;
    align-items: flex-start;
    border-left: none;
    border-top: 1px solid var(--color-border);
    margin: 0;
    padding: .75rem 0 .25rem;
  }

  .navbar-links .nav-user-name,
  .navbar-links .nav-user-rol {
    max-width: 100%;
  }

  .nav-toggle {
    display: block;
  }

  .main-content {
    padding: 1.5rem 1rem 3rem;
  }
}

@media (max-width: 768px) {
  .form-grid {
    grid-template-columns: 1fr;
  }

  .detail-grid {
    grid-template-columns: 1fr;
  }

  .detail-field-full {
    grid-column: auto;
  }

  .kpi-grid {
    grid-template-columns: 1fr 1fr;
  }

  .page-header-row {
    flex-direction: column;
    align-items: flex-start;
  }

  .resumen-cards {
    display: grid !important;
    grid-template-columns: 1fr 1fr;
    gap: 12px !important;
  }

  .resumen-cards .card {
    margin-bottom: 0;
  }
}

@media (max-width: 480px) {
  body {
    font-size: 14px;
  }

  .navbar {
    min-height: 56px;
  }

  .navbar-links {
    top: 56px;
  }

  .main-content {
    padding: 1.25rem .75rem 2.5rem;
  }

  .card {
    padding: 1rem;
  }

  .kpi-grid,
  .resumen-cards {
    grid-template-columns: 1fr !important;
  }

  .btn-group {
    align-items: stretch;
  }

  .btn-group .btn,
  .filtro-form button,
  .filtro-form input,
  .filtro-form select {
    width: 100%;
    max-width: none;
  }

  .btn {
    white-space: normal;
    text-align: center;
  }

  .search-bar .form-control,
  .search-bar select.form-control {
    max-width: none;
    width: 100%;
  }

  .login-wrap {
    padding: 1rem;
  }

  .login-card {
    padding: 2rem 1rem;
  }

  .empty-state {
    padding: 2rem 1rem;
  }
}

/* ---- Dashboard responsive ---- */

.dashboard-layout {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(220px, 1fr);
  gap: 1.25rem;
  width: 100%;
  max-width: 100%;
  align-items: start;
}

.dashboard-layout > *,
.dashboard-sidebar,
.dashboard-recent {
  min-width: 0;
  max-width: 100%;
}

.dashboard-sidebar {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.dashboard-sidebar .card {
  width: 100%;
}

.referral-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: .75rem;
  min-width: 0;
  padding: .5rem 0;
  border-bottom: 1px solid var(--color-border);
  font-size: .875rem;
}

.referral-row:last-child {
  border-bottom: none;
}

.referral-row span {
  min-width: 0;
  overflow-wrap: anywhere;
}

.referral-row strong {
  flex: 0 0 auto;
  color: var(--color-primary);
}

.quick-actions {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: .5rem;
  width: 100%;
}

.quick-actions .btn {
  width: 100%;
  margin-top: 0 !important;
  white-space: normal;
  text-align: center;
}

.dashboard-recent .table-wrap {
  width: 100%;
  max-width: 100%;
}

@media (max-width: 900px) {
  .dashboard-layout {
    grid-template-columns: minmax(0, 1fr);
  }

  .dashboard-sidebar {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 1.25rem;
  }

  .dashboard-sidebar .card {
    margin-bottom: 0;
  }
}

@media (max-width: 600px) {
  .dashboard-layout {
    display: block;
  }

  .dashboard-recent {
    margin-bottom: 1.25rem;
  }

  .dashboard-sidebar {
    display: block;
  }

  .dashboard-sidebar .card {
    margin-bottom: 1.25rem;
  }

  .dashboard-sidebar .card:last-child {
    margin-bottom: 0;
  }
}

/* ---- Listado de registros responsive ---- */

@media (max-width: 700px) {
  .page-header-row {
    width: 100%;
  }

  .page-header-row > div {
    width: 100%;
    max-width: 100%;
  }

  .page-header-row .btn-group {
    width: 100%;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: .5rem;
  }

  .page-header-row .btn-group .btn {
    width: 100%;
    min-width: 0;
    white-space: normal;
    text-align: center;
  }

  .search-bar {
    width: 100%;
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    align-items: stretch;
    gap: .5rem;
  }

  .search-bar .form-control {
    width: 100%;
    max-width: none;
    min-width: 0;
  }

  .search-bar input[name="q"] {
    grid-column: 1 / -1;
  }

  .search-bar select[name="reg"] {
    grid-column: 1;
  }

  .search-bar input[name="mes"] {
    grid-column: 2;
  }

  .search-bar button {
    grid-column: 1 / -1;
    width: 100%;
    min-width: 0;
    white-space: normal;
  }

  .search-bar a.btn {
    grid-column: 1 / -1;
    width: 100%;
    min-width: 0;
    white-space: normal;
  }

  .alert-info {
    overflow-wrap: anywhere;
  }
}

@media (max-width: 480px) {
  .page-header-row .btn-group {
    grid-template-columns: 1fr;
  }

  .search-bar {
    display: flex;
    flex-direction: column;
    align-items: stretch;
  }

  .search-bar .form-control,
  .search-bar button,
  .search-bar a.btn {
    width: 100%;
    max-width: none;
  }
}