/* ===========================================================
   SCM Design System — Light/Dark Theme with Toggle
   =========================================================== */

/* --- CSS Variables / Design Tokens (Light Theme - Default) --- */
:root {
    /* Colors */
    --primary: #3B82F6;
    --primary-dark: #2563EB;
    --primary-bg: rgba(59, 130, 246, 0.08);
    --success: #16A34A;
    --success-bg: rgba(22, 163, 74, 0.08);
    --danger: #DC2626;
    --danger-bg: rgba(220, 38, 38, 0.08);
    --warning: #D97706;
    --warning-bg: rgba(217, 119, 6, 0.08);
    --info: #0891B2;
    --info-bg: rgba(8, 145, 178, 0.08);

    /* Backgrounds */
    --bg-body: #F1F5F9;
    --bg-sidebar: #FFFFFF;
    --bg-card: #FFFFFF;
    --bg-header: rgba(255, 255, 255, 0.92);
    --bg-input: #FFFFFF;
    --bg-hover: rgba(0, 0, 0, 0.04);
    --bg-selected: rgba(59, 130, 246, 0.08);

    /* Text */
    --text-primary: #0F172A;
    --text-secondary: #475569;
    --text-muted: #94A3B8;

    /* Borders */
    --border-color: #E2E8F0;

    /* Radius */
    --radius-sm: 4px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --radius-xl: 16px;
    --radius-full: 9999px;

    /* Shadows */
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.08);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08);
    --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.1);

    /* Transitions */
    --transition-fast: 0.15s ease;
    --transition-base: 0.25s ease;

    /* Layout */
    --sidebar-width: 260px;
    --sidebar-collapsed-width: 68px;
    --header-height: 64px;
}

/* --- Dark Theme Override --- */
[data-theme="dark"] {
    --primary-bg: rgba(59, 130, 246, 0.12);
    --success: #22C55E;
    --success-bg: rgba(34, 197, 94, 0.12);
    --danger: #EF4444;
    --danger-bg: rgba(239, 68, 68, 0.12);
    --warning: #F59E0B;
    --warning-bg: rgba(245, 158, 11, 0.12);
    --info: #06B6D4;
    --info-bg: rgba(6, 182, 212, 0.12);

    --bg-body: #0F172A;
    --bg-sidebar: #1E293B;
    --bg-card: #1E293B;
    --bg-header: rgba(30, 41, 59, 0.95);
    --bg-input: #0F172A;
    --bg-hover: rgba(255, 255, 255, 0.05);
    --bg-selected: rgba(59, 130, 246, 0.1);

    --text-primary: #F1F5F9;
    --text-secondary: #CBD5E1;
    --text-muted: #64748B;

    --border-color: rgba(255, 255, 255, 0.08);

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.25);
    --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.3);
}

/* --- Reset & Base --- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; text-rendering: optimizeLegibility; }
body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-body); color: var(--text-primary); line-height: 1.5;
    transition: background-color 0.3s ease, color 0.3s ease;
}
/* Force Inter on all elements */
input, textarea, select, button, a, th, td, label, span, div, p, h1, h2, h3, h4, h5, h6, li, canvas {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}
.sidebar, .header, .card, .stat-card, .bg-card, .dropdown-menu, .toast, .form-control {
    transition: background-color 0.3s ease, border-color 0.3s ease, color 0.3s ease, box-shadow 0.3s ease;
}
a { color: var(--primary); text-decoration: none; transition: color var(--transition-fast); }
a:hover { color: var(--primary-dark); }

/* --- Layout --- */
.app-wrapper { display: flex; min-height: 100vh; }
.app-main { flex: 1; margin-left: var(--sidebar-width); display: flex; flex-direction: column; transition: margin-left var(--transition-base); }
.app-content { flex: 1; padding: 24px; }
.container-fluid { width: 100%; }

/* --- Sidebar --- */
.sidebar {
    position: fixed; top: 0; left: 0; bottom: 0;
    width: var(--sidebar-width);
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border-color);
    display: flex; flex-direction: column;
    z-index: 100;
    transition: width var(--transition-base), transform var(--transition-base);
    overflow-x: hidden;
}
.sidebar-header {
    height: var(--header-height);
    padding: 0 20px;
    display: flex; align-items: center; justify-content: space-between;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}
