:root {
    --primary: #4F46E5;
    --primary-hover: #4338CA;
    --bg-color: #F3F4F6;
    --surface: #FFFFFF;
    --text-main: #111827;
    --text-muted: #6B7280;
    --border: #E5E7EB;
    --success: #10B981;
    --danger: #EF4444;
    --sidebar-w: 250px;
    --radius: 12px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Inter', sans-serif;
}

body {
    background: var(--bg-color);
    color: var(--text-main);
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: var(--sidebar-w);
    background: var(--surface);
    border-right: 1px solid var(--border);
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    position: fixed;
    height: 100vh;
}

.sidebar h2 {
    color: var(--primary);
    margin-bottom: 2rem;
    font-weight: 800;
    font-size: 1.5rem;
}

.sidebar nav a {
    text-decoration: none;
    color: var(--text-muted);
    padding: 0.75rem 1rem;
    border-radius: 8px;
    font-weight: 500;
    transition: all 0.2s ease;
    display: block;
    margin-bottom: 0.5rem;
}

.sidebar nav a:hover,
.sidebar nav a.active {
    background: var(--primary);
    color: white;
    transform: translateX(5px);
}

.content {
    flex: 1;
    margin-left: var(--sidebar-w);
    padding: 2rem;
    min-width: 0;
}

.menu-toggle {
    display: none;
    position: fixed;
    top: 0.9rem;
    left: 1rem;
    z-index: 210;
    width: 42px;
    height: 42px;
    border: none;
    border-radius: 10px;
    background: var(--surface);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    font-size: 1.3rem;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    z-index: 190;
}

.sidebar-overlay.active {
    display: block;
}

.header {
    margin-bottom: 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.header h1 {
    font-size: 1.8rem;
    font-weight: 700;
    color: var(--text-main);
}

.card {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 1.5rem;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
    transition: transform 0.2s;
}

.card:hover {
    transform: translateY(-3px);
}

.card h3 {
    color: var(--text-muted);
    font-size: 0.9rem;
    margin-bottom: 0.5rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.card .value {
    font-size: 1.8rem;
    font-weight: 700;
    color: var(--text-main);
    margin-bottom: 0.25rem;
}

.grid-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.table-container {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 1.5rem;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
    overflow-x: auto;
    margin-bottom: 2rem;
    max-height: 400px;
    display: flex;
    flex-direction: column;
}

.chart-wrapper {
    position: relative;
    height: 300px;
    width: 100%;
}

table {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
}

th {
    color: var(--text-muted);
    font-size: 0.8rem;
    text-transform: uppercase;
    padding: 1rem;
    border-bottom: 1px solid var(--border);
}

td {
    padding: 1rem;
    border-bottom: 1px solid var(--border);
    color: var(--text-main);
    font-size: 0.95rem;
}

tr:last-child td {
    border-bottom: none;
}

tr:hover {
    background: #f9fafb;
}

.btn {
    padding: 0.6rem 1.2rem;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 500;
    transition: all 0.2s;
    font-size: 0.95rem;
}

.btn-primary {
    background: var(--primary);
    color: white;
}

.btn-primary:hover {
    background: var(--primary-hover);
    transform: translateY(-1px);
}

.btn-danger {
    background: var(--danger);
    color: white;
}

.btn-success {
    background: var(--success);
    color: white;
}

.flex-between {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    gap: 1rem;
}

.flex-gap {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.form-group {
    margin-bottom: 1rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    color: var(--text-main);
    font-weight: 500;
    font-size: 0.9rem;
}

.form-control {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    outline: none;
    transition: border 0.2s;
    font-size: 0.95rem;
    background: #fefefe;
}

.form-control:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

select.form-control {
    cursor: pointer;
}

.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(2px);
    align-items: center;
    justify-content: center;
    z-index: 100;
}

.modal.active {
    display: flex;
}

.modal-content {
    background: var(--surface);
    padding: 2rem;
    border-radius: var(--radius);
    width: 100%;
    max-width: 500px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1);
    animation: modalIn 0.3s ease-out;
}

@keyframes modalIn {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.modal-header {
    margin-bottom: 1.5rem;
    font-size: 1.3rem;
    font-weight: 700;
}

.toast {
    position: fixed;
    bottom: 20px;
    right: 20px;
    background: var(--success);
    color: white;
    padding: 1rem 1.5rem;
    border-radius: 8px;
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    transform: translateY(100px);
    opacity: 0;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 1000;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.toast.show {
    transform: translateY(0);
    opacity: 1;
}

.badge {
    padding: 0.25rem 0.75rem;
    border-radius: 999px;
    font-size: 0.8rem;
    font-weight: 600;
    display: inline-block;
}

.badge.pendiente {
    background: #FEF3C7;
    color: #D97706;
}

.badge.entregado {
    background: #D1FAE5;
    color: #059669;
}

.badge.cancelado {
    background: #FEE2E2;
    color: #DC2626;
}

/* =====================================================================
   CRM/ERP — estados de pedidos, calendario, fichas, materiales
   (append-only: no modifica reglas existentes)
   ===================================================================== */

/* ---- Badges por estado de fabricación ---- */
.badge.cotizacion {
    background: #F3F4F6;
    color: #6B7280;
}

.badge.diseno {
    background: #E0E7FF;
    color: #4338CA;
}

.badge.diseno-aprobado {
    background: #DBEAFE;
    color: #1D4ED8;
}

.badge.en-produccion {
    background: #FEF3C7;
    color: #D97706;
}

.badge.terminado {
    background: #CCFBF1;
    color: #0F766E;
}

.badge.entregado {
    background: #D1FAE5;
    color: #059669;
}

.badge.atrasado {
    background: #FEE2E2;
    color: #DC2626;
}

.badge.alerta {
    background: #FEE2E2;
    color: #DC2626;
}

.badge.saldo-pendiente {
    background: #FFEDD5;
    color: #C2410C;
}

/* ---- Grids para fichas ---- */
.grid-2 {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 1.5rem;
}

.grid-3 {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
}

/* ---- Filas etiqueta/valor para fichas ---- */
.detail-row {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--border);
}

.detail-row:last-child {
    border-bottom: none;
}

.detail-label {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--text-muted);
    font-weight: 600;
}

.detail-value {
    font-size: 0.95rem;
    color: var(--text-main);
}

/* ---- Botones de estados (workflow) ---- */
.workflow-strip {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    align-items: center;
}

.workflow-btn {
    border: 1.5px solid var(--border);
    background: var(--surface);
    color: var(--text-muted);
    padding: 0.45rem 0.9rem;
    border-radius: 999px;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
}

.workflow-btn:hover {
    border-color: var(--primary);
    color: var(--primary);
}

.workflow-btn.current {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
    cursor: default;
}

/* ---- Calendario ---- */
.view-toggle {
    display: inline-flex;
    border: 1.5px solid var(--border);
    border-radius: 10px;
    overflow: hidden;
    background: var(--surface);
}

.view-toggle button {
    border: none;
    background: transparent;
    padding: 0.5rem 1.1rem;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.15s;
}

.view-toggle button.active {
    background: var(--primary);
    color: #fff;
}

.calendar-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
}

.calendar-nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
    gap: 1rem;
    flex-wrap: wrap;
}

.calendar-nav h2 {
    margin: 0;
    font-size: 1.25rem;
    text-transform: capitalize;
}

.calendar-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 6px;
}

.calendar-head {
    text-align: center;
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    padding: 0.4rem 0;
}

.calendar-cell {
    background: var(--bg-color);
    border-radius: 10px;
    min-height: 96px;
    padding: 0.4rem;
    font-size: 0.8rem;
    cursor: pointer;
    transition: box-shadow 0.15s;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.calendar-cell:hover {
    box-shadow: 0 0 0 2px var(--primary);
}

.calendar-cell.is-other-month {
    opacity: 0.45;
}

.calendar-cell.is-today {
    box-shadow: inset 0 0 0 2px var(--primary);
    background: #EEF2FF;
}

.calendar-cell .day-num {
    font-weight: 700;
    color: var(--text-main);
    font-size: 0.8rem;
}

.calendar-cell.has-alert .day-num {
    color: var(--danger);
}

/* Chips de pedidos dentro del calendario */
.chip {
    display: block;
    width: 100%;
    text-align: left;
    border: none;
    border-left: 3px solid var(--text-muted);
    background: #fff;
    color: var(--text-main);
    border-radius: 6px;
    padding: 0.2rem 0.35rem;
    font-size: 0.68rem;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: transform 0.1s;
}

.chip:hover {
    transform: translateX(2px);
}

.chip.pendiente-entrega {
    border-left-color: var(--success);
    background: #ECFDF5;
    color: #047857;
}

.chip.entregado {
    border-left-color: var(--danger);
    background: #FEF2F2;
    color: #B91C1C;
}

.chip.atrasado {
    border-left-color: var(--danger);
    background: #FEF2F2;
    color: #B91C1C;
}

.chip-more {
    border: none;
    background: transparent;
    color: var(--primary);
    font-size: 0.68rem;
    font-weight: 700;
    cursor: pointer;
    text-align: left;
    padding: 0.1rem 0.35rem;
}

/* ---- Filtros en barra ---- */
.filter-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 0.6rem;
    align-items: center;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.9rem 1rem;
    margin-bottom: 1.5rem;
}

.filter-bar select,
.filter-bar input {
    padding: 0.45rem 0.6rem;
    border: 1.5px solid var(--border);
    border-radius: 8px;
    font-size: 0.88rem;
    background: #fff;
    color: var(--text-main);
}

.filter-bar label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-muted);
}

/* ---- Dropzone y galería de archivos ---- */
.dropzone {
    border: 2px dashed var(--border);
    border-radius: 10px;
    padding: 1rem;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.85rem;
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s;
    background: var(--bg-color);
}

.dropzone:hover {
    border-color: var(--primary);
    background: #EEF2FF;
}

.gallery {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
    gap: 0.75rem;
}

.gallery .file-card {
    background: var(--bg-color);
    border: 1px solid var(--border);
    border-radius: 10px;
    overflow: hidden;
    position: relative;
    font-size: 0.7rem;
}

.gallery .file-card img {
    width: 100%;
    height: 80px;
    object-fit: cover;
    display: block;
    background: #fff;
}

.gallery .file-card .file-name {
    display: block;
    padding: 0.3rem 0.4rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-weight: 600;
}

.gallery .file-card .file-del {
    position: absolute;
    top: 4px;
    right: 4px;
    border: none;
    background: rgba(239, 68, 68, 0.9);
    color: #fff;
    border-radius: 6px;
    width: 22px;
    height: 22px;
    cursor: pointer;
    font-size: 0.7rem;
    line-height: 1;
}

.gallery .file-card .file-link {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 80px;
    font-size: 1.6rem;
    text-decoration: none;
}

/* ---- Timeline de pagos ---- */
.timeline {
    list-style: none;
    margin: 0;
    padding: 0 0 0 1.25rem;
    border-left: 2px solid var(--border);
}

.timeline li {
    position: relative;
    padding: 0.5rem 0 0.5rem 1rem;
}

.timeline li::before {
    content: '';
    position: absolute;
    left: -1.7rem;
    top: 0.95rem;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--primary);
}

.timeline li.pago-liquidacion::before {
    background: var(--success);
}

.saldo-hero {
    font-size: 2rem;
    font-weight: 800;
    color: var(--danger);
}

.saldo-hero.pago {
    color: var(--success);
}

/* ---- Checklist de producción ---- */
.checklist {
    list-style: none;
    margin: 0;
    padding: 0;
}

.checklist li {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.45rem 0;
    border-bottom: 1px solid var(--border);
    font-size: 0.9rem;
}

.checklist li:last-child {
    border-bottom: none;
}

.checklist li.hecho .paso-texto {
    text-decoration: line-through;
    color: var(--text-muted);
}

.paso-texto {
    flex-grow: 1;
}

/* ---- Ficha rápida de pedido (modal reutilizable: pedidos.php, calendario.php...) ---- */
.modal-content.ficha-modal {
    max-width: 640px;
}

.ficha-hero {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1rem;
    flex-wrap: wrap;
}

.ficha-hero h2 {
    margin: 0;
    font-size: 1.5rem;
}

.ficha-mini {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-top: 0.25rem;
}

.ficha-total {
    text-align: right;
}

.ficha-total .monto {
    font-size: 1.3rem;
    font-weight: 800;
}

.ficha-section {
    padding: 1.1rem 0;
    border-top: 1px solid var(--border);
}

.ficha-section:first-of-type {
    border-top: none;
    padding-top: 1rem;
}

.ficha-section h4 {
    margin: 0 0 0.75rem;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--text-muted);
    font-weight: 700;
}

.ficha-quick-form {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    margin-top: 0.75rem;
    align-items: center;
}

.ficha-quick-form input,
.ficha-quick-form select {
    flex: 1;
    min-width: 100px;
    padding: 0.45rem 0.6rem;
    border: 1.5px solid var(--border);
    border-radius: 8px;
    font-size: 0.85rem;
}

.ficha-empty {
    color: var(--text-muted);
    font-size: 0.85rem;
    margin: 0;
}

/* ---- Actividad de ventas en tiempo real ---- */
.actividad-panel {
    max-height: 340px;
    overflow-y: auto;
}

.actividad-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.actividad-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.65rem 0.25rem;
    border-bottom: 1px solid var(--border);
    font-size: 0.88rem;
}

.actividad-item:last-child {
    border-bottom: none;
}

.actividad-punto {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--success);
    flex-shrink: 0;
}

.actividad-texto {
    flex-grow: 1;
    color: var(--text-main);
}

.actividad-meta {
    text-align: right;
    flex-shrink: 0;
}

.actividad-monto {
    display: block;
    font-weight: 700;
    color: var(--primary);
}

.actividad-tiempo {
    display: block;
    font-size: 0.75rem;
    color: var(--text-muted);
}

.actividad-vacio {
    color: var(--text-muted);
    font-size: 0.85rem;
    text-align: center;
    padding: 1rem 0;
}

.actividad-nueva {
    animation: actividadResalta 2s ease-out;
}

@keyframes actividadResalta {
    0% {
        background: #EEF2FF;
    }

    100% {
        background: transparent;
    }
}

.live-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--success);
    margin-right: 0.4rem;
    animation: liveDotPulse 1.6s ease-in-out infinite;
}

@keyframes liveDotPulse {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.35;
    }
}

/* ---- Banner de alertas (stock bajo) ---- */
.alert-banner {
    background: #FEF2F2;
    border: 1.5px solid #FECACA;
    color: #B91C1C;
    border-radius: var(--radius);
    padding: 1rem 1.25rem;
    margin-bottom: 1.5rem;
    font-size: 0.9rem;
}

.alert-banner strong {
    font-weight: 700;
}

/* ---- Responsivo: tablet y celular ---- */
@media (max-width: 900px) {
    .sidebar {
        left: -280px;
        top: 0;
        width: 260px;
        z-index: 200;
        transition: left 0.25s ease;
        box-shadow: 4px 0 20px rgba(0, 0, 0, 0.15);
    }

    .sidebar.open {
        left: 0;
    }

    .menu-toggle {
        display: flex;
    }

    .content {
        margin-left: 0;
        padding: 1.25rem 1rem;
        padding-top: 4.25rem;
    }

    .header {
        flex-wrap: wrap;
        gap: 0.75rem;
    }

    .header h1 {
        font-size: 1.4rem;
    }

    .modal-content,
    .modal-content.pedido-modal,
    .modal-content.ficha-modal {
        max-width: 100%;
        padding: 1.25rem;
    }

    .modal {
        padding: 0.75rem;
    }

    .filter-bar select,
    .filter-bar input {
        flex: 1 1 140px;
    }

    .form-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 480px) {
    .grid-cards {
        grid-template-columns: 1fr;
    }

    .card .value {
        font-size: 1.5rem;
    }
}

/* ---- Impresión (fichas y órdenes de trabajo) ---- */
@media print {

    .sidebar,
    .no-print,
    .toast,
    .logout-btn,
    .view-toggle,
    .filter-bar,
    .menu-toggle,
    .sidebar-overlay {
        display: none !important;
    }

    .content {
        margin: 0;
        padding: 0;
    }
}