:root {
    --sidebar-width: 260px;
    --background-color: #f4f7fa;
    --sidebar-bg: #1e293b;
    --sidebar-text: #cbd5e1;
    --sidebar-active-bg: #334155;
    --sidebar-active-text: #ffffff;
    --card-bg: #ffffff;
    --text-color: #334155;
    --heading-color: #0f172a;
    --border-color: #e2e8f0;
    --primary-color: #3b82f6;
    --primary-hover-color: #2563eb;
    --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --border-radius: 0.75rem; /* 12px */
    --transition: all 0.2s ease-in-out;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--background-color);
    color: var(--text-color);
}

/* Authenticated App Layout */
.app-layout {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

h1, h2, h3, h4, h5, h6 {
    color: var(--heading-color);
    margin-bottom: 1rem;
}

h1 {
    flex-shrink: 0; /* Prevent h1 from shrinking */
}

a {
    color: var(--primary-color);
    text-decoration: none;
}

/* --- Sidebar --- */
.sidebar {
    width: var(--sidebar-width);
    height: 100vh;
    position: fixed;
    left: 0;
    top: 0;
    background-color: var(--sidebar-bg);
    color: var(--sidebar-text);
    display: flex;
    flex-direction: column;
    padding: 1.5rem 1rem;
}

.sidebar-brand {
    font-size: 1.5rem;
    font-weight: 700;
    color: #fff;
    text-align: center;
    margin-bottom: 2rem;
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.sidebar-nav a {
    color: var(--sidebar-text);
    padding: 0.75rem 1rem;
    border-radius: 0.5rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-weight: 500;
    transition: var(--transition);
}

.sidebar-nav a:hover {
    background-color: var(--sidebar-active-bg);
    color: var(--sidebar-active-text);
}

.sidebar-nav a.active {
    background-color: var(--primary-color);
    color: #fff;
    font-weight: 600;
}

.sidebar-footer {
    margin-top: auto;
    padding-top: 1rem;
    border-top: 1px solid var(--sidebar-active-bg);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.user-info .user-name {
    font-weight: 600;
    color: #fff;
}
.user-info .user-role {
    font-size: 0.8rem;
    color: var(--sidebar-text);
}

.logout-button {
    font-size: 1.5rem;
    padding: 0.5rem;
    border-radius: 0.5rem;
    transition: var(--transition);
}
.logout-button:hover {
    background-color: var(--sidebar-active-bg);
}

/* --- Main Content --- */
.main-content {
    width: 100%;
    padding: 2rem;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.main-header {
    display: none; /* Hidden on desktop */
    align-items: center;
    gap: 1rem;
    margin-bottom: 1.5rem;
    flex-shrink: 0;
}

.mobile-menu-btn {
    background: none;
    border: none;
    color: var(--heading-color);
    cursor: pointer;
    padding: 0.5rem;
    margin-left: -0.5rem;
    display: flex;
    align-items: center;
}

.app-layout .main-content {
    margin-left: var(--sidebar-width);
    width: calc(100% - var(--sidebar-width));
}

.container {
    width: 100%;
    max-width: 1600px;
    margin: 0 auto;
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    overflow-y: auto; /* Default scroll behavior for pages that need it */
}

/* --- Card / Bento Box --- */
.card {
    background-color: var(--card-bg);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    padding: 1.5rem;
    border: 1px solid var(--border-color);
}

/* --- Grid for Bento Layout --- */
.bento-grid {
    display: grid;
    gap: 1.5rem;
    /* Example grid, customize per page */
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
}

/* --- Forms --- */
form {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.form-group label {
    font-weight: 600;
    color: var(--heading-color);
}

input[type="text"],
input[type="password"],
input[type="number"],
input[type="email"],
input[type="date"],
select,
textarea {
    width: 100%;
    padding: 0.75rem 1rem;
    border: 1px solid var(--border-color);
    border-radius: 0.5rem;
    font-size: 1rem;
    font-family: 'Inter', sans-serif;
    transition: var(--transition);
    background-color: var(--card-bg); /* Ensure background for icon visibility */
    -webkit-appearance: none; /* Remove default appearance on webkit */
    -moz-appearance: none;
    appearance: none;
}

select {
    background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="%2364748b" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="6 9 12 15 18 9"></polyline></svg>');
    background-repeat: no-repeat;
    background-position: right 0.75rem center;
    background-size: 1em;
    padding-right: 2.5rem; /* Make space for the arrow */
}

textarea {
    resize: vertical;
    min-height: 80px;
}

/* Custom calendar icon for Webkit browsers (Chrome, Safari, Edge) */
input[type="date"]::-webkit-calendar-picker-indicator {
    background: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="%2364748b" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="4" width="18" height="18" rx="2" ry="2"></rect><line x1="16" y1="2" x2="16" y2="6"></line><line x1="8" y1="2" x2="8" y2="6"></line><line x1="3" y1="10" x2="21" y2="10"></line></svg>') no-repeat;
    background-position: 97% 50%;
    cursor: pointer;
    opacity: 0.6;
    transition: opacity 0.2s;
}

input[type="date"]::-webkit-calendar-picker-indicator:hover {
    opacity: 1;
}

input:focus, select:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.4);
}

.btn {
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: 0.5rem;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.btn-primary {
    background-color: var(--primary-color);
    color: #fff;
}

.btn-primary:hover {
    background-color: var(--primary-hover-color);
}

.btn-secondary {
    background-color: var(--border-color);
    color: var(--text-color);
}
.btn-secondary:hover {
    background-color: #d1d5db;
}

/* --- Tables --- */
.table-wrapper {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 1rem;
}

table th, table td {
    padding: 0.75rem 1rem;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

table th {
    font-weight: 600;
    background-color: #f8fafc;
    color: var(--heading-color);
}

table tr:last-child td {
    border-bottom: none;
}

table tr:hover {
    background-color: #f8fafc;
}

/* --- Alerts --- */
.alerts {
    margin-bottom: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.alert {
    padding: 1rem 1.5rem;
    border-radius: 0.5rem;
    border: 1px solid transparent;
}

.alert-success {
    background-color: #dcfce7;
    border-color: #4ade80;
    color: #15803d;
}

.alert-danger {
    background-color: #fee2e2;
    border-color: #f87171;
    color: #b91c1c;
}

.alert-info {
    background-color: #e0f2fe;
    border-color: #7dd3fc;
    color: #0369a1;
}

/* --- Warehouse Page Layout --- */
.warehouse-layout {
    display: flex;
    flex-direction: column;
    height: 100%;
    gap: 1.5rem;
}

.warehouse-layout .card-full-height {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden; /* Important for child scrolling */
}

.warehouse-layout .card-full-height .table-wrapper {
    flex-grow: 1;
    overflow-y: auto; /* Scroll only inside the table wrapper */
}


/* --- Auth Page (Login) --- */
.auth-page-wrapper {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100%; /* Changed from min-height to work with new html/body height */
    padding: 2rem;
}

.auth-page-wrapper .card {
    width: 100%;
    max-width: 450px;
}

/* Special styles for the login page to ensure it fits the viewport without scrolling */
html:has(#login-form) {
    height: 100%;
}
body:has(#login-form) {
    height: 100%;
    overflow: hidden; /* Prevents scrollbar on the body */
}

/* --- Dashboard Specific --- */
.metric-value {
    font-size: 2.5rem;
    font-weight: 700;
    color: var(--heading-color);
    margin-top: 0.5rem;
}

.metric-value.low-stock {
    color: #ef4444; /* red-500 */
}

.metric-card-action {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

.metric-card-action .metric-body {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
}

.metric-card-action .metric-value {
    margin-top: 0;
}

.metric-card-action .metric-action-btn {
    align-self: flex-start;
}

.actions-container {
    margin-top: 1rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.card-large {
    grid-column: 1 / -1; /* Span full width by default */
}

/* --- Status Badges --- */
.status-badge-sm {
    display: inline-block;
    padding: 0.25rem 0.6rem;
    border-radius: 999px; /* pill shape */
    font-size: 0.75rem; /* 12px */
    font-weight: 600;
    text-align: center;
    cursor: help; /* Indicate that there's a tooltip */
    white-space: nowrap;
}

.status-ok {
    background-color: #dcfce7; /* green-100 */
    color: #166534; /* green-800 */
}

.status-low {
    background-color: #fef9c3; /* yellow-100 */
    color: #854d0e; /* yellow-800 */
}

.status-critical {
    background-color: #fee2e2; /* red-100 */
    color: #991b1b; /* red-800 */
}

/* --- Modal --- */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(30, 41, 59, 0.5); /* sidebar-bg with alpha */
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    backdrop-filter: blur(4px);
}
.sidebar-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(30, 41, 59, 0.5);
    z-index: 1090; /* Below sidebar, above content */
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}
.sidebar-backdrop.active {
    opacity: 1;
    visibility: visible;
}

.modal-overlay.active {
    display: flex;
}
.modal-container {
    background: var(--card-bg);
    border-radius: var(--border-radius);
    width: 90%;
    max-width: 900px;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow);
    z-index: 1100; /* Above backdrop */
}
.modal-header {
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.modal-header h2 { margin: 0; }
.modal-close-btn { background: none; border: none; font-size: 1.5rem; cursor: pointer; color: var(--text-color); }
.modal-body { padding: 0; overflow-y: auto; }

/* --- Responsive --- */
@media (max-width: 768px) {
    .app-layout {
        --sidebar-width: 0;
    }
    .sidebar {
        transform: translateX(-100%);
        transition: transform 0.3s ease-in-out;
        z-index: 1100; /* Above backdrop */
        box-shadow: 0 0 20px rgba(0,0,0,0.2);
    }
    .sidebar.sidebar-open {
        transform: translateX(0);
    }
    .app-layout .main-content {
        margin-left: 0;
        width: 100%;
        padding: 1rem;
    }
    .container {
        overflow-y: auto; /* Re-enable scroll on mobile for container */
    }
    .main-header {
        display: flex;
    }
}

@media (min-width: 1024px) {
    .bento-grid .card-large {
        grid-column: span 2; /* On large screens, table spans 2 columns */
    }
}

/* --- Create Issue Page Specific --- */
.search-container {
    position: relative;
}

.search-results-list {
    position: absolute;
    width: 100%;
    border: 1px solid var(--border-color);
    background-color: var(--card-bg);
    border-radius: 0.5rem;
    max-height: 250px;
    overflow-y: auto;
    z-index: 1000;
    box-shadow: var(--shadow);
    margin-top: 0.25rem;
    display: none; /* Hidden by default */
}

.search-result-item {
    padding: 0.75rem 1rem;
    cursor: pointer;
    border-bottom: 1px solid var(--border-color);
}

.search-result-item:last-child {
    border-bottom: none;
}

.search-result-item:hover {
    background-color: #f8fafc;
}

.btn-danger {
    background-color: #ef4444;
    color: #fff;
}
.btn-danger:hover {
    background-color: #dc2626;
}

/* --- Toggle Switch --- */
.toggle-switch-container {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}
.toggle-switch {
    position: relative;
    display: inline-block;
    width: 50px;
    height: 28px;
    background-color: #ccc;
    border-radius: 28px;
    transition: var(--transition);
    cursor: pointer;
}
.toggle-switch::before {
    content: '';
    position: absolute;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background-color: white;
    top: 4px;
    left: 4px;
    transition: var(--transition);
}
.toggle-switch:checked {
    background-color: var(--primary-color);
}
.toggle-switch:checked::before {
    transform: translateX(22px);
}
/* Hide the actual checkbox */
input.toggle-switch {
    appearance: none;
    -webkit-appearance: none;
    outline: none;
}
.search-result-item-none {
    padding: 0.75rem 1rem;
    color: #94a3b8; /* cool-gray-400 */
    font-style: italic;
}