/* ============================================================
   Manatus CRM — sistema visual
   Paleta: profundidad marina (sidebar) + superficie clara (contenido)
   con dos acentos funcionales: teal (identidad) y ámbar/coral (alertas
   de vencimiento). La idea del "radar" es el elemento distintivo: una
   vista que hace visible, de un vistazo, lo que necesita atención.
   ============================================================ */

:root {
  --navy-950: #0B1826;
  --navy-900: #0F1F30;
  --navy-800: #16293D;
  --teal-500: #17A2A2;
  --teal-400: #2DBFBF;
  --teal-100: #E3F6F6;
  --amber-500: #E8A33D;
  --amber-100: #FBEDD6;
  --coral-500: #E15B4F;
  --coral-100: #FBE4E1;
  --ink-900: #16232E;
  --ink-600: #4C5D6B;
  --ink-400: #8494A0;
  --surface-0: #F5F7F8;
  --surface-1: #FFFFFF;
  --border: #E3E8EB;
  --radius: 10px;
  --font-display: 'Space Grotesk', sans-serif;
  --font-body: 'Inter', sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  font-family: var(--font-body);
  color: var(--ink-900);
  background: var(--surface-0);
  -webkit-font-smoothing: antialiased;
}

button { font-family: inherit; cursor: pointer; }

.app {
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: 100vh;
}

/* ---------- Sidebar ---------- */
.sidebar {
  background: linear-gradient(180deg, var(--navy-950), var(--navy-900) 60%, var(--navy-800));
  color: #DCE6EC;
  padding: 28px 20px;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 40px;
}

.brand-mark {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--teal-400), var(--teal-500));
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 18px;
  color: #06222A;
  flex-shrink: 0;
}

.brand-text { display: flex; flex-direction: column; line-height: 1.25; }
.brand-text strong { font-family: var(--font-display); font-size: 16px; letter-spacing: 0.01em; }
.brand-text span { font-size: 12px; color: #93A6B3; }

.nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  background: transparent;
  border: none;
  color: #B7C4CC;
  text-align: left;
  padding: 11px 12px;
  border-radius: 8px;
  font-size: 14.5px;
  font-weight: 500;
  transition: background 0.15s ease, color 0.15s ease;
}

.nav-dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: #435566;
  transition: background 0.15s ease, box-shadow 0.15s ease;
}

