/* 智捷ERP SmartJet ERP - 1:1 High-Fidelity UI System v4.0 */
@import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;500;600;700;800&display=swap');

:root {
    --primary: #6366f1;
    --primary-light: #818cf8;
    --primary-bg: #f5f3ff;
    
    --slate-50: #f8fafc;
    --slate-100: #f1f5f9;
    --slate-200: #e2e8f0;
    --slate-300: #cbd5e1;
    --slate-400: #94a3b8;
    --slate-500: #64748b;
    --slate-600: #475569;
    --slate-700: #334155;
    --slate-800: #1e293b;
    --slate-900: #0f172a;

    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --info: #3b82f6;

    --sidebar-width: 240px;
    --sidebar-collapsed-width: 0px;
    --topbar-height: 64px;
    --radius-lg: 16px;
    --radius-md: 10px;
    --shadow-card: 0 10px 15px -3px rgba(0, 0, 0, 0.04), 0 4px 6px -2px rgba(0, 0, 0, 0.02);
}

*, *::before, *::after {
    box-sizing: border-box;
}

body {
    background-color: #f1f5f9 !important;
    color: var(--slate-800) !important;
    font-family: 'Plus Jakarta Sans', -apple-system, sans-serif !important;
    margin: 0 !important;
    padding: 0 !important;
    overflow-x: hidden;
}

#container {
    display: flex !important;
    min-height: 100vh;
    min-width: 0 !important;
    max-width: 100vw;
    width: 100%;
    overflow-x: hidden;
}

/* --- SIDEBAR --- */
#header {
    width: var(--sidebar-width) !important;
    height: 100vh !important;
    position: fixed !important;
    left: 0; top: 0;
    background: #ffffff !important;
    border-right: 1px solid var(--slate-200) !important;
    padding: 0 !important;
    display: flex !important;
    flex-direction: column !important;
    z-index: 1000 !important;
    color: var(--slate-800) !important;
    line-height: normal !important;
    overflow: visible !important;
}

/* 覆盖 Django admin 默认深色顶栏链接样式（白字导致侧栏文字不可见） */
#header a:link,
#header a:visited {
    color: inherit !important;
    text-decoration: none !important;
}

#header a:focus,
#header a:hover {
    text-decoration: none !important;
}

.brand-section {
    padding: 24px;
    display: flex;
    align-items: center;
}

.brand-logo {
    width: 32px;
    height: 32px;
    background: linear-gradient(135deg, #6366f1, #a855f7);
    border-radius: 8px;
    margin-right: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 800;
}

.brand-text h1 {
    font-size: 18px !important;
    font-weight: 800 !important;
    color: #1e293b !important;
    margin: 0 !important;
    line-height: 1 !important;
}

.brand-text span {
    font-size: 11px;
    color: var(--slate-400);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.sidebar-nav {
    flex: 1;
    padding: 0 16px;
    overflow-y: auto;
}

.nav-group-label {
    padding: 20px 12px 10px 12px;
    color: var(--slate-400);
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
}

.nav-item {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    border-radius: 12px;
    color: var(--slate-600) !important;
    text-decoration: none !important;
    font-weight: 600;
    font-size: 14px;
    margin-bottom: 4px;
    transition: all 0.2s;
}

.nav-item:hover,
.nav-item:focus {
    background: var(--slate-50);
    color: var(--primary) !important;
}

.nav-item.active,
.nav-item.active:link,
.nav-item.active:visited {
    background: var(--primary-bg) !important;
    color: var(--primary) !important;
}

.nav-item i { margin-right: 12px; font-size: 18px; width: 20px; text-align: center; }
.nav-item .arrow { margin-left: auto; font-size: 10px; color: var(--slate-300); }

.sidebar-footer {
    padding: 16px;
    border-top: 1px solid var(--slate-100);
    position: relative;
    z-index: 1002;
    flex-shrink: 0;
    background: #ffffff;
}

.nav-item-btn {
    width: 100%;
    border: none;
    background: transparent;
    cursor: pointer;
    font-family: inherit;
    text-align: left;
}

button.nav-item-btn:hover,
button.nav-item-btn:focus {
    background: var(--slate-50);
    color: var(--primary) !important;
    outline: none;
}

/* 侧栏收起 */
#header {
    transition: transform 0.25s ease;
}

body.sidebar-collapsed #header {
    transform: translateX(-100%);
    pointer-events: none;
}

