:root {
    --bg-primary: #0f172a;
    --bg-secondary: #1e293b;
    --card-bg: #1e1b4b;
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --accent: #6366f1;
    --accent-hover: #818cf8;
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --border: rgba(255, 255, 255, 0.1);
    --info: #3b82f6;
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --card-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.5);
}

/* Auth System Styles */
.login-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: radial-gradient(circle at top left, #1e293b, #0f172a);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 10000;
}

.login-overlay.active {
    display: flex;
}

.login-card {
    background: rgba(30, 41, 59, 0.7);
    backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    padding: 48px;
    border-radius: 32px;
    width: 100%;
    max-width: 440px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    text-align: center;
}

.login-card .logo-icon {
    width: 60px;
    height: 60px;
    font-size: 1.5rem;
    margin: 0 auto 24px;
}

.login-card h2 {
    font-size: 2rem;
    margin-bottom: 8px;
    color: white;
}

.login-card p {
    color: var(--text-secondary);
    margin-bottom: 32px;
}

.login-form .form-group {
    text-align: left;
    margin-bottom: 20px;
}

.login-form input {
    width: 100%;
    padding: 14px;
    background: rgba(15, 23, 42, 0.5);
    border: 1px solid var(--border);
    border-radius: 12px;
    color: white;
    font-size: 1rem;
    transition: all 0.3s;
}

.login-form input:focus {
    border-color: var(--accent);
    outline: none;
    background: rgba(15, 23, 42, 0.8);
}

.login-btn {
    width: 100%;
    padding: 16px;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: 12px;
    font-weight: 700;
    font-size: 1rem;
    cursor: pointer;
    margin-top: 12px;
    transition: transform 0.2s, background 0.3s;
}

.login-btn:hover {
    background: var(--accent-hover);
    transform: translateY(-2px);
}

/* Role Visibility Control */
.employee-restricted {
    display: none !important;
}

body.user-emp .admin-only {
    display: none !important;
}

body.user-emp .edit-btn, 
body.user-emp .delete-btn {
    display: none !important;
}

body.user-emp .import-actions,
body.user-emp .settings-nav,
body.user-emp .add-btn-main {
    display: none !important;
}

body.light-mode {
    --bg-primary: #f8fafc;
    --bg-secondary: #f1f5f9;
    --card-bg: #ffffff;
    --text-primary: #0f172a;
    --text-secondary: #64748b;
    --accent: #4f46e5;
    --accent-hover: #4338ca;
    --success: #059669;
    --warning: #d97706;
    --danger: #dc2626;
    --info: #2563eb;
    --border: #e2e8f0;
    --shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06);
    --card-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Inter', sans-serif;
}

body {
    background-color: var(--bg-primary);
    color: var(--text-primary);
    overflow-x: hidden;
    transition: background-color 0.3s ease, color 0.3s ease;
}

h1,
h2,
h3,
.logo-text h1 {
    font-family: 'Outfit', sans-serif;
    font-weight: 700;
}

.app-container {
    display: flex;
    min-height: 100vh;
}

/* Sidebar */
.sidebar {
    width: 280px;
    background-color: var(--bg-secondary);
    border-right: 1px solid var(--border);
    padding: 32px 20px;
    display: flex;
    flex-direction: column;
    position: fixed;
    height: 100vh;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    color: var(--text-secondary);
    text-decoration: none;
    border-radius: 12px;
    margin-bottom: 4px;
    transition: all 0.2s ease;
    cursor: pointer;
}

body.light-mode .sidebar {
    background-color: #ffffff;
}

.logo-section {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 48px;
}

