*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background-color: #eef2f7;
    color: #1e293b;
    min-height: 100vh;
}

/* ── Header ── */
.app-header {
    background: linear-gradient(135deg, #0f2044 0%, #1e4080 100%);
    color: white;
    padding: 18px 36px;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
}

.header-brand {
    display: flex;
    align-items: center;
    gap: 16px;
}

.header-icon {
    width: 44px;
    height: 44px;
    background: rgba(255, 255, 255, 0.15);
    border: 1px solid rgba(255, 255, 255, 0.25);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.3rem;
}

.header-brand h1 {
    font-size: 1.4rem;
    font-weight: 700;
    letter-spacing: 0.3px;
}

.header-brand p {
    font-size: 0.78rem;
    opacity: 0.65;
    margin-top: 2px;
    letter-spacing: 0.5px;
}

.header-actions {
    display: flex;
    gap: 10px;
}

/* ── Container ── */
.container {
    max-width: 1300px;
    margin: 0 auto;
    padding: 28px 36px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

/* ── Cards ── */
.card {
    background: #ffffff;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(15, 32, 68, 0.07), 0 0 1px rgba(15, 32, 68, 0.1);
    overflow: hidden;
}

.card-header {
    background: linear-gradient(90deg, #0f2044 0%, #1e4080 100%);
    color: white;
    padding: 11px 20px;
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 1.8px;
    text-transform: uppercase;
}

.card-body {
    padding: 20px;
}

/* ── Search card ── */
.search-body {
    display: flex;
    align-items: center;
    gap: 14px;
    flex-wrap: wrap;
}

.search-form {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
}

.search-form label {
    font-weight: 600;
    font-size: 0.88rem;
    color: #475569;
    white-space: nowrap;
}

.search-form input {
    padding: 9px 14px;
    border: 2px solid #e2e8f0;
    border-radius: 8px;
    font-size: 0.95rem;
    width: 240px;
    max-width: 100%;
    flex: 1 1 200px;
    font-family: inherit;
    color: #1e293b;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.search-form input:focus {
    outline: none;
    border-color: #2563eb;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

.btn-buscar {
    padding: 9px 24px;
    background: linear-gradient(135deg, #2563eb, #1d4ed8);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 0.88rem;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    letter-spacing: 0.3px;
    transition: opacity 0.2s, transform 0.1s;
}

.btn-buscar:hover { opacity: 0.9; }
.btn-buscar:active { transform: scale(0.98); }

/* ── Hint box ── */
.hint-box {
    border: 1.5px solid #cbd5e1;
    border-radius: 8px;
    padding: 14px 24px;
    background: #ffffff;
    text-align: center;
    min-width: 210px;
}

.hint-title {
    font-size: 1rem;
    font-weight: 700;
    color: #dc2626;
    letter-spacing: 0.5px;
    margin-bottom: 8px;
}

.hint-body {
    font-size: 1.05rem;
    color: #475569;
}

.hint-clave {
    font-size: 1.1rem;
    font-weight: 700;
    color: #2563eb;
    cursor: pointer;
    text-decoration: underline;
    text-underline-offset: 2px;
    transition: color 0.15s;
}

.hint-clave:hover {
    color: #1d4ed8;
}

/* ── Export buttons ── */
.btn-pdf, .btn-excel {
    padding: 8px 18px;
    border: none;
    border-radius: 8px;
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    letter-spacing: 0.3px;
    transition: opacity 0.2s, transform 0.1s;
}

.btn-pdf {
    background: linear-gradient(135deg, #dc2626, #b91c1c);
    color: white;
}

.btn-excel {
    background: linear-gradient(135deg, #16a34a, #15803d);
    color: white;
}

.btn-pdf:hover, .btn-excel:hover { opacity: 0.88; }
.btn-pdf:active, .btn-excel:active { transform: scale(0.98); }

/* ── Results ── */
#resultado {
    overflow-x: auto;
    min-height: 48px;
}

#resultado table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}

#resultado th {
    background-color: #1e3a5f;
    color: white;
    padding: 11px 14px;
    text-align: left;
    font-weight: 600;
    font-size: 0.78rem;
    letter-spacing: 0.6px;
    white-space: nowrap;
}

#resultado td {
    padding: 10px 14px;
    border-bottom: 1px solid #f1f5f9;
    color: #334155;
}

#resultado tr:hover td {
    background-color: #f0f7ff;
}

#resultado tr:last-child td {
    border-bottom: none;
}

.resultado-placeholder {
    color: #94a3b8;
    font-style: italic;
    font-size: 0.9rem;
    padding: 8px 0;
}

.resultado-info {
    color: #475569;
    font-size: 0.9rem;
    padding: 8px 0;
}

.resultado-error {
    color: #dc2626;
    font-size: 0.88rem;
    background: #fef2f2;
    border: 1px solid #fecaca;
    border-radius: 8px;
    padding: 10px 14px;
}

.resultado-loading {
    color: #2563eb;
    font-size: 0.88rem;
    padding: 8px 0;
}

/* ── Bottom section ── */
.bottom-section {
    display: flex;
    flex-wrap: wrap;
    gap: 20px;
    align-items: flex-start;
}

.gastos-card {
    flex: 1 1 320px;
}

/* ── Gastos inputs ── */
#gastos-venta-container {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.gasto-item {
    display: flex;
    align-items: center;
    gap: 10px;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 10px 14px;
    transition: border-color 0.2s;
}

.gasto-item:focus-within {
    border-color: #93c5fd;
    background: #eff6ff;
}

.gasto-item label {
    flex: 1;
    font-size: 0.82rem;
    color: #475569;
    font-weight: 500;
}

.gasto-item input {
    width: 110px;
    padding: 6px 10px;
    border: 2px solid #e2e8f0;
    border-radius: 6px;
    font-size: 0.9rem;
    text-align: right;
    color: #1e293b;
    font-family: inherit;
    background: white;
    transition: border-color 0.2s;
}

.gasto-item input:focus {
    outline: none;
    border-color: #2563eb;
}

/* ── Totales card ── */
#totales {
    display: none;
    width: 300px;
    max-width: 100%;
    flex: 1 1 300px;
}

