/* Modern Theme Variables */
:root {
    --primary: #4f46e5;
    --primary-hover: #4338ca;
    --danger: #ef4444;
    --success: #22c55e;
    --bg-body: #f8fafc;
    --bg-card: #ffffff;
    --text-main: #1e293b;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --radius: 12px;
    --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1);
}

* { 
    box-sizing: border-box; 
    margin: 0; 
    padding: 0; 
}

body { 
    font-family: 'Inter', system-ui, -apple-system, sans-serif; 
    background-color: var(--bg-body); 
    color: var(--text-main);
    padding: 20px;
    line-height: 1.5;
}

/* --- Polished Navigation Section --- */
.navbar {
    background-color: #1e293b;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1.5rem;
    margin-bottom: 2rem;
    border-radius: var(--radius);
    position: sticky;
    top: 0;
    z-index: 1000;
}

/* Style for the new logo */
.navbar-brand {
    display: flex;
    align-items: center;
    padding: 5px 0;
}

.nav-logo {
    height: 40px; /* Adjust this height to fit your navbar */
    width: auto;  /* Maintains aspect ratio */
    display: block;
}

.navbar-links {
    display: flex;
    list-style: none;
    align-items: center;
}

.navbar-links a {
    color: #94a3b8;
    text-decoration: none;
    padding: 0.6rem 1rem;
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 500;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 8px;
}

.navbar-links a:hover, 
.navbar-links a.active {
    background-color: rgba(255, 255, 255, 0.1);
    color: white;
}

.logout-link:hover {
    background-color: var(--danger) !important;
}

.nav-toggle { display: none; }
.nav-toggle-label {
    display: none;
    cursor: pointer;
    color: white;
    font-size: 1.5rem;
}

.dropdown { position: relative; }

.dropdown-content {
    display: none;
    position: absolute;
    background-color: #1e293b;
    min-width: 200px;
    box-shadow: 0px 8px 16px rgba(0,0,0,0.3);
    z-index: 1001;
    border-radius: 8px;
    top: 100%;
    left: 0;
    padding: 8px 0;
    border: 1px solid rgba(255,255,255,0.1);
}

.dropdown:hover .dropdown-content { display: block; }

.dropdown-content a {
    color: #94a3b8 !important;
    padding: 10px 20px !important;
    width: 100%;
}

/* Extra invisible bridge to prevent menu from closing when moving mouse down */
.dropdown::after {
    content: "";
    position: absolute;
    width: 100%;
    height: 20px;
    bottom: -20px;
    left: 0;
    display: none;
}

.dropdown:hover::after {
    display: block;
}

.dropdown-content a {
    color: #94a3b8 !important;
    padding: 10px 15px !important;
    display: flex !important;
    width: 100%;
    border-radius: 0; /* Keep it square inside the menu */
}

.dropdown-content a:hover {
    background-color: var(--primary) !important;
    color: white !important;
}

/* Layout Grid */
.main-layout {
    display: block; 
    width: 100%;
}

/* Capacity Card */
.capacity-card {
    background: white;
    padding: 20px;
    border-radius: var(--radius);
    margin-bottom: 24px;
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
}

/* Controls (Search/Sort/Add Button) */
.controls-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    gap: 15px;
    flex-wrap: wrap;
}

.search-box {
    position: relative;
    background: white;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 8px 12px;
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 250px;
}

input, select { 
    padding: 10px; 
    border: 1px solid var(--border); 
    border-radius: 8px; 
    font-size: 0.9rem;
    transition: border-color 0.2s;
}

input:focus, select:focus {
    outline: none;
    border-color: var(--primary);
}

.search-box input {
    border: none;
    outline: none;
    width: 100%;
}

.sidebar {
    display: none;
}

