/* --- ADMIN MODERN BLACK & WHITE THEME --- */
@import url('https://fonts.googleapis.com/css2?family=Kanit:wght@400;500;700&display=swap');

/* ======================================= */
/* ======== 1. ROOT & UNIVERSAL STYLES ======== */
/* ======================================= */
:root {
    /* Color Palette */
    --bg-canvas: #000000;
    /* Pure black canvas for the body background */
    --bg-main: #121212;
    /* Near-black for main elements like cards and sidebars */
    --border-color: #2e2e2e;
    /* Subtle gray for borders and dividers */
    --text-primary: #FFFFFF;
    /* Pure white for high contrast text */
    --text-secondary: #b3b3b3;
    /* Light gray for secondary info, labels, and placeholders */
    --accent-primary: #007BFF;
    /* Vibrant blue for primary buttons, active states, and links */
    --accent-red: #FF4136;
    /* Vibrant red for delete and logout actions */

    /* Typography & Layout */
    --font-main: 'Kanit', sans-serif;
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
    --radius-md: 12px;
    --radius-lg: 16px;
}

body {
    margin: 0;
    font-family: var(--font-main);
    background-color: var(--bg-canvas);
    color: var(--text-primary);
}

a {
    text-decoration: none;
    color: inherit;
}

/* ============================== */
/* ======== 2. ADMIN LAYOUT ======== */
/* ============================== */
.admin-layout {
    display: grid;
    grid-template-columns: 260px 1fr;
    /* Fixed sidebar, flexible main content */
    min-height: 100vh;
}

/* ============================== */
/* ======== 3. ADMIN SIDEBAR ======== */
/* ============================== */
.sidebar {
    background-color: var(--bg-main);
    border-right: 1px solid var(--border-color);
    padding: 32px;
    position: sticky;
    top: 0;
    height: 100vh;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    /* Pushes bottom links (logout) down */
}

.sidebar-logo {
    font-size: 1.8em;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 40px;
}

.sidebar-logo span {
    color: var(--accent-primary);
}

.sidebar-nav h3 {
    font-size: 0.8em;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-secondary);
    margin: 0 0 16px 0;
}

.sidebar-nav ul {
    list-style: none;
    padding: 0;
    margin: 0 0 32px 0;
}

.sidebar-nav a {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px;
    border-radius: 8px;
    font-weight: 500;
    font-size: 1.05em;
    transition: all 0.2s;
}

.sidebar-nav a:hover {
    background-color: var(--border-color);
    color: var(--accent-primary);
}

.sidebar-nav a.active {
    background-color: var(--accent-primary);
    color: var(--text-primary);
    font-weight: 700;
}

.sidebar-nav a.logout-link {
    color: var(--accent-red);
}

.sidebar-nav a.logout-link:hover {
    background-color: rgba(255, 65, 54, 0.1);
}

/* ==================================== */
/* ======== 4. ADMIN MAIN CONTENT ======== */
/* ==================================== */
.admin-main {
    padding: 40px;
}

.desktop-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 40px;
}

.desktop-header h1 {
    font-size: 2.2em;
    font-weight: 700;
    margin: 0;
}

.button {
    padding: 10px 20px;
    border: none;
    border-radius: 8px;
    font-family: var(--font-main);
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 1em;
}

.button-primary {
    background-color: var(--accent-primary);
    color: var(--text-primary);
}

.button-primary:hover {
    filter: brightness(1.2);
}

.button-secondary {
    background-color: var(--bg-main);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
}

.button-secondary:hover {
    border-color: var(--accent-primary);
}

/* ====================================== */
/* ======== 5. ADMIN CARDS & FORMS ======== */
/* ====================================== */
.admin-card {
    background: var(--bg-main);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 32px;
    margin-bottom: 32px;
}

.admin-card h2 {
    margin-top: 0;
    font-size: 1.5em;
    font-weight: 700;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 16px;
    margin-bottom: 24px;
    color: #24bad9;
}

.form-section-header {
    margin-top: 60px;
    /* Increased margin for better visual separation between form sections */
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    /* Responsive grid for form inputs */
    gap: 22px;
}

.input-group label {
    display: block;
    font-weight: 600;
    margin-bottom: 8px;
    font-size: 0.9em;
}

.input-group input,
.input-group textarea,
.input-group select {
    width: 100%;
    padding: 12px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-family: var(--font-main);
    font-size: 1em;
    background-color: var(--bg-canvas);
    box-sizing: border-box;
    color: var(--text-primary);
}

.input-group input[type="file"] {
    padding: 8px;
}

