/* ===== Modelo 303 Snap — Dark-Slate Fintech Design System ===== */
:root {
  --bg: #0f172a;
  --bg-elevated: #1e293b;
  --bg-card: #162033;
  --bg-input: #0b1220;
  --border: rgba(148, 163, 184, 0.16);
  --border-strong: rgba(148, 163, 184, 0.28);

  --text: #f8fafc;
  --text-secondary: #cbd5e1;
  --text-muted: #94a3b8;

  --accent: #38bdf8;
  --accent-strong: #0ea5e9;
  --indigo: #6366f1;
  --mint: #10b981;
  --mint-bg: rgba(16, 185, 129, 0.14);
  --amber: #f59e0b;
  --amber-bg: rgba(245, 158, 11, 0.14);
  --rose: #f43f5e;
  --rose-bg: rgba(244, 63, 94, 0.14);

  --radius-sm: 10px;
  --radius-md: 16px;
  --radius-lg: 22px;
  --shadow: 0 12px 32px rgba(2, 6, 23, 0.45);
  --nav-height: 68px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

*, *::before, *::after {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, Helvetica, Arial, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  min-height: 100%;
  -webkit-font-smoothing: antialiased;
}

body {
  padding-bottom: calc(var(--nav-height) + var(--safe-bottom) + 92px);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.hidden {
  display: none !important;
}

.print-only {
  display: none;
}

/* ===== Header ===== */
.app-header {
  position: sticky;
  top: 0;
  z-index: 40;
  background: rgba(15, 23, 42, 0.88);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
  padding: calc(10px + env(safe-area-inset-top, 0px)) 16px 12px;
}

.header-top,
.period-bar,
.app-main {
  max-width: 780px;
  margin-left: auto;
  margin-right: auto;
}

.header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-icon {
  border-radius: 9px;
  flex-shrink: 0;
  box-shadow: 0 4px 12px rgba(56, 189, 248, 0.25);
}

.brand-title {
  margin: 0;
  font-size: 1.08rem;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.brand-sub {
  margin: 0;
  font-size: 0.74rem;
  color: var(--text-muted);
}

.ocr-badge {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 11px;
  border-radius: 999px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  color: var(--text-secondary);
  font-size: 0.76rem;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
}

.ocr-badge:hover {
  border-color: var(--accent);
}

.ocr-badge.gemini {
  border-color: rgba(56, 189, 248, 0.45);
  background: rgba(56, 189, 248, 0.12);
  color: #7dd3fc;
}

.ocr-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--mint);
  box-shadow: 0 0 8px var(--mint);
}

.ocr-badge.gemini .ocr-dot {
  background: var(--accent);
  box-shadow: 0 0 8px var(--accent);
}

/* Period Selector */
.period-bar {
  display: flex;
  align-items: center;
  gap: 10px;
}

.year-select {
  appearance: none;
  background: var(--bg-elevated);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 8px 28px 8px 12px;
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 9px center;
}

.quarter-pills {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  background: var(--bg-input);
  padding: 4px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

.quarter-pill {
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.86rem;
  font-weight: 700;
  padding: 7px 4px;
  border-radius: 7px;
  cursor: pointer;
  transition: all 0.18s ease;
}

.quarter-pill.active {
  background: linear-gradient(135deg, var(--accent-strong), var(--indigo));
  color: #ffffff;
  box-shadow: 0 3px 12px rgba(14, 165, 233, 0.35);
}

/* ===== Main & Tabs ===== */
.app-main {
  padding: 16px;
}

.tab-panel {
  display: none;
  animation: fadeIn 0.2s ease;
}

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

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

/* ===== KPI Grid ===== */
.kpi-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 14px;
}

.kpi-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px 15px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.kpi-resultado {
  grid-column: 1 / -1;
  background: linear-gradient(145deg, #1b2840, #121c2f);
  border-color: var(--border-strong);
}

.kpi-resultado.ingresar {
  border-color: rgba(244, 63, 94, 0.45);
  background: linear-gradient(145deg, rgba(244, 63, 94, 0.14), #162033 65%);
}

.kpi-resultado.compensar {
  border-color: rgba(16, 185, 129, 0.45);
  background: linear-gradient(145deg, rgba(16, 185, 129, 0.14), #162033 65%);
}

.kpi-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.kpi-label {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.casilla-tag {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--accent);
  background: rgba(56, 189, 248, 0.12);
  padding: 2px 7px;
  border-radius: 6px;
}

.kpi-value {
  font-size: 1.38rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}

.kpi-resultado .kpi-value {
  font-size: 1.75rem;
}

.kpi-result-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.result-pill {
  font-size: 0.74rem;
  font-weight: 800;
  letter-spacing: 0.05em;
  padding: 5px 11px;
  border-radius: 999px;
  background: rgba(148, 163, 184, 0.16);
  color: var(--text-secondary);
}

.result-pill.ingresar {
  background: var(--rose-bg);
  color: #fda4af;
  border: 1px solid rgba(244, 63, 94, 0.4);
}

.result-pill.compensar {
  background: var(--mint-bg);
  color: #6ee7b7;
  border: 1px solid rgba(16, 185, 129, 0.4);
}

.kpi-meta {
  font-size: 0.78rem;
  color: var(--text-muted);
}

/* ===== Export Bar ===== */
.export-bar {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 16px;
}

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border: none;
  border-radius: var(--radius-sm);
  padding: 11px 14px;
  font-size: 0.86rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.12s ease, opacity 0.15s ease, background 0.18s ease;
  text-decoration: none;
  white-space: nowrap;
}

.btn:active {
  transform: scale(0.97);
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent-strong), var(--indigo));
  color: #ffffff;
  box-shadow: 0 6px 18px rgba(14, 165, 233, 0.3);
}

.btn-secondary {
  background: var(--bg-elevated);
  color: var(--text);
  border: 1px solid var(--border-strong);
}

.btn-secondary:hover {
  border-color: var(--accent);
}

.btn-block {
  width: 100%;
  padding: 13px 16px;
  font-size: 0.94rem;
}

.btn-link {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 0.82rem;
  font-weight: 600;
  padding: 4px 0;
  cursor: pointer;
  text-decoration: underline;
}

.btn-link.danger {
  color: #fb7185;
}

.icon-btn {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text-secondary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.35rem;
  line-height: 1;
  cursor: pointer;
}

/* ===== Cards & AEAT Casillas Tables ===== */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px;
  margin-bottom: 14px;
}