.sidebar-logo {
    display: flex; align-items: center; gap: 10px;
    color: var(--text-primary); font-size: 1.25rem; font-weight: 700;
}
.sidebar-logo svg { color: var(--primary); }
.sidebar-toggle {
    width: 28px; height: 28px; border-radius: var(--radius-sm);
    background: transparent; border: none; color: var(--text-muted);
    cursor: pointer; display: flex; align-items: center; justify-content: center;
    transition: all var(--transition-fast);
}
.sidebar-toggle:hover { background: var(--bg-hover); color: var(--text-primary); }
.sidebar-content { flex: 1; overflow-y: auto; padding: 12px 0; scrollbar-width: thin; scrollbar-color: var(--border-color) transparent; }
.sidebar-menu { list-style: none; }

/* Menu Items */
.menu-heading {
    padding: 20px 20px 8px;
    font-size: 0.6875rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
}
.menu-link {
    display: flex; align-items: center; gap: 10px;
    padding: 9px 20px;
    color: var(--text-secondary);
    font-size: 0.8125rem;
    font-weight: 500;
    border-radius: 0;
    transition: all var(--transition-fast);
    position: relative;
}
.menu-link:hover { background: var(--bg-hover); color: var(--text-primary); }
.menu-link.active {
    color: var(--primary);
    background: var(--bg-selected);
}
.menu-link.active::before {
    content: '';
    position: absolute; left: 0; top: 8px; bottom: 8px;
    width: 3px; border-radius: 0 3px 3px 0;
    background: var(--primary);
}
.menu-icon { display: flex; align-items: center; flex-shrink: 0; opacity: 0.75; }
.menu-link.active .menu-icon { opacity: 1; }
.menu-arrow { margin-left: auto; transition: transform var(--transition-fast); }

/* Submenu */
.has-submenu > .menu-link { cursor: pointer; }
.submenu { list-style: none; display: none; padding-left: 0; }
.has-submenu.open > .submenu { display: block; }
.has-submenu.open > .menu-link .menu-arrow { transform: rotate(90deg); }
.submenu .menu-link { padding-left: 50px; font-size: 0.8125rem; }

/* --- Header --- */
.header {
    height: var(--header-height);
    background: var(--bg-header);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border-color);
    display: flex; align-items: center; justify-content: space-between;
    padding: 0 24px;
    position: sticky; top: 0;
    z-index: 50;
}
.header-left { display: flex; align-items: center; gap: 16px; }
.header-right { display: flex; align-items: center; gap: 12px; }
.mobile-menu-toggle { display: none; background: none; border: none; color: var(--text-secondary); cursor: pointer; padding: 6px; border-radius: var(--radius-sm); }
.mobile-menu-toggle:hover { background: var(--bg-hover); }

/* Breadcrumb */
.breadcrumb { display: flex; align-items: center; gap: 6px; font-size: 0.8125rem; }
.breadcrumb a { color: var(--text-muted); }
.breadcrumb a:hover { color: var(--primary); }
.breadcrumb .separator { color: var(--text-muted); }
.breadcrumb .current { color: var(--text-primary); font-weight: 500; }

/* User Dropdown */
.user-dropdown { position: relative; }
.user-btn {
    display: flex; align-items: center; gap: 10px;
    background: none; border: 1px solid var(--border-color); border-radius: var(--radius-md);
    padding: 6px 12px; cursor: pointer; color: var(--text-primary);
    transition: all var(--transition-fast);
}
.user-btn:hover { background: var(--bg-hover); border-color: var(--primary); }
.user-avatar {
    width: 32px; height: 32px; border-radius: var(--radius-full);
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: white; display: flex; align-items: center; justify-content: center;
    font-size: 0.75rem; font-weight: 700;
}
.user-info { text-align: left; }
.user-name { font-size: 0.8125rem; font-weight: 600; line-height: 1.2; }
.user-role { font-size: 0.6875rem; color: var(--text-muted); }
.dropdown-menu {
    position: absolute; right: 0; top: calc(100% + 6px);
    background: var(--bg-card); border: 1px solid var(--border-color);
    border-radius: var(--radius-md); min-width: 180px;
    box-shadow: var(--shadow-lg);
    display: none; z-index: 200;
    animation: fadeInUp 0.15s ease;
}
.dropdown-menu.show { display: block; }
.dropdown-item {
    display: flex; align-items: center; gap: 8px;
    padding: 10px 14px; font-size: 0.8125rem;
    color: var(--text-secondary); transition: all var(--transition-fast);
}
.dropdown-item:hover { background: var(--bg-hover); color: var(--text-primary); }