.logo-icon {
    width: 40px;
    height: 40px;
    background: linear-gradient(135deg, var(--accent) 0%, #4f46e5 100%);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    color: white;
    box-shadow: 0 4px 12px var(--accent-glow);
}

.logo-text h1 {
    font-size: 1.25rem;
    letter-spacing: 0.5px;
}

.logo-text span {
    font-size: 0.75rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.nav-menu {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    color: var(--text-secondary);
    text-decoration: none;
    border-radius: 12px;
    transition: var(--transition);
}

.nav-item i {
    width: 20px;
}

.nav-item:hover {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-primary);
}

.nav-item.active {
    background: rgba(99, 102, 241, 0.1);
    color: var(--accent);
}

.sidebar-footer {
    padding-top: 24px;
    border-top: 1px solid var(--border);
}

.user-profile {
    display: flex;
    align-items: center;
    gap: 12px;
}

.avatar {
    width: 36px;
    height: 36px;
    background: #334155;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.875rem;
    font-weight: 600;
}

.user-info .name {
    font-size: 0.875rem;
    font-weight: 600;
}

.user-info .role {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

/* Main Content */
.main-content {
    margin-left: 260px;
    flex: 1;
    padding: 32px;
}

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

.header-search {
    position: relative;
    width: 400px;
}

.header-search i {
    position: absolute;
    left: 16px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-secondary);
    width: 18px;
}

input[type="text"],
input[type="date"],
select,
textarea {
    width: 100%;
    height: 48px;
    /* Fixed height for absolute parity */
    padding: 0 16px;
    background: linear-gradient(to bottom, #f1f5f9, #e2e8f0);
    border: 1px solid #cbd5e1;
    border-radius: 12px;
    color: #475569;
    font-size: 0.95rem;
    transition: all 0.2s ease;
    box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.05);
    box-sizing: border-box;
    display: flex;
    align-items: center;
    line-height: normal;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
}

textarea {
    height: auto;
    min-height: 100px;
    padding: 12px 16px;
}

/* Fix for Date inputs specifically */
input[type="date"]::-webkit-calendar-picker-indicator {
    filter: invert(0.5);
    cursor: pointer;
}

select {
    padding-right: 32px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23475569' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
}

body.light-mode input[type="text"],
body.light-mode input[type="date"],
body.light-mode select,
body.light-mode textarea {
    background: linear-gradient(to bottom, #ffffff, #f1f5f9);
    background-repeat: no-repeat;
    background-position: right 12px center;
    border-color: #cbd5e1;
    color: #0f172a;
}

.header-search input {
    width: 100%;
    background: var(--card-bg);
    border: 1px solid var(--border);
    padding: 12px 16px 12px 48px;
    border-radius: 12px;
    color: var(--text-primary);
    outline: none;
    transition: var(--transition);
}

.header-search input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 20px;
}

.status-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.pulse {
    width: 8px;
    height: 8px;
    background: var(--success);
    border-radius: 50%;
    box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.4);
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% {
        transform: scale(0.95);
        box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7);
    }

    70% {
        transform: scale(1);
        box-shadow: 0 0 0 10px rgba(16, 185, 129, 0);
    }

    100% {
        transform: scale(0.95);
        box-shadow: 0 0 0 0 rgba(16, 185, 129, 0);
    }
}

/* Stats Cards */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 24px;
    margin-bottom: 32px;
}

.stat-card {
    background: var(--card-bg);
    padding: 24px;
    border-radius: 20px;
    border: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 20px;
    transition: var(--transition);
}

.stat-card:hover {
    transform: translateY(-5px);
    border-color: rgba(255, 255, 255, 0.1);
}

