/* Operaciones ABBA — estilos base */

:root {
    --bg: #f4f5f7;
    --surface: #ffffff;
    --surface-2: #f9fafb;
    --border: #e2e8f0;
    --border-strong: #cbd5e1;
    --text: #0f172a;
    --text-muted: #64748b;
    --text-soft: #94a3b8;
    --primary: #1e293b;
    --primary-hover: #0f172a;
    --accent: #1e40af;
    --accent-hover: #1e3a8a;
    --accent-soft: #eff6ff;
    --success: #15803d;
    --success-soft: #dcfce7;
    --warning: #b45309;
    --warning-soft: #fef3c7;
    --danger: #b91c1c;
    --danger-soft: #fee2e2;
    --info: #0369a1;
    --info-soft: #e0f2fe;
    --radius: 6px;
    --radius-lg: 10px;
    --shadow-sm: 0 1px 2px rgba(15, 23, 42, .04), 0 1px 1px rgba(15, 23, 42, .02);
    --shadow: 0 4px 12px rgba(15, 23, 42, .08), 0 1px 2px rgba(15, 23, 42, .04);
    --shadow-lg: 0 20px 50px rgba(15, 23, 42, .18);
    --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
    font-family: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, sans-serif;
    color: var(--text);
    background: var(--bg);
    font-size: 14px;
    line-height: 1.45;
    -webkit-font-smoothing: antialiased;
}

/* ===== Login ===== */
.body-login {
    min-height: 100vh;
    display: grid;
    place-items: center;
    background: linear-gradient(135deg, #f8fafc 0%, #e2e8f0 100%);
}
.login-shell { width: min(420px, 92vw); padding: 24px; }
.login-card {
    background: var(--surface);
    border-radius: var(--radius-lg);
    padding: 36px 32px;
    box-shadow: var(--shadow-lg);
}
.login-header { text-align: center; margin-bottom: 24px; }
.login-header h1 {
    margin: 16px 0 4px; font-size: 24px; font-weight: 600; letter-spacing: -0.01em;
}
.login-sub { margin: 0; color: var(--text-muted); font-size: 12px; }
.login-form { display: flex; flex-direction: column; gap: 16px; }

.brand-mark {
    display: inline-flex; align-items: center; justify-content: center;
    width: 56px; height: 56px; border-radius: 12px;
    background: var(--primary); color: #fff;
    font-weight: 700; letter-spacing: 0.04em; font-size: 16px;
}
.brand-mark.sm { width: 36px; height: 36px; border-radius: 8px; font-size: 12px; }

/* ===== Botones ===== */
.btn {
    display: inline-flex; align-items: center; justify-content: center;
    padding: 8px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface); color: var(--text);
    font: inherit; cursor: pointer;
    transition: background .15s, border-color .15s, color .15s, box-shadow .15s;
}
.btn:hover { border-color: var(--border-strong); background: var(--surface-2); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }

.btn-primary {
    background: var(--primary); color: #fff; border-color: var(--primary);
}
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--text); }
.btn-ghost:hover { background: var(--surface-2); border-color: var(--border); }
.btn-danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-danger:hover { background: #991b1b; border-color: #991b1b; }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-block { width: 100%; }

/* ===== Forms ===== */
.field { display: flex; flex-direction: column; gap: 6px; }
.field > span,
.field-group > legend {
    font-size: 12px; font-weight: 500; color: var(--text-muted);
}
.input, .field input, .field textarea, .field select {
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text);
    font: inherit;
    transition: border-color .15s, box-shadow .15s;
}
.field textarea { font-family: inherit; resize: vertical; min-height: 60px; }
.field input:focus, .field textarea:focus, .field select:focus, .input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(30, 64, 175, .15);
}

.form-row { display: flex; gap: 12px; flex-wrap: wrap; }
.form-row > * { flex: 1 1 0; min-width: 140px; }
.form-row .flex-2 { flex: 2 1 0; }
.form-row .flex-1 { flex: 1 1 0; }

.form-section { margin-top: 4px; padding-top: 12px; border-top: 1px dashed var(--border); }
.form-section-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.form-section-header h3 { margin: 0; font-size: 13px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; }

.field-group { border: 1px solid var(--border); border-radius: var(--radius); padding: 8px 10px 10px; min-width: 0; }
.field-group legend { padding: 0 6px; margin-left: -6px; }

.radio-pill {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 5px 10px; margin: 2px 4px 2px 0;
    border: 1px solid var(--border); border-radius: 999px;
    font-size: 13px; cursor: pointer; user-select: none;
    transition: background .15s, border-color .15s;
}
.radio-pill:hover { background: var(--surface-2); }
.radio-pill input { margin: 0; }
.radio-pill input:checked + * { font-weight: 600; }
.radio-pill:has(input:checked) {
    background: var(--accent-soft);
    border-color: var(--accent);
    color: var(--accent);
}

.check-inline { display: inline-flex; align-items: center; gap: 6px; color: var(--text-muted); font-size: 13px; }

.form-error {
    background: var(--danger-soft);
    color: var(--danger);
    padding: 8px 12px;
    border-radius: var(--radius);
    font-size: 13px;
    border: 1px solid #fecaca;
}

/* ===== Dashboard layout ===== */
.body-dashboard { min-height: 100vh; }

.masthead {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    gap: 16px;
    padding: 12px 24px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
    position: sticky; top: 0; z-index: 50;
}
.masthead-left { display: flex; align-items: center; gap: 12px; }
.masthead-title { display: flex; flex-direction: column; line-height: 1.1; }
.masthead-title strong { font-size: 15px; }
.masthead-sub { color: var(--text-muted); font-size: 11px; }
.masthead-center { text-align: center; }
.now-clock { font-variant-numeric: tabular-nums; font-size: 14px; color: var(--text-muted); }
.masthead-right { display: flex; align-items: center; gap: 8px; justify-content: flex-end; }
.user-chip {
    display: flex; flex-direction: column; line-height: 1.1;
    text-align: right; padding-right: 8px; border-right: 1px solid var(--border);
    margin-right: 4px;
}
.user-chip-name { font-weight: 500; }
.user-chip-rol { color: var(--text-muted); font-size: 11px; text-transform: lowercase; }

.tabs {
    display: flex; gap: 4px; padding: 8px 24px 0;
    background: var(--surface); border-bottom: 1px solid var(--border);
    overflow-x: auto;
}
.tab {
    border: 1px solid transparent;
    border-bottom: none;
    background: transparent;
    padding: 10px 14px;
    cursor: pointer;
    border-radius: 6px 6px 0 0;
    color: var(--text-muted);
    font: inherit; font-weight: 500;
    white-space: nowrap;
}
.tab:hover { background: var(--surface-2); color: var(--text); }
.tab-active {
    background: var(--bg);
    border-color: var(--border);
    color: var(--text);
    margin-bottom: -1px;
}
.tab-admin { margin-left: auto; }

.dashboard { padding: 20px 24px 80px; max-width: 1400px; margin: 0 auto; }

.tab-panel { display: none; }
.tab-panel-active { display: block; }

.panel-toolbar {
    display: flex; gap: 12px; align-items: center; flex-wrap: wrap;
    margin-bottom: 16px;
}
.panel-toolbar .filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; flex: 1 1 auto; }
.panel-toolbar .actions { display: flex; gap: 8px; }
.panel-toolbar .filters .input { min-width: 140px; }
.panel-title { margin: 0; font-size: 18px; font-weight: 600; }

.panel-summary { color: var(--text-muted); font-size: 13px; margin-bottom: 8px; }

.table-wrap {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: auto;
    box-shadow: var(--shadow-sm);
}
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table th, .data-table td {
    padding: 10px 12px;
    text-align: left;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}
.data-table th {
    background: var(--surface-2);
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    font-size: 11px;
    letter-spacing: 0.04em;
}
.data-table tbody tr:hover { background: var(--surface-2); }
.data-table tbody tr.is-cancelled td { color: var(--text-soft); text-decoration: line-through; }
.data-table tbody tr { cursor: pointer; }
.data-table .col-codigo { font-family: var(--mono); font-weight: 600; }
.data-table .col-acciones { width: 80px; text-align: right; }
.data-table .col-prio { width: 70px; }
.data-table .col-fecha { width: 110px; color: var(--text-muted); }
.empty-row { text-align: center; color: var(--text-muted); padding: 24px; cursor: default; }

.pill {
    display: inline-flex; align-items: center;
    padding: 2px 8px; border-radius: 999px;
    font-size: 11px; font-weight: 500;
    text-transform: lowercase;
}
.pill-info     { background: var(--info-soft);    color: var(--info); }
.pill-success  { background: var(--success-soft); color: var(--success); }
.pill-warning  { background: var(--warning-soft); color: var(--warning); }
.pill-danger   { background: var(--danger-soft);  color: var(--danger); }
.pill-muted    { background: #f1f5f9;             color: var(--text-muted); }

.pagination {
    display: flex; justify-content: flex-end; align-items: center;
    gap: 8px; margin-top: 16px; color: var(--text-muted); font-size: 12px;
}

.coming-soon {
    background: var(--surface);
    border: 1px dashed var(--border-strong);
    border-radius: var(--radius-lg);
    padding: 48px 32px;
    text-align: center;
    color: var(--text-muted);
}
.coming-soon h2 { margin: 0 0 8px; color: var(--text); font-weight: 600; }

.section-title {
    margin: 24px 0 10px;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.vinc-stats {
    display: flex; gap: 16px; flex-wrap: wrap;
    padding: 12px 14px; margin-bottom: 12px;
    background: var(--accent-soft);
    border: 1px solid var(--accent);
    border-radius: var(--radius);
    color: var(--accent-hover);
    font-size: 13px;
}
.vinc-stats strong { font-weight: 600; }

/* ===== Logística ===== */
.log-filters {
    display: flex; gap: 8px; flex-wrap: wrap;
    margin-bottom: 16px;
}
.log-filter {
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    padding: 8px 14px;
    border-radius: 999px;
    font: inherit; font-weight: 500;
    cursor: pointer;
    display: inline-flex; align-items: center; gap: 6px;
}
.log-filter:hover { background: var(--surface-2); }
.log-filter-active {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}
.log-filter-badge {
    display: inline-flex; align-items: center; justify-content: center;
    min-width: 22px; height: 18px; padding: 0 6px;
    background: var(--bg); color: var(--text-muted);
    border-radius: 999px; font-size: 11px; font-weight: 600;
}
.log-filter-active .log-filter-badge { background: rgba(255, 255, 255, .2); color: #fff; }

.log-cards {
    display: grid;
    gap: 14px;
    grid-template-columns: repeat(auto-fill, minmax(360px, 1fr));
}
.log-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 16px;
    box-shadow: var(--shadow-sm);
    display: flex; flex-direction: column; gap: 10px;
    position: relative;
}
.log-card.is-urgente { border-left: 4px solid var(--danger); }
.log-card.is-problema { background: linear-gradient(0deg, #fffbeb, #fffbeb), var(--surface); border-color: #fde68a; }
.log-card-head {
    display: flex; align-items: center; justify-content: space-between; gap: 8px;
}
.log-card-codigo { font-family: var(--mono); font-weight: 600; font-size: 13px; }
.log-card-cliente { font-size: 15px; font-weight: 600; }
.log-card-info {
    color: var(--text-muted); font-size: 13px;
    display: flex; flex-direction: column; gap: 4px;
}
.log-card-info .row { display: flex; gap: 6px; align-items: flex-start; }
.log-card-info .icon { width: 16px; display: inline-block; text-align: center; flex-shrink: 0; }
.log-card-items { font-size: 12px; color: var(--text); line-height: 1.4; }
.log-card-actions {
    display: flex; flex-wrap: wrap; gap: 8px;
    padding-top: 8px;
    border-top: 1px dashed var(--border);
}
.log-card-actions .btn { min-height: 40px; padding: 8px 14px; flex: 1 1 auto; }
.log-empty {
    grid-column: 1 / -1;
    text-align: center; padding: 32px 16px;
    color: var(--text-muted);
    background: var(--surface);
    border: 1px dashed var(--border-strong);
    border-radius: var(--radius-lg);
}

.check-inline.big {
    display: flex; align-items: center; gap: 12px;
    padding: 12px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface-2);
    color: var(--text);
    font-size: 14px;
    cursor: pointer;
}
.check-inline.big input { width: 18px; height: 18px; }

@media (max-width: 768px) {
    .log-cards { grid-template-columns: 1fr; gap: 12px; }
    .log-card-actions .btn { min-height: 48px; font-size: 14px; }
    .log-card-cliente { font-size: 16px; }
}

/* ===== KPI bar ===== */
.kpi-bar {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 10px;
    padding: 12px 24px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}
.kpi-chip {
    display: flex; flex-direction: column; gap: 2px;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface-2);
    transition: border-color .15s, background .15s;
    cursor: default;
}
.kpi-chip:hover { background: var(--bg); }
.kpi-label { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; }
.kpi-value { font-size: 22px; font-weight: 600; font-variant-numeric: tabular-nums; }
.kpi-sub { font-size: 11px; color: var(--text-muted); }
.kpi-alert { border-color: var(--warning); background: var(--warning-soft); }
.kpi-alert .kpi-value { color: var(--warning); }
.kpi-alert.has-red { border-color: var(--danger); background: var(--danger-soft); }
.kpi-alert.has-red .kpi-value { color: var(--danger); }

/* ===== Alertas ===== */
.alerta-grupo { margin-bottom: 18px; }
.alerta-grupo-head {
    display: flex; align-items: center; gap: 10px;
    margin: 0 0 10px;
    font-size: 13px; font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.alerta-grupo-head .pill { text-transform: lowercase; letter-spacing: 0; }
.alerta-list { display: flex; flex-direction: column; gap: 8px; }
.alerta-item {
    display: flex; gap: 12px; align-items: flex-start;
    padding: 12px 14px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-left: 4px solid var(--text-muted);
    border-radius: var(--radius);
}
.alerta-item.sev-roja     { border-left-color: var(--danger); }
.alerta-item.sev-naranja  { border-left-color: var(--warning); }
.alerta-item.sev-amarilla { border-left-color: #eab308; }
.alerta-item.sev-verde    { border-left-color: var(--success); }
.alerta-msg { flex: 1; }
.alerta-tipo { display: block; font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; margin-top: 2px; }
.alerta-fecha { color: var(--text-muted); font-size: 12px; white-space: nowrap; }

/* ===== Reportes ===== */
.rep-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 14px;
    margin-bottom: 14px;
}
.rep-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 16px;
    box-shadow: var(--shadow-sm);
    margin-bottom: 14px;
}
.rep-card h3 {
    margin: 0 0 12px;
    font-size: 12px; font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase; letter-spacing: 0.04em;
}
.rep-stats {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}
.rep-stat { display: flex; flex-direction: column; gap: 2px; }
.rep-stat-label { font-size: 11px; color: var(--text-muted); }
.rep-stat-value { font-size: 22px; font-weight: 600; font-variant-numeric: tabular-nums; }

.rep-bar-chart {
    display: flex; align-items: flex-end;
    gap: 4px;
    height: 140px;
    padding: 8px 0;
}
.rep-bar {
    flex: 1; min-width: 6px;
    background: var(--accent);
    border-radius: 2px 2px 0 0;
    position: relative;
    transition: background .15s;
}
.rep-bar:hover { background: var(--accent-hover); }
.rep-bar-empty { background: var(--border); }
.rep-bar-label {
    position: absolute; top: -18px; left: 50%; transform: translateX(-50%);
    font-size: 10px; color: var(--text-muted);
    opacity: 0; transition: opacity .15s;
    white-space: nowrap; pointer-events: none;
}
.rep-bar:hover .rep-bar-label { opacity: 1; }
.rep-axis {
    display: flex; justify-content: space-between;
    margin-top: 6px;
    font-size: 10px; color: var(--text-muted);
}

@media (max-width: 768px) {
    .kpi-bar {
        grid-template-columns: repeat(2, 1fr);
        padding: 10px 12px;
        gap: 8px;
    }
    .kpi-chip { padding: 8px 10px; }
    .kpi-value { font-size: 18px; }
}

/* ===== Modal ===== */
.modal-backdrop {
    position: fixed; inset: 0;
    background: rgba(15, 23, 42, .55);
    backdrop-filter: blur(2px);
    display: grid; place-items: center;
    z-index: 100;
    padding: 20px;
}
.modal-backdrop[hidden] { display: none; }
.modal {
    background: var(--surface);
    border-radius: var(--radius-lg);
    width: min(560px, 92vw);
    max-height: 90vh;
    overflow: auto;
    box-shadow: var(--shadow-lg);
    display: flex; flex-direction: column;
}
.modal-sm { width: min(420px, 92vw); }
.modal-lg { width: min(800px, 96vw); }
.modal-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 16px 20px; border-bottom: 1px solid var(--border);
}
.modal-header h2 { margin: 0; font-size: 16px; font-weight: 600; }
.modal-close {
    border: 0; background: transparent; cursor: pointer;
    font-size: 18px; padding: 4px 8px; color: var(--text-muted);
    border-radius: var(--radius);
}
.modal-close:hover { color: var(--text); background: var(--surface-2); }
.modal-body { padding: 20px; display: flex; flex-direction: column; gap: 14px; }
.modal-footer {
    padding: 14px 20px; border-top: 1px solid var(--border);
    display: flex; justify-content: flex-end; gap: 8px;
}

.codigo-display {
    text-align: center;
    padding: 24px 12px;
    background: var(--accent-soft);
    border: 1px dashed var(--accent);
    border-radius: var(--radius);
    margin: 4px 0;
}
.codigo-display code {
    font-family: var(--mono);
    font-size: 32px;
    font-weight: 700;
    color: var(--accent-hover);
    letter-spacing: 0.04em;
}
.codigo-actions { display: flex; justify-content: center; }

/* ===== Item row del form de pre-pedido ===== */
.item-row {
    display: grid;
    grid-template-columns: 80px 80px 1fr auto;
    gap: 8px;
    align-items: end;
    margin-bottom: 8px;
}
.item-row .item-remove {
    background: transparent; border: 1px solid var(--border);
    color: var(--text-muted); padding: 6px 10px; cursor: pointer;
    border-radius: var(--radius);
}
.item-row .item-remove:hover { color: var(--danger); border-color: var(--danger); }
.item-row label { display: flex; flex-direction: column; gap: 4px; }
.item-row label > span { font-size: 11px; color: var(--text-muted); }
.item-row input { padding: 6px 10px; border: 1px solid var(--border); border-radius: var(--radius); }

/* ===== Detalle ===== */
.detalle-section { margin-bottom: 16px; }
.detalle-section h3 {
    margin: 0 0 8px; font-size: 12px;
    color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em;
}
.detalle-grid {
    display: grid;
    grid-template-columns: 140px 1fr;
    gap: 6px 16px;
    font-size: 13px;
}
.detalle-grid dt { color: var(--text-muted); }
.detalle-grid dd { margin: 0; }
.detalle-items, .detalle-salidas {
    border: 1px solid var(--border); border-radius: var(--radius);
}
.detalle-items table, .detalle-salidas table { width: 100%; border-collapse: collapse; }
.detalle-items th, .detalle-items td,
.detalle-salidas th, .detalle-salidas td {
    padding: 6px 10px; text-align: left; font-size: 12px;
    border-bottom: 1px solid var(--border);
}
.detalle-items th, .detalle-salidas th { background: var(--surface-2); color: var(--text-muted); }

.muted { color: var(--text-muted); }
.small { font-size: 12px; }

/* ===== Responsive ===== */
@media (max-width: 768px) {
    .masthead { grid-template-columns: 1fr auto; padding: 10px 12px; }
    .masthead-center { display: none; }
    .tabs { padding: 8px 12px 0; }
    .dashboard { padding: 16px 12px 80px; }
    .user-chip { display: none; }
    .data-table .col-fecha { display: none; }
}