.totals-table {
    width: 100%;
    border-collapse: collapse;
}

.totals-table tr {
    border-bottom: 1px solid #f1f5f9;
}

.totals-table tr:last-child {
    border-bottom: none;
}

.totals-table th {
    padding: 12px 16px;
    text-align: left;
    font-size: 0.8rem;
    color: #64748b;
    font-weight: 600;
    background: none;
    letter-spacing: 0;
    white-space: nowrap;
}

.totals-table td {
    padding: 12px 16px;
    text-align: right;
    font-weight: 700;
    font-size: 0.95rem;
    color: #1e293b;
}

.totals-table .row-highlight {
    background: #f0f7ff;
}

.totals-table .row-highlight th {
    color: #1e3a5f;
    font-size: 0.85rem;
}

.totals-table .row-highlight td {
    font-size: 1.05rem;
}

.totals-table .row-commission th {
    color: #475569;
}

.totals-table .row-commission td {
    color: #059669;
}

/* ── Responsive ───────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
    .app-header { padding: 16px 20px; }
    .container { padding: 20px 16px; }
    .header-actions { width: 100%; }
    .btn-pdf, .btn-excel { flex: 1; }
    #gastos-venta-container { grid-template-columns: 1fr; }
}

@media (max-width: 480px) {
    .header-brand h1 { font-size: 1.15rem; }
    .search-form { width: 100%; }
    .search-form input { width: 100%; }
    .btn-buscar { width: 100%; }
    .hint-box { width: 100%; }
    .gasto-item { flex-wrap: wrap; }
    .gasto-item input { width: 100%; }
}
