/**
 * Estilos para Generador de autorizaciones y representaciones en 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;

  /* 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;
  --sheet-bg: #ffffff;
  --sheet-text: #0f172a;
  --sheet-border: #cbd5e1;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 14px 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;
}

* {
  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,
.a4-title,
.editor-card-title {
  font-family: var(--font-heading);
}

.mono,
.a4-party-detail strong {
  font-family: var(--font-mono);
}

/* Layout canónico */
.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%;
}

/* Hero introductorio */
.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;
}

/* Selector de plantilla */
.template-picker-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.25rem 1.5rem;
  margin-bottom: 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 1rem;
}

.template-picker-left {
  flex: 1 1 300px;
}

.template-picker-label {
  display: block;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text-main);
  margin-bottom: 0.4rem;
}

.template-select {
  width: 100%;
  max-width: 100%;
  min-height: 42px;
  background-color: var(--bg-card-alt);
  color: var(--text-main);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 0.6rem 2.5rem 0.6rem 0.85rem;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
}

.template-badge {
  display: inline-block;
  background: var(--primary-light);
  color: var(--primary);
  font-size: 0.82rem;
  font-weight: 700;
  padding: 0.35rem 0.75rem;
  border-radius: 20px;
}

.btn-sample-inline {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  background: var(--bg-card-alt);
  color: var(--text-main);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 0.55rem 0.95rem;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  min-height: 40px;
  transition: all 0.15s ease;
}

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

/* Panel del editor y pestañas */
.editor-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  margin-bottom: 2rem;
  box-shadow: var(--shadow-sm);
}

.editor-card-header {
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 1rem;
  margin-bottom: 1.25rem;
}

.editor-card-title {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 700;
}

/* Cuadrículas de formulario */
.form-section-title {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.98rem;
  font-weight: 700;
  color: var(--primary);
  margin: 1.25rem 0 0.85rem;
  padding-top: 1rem;
  border-top: 1px dashed var(--border-color);
}

.form-section-title:first-of-type {
  border-top: none;
  padding-top: 0;
  margin-top: 0;
}

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

.col-span-full {
  grid-column: 1 / -1;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.form-label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-main);
}

.form-control {
  width: 100%;
  min-height: 40px;
  background: var(--bg-card-alt);
  color: var(--text-main);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 0.55rem 0.8rem;
  font-size: 0.9rem;
  transition: border-color 0.15s ease;
}

.form-control:focus {
  outline: none;
  border-color: var(--primary);
  background: var(--bg-card);
}

.fields-group-title {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--primary);
  margin: 1.25rem 0 0.75rem;
}

/* Módulo de firma táctil */
.signature-card-box {
  background: var(--bg-card-alt);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1.25rem;
  margin-top: 1.25rem;
}

.sig-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.sig-color-options {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.sig-color-swatch {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  padding: 0;
  transition: transform 0.1s ease;
}

.sig-color-swatch.active {
  transform: scale(1.15);
  border-color: #ffffff;
  box-shadow: 0 0 0 2px var(--primary);
}

.signature-canvas-wrapper {
  background: #ffffff;
  border: 2px dashed var(--border-color);
  border-radius: var(--radius-md);
  overflow: hidden;
  position: relative;
  touch-action: none;
}

.signature-canvas {
  width: 100%;
  height: 160px;
  display: block;
  cursor: crosshair;
}

.sig-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 0.5rem;
}

.btn-sig-clear {
  background: transparent;
  color: var(--danger);
  border: 1px solid rgba(220, 38, 38, 0.3);
  border-radius: var(--radius-sm);
  padding: 0.35rem 0.75rem;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  min-height: 32px;
}

.btn-sig-clear:hover {
  background: rgba(220, 38, 38, 0.08);
}

/* Adjuntar fotos de DNI */
.dni-attachments-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin-top: 1rem;
}

.dni-upload-box {
  background: var(--bg-card-alt);
  border: 1px dashed var(--border-color);
  border-radius: var(--radius-md);
  padding: 1rem;
  text-align: center;
}

.dni-upload-label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 0.6rem;
  color: var(--text-main);
}

.btn-upload-file {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  background: var(--bg-card);
  color: var(--text-main);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.85rem;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  min-height: 36px;
}

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

.dni-preview-box {
  margin-top: 0.65rem;
  border-radius: var(--radius-sm);
  overflow: hidden;
  max-height: 120px;
}

.dni-thumb {
  max-width: 100%;
  max-height: 120px;
  object-fit: contain;
  display: block;
  margin: 0 auto;
  border-radius: var(--radius-sm);
}

.btn-remove-thumb {
  background: transparent;
  color: var(--danger);
  border: none;
  font-size: 0.78rem;
  cursor: pointer;
  margin-top: 0.4rem;
  text-decoration: underline;
}

