/* ==========================================================================
   FERROCLIENTES - CREDITO Y COBRANZA
   Ultra-Professional & Minimalist Design System
   ========================================================================== */

:root {
  --bg-app: #f8fafc;
  --bg-surface: #ffffff;
  --bg-surface-elevated: #ffffff;
  --bg-muted: #f1f5f9;
  --bg-hover: #f1f5f9;
  
  --border-color: #e2e8f0;
  --border-focus: #0284c7;
  
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #94a3b8;
  --text-white: #ffffff;

  --brand-primary: #0284c7;
  --brand-primary-hover: #0369a1;
  --brand-navy: #0f172a;
  
  --success-bg: #ecfdf5;
  --success-text: #059669;
  --success-border: #a7f3d0;
  
  --warning-bg: #fffbeb;
  --warning-text: #d97706;
  --warning-border: #fde68a;
  
  --danger-bg: #fef2f2;
  --danger-text: #dc2626;
  --danger-border: #fecaca;

  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.07), 0 2px 4px -2px rgb(0 0 0 / 0.07);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.08), 0 4px 6px -4px rgb(0 0 0 / 0.08);
  --shadow-xl: 0 20px 25px -5px rgb(0 0 0 / 0.12), 0 8px 10px -6px rgb(0 0 0 / 0.1);

  --font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-full: 9999px;
}

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

body {
  font-family: var(--font-family);
  background-color: var(--bg-app);
  color: var(--text-primary);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ---------------- Navbar ---------------- */
.navbar {
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-color);
  padding: 0.75rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 40;
}

.navbar-brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  text-decoration: none;
  color: var(--text-primary);
}

.navbar-brand img {
  height: 32px;
  width: auto;
  object-fit: contain;
}

.brand-title {
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text-primary);
}

.brand-badge {
  font-size: 0.7rem;
  font-weight: 600;
  padding: 0.2rem 0.5rem;
  border-radius: var(--radius-full);
  background: var(--bg-muted);
  color: var(--brand-primary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.nav-user {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.user-chip {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.35rem 0.75rem;
  background: var(--bg-muted);
  border-radius: var(--radius-full);
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-secondary);
}

.user-avatar {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--brand-primary);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 700;
}

.btn-logout {
  background: transparent;
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  padding: 0.4rem 0.8rem;
  border-radius: var(--radius-md);
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
  text-decoration: none;
}

.btn-logout:hover {
  background: var(--bg-muted);
  color: var(--danger-text);
  border-color: var(--danger-border);
}

/* ---------------- Main Layout ---------------- */
.main-container {
  flex: 1;
  max-width: 1440px;
  width: 100%;
  margin: 0 auto;
  padding: 1.5rem 1.5rem 3rem;
}

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

.header-title-group h1 {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text-primary);
}

.header-title-group p {
  font-size: 0.875rem;
  color: var(--text-secondary);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  padding: 0.5rem 0.9rem;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.15s ease;
  text-decoration: none;
  white-space: nowrap;
}

.btn-primary {
  background: var(--brand-primary);
  color: white;
}

.btn-primary:hover {
  background: var(--brand-primary-hover);
  box-shadow: var(--shadow-sm);
}

.btn-secondary {
  background: var(--bg-surface);
  border-color: var(--border-color);
  color: var(--text-secondary);
}

.btn-secondary:hover {
  background: var(--bg-muted);
  color: var(--text-primary);
}

.btn-dark {
  background: var(--brand-navy);
  color: white;
}

.btn-dark:hover {
  background: #1e293b;
}

.btn-success {
  background: var(--success-text);
  color: white;
}

.btn-success:hover {
  background: #047857;
}

.btn-sm {
  padding: 0.35rem 0.65rem;
  font-size: 0.78rem;
  border-radius: var(--radius-sm);
}

/* ---------------- KPI Cards Grid ---------------- */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.kpi-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1.1rem;
  box-shadow: var(--shadow-sm);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.kpi-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.kpi-label {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary);
  margin-bottom: 0.35rem;
}

.kpi-value {
  font-size: 1.45rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
}

.kpi-sub {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: 0.25rem;
}

