/* ── Grupo4 — Gestoría de Facturas ── */
/* Tablet-first design */

:root {
  --bg: #f1f5f9;
  --panel: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --brand: #1e40af;
  --brand-light: #3b82f6;
  --brand-bg: #eff6ff;
  --ok: #16a34a;
  --ok-bg: #dcfce7;
  --warn: #d97706;
  --warn-bg: #fef3c7;
  --err: #dc2626;
  --err-bg: #fee2e2;
  --touch-min: 48px;
  --radius: 12px;
  --radius-sm: 8px;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

/* ── Layout ── */
#app {
  max-width: 960px;
  margin: 0 auto;
  padding: 0 16px;
  min-height: 100vh;
}

/* ── Login ── */
.login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 24px;
}
.login-box {
  background: var(--panel);
  border-radius: var(--radius);
  padding: 40px 32px;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 4px 24px rgba(0,0,0,.08);
}
.login-box h1 {
  font-size: 1.5rem;
  text-align: center;
  margin: 0 0 8px;
  color: var(--brand);
}
.login-box p {
  text-align: center;
  color: var(--muted);
  margin: 0 0 24px;
  font-size: 0.95rem;
}
.login-box input {
  display: block;
  width: 100%;
  padding: 14px 16px;
  font-size: 1rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  margin-bottom: 12px;
  outline: none;
  transition: border-color .15s;
}
.login-box input:focus { border-color: var(--brand-light); }
.login-box .btn-login {
  width: 100%;
  padding: 14px;
  font-size: 1.05rem;
  font-weight: 600;
  background: var(--brand);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  min-height: var(--touch-min);
  transition: background .15s;
}
.login-box .btn-login:active { background: #1e3a8a; }
.login-msg {
  text-align: center;
  color: var(--err);
  margin-top: 12px;
  min-height: 20px;
  font-size: 0.9rem;
}

/* ── Header ── */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 0;
  border-bottom: 1px solid var(--line);
  margin-bottom: 16px;
}
.app-header h1 {
  font-size: 1.25rem;
  margin: 0;
  color: var(--brand);
  font-weight: 700;
}
.app-header .user-info {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 0.9rem;
  color: var(--muted);
}
.btn-logout {
  padding: 8px 16px;
  font-size: 0.85rem;
  background: transparent;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--muted);
  min-height: 36px;
}

/* ── Back button ── */
.btn-back {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 16px;
  font-size: 0.95rem;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--text);
  min-height: var(--touch-min);
  margin-bottom: 16px;
}
.btn-back:active { background: var(--bg); }

