/* ═══════════════════════════════════════════
   🌊 AGUA MI ÁNGEL — Dashboard PWA Styles
   ═══════════════════════════════════════════ */

:root {
  --bg-primary: #0a1628;
  --bg-secondary: #111d35;
  --bg-card: #162244;
  --bg-hover: #1c2e54;
  --text-primary: #e2e8f0;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --accent: #3b82f6;
  --accent-light: #60a5fa;
  --green: #22c55e;
  --yellow: #eab308;
  --orange: #f97316;
  --red: #ef4444;
  --border: #1e3a5f;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
  --nav-height: 64px;
  --header-height: 60px;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.5;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

#app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  padding-bottom: calc(var(--nav-height) + 16px);
}

/* ═══ HEADER ═══ */
.header {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  height: var(--header-height);
}

.header-title {
  font-size: 18px;
  font-weight: 700;
  background: linear-gradient(135deg, var(--accent), var(--accent-light));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.header-subtitle {
  font-size: 12px;
  color: var(--text-muted);
  display: block;
}

.header-right {
  display: flex;
  gap: 8px;
}

.btn-icon {
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 50%;
  background: var(--bg-card);
  color: var(--text-secondary);
  font-size: 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.btn-icon:active {
  transform: scale(0.9);
  background: var(--bg-hover);
}

/* ═══ BOTTOM NAV ═══ */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 200;
  display: flex;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  height: var(--nav-height);
  padding-bottom: env(safe-area-inset-bottom, 0);
}

.nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 8px 4px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.2s;
  font-size: 10px;
  font-weight: 500;
}

.nav-item.active {
  color: var(--accent);
}

.nav-item:active {
  transform: scale(0.95);
}

.nav-icon {
  font-size: 22px;
  line-height: 1;
}

.nav-label {
  font-size: 10px;
}

/* ═══ CONTENT ═══ */
.content {
  flex: 1;
  padding: 16px;
  max-width: 800px;
  margin: 0 auto;
  width: 100%;
}

.tab-content {
  display: none;
  animation: fadeIn 0.3s ease;
}

.tab-content.active {
  display: block;
}

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

/* ═══ STATS GRID ═══ */
.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 16px;
}

.stat-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 16px;
  border: 1px solid var(--border);
  position: relative;
  overflow: hidden;
}

.stat-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: var(--accent);
  opacity: 0.5;
}

.stat-card:nth-child(1)::before { background: var(--accent); }
.stat-card:nth-child(2)::before { background: var(--green); }
.stat-card:nth-child(3)::before { background: var(--yellow); }
.stat-card:nth-child(4)::before { background: var(--orange); }

.stat-label {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.stat-value {
  font-size: 24px;
  font-weight: 700;
}

.stat-card--loading .stat-value {
  color: var(--text-muted);
}

/* ═══ CARDS ═══ */
.card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
  border: 1px solid var(--border);
}

.card-title {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 12px;
  color: var(--text-primary);
}

.text-muted {
  color: var(--text-muted);
  font-size: 14px;
}

/* ═══ MINI CHART ═══ */
.mini-chart {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  height: 80px;
  padding-top: 8px;
}

.chart-bar {
  flex: 1;
  border-radius: 4px 4px 0 0;
  min-height: 8px;
  background: var(--accent);
  opacity: 0.7;
  transition: opacity 0.2s;
  position: relative;
}

.chart-bar:hover {
  opacity: 1;
}

.chart-bar-label {
  position: absolute;
  bottom: -18px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 8px;
  color: var(--text-muted);
  white-space: nowrap;
}

.chart-bar-value {
  position: absolute;
  top: -16px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 9px;
  color: var(--text-secondary);
  font-weight: 600;
  white-space: nowrap;
}

/* ═══ TABLE ═══ */
.table-responsive {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 0 -16px;
  padding: 0 16px;
}

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.table th {
  text-align: left;
  padding: 10px 8px;
  color: var(--text-muted);
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  position: sticky;
  top: 0;
  background: var(--bg-card);
}

