/* public/css/custom.css - Estilos personalizados para StockProyect */

/* ═══════════════════════════════════════════════════════════════
   DESIGN TOKENS
═══════════════════════════════════════════════════════════════ */
:root {
    /* Sidebar palette (mockup) */
    --bg: #0A0E1A;
    --surface: #121A2C;
    --surface-hover: rgba(23, 32, 53, 0.7);
    --border: rgba(255, 255, 255, 0.07);
    --accent: #5B8DEF;
    --accent-soft: rgba(91, 141, 239, 0.14);
    --text: #E7EAF1;
    --text-muted: #7C879E;
    --text-faint: #454E63;
    --radius: 10px;

    /* App palette (kept for content area) */
    --sp-primary: #0f172a;
    --sp-accent: #2563eb;
    --sp-accent-hover: #1d4ed8;
    --sp-bg-light: #f8fafc;
    --sp-card-border: #e2e8f0;

    /* Sidebar dimensions */
    --sidebar-w: 236px;
    --sidebar-w-collapsed: 68px;
    --topbar-h: 56px;
}

/* ═══════════════════════════════════════════════════════════════
   BASE
═══════════════════════════════════════════════════════════════ */
*, *::before, *::after {
    box-sizing: border-box;
}

body {
    background-color: var(--sp-bg-light);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, "Helvetica Neue", Arial, sans-serif;
    color: #334155;
    margin: 0;
}

/* ═══════════════════════════════════════════════════════════════
   LAYOUT WRAPPER
═══════════════════════════════════════════════════════════════ */
.wrapper {
    display: flex;
    width: 100%;
    min-height: 100vh;
}

/* ═══════════════════════════════════════════════════════════════
   SIDEBAR — BASE (shared desktop + mobile)
═══════════════════════════════════════════════════════════════ */
#sidebar {
    background: var(--bg);
    display: flex;
    flex-direction: column;
    height: 100vh;
    border-right: 1px solid var(--border);
    flex-shrink: 0;
    overflow-y: auto;
    overflow-x: hidden;
    transition: width 0.18s ease;
    /* Desktop: sticky */
    position: sticky;
    top: 0;
    width: var(--sidebar-w);
    /* Custom scrollbar */
    scrollbar-width: thin;
    scrollbar-color: var(--text-faint) transparent;
}

#sidebar::-webkit-scrollbar { width: 4px; }
#sidebar::-webkit-scrollbar-thumb { background: var(--text-faint); border-radius: 2px; }

/* ── Brand row ── */
.brand-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 18px 16px 14px;
    flex-shrink: 0;
}

.brand-icon {
    width: 30px;
    height: 30px;
    border-radius: 8px;
    background: var(--accent-soft);
    color: var(--accent);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.brand-text {
    overflow: hidden;
    white-space: nowrap;
    flex: 1;
    min-width: 0;
}

.brand-name {
    font-size: 14.5px;
    font-weight: 600;
    color: var(--text);
    line-height: 1.2;
}

.brand-sub {
    font-size: 11.5px;
    color: var(--text-faint);
    margin-top: 1px;
}

.collapse-btn {
    margin-left: auto;
    width: 24px;
    height: 24px;
    border-radius: 6px;
    border: none;
    background: transparent;
    color: var(--text-faint);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.15s, color 0.15s, transform 0.18s ease;
}

.collapse-btn:hover {
    background: var(--surface);
    color: var(--text-muted);
}

/* ── Nav ── */
.sidebar-nav {
    padding: 6px 10px 18px;
    display: flex;
    flex-direction: column;
    gap: 2px;
    flex: 1;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 9px 10px;
    border-radius: 8px;
    color: var(--text-muted);
    text-decoration: none;
    font-size: 13.5px;
    font-weight: 500;
    position: relative;
    white-space: nowrap;
    overflow: hidden;
    transition: background 0.15s, color 0.15s;
}

.nav-item svg {
    flex-shrink: 0;
    width: 18px;
    height: 18px;
}

.nav-item:hover {
    background: var(--surface);
    color: var(--text);
}

.nav-item.active {
    background: var(--accent-soft);
    color: var(--text);
}

.nav-item.active svg {
    color: var(--accent);
}

.nav-item.active::before {
    content: "";
    position: absolute;
    left: 0;
    top: 8px;
    bottom: 8px;
    width: 3px;
    background: var(--accent);
    border-radius: 0 3px 3px 0;
}

/* Section headings */
.nav-section {
    font-size: 10.5px;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--text-faint);
    padding: 16px 12px 6px;
    white-space: nowrap;
    overflow: hidden;
}

/* ═══════════════════════════════════════════════════════════════
   SIDEBAR — COLLAPSED STATE (desktop ≥ 768px)
═══════════════════════════════════════════════════════════════ */
#sidebar.sidebar--collapsed {
    width: var(--sidebar-w-collapsed);
}

#sidebar.sidebar--collapsed .brand-text,
#sidebar.sidebar--collapsed .nav-item span {
    display: none;
}

#sidebar.sidebar--collapsed .brand-row {
    justify-content: center;
    padding: 18px 8px 14px;
}

#sidebar.sidebar--collapsed .collapse-btn {
    display: none; /* hidden; the topbar toggle shows instead in collapsed rail */
}

#sidebar.sidebar--collapsed .nav-item {
    justify-content: center;
    padding: 9px 0;
}

#sidebar.sidebar--collapsed .nav-section {
    padding: 14px 4px 6px;
    text-align: center;
}

#sidebar.sidebar--collapsed .nav-section span {
    display: none;
}

#sidebar.sidebar--collapsed .nav-section::after {
    content: "·";
    color: var(--text-faint);
}

/* Collapsed: show expand button inside brand row */
#sidebar.sidebar--collapsed .brand-row .collapse-btn {
    display: flex;
    transform: rotate(180deg);
    margin-left: 0;
}

/* ═══════════════════════════════════════════════════════════════
   MAIN CONTENT
═══════════════════════════════════════════════════════════════ */
#content {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    /* Smooth width adjustment when sidebar collapses */
    transition: margin-left 0.18s ease;
}

/* ── In-page topbar (page title + user info) ── */
.main-topbar {
    background: #ffffff;
    border-bottom: 1px solid var(--sp-card-border);
    padding: 14px 24px;
}

/* ═══════════════════════════════════════════════════════════════
   MOBILE TOPBAR (visible < 768px only)
═══════════════════════════════════════════════════════════════ */
.sp-topbar {
    display: none; /* shown via media query below */
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--topbar-h);
    z-index: 200;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
    align-items: center;
    gap: 12px;
    padding: 0 16px;
}

.sp-topbar .brand-name {
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
}

.hamburger-btn {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    border: none;
    background: var(--surface);
    color: var(--text-muted);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    transition: background 0.15s, color 0.15s;
}

.hamburger-btn:hover {
    background: var(--accent-soft);
    color: var(--accent);
}

/* ── Backdrop for mobile drawer ── */
.sp-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.48);
    z-index: 149;
    cursor: pointer;
}

.sp-backdrop.active {
    display: block;
}

/* ═══════════════════════════════════════════════════════════════
   RESPONSIVE — MOBILE (< 768px)
═══════════════════════════════════════════════════════════════ */
@media (max-width: 767px) {
    /* Show mobile topbar */
    .sp-topbar {
        display: flex;
    }

    /* Push content below topbar */
    #content {
        padding-top: var(--topbar-h);
    }

    /* Sidebar becomes a fixed drawer */
    #sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        width: 250px !important; /* override collapsed/expanded vars */
        height: 100%;
        z-index: 150;
        transform: translateX(-100%);
        transition: transform 0.22s ease;
        /* Reset sticky from desktop */
    }

    /* Open state */
    #sidebar.drawer-open {
        transform: translateX(0);
    }

    /* Hide the collapse button in drawer mode */
    .collapse-btn {
        display: none !important;
    }

    /* Show all labels in drawer (never collapsed) */
    #sidebar.sidebar--collapsed .brand-text,
    #sidebar.sidebar--collapsed .nav-item span {
        display: revert;
    }

    #sidebar.sidebar--collapsed .brand-row {
        justify-content: flex-start;
        padding: 18px 16px 14px;
    }

    #sidebar.sidebar--collapsed .nav-item {
        justify-content: flex-start;
        padding: 9px 10px;
    }

    #sidebar.sidebar--collapsed .nav-section {
        padding: 16px 12px 6px;
        text-align: left;
    }

    #sidebar.sidebar--collapsed .nav-section span {
        display: inline;
    }

    #sidebar.sidebar--collapsed .nav-section::after {
        content: "";
    }

    /* Remove wrapper flex-row; sidebar is out of flow */
    .wrapper {
        display: block;
    }
}

/* ═══════════════════════════════════════════════════════════════
   DESKTOP (≥ 768px) — ensure mobile topbar is hidden
═══════════════════════════════════════════════════════════════ */
@media (min-width: 768px) {
    .sp-topbar {
        display: none;
    }
}

/* ═══════════════════════════════════════════════════════════════
   CONTENT AREA COMPONENTS
═══════════════════════════════════════════════════════════════ */
.card-custom {
    background: #ffffff;
    border: 1px solid var(--sp-card-border);
    border-radius: 12px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.table-custom th {
    background: #f1f5f9;
    color: #475569;
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 600;
}

/* Badges de Estado */
.badge-activo {
    background-color: #dcfce7;
    color: #166534;
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 600;
}

.badge-inactivo {
    background-color: #fee2e2;
    color: #991b1b;
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 600;
}

/* Vista Árbol de Áreas */
.area-tree-card {
    border-left: 4px solid var(--sp-accent);
    margin-bottom: 12px;
}

.subarea-list {
    margin-left: 28px;
    border-left: 2px dashed #cbd5e1;
    padding-left: 16px;
}

.subarea-item {
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 10px 16px;
    margin-bottom: 8px;
}

/* ═══════════════════════════════════════════════════════════════
   DASHBOARD COMPACTION & COMPONENT STYLES
═══════════════════════════════════════════════════════════════ */
/* KPI Card compact layout */
.kpi-card {
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.kpi-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08) !important;
}

.kpi-body {
    padding: 12px 14px;
}

.kpi-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.kpi-icon-sm {
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 0.95rem;
}

/* Merma list representation (1-2 categories) */
.merma-lista {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 4px 0;
}

.merma-lista-fila {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.85rem;
}

.merma-color-dot {
    width: 10px;
    height: 10px;
    border-radius: 3px;
    flex-shrink: 0;
}

.merma-nombre {
    font-weight: 500;
    color: #1e293b;
    min-width: 110px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.merma-barra-wrap {
    flex: 1;
    height: 6px;
    background: #e2e8f0;
    border-radius: 3px;
    overflow: hidden;
}

.merma-barra {
    height: 100%;
    border-radius: 3px;
    transition: width 0.3s ease;
}

.merma-monto {
    color: #0f172a;
    font-size: 0.9rem;
    white-space: nowrap;
}

.merma-casos {
    font-size: 0.75rem;
    white-space: nowrap;
}

/* Date filter responsive visibility */
.dash-filter-desktop {
    display: block;
}

.dash-filter-mobile {
    display: none;
}

@media (max-width: 767px) {
    /* Hide desktop in-page topbar on mobile to save vertical space */
    .main-topbar {
        display: none !important;
    }

    /* Switch date filter to mobile dropdown mode */
    .dash-filter-desktop {
        display: none !important;
    }
    .dash-filter-mobile {
        display: block !important;
    }

    /* KPI grid in 2 columns on mobile */
    .kpi-grid {
        display: flex;
        flex-wrap: wrap;
    }

    .kpi-grid > [class*="col-"] {
        flex: 0 0 50%;
        max-width: 50%;
    }
}

/* ═══════════════════════════════════════════════════════════════
   INVENTARIO POR UBICACIÓN — TREE ROWS COMPACT STYLES
═══════════════════════════════════════════════════════════════ */
.area-tree-container {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.area-tree-row {
    background: #ffffff;
    border: 1px solid var(--sp-card-border);
    border-radius: 8px;
    padding: 10px 14px;
    min-height: 48px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    transition: background 0.15s ease, border-color 0.15s ease;
}

.area-tree-row:hover {
    background: #f8fafc;
    border-color: #cbd5e1;
}

.area-tree-row-sub {
    border-left: 3px solid var(--accent);
    background: #fafafa;
}

.area-tree-info {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
    flex: 1;
}

.area-tree-name {
    font-weight: 600;
    font-size: 0.9rem;
    color: #1e293b;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.area-tree-meta {
    font-size: 0.8rem;
    color: #64748b;
    white-space: nowrap;
}

.area-tree-actions {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}

.area-tree-actions .btn-chevron[aria-expanded="true"] i {
    transform: rotate(180deg);
}

.area-tree-actions .btn-chevron i {
    transition: transform 0.2s ease;
}

.area-tree-detail {
    background: #ffffff;
    border: 1px solid var(--sp-card-border);
    border-top: none;
    border-radius: 0 0 8px 8px;
    margin-top: -6px;
    margin-bottom: 6px;
    padding: 0;
    overflow: hidden;
}

@media (max-width: 767px) {
    .area-tree-row {
        padding: 8px 10px;
    }
    .area-tree-row-sub-wrapper {
        margin-left: 14px !important;
    }
}

/* ═══════════════════════════════════════════════════════════════
   MODAL SALIDAS / TRASLADOS — SEARCH AUTOCOMPLETE & MOBILE CARDS
═══════════════════════════════════════════════════════════════ */
.product-search-container {
    position: relative;
    width: 100%;
}

.product-search-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    z-index: 1060;
    max-height: 240px;
    overflow-y: auto;
    background: #ffffff;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.15), 0 8px 10px -6px rgba(0, 0, 0, 0.1);
    margin-top: 4px;
    padding: 4px 0;
}

.product-item-option {
    padding: 8px 12px;
    cursor: pointer;
    font-size: 0.875rem;
    color: #1e293b;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    border-bottom: 1px solid #f1f5f9;
    transition: background 0.12s ease;
}

.product-item-option:last-child {
    border-bottom: none;
}

.product-item-option:hover,
.product-item-option.active-item {
    background-color: #f1f5f9;
    color: var(--sp-primary);
}

.product-item-option .item-sku {
    font-weight: 700;
    font-family: monospace;
    color: var(--accent);
}

.product-item-option .item-stock {
    font-size: 0.775rem;
    color: #64748b;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    padding: 2px 6px;
    border-radius: 12px;
    white-space: nowrap;
}

/* Tarjeta editable de línea de producto en mobile (< 768px) */
.salida-linea-card {
    background: #ffffff;
    border: 1px solid var(--sp-card-border);
    border-radius: 10px;
    padding: 14px;
    position: relative;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.salida-linea-card .btn-remove-line {
    position: absolute;
    top: 10px;
    right: 10px;
}

/* ═══════════════════════════════════════════════════════════════════════
   Desplegable buscable (App.enhanceSelect)
   Sustituye visualmente a un <select> nativo, que queda oculto pero sigue
   siendo la fuente de la verdad del valor seleccionado.
   ═══════════════════════════════════════════════════════════════════════ */
.sp-select { position: relative; }

/* El select real: fuera de la vista pero accesible para el código y los forms */
.sp-select .sp-select-native {
    position: absolute;
    opacity: 0;
    pointer-events: none;
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
    z-index: -1;
}

.sp-select__trigger {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    cursor: pointer;
    background-color: #fff;
    transition: border-color .15s ease, box-shadow .15s ease;
}
.sp-select__trigger:hover  { border-color: #94a3b8; }
.sp-select__trigger:focus,
.sp-select__trigger:focus-visible {
    outline: none;
    border-color: var(--sp-accent);
    box-shadow: 0 0 0 .2rem rgba(37, 99, 235, .15);
}
.sp-select__trigger.is-placeholder .sp-select__label { color: #94a3b8; }

.sp-select__icon  { color: #94a3b8; flex-shrink: 0; font-size: .95rem; }
.sp-select__label {
    flex: 1 1 auto;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--sp-primary);
}

.sp-select__panel {
    display: none;
    position: absolute;
    z-index: 1080;              /* por encima del contenido de un modal */
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    min-width: 240px;
    background: #fff;
    border: 1px solid var(--sp-card-border);
    border-radius: 10px;
    box-shadow: 0 12px 28px -8px rgba(15, 23, 42, .22);
    overflow: hidden;
}
.sp-select__panel.is-open { display: block; }
.sp-select__panel.is-up   { top: auto; bottom: calc(100% + 4px); }

.sp-select__search {
    position: relative;
    padding: 8px;
    border-bottom: 1px solid #f1f5f9;
}
.sp-select__search i {
    position: absolute;
    left: 18px;
    top: 50%;
    transform: translateY(-50%);
    color: #94a3b8;
    font-size: .85rem;
    pointer-events: none;
}
.sp-select__search input { padding-left: 30px; }

.sp-select__list {
    max-height: 260px;
    overflow-y: auto;
    padding: 6px;
}

.sp-select__opt {
    display: flex;
    align-items: flex-start;
    gap: 9px;
    width: 100%;
    padding: 7px 9px;
    border: 0;
    border-radius: 7px;
    background: transparent;
    text-align: left;
    font-size: .9rem;
    line-height: 1.35;
    color: var(--sp-primary);
    cursor: pointer;
}
.sp-select__opt:hover,
.sp-select__opt.is-marked { background: #f1f5f9; }
.sp-select__opt.is-active {
    background: rgba(37, 99, 235, .09);
    font-weight: 600;
}
/* Las sub-áreas se indentan: la jerarquía se lee de un vistazo sin repetir
   "Padre > Hijo" en cada fila. */
.sp-select__opt[data-nivel="1"] { padding-left: 26px; }

.sp-select__opt-icon      { color: #94a3b8; font-size: .85rem; margin-top: 2px; flex-shrink: 0; }
.sp-select__opt.is-active .sp-select__opt-icon { color: var(--sp-accent); }
.sp-select__opt[data-nivel="0"] .sp-select__opt-icon { color: #f59e0b; }

.sp-select__opt-body   { display: flex; flex-direction: column; min-width: 0; }
.sp-select__opt-text   { overflow: hidden; text-overflow: ellipsis; }
.sp-select__opt-parent,
.sp-select__opt-sub {
    font-size: .74rem;
    color: #94a3b8;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sp-select__empty {
    margin: 0;
    padding: 14px 10px;
    text-align: center;
    color: #94a3b8;
    font-size: .85rem;
}