body.sidebar-collapsed #main {
    margin-left: 0 !important;
    max-width: 100vw !important;
}

/* --- TOPBAR --- */
#main {
    flex: 1 1 auto !important;
    margin-left: var(--sidebar-width) !important;
    width: auto !important;
    min-width: 0 !important;
    max-width: calc(100vw - var(--sidebar-width)) !important;
    overflow-x: hidden;
    position: relative;
    z-index: 1;
}

.topbar {
    height: var(--topbar-height);
    background: #ffffff !important;
    opacity: 1 !important;
    display: flex;
    align-items: center;
    padding: 0 32px;
    position: sticky;
    top: 0;
    z-index: 900;
    box-shadow: 0 1px 2px rgba(0,0,0,0.02);
}

.topbar-left { display: flex; align-items: center; flex: 1; }
.topbar-right {
    display: flex;
    align-items: center;
    gap: 20px;
    background: #ffffff !important;
    opacity: 1 !important;
    position: relative;
    z-index: 901;
    pointer-events: auto;
}

.breadcrumb-new {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: var(--slate-400);
    margin-left: 20px;
}

.breadcrumb-new span { color: var(--slate-800); font-weight: 600; }

.search-btn, .icon-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--slate-500);
    cursor: pointer;
    transition: background 0.2s;
    border: none;
    background: transparent;
    padding: 0;
    font-size: 16px;
    line-height: 1;
    pointer-events: auto;
    position: relative;
    z-index: 1;
}

.search-btn:hover, .icon-btn:hover,
.search-btn:focus, .icon-btn:focus {
    background: var(--slate-100);
    outline: none;
}

.user-menu-wrap {
    position: relative;
    padding-left: 20px;
    border-left: 1px solid var(--slate-200);
}

.user-profile {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 4px 8px;
    border: none;
    border-radius: 10px;
    background: #ffffff !important;
    opacity: 1 !important;
    cursor: pointer;
    font-family: inherit;
    pointer-events: auto;
}

.user-profile:hover,
.user-profile:focus {
    background: var(--slate-50) !important;
    outline: none;
}

.user-caret {
    font-size: 10px;
    color: var(--slate-400);
    margin-left: 4px;
}

.user-dropdown {
    display: none;
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    min-width: 140px;
    background: #ffffff;
    border: 1px solid var(--slate-200);
    border-radius: 10px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
    padding: 6px;
    z-index: 1100;
}

.user-dropdown.open {
    display: block;
}

.user-dropdown a {
    display: block;
    padding: 10px 14px;
    border-radius: 8px;
    color: var(--slate-700) !important;
    text-decoration: none !important;
    font-size: 13px;
    font-weight: 600;
}

.user-dropdown a:hover {
    background: var(--slate-50);
    color: var(--primary) !important;
}

.avatar {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    background: var(--slate-200);
    flex-shrink: 0;
    opacity: 1 !important;
}

.user-info { display: flex; flex-direction: column; background: transparent; }
.user-name { font-weight: 700; font-size: 13px; color: var(--slate-800) !important; opacity: 1 !important; }
.user-role { font-size: 11px; color: var(--slate-500) !important; opacity: 1 !important; }

/* --- CONTENT --- */
#content {
    padding: 32px !important;
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    position: relative;
    z-index: 1;
}

.dashboard #content {
    width: 100% !important;
    max-width: 100% !important;
}

#content-main {
    float: none !important;
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
}

.dashboard #content > h1 {
    display: none;
}

#content > h1 {
    font-size: 22px;
    font-weight: 700;
    color: var(--slate-900);
    margin: 0 0 24px;
    padding-right: 120px;
}

.colM, .colMS {
    max-width: 100%;
    min-width: 0;
}

#changelist, #changelist-form, .results {
    max-width: 100%;
    overflow-x: auto;
}

/* --- STATS CARDS --- */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 24px;
    margin-bottom: 32px;
    width: 100%;
    max-width: 100%;
}

.stat-card {
    background: #ffffff;
    padding: 24px;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-card);
    position: relative;
    min-width: 0;
}

