/**
 * Estilos para Visor y conversor de Facturae a PDF
 * Cumple con estándares canónicos de Fijate Tools
 */

:root {
  --font-main: 'Inter', system-ui, -apple-system, sans-serif;
  --font-heading: 'Outfit', 'Inter', sans-serif;
  --font-mono: 'JetBrains Mono', monospace;

  /* Colores base tema claro */
  --bg-page: #f8fafc;
  --bg-card: #ffffff;
  --bg-card-alt: #f1f5f9;
  --border-color: #e2e8f0;
  --text-main: #0f172a;
  --text-muted: #64748b;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-light: #eff6ff;
  --success: #16a34a;
  --success-light: #f0fdf4;
  --danger: #dc2626;
  --warning: #d97706;
  --sheet-bg: #ffffff;
  --sheet-text: #0f172a;
  --sheet-border: #cbd5e1;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08);
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
}

[data-theme="dark"] {
  --bg-page: #0b0f17;
  --bg-card: #151d2a;
  --bg-card-alt: #1c2637;
  --border-color: #273549;
  --text-main: #f1f5f9;
  --text-muted: #94a3b8;
  --primary: #3b82f6;
  --primary-hover: #60a5fa;
  --primary-light: rgba(59, 130, 246, 0.15);
  --sheet-bg: #151d2a;
  --sheet-text: #f1f5f9;
  --sheet-border: #334155;
}

/* Reset y estructura global */
* {
  box-sizing: border-box;
}

body {
  margin: 0;
  padding: 0;
  font-family: var(--font-main);
  background-color: var(--bg-page);
  color: var(--text-main);
  overflow-x: clip;
  width: 100%;
  max-width: 100%;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

h1, h2, h3, h4, h5, h6,
.brand-title,
.section-title,
.doc-number,
.grand-total-label {
  font-family: var(--font-heading);
}

.mono,
.doc-meta-box,
.items-table .mono,
.totals-summary-box .mono,
.payment-card .mono {
  font-family: var(--font-mono);
}

/* Layout con sidebar AdSense canónica */
.tool-layout {
  max-width: 1200px;
  margin: 1.5rem auto 3rem;
  padding: 0 1rem;
  box-sizing: border-box;
  flex: 1 0 auto;
  width: 100%;
}

.tool-with-sidebar {
  display: flex;
  gap: 2rem;
  align-items: flex-start;
  width: 100%;
}

.tool-main-content {
  flex: 1 1 0%;
  min-width: 0;
  width: 100%;
}

/* Cabecera hero introductoria */
.tool-intro-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.5rem 1.75rem;
  margin-bottom: 1.5rem;
  box-shadow: var(--shadow-sm);
}

.tool-intro-title {
  margin: 0 0 0.5rem;
  font-size: 1.45rem;
  font-weight: 700;
  color: var(--text-main);
}

.tool-intro-desc {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.95rem;
  line-height: 1.55;
}

/* Zona de subida Drag & Drop */
.uploader-card {
  background: var(--bg-card);
  border: 2px dashed var(--border-color);
  border-radius: var(--radius-lg);
  padding: 2.25rem 1.5rem;
  text-align: center;
  margin-bottom: 2rem;
  transition: all 0.2s ease;
  cursor: pointer;
}

.uploader-card:hover,
.uploader-card.drag-active {
  border-color: var(--primary);
  background: var(--primary-light);
}

.uploader-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: var(--primary-light);
  color: var(--primary);
  margin-bottom: 1rem;
}

.uploader-title {
  margin: 0 0 0.4rem;
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text-main);
}

.uploader-subtitle {
  margin: 0 0 1.25rem;
  font-size: 0.88rem;
  color: var(--text-muted);
}

.uploader-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
}

.btn-file-select {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--primary);
  color: #ffffff;
  padding: 0.65rem 1.25rem;
  font-size: 0.9rem;
  font-weight: 600;
  border-radius: var(--radius-md);
  cursor: pointer;
  border: none;
  transition: background 0.15s ease;
  min-height: 40px;
}

.btn-file-select:hover {
  background: var(--primary-hover);
}

