/* ShopERP Main Styles */

/* CSS Variables for Safe Areas (PWA on iPhone) */
:root {
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --safe-left: env(safe-area-inset-left, 0px);
    --safe-right: env(safe-area-inset-right, 0px);

    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --success: #16a34a;
    --warning: #ca8a04;
    --danger: #dc2626;
}

* {
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    margin: 0;
    padding: 0;
    background-color: #f3f4f6;
}

/* PWA Safe Area Padding */
.pwa-safe-padding {
    padding-top: var(--safe-top);
    padding-bottom: var(--safe-bottom);
    padding-left: var(--safe-left);
    padding-right: var(--safe-right);
}

/* Responsive Table - Show as Cards on Mobile */
.responsive-table {
    width: 100%;
}

@media (max-width: 768px) {
    /* Hide table headers on mobile */
    .responsive-table thead {
        display: none;
    }

    /* Convert table rows to cards */
    .responsive-table tbody,
    .responsive-table tr {
        display: block;
        width: 100%;
    }

    .responsive-table tr {
        background: white;
        border-radius: 8px;
        padding: 12px;
        margin-bottom: 12px;
        box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    }

    .responsive-table td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 8px 0;
        border-bottom: 1px solid #e5e7eb;
    }

    .responsive-table td:last-child {
        border-bottom: none;
    }

    /* Add labels via data attribute or before pseudo */
    .responsive-table td::before {
        content: attr(data-label);
        font-weight: 600;
        color: #374151;
        margin-right: 12px;
    }

    /* Action buttons - remove ::before */
    .responsive-table td[data-label="Thao tác"]::before,
    .responsive-table td.actions::before {
        content: "";
        margin: 0;
    }

    .responsive-table td.actions {
        justify-content: center;
        gap: 8px;
    }
}

/* Card Component for Mobile Lists */
.mobile-card {
    background: white;
    border-radius: 8px;
    padding: 12px;
    margin-bottom: 12px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.mobile-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.mobile-card-title {
    font-weight: 600;
    color: #111827;
}

.mobile-card-subtitle {
    font-size: 0.875rem;
    color: #6b7280;
}

.mobile-card-body {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
}

.mobile-card-row {
    display: flex;
    flex-direction: column;
}

.mobile-card-label {
    font-size: 0.75rem;
    color: #6b7280;
}

.mobile-card-value {
    font-weight: 500;
    color: #111827;
}

.mobile-card-actions {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid #e5e7eb;
}

/* Hide cards on desktop, show table */
@media (min-width: 769px) {
    .mobile-cards-container {
        display: none;
    }
    .desktop-table-container {
        display: block;
    }
}

/* Hide table on mobile, show cards */
@media (max-width: 768px) {
    .mobile-cards-container {
        display: block;
    }
    .desktop-table-container {
        display: none;
    }
}

/* ============================================
   OFFCANVAS SIDEBAR (Bootstrap style)
   ============================================ */

/* Sidebar base - hidden by default on mobile */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 288px;
    max-width: 85vw;
    z-index: 50;
    display: flex;
    flex-direction: column;
    background-color: #111827;
    color: white;
    transform: translateX(-100%);
    transition: transform 0.3s ease-in-out;
}

/* Sidebar open state */
.sidebar.is-open {
    transform: translateX(0);
}

/* Sidebar backdrop/overlay */
.sidebar-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 40;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.sidebar-overlay.is-open {
    opacity: 1;
    pointer-events: auto;
}

/* Desktop: sidebar always visible */
@media (min-width: 768px) {
    .sidebar {
        position: static !important;
        transform: none !important;
        width: 280px;
        flex-shrink: 0;
    }

    .sidebar-overlay {
        display: none !important;
    }
}

