/* --- Variables & Modern Reset --- */
:root {
    --primary-color: #2563eb;
    /* Royal Blue */
    --primary-hover: #1d4ed8;
    --secondary-color: #64748b;
    /* Slate */
    --accent-color: #0ea5e9;
    /* Sky Blue */
    --success-color: #10b981;
    /* Emerald */
    --warning-color: #f59e0b;
    /* Amber */
    --danger-color: #ef4444;
    /* Red */
    --dark-bg: #0f172a;
    /* Slate 900 */
    --light-bg: #f8fafc;
    /* Slate 50 */
    --card-bg: #ffffff;
    --text-main: #1e293b;
    /* Slate 800 */
    --text-muted: #64748b;
    --border-color: #e2e8f0;
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
    --radius: 0.5rem;
    --font-sans: 'Inter', system-ui, -apple-system, sans-serif;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: var(--font-sans);
    background-color: var(--light-bg);
    color: var(--text-main);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

/* --- Layout Principal --- */
.app-container {
    display: flex;
    min-height: 100vh;
}

/* --- Sidebar --- */
.sidebar {
    width: 260px;
    background-color: var(--dark-bg);
    color: white;
    display: flex;
    flex-direction: column;
    padding: 1rem;
    position: fixed;
    height: 100vh;
    left: 0;
    top: 0;
    z-index: 50;
    box-shadow: var(--shadow-lg);
}

.sidebar-header {
    padding: 1.5rem 0;
    text-align: center;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    margin-bottom: 2rem;
}

.sidebar-header h1 {
    font-size: 1.25rem;
    font-weight: 700;
    color: white;
    letter-spacing: -0.025em;
}

.logo {
    height: 60px;
    width: auto;
    margin-bottom: 0.5rem;
    border-radius: var(--radius);
}

.nav-links {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.nav-links a {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    color: #cbd5e1;
    text-decoration: none;
    border-radius: var(--radius);
    transition: all 0.2s;
    font-weight: 500;
}

.nav-links a:hover,
.nav-links a.active {
    background-color: rgba(255, 255, 255, 0.1);
    color: white;
}

/* --- Main Content --- */
.main-content {
    margin-left: 260px;
    flex: 1;
    padding: 2rem;
    background-color: var(--light-bg);
}

.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
}

.page-title {
    font-size: 1.875rem;
    font-weight: 700;
    color: var(--text-main);
}

/* --- Tables --- */
.table-container {
    background: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    overflow: hidden;
    overflow-x: auto;
    /* Permitir scroll horizontal si la tabla es muy ancha */
    border: 1px solid var(--border-color);
}

/* --- Responsive Layout --- */
@media (max-width: 768px) {
    .app-container {
        flex-direction: column;
    }

    .sidebar {
        width: 100%;
        height: auto;
        position: relative;
        padding: 1rem;
    }

    .main-content {
        margin-left: 0;
        padding: 1rem;
    }

    .page-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 1rem;
    }

    .header-actions {
        width: 100%;
        flex-direction: column;
    }

    #buscador {
        width: 100% !important;
    }

    .btn {
        width: 100%;
    }
}

.tabla-ordenes {
    width: 100%;
    border-collapse: collapse;
    white-space: nowrap;
}

.tabla-ordenes cur {
    /* cursor pointer for rows if needed */
}

.tabla-ordenes th {
    background-color: #f1f5f9;
    color: var(--text-muted);
    font-weight: 600;
    text-transform: uppercase;
    font-size: 0.75rem;
    letter-spacing: 0.05em;
    padding: 1rem 1.5rem;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

.tabla-ordenes td {
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
    color: var(--text-main);
}

.tabla-ordenes tbody tr:last-child td {
    border-bottom: none;
}

.tabla-ordenes tbody tr:hover {
    background-color: #f8fafc;
}

/* --- Buttons --- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.5rem 1rem;
    border-radius: var(--radius);
    font-weight: 500;
    text-decoration: none;
    cursor: pointer;
    transition: all 0.2s;
    border: 1px solid transparent;
    font-size: 0.875rem;
    gap: 0.5rem;
}

.btn-primary {
    background-color: var(--primary-color);
    color: white;
}

.btn-primary:hover {
    background-color: var(--primary-hover);
    box-shadow: 0 4px 6px -1px rgba(37, 99, 235, 0.3);
}

.btn-secondary {
    background-color: white;
    border-color: var(--border-color);
    color: var(--text-main);
}

.btn-secondary:hover {
    background-color: #f1f5f9;
}

.btn-danger {
    background-color: #fee2e2;
    color: var(--danger-color);
}

.btn-danger:hover {
    background-color: #fecaca;
}

.btn-sm {
    padding: 0.25rem 0.5rem;
    font-size: 0.75rem;
}

/* --- Status Chips (Semáforo) --- */
.estado-chip {
    display: inline-flex;
    padding: 0.25rem 0.75rem;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* 🔵 INICIO / REVISIÓN */
.estado-ingresado {
    background-color: #dbeafe;
    color: #1e40af;
    border: 1px solid #bfdbfe;
}

.estado-en-reparación {
    background-color: #e0f2fe;
    color: #0369a1;
    border: 1px solid #bae6fd;
}

/* 🟡 ESPERA / ATENCIÓN */
.estado-presupuestado {
    background-color: #fef9c3;
    color: #854d0e;
    border: 1px solid #fde047;
}

.estado-esperando-repuesto {
    background-color: #ffedd5;
    color: #9a3412;
    border: 1px solid #fed7aa;
}

/* 🟢 ÉXITO / LISTO */
.estado-listo-para-retirar {
    background-color: #dcfce7;
    color: #15803d;
    border: 1px solid #86efac;
}

.estado-entregado {
    background-color: #f0fdf4;
    color: #166534;
    border: 1px solid #bbf7d0;
}

/* 🔴 ERROR / CANCELADO */
.estado-rechazado-sin-reparación {
    background-color: #fee2e2;
    color: #b91c1c;
    border: 1px solid #fecaca;
}

/* --- Forms --- */
.form-card {
    background: var(--card-bg);
    padding: 2rem;
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    max-width: 800px;
    margin: 0 auto;
}

.form-group {
    margin-bottom: 1.5rem;
}

.form-group label {
    display: block;
    font-weight: 500;
    margin-bottom: 0.5rem;
    color: var(--text-main);
}

.form-control {
    width: 100%;
    padding: 0.75rem 1rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    font-size: 0.95rem;
    transition: border-color 0.2s;
    font-family: inherit;
}

.form-control:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

/* --- KPI Cards --- */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.kpi-card {
    background: white;
    padding: 1.5rem;
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-color);
}

.kpi-title {
    color: var(--text-muted);
    font-size: 0.875rem;
    font-weight: 500;
    margin-bottom: 0.5rem;
}

.kpi-value {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--text-main);
}

