/* ============================================================
   app.css — Sistema de Retenciones
   Fuentes: DM Sans + DM Mono (Google Fonts)
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=DM+Sans:opsz,wght@9..40,300;9..40,400;9..40,500;9..40,600&family=DM+Mono:wght@400;500&display=swap');

/* ── Reset básico ─────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --font:   'DM Sans',  sans-serif;
  --mono:   'DM Mono',  monospace;
  --radius: 8px;
  --radius-lg: 12px;

  /* Colores modo claro */
  --bg:      #ffffff;
  --bg2:     #f5f5f4;
  --bg3:     #eeece8;
  --ink:     #1a1916;
  --ink2:    #5f5e5a;
  --ink3:    #888780;
  --border:  rgba(0,0,0,.10);
  --border2: rgba(0,0,0,.18);

  --accent:    #185FA5;
  --accent-bg: #E6F1FB;
  --accent-lt: #B5D4F4;
  --accent-dk: #0C447C;

  --green:    #3B6D11;
  --green-bg: #EAF3DE;
  --amber:    #BA7517;
  --amber-bg: #FAEEDA;
  --red:      #A32D2D;
  --red-bg:   #FCEBEB;

  --shadow-sm: 0 1px 3px rgba(0,0,0,.08);
  --shadow:    0 2px 8px rgba(0,0,0,.10);
}

:root[data-theme='dark'] {
  --bg:      #1c1b18;
  --bg2:     #252420;
  --bg3:     #2e2d28;
  --ink:     #e8e6df;
  --ink2:    #9c9a92;
  --ink3:    #6e6c66;
  --border:  rgba(255,255,255,.10);
  --border2: rgba(255,255,255,.16);

  --accent:    #378ADD;
  --accent-bg: #0C2A44;
  --accent-lt: #185FA5;
  --accent-dk: #85B7EB;

  --green-bg: #1a2e0a;
  --amber-bg: #2e1e04;
  --red-bg:   #2e0f0f;
}

/* ── Base ─────────────────────────────────────────────────── */
html { font-size: 14px; -webkit-font-smoothing: antialiased; }

body {
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.6;
  color: var(--ink);
  background: var(--bg3);
  min-height: 100vh;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Topbar ───────────────────────────────────────────────── */
.topbar {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--bg);
  border-bottom: 0.5px solid var(--border);
  box-shadow: var(--shadow-sm);
}
.topbar-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 20px;
  height: 52px;
  display: flex;
  align-items: center;
  gap: 0;
}
.btn-back {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: none;
  background: var(--bg2);
  color: var(--ink);
  cursor: pointer;
  margin-right: 12px;
  transition: all 0.2s;
  flex-shrink: 0;
}
.btn-back:hover {
  background: var(--bg3);
  transform: translateX(-2px);
}
.topbar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  margin-right: 28px;
  color: var(--ink);
}
.topbar-logo {
  width: 30px; height: 30px;
  border-radius: 7px;
  background: var(--accent);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: -.01em;
  display: flex; align-items: center; justify-content: center;
}
.topbar-name {
  font-size: 13px;
  font-weight: 500;
  color: var(--ink);
  max-width: 180px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.topbar-nav {
  display: flex;
  align-items: center;
  gap: 2px;
  flex: 1;
}
.topbar-toggle {
  display: none;
  background: transparent;
  border: none;
  color: var(--ink);
  cursor: pointer;
  padding: 6px;
  margin-left: 10px;
}
.topbar-link {
  padding: 6px 12px;
  border-radius: var(--radius);
  font-size: 13px;
  color: var(--ink2);
  text-decoration: none;
  transition: background .12s, color .12s;
}
.mobile-logout { display: none; }
.topbar-link:hover { background: var(--bg2); color: var(--ink); text-decoration: none; }
.topbar-link.active { background: var(--accent-bg); color: var(--accent-dk); font-weight: 500; }
.topbar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-left: auto;
}
.topbar-user-name { font-size: 12px; color: var(--ink3); }

/* ── Page layout ──────────────────────────────────────────── */
.page-wrap {
  max-width: 1200px;
  margin: 0 auto;
  padding: 28px 20px 60px;
}
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
}
.page-title {
  font-size: 22px;
  font-weight: 500;
  color: var(--ink);
  line-height: 1.2;
}
.page-sub {
  font-size: 12px;
  color: var(--ink3);
  margin-top: 3px;
}
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 24px 0 12px;
}
.section-title {
  font-size: 11px;
  font-weight: 500;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--ink3);
}

/* ── Cards ────────────────────────────────────────────────── */
.card {
  background: var(--bg);
  border: 0.5px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: var(--shadow-sm);
}
.card.p0 { padding: 0; }
.card-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
}
.card-title { font-size: 14px; font-weight: 500; }
.card-step {
  width: 22px; height: 22px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}