.btn-secondary {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--bg-card-alt);
  color: var(--text-main);
  border: 1px solid var(--border-color);
  padding: 0.65rem 1.1rem;
  font-size: 0.9rem;
  font-weight: 500;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background 0.15s ease;
  min-height: 40px;
}

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

.btn-sample {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--success-light);
  color: var(--success);
  border: 1px solid rgba(22, 163, 74, 0.25);
  padding: 0.65rem 1.1rem;
  font-size: 0.9rem;
  font-weight: 600;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all 0.15s ease;
  min-height: 40px;
}

.btn-sample:hover {
  background: rgba(22, 163, 74, 0.18);
}

/* Estado vacío inicial */
.empty-state-card {
  text-align: center;
  padding: 3rem 1.5rem;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  color: var(--text-muted);
}

.empty-state-icon {
  color: var(--text-muted);
  opacity: 0.5;
  margin-bottom: 1rem;
}

/* Barra de herramientas superior de la factura */
.invoice-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 1rem;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 0.9rem 1.25rem;
  margin-bottom: 1.5rem;
}

.toolbar-left {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.65rem;
}

.toolbar-filename {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-weight: 600;
  font-size: 0.92rem;
  color: var(--text-main);
}

.schema-pill {
  background: var(--bg-card-alt);
  color: var(--text-muted);
  padding: 0.2rem 0.6rem;
  border-radius: var(--radius-sm);
  font-size: 0.75rem;
  font-weight: 600;
  font-family: var(--font-mono);
}

.badge-signature-valid {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  background: var(--success-light);
  color: var(--success);
  padding: 0.25rem 0.65rem;
  border-radius: var(--radius-sm);
  font-size: 0.78rem;
  font-weight: 600;
}

.badge-signature-none {
  background: var(--bg-card-alt);
  color: var(--text-muted);
  padding: 0.25rem 0.65rem;
  border-radius: var(--radius-sm);
  font-size: 0.78rem;
}

.toolbar-actions {
  display: flex;
  align-items: center;
  gap: 0.65rem;
}

.btn-action {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  background: var(--primary);
  color: #ffffff;
  padding: 0.55rem 1rem;
  font-size: 0.88rem;
  font-weight: 600;
  border-radius: var(--radius-md);
  border: none;
  cursor: pointer;
  min-height: 38px;
  transition: background 0.15s ease;
}

.btn-action:hover {
  background: var(--primary-hover);
}

.btn-secondary-action {
  background: var(--bg-card-alt);
  color: var(--text-main);
  border: 1px solid var(--border-color);
}

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

/* Hoja A4 simulada */
.a4-sheet {
  background: var(--sheet-bg);
  border: 1px solid var(--sheet-border);
  border-radius: var(--radius-lg);
  padding: 2.5rem;
  box-shadow: var(--shadow-md);
  color: var(--sheet-text);
  margin-bottom: 2rem;
}

/* Cabecera del documento A4 */
.invoice-doc-header {
  border-bottom: 2px solid var(--border-color);
  padding-bottom: 1.5rem;
  margin-bottom: 1.75rem;
}

.doc-header-main {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 1.25rem;
}

.doc-badge {
  display: inline-block;
  background: var(--primary-light);
  color: var(--primary);
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.2rem 0.55rem;
  border-radius: var(--radius-sm);
  margin-bottom: 0.4rem;
}

.doc-number {
  margin: 0 0 0.25rem;
  font-size: 1.8rem;
  font-weight: 800;
  color: var(--text-main);
}

.doc-type-name {
  font-size: 0.9rem;
  color: var(--text-muted);
}

.doc-meta-box {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  background: var(--bg-card-alt);
  padding: 0.85rem 1.15rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  min-width: 200px;
}

.meta-item {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  font-size: 0.84rem;
}

.meta-label {
  color: var(--text-muted);
}

.meta-value {
  font-weight: 600;
  color: var(--text-main);
}

/* Bloque partes (Emisor y Receptor) */
.parties-container {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
  margin-bottom: 1.75rem;
}

.party-card {
  background: var(--bg-card-alt);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1.25rem;
}

.party-badge {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 0.4rem;
}

.party-name {
  margin: 0 0 0.4rem;
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-main);
}

.party-nif {
  font-size: 0.9rem;
  margin-bottom: 0.4rem;
  color: var(--text-main);
}

