/* Categories Management Styles */

.categories-container {
    padding: 20px;
    max-width: 1200px;
    margin: 0 auto;
}

.categories-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 25px;
    padding-bottom: 15px;
    border-bottom: 2px solid var(--border-color);
}

.categories-header h2 {
    margin: 0;
    color: #ffffff;
    font-size: 24px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.categories-header h2 i {
    color: #ffffff;
}

.categories-content {
    display: grid;
    grid-template-columns: 400px 1fr;
    gap: 25px;
}

/* Form Section */
.category-form-section {
    background: white;
    border-radius: 12px;
    padding: 20px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    height: fit-content;
    position: sticky;
    top: 20px;
}

.category-form-section h3 {
    margin: 0 0 20px 0;
    color: var(--text-primary);
    font-size: 18px;
    display: flex;
    align-items: center;
    gap: 8px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border-color);
}

.category-form-section h3 i {
    color: var(--primary-brown);
}

.category-form .form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px;
}

.category-form .form-group {
    margin-bottom: 15px;
}

.category-form label {
    display: block;
    margin-bottom: 6px;
    font-weight: 600;
    color: var(--text-secondary);
    font-size: 13px;
}

.category-form label .required {
    color: #dc3545;
}

.category-form input,
.category-form select {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 14px;
    transition: all 0.2s ease;
    background: white;
}

.category-form input:focus,
.category-form select:focus {
    border-color: var(--primary-brown);
    outline: none;
    box-shadow: 0 0 0 3px rgba(166, 124, 82, 0.1);
}

.category-form .form-buttons {
    display: flex;
    gap: 10px;
    margin-top: 20px;
}

.category-form .btn-save,
.category-form .btn-cancel {
    flex: 1;
    padding: 12px 20px;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: all 0.2s ease;
}

.category-form .btn-save {
    background: linear-gradient(135deg, var(--primary-brown), var(--primary-brown-dark));
    color: white;
}

.category-form .btn-save:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(166, 124, 82, 0.3);
}

.category-form .btn-cancel {
    background: #6c757d;
    color: white;
}

.category-form .btn-cancel:hover {
    background: #5a6268;
}

/* List Section */
.category-list-section {
    background: white;
    border-radius: 12px;
    padding: 20px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.category-list-section .list-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border-color);
}

.category-list-section .list-header h3 {
    margin: 0;
    color: var(--text-primary);
    font-size: 18px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.category-list-section .list-header h3 i {
    color: var(--primary-brown);
}

.category-list-section .list-info {
    background: var(--secondary-cream);
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 13px;
    color: var(--text-secondary);
}

.category-list-section .list-info span {
    font-weight: 700;
    color: var(--primary-brown);
}

/* Table Styles */
#categoryTable {
    width: 100%;
    border-collapse: collapse;
}

#categoryTable thead {
    background: linear-gradient(135deg, var(--primary-brown), var(--primary-brown-dark));
    color: white;
}

#categoryTable th {
    padding: 12px 15px;
    text-align: left;
    font-weight: 600;
    font-size: 13px;
}

#categoryTable tbody tr {
    border-bottom: 1px solid var(--border-color);
    transition: background 0.2s ease;
}

#categoryTable tbody tr:hover {
    background: var(--secondary-cream);
}

#categoryTable td {
    padding: 12px 15px;
    font-size: 14px;
    vertical-align: middle;
}

#categoryTable .empty-message {
    text-align: center;
    padding: 40px 20px !important;
    color: #999;
}

#categoryTable .empty-message i {
    font-size: 40px;
    display: block;
    margin-bottom: 10px;
    color: #ddd;
}

/* Icon Column */
.category-icon {
    width: 45px;
    height: 45px;
    background: var(--secondary-cream);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    color: var(--primary-brown);
}

/* Action Buttons */
.category-actions {
    display: flex;
    gap: 8px;
}

.category-actions .btn-edit,
.category-actions .btn-delete {
    padding: 8px 12px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 5px;
}

.category-actions .btn-edit {
    background: #e8f5e9;
    color: #2e7d32;
}

.category-actions .btn-edit:hover {
    background: #c8e6c9;
}

.category-actions .btn-delete {
    background: #ffebee;
    color: #c62828;
}

.category-actions .btn-delete:hover {
    background: #ffcdd2;
}

/* Product Count Badge */
.product-count-badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    background: var(--secondary-cream);
    padding: 5px 12px;
    border-radius: 15px;
    font-size: 13px;
    color: var(--text-secondary);
}

.product-count-badge i {
    color: var(--primary-brown);
    font-size: 12px;
}

/* ==================== MODAL STYLES ==================== */

/* Modal Large */
.modal-content.modal-large {
    max-width: 700px;
    width: 95%;
    /* Prevent modal from exceeding viewport height */
    max-height: 85vh;
    overflow: hidden;
}

/* Form Wrapper in Modal */
.category-form-wrapper {
    background: #f8f9fa;
    padding: 15px 20px;
    border-radius: 10px;
    margin-bottom: 20px;
}

