/* ManuPro - Main CSS */

/* Global font size reduction to 80% */
html {
    font-size: 80%;
}

/* Custom Bootstrap variables and overrides */
:root {
    --primary-color: #0d6efd;
    --sidebar-bg: #212529;
    --sidebar-width: 250px;
}

/* Sidebar styling */
#sidebar {
    transition: all 0.3s;
    min-height: 100vh;
}

#sidebar.d-none {
    margin-left: calc(-1 * var(--sidebar-width));
}

#sidebar .nav-link {
    padding: 0.75rem 1rem;
    border-radius: 0.25rem;
    transition: all 0.2s;
}

#sidebar .nav-link:hover {
    background-color: rgba(255, 255, 255, 0.1);
}

#sidebar .nav-link.active {
    background-color: var(--primary-color);
}

/* Sidebar wrapper */
#sidebar-wrapper {
    min-height: 100vh;
    transition: margin 0.3s;
}

#page-content-wrapper {
    min-width: 0;
    width: 100%;
}

/* Turbo progress bar */
.turbo-progress-bar {
    background-color: var(--primary-color);
    height: 3px;
}

/* Vietnamese number input */
input[type="number"].vn-number {
    text-align: right;
}

/* Toast notifications */
.toast-container {
    z-index: 9999;
    position: fixed;
    bottom: 1rem;
    right: 1rem;
}

/* Loading state for Turbo frames */
[data-turbo-frame][busy] {
    opacity: 0.6;
    pointer-events: none;
}

/* Page transitions */
[data-turbo-preview] {
    opacity: 0.5;
}

/* Custom scrollbar for sidebar */
#sidebar {
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.3) transparent;
}

#sidebar::-webkit-scrollbar {
    width: 6px;
}

#sidebar::-webkit-scrollbar-track {
    background: transparent;
}

#sidebar::-webkit-scrollbar-thumb {
    background-color: rgba(255, 255, 255, 0.3);
    border-radius: 3px;
}

/* Card styling */
.card {
    border-radius: 0.5rem;
    transition: transform 0.2s, box-shadow 0.2s;
}

.card:hover {
    /* transform: translateY(-2px); */
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.card-header {
    background-color: #f8f9fa;
    border-bottom: 1px solid #dee2e6;
}

/* Table styling */
.table th {
    font-weight: 600;
    text-transform: uppercase;
    font-size: 0.85rem;
    color: #6c757d;
}

/* Table responsive */
.table-responsive {
    border-radius: 0.25rem;
}

/* Badge styles */
.badge {
    padding: 0.375rem 0.75rem;
    font-weight: 500;
}

/* Form controls */
.form-control:focus,
.form-select:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 0.2rem rgba(13, 110, 253, 0.25);
}

/* Vietnamese number formatting */
.vn-currency::after {
    content: ' ₫';
}

/* ============================================
   MOBILE RESPONSIVE - Main Breakpoints
   ============================================ */

/* --- Sidebar as overlay on mobile --- */
@media (max-width: 991.98px) {
    /* Sidebar becomes a fixed overlay drawer */
    #sidebar-wrapper {
        position: fixed !important;
        top: 0;
        left: 0;
        z-index: 1045;
        height: 100vh;
        transform: translateX(-100%);
        transition: transform 0.3s ease-in-out;
        overflow-y: auto;
        box-shadow: 4px 0 16px rgba(0,0,0,0.3);
    }

    #sidebar-wrapper.sidebar-open {
        transform: translateX(0);
    }

    /* Backdrop overlay */
    #sidebar-backdrop {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: rgba(0, 0, 0, 0.5);
        z-index: 1040;
    }

    #sidebar-backdrop.show {
        display: block;
    }

    /* Page content takes full width */
    #page-content-wrapper {
        width: 100% !important;
        margin-left: 0 !important;
    }

    /* Wrapper no longer flex-row on mobile */
    #wrapper {
        display: block !important;
    }

    /* Main content padding reduced */
    #page-content-wrapper .container-fluid.p-4 {
        padding: 1rem !important;
    }

    /* Page header: stack title and actions */
    .d-flex.justify-content-between.align-items-center.mb-4 {
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 0.75rem;
    }

    .d-flex.justify-content-between.align-items-center.mb-4 h2,
    .d-flex.justify-content-between.align-items-center.mb-4 h3 {
        font-size: 1.25rem;
        margin-bottom: 0;
    }

    /* Action buttons in page header go full width on small screens */
    .d-flex.justify-content-between.align-items-center.mb-4 > div,
    .d-flex.justify-content-between.align-items-center.mb-4 > a {
        width: 100%;
    }
}