/* --- Cards --- */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    overflow: hidden;
    transition: box-shadow var(--transition-fast);
}
.card:hover { box-shadow: var(--shadow-sm); }
.card-header {
    padding: 16px 20px;
    display: flex; align-items: center; justify-content: space-between;
    border-bottom: 1px solid var(--border-color);
}
.card-title { font-size: 0.875rem; font-weight: 600; }
.card-body { padding: 20px; }
.card-body.p-0 { padding: 0; }
.card-footer { padding: 12px 20px; border-top: 1px solid var(--border-color); }

/* Stat Cards */
.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 20px;
    transition: all var(--transition-fast);
}
.stat-card:hover { border-color: var(--primary); transform: translateY(-1px); box-shadow: var(--shadow-md); }
.stat-icon { width: 44px; height: 44px; border-radius: var(--radius-md); display: flex; align-items: center; justify-content: center; }
.stat-value { font-size: 1.75rem; font-weight: 700; margin-top: 12px; line-height: 1; }
.stat-label { font-size: 0.8125rem; color: var(--text-muted); margin-top: 4px; }

/* --- Tables --- */
table { width: 100%; border-collapse: collapse; }
thead th {
    padding: 12px 16px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border-color);
    text-align: left;
}
tbody td {
    padding: 12px 16px;
    font-size: 0.8125rem;
    border-bottom: 1px solid var(--border-color);
    vertical-align: middle;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--bg-hover); }
.user-cell { display: flex; align-items: center; gap: 10px; }
.user-cell-name { font-weight: 500; font-size: 0.8125rem; }
.user-cell-email { font-size: 0.75rem; color: var(--text-muted); }

/* --- Forms --- */
.form-group { margin-bottom: 16px; }
.form-label { display: block; font-size: 0.8125rem; font-weight: 500; margin-bottom: 6px; color: var(--text-secondary); }
.form-label .required { color: var(--danger); }
.form-control {
    width: 100%;
    padding: 9px 14px;
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-size: 0.875rem;
    font-family: inherit;
    transition: all var(--transition-fast);
    outline: none;
}
.form-control:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-bg); }
.form-control::placeholder { color: var(--text-muted); }
textarea.form-control { resize: vertical; min-height: 80px; }
select.form-control { 
    cursor: pointer; 
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    padding-right: 38px !important;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E") !important;
    background-repeat: no-repeat !important;
    background-position: right 14px center !important;
    background-size: 14px 14px !important;
}
[data-theme="dark"] select.form-control {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E") !important;
}
.form-hint { font-size: 0.75rem; color: var(--text-muted); margin-top: 4px; }

/* --- Buttons --- */
.btn {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 9px 18px;
    font-size: 0.8125rem;
    font-weight: 500;
    font-family: inherit;
    border: 1px solid transparent;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition-fast);
    text-decoration: none;
    line-height: 1.4;
}
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0); }