/* Mobile specific styles */
@media (max-width: 767px) {
    .sidebar > nav {
        flex: 1;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    .sidebar > div:first-child,
    .sidebar > div:last-child {
        flex-shrink: 0;
    }
}

/* Flash Messages */
.flash-message {
    padding: 12px 16px;
    border-radius: 8px;
    margin-bottom: 16px;
    animation: slideIn 0.3s ease;
}

@keyframes slideIn {
    from {
        transform: translateY(-20px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.flash-success {
    background-color: #d1fae5;
    color: #065f46;
    border: 1px solid #a7f3d0;
}

.flash-error {
    background-color: #fee2e2;
    color: #991b1b;
    border: 1px solid #fecaca;
}

.flash-warning {
    background-color: #fef3c7;
    color: #92400e;
    border: 1px solid #fde68a;
}

.flash-info {
    background-color: #dbeafe;
    color: #1e40af;
    border: 1px solid #bfdbfe;
}

/* Loading Spinner */
.spinner {
    border: 3px solid #e5e7eb;
    border-top-color: var(--primary);
    border-radius: 50%;
    width: 40px;
    height: 40px;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Status Badges */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 4px 10px;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 500;
}

.badge-success {
    background-color: #d1fae5;
    color: #065f46;
}

.badge-warning {
    background-color: #fef3c7;
    color: #92400e;
}

.badge-danger {
    background-color: #fee2e2;
    color: #991b1b;
}

.badge-info {
    background-color: #dbeafe;
    color: #1e40af;
}

.badge-gray {
    background-color: #f3f4f6;
    color: #374151;
}

/* Form Styles */
.form-group {
    margin-bottom: 16px;
}

.form-label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    color: #374151;
    margin-bottom: 4px;
}

.form-input,
.form-select,
.form-textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    font-size: 0.875rem;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.form-input.is-invalid,
.form-select.is-invalid,
.form-textarea.is-invalid {
    border-color: var(--danger);
}

.form-error {
    font-size: 0.75rem;
    color: var(--danger);
    margin-top: 4px;
}

/* Button Styles */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 10px 16px;
    border-radius: 8px;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    border: none;
    gap: 8px;
}

.btn-primary {
    background-color: var(--primary);
    color: white;
}

.btn-primary:hover {
    background-color: var(--primary-hover);
}

.btn-success {
    background-color: var(--success);
    color: white;
}

.btn-danger {
    background-color: var(--danger);
    color: white;
}

.btn-outline {
    background-color: transparent;
    border: 1px solid #d1d5db;
    color: #374151;
}

.btn-outline:hover {
    background-color: #f9fafb;
}

.btn-sm {
    padding: 6px 12px;
    font-size: 0.75rem;
}

.btn-lg {
    padding: 14px 20px;
    font-size: 1rem;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Utility Classes */
.text-center { text-align: center; }
.text-right { text-align: right; }
.text-left { text-align: left; }

.font-bold { font-weight: 700; }
.font-semibold { font-weight: 600; }
.font-medium { font-weight: 500; }

.text-primary { color: var(--primary); }
.text-success { color: var(--success); }
.text-danger { color: var(--danger); }
.text-warning { color: var(--warning); }
.text-gray { color: #6b7280; }

.bg-primary { background-color: var(--primary); }
.bg-success { background-color: var(--success); }
.bg-danger { background-color: var(--danger); }

.mt-1 { margin-top: 4px; }
.mt-2 { margin-top: 8px; }
.mt-3 { margin-top: 12px; }
.mt-4 { margin-top: 16px; }
.mb-1 { margin-bottom: 4px; }
.mb-2 { margin-bottom: 8px; }
.mb-3 { margin-bottom: 12px; }
.mb-4 { margin-bottom: 16px; }
.p-4 { padding: 16px; }

/* ============================================
   MODAL SYSTEM
   ============================================ */

/* Modal Overlay */
.modal-overlay {
    animation: fadeIn 0.2s ease-out;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

/* Modal Wrapper */
.modal-wrapper {
    animation: slideUp 0.3s ease-out;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(20px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* Modal Header */
.modal-header {
    border-radius: 12px 12px 0 0;
}

.modal-title {
    font-weight: 600;
    color: #111827;
}

/* Modal Body */
.modal-body {
    min-height: 100px;
}

/* Modal Footer */
.modal-footer {
    border-radius: 0 0 12px 12px;
    background-color: #f9fafb;
}

/* Modal Loading */
.modal-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 200px;
}

/* Form in Modal */
#modal-form .form-group {
    margin-bottom: 1rem;
}

#modal-form .form-label {
    display: block;
    font-weight: 500;
    color: #374151;
    margin-bottom: 0.25rem;
    font-size: 0.875rem;
}

#modal-form .form-input,
#modal-form .form-select,
#modal-form .form-textarea {
    width: 100%;
    padding: 0.625rem 0.75rem;
    border: 1px solid #d1d5db;
    border-radius: 0.5rem;
    font-size: 0.875rem;
    transition: border-color 0.15s, box-shadow 0.15s;
}

#modal-form .form-input:focus,
#modal-form .form-select:focus,
#modal-form .form-textarea:focus {
    outline: none;
    border-color: #2563eb;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

#modal-form .form-input.is-invalid,
#modal-form .form-select.is-invalid,
#modal-form .form-textarea.is-invalid {
    border-color: #dc2626;
}

#modal-form .form-error {
    color: #dc2626;
    font-size: 0.75rem;
    margin-top: 0.25rem;
}

#modal-form .required::after {
    content: ' *';
    color: #dc2626;
}

/* Modal Buttons */
.modal-footer button {
    padding: 0.625rem 1rem;
    border-radius: 0.5rem;
    font-size: 0.875rem;
    font-weight: 500;
    transition: all 0.15s;
}

.modal-footer button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Responsive Modal */
@media (max-width: 640px) {
    .modal-wrapper {
        max-width: 95vw !important;
        max-height: 90vh;
        margin: 0.5rem;
    }

    .modal-header,
    .modal-body,
    .modal-footer {
        padding-left: 1rem;
        padding-right: 1rem;
    }
}

/* Print Styles */
@media print {
    .no-print,
    .sidebar,
    .topbar,
    button,
    .pagination,
    .modal-overlay {
        display: none !important;
    }

    .main-content {
        margin: 0 !important;
    }
}