/* --- Navbar mobile improvements --- */
@media (max-width: 991.98px) {
    .navbar .d-flex.align-items-center {
        gap: 0.25rem;
    }

    /* Show brand name in navbar on mobile */
    .navbar-brand-mobile {
        display: inline-block !important;
    }

    /* Reduce notification badge size */
    .navbar .badge {
        font-size: 0.6rem;
        padding: 0.2rem 0.35rem;
    }

    /* User menu - hide full name on very small screens, keep icon */
    .navbar .dropdown > button span.d-none-mobile {
        display: none;
    }
}

/* --- Tables on mobile --- */
@media (max-width: 767.98px) {
    /* Ensure all tables are scrollable */
    .table-responsive-auto {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* Card inside a card on mobile */
    .card-body .card {
        margin-bottom: 0.75rem;
    }

    /* Compact table on mobile */
    .table td, .table th {
        padding: 0.5rem 0.4rem;
        font-size: 0.85rem;
    }

    /* Stats cards row */
    .row.g-4 > [class*="col-lg"],
    .row.g-3 > [class*="col-lg"] {
        margin-bottom: 0.5rem;
    }

    /* Badge smaller on mobile */
    .badge {
        font-size: 0.7rem;
    }

    /* Filter forms: stack on mobile */
    .filter-form .row > [class*="col-md"] {
        margin-bottom: 0.5rem;
    }

    /* Button groups: wrap on mobile */
    .btn-group {
        flex-wrap: wrap;
    }

    /* Action buttons in table: icon only hint */
    .btn-sm {
        padding: 0.3rem 0.5rem;
    }

    /* Messages/alerts on mobile: full width */
    .messages {
        left: 0.5rem;
        right: 0.5rem;
        max-width: 100%;
        top: auto;
        bottom: 1rem;
    }
}

/* --- Forms on mobile --- */
@media (max-width: 767.98px) {
    /* Horizontal forms stack vertically */
    .row.g-3 > .col-md-6,
    .row.g-3 > .col-md-4,
    .row.g-3 > .col-md-3,
    .row.g-3 > .col-md-8,
    .row.g-3 > .col-md-9 {
        flex: 0 0 100%;
        max-width: 100%;
    }

    /* Form labels in horizontal layout */
    .col-form-label {
        text-align: left !important;
    }

    /* Touch-friendly input sizes */
    .form-control,
    .form-select,
    .btn {
        min-height: 2.5rem;
    }

    /* Inline form groups: stack */
    .d-flex.gap-2 {
        flex-wrap: wrap;
    }

    /* Modal full-width on mobile */
    .modal-dialog {
        margin: 0.5rem;
    }

    /* Pagination: smaller on mobile */
    .pagination .page-link {
        padding: 0.3rem 0.55rem;
        font-size: 0.85rem;
    }
}

/* --- Touch target minimum size --- */
@media (max-width: 991.98px) {
    .btn, a.btn, button {
        min-height: 2.2rem;
    }

    .nav-link {
        padding: 0.55rem 1rem;
    }

    /* Dropdown items easier to tap */
    .dropdown-item {
        padding: 0.6rem 1rem;
    }
}

/* --- Very small phones (< 400px) --- */
@media (max-width: 399.98px) {
    html {
        font-size: 75%;
    }

    #page-content-wrapper .container-fluid {
        padding: 0.5rem !important;
    }

    .card-body {
        padding: 0.75rem;
    }

    h2 { font-size: 1.1rem; }
    h3 { font-size: 1rem; }
}

/* Custom scrollbar */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: #f1f1f1;
}

::-webkit-scrollbar-thumb {
    background: #888;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: #555;
}

/* Loading spinner */
.spinner-border-sm {
    width: 1rem;
    height: 1rem;
    border-width: 0.15em;
}

/* Messages - Toast Notifications */
.messages {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 9999;
    max-width: 500px;
}

.messages .alert {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    border-left-width: 4px;
    border-left-style: solid;
    font-size: 0.95rem;
    animation: slideInRight 0.3s ease-out;
}

.messages .alert-success {
    background-color: #d1e7dd;
    border-color: #badbcc;
    border-left-color: #198754;
    color: #0f5132;
}

.messages .alert-danger,
.messages .alert-error {
    background-color: #f8d7da;
    border-color: #f5c2c7;
    border-left-color: #dc3545;
    color: #842029;
}

.messages .alert-warning {
    background-color: #fff3cd;
    border-color: #ffecb5;
    border-left-color: #ffc107;
    color: #664d03;
}

.messages .alert-info {
    background-color: #cff4fc;
    border-color: #b6effb;
    border-left-color: #0dcaf0;
    color: #055160;
}