.table td {
  padding: 10px 8px;
  border-bottom: 1px solid rgba(30, 58, 95, 0.5);
  white-space: nowrap;
}

.table tbody tr {
  transition: background 0.2s;
}

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

/* ═══ FILTERS ═══ */
.filters {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.filter-input {
  flex: 1;
  min-width: 120px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  color: var(--text-primary);
  font-size: 14px;
  outline: none;
  transition: border 0.2s;
}

.filter-input:focus {
  border-color: var(--accent);
}

.filter-input::placeholder {
  color: var(--text-muted);
}

/* ═══ BADGE ═══ */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  background: var(--bg-hover);
  color: var(--text-secondary);
}

.registros-header, .morosidad-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

/* ═══ CLIENTES LIST ═══ */
.cliente-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid rgba(30, 58, 95, 0.5);
}

.cliente-item:last-child {
  border-bottom: none;
}

.cliente-nombre {
  font-weight: 600;
}

.cliente-meta {
  font-size: 12px;
  color: var(--text-muted);
}

.cliente-status {
  font-size: 12px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 12px;
}

.status-ok { color: var(--green); }
.status-warn { color: var(--yellow); }
.status-moroso { color: var(--red); }

/* ═══ MOROSIDAD ═══ */
.morosidad-section {
  margin-bottom: 12px;
}

.morosidad-section:last-child {
  margin-bottom: 0;
}

.morosidad-section h4 {
  font-size: 14px;
  margin-bottom: 8px;
}

.morosidad-item {
  display: flex;
  justify-content: space-between;
  padding: 6px 0;
  font-size: 14px;
}

.morosidad-dias {
  font-weight: 600;
}

/* ═══ INFO GRID ═══ */
.info-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.info-item {
  padding: 8px;
  background: var(--bg-secondary);
  border-radius: var(--radius-sm);
  text-align: center;
}

.info-item .info-value {
  font-size: 20px;
  font-weight: 700;
  display: block;
}

.info-item .info-label {
  font-size: 11px;
  color: var(--text-muted);
}

/* ═══ LOADING ═══ */
.loading-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(10, 22, 40, 0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 999;
}

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

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

/* ═══ FOOTER ═══ */
.footer {
  text-align: center;
  padding: 20px 16px;
  font-size: 12px;
  color: var(--text-muted);
}

.footer-update {
  display: block;
  margin-top: 4px;
  font-size: 11px;
}

/* ═══ RESPONSIVE ═══ */
@media (min-width: 600px) {
  .stats-grid {
    grid-template-columns: repeat(4, 1fr);
  }

  .info-grid {
    grid-template-columns: repeat(4, 1fr);
  }

  .content {
    padding: 24px;
  }

  .header {
    padding: 12px 24px;
  }
}

/* ═══ STATUS COLORS ═══ */
.text-green { color: var(--green); }
.text-yellow { color: var(--yellow); }
.text-orange { color: var(--orange); }
.text-red { color: var(--red); }
.text-accent { color: var(--accent); }

/* ═══ PULL-TO-REFRESH hint ═══ */
.pull-hint {
  text-align: center;
  padding: 8px;
  font-size: 11px;
  color: var(--text-muted);
  opacity: 0;
  transition: opacity 0.3s;
}

/* ═══════════════════════════════════════════
   🔐 LOGIN
   ═══════════════════════════════════════════ */
.login-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-primary);
}

.login-box {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 40px 32px;
  width: 90%;
  max-width: 360px;
  text-align: center;
}

.login-icon {
  font-size: 48px;
  margin-bottom: 8px;
}

.login-title {
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 4px;
  background: linear-gradient(135deg, var(--accent), var(--accent-light));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.login-subtitle {
  color: var(--text-muted);
  font-size: 14px;
  margin-bottom: 20px;
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.login-input {
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-secondary);
  color: var(--text-primary);
  font-size: 16px;
  text-align: center;
  outline: none;
  transition: border 0.2s;
}

.login-input:focus {
  border-color: var(--accent);
}

.login-btn {
  padding: 14px;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: white;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.2s;
}

.login-btn:active {
  opacity: 0.8;
}

.login-error {
  color: var(--red);
  font-size: 13px;
  min-height: 18px;
}

/* ═══════════════════════════════════════════
   📋 MODAL
   ═══════════════════════════════════════════ */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 5000;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgba(0,0,0,0.6);
  animation: fadeIn 0.2s ease;
}

