:root {
    /* Color Palette */
    --bg-dark: #09090b;
    --bg-panel: #18181b;
    --bg-card: rgba(39, 39, 42, 0.4);
    
    --primary: #3b82f6;
    --primary-hover: #2563eb;
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    
    --border-color: rgba(255, 255, 255, 0.1);
    
    /* Layout Variables */
    --sidebar-width: 260px;
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    
    /* Effects */
    --glass-blur: blur(12px);
    --shadow-subtle: 0 4px 20px rgba(0, 0, 0, 0.4);
    --shadow-glow: 0 0 20px rgba(59, 130, 246, 0.3);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-dark);
    color: var(--text-main);
    overflow: hidden;
    background-image: 
        radial-gradient(circle at 15% 50%, rgba(59, 130, 246, 0.05), transparent 25%),
        radial-gradient(circle at 85% 30%, rgba(16, 185, 129, 0.05), transparent 25%);
}

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

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    background-color: var(--bg-panel);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    padding: 24px;
    z-index: 10;
}

.logo {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 24px;
    font-weight: 700;
    margin-bottom: 40px;
    color: var(--text-main);
}

.logo i {
    color: var(--primary);
    font-size: 28px;
}

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

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    color: var(--text-muted);
    text-decoration: none;
    border-radius: var(--radius-md);
    transition: all 0.3s ease;
    font-weight: 500;
}

.nav-item i {
    font-size: 20px;
}

.nav-item:hover, .nav-item.active {
    background: rgba(59, 130, 246, 0.1);
    color: var(--primary);
}

.nav-item.active {
    position: relative;
}
.nav-item.active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 4px;
    height: 20px;
    background: var(--primary);
    border-radius: 0 4px 4px 0;
    box-shadow: var(--shadow-glow);
}

.user-profile {
    display: flex;
    align-items: center;
    gap: 12px;
    padding-top: 24px;
    border-top: 1px solid var(--border-color);
}

.avatar img {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--bg-dark);
    padding: 2px;
    border: 2px solid var(--primary);
}

.user-info {
    display: flex;
    flex-direction: column;
}

.user-name {
    font-weight: 600;
    font-size: 14px;
}

.user-role {
    font-size: 12px;
    color: var(--text-muted);
}

/* Main Content */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    position: relative;
}

.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 24px 40px;
    position: sticky;
    top: 0;
    z-index: 5;
    background: rgba(9, 9, 11, 0.8);
    backdrop-filter: var(--glass-blur);
    border-bottom: 1px solid var(--border-color);
}

.search-bar {
    display: flex;
    align-items: center;
    background: var(--bg-panel);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 10px 16px;
    width: 350px;
    gap: 10px;
    transition: all 0.3s ease;
}
.search-bar:focus-within {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2);
}

.search-bar i {
    color: var(--text-muted);
    font-size: 18px;
}

.search-bar input {
    background: none;
    border: none;
    outline: none;
    color: var(--text-main);
    width: 100%;
    font-size: 14px;
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 16px;
}

.primary-btn {
    background: var(--primary);
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: var(--radius-lg);
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 600;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
}

.primary-btn:hover {
    background: var(--primary-hover);
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(59, 130, 246, 0.4);
}

.secondary-btn {
    background: transparent;
    color: var(--text-main);
    border: 1px solid var(--border-color);
    padding: 10px 20px;
    border-radius: var(--radius-lg);
    font-weight: 600;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.3s ease;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.secondary-btn:hover {
    background: var(--bg-panel);
    border-color: var(--text-muted);
}

.danger-btn {
    background: transparent;
    color: var(--danger);
    border: 1px solid var(--danger);
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    font-weight: 500;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s;
}
.danger-btn:hover {
    background: rgba(239, 68, 68, 0.1);
}

/* Utils */
.mt-2 { margin-top: 8px; }
.mt-4 { margin-top: 16px; }

/* Views */
.views {
    padding: 32px 40px;
    flex: 1;
}

.view {
    display: none;
    animation: fadeIn 0.4s ease-out forwards;
}

.view.active {
    display: block;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

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

.page-title {
    font-size: 28px;
    font-weight: 700;
    letter-spacing: -0.5px;
    margin-bottom: 0;
}
#dashboard .page-title, #production .page-title, #products .page-title {
    margin-bottom: 32px;
}

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

.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 24px;
    display: flex;
    align-items: center;
    gap: 20px;
    backdrop-filter: var(--glass-blur);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.stat-card:hover {
    transform: translateY(-5px);
    box-shadow: var(--shadow-subtle);
    border-color: rgba(255, 255, 255, 0.2);
}

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

.stat-details h3 {
    font-size: 13px;
    color: var(--text-muted);
    font-weight: 500;
    margin-bottom: 4px;
}

.stat-details p {
    font-size: 24px;
    font-weight: 700;
    color: var(--text-main);
}

/* Tabs */
.tabs {
    display: flex;
    gap: 12px;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 12px;
}
.tab-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    transition: all 0.2s;
}
.tab-btn:hover {
    color: var(--text-main);
    background: rgba(255,255,255,0.05);
}
.tab-btn.active {
    color: var(--primary);
    background: rgba(59, 130, 246, 0.1);
}