.card-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.card-header.compact {
  align-items: center;
}

.card-header h2 {
  margin: 0;
  font-size: 0.98rem;
  font-weight: 700;
}

.card-subtitle {
  font-size: 0.76rem;
  color: var(--text-muted);
}

.table-wrap {
  overflow-x: auto;
  margin: 0 -4px;
  padding: 0 4px;
}

.casillas-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.casillas-table th {
  text-align: left;
  color: var(--text-muted);
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 0 6px 8px;
  border-bottom: 1px solid var(--border);
}

.casillas-table td {
  padding: 10px 6px;
  border-bottom: 1px solid rgba(148, 163, 184, 0.09);
  vertical-align: middle;
}

.casillas-table .num {
  text-align: right;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.casillas-table td.strong {
  font-weight: 700;
  color: var(--text);
}

.casillas-table tfoot .total-row td {
  border-bottom: none;
  border-top: 1px solid var(--border-strong);
  padding-top: 12px;
  font-weight: 800;
  font-size: 0.92rem;
}

.casilla-mini {
  display: inline-block;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.68rem;
  font-weight: 700;
  color: var(--text-muted);
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 1px 5px;
  margin-right: 4px;
  vertical-align: middle;
}

.casilla-mini.accent {
  color: #7dd3fc;
  border-color: rgba(56, 189, 248, 0.4);
  background: rgba(56, 189, 248, 0.14);
}

.casilla-mini.mint {
  color: #6ee7b7;
  border-color: rgba(16, 185, 129, 0.4);
  background: rgba(16, 185, 129, 0.14);
}

.casilla-inline {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.78rem;
  color: var(--text-muted);
}

.summary-rows {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.summary-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: 0.88rem;
  color: var(--text-secondary);
}

.summary-row .num {
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.summary-final {
  padding-top: 12px;
  margin-top: 2px;
  border-top: 1px solid var(--border-strong);
  font-size: 0.96rem;
  font-weight: 700;
  color: var(--text);
}

/* ===== Facturas Tab ===== */
.facturas-toolbar {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 14px;
}

.filter-chips {
  display: flex;
  gap: 8px;
  overflow-x: auto;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-muted);
  font-size: 0.84rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}

.chip.active {
  background: rgba(56, 189, 248, 0.16);
  border-color: rgba(56, 189, 248, 0.5);
  color: #e0f2fe;
}

.chip-count {
  font-size: 0.74rem;
  background: rgba(15, 23, 42, 0.6);
  padding: 1px 7px;
  border-radius: 999px;
}

.search-box {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0 12px;
  color: var(--text-muted);
}

.search-box input {
  width: 100%;
  background: transparent;
  border: none;
  color: var(--text);
  font-size: 0.92rem;
  padding: 11px 0;
  outline: none;
}

.invoices-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.invoice-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 13px;
  display: flex;
  gap: 12px;
  align-items: flex-start;
}