.watermark-toggle-label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-top: 0.85rem;
  cursor: pointer;
}

/* Barra de herramientas para exportar */
.export-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: 1rem 1.5rem;
  margin-bottom: 1.5rem;
}

.export-toolbar-title {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text-main);
}

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

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

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

.btn-export-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.15rem;
  font-size: 0.92rem;
  font-weight: 600;
  border-radius: var(--radius-md);
  cursor: pointer;
  min-height: 42px;
  transition: background 0.15s ease;
}

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

/* Hoja A4 formal en pantalla */
.a4-preview-wrapper {
  margin-bottom: 2rem;
}

.a4-document {
  background: var(--sheet-bg);
  border: 1px solid var(--sheet-border);
  border-radius: var(--radius-lg);
  padding: 3rem 2.75rem;
  box-shadow: var(--shadow-md);
  color: var(--sheet-text);
  line-height: 1.6;
}

.a4-header {
  border-bottom: 2px solid var(--border-color);
  padding-bottom: 1.25rem;
  margin-bottom: 1.75rem;
}

.a4-header-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-bottom: 0.65rem;
}

.a4-doc-type {
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--primary);
}

.a4-title {
  margin: 0;
  font-size: 1.55rem;
  font-weight: 800;
  color: var(--text-main);
}

.a4-parties-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
  margin-bottom: 1.75rem;
}

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

.a4-party-badge {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--primary);
  margin-bottom: 0.5rem;
}

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

.a4-party-detail {
  font-size: 0.86rem;
  color: var(--text-muted);
  margin-bottom: 0.25rem;
}

.a4-section-heading {
  font-size: 1.05rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-main);
  margin: 0 0 0.85rem;
}

.a4-body-paragraphs {
  font-size: 0.95rem;
  color: var(--text-main);
  text-align: justify;
}

.a4-paragraph {
  margin: 0 0 1rem;
}

.a4-validity-box {
  background: var(--bg-card-alt);
  border-left: 3px solid var(--primary);
  padding: 0.65rem 0.95rem;
  font-size: 0.88rem;
  color: var(--text-muted);
  margin: 1.25rem 0;
}

.a4-date-line {
  font-size: 0.92rem;
  color: var(--text-main);
  margin: 1.5rem 0;
}

/* Firmas en A4 */
.a4-signatures-section {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
  margin: 2rem 0 1.5rem;
}

.a4-signature-box {
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1.25rem;
  text-align: center;
  background: var(--bg-card-alt);
}

.a4-sig-title {
  display: block;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 0.85rem;
}

.sig-image-box {
  height: 80px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 0.65rem;
}

.sig-rendered-img {
  max-height: 75px;
  max-width: 100%;
}

.sig-empty-line {
  height: 80px;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  border-bottom: 1px dashed var(--border-color);
  color: var(--text-muted);
  font-size: 0.78rem;
  padding-bottom: 0.5rem;
  margin-bottom: 0.65rem;
}

.a4-sig-signer-name {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--text-main);
}

.a4-sig-signer-dni {
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* Anexo DNI */
.a4-attachment-section {
  border-top: 2px dashed var(--border-color);
  padding-top: 1.5rem;
  margin-top: 2rem;
}

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

.a4-dni-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.25rem;
}

.a4-dni-box {
  background: var(--bg-card-alt);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 0.85rem;
  text-align: center;
}

.a4-dni-label {
  display: block;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
}

.a4-dni-box img {
  max-width: 100%;
  max-height: 180px;
  border-radius: var(--radius-sm);
}

.a4-footer {
  border-top: 1px solid var(--border-color);
  padding-top: 1rem;
  margin-top: 2rem;
  font-size: 0.75rem;
  color: var(--text-muted);
  text-align: center;
}

/* Modal */
.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: 500px;
  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;
}

.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;
  background: var(--bg-card-alt);
}

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

.hidden {
  display: none !important;
}

/* Responsive móvil */
@media (max-width: 768px) {
  .a4-parties-grid,
  .a4-signatures-section,
  .dni-attachments-grid,
  .a4-dni-grid {
    grid-template-columns: 1fr;
  }

  .a4-document {
    padding: 1.5rem 1.25rem;
  }

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

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

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

/* Modo de impresión formal A4 */
@media print {
  .app-header,
  .fijate-footer,
  .tool-ad-sidebar,
  .tools-ad-banner-section,
  .tool-intro-card,
  .template-picker-card,
  .editor-card,
  .export-toolbar,
  .seo-guide-section,
  .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-document {
    border: none !important;
    box-shadow: none !important;
    padding: 0 !important;
    background: #ffffff !important;
    color: #000000 !important;
  }

  .a4-party-box,
  .a4-signature-box,
  .a4-dni-box {
    background: #f8fafc !important;
    border: 1px solid #cbd5e1 !important;
  }

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