/*
 * Farmalisto SAS - Main CSS (Responsive)
 */

/* ===========================
   Variables
   =========================== */
:root {
    --green-dark:  #1B5E20;
    --green:       #2E7D32;
    --green-light: #4CAF50;
    --green-pale:  #E8F5E9;
    --sidebar-width: 260px;
    --navbar-h: 56px;
    --shadow-sm: 0 2px 8px rgba(0,0,0,0.06);
    --shadow-md: 0 4px 16px rgba(0,0,0,0.10);
    --radius: 8px;
    --touch-min: 44px;  /* mínimo área táctil */
}

/* ===========================
   Base
   =========================== */
body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    font-size: 14px;
    color: #333;
    background-color: #F5F6FA;
    overflow-x: hidden;
}

h1,h2,h3,h4,h5,h6 { font-weight: 600; }

code {
    font-size: 0.85em;
    color: var(--green);
    background: var(--green-pale);
    padding: 2px 5px;
    border-radius: 4px;
}

/* ===========================
   Layout wrapper
   =========================== */
#layout-wrapper {
    display: flex;
    min-height: 100vh;
}

/* ===========================
   Sidebar
   =========================== */
#sidebar {
    width: var(--sidebar-width);
    min-height: 100vh;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
    flex-shrink: 0;
    scrollbar-width: thin;
    scrollbar-color: rgba(255,255,255,0.2) transparent;
    transition: transform 0.28s ease;
    z-index: 1040;
}

#sidebar::-webkit-scrollbar { width: 4px; }
#sidebar::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.2); border-radius: 2px; }

#sidebar .nav-link {
    border-radius: 6px;
    padding: 10px 12px;
    font-size: 13.5px;
    transition: all 0.15s ease;
    margin-bottom: 2px;
    min-height: var(--touch-min);
    display: flex;
    align-items: center;
}

#sidebar .nav-link:hover  { background: rgba(255,255,255,0.12); }
#sidebar .nav-link.active { background: var(--green-light) !important; color: #fff !important; font-weight: 600; }

/* Overlay para móvil */
#sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.45);
    z-index: 1039;
}

/* ===========================
   Main content
   =========================== */
#main-content {
    flex: 1;
    min-width: 0;       /* evita overflow en flex */
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

main {
    flex: 1;
    padding: 1.25rem;
    min-width: 0;
    max-width: 100%;
    overflow-x: clip;
}

/* ===========================
   Top navbar
   =========================== */
