/* System Design & Theme Tokens
   Colores/radios de marca vienen de tokens.css (compartido con el CRM V2, cargado
   antes que este archivo). Figtree se carga aquí también, en local, para que el
   texto no dependa de que crm.mejocasa.es esté disponible (spec_unificacion_app_visitas.md RF-5). */
@import url('https://fonts.googleapis.com/css2?family=Figtree:wght@400;500;600;700&display=swap');

:root {
  --primary: #0d3c61;
  --primary-light: #1e5987;
  --accent: #0ea5e9;
  --accent-light: #e0f2fe;
  --success: #10b981;
  --success-light: #d1fae5;
  --warning: #f59e0b;
  --warning-light: #fef3c7;
  --danger: #ef4444;

  /* Light Theme (Default for Forms & Client View) */
  --bg-app: #f8fafc;
  --bg-card: #ffffff;
  --text-main: #0f172a;
  --text-muted: #64748b;
  --text-inverse: #ffffff;
  --border: #e2e8f0;
  --input-bg: #ffffff;
  --input-border: #cbd5e1;
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
  --radius: 12px;
  --radius-lg: 16px;

  /* Shared Layout Constants */
  --transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  --font-main: var(--font-ui, 'Figtree', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif);
}

/* Dark Theme (Automatic for CRM Dashboard, optional toggle) */
body.dark-mode {
  --bg-app: #0b0f19;
  --bg-card: #151f32;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --border: #1e293b;
  --input-bg: #0f172a;
  --input-border: #334155;
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.3), 0 2px 4px -2px rgb(0 0 0 / 0.3);
}

/* Reset & Global Styles */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  font-family: var(--font-main);
  background-color: var(--bg-app);
  color: var(--text-main);
  min-height: 100vh;
  line-height: 1.5;
  overflow-x: hidden;
  transition: background-color 0.3s ease, color 0.3s ease;
  -webkit-tap-highlight-color: transparent;
}

/* Page Transitions and Views */
.app-container {
  max-width: 600px;
  margin: 0 auto;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  position: relative;
}

/* For larger dashboard views (CRM), expand max-width */
.app-container.dashboard-mode {
  max-width: 1200px;
}

.view-section {
  display: none !important;
  flex-direction: column;
  padding: 20px 16px 80px 16px;
  animation: fadeIn 0.35s ease-out forwards;
}

.view-section.active {
  display: flex !important;
}

#app-viewport.dashboard-mode {
  max-width: 1200px !important;
}

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

/* Premium Typography */
h1 {
  font-size: 24px;
  font-weight: 800;
  color: var(--primary);
  margin-bottom: 8px;
  letter-spacing: -0.5px;
}

.dark-mode h1 {
  color: var(--accent);
}

h2 {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 16px;
  color: var(--text-main);
}

.subtitle {
  font-size: 14px;
  color: var(--text-muted);
  margin-bottom: 24px;
}

/* Layout Utilities & Navigation Bar */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 64px;
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-around;
  align-items: center;
  z-index: 100;
  box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.03);
}

.dark-mode .bottom-nav {
  background: rgba(21, 31, 50, 0.85);
}

.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  background: none;
  border: none;
  outline: none;
  padding: 8px 12px;
  border-radius: 8px;
  transition: var(--transition);
}

.nav-item svg {
  width: 22px;
  height: 22px;
  margin-bottom: 4px;
  stroke: currentColor;
  stroke-width: 2px;
  fill: none;
  transition: var(--transition);
}

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

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

.nav-item.active svg {
  transform: translateY(-2px);
}

/* Cards & Containers */
.card {
  background-color: var(--bg-card);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  padding: 24px;
  margin-bottom: 20px;
  box-shadow: var(--shadow-sm);
  transition: var(--transition);
}

.card:hover {
  box-shadow: var(--shadow-md);
}

/* Beautiful Interactive Inputs */
.form-group {
  margin-bottom: 18px;
}

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

@media (max-width: 480px) {
  .form-row {
    grid-template-columns: 1fr;
    gap: 0;
  }
}

label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--text-main);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.input-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}

.input-icon {
  position: absolute;
  left: 14px;
  color: var(--text-muted);
  pointer-events: none;
}

.input-icon svg {
  width: 18px;
  height: 18px;
}

input[type="text"],
input[type="tel"],
input[type="number"],
input[type="email"],
select {
  width: 100%;
  padding: 12px 14px 12px 42px;
  font-family: var(--font-main);
  font-size: 15px;
  color: var(--text-main);
  background-color: var(--input-bg);
  border: 1.5px solid var(--input-border);
  border-radius: var(--radius);
  outline: none;
  transition: var(--transition);
}

