:root { --c-primary: #4f6ef7; --c-dark: #1a1a2e; }
* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: 'Segoe UI', sans-serif; background: #f0f2f5; color: var(--c-dark); min-height: 100vh; }
a { color: inherit; }

/* ── HEADER / NAV ── */
header.app-header { background: var(--c-dark); color: white; padding: 13px 28px; display: flex; align-items: center; gap: 12px; box-shadow: 0 2px 8px rgba(0,0,0,0.3); }
header.app-header h1 { font-size: 1.05rem; font-weight: 700; }
header.app-header span.sub { font-size: 0.75rem; opacity: 0.4; margin-left: 8px; }
header.app-header .spacer { flex: 1; }
header.app-header .user-chip { font-size: 0.8rem; opacity: 0.8; display: flex; align-items: center; gap: 10px; }
header.app-header .user-chip button { background: none; border: 1px solid rgba(255,255,255,0.25); color: white; border-radius: 6px; padding: 4px 10px; cursor: pointer; font-size: 0.75rem; }
header.app-header .user-chip button:hover { background: rgba(255,255,255,0.1); }

.tabs-bar { background: var(--c-dark); padding: 0 28px; display: flex; align-items: stretch; }
.tab-btn { padding: 9px 22px; border: none; background: transparent; color: rgba(255,255,255,0.4); cursor: pointer; font-size: 0.84rem; border-bottom: 3px solid transparent; transition: all 0.15s; display: flex; align-items: center; gap: 6px; text-decoration: none; }
.tab-btn:hover { color: white; }
.tab-btn.active { color: white; border-bottom-color: var(--c-primary); }
.tab-btn-admin { margin-left: auto; color: rgba(255,255,255,0.35); }
.tab-btn-admin.active { border-bottom-color: #f59e0b; color: #f59e0b; }

.container { padding: 24px 28px; max-width: 1600px; margin: 0 auto; }

/* ── BTNS ── */
.btn { padding: 7px 14px; border-radius: 8px; border: 1px solid #dde1ea; background: white; cursor: pointer; font-size: 0.82rem; display: inline-flex; align-items: center; gap: 5px; color: #333; transition: all 0.15s; white-space: nowrap; text-decoration: none; }
.btn:hover { background: #f5f7ff; border-color: var(--c-primary); color: var(--c-primary); }
.btn-primary { background: var(--c-primary); color: white; border-color: var(--c-primary); font-weight: 600; }
.btn-primary:hover { background: #3d5ce5; color: white; }
.btn-success { background: #15803d; color: white; border-color: #15803d; font-weight: 700; }
.btn-success:hover { background: #166534; color: white; }
.btn-danger { border-color: #dc2626; color: #dc2626; }
.btn-danger:hover { background: #fff5f5; }
.btn-sm { padding: 5px 10px; font-size: 0.75rem; border-radius: 6px; }
.btn:disabled { opacity: 0.4; cursor: default; pointer-events: none; }

/* ── LOGIN ── */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: linear-gradient(135deg, var(--c-dark) 0%, #2d3a6e 100%); }
.login-box { background: white; border-radius: 16px; padding: 40px; width: 100%; max-width: 380px; box-shadow: 0 20px 60px rgba(0,0,0,0.35); }
.login-box .logo { text-align: center; font-size: 1.3rem; font-weight: 800; margin-bottom: 4px; }
.login-box .logo span { color: var(--c-primary); }
.login-box p.sub { text-align: center; color: #888; font-size: 0.82rem; margin-bottom: 24px; }
.login-box .form-field { margin-bottom: 14px; }
.login-box label { font-size: 0.72rem; color: #666; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; display: block; margin-bottom: 4px; }
.login-box input { width: 100%; padding: 10px 14px; border: 1px solid #dde1ea; border-radius: 8px; font-size: 0.92rem; outline: none; }
.login-box input:focus { border-color: var(--c-primary); }
.login-box button { width: 100%; margin-top: 8px; justify-content: center; padding: 11px; font-size: 0.92rem; }
.login-error { background: #fff5f5; color: #dc2626; border: 1px solid #fecaca; border-radius: 8px; padding: 10px 14px; font-size: 0.82rem; margin-bottom: 14px; }

/* ── CARDS / GRID / TABLE / FORM (compartido entre vistas) ── */
.card { background: white; border-radius: 12px; box-shadow: 0 1px 5px rgba(0,0,0,0.08); padding: 20px; margin-bottom: 16px; }
.card h2 { font-size: 1rem; font-weight: 700; margin-bottom: 4px; }
.card .subtitle { font-size: 0.8rem; color: #888; margin-bottom: 18px; }

.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; }
.form-field { display: flex; flex-direction: column; gap: 4px; }
.form-field.full { grid-column: 1 / -1; }
.form-field label { font-size: 0.72rem; color: #666; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; }
.form-field input, .form-field select, .form-field textarea { padding: 9px 12px; border: 1px solid #dde1ea; border-radius: 8px; font-size: 0.88rem; outline: none; font-family: inherit; }
.form-field input:focus, .form-field select:focus, .form-field textarea:focus { border-color: var(--c-primary); }
.form-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 18px; padding-top: 16px; border-top: 1px solid #f0f0f0; }

table.data-table { width: 100%; border-collapse: collapse; font-size: 0.82rem; }
table.data-table thead tr { background: #f8f9fb; }
table.data-table th { padding: 8px 14px; text-align: left; font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.05em; color: #888; border-bottom: 2px solid #eef0f4; }
table.data-table td { padding: 10px 14px; border-bottom: 1px solid #f0f2f5; }
table.data-table tbody tr:hover td { background: #f8faff; }
.role-badge { display: inline-block; padding: 2px 10px; border-radius: 20px; font-size: 0.7rem; font-weight: 700; }
.role-badge.superadmin { background: #ede9fe; color: #6d28d9; }
.role-badge.admin { background: #fef3c7; color: #92400e; }
.role-badge.usuario { background: #eff6ff; color: #1d4ed8; }
.tipo-badge { display: inline-block; padding: 2px 10px; border-radius: 20px; font-size: 0.68rem; font-weight: 700; }
.tipo-badge.presupuesto { background: #eff6ff; color: #1d4ed8; }
.tipo-badge.albaran { background: #f0fdf4; color: #15803d; }
.tipo-badge.cotizacion { background: #fef3c7; color: #92400e; }

.empty-state { text-align: center; padding: 56px 20px; color: #aaa; background: white; border-radius: 12px; }
.empty-state .ei { font-size: 3rem; margin-bottom: 10px; }

.toast { position: fixed; bottom: 20px; right: 20px; background: var(--c-dark); color: white; padding: 12px 18px; border-radius: 10px; font-size: 0.85rem; box-shadow: 0 8px 24px rgba(0,0,0,0.25); z-index: 2000; opacity: 0; transform: translateY(10px); transition: all 0.25s; }
.toast.show { opacity: 1; transform: translateY(0); }
.toast.error { background: #dc2626; }
.toast.success { background: #15803d; }

.modal-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.6); z-index: 1000; align-items: center; justify-content: center; padding: 20px; }
.modal-overlay.open { display: flex; }
.modal-box { background: white; border-radius: 14px; max-width: 820px; width: 100%; max-height: 93vh; overflow-y: auto; box-shadow: 0 20px 60px rgba(0,0,0,0.35); }
.modal-box.wide { max-width: 98vw; width: 98vw; }
.modal-topbar { position: sticky; top: 0; background: #f8f9fb; padding: 10px 16px; display: flex; gap: 8px; justify-content: flex-end; border-bottom: 1px solid #eee; z-index: 10; align-items: center; }
.mu-box { max-width: 460px; }
.mu-body { padding: 26px; }
.mu-body h3 { font-size: 1rem; font-weight: 700; margin-bottom: 16px; }
.mu-field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.mu-field label { font-size: 0.74rem; color: #666; font-weight: 600; }
.mu-field input, .mu-field select, .mu-field textarea { padding: 8px 12px; border: 1px solid #dde1ea; border-radius: 8px; font-size: 0.9rem; outline: none; font-family: inherit; }
.mu-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 18px; }

/* ── Líneas de documento (formulario) ── */
.lineas-table { width: 100%; border-collapse: collapse; font-size: 0.82rem; margin-bottom: 10px; }
.lineas-table th { text-align: left; font-size: 0.68rem; color: #999; text-transform: uppercase; padding: 6px 8px; }
.lineas-table td { padding: 4px 6px; }
.lineas-table input { width: 100%; padding: 7px 9px; border: 1px solid #dde1ea; border-radius: 6px; font-size: 0.85rem; }
.lineas-table td.imp { text-align: right; font-weight: 600; white-space: nowrap; padding-right: 10px; }
.lineas-table .rm-btn { background: none; border: none; color: #dc2626; cursor: pointer; font-size: 1rem; }

.qr-box { text-align: center; background: white; border-radius: 12px; padding: 20px; }
.qr-box img { width: 200px; height: 200px; }
.verify-link { font-size: 0.78rem; color: #888; word-break: break-all; margin-top: 8px; }

/* ── Selector de cliente (superadmin) y etiquetas ── */
.ctx-picker { display: flex; align-items: center; gap: 8px; font-size: 0.75rem; color: rgba(255,255,255,0.6); }
.ctx-picker select { background: rgba(255,255,255,0.08); color: white; border: 1px solid rgba(255,255,255,0.25); border-radius: 6px; padding: 5px 8px; font-size: 0.8rem; max-width: 260px; }
.ctx-picker select option { color: var(--c-dark); }
.ctx-name { font-size: 0.8rem; color: rgba(255,255,255,0.75); padding: 4px 10px; border: 1px solid rgba(255,255,255,0.2); border-radius: 6px; }
.color-dot { display: inline-block; width: 14px; height: 14px; border-radius: 50%; border: 1px solid rgba(0,0,0,0.15); vertical-align: middle; }
.pill { display: inline-block; padding: 2px 9px; border-radius: 20px; font-size: 0.68rem; font-weight: 700; }
.pill.ok { background: #ecfdf3; color: #15803d; }
.pill.off { background: #fef2f2; color: #b91c1c; }
.mini-fieldset { border: 1px solid #eef0f4; border-radius: 10px; padding: 10px 14px 2px; margin: 6px 0 4px; }
.mini-fieldset legend { font-size: 0.72rem; color: #888; font-weight: 600; padding: 0 6px; }

/* ── Icono (i) y su globo ── */
.info { display: inline-flex; align-items: center; justify-content: center; width: 15px; height: 15px; border-radius: 50%; background: #e8edff; color: var(--c-primary); font: italic 700 10px/1 Georgia, serif; cursor: help; vertical-align: middle; margin-left: 5px; text-transform: none; letter-spacing: 0; flex-shrink: 0; user-select: none; }
.info:hover, .info:focus { background: var(--c-primary); color: white; outline: none; }
.info-tip { position: fixed; z-index: 3000; max-width: 260px; background: var(--c-dark); color: white; font-size: 0.76rem; line-height: 1.4; padding: 8px 11px; border-radius: 8px; box-shadow: 0 6px 20px rgba(0,0,0,0.25); pointer-events: none; opacity: 0; transition: opacity 0.12s; font-weight: 400; text-transform: none; letter-spacing: 0; }
.info-tip.show { opacity: 1; }

/* ── Botón de instrucciones (arriba a la derecha) ── */
.help-toggle { display: inline-flex; align-items: center; gap: 6px; background: rgba(255,255,255,0.08); border: 1px solid rgba(255,255,255,0.25); color: white; border-radius: 20px; padding: 4px 6px 4px 11px; font-size: 0.75rem; cursor: pointer; }
.help-toggle:hover { background: rgba(255,255,255,0.15); }
.help-toggle .ht-state { background: #22c55e; color: #052e14; border-radius: 12px; padding: 1px 7px; font-weight: 800; font-size: 0.66rem; }
.help-toggle[aria-pressed=false] .ht-state { background: rgba(255,255,255,0.2); color: white; }

/* ── Cajas de instrucciones ── */
.guide { display: flex; gap: 12px; align-items: flex-start; background: #f0f5ff; border: 1px solid #cfdcff; border-left: 4px solid var(--c-primary); border-radius: 10px; padding: 12px 14px; margin-bottom: 16px; font-size: 0.82rem; color: #2a3350; }
.guide-icon { font-size: 1.2rem; line-height: 1; }
.guide-body { flex: 1; }
.guide-body strong { display: block; margin-bottom: 4px; font-size: 0.86rem; }
.guide-body ol { margin: 0 0 0 18px; }
.guide-body li { margin: 2px 0; line-height: 1.4; }
.guide-note { margin-top: 6px; color: #5a6480; font-size: 0.76rem; }
.guide-x { background: none; border: none; color: #7b86a8; font-size: 0.7rem; cursor: pointer; white-space: nowrap; }
.guide-x:hover { color: var(--c-primary); text-decoration: underline; }
.help-off .guide, .help-off .guide-inline { display: none !important; }
.guide-inline { font-size: 0.74rem; color: #5a6480; background: #f0f5ff; border-radius: 6px; padding: 6px 9px; margin: 6px 0 10px; line-height: 1.4; }

/* ── Visor PDF propio ── */
.pdfv { position: relative; display: flex; flex-direction: column; background: #525659; overflow: hidden; }
.pdfv-scroll { flex: 1; overflow: auto; padding: 16px; min-height: 0; }
.pdfv-pages canvas { display: block; margin: 0 auto 14px; box-shadow: 0 3px 14px rgba(0,0,0,0.45); background: white; }
.pdfv-zoom { position: absolute; top: 10px; right: 14px; display: flex; align-items: center; gap: 2px; background: rgba(20,22,30,0.82); border-radius: 20px; padding: 3px; box-shadow: 0 2px 8px rgba(0,0,0,0.3); }
.pdfv-zoom button { width: 30px; height: 30px; border: none; border-radius: 50%; background: none; color: white; font-size: 1.15rem; line-height: 1; cursor: pointer; }
.pdfv-zoom button:hover { background: rgba(255,255,255,0.15); }
.pdfv-pct { color: #e5e7eb; font-size: 0.72rem; min-width: 44px; text-align: center; }
.pdfv-loading, .pdfv-error { color: #e5e7eb; font-size: 0.85rem; text-align: center; padding: 40px 0; }
.pdfv-error a { color: white; }

/* ── Modal QR grande ── */
.qr-modal-box { max-width: 460px; text-align: center; padding: 26px 24px 20px; position: relative; }
.qr-close { position: absolute; top: 10px; right: 12px; background: none; border: none; font-size: 1.1rem; cursor: pointer; color: #888; }
.qr-modal-num { font-weight: 800; font-size: 1.05rem; margin-bottom: 10px; }
.qr-modal-img { width: min(78vw, 60vh, 380px); height: auto; aspect-ratio: 1; image-rendering: pixelated; }
.qr-modal-tip { font-size: 0.82rem; color: #555; margin: 10px 0 14px; }
.qr-modal-actions { display: flex; gap: 8px; justify-content: center; }
.btn-qr { border-color: #6d28d9; color: #6d28d9; }
.btn-qr:hover { background: #f5f3ff; color: #6d28d9; border-color: #6d28d9; }

/* ── Chat de ayuda ── */
.chat { position: fixed; right: 20px; bottom: 20px; z-index: 1500; font-size: 0.84rem; }
.chat-fab { display: flex; align-items: center; gap: 7px; background: var(--c-primary); color: white; border: none; border-radius: 30px; padding: 11px 17px; font-size: 1rem; cursor: pointer; box-shadow: 0 6px 20px rgba(79,110,247,0.45); }
.chat-fab span { font-size: 0.85rem; font-weight: 700; }
.chat-fab:hover { background: #3d5ce5; }
.chat.open .chat-fab { display: none; }
.chat-panel { display: none; width: min(360px, calc(100vw - 32px)); height: min(520px, calc(100vh - 100px)); background: white; border-radius: 16px; box-shadow: 0 16px 50px rgba(0,0,0,0.3); flex-direction: column; overflow: hidden; }
.chat.open .chat-panel { display: flex; }
.chat-head { background: var(--c-dark); color: white; padding: 12px 16px; display: flex; align-items: baseline; gap: 8px; }
.chat-head span { font-size: 0.72rem; opacity: 0.6; flex: 1; }
.chat-x { background: none; border: none; color: white; opacity: 0.7; cursor: pointer; font-size: 0.95rem; }
.chat-body { flex: 1; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 8px; background: #f6f7fb; }
.chat-msg { max-width: 86%; padding: 8px 12px; border-radius: 14px; line-height: 1.4; white-space: pre-line; }
.chat-msg.bot { background: white; border: 1px solid #e6e9f0; align-self: flex-start; border-bottom-left-radius: 4px; }
.chat-msg.me { background: var(--c-primary); color: white; align-self: flex-end; border-bottom-right-radius: 4px; }
.chat-opts { display: flex; flex-wrap: wrap; gap: 6px; }
.chat-opts button, .chat-go { border: 1px solid #c9d3ff; background: white; color: var(--c-primary); border-radius: 16px; padding: 6px 11px; font-size: 0.78rem; cursor: pointer; text-decoration: none; }
.chat-opts button:hover, .chat-go:hover { background: #eef2ff; }
.chat-opts button.nav { border-color: #e2e5ec; color: #777; }
.chat-go { background: #eef2ff; font-weight: 600; }
.chat-form { display: flex; border-top: 1px solid #eee; }
.chat-form input { flex: 1; border: none; padding: 12px 14px; font-size: 0.84rem; outline: none; font-family: inherit; }
.chat-form button { border: none; background: none; color: var(--c-primary); font-size: 1.1rem; padding: 0 14px; cursor: pointer; }
/* ── Autorrelleno desde el directorio ── */
[data-auto] { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14'%3E%3Ctext y='12' font-size='12'%3E%F0%9F%93%87%3C/text%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 8px top 8px; padding-right: 28px !important; }
.ac-box { position: fixed; z-index: 2500; background: white; border: 1px solid #d5dbea; border-radius: 10px; box-shadow: 0 12px 32px rgba(0,0,0,0.18); overflow: hidden; display: none; max-width: 520px; }
.ac-item { padding: 8px 12px; cursor: pointer; border-bottom: 1px solid #f2f4f8; }
.ac-item.on, .ac-item:hover { background: #eef2ff; }
.ac-n { font-size: 0.84rem; font-weight: 600; color: var(--c-dark); }
.ac-cod { font-weight: 400; color: #888; font-family: Consolas, monospace; font-size: 0.72rem; }
.ac-d { font-size: 0.74rem; color: #777; margin-top: 1px; }
.ac-foot { font-size: 0.66rem; color: #aaa; padding: 5px 12px; background: #fafbfd; }
@keyframes acFlash { from { background-color: #dcfce7; } to { background-color: white; } }
.ac-flash { animation: acFlash 1.2s ease-out; }

@media print { .chat, .help-toggle, .guide { display: none !important; } }

@media print {
  header.app-header, .tabs-bar, .no-print { display: none !important; }
}