.invoice-thumb-btn {
  width: 56px;
  height: 70px;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--border-strong);
  background: var(--bg-input);
  padding: 0;
  flex-shrink: 0;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
}

.invoice-thumb-btn img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.invoice-thumb-btn.no-photo {
  cursor: default;
  border-style: dashed;
}

.invoice-body {
  flex: 1;
  min-width: 0;
}

.invoice-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}

.invoice-name {
  margin: 0;
  font-size: 0.94rem;
  font-weight: 700;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.invoice-total {
  font-size: 1rem;
  font-weight: 800;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.invoice-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin-top: 4px;
  font-size: 0.76rem;
  color: var(--text-muted);
}

.badge {
  display: inline-block;
  font-size: 0.68rem;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 6px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.badge-recibida {
  background: var(--mint-bg);
  color: #6ee7b7;
}

.badge-emitida {
  background: var(--amber-bg);
  color: #fcd34d;
}

.badge-inversion {
  background: rgba(99, 102, 241, 0.2);
  color: #a5b4fc;
}

.badge-abono {
  background: var(--rose-bg);
  color: #fda4af;
}

.invoice-thumb-btn.pdf-thumb {
  flex-direction: column;
  gap: 3px;
  text-decoration: none;
  background: rgba(244, 63, 94, 0.12);
  border-color: rgba(244, 63, 94, 0.4);
  color: #fda4af;
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.04em;
}

.invoice-total.negative {
  color: #fda4af;
}

/* Learned OCR Contacts */
.contacts-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.contact-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.contact-info {
  min-width: 0;
  flex: 1;
}

.contact-name {
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.contact-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 3px;
  font-size: 0.74rem;
  color: var(--text-muted);
}

/* Modal Tags, PDF Thumb & Abono Toggle */
.modal-tags-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-top: 3px;
}

.learned-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.72rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--mint-bg);
  color: #6ee7b7;
  border: 1px solid rgba(16, 185, 129, 0.45);
}

.pdf-thumb-box {
  width: 52px;
  height: 64px;
  border-radius: 7px;
  background: rgba(244, 63, 94, 0.14);
  border: 1px solid rgba(244, 63, 94, 0.45);
  color: #fda4af;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  font-weight: 800;
  letter-spacing: 0.05em;
  flex-shrink: 0;
}

.scan-pdf-preview {
  width: 100%;
  height: 100%;
  background: rgba(244, 63, 94, 0.12);
  color: #fda4af;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-weight: 800;
  letter-spacing: 0.06em;
}

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

.amounts-header .field-mini-label {
  margin-bottom: 0;
}