.party-trade {
  font-size: 0.85rem;
  font-style: italic;
  color: var(--text-muted);
  margin-bottom: 0.4rem;
}

.party-address {
  font-size: 0.88rem;
  color: var(--text-muted);
  line-height: 1.45;
  margin-bottom: 0.4rem;
}

.party-contact {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-top: 0.4rem;
}

.party-reg {
  font-size: 0.78rem;
  color: var(--text-muted);
  border-top: 1px dashed var(--border-color);
  padding-top: 0.4rem;
  margin-top: 0.5rem;
}

/* Sección DIR3 */
.dir3-section {
  background: rgba(37, 99, 235, 0.04);
  border: 1px solid rgba(37, 99, 235, 0.15);
  border-radius: var(--radius-md);
  padding: 1rem 1.25rem;
  margin-bottom: 1.75rem;
}

.dir3-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--primary);
  margin-bottom: 0.85rem;
}

.section-subtitle {
  margin: 0;
  font-size: 0.98rem;
  font-weight: 700;
  color: var(--text-main);
}

.dir3-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 0.85rem;
}

.dir3-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 0.75rem;
}

.dir3-badge {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--primary);
  text-transform: uppercase;
  margin-bottom: 0.2rem;
}

.dir3-code {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text-main);
  margin-bottom: 0.25rem;
}

.dir3-name {
  font-size: 0.82rem;
  color: var(--text-muted);
}

.dir3-addr {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 0.25rem;
}

/* Tabla de conceptos */
.items-section {
  margin-bottom: 1.75rem;
  overflow-x: auto;
}

.items-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.items-table th {
  background: var(--bg-card-alt);
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 0.75rem 0.85rem;
  border-bottom: 2px solid var(--border-color);
}

.items-table td {
  padding: 0.85rem;
  border-bottom: 1px solid var(--border-color);
  vertical-align: top;
}

.col-num {
  width: 35px;
  color: var(--text-muted);
  text-align: center;
}

.col-desc {
  line-height: 1.45;
}

.tag-discount {
  display: inline-block;
  background: rgba(220, 38, 38, 0.1);
  color: var(--danger);
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.1rem 0.4rem;
  border-radius: 4px;
  margin-left: 0.4rem;
}

.text-center {
  text-align: center;
}

.text-right {
  text-align: right;
}

.text-danger {
  color: var(--danger);
}

.text-primary {
  color: var(--primary);
}

/* Contenedor de impuestos y totales */
.totals-and-taxes-container {
  display: grid;
  grid-template-columns: 1.2fr 1fr;
  gap: 1.75rem;
  margin-bottom: 1.75rem;
}

.tax-breakdown-box {
  background: var(--bg-card-alt);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1rem;
  margin-bottom: 1rem;
}

.tax-breakdown-title {
  margin: 0 0 0.65rem;
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--text-main);
}

.tax-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.84rem;
}

.tax-table th {
  color: var(--text-muted);
  font-weight: 500;
  padding: 0.35rem 0.5rem;
  border-bottom: 1px solid var(--border-color);
}

.tax-table td {
  padding: 0.4rem 0.5rem;
  border-bottom: 1px solid rgba(0, 0, 0, 0.05);
}

/* Tarjeta de totales */
.totals-summary-box {
  background: var(--bg-card-alt);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1.25rem;
}

.total-line {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.45rem 0;
  font-size: 0.92rem;
  border-bottom: 1px dashed var(--border-color);
}

.total-line:last-child {
  border-bottom: none;
}

.grand-total {
  margin-top: 0.65rem;
  padding-top: 0.75rem;
  border-top: 2px solid var(--border-color);
  border-bottom: none;
}

.grand-total-label {
  font-size: 1.15rem;
  font-weight: 800;
  color: var(--text-main);
}

.grand-total-value {
  font-size: 1.45rem;
  font-weight: 800;
  color: var(--primary);
}

/* Pagos y vencimientos */
.payment-section {
  background: var(--bg-card-alt);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1.25rem;
  margin-bottom: 1.5rem;
}

.payment-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 1rem;
  margin-top: 0.75rem;
}

.payment-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 0.85rem 1rem;
}