/* --- Helper Classes --- */
.detalle-container {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.text-right {
    text-align: right;
}

.mt-4 {
    margin-top: 1rem;
}

.mb-4 {
    margin-bottom: 1rem;
}

.hidden {
    display: none;
}

/* --- Presupuestos --- */
.presupuesto-items-container {
    background: white;
    padding: 1.5rem;
    border-radius: var(--radius);
    border: 1px solid var(--border-color);
    margin-bottom: 2rem;
}

.items-header {
    display: flex;
    font-weight: 600;
    color: var(--text-muted);
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 1rem;
    gap: 1rem;
}

.item-row {
    display: flex;
    gap: 1rem;
    margin-bottom: 0.75rem;
    align-items: center;
}

.item-descripcion {
    flex: 3;
}

.item-tipo {
    flex: 1.5;
}

.item-costo {
    flex: 1;
    text-align: right;
}

.item-accion {
    width: 40px;
    text-align: center;
}

/* Inputs dentro de las filas de items */
.item-row input[name="descripcion[]"] {
    flex: 3;
    padding: 0.5rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
}

.item-row select[name="tipo[]"] {
    flex: 1.5;
    padding: 0.5rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
}

.item-row input[name="costo[]"] {
    flex: 1;
    padding: 0.5rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    text-align: right;
}

.presupuesto-total {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 1rem;
    font-size: 1.25rem;
    color: var(--text-main);
    padding: 1rem 0;
    border-top: 2px solid var(--border-color);
}

.presupuesto-total strong:last-child {
    color: var(--primary-color);
    font-size: 1.5rem;
}

/* Mensaje de Éxito */
.mensaje-exito {
    background-color: #ecfdf5;
    border: 1px solid #a7f3d0;
    border-radius: var(--radius);
    padding: 2rem;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.5rem;
    margin-top: 2rem;
}

.mensaje-exito h3 {
    color: #065f46;
    font-size: 1.5rem;
    margin-bottom: 0.5rem;
}

.mensaje-exito p {
    color: #047857;
}

/* Ocultar ticket en pantalla normal (FIX: Opacidad 0 y atrás para que renderice QR pero no se vea) */
#ticket-print {
    position: absolute;
    top: 0;
    left: 0;
    width: 80mm;
    opacity: 0;
    z-index: -1000;
    pointer-events: none;
}

/* --- PRINT STYLES FOR TICKET --- */
@media print {
    @page {
        size: 80mm 50mm;
        /* Forzar tamaño de etiqueta si el navegador lo respeta */
        margin: 0;
    }

    body * {
        visibility: hidden;
    }

    .app-container,
    .sidebar,
    .main-content {
        display: none !important;
        margin: 0 !important;
        padding: 0 !important;
    }

    #ticket-print,
    #ticket-print * {
        visibility: visible;
        opacity: 1;
    }

    #ticket-print {
        position: absolute;
        left: 0;
        top: 0;
        width: 80mm;
        height: 50mm;
        /* Altura fija */
        padding: 2mm;
        /* Padding mínimo */
        font-family: 'Courier New', Courier, monospace;
        visibility: visible;
        opacity: 1;
        z-index: 9999;
        overflow: hidden;
        /* Evitar desborde */
        background: white;
    }

    .ticket-header {
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 5px;
        margin-bottom: 2px;
        border-bottom: 1px solid black;
        padding-bottom: 2px;
    }

    .ticket-logo {
        max-width: 25px;
        /* Logo muy chico */
        display: block;
    }

    .ticket-header div {
        text-align: left;
    }

    .ticket-header h2 {
        font-size: 0.9rem;
        /* Título chico */
        margin: 0;
        line-height: 1;
        text-transform: uppercase;
    }

    .ticket-header p {
        font-size: 0.6rem;
        margin: 0;
    }

    .ticket-body {
        font-size: 0.7rem;
        /* Texto muy compacto */
        margin-bottom: 2px;
    }

    .ticket-body p {
        margin: 1px 0;
        line-height: 1.1;
        white-space: nowrap;
        /* Evitar saltos de línea si es posible */
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .ticket-divider {
        display: none;
        /* Ahorrar espacio vertical */
    }

    .ticket-qr {
        position: absolute;
        /* Posicionar QR a la derecha o abajo fijo */
        bottom: 2mm;
        right: 2mm;
        width: 20mm;
        /* QR chico */
        height: 20mm;
    }

    .ticket-qr img {
        width: 100% !important;
        height: auto !important;
    }

    /* Layout Flexible para aprovechar 50mm */
    /* Header arriba, info a la izquierda, QR a la derecha abajo */
}