.abono-toggle {
  border: 1px solid var(--border-strong);
  background: var(--bg-elevated);
  color: var(--text-secondary);
  border-radius: 999px;
  padding: 4px 12px;
  font-size: 0.76rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.15s ease;
}

.abono-toggle.active {
  background: var(--rose-bg);
  color: #fda4af;
  border-color: rgba(244, 63, 94, 0.55);
}

.invoice-concepto {
  margin: 5px 0 0;
  font-size: 0.8rem;
  color: var(--text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.invoice-bottom {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 9px;
  padding-top: 8px;
  border-top: 1px solid rgba(148, 163, 184, 0.1);
}

.invoice-tax-line {
  font-size: 0.76rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.invoice-actions {
  display: flex;
  gap: 6px;
}

.mini-btn {
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text-secondary);
  border-radius: 8px;
  padding: 5px 10px;
  font-size: 0.76rem;
  font-weight: 600;
  cursor: pointer;
}

.mini-btn.danger {
  color: #fda4af;
  border-color: rgba(244, 63, 94, 0.3);
}

/* Empty state */
.empty-state {
  text-align: center;
  padding: 36px 20px;
  background: var(--bg-card);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-md);
}

.empty-icon {
  color: var(--accent);
  margin-bottom: 10px;
}

.empty-state h3 {
  margin: 0 0 6px;
  font-size: 1.05rem;
}

.empty-state p {
  margin: 0 0 18px;
  font-size: 0.86rem;
  color: var(--text-muted);
}

.empty-actions {
  display: flex;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
}

/* ===== Forms & Ajustes ===== */
.form-group {
  margin-bottom: 13px;
}

.form-group label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 5px;
}

.form-group input,
.form-group select {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 0.94rem;
  padding: 11px 12px;
  outline: none;
  transition: border-color 0.15s;
}

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

.form-row-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.form-hint {
  display: block;
  margin-top: 5px;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 18px 0;
}

.password-wrap {
  display: flex;
  gap: 8px;
}

.password-wrap input {
  flex: 1;
}

.gemini-actions {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
}

.status-pill {
  font-size: 0.72rem;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--bg-elevated);
  color: var(--text-muted);
  border: 1px solid var(--border);
}

.status-pill.active {
  background: rgba(56, 189, 248, 0.15);
  color: #7dd3fc;
  border-color: rgba(56, 189, 248, 0.4);
}

.install-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: linear-gradient(135deg, rgba(14, 165, 233, 0.18), rgba(99, 102, 241, 0.16));
  border-color: rgba(56, 189, 248, 0.35);
}

.install-card h3 {
  margin: 0 0 3px;
  font-size: 0.95rem;
}

.install-card p {
  margin: 0;
  font-size: 0.78rem;
  color: var(--text-secondary);
}

/* ===== Segmented Controls ===== */
.segmented-control {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  background: var(--bg-input);
  padding: 4px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

.seg-btn {
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.8rem;
  font-weight: 700;
  padding: 9px 8px;
  border-radius: 7px;
  cursor: pointer;
  transition: all 0.15s;
}

.seg-btn.active {
  background: var(--bg-elevated);
  color: var(--text);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
  border: 1px solid var(--border-strong);
}

/* ===== FAB & Bottom Navigation ===== */
.fab {
  position: fixed;
  right: 18px;
  bottom: calc(var(--nav-height) + var(--safe-bottom) + 16px);
  z-index: 45;
  display: inline-flex;
  align-items: center;
  gap: 9px;
  padding: 14px 20px;
  border: none;
  border-radius: 999px;
  background: linear-gradient(135deg, var(--accent-strong), var(--indigo));
  color: #ffffff;
  font-size: 0.94rem;
  font-weight: 800;
  box-shadow: 0 10px 28px rgba(14, 165, 233, 0.45);
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.fab:active {
  transform: scale(0.95);
}

.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 40;
  height: calc(var(--nav-height) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: rgba(15, 23, 42, 0.94);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--border);
  display: grid;
  grid-template-columns: repeat(3, 1fr);
}

.nav-item {
  border: none;
  background: transparent;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  font-size: 0.72rem;
  font-weight: 600;
  cursor: pointer;
}

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

/* ===== Modals & Bottom Sheets ===== */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 80;
  background: rgba(2, 6, 23, 0.76);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0;
}