/* Make modal body scrollable to avoid being clipped by window chrome */
.modal-content.modal-large .modal-body {
    max-height: calc(85vh - 80px);
    overflow-y: auto;
    padding: 16px;
}

/* Constrain the category list so the table scrolls inside the modal */
.category-list-wrapper {
    max-height: calc(85vh - 240px);
    overflow-y: auto;
}

/* Ensure the modal is positioned slightly below top to avoid being behind OS chrome */
.modal.active .modal-content.modal-large {
    margin-top: 3vh;
}

.category-form-wrapper h4 {
    margin: 0 0 12px 0;
    font-size: 14px;
    color: #666;
    display: flex;
    align-items: center;
    gap: 8px;
}

.category-form-wrapper h4 i {
    color: var(--primary-brown);
}

/* Inline Form */
.inline-category-form .form-inline-row {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: nowrap;
}

.inline-category-form .form-group {
    flex: 1;
    min-width: 150px;
    margin: 0;
}

.inline-category-form input,
.inline-category-form select {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #ddd;
    border-radius: 8px;
    font-size: 14px;
}

.inline-category-form input:focus,
.inline-category-form select:focus {
    border-color: var(--primary-brown);
    outline: none;
}

.btn-add-category {
    padding: 10px 20px;
    background: var(--primary-brown);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
    transition: all 0.2s;
}

.btn-add-category:hover {
    background: var(--primary-brown-dark);
}

.btn-cancel-category {
    padding: 10px 16px;
    background: #6c757d;
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: all 0.2s;
}

/* Editing state: show Save (Lưu) as green and Cancel (Hủy) as red; keep inline */
.inline-category-form.editing .btn-add-category {
    background: #28a745;
}
.inline-category-form.editing .btn-add-category:hover {
    background: #218838;
}
.inline-category-form.editing .btn-cancel-category {
    background: #dc3545;
}
.inline-category-form.editing .btn-cancel-category:hover {
    background: #c82333;
}

/* Allow wrapping on very small screens */
@media (max-width: 720px) {
    .inline-category-form .form-inline-row {
        flex-wrap: wrap;
    }
}

.btn-cancel-category:hover {
    background: #5a6268;
}

/* Category List in Modal */
.category-list-wrapper {
    max-height: 400px;
    overflow-y: auto;
}

.category-table {
    width: 100%;
    border-collapse: collapse;
}

.category-table thead {
    background: var(--primary-brown);
    color: white;
    position: sticky;
    top: 0;
    z-index: 10;
}

/* Ensure table header cells use white text (override global table th color if needed) */
.category-table thead th {
    color: #ffffff !important;
}

.category-table th {
    padding: 12px 10px;
    text-align: left;
    font-weight: 600;
    font-size: 13px;
}

.category-table tbody tr {
    border-bottom: 1px solid #eee;
    transition: background 0.2s;
}

.category-table tbody tr:hover {
    background: #f8f9fa;
}

.category-table td {
    padding: 10px;
    font-size: 14px;
    vertical-align: middle;
}

.category-table .empty-message {
    text-align: center;
    padding: 40px 20px !important;
    color: #999;
}

.category-table .empty-message i {
    font-size: 36px;
    display: block;
    margin-bottom: 10px;
    color: #ddd;
}

.category-table .empty-message p {
    margin: 0;
}

/* Category Icon in Table */
.category-table .category-icon {
    width: 40px;
    height: 40px;
    background: #f0f0f0;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
}

/* Action Buttons in Modal Table */
.category-table .category-actions {
    display: flex;
    gap: 5px;
}

/* Ensure action buttons don't overlap sticky header */
.category-table .category-actions {
    position: relative;
    z-index: 1;
}

/* Totals row at bottom of table - sticky and visible when scrolling */
.category-table tbody tr.totals-row {
    position: sticky;
    bottom: 0;
    background: #ffffff;
    z-index: 9;
    font-weight: 700;
    border-top: 2px solid var(--border-color);
}

.category-table .btn-edit,
.category-table .btn-delete {
    width: 32px;
    height: 32px;
    padding: 0;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.category-table .btn-edit {
    background: #e3f2fd;
    color: #1976d2;
}

.category-table .btn-edit:hover {
    background: #bbdefb;
}

.category-table .btn-delete {
    background: #ffebee;
    color: #c62828;
}

.category-table .btn-delete:hover {
    background: #ffcdd2;
}

/* Responsive */
@media (max-width: 900px) {
    .categories-content {
        grid-template-columns: 1fr;
    }

    .category-form-section {
        position: static;
    }

    .category-form .form-row {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 600px) {
    .categories-header {
        flex-direction: column;
        gap: 15px;
        text-align: center;
    }

    .category-actions {
        flex-direction: column;
    }

    #categoryTable th:nth-child(4),
    #categoryTable td:nth-child(4) {
        display: none;
    }
}