.stat-icon {
    width: 56px;
    height: 56px;
    border-radius: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.stat-icon.pending {
    background: rgba(245, 158, 11, 0.1);
    color: var(--warning);
}

.stat-icon.ready {
    background: rgba(16, 185, 129, 0.1);
    color: var(--success);
}

.stat-icon.approved {
    background: rgba(59, 130, 246, 0.1);
    color: var(--info);
}

.stat-icon.total {
    background: rgba(99, 102, 241, 0.1);
    color: var(--accent);
}

.stat-icon.waiting {
    background: rgba(236, 72, 153, 0.1);
    color: #ec4899;
}

.stat-icon.orders {
    background: rgba(16, 185, 129, 0.1);
    color: #10b981;
}

.stat-icon.rejected {
    background: rgba(239, 68, 68, 0.1);
    color: var(--danger);
}

.stat-data h3 {
    font-size: 1.75rem;
    margin-bottom: 4px;
}

.stat-data p {
    color: var(--text-secondary);
    font-size: 0.875rem;
}

/* Content Layout */
.content-grid {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 24px;
}

.table-container,
.summary-card {
    background: var(--card-bg);
    border-radius: 20px;
    border: 1px solid var(--border);
    padding: 24px;
}

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

.container-header h2 {
    font-size: 1.25rem;
}

.table-scroll {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
}

thead th {
    text-align: left;
    padding: 12px 16px;
    color: var(--text-secondary);
    font-weight: 500;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    border-bottom: 1px solid var(--border);
}

tbody td {
    padding: 16px;
    font-size: 0.875rem;
    border-bottom: 1px solid var(--border);
}

.status-badge,
.status-badge-select {
    padding: 6px 12px;
    border-radius: 99px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    display: inline-block;
    border: 1px solid transparent;
}

.cmr-link {
    color: var(--accent);
    text-decoration: none;
    font-weight: 700;
    cursor: pointer;
    border-bottom: 1px dashed transparent;
    transition: all 0.2s ease;
}

.cmr-link:hover {
    color: var(--accent-hover);
    border-bottom-color: var(--accent-hover);
    filter: brightness(1.2);
}

.status-badge-select {
    height: 32px;
    padding: 0 28px 0 12px;
    background: var(--bg-secondary);
    color: var(--text-primary);
    cursor: pointer;
    border: 1px solid var(--border);
    border-radius: 99px;
    font-size: 0.75rem;
    font-weight: 600;
    -webkit-appearance: menulist;
    /* Restoration of standard picker UI */
    appearance: menulist;
}

/* Toast & Warning System */
#toast-container {
    position: fixed;
    top: 24px;
    right: 24px;
    z-index: 9999;
}

.toast {
    background: rgba(239, 68, 68, 0.1);
    backdrop-filter: blur(12px);
    border: 1px solid var(--danger);
    color: var(--danger);
    padding: 16px 24px;
    border-radius: 12px;
    font-weight: 600;
    font-size: 0.9rem;
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    animation: slideIn 0.3s ease forwards;
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
    max-width: 320px;
}

@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }

    to {
        transform: translateX(0);
        opacity: 1;
    }
}

.input-warn {
    border-color: var(--danger) !important;
    background: rgba(239, 68, 68, 0.1) !important;
    box-shadow: 0 0 0 4px rgba(239, 68, 68, 0.1) !important;
}

/* Polishing Cards and Tables */
.table-container {
    background: var(--card-bg);
    border-radius: 20px;
    border: 1px solid var(--border);
    padding: 24px;
    box-shadow: var(--card-shadow);
    transition: transform 0.2s ease;
}

.table-container:hover {
    transform: translateY(-2px);
}

/* Spec Sheet (Detail View) */
.spec-sheet {
    padding: 24px;
    background: var(--bg-secondary);
    border-radius: 16px;
    border: 1px solid var(--border);
}

.spec-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 2px solid var(--border);
    padding-bottom: 20px;
    margin-bottom: 24px;
}

.spec-header h2 {
    font-size: 1.5rem;
    color: var(--accent);
}

.spec-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 32px;
}

.spec-section h4 {
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-secondary);
    margin-bottom: 16px;
    border-bottom: 1px solid var(--border);
    padding-bottom: 8px;
}

.spec-section p {
    font-size: 0.95rem;
    margin-bottom: 12px;
    display: flex;
    justify-content: space-between;
    color: var(--text-primary);
}

.spec-section p strong {
    color: var(--text-secondary);
    font-weight: 500;
}

.status-badge-select.ready {
    background-color: rgba(16, 185, 129, 0.15);
    color: #10b981;
    border: 1px solid rgba(16, 185, 129, 0.2);
}