.table-container {
    background: white;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.table-header {
    padding: 15px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #f8fafc;
    border-bottom: 1px solid var(--border);
    color: var(--text-main);
}

.total-worth {
    margin-left: auto;
    background: var(--primary);
    color: white;
    padding: 8px 16px;
    border-radius: 8px;
    font-weight: 700;
    font-size: 0.85rem;
}

table {
    width: 100%;
    border-collapse: collapse;
    background: white;
}

table th{
    padding: 8px 12px !important; 
    border-bottom: 1px solid #f1f5f9;
    font-size: 0.85rem;
    line-height: 1.2;
}

table td {
    padding: 8px 12px !important; 
    border-bottom: 1px solid #f1f5f9;
    text-align: center;
    font-size: 0.85rem;
    line-height: 1.2;
}

th {
    background: #f8fafc;
    font-size: 0.75rem;
    text-transform: uppercase;
    color: var(--text-muted);
}

.low-stock { background-color: #fff1f2; }

.description-cell {
    font-size: 0.8rem;
    color: var(--text-muted);
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
}

.btn-blue { background: var(--primary); color: white; border: none; padding: 10px 20px; border-radius: 8px; cursor: pointer; font-weight: 600; }
.btn-red { background: var(--danger); color: white; border: none; padding: 10px 20px; border-radius: 8px; cursor: pointer; font-weight: 600; }

/* Modal Styling */
.modal {
    display: none; 
    position: fixed; 
    z-index: 2000; 
    left: 0; top: 0;
    width: 100%; height: 100%; 
    background-color: rgba(0,0,0,0.5); 
    backdrop-filter: blur(4px);
}

.modal-content {
    background-color: white;
    margin: 30px auto; 
    border-radius: 12px;
    width: 95%;
    max-width: 600px; /* Slightly wider for better desktop layout */
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
    overflow: hidden;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
}

.modal-body {
    padding: 24px;
    overflow-y: auto; 
    flex: 1;
}

/* Modal Grid Logic */
.modal-grid {
    display: grid;
    grid-template-columns: 1fr 1fr; /* 2 columns on desktop */
    gap: 20px;
}

/* Form Element Styling */
.modal-body label {
    display: block;
    font-size: 0.85rem;
    font-weight: 600;
    color: #475569;
    margin-bottom: 6px;
    text-align: left;
}

.modal-body input, 
.modal-body select {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    font-size: 0.95rem;
    background-color: #fff;
    transition: all 0.2s;
}

.modal-body input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(30, 41, 59, 0.1);
    outline: none;
}

/* Utility for items that should always be wide */
.full-width {
    grid-column: span 2;
}

@keyframes slideDown {
    from { transform: translateY(-30px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

.modal-header { background: #1e293b; color: white; padding: 15px 20px; font-weight: 700; }
.modal-footer { padding: 15px 20px; border-top: 1px solid var(--border); display: flex; gap: 10px; justify-content: flex-end; }
.readonly-input { background-color: #f1f5f9; cursor: not-allowed; }

/* Badge Styles */
.badge {
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: bold;
    color: white;
    display: inline-block;
}

.badge-create { background-color: var(--success); }
.badge-edit   { background-color: var(--primary); }
.badge-delete { background-color: var(--danger); }
.badge-stock  { background-color: #f59e0b; }

/* Image Zoom */
.zoomable-img {
    width: 45px;
    height: 45px;
    object-fit: cover;
    border-radius: 4px;
    cursor: zoom-in;
    transition: transform 0.2s;
}

.zoomable-img:hover { transform: scale(1.1); }

.image-zoom-overlay {
    display: none; 
    position: fixed; 
    z-index: 2000; 
    padding-top: 50px; 
    left: 0; top: 0;
    width: 100%; height: 100%; 
    background-color: rgba(0,0,0,0.9); 
    cursor: zoom-out;
}

.zoom-content {
    margin: auto;
    display: block;
    max-width: 80%;
    max-height: 80vh;
    border-radius: 8px;
    box-shadow: 0 0 20px rgba(0,0,0,0.5);
    animation: zoomAnim 0.3s ease;
}

@keyframes zoomAnim {
    from {transform: scale(0)} 
    to {transform: scale(1)}
}

.close-zoom {
    position: absolute;
    top: 20px;
    right: 35px;
    color: #f1f1f1;
    font-size: 40px;
    font-weight: bold;
    cursor: pointer;
}

/* --- Consolidated Media Queries --- */

@media screen and (max-width: 1024px) {
    .navbar { flex-wrap: wrap; }
    .nav-toggle-label { display: block; }

    /* Vertical Mobile Menu Style */
    .navbar-links {
        display: none; 
        flex-direction: column;
        width: calc(100% + 3rem); 
        margin: 0.75rem -1.5rem -0.75rem -1.5rem; 
        background-color: #1e293b;
        border-top: 1px solid rgba(255,255,255,0.1);
    }

    .nav-toggle:checked ~ .navbar-links { display: flex; }
    .navbar-links li { width: 100%; border-bottom: 1px solid rgba(255,255,255,0.05); }
    .navbar-links a { padding: 15px 20px; border-radius: 0; }

    /* Indented Mobile Dropdowns */
.dropdown-content {
        /* This is the magic fix */
        position: static; 
        display: none; 
        
        /* Visual adjustments for mobile */
        width: 100%;
        background-color: #0f172a; /* Darker background to show it's nested */
        box-shadow: none;         /* Remove desktop shadows */
        border: none;             /* Remove desktop borders */
        padding: 0;
        opacity: 1;               /* Ensure it's visible */
        transform: none;          /* Disable desktop animations */
    }
    /* When the menu is toggled open via JS */
    .dropdown.show-mobile .dropdown-content {
        display: block;
    }

    /* Indent the sub-items so they look nested */
    .dropdown-content a {
        padding-left: 45px !important; 
        font-size: 0.85rem;
        border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    }
}

/* --- 600px: Compact Table Fix --- */
@media screen and (max-width: 600px) {
    .nav-logo {
        height: 30px; /* Slightly smaller on phones */
    }
    body { padding: 10px; }
    input { width: 300px;;
    }
    

.table-area, .table-container {
        overflow-x: auto; /* Enables the swipe gesture */
        display: block;
        width: 100%;
        -webkit-overflow-scrolling: touch;
        position: relative;
    }

    table {
        border-collapse: separate; /* Required for sticky borders to look right */
        border-spacing: 0;
        width: 100%;
        min-width: 400px; /* Forces enough width to allow swiping */
    }

    /* The "Legend" (First Column) */
    th:first-child, 
    td:first-child {
        position: sticky;
        left: 0;
        background-color: white !important; /* Must be solid to hide text scrolling behind it */
        z-index: 10;
        border-right: 2px solid #e2e8f0; /* Visual "split" line */
        box-shadow: 2px 0 5px rgba(0,0,0,0.05);
    }

    /* Header for the sticky column needs to stay on top */
    th:first-child {
        z-index: 11;
        background-color: #f8fafc !important; /* Match your header color */
    }

    /* Shrink the cells to make it "Collapsed" and compact */
    th, td {
        padding: 8px 10px !important;
        font-size: 0.75rem !important;
    }

    .nav-logo {
        height: 30px; /* Slightly smaller on phones */
    }

    .table-header { flex-direction: column; align-items: stretch; gap: 10px; }
    .controls-row { flex-direction: column; gap: 10px; }
    .btn-blue, .btn-red { width: 100%; }
    
}

@media screen and (max-width: 480px) {
    .navbar-brand { font-size: 1rem; }
    
    /* Make buttons full-width for thumbs */
    .btn-blue, .btn-red, .modal-footer button {
        width: 100%;
        margin-top: 5px;
    }
}