input:focus,
select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(13, 60, 97, 0.15);
}

.dark-mode input:focus,
.dark-mode select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(14, 165, 233, 0.2);
}

/* Office selection grid */
.office-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  margin-top: 8px;
}

.office-card {
  position: relative;
  border: 1.5px solid var(--input-border);
  border-radius: var(--radius);
  padding: 14px 16px 14px 44px;
  cursor: pointer;
  transition: var(--transition);
  user-select: none;
}

.office-card input[type="radio"] {
  position: absolute;
  left: 16px;
  top: 50%;
  transform: translateY(-50%);
  width: 18px;
  height: 18px;
  accent-color: var(--primary);
}

.office-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-main);
  margin-bottom: 2px;
}

.office-desc {
  font-size: 11px;
  color: var(--text-muted);
  line-height: 1.3;
}

.office-card:hover {
  border-color: var(--primary-light);
  background-color: rgba(13, 60, 97, 0.02);
}

.office-card.selected {
  border-color: var(--primary);
  background-color: rgba(13, 60, 97, 0.05);
}

.dark-mode .office-card.selected {
  border-color: var(--accent);
  background-color: rgba(14, 165, 233, 0.08);
}

/* Legal text block */
.legal-container {
  font-size: 11px;
  color: var(--text-muted);
  max-height: 180px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  background-color: rgba(0, 0, 0, 0.01);
  margin-bottom: 16px;
  line-height: 1.4;
  scrollbar-width: thin;
}

/* Custom Checkbox */
.checkbox-group {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 20px;
  cursor: pointer;
}

.checkbox-group input[type="checkbox"] {
  width: 18px;
  height: 18px;
  margin-top: 2px;
  accent-color: var(--primary);
  flex-shrink: 0;
}

.checkbox-label {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.4;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 14px 24px;
  font-family: var(--font-main);
  font-size: 15px;
  font-weight: 700;
  border-radius: var(--radius);
  border: none;
  cursor: pointer;
  transition: var(--transition);
  text-decoration: none;
}

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

.btn-primary:hover {
  background-color: var(--primary-light);
  transform: translateY(-1px);
}

.btn-primary:active {
  transform: translateY(1px);
}

.btn-success {
  background-color: var(--success);
  color: var(--text-inverse);
}

.btn-success:hover {
  background-color: #059669;
  transform: translateY(-1px);
}

.btn-outline {
  background-color: transparent;
  border: 1.5px solid var(--border);
  color: var(--text-main);
}

.btn-outline:hover {
  background-color: rgba(0, 0, 0, 0.02);
  border-color: var(--text-muted);
}

.dark-mode .btn-outline:hover {
  background-color: rgba(255, 255, 255, 0.04);
}

.btn-icon {
  width: auto;
  padding: 10px;
  border-radius: 8px;
}

/* Signature Pad Canvas */
.signature-box {
  border: 2px dashed var(--input-border);
  border-radius: var(--radius);
  background-color: var(--input-bg);
  position: relative;
  overflow: hidden;
  margin-bottom: 12px;
}

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

.signature-placeholder {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: var(--text-muted);
  font-size: 14px;
  pointer-events: none;
  text-align: center;
  transition: opacity 0.2s ease;
}

.signature-placeholder svg {
  width: 32px;
  height: 32px;
  margin-bottom: 6px;
  opacity: 0.5;
}

.signature-controls {
  display: flex;
  gap: 12px;
  margin-bottom: 20px;
}

.signature-controls button {
  flex: 1;
}

/* Mejocasa Document Replica */
.document-container {
  background-color: #ffffff;
  color: #000000;
  border-radius: 8px;
  box-shadow: var(--shadow-lg);
  padding: 24px;
  border: 1px solid #cbd5e1;
  font-family: 'Outfit', sans-serif;
  margin-bottom: 24px;
}

.doc-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  border-bottom: 2px solid #0d3c61;
  padding-bottom: 16px;
  margin-bottom: 16px;
}

.doc-logo-area {
  display: flex;
  flex-direction: column;
}

.doc-logo-title {
  font-size: 26px;
  font-weight: 800;
  color: #0d3c61;
  letter-spacing: -1px;
  line-height: 1.1;
  display: flex;
  align-items: center;
  gap: 4px;
}

.doc-logo-sub {
  font-size: 9px;
  text-transform: uppercase;
  color: #64748b;
  letter-spacing: 2px;
  font-weight: 600;
  margin-left: 2px;
}

.doc-title-area {
  text-align: right;
}

.doc-main-title {
  font-size: 20px;
  font-weight: 800;
  color: #0d3c61;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.doc-sub-title {
  font-size: 16px;
  font-weight: 700;
  color: #0d3c61;
  margin-top: -2px;
}