/* Tables */
.recent-section {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    backdrop-filter: var(--glass-blur);
    overflow: hidden;
}

.section-header {
    padding: 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border-color);
}
.section-header h2 { font-size: 18px; font-weight: 600; }

.table-container {
    width: 100%;
    overflow-x: auto;
}

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

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

.data-table th {
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-muted);
    font-weight: 600;
    background: rgba(0, 0, 0, 0.2);
}

.data-table td { font-size: 14px; }
.data-table tbody tr { transition: background 0.2s; }
.data-table tbody tr:hover { background: rgba(255, 255, 255, 0.03); }
.data-table tbody tr.negative-stock-row { background: rgba(239, 68, 68, 0.15) !important; }
.data-table tbody tr.critical-stock-row { background: rgba(234, 179, 8, 0.15) !important; }

/* Status & Type Badges */
.type-badge {
    padding: 4px 10px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 600;
    display: inline-block;
    border: 1px solid;
}
.type-hammadde { background: rgba(245, 158, 11, 0.1); color: #fbbf24; border-color: rgba(245, 158, 11, 0.3); }
.type-badge.type-mamul { background: rgba(16, 185, 129, 0.15); color: #10b981; }

/* MACHINES & WORK ORDERS */
.machine-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.machine-card h3 {
    margin: 0;
    font-size: 16px;
}
.status-badge {
    display: inline-block;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 12px;
    font-weight: 600;
}
.status-badge.status-idle { background: rgba(59, 130, 246, 0.1); color: #3b82f6; border: 1px solid #3b82f6; }
.status-badge.status-working { background: rgba(16, 185, 129, 0.1); color: #10b981; border: 1px solid #10b981; }
.status-badge.status-broken { background: rgba(239, 68, 68, 0.1); color: #ef4444; border: 1px solid #ef4444; }

.work-orders-kanban {
    display: flex;
    gap: 16px;
    align-items: flex-start;
    overflow-x: auto;
    padding-bottom: 12px;
}
.kanban-column {
    background: rgba(0, 0, 0, 0.2);
    border-radius: var(--radius-md);
    padding: 16px;
    min-width: 300px;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.kanban-column h4 {
    margin: 0 0 8px 0;
    border-bottom: 1px solid var(--border);
    padding-bottom: 8px;
    color: var(--text-muted);
}
.wo-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.wo-card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
}
.wo-card-header h5 {
    margin: 0;
    font-size: 14px;
    color: var(--text-main);
}
.wo-actions {
    display: flex;
    gap: 8px;
    margin-top: 8px;
}
.type-mamul { border-color: rgba(16, 185, 129, 0.3); }

/* Recipes Grid */
.recipes-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 24px;
}

.recipe-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    transition: transform 0.2s;
}
.recipe-card:hover {
    transform: translateY(-4px);
    border-color: rgba(255,255,255,0.2);
}
.recipe-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
}
.recipe-header h3 {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-main);
}
.recipe-materials {
    list-style: none;
    font-size: 13px;
    color: var(--text-muted);
    background: rgba(0,0,0,0.2);
    padding: 12px;
    border-radius: var(--radius-sm);
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.recipe-materials li {
    display: flex;
    justify-content: space-between;
    border-bottom: 1px dashed var(--border-color);
    padding-bottom: 4px;
}
.recipe-materials li:last-child { border: none; padding-bottom: 0; }

/* Production Form */
.production-container {
    display: flex;
    justify-content: center;
}
.production-form-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 32px;
    width: 100%;
    max-width: 500px;
    backdrop-filter: var(--glass-blur);
}
.production-form-card h2 {
    font-size: 20px;
    margin-bottom: 24px;
}
.material-preview {
    background: rgba(0,0,0,0.2);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 16px;
    margin-top: 24px;
}
.material-preview h3 {
    font-size: 14px;
    margin-bottom: 12px;
    color: var(--text-muted);
}
.material-preview ul {
    list-style: none;
    font-size: 13px;
}
.material-preview li {
    display: flex;
    justify-content: space-between;
    padding: 8px 0;
    border-bottom: 1px solid rgba(255,255,255,0.05);
}
.material-preview li.insufficient {
    color: var(--danger);
}

/* Modals */
.modal-overlay {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0, 0, 0, 0.7); backdrop-filter: blur(4px);
    z-index: 100; display: flex; align-items: center; justify-content: center;
    opacity: 0; pointer-events: none; transition: opacity 0.3s ease;
}
.modal-overlay.active { opacity: 1; pointer-events: auto; }
.modal-content {
    background: var(--bg-panel); border: 1px solid var(--border-color);
    border-radius: var(--radius-lg); width: 100%; max-width: 500px;
    box-shadow: var(--shadow-subtle); transform: translateY(20px);
    transition: transform 0.3s ease;
    max-height: 90vh; overflow-y: auto;
}
.modal-overlay.active .modal-content { transform: translateY(0); }
.modal-header {
    padding: 24px; border-bottom: 1px solid var(--border-color);
    display: flex; justify-content: space-between; align-items: center;
    position: sticky; top: 0; background: var(--bg-panel); z-index: 10;
}
.close-btn { background: none; border: none; color: var(--text-muted); font-size: 20px; cursor: pointer; }
.close-btn:hover { color: var(--text-main); }
form { padding: 24px; display: flex; flex-direction: column; gap: 20px; }
.form-row { display: flex; gap: 16px; }
.form-row .form-group { flex: 1; }
.form-group { display: flex; flex-direction: column; gap: 8px; }
.form-group label { font-size: 13px; color: var(--text-muted); font-weight: 500; }
.form-group input, .form-group select {
    background: var(--bg-dark); border: 1px solid var(--border-color);
    color: var(--text-main); padding: 12px; border-radius: var(--radius-sm);
    outline: none; font-family: inherit; font-size: 14px; transition: border-color 0.2s;
}
.form-group input:focus, .form-group select:focus { border-color: var(--primary); }
.modal-actions { display: flex; justify-content: flex-end; gap: 12px; margin-top: 10px; }