.kpi-value.danger { color: var(--danger-text); }
.kpi-value.success { color: var(--success-text); }
.kpi-value.primary { color: var(--brand-primary); }

/* ---------------- Table Card & Filter Bar ---------------- */
.card-table-wrapper {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.table-toolbar {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.search-box {
  position: relative;
  min-width: 280px;
  max-width: 360px;
  flex: 1;
}

.search-box input {
  width: 100%;
  font-family: inherit;
  font-size: 0.875rem;
  padding: 0.55rem 1rem 0.55rem 2.25rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  background: var(--bg-muted);
  color: var(--text-primary);
  outline: none;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.search-box input:focus {
  background: var(--bg-surface);
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(2, 132, 199, 0.15);
}

.search-icon {
  position: absolute;
  left: 0.75rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
}

.filter-pills {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-wrap: wrap;
}

.filter-pill {
  font-size: 0.8rem;
  font-weight: 500;
  padding: 0.35rem 0.75rem;
  border-radius: var(--radius-full);
  background: var(--bg-muted);
  color: var(--text-secondary);
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.15s ease;
}

.filter-pill:hover {
  background: #e2e8f0;
  color: var(--text-primary);
}

.filter-pill.active {
  background: var(--brand-navy);
  color: white;
}

/* ---------------- Clean Data Table ---------------- */
.table-responsive {
  width: 100%;
  overflow-x: auto;
}

.modern-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 0.85rem;
}

.modern-table thead th {
  background: var(--bg-muted);
  color: var(--text-secondary);
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border-color);
  white-space: nowrap;
  user-select: none;
}

.modern-table tbody tr {
  border-bottom: 1px solid var(--border-color);
  transition: background-color 0.15s ease;
  cursor: pointer;
}

.modern-table tbody tr:hover {
  background-color: var(--bg-hover);
}

.modern-table tbody td {
  padding: 0.8rem 1rem;
  color: var(--text-primary);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.modern-table td.text-right,
.modern-table th.text-right {
  text-align: right;
}

.modern-table td.text-center,
.modern-table th.text-center {
  text-align: center;
}

.col-name {
  font-weight: 600;
  color: var(--text-primary);
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.col-notes {
  max-width: 240px;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text-secondary);
  font-size: 0.8rem;
}

/* ---------------- Badges ---------------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 0.2rem 0.55rem;
  border-radius: var(--radius-full);
  white-space: nowrap;
}

.badge-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
}

.badge-al_corriente {
  background: var(--success-bg);
  color: var(--success-text);
  border: 1px solid var(--success-border);
}
.badge-al_corriente .badge-dot { background: var(--success-text); }

.badge-vencido_bajo {
  background: #fefce8;
  color: #ca8a04;
  border: 1px solid #fef08a;
}
.badge-vencido_bajo .badge-dot { background: #ca8a04; }

.badge-vencido_medio {
  background: var(--warning-bg);
  color: var(--warning-text);
  border: 1px solid var(--warning-border);
}
.badge-vencido_medio .badge-dot { background: var(--warning-text); }

.badge-vencido_alto {
  background: var(--danger-bg);
  color: var(--danger-text);
  border: 1px solid var(--danger-border);
}
.badge-vencido_alto .badge-dot { background: var(--danger-text); }

/* ---------------- Modal System ---------------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.65);
  backdrop-filter: blur(5px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 1rem;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s ease, visibility 0.2s ease;
}

.modal-overlay.active {
  opacity: 1;
  visibility: visible;
}

.modal-container {
  background: var(--bg-surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xl);
  width: 100%;
  max-width: 1120px;
  max-height: 94vh;
  display: flex;
  flex-direction: column;
  transform: scale(0.97) translateY(8px);
  transition: transform 0.2s ease;
  overflow: hidden;
}

.modal-overlay.active .modal-container {
  transform: scale(1) translateY(0);
}

.modal-header {
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-surface);
}

.modal-title-group h2 {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.modal-subtitle {
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-top: 0.15rem;
}

.btn-close-modal {
  background: transparent;
  border: none;
  font-size: 1.6rem;
  line-height: 1;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0.2rem 0.5rem;
  border-radius: var(--radius-sm);
  transition: color 0.15s ease, background 0.15s ease;
}

.btn-close-modal:hover {
  color: var(--text-primary);
  background: var(--bg-muted);
}

.modal-body {
  padding: 1.25rem 1.5rem;
  overflow-y: auto;
  flex: 1;
}

/* ---------------- DATOS DEL CLIENTE (Imagen 2 Layout) ---------------- */
.modal-grid-top {
  display: grid;
  grid-template-columns: 1fr 280px;
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.chart-card {
  background: var(--bg-muted);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 0.85rem;
  display: flex;
  flex-direction: column;
  height: 240px;
}

.chart-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.5rem;
}

.chart-title {
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.chart-badge-legend {
  display: inline-block;
  width: 10px;
  height: 10px;
  background: var(--brand-primary);
  border-radius: 2px;
}

.chart-wrapper {
  flex: 1;
  position: relative;
  min-height: 140px;
}

/* Monthly Table Widget */
.monthly-table-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  overflow: hidden;
  height: 240px;
  display: flex;
  flex-direction: column;
}

.monthly-table-card table {
  width: 100%;
  font-size: 0.8rem;
  border-collapse: collapse;
}

.monthly-table-card th {
  background: #1e293b;
  color: #ffffff;
  padding: 0.5rem 0.75rem;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
}

.monthly-table-card td {
  padding: 0.4rem 0.75rem;
  border-bottom: 1px solid var(--border-color);
  font-variant-numeric: tabular-nums;
}

.monthly-scroll {
  flex: 1;
  overflow-y: auto;
}

/* Date range bar */
.date-filter-bar {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-top: 0.6rem;
  flex-wrap: wrap;
}

.date-filter-bar input[type="date"] {
  font-family: inherit;
  font-size: 0.8rem;
  padding: 0.35rem 0.6rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  background: var(--bg-surface);
  color: var(--text-primary);
  outline: none;
}

/* Middle Section: Table + Action Buttons */
.modal-grid-middle {
  display: grid;
  grid-template-columns: 1fr 180px;
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.middle-table-card {
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  background: var(--bg-surface);
  overflow: hidden;
  min-height: 180px;
  max-height: 220px;
  display: flex;
  flex-direction: column;
}

.middle-table-card .table-scroll {
  flex: 1;
  overflow-y: auto;
}

.actions-column {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  justify-content: flex-start;
}

.actions-column .btn {
  width: 100%;
  padding: 0.55rem 0.75rem;
  font-size: 0.82rem;
  justify-content: flex-start;
  gap: 0.5rem;
}

/* Bottom Section: Client Info & Parameter Editors */
.modal-bottom-card {
  background: var(--bg-muted);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.client-meta-row {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  flex-wrap: wrap;
  font-size: 0.85rem;
}

.meta-item {
  display: flex;
  align-items: baseline;
  gap: 0.4rem;
}

.meta-item strong {
  font-weight: 700;
  color: var(--text-primary);
}

.meta-item span {
  color: var(--text-secondary);
}

.meta-saldo {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--danger-text);
  margin-left: auto;
}

/* Parameter edit rows */
.param-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.param-row label {
  font-size: 0.8rem;
  font-weight: 600;
  min-width: 110px;
  color: var(--text-secondary);
}

.param-row input[type="number"],
.param-row input[type="text"],
.param-row textarea {
  font-family: inherit;
  font-size: 0.85rem;
  padding: 0.4rem 0.65rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  background: var(--bg-surface);
  color: var(--text-primary);
  outline: none;
}

.param-row textarea {
  flex: 1;
  min-height: 48px;
  resize: vertical;
}

/* Toast notifications */
.toast-container {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  z-index: 100;
}

.toast {
  background: var(--brand-navy);
  color: white;
  padding: 0.75rem 1.25rem;
  border-radius: var(--radius-md);
  font-size: 0.85rem;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  animation: toastIn 0.2s ease;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

@keyframes toastIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Responsive */
@media (max-width: 900px) {
  .modal-grid-top {
    grid-template-columns: 1fr;
  }
  .modal-grid-middle {
    grid-template-columns: 1fr;
  }
  .actions-column {
    flex-direction: row;
    flex-wrap: wrap;
  }
  .actions-column .btn {
    width: auto;
    flex: 1;
  }
}