.modal-box {
  background: var(--bg-secondary);
  border-radius: var(--radius) var(--radius) 0 0;
  width: 100%;
  max-width: 500px;
  max-height: 90vh;
  overflow-y: auto;
  padding: 20px;
  animation: slideUp 0.25s ease;
}

.modal-confirm {
  max-width: 380px;
  text-align: center;
}

@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.modal-title {
  font-size: 18px;
  font-weight: 600;
}

.modal-close {
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 50%;
  background: var(--bg-card);
  color: var(--text-muted);
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.form-label {
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 2px;
}

.form-input {
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  color: var(--text-primary);
  font-size: 15px;
  outline: none;
  transition: border 0.2s;
}

.form-input:focus {
  border-color: var(--accent);
}

.form-input::placeholder {
  color: var(--text-muted);
}

.form-error {
  color: var(--red);
  font-size: 13px;
  text-align: center;
}

.modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 4px;
}

.btn-cancel {
  flex: 1;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-secondary);
  font-size: 15px;
  cursor: pointer;
}

.btn-save {
  flex: 2;
  padding: 12px;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: white;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}

.btn-delete-confirm {
  flex: 2;
  padding: 12px;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--red);
  color: white;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}

.confirm-text {
  color: var(--text-secondary);
  margin-bottom: 16px;
  font-size: 15px;
  padding: 0 8px;
}

/* ═══════════════════════════════════════════
   📈 INCOME CHART
   ═══════════════════════════════════════════ */
.income-chart {
  display: flex;
  align-items: flex-end;
  gap: 4px;
  height: 160px;
  padding: 8px 0;
  overflow-x: auto;
}

.ibar-wrap {
  flex: 1;
  min-width: 32px;
  display: flex;
  flex-direction: column;
  align-items: center;
  height: 100%;
  justify-content: flex-end;
}

.ibar {
  width: 100%;
  border-radius: 4px 4px 0 0;
  min-height: 4px;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  position: relative;
  transition: opacity 0.2s;
}

.ibar-value {
  font-size: 8px;
  color: var(--text-secondary);
  white-space: nowrap;
  position: absolute;
  top: -14px;
  font-weight: 600;
}

.ibar-label {
  font-size: 8px;
  color: var(--text-muted);
  margin-top: 2px;
  white-space: nowrap;
}

.income-row {
  display: flex;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px solid rgba(30,58,95,0.3);
  font-size: 14px;
}

.income-row:last-child {
  border-bottom: none;
}

/* ═══════════════════════════════════════════
   📋 ACTION BUTTONS (table)
   ═══════════════════════════════════════════ */
.action-cell {
  white-space: nowrap;
  text-align: right;
}

.btn-row-edit, .btn-row-del {
  padding: 4px 6px;
  border: none;
  border-radius: 4px;
  background: transparent;
  font-size: 14px;
  cursor: pointer;
  transition: background 0.2s;
}

.btn-row-edit:active, .btn-row-del:active {
  background: var(--bg-hover);
}

/* ═══ DESKTOP ═══ */
@media (min-width: 600px) {
  .modal-overlay {
    align-items: center;
  }
  .modal-box {
    border-radius: var(--radius);
    max-height: 80vh;
  }
}

/* ═══ TOAST ═══ */
.toast {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 9999;
  padding: 12px 24px;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 600;
  box-shadow: 0 4px 20px rgba(0,0,0,0.4);
  animation: slideUp 0.3s ease;
  max-width: 90vw;
  text-align: center;
}

.toast-success { background: #065f46; color: #d1fae5; }
.toast-info { background: var(--bg-card); color: var(--text-primary); border: 1px solid var(--border); }

/* ═══ TEXTAREA ═══ */
textarea.form-input {
  resize: vertical;
  min-height: 60px;
  font-family: inherit;
}