.sheet-card,
.modal-card {
  width: 100%;
  max-width: 560px;
  background: var(--bg-card);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  box-shadow: var(--shadow);
  animation: slideUp 0.22s ease;
}

.modal-card {
  max-height: 92vh;
  display: flex;
  flex-direction: column;
}

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

.sheet-handle {
  width: 42px;
  height: 4px;
  border-radius: 999px;
  background: var(--border-strong);
  margin: 10px auto 4px;
}

.sheet-header,
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}

.sheet-header h3,
.modal-header h3 {
  margin: 0;
  font-size: 1.04rem;
}

.scan-tipo-picker {
  padding: 14px 18px 4px;
}

.field-mini-label {
  display: block;
  font-size: 0.76rem;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.sheet-actions {
  padding: 12px 18px calc(22px + var(--safe-bottom));
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.sheet-action-btn {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  text-align: left;
  padding: 14px 15px;
  border-radius: var(--radius-md);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text);
  cursor: pointer;
}

.sheet-action-btn.primary {
  background: linear-gradient(135deg, rgba(14, 165, 233, 0.22), rgba(99, 102, 241, 0.22));
  border-color: rgba(56, 189, 248, 0.45);
}

.action-icon {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: rgba(15, 23, 42, 0.65);
  color: var(--accent);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.action-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.action-text strong {
  font-size: 0.94rem;
}

.action-text small {
  font-size: 0.76rem;
  color: var(--text-muted);
}

/* Invoice Modal Body */
.modal-body {
  padding: 16px 18px calc(18px + var(--safe-bottom));
  overflow-y: auto;
}

.ocr-mini-tag {
  display: inline-block;
  margin-top: 3px;
  font-size: 0.72rem;
  font-weight: 700;
  color: #7dd3fc;
}

.inv-photo-box {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: 14px;
}

.inv-photo-box img {
  width: 52px;
  height: 64px;
  object-fit: cover;
  border-radius: 7px;
  border: 1px solid var(--border-strong);
}

.inv-photo-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.raw-ocr-box {
  background: #070d18;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px;
  font-size: 0.74rem;
  color: var(--text-muted);
  max-height: 150px;
  overflow: auto;
  white-space: pre-wrap;
  margin: 0 0 14px;
}

.amounts-box {
  background: rgba(11, 18, 32, 0.55);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 12px 2px;
  margin-bottom: 14px;
}

.deducible-row {
  display: flex;
  gap: 8px;
}

.quick-pct {
  display: flex;
  gap: 6px;
}

.pct-btn {
  border: 1px solid var(--border-strong);
  background: var(--bg-elevated);
  color: var(--text-secondary);
  border-radius: var(--radius-sm);
  padding: 0 12px;
  font-size: 0.8rem;
  font-weight: 700;
  cursor: pointer;
}

.modal-footer {
  display: grid;
  grid-template-columns: 1fr 1.6fr;
  gap: 10px;
  margin-top: 14px;
}

/* Scan Loader */
#scan-loading {
  align-items: center;
  padding: 20px;
}

.scan-loader-card {
  width: 100%;
  max-width: 340px;
  background: var(--bg-card);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  padding: 24px 20px;
  text-align: center;
}

.scan-preview-wrap {
  position: relative;
  width: 120px;
  height: 150px;
  margin: 0 auto 16px;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--border-strong);
}

.scan-preview-wrap img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.scan-beam {
  position: absolute;
  left: 0;
  right: 0;
  height: 3px;
  background: var(--accent);
  box-shadow: 0 0 14px 3px var(--accent);
  animation: scanMove 1.4s ease-in-out infinite alternate;
}

@keyframes scanMove {
  from { top: 6%; }
  to { top: 92%; }
}

.spinner {
  width: 26px;
  height: 26px;
  border: 3px solid rgba(56, 189, 248, 0.25);
  border-top-color: var(--accent);
  border-radius: 50%;
  margin: 0 auto 10px;
  animation: spin 0.8s linear infinite;
}

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