.stat-header { display: flex; justify-content: space-between; margin-bottom: 12px; }
.stat-icon-bg { width: 40px; height: 40px; border-radius: 12px; display: flex; align-items: center; justify-content: center; color: white; font-size: 18px; }
.stat-info-icon { color: var(--slate-300); font-size: 14px; cursor: help; }

.stat-value { font-size: 24px; font-weight: 800; color: var(--slate-900); margin-bottom: 8px; }
.stat-label { font-size: 14px; color: var(--slate-500); font-weight: 500; }

.stat-footer { display: flex; align-items: center; justify-content: space-between; margin-top: 16px; border-top: 1px solid var(--slate-50); padding-top: 16px; }
.stat-trend { font-size: 12px; font-weight: 600; display: flex; align-items: center; gap: 4px; }
.trend-up { color: var(--success); }
.trend-down { color: var(--danger); }

.sparkline { width: 60px; height: 30px; }

/* --- DATA MODULES --- */
.dashboard-main-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(260px, 340px);
    gap: 24px;
    width: 100%;
    max-width: 100%;
}

.module-card {
    background: white;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-card);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.card-title {
    padding: 24px 32px;
    font-size: 16px;
    font-weight: 700;
    color: var(--slate-900);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

/* --- TABLE STYLES --- */
.table-container { overflow-x: auto; max-width: 100%; padding: 0 12px 12px 12px; }
table { width: 100%; max-width: 100%; border-collapse: collapse; }
th { text-align: left; padding: 12px 20px; font-size: 12px; color: var(--slate-400); font-weight: 600; border-bottom: 1px solid var(--slate-100); }
td { padding: 16px 20px; font-size: 13px; color: var(--slate-700); border-bottom: 1px solid var(--slate-50); }
tr:last-child td { border: none; }

.badge {
    padding: 4px 10px;
    border-radius: 6px;
    font-size: 11px;
    font-weight: 700;
}
.badge-new { background: #eef2ff; color: #6366f1; }
.badge-audit { background: #ecfdf5; color: #10b981; }
.badge-update { background: #eff6ff; color: #3b82f6; }
.badge-submit { background: #fff7ed; color: #f97316; }

/* --- TASK LIST --- */
.task-list { padding: 0 24px 24px 24px; }
.task-item {
    display: flex;
    align-items: flex-start;
    gap: 16px;
    padding: 16px;
    border-radius: 12px;
    margin-bottom: 12px;
    background: #ffffff;
    border: 1px solid var(--slate-50);
    transition: all 0.2s;
}
.task-item:hover { border-color: var(--slate-200); background: var(--slate-50); }

.task-icon { width: 36px; height: 36px; border-radius: 10px; display: flex; align-items: center; justify-content: center; font-size: 16px; color: white; }
.task-content { flex: 1; }
.task-name { font-size: 13px; font-weight: 700; color: var(--slate-800); }
.task-info { font-size: 11px; color: var(--slate-400); margin-top: 2px; }
.task-time { font-size: 11px; color: var(--slate-400); }

.priority-tag { font-size: 10px; font-weight: 800; padding: 2px 6px; border-radius: 4px; text-transform: uppercase; margin-top: 8px; display: inline-block; }
.p-urgent { background: #fef2f2; color: #ef4444; }
.p-high { background: #fff7ed; color: #f97316; }
.p-medium { background: #fffbeb; color: #f59e0b; }
.p-low { background: #f0fdf4; color: #10b981; }

.view-all { text-align: center; padding: 20px; border-top: 1px solid var(--slate-50); }
.view-all a { color: var(--primary); text-decoration: none; font-size: 13px; font-weight: 700; }

/* --- ADMIN FORM ACTIONS --- */
#content-main {
    position: relative;
    padding-bottom: 24px;
}

.object-tools {
    float: none !important;
    position: absolute !important;
    top: 32px;
    right: 32px;
    margin: 0 !important;
    padding: 0 !important;
    font-size: 12px !important;
    font-weight: 600 !important;
    opacity: 1 !important;
    z-index: 5;
    pointer-events: auto;
}

.object-tools li {
    height: auto !important;
    margin-left: 0 !important;
}

.object-tools a:link,
.object-tools a:visited,
.object-tools a.historylink {
    display: inline-flex !important;
    align-items: center;
    float: none !important;
    padding: 8px 16px !important;
    background: var(--slate-600) !important;
    color: #ffffff !important;
    opacity: 1 !important;
    border-radius: 8px !important;
    font-size: 12px !important;
    font-weight: 600 !important;
    text-transform: none !important;
    letter-spacing: 0 !important;
    text-decoration: none !important;
}

.object-tools a:hover,
.object-tools a:focus {
    background: var(--slate-700) !important;
    color: #ffffff !important;
    opacity: 1 !important;
}

.submit-row {
    display: flex !important;
    flex-wrap: wrap;
    align-items: center;
    justify-content: flex-end;
    gap: 10px;
    overflow: visible !important;
    padding: 16px 20px !important;
    margin: 24px 0 0 !important;
    background: #ffffff !important;
    border: 1px solid var(--slate-200) !important;
    border-radius: var(--radius-md) !important;
    box-shadow: var(--shadow-card);
}

.submit-row p {
    margin: 0 !important;
}

.submit-row p.deletelink-box {
    float: none !important;
    margin-right: auto !important;
}

.submit-row a.deletelink {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    height: auto !important;
    min-height: 38px;
    line-height: 1.4 !important;
    padding: 10px 20px !important;
    border-radius: 8px !important;
    color: #ffffff !important;
    background: var(--danger) !important;
    text-decoration: none !important;
    font-weight: 600;
    font-size: 13px;
}

.submit-row a.deletelink:hover,
.submit-row a.deletelink:focus {
    background: #dc2626 !important;
}

.submit-row input,
.submit-row a.button,
.submit-row .button {
    height: auto !important;
    min-height: 38px;
    line-height: 1.4 !important;
    padding: 10px 20px !important;
    margin: 0 !important;
    border-radius: 8px !important;
    font-size: 13px !important;
    font-weight: 600 !important;
    text-transform: none !important;
    cursor: pointer;
}

.submit-row input.default {
    background: var(--primary) !important;
    border-color: var(--primary) !important;
    color: #ffffff !important;
}

.submit-row input[name="_addanother"],
.submit-row input[name="_continue"],
.submit-row input[name="_saveasnew"] {
    background: #ffffff !important;
    color: var(--slate-700) !important;
    border: 1px solid var(--slate-300) !important;
}

/* 双栏选择器 */
.selector {
    max-width: 100%;
}

.selector .selector-available h2,
.selector .selector-chosen h2 {
    font-size: 13px;
    font-weight: 600;
    color: var(--slate-700);
}

.selector select {
    max-width: 100%;
}

.selector .selector-filter label {
    font-size: 12px;
    color: var(--slate-500);
}

/* 表单模块 */
.module h2, fieldset.module h2 {
    font-size: 14px;
    font-weight: 700;
    color: var(--slate-800);
    background: var(--slate-50) !important;
    border-bottom: 1px solid var(--slate-200);
}

.form-row label {
    color: var(--slate-700) !important;
    font-weight: 600;
}

/* Hide messy native elements */
#footer, .breadcrumbs, #content-related { display: none !important; }

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

    .dashboard-main-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 768px) {
    .stats-grid {
        grid-template-columns: 1fr;
    }

    #content {
        padding: 20px !important;
    }

    .topbar {
        padding: 0 16px;
    }
}

/* --- LOGIN PAGE --- */
body.login-page {
    margin: 0;
    padding: 0;
    min-height: 100vh;
    background: var(--slate-100);
    overflow-x: hidden;
}

.login-shell {
    display: flex;
    min-height: 100vh;
    width: 100%;
}

.login-brand {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 48px;
    background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 50%, #a855f7 100%);
    color: #ffffff;
    position: relative;
    overflow: hidden;
}

.login-brand::before {
    content: '';
    position: absolute;
    inset: 0;
    background: radial-gradient(circle at 20% 80%, rgba(255,255,255,0.12) 0%, transparent 50%),
                radial-gradient(circle at 80% 20%, rgba(255,255,255,0.08) 0%, transparent 40%);
    pointer-events: none;
}

.login-brand-inner {
    position: relative;
    max-width: 420px;
    z-index: 1;
}

.login-brand-logo {
    width: 56px;
    height: 56px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 28px;
    margin-bottom: 24px;
    backdrop-filter: blur(4px);
}

.login-brand h1 {
    font-size: 36px;
    font-weight: 800;
    margin: 0 0 8px;
    letter-spacing: -0.02em;
}

.login-brand-tagline {
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    opacity: 0.8;
    margin: 0 0 20px;
}

.login-brand-desc {
    font-size: 16px;
    opacity: 0.9;
    margin: 0 0 32px;
    line-height: 1.6;
}

.login-brand-features {
    list-style: none;
    padding: 0;
    margin: 0;
}

.login-brand-features li {
    padding: 10px 0;
    padding-left: 24px;
    position: relative;
    font-size: 14px;
    opacity: 0.9;
}

.login-brand-features li::before {
    content: '✓';
    position: absolute;
    left: 0;
    font-weight: 700;
}

.login-panel {
    flex: 0 0 480px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 32px;
    background: var(--slate-50);
}

.login-card {
    width: 100%;
    max-width: 400px;
    background: #ffffff;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-card);
    padding: 40px 36px;
    border: 1px solid var(--slate-200);
}

.login-card-header {
    margin-bottom: 28px;
}

.login-card-header h2 {
    font-size: 24px;
    font-weight: 800;
    color: var(--slate-900);
    margin: 0 0 8px;
}

.login-card-header p {
    font-size: 14px;
    color: var(--slate-500);
    margin: 0;
}

.login-error {
    background: #fef2f2;
    color: #dc2626;
    padding: 12px 14px;
    border-radius: 8px;
    font-size: 13px;
    margin-bottom: 20px;
    border: 1px solid #fecaca;
}

.login-form {
    margin-bottom: 24px;
}

.login-field {
    margin-bottom: 20px;
}

.login-field label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--slate-700);
    margin-bottom: 8px;
}

.login-field input[type="text"],
.login-field input[type="password"] {
    width: 100%;
    padding: 12px 14px;
    font-size: 14px;
    font-family: inherit;
    border: 1px solid var(--slate-300);
    border-radius: var(--radius-md);
    background: #ffffff;
    color: var(--slate-800);
    box-sizing: border-box;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.login-field input[type="text"]:focus,
.login-field input[type="password"]:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-bg);
}

.login-submit {
    width: 100%;
    padding: 14px;
    margin-top: 8px;
    font-size: 15px;
    font-weight: 700;
    font-family: inherit;
    color: #ffffff;
    background: linear-gradient(135deg, var(--primary), #7c3aed);
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: opacity 0.2s, transform 0.15s;
}

.login-submit:hover {
    opacity: 0.92;
    transform: translateY(-1px);
}

.login-submit:active {
    transform: translateY(0);
}

.login-demo {
    background: var(--primary-bg);
    border: 1px solid #e0e7ff;
    border-radius: var(--radius-md);
    padding: 16px;
    margin-bottom: 20px;
}

.login-demo-title {
    font-size: 12px;
    font-weight: 700;
    color: var(--primary);
    margin-bottom: 8px;
}

.login-demo-row {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 13px;
    color: var(--slate-600);
    margin-bottom: 4px;
}

.login-demo-row span {
    min-width: 48px;
    color: var(--slate-500);
}

.login-demo-row code {
    font-family: 'Consolas', monospace;
    background: rgba(255, 255, 255, 0.8);
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 12px;
    color: var(--slate-800);
}

.login-demo-divider {
    height: 1px;
    background: #e0e7ff;
    margin: 12px 0;
}

.login-footer-link {
    text-align: center;
}

.login-footer-link a {
    font-size: 12px;
    color: var(--slate-400);
    text-decoration: none;
}

.login-footer-link a:hover {
    color: var(--primary);
}

@media (max-width: 900px) {
    .login-shell {
        flex-direction: column;
    }

    .login-brand {
        flex: none;
        padding: 32px 24px;
    }

    .login-brand-inner {
        max-width: 100%;
        text-align: center;
    }

    .login-brand-logo {
        margin-left: auto;
        margin-right: auto;
    }

    .login-brand-features {
        display: none;
    }

    .login-panel {
        flex: 1;
        padding: 24px 16px 32px;
    }
}