.payment-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.25rem 0;
  font-size: 0.85rem;
}

.payment-row .label {
  color: var(--text-muted);
}

.iban-row {
  flex-direction: column;
  align-items: flex-start;
  margin-top: 0.4rem;
  padding-top: 0.4rem;
  border-top: 1px dashed var(--border-color);
}

.iban-text {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text-main);
  letter-spacing: 0.05em;
  margin-top: 0.2rem;
}

/* Avisos legales */
.legal-notice-box {
  background: var(--bg-card-alt);
  border-left: 3px solid var(--primary);
  padding: 0.85rem 1rem;
  font-size: 0.82rem;
  color: var(--text-muted);
  line-height: 1.5;
  margin-bottom: 1.5rem;
}

.legal-notice-box strong {
  color: var(--text-main);
  display: block;
  margin-bottom: 0.25rem;
}

.legal-notice-box p {
  margin: 0;
}

/* Pie técnico A4 */
.invoice-doc-footer {
  border-top: 1px solid var(--border-color);
  padding-top: 1rem;
  margin-top: 1.5rem;
}

.doc-footer-info {
  display: flex;
  justify-content: space-between;
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* Modal genérico */
.app-modal {
  position: fixed;
  inset: 0;
  background: rgba(11, 15, 23, 0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  padding: 1rem;
}

.app-modal.active {
  opacity: 1;
  pointer-events: auto;
}

.modal-content {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  max-width: 520px;
  width: 100%;
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.3);
  overflow: hidden;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.1rem 1.25rem;
  border-bottom: 1px solid var(--border-color);
}

.modal-title {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text-main);
}

.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0.25rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-close:hover {
  color: var(--text-main);
}

.modal-body {
  padding: 1.25rem;
  color: var(--text-main);
  font-size: 0.92rem;
  line-height: 1.55;
}

.modal-footer {
  padding: 0.9rem 1.25rem;
  border-top: 1px solid var(--border-color);
  display: flex;
  justify-content: flex-end;
  gap: 0.65rem;
  background: var(--bg-card-alt);
}

.modal-textarea {
  width: 100%;
  min-height: 220px;
  font-family: var(--font-mono);
  font-size: 0.82rem;
  background: var(--bg-card-alt);
  color: var(--text-main);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 0.75rem;
  resize: vertical;
}

.hidden {
  display: none !important;
}

/* Responsive móvil */
@media (max-width: 768px) {
  .parties-container {
    grid-template-columns: 1fr;
  }

  .totals-and-taxes-container {
    grid-template-columns: 1fr;
  }

  .a4-sheet {
    padding: 1.25rem;
  }

  .doc-header-main {
    flex-direction: column;
  }

  .doc-meta-box {
    width: 100%;
  }

  .invoice-toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .toolbar-actions {
    flex-direction: column;
  }

  .btn-action,
  .btn-secondary-action {
    width: 100%;
    justify-content: center;
  }

  .doc-footer-info {
    flex-direction: column;
    gap: 0.4rem;
  }
}

/* Modo de impresión A4 profesional */
@media print {
  /* Ocultar todo lo innecesario */
  .app-header,
  .fijate-footer,
  .tool-ad-sidebar,
  .tools-ad-banner-section,
  .uploader-card,
  .tool-intro-card,
  .seo-guide-section,
  .print-hide,
  .invoice-toolbar,
  .app-modal {
    display: none !important;
  }

  body {
    background: #ffffff !important;
    color: #000000 !important;
    margin: 0 !important;
    padding: 0 !important;
  }

  .tool-layout {
    max-width: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
  }

  .tool-with-sidebar {
    display: block !important;
  }

  .a4-sheet {
    border: none !important;
    box-shadow: none !important;
    padding: 0 !important;
    margin: 0 !important;
    background: #ffffff !important;
    color: #000000 !important;
  }

  .party-card,
  .tax-breakdown-box,
  .totals-summary-box,
  .payment-section,
  .dir3-card,
  .doc-meta-box {
    background: #f8fafc !important;
    border: 1px solid #cbd5e1 !important;
  }

  .grand-total-value {
    color: #000000 !important;
  }

  @page {
    size: A4 portrait;
    margin: 1.5cm;
  }
}