.doc-contact-info {
  font-size: 10px;
  color: #475569;
  margin-top: 4px;
  line-height: 1.3;
}

.doc-body {
  font-size: 12px;
  line-height: 1.5;
  color: #000000;
}

.doc-data-section {
  background-color: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  padding: 12px;
  margin-bottom: 16px;
}

.doc-data-row {
  margin-bottom: 8px;
}

.doc-data-row:last-child {
  margin-bottom: 0;
}

.doc-label {
  font-weight: 700;
  color: #0d3c61;
  text-transform: uppercase;
  font-size: 10px;
}

.doc-val {
  border-bottom: 1px dashed #94a3b8;
  padding-left: 4px;
  font-weight: 500;
}

.doc-clause-p {
  margin-bottom: 12px;
  text-align: justify;
  font-size: 11px;
  line-height: 1.4;
  color: #1e293b;
}

.doc-clause-p strong {
  color: #0d3c61;
}

.doc-office-info {
  font-size: 9px;
  color: #64748b;
  border-top: 1px solid #e2e8f0;
  padding-top: 8px;
  margin-top: 16px;
  line-height: 1.3;
}

.doc-office-info strong {
  color: #475569;
}

.doc-footer-signature {
  display: flex;
  justify-content: space-between;
  margin-top: 24px;
  border-top: 1px solid #e2e8f0;
  padding-top: 16px;
}

.doc-sig-box {
  width: 45%;
  text-align: center;
}

.doc-sig-title {
  font-size: 11px;
  font-weight: 700;
  color: #475569;
  margin-bottom: 10px;
}

.doc-sig-img {
  height: 60px;
  max-width: 100%;
  object-fit: contain;
  border-bottom: 1px solid #94a3b8;
  padding-bottom: 4px;
}

/* Toast Notification */
.toast-notification {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%) translateY(-100px);
  background: var(--primary);
  color: var(--text-inverse);
  padding: 12px 24px;
  border-radius: 40px;
  font-size: 14px;
  font-weight: 600;
  box-shadow: var(--shadow-lg);
  z-index: 1000;
  opacity: 0;
  transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275), opacity 0.3s ease;
  display: flex;
  align-items: center;
  gap: 8px;
}

.toast-notification.success {
  background: var(--success);
}

.toast-notification.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

/* Simulated sending screen and modern loader */
.sending-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(11, 15, 25, 0.8);
  backdrop-filter: blur(8px);
  z-index: 500;
  justify-content: center;
  align-items: center;
  flex-direction: column;
  color: #ffffff;
}

.sending-overlay.active {
  display: flex;
}

.spinner {
  width: 48px;
  height: 48px;
  border: 4px solid rgba(255, 255, 255, 0.1);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin-bottom: 16px;
}

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

.sending-text {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 8px;
}

.sending-sub {
  font-size: 13px;
  color: #94a3b8;
}

/* CRM / Dashboard styles */
.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background-color: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  display: flex;
  align-items: center;
  gap: 16px;
}

.stat-icon {
  width: 48px;
  height: 48px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: var(--accent-light);
  color: var(--accent);
}

.dark-mode .stat-icon {
  background-color: rgba(14, 165, 233, 0.15);
}

.stat-info {
  display: flex;
  flex-direction: column;
}

.stat-val {
  font-size: 24px;
  font-weight: 800;
  color: var(--text-main);
  line-height: 1.1;
}

.stat-label {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 600;
}

/* Search and Filters */
.filter-bar {
  display: flex;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.filter-bar input {
  flex: 2;
  min-width: 200px;
}

.filter-bar select {
  flex: 1;
  min-width: 150px;
}

/* Table Layout */
.table-container {
  background-color: var(--bg-card);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  overflow-x: auto;
  margin-bottom: 20px;
}

table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 14px;
}

th {
  background-color: rgba(0, 0, 0, 0.02);
  color: var(--text-muted);
  font-weight: 700;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.dark-mode th {
  background-color: rgba(255, 255, 255, 0.02);
}

td {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  color: var(--text-main);
}

tr:last-child td {
  border-bottom: none;
}

tr:hover td {
  background-color: rgba(0, 0, 0, 0.01);
}

.dark-mode tr:hover td {
  background-color: rgba(255, 255, 255, 0.01);
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
}

.badge-pending {
  background-color: var(--warning-light);
  color: #b45309;
}

.badge-success {
  background-color: var(--success-light);
  color: #047857;
}

.action-buttons {
  display: flex;
  gap: 8px;
}

.action-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-main);
  padding: 6px 10px;
  border-radius: 6px;
  cursor: pointer;
  font-family: var(--font-main);
  font-size: 12px;
  font-weight: 600;
  transition: var(--transition);
}