.input-group input:focus,
.input-group textarea:focus,
.input-group select:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px rgba(0, 123, 255, 0.25);
    background-color: var(--bg-main);
}

.form-grid .full-width {
    grid-column: 1 / -1;
    /* Makes an element span the full width of the grid */
}

.form-actions {
    margin-top: 32px;
}

/* ==================================== */
/* ======== 6. PRODUCT LIST TABLE ======== */
/* ==================================== */
.product-table {
    width: 100%;
    border-collapse: collapse;
}

.product-table th,
.product-table td {
    text-align: left;
    padding: 16px;
    border-bottom: 1px solid var(--border-color);
    vertical-align: middle;
}

.product-table thead {
    color: var(--text-secondary);
    font-size: 0.9em;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.product-table tbody tr {
    transition: background-color 0.2s;
}

.product-table tbody tr:hover {
    background-color: #1a1a1a;
}

.product-table tbody tr:last-child td {
    border-bottom: none;
}

.product-info-cell {
    display: flex;
    align-items: center;
    gap: 16px;
}

.product-info-cell img {
    width: 60px;
    height: 60px;
    object-fit: cover;
    border-radius: var(--radius-md);
}

.product-info-cell .name {
    font-weight: 600;
    color: var(--text-primary);
}

.product-info-cell .details {
    font-size: 0.9em;
    color: var(--text-secondary);
}

/* Status badge colors - using light theme colors for better visibility and distinction */
.status-badge {
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 0.8em;
    font-weight: 600;
}

.status-badge.available {
    background-color: #D3F9D8;
    color: #2B8A3E;
}

.status-badge.preordered {
    background-color: #FFF3BF;
    color: #C59300;
}

.status-badge.sold {
    background-color: #FFF5F5;
    color: #FA5252;
}

.action-buttons a,
.action-buttons button {
    font-size: 0.9em;
    padding: 6px 12px;
    border-radius: 6px;
    margin-right: 8px;
    border: 1px solid transparent;
    background: none;
}

.action-buttons .edit-btn {
    background-color: rgba(0, 123, 255, 0.15);
    color: var(--accent-primary);
}

.action-buttons .delete-btn {
    background-color: rgba(255, 65, 54, 0.15);
    color: var(--accent-red);
}

/* ============================ */
/* ======== 7. LOGIN PAGE ======== */
/* ============================ */
.login-container {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    padding: 24px;
    box-sizing: border-box;
}

.login-form {
    width: 100%;
    max-width: 420px;
    background-color: var(--bg-main);
    padding: 40px;
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
}

.login-form h2 {
    text-align: center;
    margin-top: 0;
    margin-bottom: 32px;
    font-size: 1.8em;
    color: #24bad9;
}

.login-form .input-group {
    margin-bottom: 24px;
}

.login-form .button {
    width: 100%;
    padding: 14px;
    font-size: 1.1em;
    margin-top: 8px;
}

.login-form .home-link {
    text-align: center;
    margin-top: 24px;
    font-size: 0.9em;
}

.login-form .home-link a {
    color: var(--accent-primary);
    font-weight: 500;
}

/* =================================== */
/* ======== 8. RESPONSIVE ADMIN ======== */
/* =================================== */
.mobile-header {
    display: none;
    /* Hidden by default */
}

@media (max-width: 1024px) {

    /* Switch to a single-column layout on smaller screens */
    .admin-layout {
        grid-template-columns: 1fr;
    }

    /* Make sidebar a slide-out menu */
    .sidebar {
        position: fixed;
        left: -100%;
        top: 0;
        z-index: 200;
        height: 100%;
        transition: left 0.3s ease-in-out;
        box-shadow: 0 0 40px rgba(0, 0, 0, 0.1);
        width: 280px;
    }

    .sidebar.open {
        left: 0;
    }

    /* Hide desktop header and show mobile header */
    .desktop-header {
        display: none;
    }

    .mobile-header {
        display: flex;
        justify-content: space-between;
        align-items: center;
        margin-bottom: 24px;
        flex-direction: row-reverse; /* MODIFICATION: Swap logo and menu button */
    }

    .mobile-logo {
        font-size: 1.5em;
        font-weight: 700;
        color: var(--text-primary);
    }

    .mobile-logo span {
        color: var(--accent-primary);
    }

    .mobile-menu-button {
        display: flex; /* MODIFICATION: Use flex for alignment */
        align-items: center; /* MODIFICATION: Vertically align icon and text */
        gap: 8px; /* MODIFICATION: Space between icon and text */
        font-size: 1rem; /* MODIFICATION: Adjust font size */
        background: none;
        border: 1px solid var(--border-color); /* MODIFICATION: Add border */
        border-radius: 8px; /* MODIFICATION: Add border radius */
        cursor: pointer;
        padding: 8px 12px; /* MODIFICATION: Add padding */
        color: var(--text-primary);
    }

    .mobile-header-actions {
        display: flex;
        align-items: center;
        gap: 12px;
        /* MODIFICATION: The menu button is now the primary action on the left */
        flex-direction: row-reverse;
    }

    .mobile-add-btn {
        padding: 8px 14px;
        font-size: 0.9em;
    }

    .admin-main {
        padding: 24px;
    }

    /* Responsive Table: Convert table to a list of cards */
    .product-table {
        display: block;
    }

    .product-table thead {
        display: none;
    }

    .product-table tbody,
    .product-table tr,
    .product-table td {
        display: block;
        width: 100%;
        box-sizing: border-box;
    }

    .product-table tr {
        border: 1px solid var(--border-color);
        border-radius: var(--radius-lg);
        margin-bottom: 16px;
        padding: 16px;
        background-color: var(--bg-main);
    }

    .product-table td {
        padding: 12px 0;
        display: flex;
        justify-content: space-between;
        align-items: center;
        border: none;
        border-bottom: 1px solid var(--border-color);
    }

    .product-table tr td:last-child {
        border-bottom: none;
    }

    /* Use data-label attribute to create labels for each "cell" */
    .product-table td::before {
        content: attr(data-label);
        font-weight: 600;
        color: var(--text-secondary);
        margin-right: 16px;
    }

    .product-info-cell {
        flex-direction: row;
    }
}

/* ========================================= */
/* ======== 9. IMAGE UPLOAD PREVIEW ======== */
/* ========================================= */
.image-upload-area {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    border: 2px dashed var(--border-color);
    border-radius: var(--radius-md);
    padding: 32px;
    text-align: center;
    cursor: pointer;
    transition: border-color 0.2s, background-color 0.2s;
    background-color: var(--bg-canvas);
    min-height: 150px;
}

.image-upload-area:hover {
    border-color: var(--accent-primary);
    background-color: #1a1a1a;
}

.image-upload-area .upload-icon {
    color: var(--text-secondary);
    margin-bottom: 16px;
}

.image-upload-area .upload-main-text {
    font-weight: 600;
    color: var(--text-primary);
    font-size: 1.1em;
}

.image-upload-area .upload-sub-text {
    font-size: 0.9em;
    color: var(--text-secondary);
    margin-top: 4px;
}

.image-preview-container {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 16px;
    margin-top: 16px;
    padding: 16px;
    border: 1px dashed var(--border-color);
    border-radius: var(--radius-md);
    min-height: 100px;
    background-color: var(--bg-canvas);
}

.image-preview-item {
    position: relative;
    aspect-ratio: 1 / 1;
    border-radius: 8px;
    overflow: hidden;
    background-color: var(--border-color);
    cursor: grab;
}

.image-preview-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.image-preview-item .remove-btn {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 24px;
    height: 24px;
    background-color: rgba(0, 0, 0, 0.6);
    color: white;
    border: none;
    border-radius: 50%;
    font-size: 16px;
    line-height: 24px;
    text-align: center;
    cursor: pointer;
    opacity: 0;
    /* Hidden by default, appears on hover */
    transition: opacity 0.2s;
    z-index: 10;
}

.image-preview-item:hover .remove-btn {
    opacity: 1;
}

.image-preview-item .drag-handle {
    position: absolute;
    bottom: 4px;
    left: 4px;
    background-color: rgba(0, 0, 0, 0.6);
    color: white;
    border-radius: 4px;
    padding: 2px 6px;
    font-size: 14px;
    cursor: grab;
    z-index: 10;
}

.image-preview-container .sortable-ghost {
    background-color: var(--accent-primary);
    opacity: 0.4;
    border: 2px dashed white;
}

/* =================================== */
/* ======== 10. CROPPER MODAL ======== */
/* =================================== */
.crop-modal {
    display: none;
    /* Hidden by default, shown with JS */
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.8);
    justify-content: center;
    align-items: center;
}

.crop-modal-content {
    background-color: var(--bg-main);
    margin: auto;
    padding: 20px;
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
    width: 90%;
    max-width: 800px;
    box-shadow: 0 5px 25px rgba(0, 0, 0, 0.2);
}

.crop-image-container {
    width: 100%;
    max-height: 60vh;
    /* Limit height to prevent huge images from taking over the screen */
    margin-bottom: 20px;
}

.crop-image-container img {
    max-width: 100%;
}

.crop-modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
}