/* Markatel · PedidosAuto Basor — UI styles */
:root {
  --c-bg: #0f172a;
  --c-bg-2: #1e293b;
  --c-card: #ffffff;
  --c-text: #1e293b;
  --c-muted: #64748b;
  --c-primary: #2563eb;
  --c-primary-hover: #1d4ed8;
  --c-success: #16a34a;
  --c-error: #dc2626;
  --c-warning: #d97706;
  --c-error-bg: #fee2e2;
  --c-warning-bg: #fef3c7;
  --c-success-bg: #d1fae5;
  --c-border: #e2e8f0;
  --c-accent: #0ea5e9;
  --c-bg-page: #f8fafc;
  --radius: 8px;
  --shadow: 0 10px 25px rgba(0,0,0,0.08);
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.06);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: var(--c-text);
  background: var(--c-bg-page);
}
code { font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace; font-size: 0.9em; background: #f1f5f9; padding: 0.1em 0.35em; border-radius: 3px; }
pre code { background: transparent; padding: 0; }
.muted { color: var(--c-muted); }

/* Login */
.login-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: linear-gradient(135deg, var(--c-bg) 0%, var(--c-bg-2) 100%); padding: 1rem; }
.login-box { width: 100%; max-width: 420px; background: var(--c-card); padding: 2.5rem 2rem; border-radius: var(--radius); box-shadow: var(--shadow); }
.brand { display: flex; align-items: center; justify-content: center; gap: 0.5rem; margin-bottom: 0.5rem; font-weight: 700; font-size: 1.5rem; }
.logo-mark { color: var(--c-primary); }
.logo-divider { color: var(--c-muted); }
.logo-product { color: var(--c-text); }
.tagline { text-align: center; color: var(--c-muted); margin: 0 0 2rem 0; font-size: 0.9rem; }

form label { display: block; margin-bottom: 1rem; }
form label span { display: block; font-size: 0.85rem; font-weight: 600; margin-bottom: 0.35rem; color: var(--c-text); }
form input { width: 100%; padding: 0.65rem 0.85rem; border: 1px solid var(--c-border); border-radius: var(--radius); font-size: 1rem; transition: border 0.15s; background: white; }
form input:focus { outline: none; border-color: var(--c-primary); box-shadow: 0 0 0 3px rgba(37,99,235,0.15); }
form button { padding: 0.75rem 1.25rem; background: var(--c-primary); color: white; border: none; border-radius: var(--radius); font-size: 1rem; font-weight: 600; cursor: pointer; transition: background 0.15s; }
form button:hover { background: var(--c-primary-hover); }
form button:disabled { background: var(--c-muted); cursor: not-allowed; }

.login-box form button { width: 100%; margin-top: 0.5rem; }
.login-footer { text-align: center; margin-top: 1.5rem; color: var(--c-muted); }