.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); color: white; box-shadow: 0 4px 12px rgba(59, 130, 246, 0.35); }
.btn-success { background: var(--success); color: white; }
.btn-success:hover { background: #16A34A; color: white; }
.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover { background: #DC2626; color: white; }
.btn-outline { background: transparent; border-color: var(--border-color); color: var(--text-secondary); }
.btn-outline:hover { border-color: var(--primary); color: var(--primary); background: var(--primary-bg); }
.btn-ghost { background: transparent; color: var(--text-secondary); }
.btn-ghost:hover { background: var(--bg-hover); color: var(--text-primary); }

.btn-sm { padding: 6px 12px; font-size: 0.75rem; }
.btn-lg { padding: 12px 24px; font-size: 0.9375rem; }
.w-100 { width: 100%; justify-content: center; }

/* --- Badges --- */
.badge {
    display: inline-flex; align-items: center; gap: 4px;
    padding: 3px 10px;
    font-size: 0.6875rem;
    font-weight: 600;
    border-radius: var(--radius-full);
    white-space: nowrap;
}
.badge-primary { background: var(--primary-bg); color: var(--primary); }
.badge-success { background: var(--success-bg); color: var(--success); }
.badge-danger { background: var(--danger-bg); color: var(--danger); }
.badge-warning { background: var(--warning-bg); color: var(--warning); }
.badge-info { background: var(--info-bg); color: var(--info); }
.badge-neutral { background: rgba(100, 116, 139, 0.15); color: var(--text-muted); }
.badge-dot { width: 6px; height: 6px; border-radius: 50%; }

/* --- Alerts --- */
.alert {
    display: flex; align-items: flex-start; gap: 10px;
    padding: 12px 16px;
    border-radius: var(--radius-md);
    font-size: 0.8125rem;
    line-height: 1.5;
    animation: fadeInUp 0.3s ease;
}
.alert svg { flex-shrink: 0; margin-top: 2px; }
.alert-success { background: var(--success-bg); color: var(--success); border: 1px solid rgba(34, 197, 94, 0.2); }
.alert-danger { background: var(--danger-bg); color: var(--danger); border: 1px solid rgba(239, 68, 68, 0.2); }
.alert-warning { background: var(--warning-bg); color: var(--warning); border: 1px solid rgba(245, 158, 11, 0.2); }
.alert-info { background: var(--info-bg); color: var(--info); border: 1px solid rgba(6, 182, 212, 0.2); }

/* --- Avatars --- */
.avatar {
    width: 40px; height: 40px; border-radius: var(--radius-full);
    display: flex; align-items: center; justify-content: center;
    font-size: 0.75rem; font-weight: 700; flex-shrink: 0;
}
.avatar-sm { width: 32px; height: 32px; font-size: 0.6875rem; }
.avatar-lg { width: 48px; height: 48px; font-size: 1rem; }

/* --- Toast --- */
.toast-container {
    position: fixed; top: 20px; right: 20px;
    z-index: 9999; display: flex; flex-direction: column; gap: 8px;
}
.toast {
    background: var(--bg-card); border: 1px solid var(--border-color);
    border-radius: var(--radius-md); padding: 12px 16px;
    box-shadow: var(--shadow-lg); min-width: 280px; max-width: 400px;
    animation: slideInRight 0.3s ease;
    display: flex; align-items: center; gap: 10px;
    font-size: 0.8125rem;
}
.toast.toast-success { border-left: 3px solid var(--success); }
.toast.toast-danger { border-left: 3px solid var(--danger); }
.toast.toast-warning { border-left: 3px solid var(--warning); }
.toast.toast-info { border-left: 3px solid var(--info); }

/* --- Grid System --- */
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }

/* --- Utilities --- */
.d-flex { display: flex; }
.gap-1 { gap: 4px; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.justify-between { justify-content: space-between; }
.align-items-center { align-items: center; }
.flex-wrap { flex-wrap: wrap; }
.text-center { text-align: center; }
.text-sm { font-size: 0.8125rem; }
.text-xs { font-size: 0.75rem; }
.text-muted { color: var(--text-muted); }
.text-primary { color: var(--primary) !important; }
.font-medium { font-weight: 500; }
.font-bold { font-weight: 700; }
.mb-4 { margin-bottom: 16px; }
.mb-5 { margin-bottom: 20px; }
.mb-6 { margin-bottom: 24px; }
.page-title { font-size: 1.375rem; font-weight: 700; }

/* Sidebar Overlay */
.sidebar-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 99; }

/* --- Animations --- */
@keyframes fadeInUp { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
@keyframes slideInRight { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: translateX(0); } }

/* --- Responsive --- */
@media (max-width: 1024px) {
    .grid-4 { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 768px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar.show { transform: translateX(0); }
    .sidebar-overlay.show { display: block; }
    .app-main { margin-left: 0; }
    .mobile-menu-toggle { display: flex; }
    .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
    .header { padding: 0 16px; }
    .app-content { padding: 16px; }
    .d-flex.gap-2.flex-wrap { flex-direction: column; }
    table { font-size: 0.75rem; }
    thead th, tbody td { padding: 8px 10px; }
}
@media (max-width: 480px) {
    .stat-card { padding: 14px; }
    .stat-value { font-size: 1.25rem; }
}

/* --- Scrollbar --- */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.15); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(0,0,0,0.25); }
[data-theme="dark"] ::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); }
[data-theme="dark"] ::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.2); }

/* --- Theme Toggle Button --- */
.theme-toggle {
    width: 38px; height: 38px;
    border-radius: var(--radius-md);
    background: var(--bg-hover);
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: all var(--transition-fast);
    position: relative;
    overflow: hidden;
}
.theme-toggle:hover { background: var(--bg-selected); color: var(--primary); border-color: var(--primary); }
.theme-toggle .icon-sun,
.theme-toggle .icon-moon { position: absolute; transition: all 0.3s ease; }
.theme-toggle .icon-sun { opacity: 1; transform: rotate(0deg) scale(1); }
.theme-toggle .icon-moon { opacity: 0; transform: rotate(-90deg) scale(0.5); }
[data-theme="dark"] .theme-toggle .icon-sun { opacity: 0; transform: rotate(90deg) scale(0.5); }
[data-theme="dark"] .theme-toggle .icon-moon { opacity: 1; transform: rotate(0deg) scale(1); }