.top-navbar {
    min-height: var(--navbar-h);
    position: sticky;
    top: 0;
    z-index: 1030;
    background: #fff;
    border-bottom: 1px solid #e9ecef;
    padding: 0 1rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.top-navbar .breadcrumb { margin-bottom: 0; font-size: 12.5px; }
.top-navbar .breadcrumb-item a { color: var(--green); text-decoration: none; }

/* ===========================
   Cards
   =========================== */
.card {
    border: none;
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
}
.card-header {
    border-radius: var(--radius) var(--radius) 0 0 !important;
    font-size: 13.5px;
    padding: 12px 16px;
}
.card-body { padding: 1rem; max-width: 100%; }
main .card { min-width: 0; max-width: 100%; }

/* ===========================
   Tables — scroll horizontal en móvil
   =========================== */
.table-responsive { overflow-x: auto; -webkit-overflow-scrolling: touch; }

.table { font-size: 13.5px; }
.table thead th {
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    font-weight: 600;
    padding: 10px 12px;
    white-space: nowrap;
}
.table tbody td { padding: 10px 12px; vertical-align: middle; }
.table-hover tbody tr:hover { background: rgba(27,94,32,0.04); }

/* ===========================
   Forms
   =========================== */
.form-control, .form-select {
    border-radius: 6px;
    border: 1.5px solid #e0e0e0;
    font-size: 14px;
    min-height: var(--touch-min);
    transition: border-color 0.15s, box-shadow 0.15s;
}
.form-control:focus, .form-select:focus {
    border-color: var(--green-light);
    box-shadow: 0 0 0 0.2rem rgba(76,175,80,0.25);
}
.form-label { font-size: 13px; margin-bottom: 4px; }
.input-group-text { border: 1.5px solid #e0e0e0; font-size: 14px; background: #fafafa; }

/* ===========================
   Buttons — táctiles
   =========================== */
.btn {
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    min-height: var(--touch-min);
    padding: 0.5rem 1rem;
    transition: all 0.15s ease;
}
.btn-sm { min-height: 36px; padding: 0.3rem 0.7rem; font-size: 13px; }
.btn:hover { transform: translateY(-1px); box-shadow: 0 3px 8px rgba(0,0,0,0.15); }
.btn:active { transform: translateY(0); }

.btn-success { background: var(--green); border-color: var(--green); }
.btn-success:hover { background: var(--green-dark); border-color: var(--green-dark); }

/* ===========================
   Item rows (cotizaciones)
   =========================== */
.item-row { background: #f8f9fa; border-radius: 8px; padding: 12px; margin-bottom: 8px; }
.item-row:hover { background: #e8f5e9; }

/* ===========================
   Badges, Alerts, Pagination
   =========================== */
.badge { font-size: 11px; font-weight: 600; padding: 4px 8px; border-radius: 20px; }

.alert {
    border: none;
    border-radius: var(--radius);
    font-size: 13.5px;
    padding: 10px 16px;
    border-left: 4px solid;
}
.alert-success  { background: var(--green-pale);   border-left-color: var(--green);     color: var(--green-dark); }
.alert-danger   { background: #FFEBEE;             border-left-color: #C62828;          color: #B71C1C; }
.alert-warning  { background: #FFF8E1;             border-left-color: #F57F17;          color: #E65100; }
.alert-info     { background: #E3F2FD;             border-left-color: #1565C0;          color: #0D47A1; }

.pagination .page-link {
    border-radius: 6px; margin: 0 2px;
    border: 1.5px solid #dee2e6;
    font-size: 13px; color: var(--green);
    min-height: 38px; display: flex; align-items: center;
}
.pagination .page-link:hover       { background: var(--green-pale); border-color: var(--green); }
.pagination .page-item.active .page-link { background: var(--green); border-color: var(--green); }

/* ===========================
   Stat cards
   =========================== */
.stat-card { transition: transform 0.15s ease; }
.stat-card:hover { transform: translateY(-3px); }

/* ===========================
   Mobile bottom bar (visitadores)
   =========================== */
.mobile-bottombar {
    display: none;
    position: fixed;
    bottom: 0; left: 0; right: 0;
    height: 60px;
    background: #1a1a2e;
    border-top: 1px solid rgba(255,255,255,0.1);
    z-index: 1038;
    padding: 0 0.5rem;
}
.mobile-bottombar a {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: rgba(255,255,255,0.65);
    text-decoration: none;
    font-size: 10px;
    gap: 2px;
    padding: 6px 4px;
    border-radius: 6px;
    transition: color 0.15s, background 0.15s;
}
.mobile-bottombar a i { font-size: 20px; }
.mobile-bottombar a.active,
.mobile-bottombar a:hover { color: #4CAF50; background: rgba(76,175,80,0.12); }

/* Espacio para bottom bar en móvil */
@media (max-width: 767.98px) {
    main { padding-bottom: 75px !important; }
    .mobile-bottombar { display: flex; }
}

/* ===========================
   RESPONSIVE — Tablet & Mobile
   =========================== */

/* --- Tablet (≤ 991px) --- */
@media (max-width: 991.98px) {
    #sidebar {
        position: fixed;
        left: 0; top: 0;
        height: 100vh;
        transform: translateX(-100%);
    }
    #sidebar.open {
        transform: translateX(0);
    }
    #sidebar-overlay.open { display: block; }

    #main-content { width: 100%; }
}

/* --- Mobile (≤ 767px) --- */
@media (max-width: 767.98px) {
    main { padding: 0.75rem; }

    /* Header con botones apilados */
    .page-header-row {
        flex-direction: column;
        align-items: flex-start !important;
        gap: 0.5rem;
    }
    .page-header-row .btn-group-actions {
        width: 100%;
        display: flex;
        flex-wrap: wrap;
        gap: 0.4rem;
    }
    .page-header-row .btn-group-actions .btn {
        flex: 1;
        min-width: 120px;
    }

    /* Ocultar columnas no esenciales en tablas */
    .table .hide-mobile { display: none; }

    /* Tarjetas de cotización en lugar de tabla */
    .quotation-table-row td { padding: 8px 10px; font-size: 13px; }

    /* Formulario items — apila en móvil */
    .item-row .row > [class*="col-md-"] {
        width: 100%;
        margin-bottom: 0.4rem;
    }

    /* Botones de acción en detalle */
    .detail-actions {
        flex-wrap: wrap;
        gap: 0.4rem !important;
    }
    .detail-actions .btn { flex: 1 1 140px; font-size: 13px; }

    /* Sidebar: cerrar con X visible */
    #sidebar-close { display: flex !important; }

    /* Ocultar reloj en móvil */
    .clock-display { display: none; }

    /* Cards en formularios */
    .card-body { padding: 0.75rem; }
    .card-header { padding: 10px 12px; }

    /* Columnas de 2 en grids de resumen */
    .summary-grid .col-md-4 { width: 50%; }
}

/* --- Pantallas muy pequeñas (≤ 380px) --- */
@media (max-width: 380px) {
    .detail-actions .btn { flex: 1 1 100%; }
    .top-navbar .breadcrumb { display: none; }
}

/* ===========================
   Print
   =========================== */
@media print {
    #sidebar, .top-navbar, footer, .btn, .mobile-bottombar, #sidebar-overlay { display: none !important; }
    body { background: #fff; }
    .card { box-shadow: none; border: 1px solid #ddd; }
    main { padding: 0 !important; }
}

/* ===========================
   Scrollbar
   =========================== */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: #f1f1f1; }
::-webkit-scrollbar-thumb { background: #c0c0c0; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #a0a0a0; }

/* ===========================
   Loading
   =========================== */
.btn.loading { pointer-events: none; opacity: 0.7; }
.btn.loading::after {
    content: '';
    display: inline-block;
    width: 12px; height: 12px;
    border: 2px solid rgba(255,255,255,0.5);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
    margin-left: 6px;
}
@keyframes spin { to { transform: rotate(360deg); } }