.nav-item:hover { background: rgba(255,255,255,0.06); color: #fff; }

.nav-item.active {
  background: rgba(45, 191, 191, 0.14);
  color: #fff;
}
.nav-item.active .nav-dot {
  background: var(--teal-400);
  box-shadow: 0 0 0 3px rgba(45,191,191,0.22);
}

.sidebar-foot { font-size: 11.5px; color: #5D7280; letter-spacing: 0.02em; }
.sidebar-logout { margin-top: 8px; }

/* ---------- Main ---------- */
.main { padding: 36px 44px 60px; max-width: 1120px; }

.view { display: none; }
.view.active { display: block; animation: fade-in 0.18s ease; }

@keyframes fade-in {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

.view-header { margin-bottom: 28px; position: relative; }
.view-header h1 {
  font-family: var(--font-display);
  font-size: 26px;
  margin: 0 0 4px;
  letter-spacing: -0.01em;
}
.view-header p { margin: 0; color: var(--ink-600); font-size: 14.5px; }

.btn-primary {
  position: absolute;
  right: 0;
  top: 0;
  background: var(--ink-900);
  color: #fff;
  border: none;
  padding: 10px 16px;
  border-radius: 8px;
  font-size: 13.5px;
  font-weight: 600;
  transition: background 0.15s ease;
}
.btn-primary:hover { background: var(--teal-500); }

/* ---------- Stat row ---------- */
.stat-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin-bottom: 28px; }
.stat-card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.stat-label { font-size: 12.5px; color: var(--ink-400); font-weight: 500; }
.stat-value { font-family: var(--font-display); font-size: 24px; font-weight: 600; }

/* ---------- Panels & cobro list ---------- */
.panel {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 20px;
  overflow: hidden;
}
.panel-head { padding: 16px 20px 8px; }
.panel-head h2 { font-size: 15px; margin: 0; font-family: var(--font-display); }

.cobro-list { padding: 4px 12px 14px; }
.cobro-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 8px;
  border-bottom: 1px solid var(--border);
}
.cobro-row:last-child { border-bottom: none; }

.cobro-main { display: flex; flex-direction: column; gap: 2px; }
.cobro-cliente { font-weight: 600; font-size: 14px; }
.cobro-concepto { font-size: 12.5px; color: var(--ink-600); }

.cobro-side { display: flex; align-items: center; gap: 14px; }
.cobro-monto { font-family: var(--font-display); font-size: 14.5px; font-weight: 600; }

.badge {
  font-size: 11.5px;
  font-weight: 600;
  padding: 4px 9px;
  border-radius: 100px;
  white-space: nowrap;
}
.badge-vencido { background: var(--coral-100); color: var(--coral-500); }
.badge-porvencer { background: var(--amber-100); color: #92671C; }
.badge-ok { background: var(--teal-100); color: #0E6E6E; }
.badge-neutral { background: #EEF1F3; color: var(--ink-600); }

.empty-state {
  padding: 22px 8px;
  color: var(--ink-400);
  font-size: 13.5px;
  text-align: center;
}

.btn-mini {
  background: var(--teal-500);
  color: #fff;
  border: none;
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 12.5px;
  font-weight: 600;
}
.btn-mini:hover { background: var(--teal-400); }

/* ---------- Tables ---------- */
.table-wrap {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
table { width: 100%; border-collapse: collapse; }
thead th {
  text-align: left;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--ink-400);
  font-weight: 600;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: #FAFBFC;
}
tbody td {
  padding: 13px 16px;
  font-size: 13.5px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #FAFCFC; }

.row-actions { display: flex; gap: 8px; justify-content: flex-end; }
.icon-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  width: 28px; height: 28px;
  font-size: 13px;
  color: var(--ink-600);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.icon-btn:hover { border-color: var(--teal-500); color: var(--teal-500); }
.icon-btn.danger:hover { border-color: var(--coral-500); color: var(--coral-500); }

/* ---------- Modal ---------- */
.modal-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(11, 24, 38, 0.45);
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 20px;
}
.modal-backdrop.open { display: flex; }

.modal {
  background: var(--surface-1);
  border-radius: 14px;
  width: 100%;
  max-width: 460px;
  max-height: 88vh;
  overflow-y: auto;
  box-shadow: 0 24px 60px rgba(11,24,38,0.25);
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 22px;
  border-bottom: 1px solid var(--border);
}
.modal-head h3 { margin: 0; font-family: var(--font-display); font-size: 17px; }
.modal-close {
  background: none; border: none; font-size: 22px; line-height: 1;
  color: var(--ink-400);
}

#modal-form { padding: 20px 22px 22px; display: flex; flex-direction: column; gap: 14px; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 12.5px; font-weight: 600; color: var(--ink-600); }
.field input, .field select, .field textarea {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 11px;
  font-size: 14px;
  font-family: inherit;
  color: var(--ink-900);
  background: var(--surface-0);
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none;
  border-color: var(--teal-500);
  background: #fff;
}
.field textarea { resize: vertical; min-height: 60px; }

.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.modal-submit {
  margin-top: 6px;
  background: var(--teal-500);
  color: #fff;
  border: none;
  padding: 11px;
  border-radius: 8px;
  font-weight: 600;
  font-size: 14px;
}
.modal-submit:hover { background: var(--teal-400); }

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--ink-900);
  color: #fff;
  padding: 11px 20px;
  border-radius: 8px;
  font-size: 13.5px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 100;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- Responsive ---------- */
@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: relative;
    height: auto;
    flex-direction: row;
    align-items: center;
    padding: 16px 20px;
  }
  .brand { margin-bottom: 0; }
  .nav { flex-direction: row; overflow-x: auto; }
  .sidebar-foot { display: none; }
  .main { padding: 24px 18px 50px; }
  .stat-row { grid-template-columns: 1fr; }
  .btn-primary { position: static; margin-top: 12px; }
  .field-row { grid-template-columns: 1fr; }
  table, thead, tbody, tr, th, td { font-size: 12.5px; }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  .view.active, .toast { animation: none; transition: none; }
}

/* ---------- Login ---------- */
.login-body { background: linear-gradient(180deg, var(--navy-950), var(--navy-900) 60%, var(--navy-800)); }

.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.login-card {
  background: var(--surface-1);
  border-radius: 16px;
  padding: 32px 28px;
  width: 100%;
  max-width: 340px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  box-shadow: 0 24px 60px rgba(11,24,38,0.35);
}

.login-brand { margin-bottom: 4px; }
.login-brand .brand-text strong { color: var(--ink-900); }
.login-brand .brand-text span { color: var(--ink-600); }

.login-error {
  margin: 0;
  font-size: 13px;
  color: var(--coral-500);
}

.login-submit { margin-top: 0; }