.alert { padding: 0.7rem 0.9rem; border-radius: var(--radius); margin-bottom: 1rem; font-size: 0.9rem; }
.alert-error { background: var(--c-error-bg); color: var(--c-error); border: 1px solid #fecaca; }

/* Topbar */
.topbar { display: flex; align-items: center; padding: 1rem 2rem; background: white; border-bottom: 1px solid var(--c-border); box-shadow: var(--shadow-sm); gap: 2rem; }
.topbar-brand { font-weight: 700; display: flex; gap: 0.5rem; align-items: center; }
.topbar-nav { list-style: none; margin: 0; padding: 0; display: flex; gap: 1.5rem; flex: 1; }
.topbar-nav a { color: var(--c-muted); text-decoration: none; font-weight: 500; padding: 0.35rem 0; border-bottom: 2px solid transparent; transition: all 0.15s; }
.topbar-nav a:hover { color: var(--c-text); }
.topbar-nav a.active { color: var(--c-primary); border-bottom-color: var(--c-primary); }
.topbar-user { display: flex; gap: 0.5rem; align-items: center; font-size: 0.85rem; }
.topbar-user .user-pill { display: inline-flex; align-items: center; padding: 0.35rem 0.75rem; background: #f1f5f9; border: 1px solid var(--c-border); border-radius: var(--radius); color: var(--c-text); font-weight: 500; line-height: 1.2; }
.topbar-user form { margin: 0; }
.btn-link { background: white; border: 1px solid var(--c-border); padding: 0.35rem 0.75rem; border-radius: var(--radius); cursor: pointer; color: var(--c-text); font-size: 0.85rem; line-height: 1.2; text-decoration: none; font-family: inherit; }
.btn-link:hover { background: #f1f5f9; }

.container { max-width: 1200px; margin: 2rem auto; padding: 0 2rem; }
.hero h1 { margin: 0 0 0.5rem 0; font-size: 1.75rem; }
.hero p { color: var(--c-muted); margin: 0 0 2rem 0; }

/* Dropzone */
.dropzone-wrap { margin-bottom: 2rem; }
.dropzone {
  display: block; cursor: pointer; background: white; border: 2px dashed var(--c-border);
  border-radius: var(--radius); padding: 3rem 2rem; text-align: center; transition: all 0.15s;
}
.dropzone:hover, .dropzone.drag-active { border-color: var(--c-primary); background: #eff6ff; }
.dropzone-icon { font-size: 2.5rem; color: var(--c-primary); margin-bottom: 0.5rem; }
.dropzone-content p { margin: 0.5rem 0; }
.dropzone-content small { display: block; color: var(--c-muted); }
.filename-shown { margin-top: 0.5rem; color: var(--c-success) !important; font-weight: 600; }
#upload-btn { margin-top: 1rem; }
.btn-primary { padding: 0.65rem 1.25rem; background: var(--c-primary); color: white; border: none; border-radius: var(--radius); cursor: pointer; font-size: 1rem; font-weight: 600; }
.btn-primary:hover { background: var(--c-primary-hover); }
.btn-primary:disabled { background: var(--c-muted); cursor: not-allowed; }
.btn-secondary { padding: 0.65rem 1.25rem; background: white; color: var(--c-text); border: 1px solid var(--c-border); border-radius: var(--radius); cursor: pointer; font-size: 1rem; font-weight: 500; text-decoration: none; display: inline-block; }
.btn-secondary:hover { background: #f1f5f9; }
.spinner { display: inline-block; margin-left: 1rem; }
.spinner.htmx-indicator { display: none; }
.spinner.htmx-request { display: inline-block; }
.spinner.htmx-request::after { content: "Procesando..."; color: var(--c-primary); font-weight: 600; }

/* Tables */
.orders-table { width: 100%; border-collapse: collapse; background: white; border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow-sm); margin-top: 1rem; }
.orders-table thead { background: #f8fafc; }
.orders-table th { text-align: left; padding: 0.65rem 0.85rem; font-size: 0.8rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; color: var(--c-muted); border-bottom: 1px solid var(--c-border); }
.orders-table td { padding: 0.65rem 0.85rem; border-bottom: 1px solid var(--c-border); font-size: 0.9rem; }
.orders-table tr:last-child td { border-bottom: none; }
.orders-table tr:hover { background: #f8fafc; }
.orders-table .num { text-align: right; font-variant-numeric: tabular-nums; }

/* Badges */
.badge { display: inline-block; padding: 0.15rem 0.55rem; border-radius: 999px; font-size: 0.75rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.03em; }
.badge-pending_review { background: var(--c-warning-bg); color: var(--c-warning); }
.badge-emitted { background: var(--c-success-bg); color: var(--c-success); }
.badge-error { background: var(--c-error-bg); color: var(--c-error); }
.badge-ok { background: var(--c-success-bg); color: var(--c-success); }
.badge-warning { background: var(--c-warning-bg); color: var(--c-warning); }

/* Result box */
.result-box { background: white; border-radius: var(--radius); padding: 1.5rem; margin: 1.5rem 0; box-shadow: var(--shadow-sm); }
.result-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 1.5rem; padding-bottom: 1rem; border-bottom: 1px solid var(--c-border); }
.result-header h2 { margin: 0 0 0.25rem 0; font-size: 1.3rem; }
.result-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 1rem; margin-bottom: 1.5rem; }
.result-card { background: #f8fafc; padding: 0.9rem 1rem; border-radius: var(--radius); }
.card-label { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--c-muted); margin-bottom: 0.35rem; font-weight: 600; }
.card-value { font-size: 1.05rem; font-weight: 600; }
.result-actions { margin-top: 1.5rem; display: flex; gap: 0.75rem; justify-content: flex-end; flex-wrap: wrap; align-items: center; }
.result-actions form { display: inline; }

/* Warnings */
.warnings-details { background: #fefce8; border: 1px solid #fde68a; border-radius: var(--radius); padding: 0.75rem 1rem; margin: 1rem 0; }
.warnings-details summary { cursor: pointer; font-weight: 600; color: var(--c-warning); }
.warnings-list { list-style: none; padding: 0.5rem 0 0 0; margin: 0.5rem 0 0 0; }
.warnings-list li { padding: 0.5rem 0; border-top: 1px solid #fde68a; font-size: 0.9rem; }
.warnings-list li:first-child { border-top: none; }
.warnings-list li small { color: var(--c-muted); margin: 0 0.5rem; }

/* Filters */
.filters { background: white; padding: 1rem 1.25rem; border-radius: var(--radius); margin-bottom: 1.5rem; box-shadow: var(--shadow-sm); }
.filters-form { display: flex; gap: 1rem; align-items: end; flex-wrap: wrap; }
.filters-form label { flex: 1; min-width: 150px; margin-bottom: 0; }
.filters-form .btn-primary,
.filters-form .btn-clear {
  padding: 0.65rem 1.25rem;
  border-radius: var(--radius);
  font-size: 0.9rem;
  line-height: 1.2;
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
  border: 1px solid var(--c-border);
  font-family: inherit;
}
.filters-form .btn-primary { background: var(--c-accent, #2563eb); color: white; border-color: var(--c-accent, #2563eb); }
.filters-form .btn-primary:hover { filter: brightness(0.95); }
.filters-form .btn-clear { background: white; color: var(--c-text); }
.filters-form .btn-clear:hover { background: #f1f5f9; }

/* API hint */
.api-hint { background: white; padding: 1.5rem; border-radius: var(--radius); margin-top: 2rem; box-shadow: var(--shadow-sm); border-left: 4px solid var(--c-accent); }
.api-hint pre { background: var(--c-bg); color: #f1f5f9; padding: 0.85rem 1rem; border-radius: var(--radius); overflow-x: auto; margin: 0.5rem 0; }
.api-hint pre code { background: transparent; color: inherit; font-size: 0.9rem; }

.recent { margin-top: 2rem; }
.recent h3 { margin: 0 0 0.5rem 0; font-size: 1rem; color: var(--c-muted); text-transform: uppercase; letter-spacing: 0.05em; }

/* Status badges añadidos en validación */
.badge-validated_ready { background: var(--c-success-bg); color: var(--c-success); }
.badge-needs_attention { background: var(--c-error-bg); color: var(--c-error); }
.badge-quarantine { background: var(--c-error-bg); color: var(--c-error); }
.badge-emitted { background: #dbeafe; color: #1d4ed8; }
.badge-pass { background: var(--c-success-bg); color: var(--c-success); }
.badge-skip { background: #e2e8f0; color: #475569; }

/* Result box highlight por status */
.result-status-needs_attention { border-left: 4px solid var(--c-error); }
.result-status-validated_ready { border-left: 4px solid var(--c-success); }
.result-status-pending_review  { border-left: 4px solid var(--c-warning); }

.alert-info { background: #dbeafe; color: #1d4ed8; border: 1px solid #bfdbfe; }
.alert-warning { background: var(--c-warning-bg); color: var(--c-warning); border: 1px solid #fde68a; }

button:disabled { opacity: 0.5; cursor: not-allowed; }

.warning-error { background: #fef2f2; }
.warning-warning { background: #fffbeb; }
.warning-pass { background: #f0fdf4; }


.btn-danger { border-color: #dc2626; color: #dc2626; }
.btn-danger:hover { background: #fef2f2; }


.doc-lines-section { margin: 2rem 0; }
.doc-lines-section h3 { margin-bottom: 0.75rem; }
.table-scroll { overflow-x: auto; max-height: 500px; overflow-y: auto; border: 1px solid var(--c-border); border-radius: var(--radius); }
.table-scroll table { margin: 0; }

/* Toast de notificacion (emision a SAP, etc.) */
.toast {
  position: fixed; top: 1.25rem; right: 1.25rem; z-index: 9999;
  max-width: 360px; padding: 0.85rem 1.1rem;
  border-radius: var(--radius); box-shadow: var(--shadow);
  font-size: 0.92rem; font-weight: 600; color: #fff;
  opacity: 0; transform: translateY(-12px);
  transition: opacity .3s ease, transform .3s ease;
}
.toast-show { opacity: 1; transform: translateY(0); }
.toast-success { background: var(--c-success); }
.toast-error   { background: var(--c-error); }
.toast-info    { background: #57606a; }

/* Boton de descarga del XML emitido (resaltado vs btn-secondary) */
.btn-download {
  padding: 0.65rem 1.25rem; background: var(--c-success);
  color: #fff; border: 1px solid var(--c-success);
  border-radius: var(--radius); cursor: pointer;
  font-size: 1rem; font-weight: 600;
  text-decoration: none; display: inline-block;
}
.btn-download:hover { filter: brightness(0.95); }

/* --- Vista de revisión de líneas (detalle de pedido) --- */
.review-banner { display: flex; align-items: center; gap: 0.9rem; padding: 0.9rem 1.1rem; border-radius: var(--radius); margin: 0 0 1.5rem 0; border: 1px solid transparent; }
.review-banner .review-icon { font-size: 1.4rem; line-height: 1; width: 2.3rem; height: 2.3rem; display: flex; align-items: center; justify-content: center; border-radius: 50%; flex: 0 0 auto; font-weight: 700; color: #fff; }
.review-banner .review-text { display: flex; flex-direction: column; gap: 0.15rem; }
.review-banner .review-text strong { font-size: 1.05rem; }
.review-banner .review-text span { font-size: 0.88rem; opacity: 0.9; }
.review-ok    { background: var(--c-success-bg); border-color: #a7f3d0; color: #065f46; }
.review-ok .review-icon    { background: var(--c-success); }
.review-warn  { background: var(--c-warning-bg); border-color: #fde68a; color: #92400e; }
.review-warn .review-icon  { background: var(--c-warning); }
.review-error { background: var(--c-error-bg); border-color: #fecaca; color: #991b1b; }
.review-error .review-icon { background: var(--c-error); }

.lines-head { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 0.5rem; }
.lines-head h3 { margin: 0; }
.lines-legend { display: flex; gap: 0.4rem; flex-wrap: wrap; }
.lines-legend .chip { font-size: 0.72rem; font-weight: 600; padding: 0.15rem 0.55rem; border-radius: 999px; }
.chip-ok    { background: var(--c-success-bg); color: var(--c-success); }
.chip-warn  { background: var(--c-warning-bg); color: var(--c-warning); }
.chip-error { background: var(--c-error-bg); color: var(--c-error); }

.lines-table thead th { position: sticky; top: 0; background: #f1f5f9; z-index: 1; }
.lines-table td { vertical-align: top; }
.lines-table .check-col { text-align: center; width: 2.6rem; }
.lines-table .chk { font-weight: 700; cursor: help; }
.chk-ok { color: var(--c-success); }
.chk-warn { color: var(--c-warning); }
.chk-error { color: var(--c-error); }
.lines-table tfoot .total-row td { background: #f1f5f9; border-top: 2px solid var(--c-border); border-bottom: none; font-weight: 700; font-size: 0.95rem; }
.lines-note { margin-top: 0.6rem; }

/* --- Chips de estado (Historial) + badge de pendientes en topbar --- */
.status-chips { display: flex; gap: 0.5rem; flex-wrap: wrap; margin: 0 0 1rem 0; align-items: center; }
.chips-hint { font-size: 0.78rem; color: #6e7781; margin-right: 0.15rem; }
.chip-tick { font-weight: 700; }
.chip-link {
  display: inline-block; padding: 0.3rem 0.9rem; border-radius: 999px;
  border: 1px solid #d0d7de; background: #fff; color: #444;
  font-size: 0.85rem; text-decoration: none;
}
.chip-link:hover { border-color: #0969da; color: #0969da; }
.chip-link.chip-active { background: #0969da; border-color: #0969da; color: #fff; font-weight: 600; }
.chip-link.chip-pend:not(.chip-active) { border-color: #d4a72c; color: #9a6700; background: #fff8e5; }
.nav-badge {
  display: inline-block; min-width: 1.2rem; padding: 0 0.35rem; margin-left: 0.15rem;
  border-radius: 999px; background: #d4a72c; color: #fff;
  font-size: 0.72rem; font-weight: 700; text-align: center; vertical-align: middle;
}

/* Detalle: correo original y visor PDF */
.email-body {
  white-space: pre-wrap;
  word-break: break-word;
  background: #f8f9fa;
  border: 1px solid #e3e6ea;
  border-radius: 6px;
  padding: .75rem 1rem;
  margin-top: .75rem;
  font-size: .85rem;
  line-height: 1.45;
  max-height: 22rem;
  overflow-y: auto;
}
.pdf-viewer {
  width: 100%;
  height: 70vh;
  border: 1px solid #e3e6ea;
  border-radius: 6px;
  margin-top: .75rem;
}

/* Edición manual en la revisión */
.edit-cabecera { margin: .75rem 0; }
.edit-form { display: flex; flex-wrap: wrap; gap: .75rem; margin-top: .75rem; align-items: flex-end; }
.edit-form label { display: flex; flex-direction: column; font-size: .8rem; color: #555; gap: .25rem; }
.edit-form label.full { flex: 1 1 100%; }
.edit-form input, .edit-form textarea {
  border: 1px solid #cfd4da; border-radius: 5px; padding: .35rem .5rem; font-size: .9rem; min-width: 14rem;
}
.edit-form textarea { width: 100%; font-family: inherit; }
.ref-inline { display: flex; gap: .25rem; align-items: center; margin: 0; }
.ref-inline input { border: 1px solid #cfd4da; border-radius: 4px; padding: .2rem .35rem; font-size: .85rem; font-family: monospace; }
/* Resalta la referencia con cambios sin guardar (se confirman todas con un botón). */
.ref-inline.changed input { border-color: #1f883d; background: #e6f4ea; box-shadow: 0 0 0 1px #1f883d33; }
.acciones-col { white-space: nowrap; text-align: center; }
.acciones-col form { margin: 0; display: inline; }
.btn-mini {
  border: 1px solid transparent; background: transparent; color: #57606a;
  border-radius: 5px; padding: .25rem .4rem; cursor: pointer;
  font-size: .95rem; line-height: 1; display: inline-flex; align-items: center;
}
.btn-mini:hover { background: #eef1f4; color: #24292f; }
/* Botón "Guardar referencias" (guardado masivo). Compacto, alineado en lines-head. */
.btn-bulk-refs { padding: .4rem .9rem; font-size: .9rem; }
.btn-bulk-refs.has-changes { box-shadow: 0 0 0 3px var(--c-primary, #0969da)33; }
.btn-del { color: #6e7781; }
.btn-del:hover { background: #fdeceb; color: #cf222e; }
.btn-del svg { display: block; }

.sede-selector { border-left: 3px solid #d4a72c; margin: .75rem 0; }
.sede-selector select { border: 1px solid #cfd4da; border-radius: 5px; padding: .35rem .5rem; font-size: .9rem; min-width: 22rem; }

.warn-notes { font-size: .82rem; margin-top: .3rem; font-style: italic; }