.status-badge-select.pending {
    background-color: rgba(99, 102, 241, 0.15);
    color: #818cf8;
    border: 1px solid rgba(99, 102, 241, 0.2);
}

.status-badge-select.rejected {
    background-color: rgba(244, 63, 94, 0.15);
    color: #f43f5e;
    border: 1px solid rgba(244, 63, 94, 0.2);
}

.status-badge.ready {
    background: rgba(16, 185, 129, 0.1);
    color: var(--success);
}

.status-badge.pending {
    background: rgba(245, 158, 11, 0.1);
    color: var(--warning);
}

.status-badge.rejected {
    background: rgba(239, 68, 68, 0.1);
    color: var(--danger);
}

.status-badge.default {
    background: rgba(148, 163, 184, 0.1);
    color: var(--text-secondary);
}

/* Analysis Card */
.summary-list {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.analysis-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px;
    background: rgba(255, 255, 255, 0.02);
    border-radius: 12px;
}

.config-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-height: 400px;
    overflow-y: auto;
    padding-right: 8px;
}

.config-list .analysis-item {
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--border);
}

.config-list .analysis-item:hover {
    background: rgba(255, 255, 255, 0.08);
}

.header-actions input[type="text"] {
    background: var(--bg-primary);
    border: 1px solid var(--border);
    padding: 8px 12px;
    border-radius: 8px;
    color: var(--text-primary);
    width: 150px;
}

.analysis-name {
    display: flex;
    align-items: center;
    gap: 12px;
}

.analysis-avatar {
    width: 32px;
    height: 32px;
    background: var(--accent);
    color: white;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    font-weight: 700;
}

.analysis-score {
    text-align: right;
}

.analysis-score span {
    display: block;
    font-size: 0.875rem;
    font-weight: 600;
}

.analysis-score small {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(4px);
    z-index: 1000;
    align-items: center;
    justify-content: center;
}

.modal.active {
    display: flex;
}

.modal-content {
    background: var(--card-bg);
    width: 95%;
    max-width: 900px;
    border-radius: 24px;
    border: 1px solid var(--border);
    padding: 32px;
    max-height: 95vh;
    overflow-y: auto;
}

.form-section {
    margin-bottom: 32px;
    padding-bottom: 24px;
    border-bottom: 1px solid var(--border);
}

.form-section:last-of-type {
    border-bottom: none;
    margin-bottom: 0;
}

.section-title {
    font-family: 'Outfit', sans-serif;
    font-size: 1rem;
    color: var(--accent);
    margin-bottom: 20px;
    text-transform: uppercase;
    letter-spacing: 1px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.section-title::after {
    content: '';
    flex: 1;
    height: 1px;
    background: linear-gradient(to right, var(--accent), transparent);
}

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

.modal-header button {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
}

.form-row {
    display: flex;
    gap: 20px;
    margin-bottom: 20px;
}

.form-group {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.form-group.full {
    width: 100%;
}

label {
    font-size: 0.8125rem;
    color: var(--text-secondary);
    font-weight: 500;
}

input,
select,
textarea {
    background: var(--bg-primary);
    border: 1px solid var(--border);
    padding: 10px 14px;
    border-radius: 10px;
    color: var(--text-primary);
    outline: none;
    width: 100%;
}

input:focus,
select:focus,
textarea:focus {
    border-color: var(--accent);
}

.form-actions {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    margin-top: 32px;
}

.btn {
    padding: 10px 20px;
    border-radius: 10px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: var(--transition);
    border: none;
}

.btn-primary {
    background: var(--accent);
    color: white;
}

.btn-primary:hover {
    transform: scale(1.02);
    box-shadow: 0 4px 15px var(--accent-glow);
}

.btn-secondary {
    background: #334155;
    color: white;
}

.view-section {
    display: none;
}

.view-section.active {
    display: block;
}

/* Animations */
@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.stat-card,
.table-container,
.summary-card {
    animation: slideUp 0.5s ease forwards;
}