.action-btn:hover {
  background-color: var(--primary);
  color: var(--text-inverse);
  border-color: var(--primary);
}

.dark-mode .action-btn:hover {
  background-color: var(--accent);
  border-color: var(--accent);
}

.crm-empty {
  padding: 48px;
  text-align: center;
  color: var(--text-muted);
}

.crm-empty svg {
  width: 48px;
  height: 48px;
  margin-bottom: 12px;
  stroke-width: 1.5px;
}

.export-group {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  margin-top: 12px;
}

.export-group button {
  width: auto;
}

/* Share Simulation Modal/Card */
.share-simulation {
  background-color: var(--accent-light);
  border: 1px solid rgba(14, 165, 233, 0.2);
  color: var(--primary);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 20px;
}

.dark-mode .share-simulation {
  background-color: rgba(14, 165, 233, 0.1);
  color: #bae6fd;
}

.share-simulation p {
  font-size: 13px;
  font-weight: 500;
  margin-bottom: 12px;
}

.share-link-box {
  display: flex;
  gap: 8px;
  background-color: var(--bg-card);
  padding: 8px;
  border-radius: 8px;
  border: 1px solid var(--border);
}

.share-link-box input {
  border: none;
  background: transparent;
  flex: 1;
  font-size: 12px;
  color: var(--text-main);
  outline: none;
  font-family: monospace;
}

.share-link-box button {
  width: auto;
  padding: 6px 12px;
  font-size: 12px;
}

/* Responsive Overrides */
@media (max-width: 768px) {
  .bottom-nav {
    border-top-left-radius: 16px;
    border-top-right-radius: 16px;
  }
}

/* Success View Centering Override */
#view-success.active {
  display: flex !important;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
}

/* ====== VISTA PREVIA DEL DOCUMENTO ====== */

.preview-document {
  font-family: var(--font-main);
  font-size: 13px;
  line-height: 1.6;
  color: var(--text-main);
}

.prev-header {
  background: var(--primary);
  color: #fff;
  padding: 16px 20px;
  border-radius: 10px 10px 0 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin: -14px -14px 16px -14px;
}
.prev-logo-name { font-size: 22px; font-weight: 800; letter-spacing: -1px; display: block; }
.prev-logo-sub { font-size: 9px; letter-spacing: 1.5px; opacity: 0.7; text-transform: uppercase; }
.prev-title { font-size: 15px; font-weight: 700; text-align: center; flex: 1; }
.prev-contact { font-size: 10px; text-align: right; opacity: 0.85; line-height: 1.5; }

.prev-section-title {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  padding-bottom: 4px;
  margin: 16px 0 10px;
}

.prev-block {
  background: var(--bg-app);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 8px;
}
.prev-2col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
@media (max-width: 400px) {
  .prev-2col { grid-template-columns: 1fr; }
}

.prev-field { display: flex; flex-direction: column; gap: 2px; }
.prev-label { font-size: 10px; color: var(--text-muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.3px; }
.prev-value { font-size: 13px; color: var(--text-main); font-weight: 500; word-break: break-word; }

.prev-subsection-title {
  font-size: 11px;
  font-weight: 700;
  color: var(--primary);
  margin: 0 0 8px;
}
.prev-subsection-title:not(:first-child) {
  margin-top: 14px;
}

.prev-tabla-tecnica {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px 16px;
}
.prev-fila-tecnica {
  display: flex;
  flex-direction: column;
  gap: 1px;
  padding: 4px 0;
  border-bottom: 1px solid var(--border);
}
@media (max-width: 400px) {
  .prev-tabla-tecnica { grid-template-columns: 1fr; }
}

.prev-clausula {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-left: 4px solid var(--primary);
  border-radius: 0 8px 8px 0;
  padding: 14px 16px;
  margin: 16px 0;
  font-size: 12.5px;
  line-height: 1.7;
  color: var(--text-main);
}
.prev-clausula p { margin-bottom: 10px; }
.prev-clausula p:last-child { margin-bottom: 0; }

.prev-rgpd {
  font-size: 10.5px;
  color: var(--text-muted);
  line-height: 1.5;
  padding: 10px 12px;
  background: var(--bg-app);
  border-radius: 6px;
  margin: 12px 0;
}

.prev-pie {
  font-size: 11px;
  color: var(--primary);
  padding: 10px 12px;
  background: var(--accent-light);
  border: 1px solid var(--accent);
  border-radius: 8px;
  margin-top: 16px;
}
