*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; background: #f5f5f7; color: #1d1d1f; min-height: 100vh; }

/* App shell: sidebar fija + contenido */
.app-shell { display: flex; height: 100vh; overflow: hidden; }

.logo { width: 34px; height: 34px; background: #7c3aed; border-radius: 9px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.logo svg { width: 18px; height: 18px; fill: none; stroke: #fff; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.logo.logo-img { background: none; border-radius: 0; width: auto; max-width: 120px; }

/* Sidebar */
.sidebar { width: 250px; flex-shrink: 0; background: #fff; border-right: 1px solid #e5e7eb; display: flex; flex-direction: column; height: 100vh; overflow-y: auto; }
.sidebar-brand { display: flex; align-items: center; gap: 10px; padding: 16px 18px; border-bottom: 1px solid #e5e7eb; }
.sidebar-brand-title { font-size: 14px; font-weight: 700; color: #111827; line-height: 1.3; }
.sidebar-brand-sub { font-size: 11px; color: #9ca3af; }

.sidebar-nav { padding: 14px 12px 6px; }
.sidebar-nav-lbl { font-size: 10px; font-weight: 700; color: #9ca3af; text-transform: uppercase; letter-spacing: .06em; padding: 0 8px 8px; display: flex; align-items: center; justify-content: space-between; }
.sidebar-link { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 8px; font-size: 13px; font-weight: 500; color: #374151; text-decoration: none; margin-bottom: 2px; transition: background .15s, color .15s; }
.sidebar-link svg { flex-shrink: 0; }
.sidebar-link:hover { background: #f9fafb; }
.sidebar-link.active { background: #f5f3ff; color: #7c3aed; font-weight: 600; }

.sidebar-recent { padding: 10px 12px; flex: 1; overflow-y: auto; }
.sidebar-add-btn { width: 20px; height: 20px; border: none; background: #f3f4f6; border-radius: 6px; color: #6b7280; cursor: pointer; display: flex; align-items: center; justify-content: center; }
.sidebar-add-btn:hover { background: #ede9fe; color: #7c3aed; }
.sidebar-recent-list { display: flex; flex-direction: column; gap: 2px; }
.sidebar-recent-item { display: flex; align-items: center; gap: 8px; padding: 7px 8px; border-radius: 7px; font-size: 12px; color: #4b5563; cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-recent-item svg { flex-shrink: 0; color: #9ca3af; }
.sidebar-recent-item:hover { background: #f9fafb; }
.sidebar-recent-item.active { background: #f5f3ff; color: #7c3aed; font-weight: 600; }
.sidebar-recent-empty { font-size: 12px; color: #c4c4c8; padding: 6px 8px; }

.sidebar-footer { padding: 12px 18px; border-top: 1px solid #e5e7eb; font-size: 11px; color: #c4c4c8; }

main { flex: 1; overflow-y: auto; overflow-x: hidden; padding: 32px 32px 80px; min-width: 0; }
main > .view { max-width: 880px; margin: 0 auto; }
.view { display: none; }
.view.active { display: block; }

/* Menú móvil */
.mobile-topbar { display: none; }
.sidebar-overlay { display: none; }

@media (max-width: 768px) {
  .app-shell { position: relative; }

  .mobile-topbar { display: flex; align-items: center; gap: 10px; padding: 12px 16px; background: #fff; border-bottom: 1px solid #e5e7eb; position: sticky; top: 0; z-index: 150; }
  .mobile-menu-btn { width: 34px; height: 34px; border: none; background: #f3f4f6; border-radius: 8px; color: #374151; display: flex; align-items: center; justify-content: center; cursor: pointer; flex-shrink: 0; }
  .mobile-menu-btn:hover { background: #e5e7eb; }
  .mobile-topbar-title { font-size: 14px; font-weight: 700; color: #111827; }

  .sidebar { position: fixed; top: 0; left: 0; bottom: 0; z-index: 300; transform: translateX(-100%); transition: transform .2s ease; box-shadow: 0 0 0 rgba(0,0,0,0); }
  .sidebar.open { transform: translateX(0); box-shadow: 4px 0 24px rgba(0,0,0,.15); }

  .sidebar-overlay.open { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 250; }

  main { padding: 20px 16px 60px; }
}

/* Dashboard */
.dash-header { display: flex; justify-content: space-between; align-items: flex-end; margin-bottom: 24px; }
.dash-title { font-size: 22px; font-weight: 700; color: #111827; }
.dash-subtitle { font-size: 13px; color: #9ca3af; margin-top: 3px; }

/* Tabs */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid #e5e7eb; margin-bottom: 20px; }
.tab-btn { background: none; border: none; padding: 10px 16px; font-size: 13px; font-weight: 600; color: #9ca3af; cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; transition: color .15s, border-color .15s; }
.tab-btn:hover { color: #374151; }
.tab-btn.active { color: #7c3aed; border-bottom-color: #7c3aed; }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* Grid */
.projects-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 14px; }
.project-card { background: #fff; border: 1px solid #e5e7eb; border-radius: 12px; padding: 18px; cursor: pointer; transition: box-shadow .15s, border-color .15s; position: relative; }
.project-card:hover { box-shadow: 0 4px 14px rgba(0,0,0,.08); border-color: #d1d5db; }
.project-card-title { font-size: 14px; font-weight: 600; color: #111827; margin-bottom: 6px; padding-right: 40px; line-height: 1.4; }
.project-card-meta { font-size: 12px; color: #9ca3af; }
.project-card-footer { margin-top: 14px; display: flex; align-items: center; justify-content: space-between; }
.card-del { position: absolute; top: 10px; right: 10px; width: 28px; height: 28px; border-radius: 6px; border: none; background: #f3f4f6; cursor: pointer; display: flex; align-items: center; justify-content: center; color: #9ca3af; transition: background .15s, color .15s; }
.card-del:hover { background: #fee2e2; color: #dc2626; }

/* Badges */
.badge { display: inline-flex; align-items: center; padding: 2px 8px; border-radius: 20px; font-size: 11px; font-weight: 500; }
.badge-gray { background: #f3f4f6; color: #6b7280; }
.badge-green { background: #dcfce7; color: #15803d; }
.badge-red { background: #fee2e2; color: #dc2626; }

/* Empty */
.empty-state { text-align: center; padding: 64px 24px; }
.empty-icon { width: 56px; height: 56px; background: #f3f4f6; border-radius: 16px; display: flex; align-items: center; justify-content: center; margin: 0 auto 16px; color: #9ca3af; }
.empty-title { font-size: 16px; font-weight: 600; color: #374151; margin-bottom: 8px; }
.empty-text { font-size: 13px; color: #9ca3af; max-width: 340px; margin: 0 auto 20px; line-height: 1.6; }

/* Buttons */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 10px 18px; border-radius: 8px; font-size: 13px; font-weight: 600; cursor: pointer; border: none; transition: background .15s; white-space: nowrap; }
.btn-primary { background: #7c3aed; color: #fff; }
.btn-primary:hover { background: #6d28d9; }
.btn-secondary { background: #f3f4f6; color: #374151; }
.btn-secondary:hover { background: #e5e7eb; }
.btn-danger { background: #dc2626; color: #fff; }
.btn-danger:hover { background: #b91c1c; }
.btn-warning { background: #d97706; color: #fff; }
.btn-warning:hover { background: #b45309; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* Modal */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: flex; align-items: center; justify-content: center; z-index: 200; padding: 20px; }
.modal { background: #fff; border-radius: 14px; width: 100%; max-width: 440px; }
.modal-hdr { display: flex; align-items: center; justify-content: space-between; padding: 20px 24px 0; }
.modal-hdr h2 { font-size: 16px; font-weight: 700; color: #111827; }
.modal-close { width: 30px; height: 30px; border: none; background: #f3f4f6; border-radius: 8px; cursor: pointer; display: flex; align-items: center; justify-content: center; color: #6b7280; }
.modal-close:hover { background: #e5e7eb; }
.modal-body { padding: 18px 24px 24px; }
.modal-actions { display: flex; gap: 10px; margin-top: 18px; }

/* Form */
.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 14px; }
label.field-lbl { font-size: 11px; font-weight: 600; color: #6b7280; text-transform: uppercase; letter-spacing: .05em; }
input, select { width: 100%; padding: 9px 12px; border: 1px solid #d1d5db; border-radius: 8px; font-size: 13px; color: #111827; outline: none; transition: border-color .15s, box-shadow .15s; }
input:focus, select:focus { border-color: #7c3aed; box-shadow: 0 0 0 3px rgba(124,58,237,.12); }

/* Project view */
.proj-header { display: flex; align-items: center; gap: 10px; margin-bottom: 28px; flex-wrap: wrap; }
.back-btn { display: flex; align-items: center; gap: 4px; font-size: 13px; color: #7c3aed; font-weight: 500; cursor: pointer; border: none; background: none; padding: 6px 0; flex-shrink: 0; }
.back-btn:hover { text-decoration: underline; }
.sep { width: 1px; height: 18px; background: #e5e7eb; }
.proj-name { font-size: 18px; font-weight: 700; color: #111827; }

/* Steps */
.steps { display: flex; align-items: center; margin-bottom: 28px; }
.step { display: flex; align-items: center; gap: 8px; }
.step-dot { width: 28px; height: 28px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 700; flex-shrink: 0; transition: all .2s; }
.step-dot.pending { background: #f3f4f6; color: #9ca3af; }
.step-dot.active { background: #7c3aed; color: #fff; }
.step-dot.done { background: #dcfce7; color: #15803d; }
.step-lbl { font-size: 12px; font-weight: 500; }
.step-lbl.pending { color: #9ca3af; }
.step-lbl.active { color: #7c3aed; font-weight: 600; }
.step-lbl.done { color: #15803d; }
.step-line { flex: 1; height: 2px; background: #e5e7eb; margin: 0 10px; min-width: 24px; }
.step-line.done { background: #7c3aed; }

/* Step panels */
.step-panel { display: none; }
.step-panel.active { display: block; }
.card { background: #fff; border: 1px solid #e5e7eb; border-radius: 12px; padding: 24px; }
.card-title { font-size: 15px; font-weight: 700; color: #111827; margin-bottom: 4px; }
.card-desc { font-size: 13px; color: #9ca3af; margin-bottom: 20px; line-height: 1.5; }

/* Toggle */
.toggle-row { display: flex; align-items: center; gap: 10px; cursor: pointer; user-select: none; margin-bottom: 16px; }
.toggle { width: 36px; height: 20px; background: #d1d5db; border-radius: 10px; position: relative; transition: background .15s; flex-shrink: 0; }
.toggle.on { background: #7c3aed; }
.toggle::after { content: ''; width: 16px; height: 16px; background: #fff; border-radius: 50%; position: absolute; top: 2px; left: 2px; transition: left .15s; box-shadow: 0 1px 3px rgba(0,0,0,.2); }
.toggle.on::after { left: 18px; }
.toggle-lbl { font-size: 13px; color: #374151; }

/* Drop zone */
.drop-zone { border: 2px dashed #d1d5db; border-radius: 10px; padding: 26px 20px; text-align: center; cursor: pointer; transition: all .15s; }
.drop-zone:hover, .drop-zone.drag { border-color: #7c3aed; background: #faf5ff; }
.drop-zone p { font-size: 13px; color: #9ca3af; }
.drop-zone strong { color: #7c3aed; }
.drop-zone .sub { font-size: 11px; margin-top: 4px; color: #c4b5fd; }

/* File list */
.file-list { margin-top: 10px; display: flex; flex-direction: column; gap: 6px; }
.file-item { display: flex; align-items: center; gap: 8px; padding: 8px 12px; background: #f9fafb; border: 1px solid #e5e7eb; border-radius: 8px; }
.file-icon { color: #7c3aed; flex-shrink: 0; }
.file-name { font-size: 13px; color: #374151; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-size { font-size: 11px; color: #9ca3af; flex-shrink: 0; }
.file-rm { width: 22px; height: 22px; border: none; background: none; cursor: pointer; color: #9ca3af; border-radius: 4px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.file-rm:hover { background: #fee2e2; color: #dc2626; }

/* Step actions */
.step-actions { display: flex; gap: 10px; margin-top: 20px; justify-content: flex-end; }

/* Result */
.result-ok { background: #f0fdf4; border: 1px solid #bbf7d0; border-radius: 12px; padding: 20px; }
.result-err { background: #fef2f2; border: 1px solid #fecaca; border-radius: 12px; padding: 20px; }
.result-title { font-size: 14px; font-weight: 700; margin-bottom: 10px; }
.result-ok .result-title { color: #15803d; }
.result-err .result-title { color: #b91c1c; }
.result-list { padding-left: 18px; font-size: 13px; color: #4b5563; line-height: 2; }
.result-pending { margin-top: 12px; }
.result-pending summary { font-size: 12px; font-weight: 600; color: #92400e; cursor: pointer; }
.result-pending ul { margin-top: 6px; padding-left: 16px; font-size: 12px; color: #78350f; line-height: 1.8; }
.dl-btn { display: inline-flex; align-items: center; gap: 6px; margin-top: 14px; padding: 10px 18px; background: #15803d; color: #fff; border-radius: 8px; font-size: 13px; font-weight: 600; text-decoration: none; transition: background .15s; }
.dl-btn:hover { background: #166534; }

/* Error msg inline */
.err-msg { background: #fef2f2; border: 1px solid #fecaca; border-radius: 8px; padding: 10px 14px; font-size: 13px; color: #b91c1c; margin-bottom: 14px; }

/* Grupos de documentos en campos pendientes */
.pending-doc-group { margin-bottom: 22px; }
.pending-doc-header { font-size: 11px; font-weight: 700; color: #7c3aed; text-transform: uppercase; letter-spacing: .07em; padding: 5px 0 8px; border-bottom: 2px solid #ede9fe; margin-bottom: 12px; }

/* Campos pendientes */
.pending-field { margin-bottom: 16px; }
.pending-field-lbl { font-size: 12px; color: #374151; margin-bottom: 5px; line-height: 1.5; display: block; }
.pending-field-lbl em { font-style: normal; background: #fef9c3; padding: 1px 4px; border-radius: 3px; font-size: 11px; color: #92400e; }
.pending-field input { width: 100%; padding: 9px 12px; border: 1px solid #d1d5db; border-radius: 8px; font-size: 13px; color: #111827; outline: none; transition: border-color .15s, box-shadow .15s; }
.pending-field input:focus { border-color: #7c3aed; box-shadow: 0 0 0 3px rgba(124,58,237,.12); }
.pending-field input.has-suggestion { border-color: #c4b5fd; background: #faf5ff; }

/* Radio group SI/NO y selector de modo oferta */
.radio-group { display: flex; gap: 20px; margin-top: 4px; }
.radio-lbl { display: flex; align-items: center; gap: 6px; font-size: 13px; color: #374151; cursor: pointer; font-weight: 500; }
.radio-lbl input[type="radio"] { accent-color: #7c3aed; width: 15px; height: 15px; cursor: pointer; }
/* Grupo de opciones de elección (□/○) — apilado vertical */
.choice-group { flex-direction: column; gap: 6px; }
.choice-lbl { padding: 4px 8px; border: 1px solid #e5e7eb; border-radius: 6px; background: #fafafa; }
.choice-lbl:hover { border-color: #c4b5fd; background: #faf5ff; }

/* Oferta económica */
.oferta-mode-bar { background: #f5f3ff; border: 1px solid #ede9fe; border-radius: 8px; padding: 10px 14px; margin-bottom: 8px; }
.oferta-mode-bar .radio-group { margin-top: 0; }
.oferta-hint { font-size: 11px; color: #7c3aed; margin-top: 6px; }
.oferta-base { font-size: 12px; color: #374151; margin-bottom: 8px; padding: 6px 10px; background: #fff; border: 1px solid #e5e7eb; border-radius: 6px; }
.oferta-base strong { color: #059669; }

/* Spinner */
.spinner { width: 16px; height: 16px; border: 2px solid rgba(255,255,255,.35); border-top-color: #fff; border-radius: 50%; animation: spin .7s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Historial de generaciones */
.hist-section { margin-top: 36px; }
.hist-header { font-size: 13px; font-weight: 700; color: #374151; margin-bottom: 12px; display: flex; align-items: center; justify-content: space-between; }
.hist-count { font-size: 11px; font-weight: 500; color: #9ca3af; }
.hist-card { background: #fff; border: 1px solid #e5e7eb; border-radius: 10px; padding: 14px 16px; margin-bottom: 10px; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.hist-card-info { flex: 1; min-width: 200px; }
.hist-card-title { font-size: 13px; font-weight: 600; color: #111827; margin-bottom: 3px; }
.hist-card-meta { font-size: 11px; color: #9ca3af; }
.hist-card-actions { display: flex; gap: 8px; align-items: center; flex-shrink: 0; }

/* Selector de lotes (paso 1) */
.lotes-list { display: flex; flex-direction: column; gap: 8px; }
.lote-item { display: flex; align-items: flex-start; gap: 10px; padding: 12px 14px; background: #f9fafb; border: 1px solid #e5e7eb; border-radius: 10px; cursor: pointer; transition: border-color .15s, background .15s; }
.lote-item:hover { border-color: #c4b5fd; }
.lote-item input[type="checkbox"] { margin-top: 2px; accent-color: #7c3aed; width: 16px; height: 16px; flex-shrink: 0; cursor: pointer; }
.lote-item-body { flex: 1; }
.lote-item-title { font-size: 13px; font-weight: 600; color: #111827; }
.lote-item-meta { font-size: 11px; color: #9ca3af; margin-top: 2px; }

/* Resultado por lote (paso 2) — zonas independientes, nunca combinadas */
.lotes-result-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 16px; align-items: start; }
.lote-card { background: #fff; border: 1px solid #e5e7eb; border-radius: 12px; padding: 20px; }
.lote-card-header { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 14px; }
.lote-card-title { font-size: 14px; font-weight: 700; color: #111827; }
.lote-card-sub { font-size: 11px; color: #9ca3af; margin-top: 2px; }
.lote-card-body .pending-doc-group:last-child { margin-bottom: 0; }

/* Modal regenerar — más ancho para los campos */
.modal-wide { max-width: 580px; max-height: 90vh; overflow-y: auto; }
.regen-section-title { font-size: 11px; font-weight: 700; color: #7c3aed; text-transform: uppercase; letter-spacing: .07em; margin: 0 0 10px; }
.regen-section-title + * { margin-top: 0; }

/* Configuración empresa */
.config-group { margin-bottom: 22px; }
.config-group-title { font-size: 11px; font-weight: 700; color: #7c3aed; text-transform: uppercase; letter-spacing: .07em; padding: 5px 0 10px; border-bottom: 2px solid #ede9fe; margin-bottom: 14px; }
.config-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.config-save-bar { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }