/* ============ Brand palette (Mini Súper Del Sol) ============ */
:root {
    --navy: #1B2E5C;
    --navy-dark: #142046;
    --gold: #F4B81E;
    --gold-dark: #d99e0a;
    --bg: #FAF8F2;       /* warm off-white */
    --bg-card: #FFFFFF;
    --text: #1B2E5C;
    --muted: #6b7180;
    --success: #2a9d2f;
    --success-bg: #f0fbf2;
    --danger: #d33;
    --danger-bg: #fde0e0;
    --border: #e6e3d8;
}

/* ============ Reset & base ============ */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 16px;
    line-height: 1.4;
    color: var(--text);
    background: var(--bg);
    -webkit-tap-highlight-color: transparent;
    min-height: 100vh;
}
img { max-width: 100%; }
a { color: #1B2E5C; text-decoration: none; }

/* ============ Topbar ============ */
.topbar {
    background: #1B2E5C;
    color: white;
    padding: 0;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 2px 4px rgba(0,0,0,0.15);
}
.topbar-inner {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 18px;
    max-width: 720px;
    margin: 0 auto;
}
.topbar-title {
    font-weight: 600;
    font-size: 1.05rem;
}
.topbar-link {
    color: white;
    opacity: 0.9;
    font-size: 0.9rem;
}
.topbar-link:hover { opacity: 1; }

/* ============ Container & layout ============ */
.container {
    max-width: 720px;
    margin: 0 auto;
    padding: 16px;
    padding-bottom: 80px;
}
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 20px;
}
.page-header h2 {
    margin: 0;
    font-size: 1.4rem;
}
.back-link {
    display: inline-block;
    margin-bottom: 6px;
    font-size: 0.85rem;
    color: #666;
}
.muted { color: #888; font-size: 0.9em; }

/* ============ Buttons ============ */
.btn {
    display: inline-block;
    border: none;
    border-radius: 8px;
    padding: 10px 18px;
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    background: #e5e5ea;
    color: #222;
    transition: background 0.15s, transform 0.05s;
    text-align: center;
    font-family: inherit;
}
.btn:active { transform: scale(0.98); }
.btn-primary { background: #1B2E5C; color: white; }
.btn-primary:hover { background: #142046; }
.btn-success { background: #2a9d2f; color: white; }
.btn-success:hover { background: #208525; }
.btn-danger { background: #d33; color: white; }
.btn-danger:hover { background: #b22; }
.btn-block { display: block; width: 100%; }
.btn-large { padding: 14px 22px; font-size: 1.05rem; }
.btn-icon {
    background: transparent;
    border: none;
    color: #d33;
    cursor: pointer;
    padding: 6px 10px;
    font-size: 1rem;
    border-radius: 6px;
}
.btn-icon:hover { background: #ffe0e0; }

/* ============ Forms ============ */
label {
    display: block;
    margin-bottom: 14px;
    font-size: 0.9rem;
    color: #444;
    font-weight: 500;
}
input[type="text"], input[type="password"], input[type="number"],
input[type="email"], select, textarea {
    width: 100%;
    padding: 11px 12px;
    border: 1px solid #ccc;
    border-radius: 8px;
    font-size: 1rem;
    margin-top: 4px;
    background: white;
    font-family: inherit;
    color: #222;
}
input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: #1B2E5C;
    box-shadow: 0 0 0 2px rgba(27,46,92,0.15);
}
textarea { resize: vertical; }

/* ============ Login ============ */
.login-box {
    max-width: 400px;
    margin: 40px auto;
    background: white;
    padding: 28px 24px;
    border-radius: 14px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.08);
}
.login-title {
    text-align: center;
    margin: 0 0 24px;
    color: #1B2E5C;
}
.tabs {
    display: flex;
    margin-bottom: 22px;
    border-bottom: 2px solid #eee;
}
.tab {
    flex: 1;
    background: none;
    border: none;
    padding: 12px;
    cursor: pointer;
    font-size: 0.95rem;
    color: #888;
    font-weight: 500;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    font-family: inherit;
}
.tab.active {
    color: #1B2E5C;
    border-bottom-color: #1B2E5C;
}
.tab-pane { display: none; }
.tab-pane.active { display: block; }

/* ============ Flash messages ============ */
.flash-container {
    max-width: 720px;
    margin: 12px auto 0;
    padding: 0 16px;
}
.flash {
    padding: 12px 14px;
    border-radius: 8px;
    margin-bottom: 8px;
    font-size: 0.92rem;
}
.flash-error { background: #fde0e0; color: #142046; border: 1px solid #f5b5b5; }
.flash-success { background: #d5f5d8; color: #1f7a25; border: 1px solid #b0e6b5; }

/* ============ Pedido list (home) ============ */
.pedido-list {
    list-style: none;
    padding: 0;
    margin: 0;
}
.pedido-list li { margin-bottom: 10px; }
.pedido-card {
    display: block;
    background: white;
    padding: 14px 16px;
    border-radius: 10px;
    color: #222;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}
.pedido-card:hover { background: #fafafa; }
.pedido-card-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 6px;
}
.pedido-fecha { font-weight: 500; color: #444; font-size: 0.95rem; }
.pedido-card-body {
    display: flex;
    justify-content: space-between;
    color: #666;
    font-size: 0.95rem;
}
.pedido-card-foot {
    margin-top: 8px;
    color: #888;
    font-size: 0.85rem;
}
.badge {
    display: inline-block;
    padding: 3px 9px;
    border-radius: 12px;
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.5px;
}
.badge-borrador { background: #fff3cd; color: #8a6500; }
.badge-enviado { background: #d5f5d8; color: #1f7a25; }

/* ============ Pedido detalle ============ */
.pedido-totales {
    display: flex;
    gap: 18px;
    text-align: center;
}
.pedido-totales div {
    background: white;
    padding: 8px 14px;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}
.pedido-totales strong { font-size: 1.15rem; color: #1B2E5C; }
.pedido-totales small { color: #888; font-size: 0.75rem; }

.agregar-producto-card {
    background: white;
    padding: 16px;
    border-radius: 12px;
    margin-bottom: 18px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}
.agregar-producto-card h3 { margin: 0 0 12px; font-size: 1rem; color: #444; }
.agregar-row {
    display: grid;
    grid-template-columns: 1fr;
    gap: 10px;
}
.agregar-row input[type="number"] { font-size: 1.1rem; text-align: center; }
.agregar-row button { font-size: 1.05rem; }
@media (min-width: 600px) {
    .agregar-row {
        grid-template-columns: 2fr 1fr auto;
        align-items: end;
    }
}
.hint {
    margin: 8px 0 0;
    font-size: 0.82rem;
    color: #888;
    min-height: 1em;
}

/* ============ Captura table ============ */
.captura-tabla {
    width: 100%;
    background: white;
    border-radius: 10px;
    overflow: hidden;
    border-collapse: collapse;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
    margin-top: 10px;
}
.captura-tabla th, .captura-tabla td {
    padding: 9px 8px;
    text-align: left;
    border-bottom: 1px solid #f0f0f0;
    font-size: 0.92rem;
}
.captura-tabla th {
    background: #fafafa;
    font-size: 0.78rem;
    text-transform: uppercase;
    color: #666;
    font-weight: 600;
}
.captura-tabla td.num, .captura-tabla th.num { text-align: right; }
.captura-tabla tr:last-child td { border-bottom: none; }
.captura-tabla tbody tr:hover { background: #fafafa; }

/* ============ Enviar card ============ */
.enviar-card {
    background: white;
    padding: 16px;
    border-radius: 12px;
    margin-top: 24px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}
.enviar-card button { margin-top: 10px; }
.enviado-card {
    background: #d5f5d8;
    color: #1f7a25;
    padding: 16px;
    border-radius: 12px;
    margin-top: 24px;
    text-align: center;
    font-weight: 600;
}

/* ============ Empty states ============ */
.empty-state {
    text-align: center;
    color: #888;
    padding: 50px 20px;
}
.empty-state h2 { color: #333; }
.empty-state-small {
    text-align: center;
    color: #aaa;
    padding: 30px 20px;
    background: white;
    border-radius: 10px;
}

/* ============ Admin ============ */
.admin-nav {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 20px;
}
.admin-nav a {
    padding: 8px 14px;
    background: white;
    border-radius: 8px;
    color: #444;
    font-size: 0.92rem;
    border: 1px solid #e5e5e5;
}
.admin-nav a.active, .admin-nav a:hover {
    background: #1B2E5C;
    color: white;
    border-color: #1B2E5C;
}
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 12px;
    margin-bottom: 24px;
}
.stat-card {
    background: white;
    padding: 16px;
    border-radius: 10px;
    text-align: center;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}
.stat-card strong { display: block; font-size: 1.8rem; color: #1B2E5C; }
.stat-card small { color: #888; font-size: 0.85rem; }

.admin-table-wrapper { overflow-x: auto; }
.admin-table {
    width: 100%;
    background: white;
    border-collapse: collapse;
    border-radius: 10px;
    overflow: hidden;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}
.admin-table th, .admin-table td {
    padding: 9px 10px;
    border-bottom: 1px solid #f0f0f0;
    font-size: 0.88rem;
}
.admin-table th {
    background: #fafafa;
    font-size: 0.75rem;
    text-transform: uppercase;
    color: #666;
    text-align: left;
    white-space: nowrap;
}
.admin-table input, .admin-table select {
    padding: 6px;
    font-size: 0.88rem;
    margin: 0;
}
.admin-table input[type="number"] { max-width: 70px; }
.admin-table .btn { padding: 6px 12px; font-size: 0.85rem; }

.row-actions { white-space: nowrap; }
.row-actions button { margin-left: 4px; }

.section-card {
    background: white;
    padding: 18px;
    border-radius: 12px;
    margin-bottom: 18px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}
.section-card h3 { margin: 0 0 14px; }

/* ============ Dialog ============ */
dialog {
    border: none;
    border-radius: 14px;
    padding: 22px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.25);
    max-width: 95vw;
    width: 500px;
    background: white;
}
dialog::backdrop { background: rgba(0,0,0,0.45); }
dialog h3 { margin-top: 0; }
.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}
fieldset {
    border: 1px solid #e5e5e5;
    border-radius: 8px;
    padding: 10px 12px 12px;
    margin: 12px 0;
}
fieldset legend { font-size: 0.85rem; color: #666; padding: 0 6px; }
.checkbox-label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 500;
}
.checkbox-label input { width: auto; margin: 0; }
.dialog-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    margin-top: 14px;
}
code {
    background: #f0f0f0;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.85em;
}

/* ============ Search bar (pedido) ============ */
.search-bar {
    display: flex;
    gap: 12px;
    align-items: center;
    margin-bottom: 14px;
    background: white;
    padding: 12px;
    border-radius: 10px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
    position: sticky;
    top: 50px;
    z-index: 10;
}
.search-bar input[type="search"] {
    flex: 1;
    margin: 0;
}
.checkbox-inline {
    display: flex;
    align-items: center;
    gap: 5px;
    margin: 0;
    font-size: 0.85rem;
    color: #555;
    white-space: nowrap;
}
.checkbox-inline input {
    width: auto;
    margin: 0;
}

/* ============ Pedido progreso (empleado) ============ */
.pedido-progreso {
    background: white;
    padding: 8px 16px;
    border-radius: 8px;
    text-align: center;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}
.pedido-progreso strong {
    font-size: 1.2rem;
    color: #1B2E5C;
    display: block;
}
.pedido-progreso small {
    color: #888;
    font-size: 0.75rem;
}

/* ============ Producto grid (lista de captura) ============ */
.producto-grid {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 24px;
}
.producto-card {
    background: white;
    padding: 12px 14px;
    border-radius: 10px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
    display: grid;
    grid-template-columns: 1fr 110px;
    gap: 10px;
    align-items: center;
    border-left: 4px solid transparent;
    transition: background 0.15s, border-color 0.15s;
}
.producto-card.capturado {
    background: var(--success-bg);
    border-left-color: var(--gold);
}
.producto-card.saving { opacity: 0.6; }
.producto-card.error { background: #fde0e0; border-left-color: #d33; }

.producto-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}
.producto-nombre {
    font-weight: 500;
    color: #222;
    word-break: break-word;
}
.producto-paq {
    font-size: 0.75rem;
    color: #888;
}
.producto-input {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: flex-end;
}
.input-existencia {
    width: 100%;
    text-align: center;
    font-size: 1.1rem;
    font-weight: 500;
    padding: 9px 6px;
    margin: 0;
}
.exist-readonly {
    font-size: 1.2rem;
    font-weight: 600;
    color: #2a9d2f;
    padding: 0 8px;
}
.check-saved {
    position: absolute;
    right: -22px;
    top: 50%;
    transform: translateY(-50%) scale(0.5);
    color: #2a9d2f;
    font-weight: bold;
    font-size: 1.1rem;
    opacity: 0;
    transition: opacity 0.2s, transform 0.2s;
    pointer-events: none;
}
.check-saved.show {
    opacity: 1;
    transform: translateY(-50%) scale(1);
}
.producto-admin {
    grid-column: 1 / -1;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-top: 6px;
    margin-top: 4px;
    border-top: 1px dashed #eee;
    font-size: 0.9rem;
}
.apedir-texto {
    color: #1B2E5C;
    font-weight: 600;
}
.apedir-costo {
    color: #666;
}

@media (min-width: 600px) {
    .producto-card {
        grid-template-columns: 1fr 130px 200px;
    }
    .producto-admin {
        grid-column: auto;
        padding-top: 0;
        margin-top: 0;
        border-top: none;
        flex-direction: column;
        align-items: flex-end;
        gap: 2px;
    }
}

/* ============ Brand logo on login + brand topbar adjustments ============ */
.brand-logo {
    display: block;
    margin: 0 auto 18px;
    max-width: 180px;
    width: 60%;
    height: auto;
}
.brand-name {
    text-align: center;
    color: var(--navy);
    margin: 0 0 4px;
    font-weight: 700;
    letter-spacing: 0.5px;
}
.brand-tagline {
    text-align: center;
    color: var(--muted);
    margin: 14px 0 22px;
    font-size: 0.85rem;
    font-style: italic;
}
.brand-divider {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    margin: 8px 0 4px;
    font-family: Georgia, "Times New Roman", serif;
}
.brand-divider::before,
.brand-divider::after {
    content: "";
    flex: 0 0 36px;
    height: 2px;
    background: linear-gradient(90deg, transparent, var(--gold), var(--gold));
}
.brand-divider::after {
    background: linear-gradient(90deg, var(--gold), var(--gold), transparent);
}
.brand-divider-label {
    color: var(--muted);
    font-size: 0.95rem;
    letter-spacing: 1.5px;
    text-transform: uppercase;
}
.brand-divider-accent {
    color: var(--navy);
    font-size: 1.15rem;
    font-weight: 700;
    letter-spacing: 0.5px;
}
.topbar {
    background: var(--navy);
}
.topbar-title {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}
.topbar-mini-sun {
    width: 22px;
    height: 22px;
    flex: 0 0 22px;
}

/* ============ Vista resumen del pedido (admin / print) ============ */
.resumen-doc {
    background: white;
    padding: 30px;
    border-radius: 12px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
    max-width: 700px;
    margin: 0 auto;
}
.resumen-header {
    text-align: center;
    border-bottom: 2px solid var(--navy);
    padding-bottom: 14px;
    margin-bottom: 24px;
}
.resumen-header h1 {
    color: var(--navy);
    margin: 0 0 4px;
    font-family: Georgia, serif;
}
.resumen-sub {
    margin: 6px 0;
    color: #444;
}
.resumen-estado {
    margin: 6px 0 0;
    color: var(--muted);
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 1px;
}
.resumen-tabla {
    width: 100%;
    border-collapse: collapse;
}
.resumen-tabla th, .resumen-tabla td {
    padding: 10px 8px;
    border-bottom: 1px solid #eee;
    font-size: 1rem;
}
.resumen-tabla th {
    text-align: left;
    background: #faf8f2;
    color: var(--navy);
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 1px;
}
.resumen-tabla td.num, .resumen-tabla th.num { text-align: right; }
.resumen-tabla tfoot td {
    border-top: 2px solid var(--navy);
    border-bottom: none;
    padding-top: 14px;
    font-size: 1.05rem;
}
.resumen-obs {
    margin-top: 18px;
    padding: 12px;
    background: #fff8e7;
    border-left: 4px solid var(--gold);
    border-radius: 4px;
}

/* Print: ocultar UI, mostrar solo el documento */
@media print {
    .topbar, .no-print, .flash-container { display: none !important; }
    body { background: white; }
    .container { padding: 0; max-width: none; }
    .resumen-doc {
        box-shadow: none;
        padding: 0;
        max-width: none;
    }
}