.scan-loader-card h3 {
  margin: 0 0 4px;
  font-size: 1rem;
}

.scan-loader-card p {
  margin: 0;
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* Lightbox */
#lightbox {
  align-items: center;
  padding: 20px;
  background: rgba(2, 6, 23, 0.92);
}

.lightbox-close {
  position: fixed;
  top: 18px;
  right: 18px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid var(--border-strong);
  background: var(--bg-elevated);
  color: #ffffff;
  font-size: 1.7rem;
  line-height: 1;
  cursor: pointer;
}

.lightbox-img {
  max-width: 96vw;
  max-height: 88vh;
  border-radius: 12px;
  box-shadow: var(--shadow);
}

/* Toast */
.toast-container {
  position: fixed;
  top: calc(14px + env(safe-area-inset-top, 0px));
  left: 50%;
  transform: translateX(-50%);
  z-index: 120;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: min(92vw, 420px);
  pointer-events: none;
}

.toast {
  background: var(--bg-elevated);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-left: 4px solid var(--accent);
  border-radius: 12px;
  padding: 11px 14px;
  font-size: 0.85rem;
  font-weight: 600;
  box-shadow: var(--shadow);
  animation: fadeIn 0.2s ease;
}

.toast.success { border-left-color: var(--mint); }
.toast.error { border-left-color: var(--rose); }

/* ===== Desktop Enhancements ===== */
@media (min-width: 640px) {
  .modal-backdrop {
    align-items: center;
    padding: 20px;
  }

  .sheet-card,
  .modal-card {
    border-radius: var(--radius-lg);
  }

  .kpi-grid {
    grid-template-columns: repeat(3, 1fr);
  }

  .kpi-resultado {
    grid-column: auto;
  }

  .fab {
    right: max(24px, calc(50% - 390px));
  }
}

/* ===== Print Stylesheet (Modelo 303 PDF) ===== */
@media print {
  @page {
    size: A4 portrait;
    margin: 14mm;
  }

  body {
    background: #ffffff !important;
    color: #0f172a !important;
    padding: 0 !important;
    font-size: 11pt;
  }

  .no-print {
    display: none !important;
  }

  .print-only {
    display: block !important;
  }

  #tab-modelo303 {
    display: block !important;
  }

  #tab-facturas,
  #tab-ajustes {
    display: none !important;
  }

  .print-header {
    border: 1.5px solid #0f172a;
    border-radius: 6px;
    padding: 12px 14px;
    margin-bottom: 14px;
  }

  .print-title-row {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    border-bottom: 1px solid #cbd5e1;
    padding-bottom: 8px;
    margin-bottom: 8px;
  }

  .print-title-row h2 {
    margin: 0;
    font-size: 13pt;
  }

  .print-title-row p {
    margin: 2px 0 0;
    font-size: 8.5pt;
    color: #475569;
  }

  .print-period-box {
    text-align: right;
    font-size: 9.5pt;
  }

  .print-declarante {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    font-size: 9.5pt;
  }

  .app-main {
    max-width: 100%;
    padding: 0;
  }

  .kpi-grid {
    grid-template-columns: repeat(3, 1fr) !important;
    gap: 10px;
    margin-bottom: 14px;
  }

  .kpi-card,
  .card {
    background: #ffffff !important;
    color: #0f172a !important;
    border: 1px solid #94a3b8 !important;
    box-shadow: none !important;
    break-inside: avoid;
  }

  .kpi-label,
  .kpi-meta,
  .card-subtitle,
  .casillas-table th,
  .casilla-inline {
    color: #475569 !important;
  }

  .kpi-value,
  .casillas-table td,
  .summary-row,
  .summary-final {
    color: #0f172a !important;
  }

  .casilla-tag,
  .casilla-mini,
  .result-pill {
    background: #f1f5f9 !important;
    color: #0f172a !important;
    border: 1px solid #94a3b8 !important;
  }
}