/* ── Stats banner ── */
.stats-banner {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}
.stat-chip {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 12px 20px;
  border-radius: var(--radius-sm);
  min-width: 100px;
  flex: 1;
}
.stat-chip .stat-value {
  font-size: 1.5rem;
  font-weight: 700;
  line-height: 1.2;
}
.stat-chip .stat-label {
  font-size: 0.8rem;
  margin-top: 2px;
  opacity: 0.8;
}
.stat-pending { background: var(--warn-bg); color: #92400e; }
.stat-done { background: var(--ok-bg); color: #166534; }
.stat-error { background: var(--err-bg); color: #991b1b; }
.stat-money { background: var(--brand-bg); color: var(--brand); }

/* ── Client cards grid ── */
.clients-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.client-card {
  background: var(--panel);
  border-radius: var(--radius);
  padding: 20px;
  cursor: pointer;
  border: 2px solid transparent;
  transition: border-color .15s, box-shadow .15s;
  min-height: 100px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  box-shadow: 0 1px 4px rgba(0,0,0,.05);
}
.client-card:active { border-color: var(--brand-light); }
.client-card .client-name {
  font-size: 1.1rem;
  font-weight: 600;
  margin: 0 0 4px;
}
.client-card .client-cif {
  font-size: 0.85rem;
  color: var(--muted);
  margin: 0 0 12px;
}
.client-card .client-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 20px;
  font-size: 0.85rem;
  font-weight: 600;
}
.badge-pending { background: var(--warn-bg); color: #92400e; }
.badge-ok { background: var(--ok-bg); color: #166534; }

.client-card-unassigned {
  border: 2px dashed var(--warn);
  background: #fffbeb;
}

/* ── Filters row ── */
.filters-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 16px;
  align-items: center;
}
.filters-row input, .filters-row select {
  padding: 10px 12px;
  font-size: 0.9rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  min-height: 42px;
  flex: 1;
  min-width: 140px;
}
.filters-row .btn-filter {
  padding: 10px 20px;
  font-size: 0.9rem;
  font-weight: 600;
  background: var(--brand);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  min-height: 42px;
}

/* ── Invoice cards (pending list) ── */
.invoice-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.invoice-card {
  background: var(--panel);
  border-radius: var(--radius-sm);
  padding: 16px;
  display: flex;
  align-items: center;
  gap: 16px;
  box-shadow: 0 1px 3px rgba(0,0,0,.04);
  transition: transform .3s ease, opacity .3s ease, background .2s;
  cursor: pointer;
  min-height: 72px;
}
.invoice-card.slide-out {
  transform: translateX(100%);
  opacity: 0;
  max-height: 0;
  padding: 0 16px;
  margin: 0;
  overflow: hidden;
}
.invoice-card.flash-green {
  background: var(--ok-bg);
}
.invoice-card .inv-info {
  flex: 1;
  min-width: 0;
}
.invoice-card .inv-emisor {
  font-weight: 600;
  font-size: 1rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.invoice-card .inv-meta {
  font-size: 0.85rem;
  color: var(--muted);
  margin-top: 2px;
}
.invoice-card .inv-amount {
  font-size: 1.15rem;
  font-weight: 700;
  white-space: nowrap;
  min-width: 90px;
  text-align: right;
}

/* Checkbox contabilizar */
.check-contabilizar {
  width: var(--touch-min);
  height: var(--touch-min);
  border: 2px solid var(--line);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: background .15s, border-color .15s;
  font-size: 1.3rem;
  color: transparent;
  user-select: none;
  -webkit-user-select: none;
}
.check-contabilizar:active {
  background: var(--ok-bg);
  border-color: var(--ok);
  color: var(--ok);
}

/* Unassigned indicator */
.inv-unassigned {
  display: inline-block;
  background: var(--warn-bg);
  color: #92400e;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 600;
  margin-left: 8px;
}

/* ── Historial ── */
.historial-card {
  background: var(--panel);
  border-radius: var(--radius-sm);
  padding: 16px;
  display: flex;
  align-items: center;
  gap: 16px;
  box-shadow: 0 1px 3px rgba(0,0,0,.04);
  min-height: 72px;
  border-left: 4px solid var(--ok);
}
.historial-card .inv-info { flex: 1; }
.btn-revertir {
  padding: 10px 16px;
  font-size: 0.85rem;
  font-weight: 600;
  background: transparent;
  border: 1px solid var(--err);
  border-radius: var(--radius-sm);
  color: var(--err);
  cursor: pointer;
  min-height: var(--touch-min);
  white-space: nowrap;
}
.btn-revertir:active { background: var(--err-bg); }

/* ── Section header ── */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.section-header h2 {
  font-size: 1.1rem;
  margin: 0;
  color: var(--text);
}
.section-header .section-count {
  font-size: 0.9rem;
  color: var(--muted);
}

/* ── Tabs ── */
.tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 16px;
  background: var(--bg);
  padding: 4px;
  border-radius: var(--radius-sm);
}
.tab {
  flex: 1;
  padding: 10px 16px;
  text-align: center;
  font-size: 0.9rem;
  font-weight: 600;
  border: none;
  background: transparent;
  border-radius: 6px;
  cursor: pointer;
  color: var(--muted);
  min-height: var(--touch-min);
}
.tab.active {
  background: var(--panel);
  color: var(--text);
  box-shadow: 0 1px 3px rgba(0,0,0,.1);
}

/* ── Toast ── */
#toast-container {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}
.toast {
  background: #1e293b;
  color: #fff;
  padding: 14px 20px;
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  display: flex;
  align-items: center;
  gap: 16px;
  box-shadow: 0 8px 24px rgba(0,0,0,.2);
  pointer-events: auto;
  animation: toast-in .3s ease;
  max-width: 90vw;
}
.toast.toast-out { animation: toast-out .3s ease forwards; }
.toast .toast-text { flex: 1; }
.toast .btn-undo {
  padding: 8px 16px;
  font-size: 0.9rem;
  font-weight: 700;
  background: rgba(255,255,255,.15);
  color: #fff;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  white-space: nowrap;
  min-height: 40px;
}
.toast .btn-undo:active { background: rgba(255,255,255,.25); }

@keyframes toast-in {
  from { transform: translateY(20px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}
@keyframes toast-out {
  from { transform: translateY(0); opacity: 1; }
  to { transform: translateY(20px); opacity: 0; }
}

/* ── Modal ── */
#modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 5000;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
#modal-overlay.active { display: flex; }
.modal {
  background: var(--panel);
  border-radius: var(--radius);
  width: 100%;
  max-width: 900px;
  max-height: 90vh;
  overflow: auto;
  box-shadow: 0 16px 48px rgba(0,0,0,.15);
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--line);
}
.modal-header h3 { margin: 0; font-size: 1.1rem; }
.modal-close {
  width: 40px;
  height: 40px;
  border: none;
  background: transparent;
  font-size: 1.4rem;
  cursor: pointer;
  color: var(--muted);
  border-radius: var(--radius-sm);
}
.modal-body { padding: 20px; }

/* Detail split layout */
.detail-split {
  display: grid;
  grid-template-columns: 2fr 3fr;
  gap: 20px;
  min-height: 400px;
}
@media (max-width: 700px) {
  .detail-split { grid-template-columns: 1fr; }
}
.detail-data { display: flex; flex-direction: column; gap: 12px; }
.detail-row {
  display: flex;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
  font-size: 0.95rem;
}
.detail-row .label { color: var(--muted); }
.detail-row .value { font-weight: 600; text-align: right; }
.detail-total {
  font-size: 1.3rem;
  font-weight: 700;
  text-align: center;
  padding: 16px;
  background: var(--brand-bg);
  border-radius: var(--radius-sm);
  color: var(--brand);
}
.detail-pdf {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  overflow: hidden;
  min-height: 400px;
}
.detail-pdf iframe {
  width: 100%;
  height: 100%;
  min-height: 400px;
  border: none;
}

/* Detail actions */
.detail-actions {
  display: flex;
  gap: 12px;
  padding: 16px 20px;
  border-top: 1px solid var(--line);
}
.btn-action {
  flex: 1;
  padding: 14px;
  font-size: 1rem;
  font-weight: 600;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  min-height: var(--touch-min);
  transition: opacity .15s;
}
.btn-action:active { opacity: .8; }
.btn-contabilizar { background: var(--ok); color: #fff; }
.btn-descartar { background: transparent; border: 1px solid var(--muted); color: var(--muted); }
.btn-asignar { background: var(--brand); color: #fff; }

/* Assign select */
.assign-select {
  padding: 10px;
  font-size: 0.95rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  width: 100%;
  margin-top: 8px;
  min-height: var(--touch-min);
}

/* Confidence dot */
.conf-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-right: 4px;
}
.conf-high { background: var(--ok); }
.conf-med { background: var(--warn); }
.conf-low { background: var(--err); }

/* ── Empty state ── */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--muted);
}
.empty-state .empty-icon { font-size: 3rem; margin-bottom: 12px; }
.empty-state p { font-size: 1rem; margin: 0; }

/* ── Utilities ── */
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); }
.mb-16 { margin-bottom: 16px; }
.text-center { text-align: center; }
.text-muted { color: var(--muted); }
.text-sm { font-size: 0.85rem; }