/* ── Stats ────────────────────────────────────────────────── */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}
.stat-card {
  background: var(--bg);
  border: 0.5px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px 18px;
  box-shadow: var(--shadow-sm);
}
.stat-label { font-size: 11px; color: var(--ink3); margin-bottom: 6px; }
.stat-val   { font-size: 22px; font-weight: 500; font-family: var(--mono); color: var(--ink); line-height: 1; }
.stat-sub   { font-size: 11px; color: var(--ink3); margin-top: 4px; }

/* ── Retention list items ─────────────────────────────────── */
.ret-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 18px;
  border-bottom: 0.5px solid var(--border);
  cursor: pointer;
  transition: background .12s;
}
.ret-item:last-child { border-bottom: none; }
.ret-item:hover { background: var(--bg2); }
.ret-icon {
  width: 36px; height: 36px;
  border-radius: var(--radius);
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 600;
  flex-shrink: 0;
}
.ret-icon.iva  { background: var(--accent-bg); color: var(--accent-dk); }
.ret-icon.islr { background: var(--amber-bg);  color: var(--amber); }
.ret-info { flex: 1; min-width: 0; }
.ret-info-top { display: flex; align-items: center; gap: 8px; margin-bottom: 2px; }
.ret-num  { font-family: var(--mono); font-size: 13px; font-weight: 500; color: var(--ink); }
.ret-proveedor { font-size: 12px; color: var(--ink2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ret-right { text-align: right; flex-shrink: 0; }
.ret-monto { font-family: var(--mono); font-size: 13px; font-weight: 500; color: var(--ink); }
.ret-fecha { font-size: 11px; color: var(--ink3); margin-top: 2px; }

/* ── Badges ───────────────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center;
  padding: 2px 7px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 500;
  line-height: 1.5;
}
.badge-iva     { background: var(--accent-bg); color: var(--accent-dk); }
.badge-islr    { background: var(--amber-bg);  color: var(--amber);  }
.badge-done    { background: var(--green-bg);  color: var(--green);  }
.badge-pending { background: var(--amber-bg);  color: var(--amber);  }
.badge-info    { background: var(--accent-bg); color: var(--accent-dk); }

/* ── Buttons ──────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 14px;
  border-radius: var(--radius);
  border: 0.5px solid var(--border2);
  background: var(--bg);
  color: var(--ink);
  font-size: 13px;
  font-family: var(--font);
  font-weight: 400;
  cursor: pointer;
  text-decoration: none;
  transition: background .12s, border-color .12s, transform .08s;
  white-space: nowrap;
}
.btn:hover { background: var(--bg2); color: var(--ink); text-decoration: none; }
.btn:active { transform: scale(.98); }
.btn-primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.btn-primary:hover { background: var(--accent-dk); border-color: var(--accent-dk); color: #fff; }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-block { width: 100%; justify-content: center; }

/* ── Form elements ────────────────────────────────────────── */
.field { display: flex; flex-direction: column; gap: 5px; }
.field label {
  font-size: 12px;
  font-weight: 500;
  color: var(--ink2);
}
.field input, .field select, .field textarea {
  width: 100%;
  padding: 8px 10px;
  border: 0.5px solid var(--border2);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 13px;
  line-height: 1.5;
  transition: border-color .12s, box-shadow .12s;
  appearance: none;
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(24,95,165,.15);
}
.field input:disabled, .field input[readonly] {
  background: var(--bg2);
  color: var(--ink2);
}
.field-inline {
  padding: 6px 10px;
  border: 0.5px solid var(--border2);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 13px;
}
.form-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }
.form-grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.form-actions {
  display: flex;
  justify-content: flex-start;
  gap: 8px;
  margin-top: 16px;
}

/* ── Table ────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
.tbl {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.tbl th {
  text-align: left;
  padding: 9px 12px;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--ink3);
  border-bottom: 0.5px solid var(--border);
  white-space: nowrap;
  background: var(--bg2);
}
.tbl td {
  padding: 10px 12px;
  border-bottom: 0.5px solid var(--border);
  color: var(--ink2);
  vertical-align: middle;
}
.tbl tr:last-child td { border-bottom: none; }
.tbl tr:hover td     { background: var(--bg2); }
.tbl .row-selected td { background: var(--accent-bg); }
.tbl th.r, .tbl td.r { text-align: right; }
.tbl th.c, .tbl td.c { text-align: center; }
.tbl input[type=checkbox] { accent-color: var(--accent); width: 14px; height: 14px; cursor: pointer; }
.no-data { text-align: center; padding: 36px 20px; color: var(--ink3); font-size: 13px; }

/* ── Summary grid (totales retención) ────────────────────── */
.totales-layout { display: grid; grid-template-columns: 320px 1fr; gap: 20px; align-items: start; }
.summary-grid {
  display: grid;
  grid-template-columns: 1fr auto;
  border: 0.5px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}
.sg-label, .sg-val {
  padding: 9px 14px;
  border-bottom: 0.5px solid var(--border);
  font-size: 12px;
}
.sg-label { background: var(--bg2); color: var(--ink2); }
.sg-val   { background: var(--bg);  color: var(--ink);  text-align: right; }
.sg-label:last-of-type, .sg-val:last-of-type { border-bottom: none; }
.sg-label.total, .sg-val.total {
  background: var(--accent-bg);
  color: var(--accent-dk);
  font-weight: 500;
  border-bottom: none;
}
.sg-val.total { font-size: 14px; }

/* ── Helpers ──────────────────────────────────────────────── */
.mono   { font-family: var(--mono); }
.accent { color: var(--accent-dk); }
.bold   { font-weight: 500; }
.dash   { color: var(--ink3); }

/* ── Alerts ───────────────────────────────────────────────── */
.alert {
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 13px;
  margin-bottom: 16px;
  border: 0.5px solid transparent;
}
.alert-danger  { background: var(--red-bg);   color: var(--red);   border-color: rgba(162,45,45,.2); }
.alert-success { background: var(--green-bg); color: var(--green); border-color: rgba(59,109,17,.2); }
.alert-warning { background: var(--amber-bg); color: var(--amber); border-color: rgba(186,117,23,.2); }

/* ── Toast ────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9999;
  padding: 10px 16px;
  border-radius: var(--radius);
  font-size: 13px;
  background: var(--ink);
  color: var(--bg);
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(8px);
  transition: opacity .2s, transform .2s;
  pointer-events: none;
  max-width: 320px;
}
.toast.show { opacity: 1; transform: translateY(0); pointer-events: auto; }
.toast-error   { background: var(--red);   }
.toast-success { background: var(--green); }
.toast-warning { background: var(--amber); }

/* ── Filter form ──────────────────────────────────────────── */
.filter-form { display: flex; flex-direction: column; gap: 12px; }
.filter-actions { display: flex; gap: 8px; }

/* ── Login ────────────────────────────────────────────────── */
.login-body  { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: var(--bg3); }
.login-wrap  { width: 100%; max-width: 380px; padding: 20px; }
.login-card  { background: var(--bg); border: 0.5px solid var(--border); border-radius: var(--radius-lg); padding: 36px 32px; box-shadow: var(--shadow); }
.login-logo  { width: 44px; height: 44px; border-radius: 10px; background: var(--accent); color: #fff; font-size: 15px; font-weight: 600; display: flex; align-items: center; justify-content: center; margin: 0 auto 16px; }
.login-title { font-size: 18px; font-weight: 500; text-align: center; margin-bottom: 4px; }
.login-sub   { font-size: 12px; color: var(--ink3); text-align: center; margin-bottom: 20px; }
.login-form  { display: flex; flex-direction: column; gap: 14px; }
.login-hint  { font-size: 11px; color: var(--ink3); text-align: center; margin-top: 16px; }

/* ── Comprobante actions bar ──────────────────────────────── */
.comp-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  max-width: 980px;
  margin: 20px auto 12px;
  padding: 0 20px;
}

/* ── Responsive ───────────────────────────────────────────── */
@media (max-width: 768px) {
  .page-wrap { padding: 20px 10px; }
  .form-grid-2, .form-grid-3, .form-grid-4 { grid-template-columns: 1fr; }
  .totales-layout { grid-template-columns: 1fr; }
  .stat-grid { grid-template-columns: 1fr 1fr; }
  
  .topbar-inner { flex-wrap: wrap; height: auto; min-height: 52px; padding: 5px 15px; justify-content: space-between; gap: 5px; }
  .topbar-brand { margin-right: 10px; flex-shrink: 1; }
  .topbar-toggle { display: flex; align-items: center; margin-left: 5px; order: 3; }
  .topbar-user { margin-left: auto; gap: 8px; order: 2; }
  .topbar-user-name { display: none; }
  .topbar-logout-desktop { display: none; }
  .mobile-logout { display: block; margin-top: 10px; color: var(--red) !important; font-weight: 500; border-top: 1px dashed var(--border); padding-top: 12px; }
  .topbar-nav { 
      display: none; 
      width: 100%; 
      flex-direction: column; 
      align-items: stretch;
      order: 4; 
      padding: 10px 0 10px; 
      margin-top: 5px;
      border-top: 0.5px solid var(--border); 
      gap: 6px;
  }
  .topbar-nav.active-mobile { display: flex; }

  /* Tablas más compactas en móvil */
  .tbl { font-size: 11px; }
  .tbl th { font-size: 10px; padding: 6px 8px; }
  .tbl td { padding: 6px 8px; }
}

/* ── Print ────────────────────────────────────────────────── */
@media print {
  .topbar, .comp-actions, .no-print { display: none !important; }
  body { background: #fff; }
  .comp-wrap { box-shadow: none; border: none; }
}