/* Custom Form Elements */
.radio-group {
    display: flex; gap: 16px;
}
.radio-label {
    display: flex; align-items: center; gap: 8px; cursor: pointer;
    background: var(--bg-dark); padding: 10px 16px; border: 1px solid var(--border-color);
    border-radius: var(--radius-sm); flex: 1; transition: all 0.2s;
}
.radio-label:has(input:checked) {
    border-color: var(--primary); background: rgba(59,130,246,0.1);
}

.recipe-materials-list {
    display: flex; flex-direction: column; gap: 12px;
}
.material-row {
    display: flex; gap: 12px; align-items: center;
    background: rgba(0,0,0,0.2); padding: 12px; border-radius: var(--radius-sm); border: 1px solid var(--border-color);
}
.material-row .form-group { margin: 0; }
.remove-row-btn {
    background: none; border: none; color: var(--danger); font-size: 20px; cursor: pointer; padding: 4px;
}

/* Toast */
.toast {
    position: fixed;
    bottom: 24px;
    right: 24px;
    background: var(--primary);
    color: white;
    padding: 12px 24px;
    border-radius: var(--radius-sm);
    font-weight: 500;
    box-shadow: var(--shadow-subtle);
    transform: translateY(100px);
    opacity: 0;
    transition: all 0.3s ease;
    z-index: 1000;
}
.toast.show {
    transform: translateY(0);
    opacity: 1;
}

/* Login Overlay */
.login-overlay {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: var(--bg-dark);
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    background-image: 
        radial-gradient(circle at 15% 50%, rgba(59, 130, 246, 0.08), transparent 25%),
        radial-gradient(circle at 85% 30%, rgba(16, 185, 129, 0.08), transparent 25%);
}

.login-card {
    background: var(--bg-panel);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 40px;
    width: 100%;
    max-width: 400px;
    box-shadow: var(--shadow-glow);
    backdrop-filter: var(--glass-blur);
}
.text-danger {
    color: var(--danger);
}

/* =========================================
   MOBILE RESPONSIVENESS
   ========================================= */

/* Mobile Menu Button */
.mobile-menu-btn {
    display: none;
    background: transparent;
    border: none;
    color: var(--text-main);
    font-size: 24px;
    cursor: pointer;
    padding: 4px;
}

/* Sidebar Overlay */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 15;
    backdrop-filter: blur(4px);
    opacity: 0;
    transition: opacity 0.3s ease;
}

.sidebar-overlay.active {
    display: block;
    opacity: 1;
}

@media (max-width: 1024px) {
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 768px) {
    /* Hide Sidebar by default on mobile */
    .sidebar {
        position: fixed;
        left: -100%;
        top: 0;
        height: 100vh;
        transition: left 0.3s ease;
        z-index: 20;
    }
    
    .sidebar.active {
        left: 0;
    }

    .mobile-menu-btn {
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .topbar {
        padding: 16px 20px;
        gap: 12px;
    }

    .search-bar {
        width: 100%;
        flex: 1;
    }

    #apiStatus {
        font-size: 0; /* visually hide text */
    }
    #apiStatus i {
        font-size: 20px;
    }
    
    #btnAddProduct span {
        display: none; /* Hide text in top button */
    }
    
    .stats-grid {
        grid-template-columns: 1fr;
    }

    .section-header-row {
        flex-direction: column;
        align-items: flex-start;
        gap: 16px;
    }

    .filter-bar {
        flex-wrap: wrap;
        width: 100%;
    }
    
    .filter-bar input, .filter-bar select {
        flex: 1;
        min-width: 120px;
    }
    
    .data-table-container {
        width: 100%;
        overflow-x: auto;
    }

    .data-table {
        min-width: 600px;
    }
    
    /* Fix overflowing forms */
    .form-row {
        flex-direction: column;
        gap: 12px;
    }
    
    .modal-content {
        width: 95%;
        margin: 10px;
    }
    
    /* Kanban adjustments */
    .work-orders-kanban {
        flex-direction: column;
    }
    
    .kanban-column {
        width: 100%;
        min-width: unset;
    }
}