@keyframes slideInRight {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

/* Stats cards */
.border-left-primary {
    border-left: 0.25rem solid #4e73df !important;
}

.border-left-success {
    border-left: 0.25rem solid #1cc88a !important;
}

.border-left-info {
    border-left: 0.25rem solid #36b9cc !important;
}

.border-left-warning {
    border-left: 0.25rem solid #f6c23e !important;
}

/* Inline Alerts - Enhanced styling */
.alert {
    border-radius: 0.5rem;
    border-left-width: 4px;
    border-left-style: solid;
    padding: 1rem 1.25rem;
}

.alert i.bi {
    font-size: 1.2em;
    margin-right: 0.5rem;
}

.alert-warning {
    background: linear-gradient(135deg, #fff3cd 0%, #fffaeb 100%);
    border-color: #ffecb5;
    border-left-color: #ffc107;
    color: #664d03;
}

.alert-warning strong {
    color: #cc9a06;
}

.alert-danger {
    background: linear-gradient(135deg, #f8d7da 0%, #fde4e6 100%);
    border-color: #f5c2c7;
    border-left-color: #dc3545;
    color: #842029;
}

.alert-danger strong {
    color: #dc3545;
}

.alert-info {
    background: linear-gradient(135deg, #cff4fc 0%, #e7f9fd 100%);
    border-color: #b6effb;
    border-left-color: #0dcaf0;
    color: #055160;
}

.alert-success {
    background: linear-gradient(135deg, #d1e7dd 0%, #e8f5ec 100%);
    border-color: #badbcc;
    border-left-color: #198754;
    color: #0f5132;
}

/* Alert with shadow for emphasis */
.alert.shadow-sm {
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08) !important;
}

/* Compact alert variant */
.alert.py-2 {
    padding-top: 0.75rem !important;
    padding-bottom: 0.75rem !important;
}

/* Turbo loading state */
body.turbo-loading {
    cursor: wait;
}

body.turbo-loading * {
    pointer-events: none;
}

/* Form validation error styling */
.text-danger.small,
.invalid-feedback {
    display: block;
    background-color: #fee;
    border-left: 3px solid #dc3545;
    padding: 0.5rem 0.75rem;
    border-radius: 0.25rem;
    margin-top: 0.25rem;
    font-size: 0.875rem;
    color: #842029;
}

/* Django errorlist styling */
.errorlist {
    list-style: none;
    padding: 0;
    margin: 0.25rem 0 0 0;
}

.errorlist li {
    background-color: #fee;
    border-left: 3px solid #dc3545;
    padding: 0.5rem 0.75rem;
    border-radius: 0.25rem;
    margin-bottom: 0.25rem;
    font-size: 0.875rem;
    color: #842029;
}

/* Non-field errors styling */
.alert-danger {
    background-color: #f8d7da;
    border-color: #f5c2c7;
    color: #842029;
}

/* Form control with errors */
.form-control.is-invalid,
.form-select.is-invalid {
    border-color: #dc3545;
    padding-right: calc(1.5em + 0.75rem);
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12' width='12' height='12' fill='none' stroke='%23dc3545'%3e%3ccircle cx='6' cy='6' r='4.5'/%3e%3cpath stroke-linejoin='round' d='M5.8 3.6h.4L6 6.5z'/%3e%3ccircle cx='6' cy='8.2' r='.6' fill='%23dc3545' stroke='none'/%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right calc(0.375em + 0.1875rem) center;
    background-size: calc(0.75em + 0.375rem) calc(0.75em + 0.375rem);
}

.form-control.is-invalid:focus,
.form-select.is-invalid:focus {
    border-color: #dc3545;
    box-shadow: 0 0 0 0.2rem rgba(220, 53, 69, 0.25);
}

/* Success validation styling */
.form-control.is-valid,
.form-select.is-valid {
    border-color: #198754;
    padding-right: calc(1.5em + 0.75rem);
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 8 8'%3e%3cpath fill='%23198754' d='M2.3 6.73L.6 4.53c-.4-1.04.46-1.4 1.1-.8l1.1 1.4 3.4-3.8c.6-.63 1.6-.27 1.2.7l-4 4.6c-.43.5-.8.4-1.1.1z'/%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right calc(0.375em + 0.1875rem) center;
    background-size: calc(0.75em + 0.375rem) calc(0.75em + 0.375rem);
}

.valid-feedback {
    display: block;
    background-color: #d1e7dd;
    border-left: 3px solid #198754;
    padding: 0.5rem 0.75rem;
    border-radius: 0.25rem;
    margin-top: 0.25rem;
    font-size: 0.875rem;
    color: #0f5132;
}
