/* ============================================================
   NM-Ctrl MES — 浅色主题 (Light Theme)
   企业级 MES 前端样式，基于 CSS 变量实现统一主题
   ============================================================ */

/* ----- CSS Variables (Light Theme) ----- */
:root {
    /* Background colors */
    --bg-body: #f0f2f5;
    --bg-content: #ffffff;
    --bg-card: #ffffff;
    --bg-sidebar: #1e293b;
    --bg-sidebar-hover: #334155;
    --bg-sidebar-active: #0ea5e9;
    --bg-header: #ffffff;
    --bg-subnav: #f8fafc;
    --bg-hover: #f1f5f9;
    --bg-active: #e8f0fe;
    --bg-input: #ffffff;
    --bg-disabled: #f1f5f9;
    --bg-table-stripe: #f8fafc;
    --bg-table-hover: #f1f5f9;
    --bg-overlay: rgba(0, 0, 0, 0.5);

    /* Text colors */
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --text-muted: #94a3b8;
    --text-inverse: #ffffff;
    --text-link: #2563eb;
    --text-placeholder: #94a3b8;

    /* Brand colors */
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --primary-light: #dbeafe;
    --primary-dark: #1e40af;

    /* Status colors */
    --success: #10b981;
    --success-light: #d1fae5;
    --success-dark: #065f46;
    --warning: #f59e0b;
    --warning-light: #fef3c7;
    --warning-dark: #92400e;
    --danger: #ef4444;
    --danger-light: #fee2e2;
    --danger-dark: #991b1b;
    --info: #0ea5e9;
    --info-light: #e0f2fe;
    --info-dark: #075985;
    --orange: #f97316;
    --orange-light: #ffedd5;
    --orange-dark: #9a3412;
    --purple: #8b5cf6;
    --purple-light: #ede9fe;
    --purple-dark: #5b21b6;

    /* Border */
    --border: #e2e8f0;
    --border-light: #f1f5f9;
    --border-focus: #2563eb;
    --radius-sm: 4px;
    --radius: 8px;
    --radius-lg: 12px;

    /* Shadows */
    --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.04);
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.08);
    --shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.12);
    --shadow-sidebar: 2px 0 8px rgba(0, 0, 0, 0.06);

    /* Spacing */
    --sidebar-width: 240px;
    --header-height: 56px;

    /* Transitions */
    --transition: 0.2s ease;

    /* Font */
    --font-sans: 'Noto Sans SC', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --font-mono: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', monospace;
}

/* ----- Reset & Base ----- */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 14px;
    -webkit-font-smoothing: antialiased;
}

body {
    font-family: var(--font-sans);
    background: var(--bg-body);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    overflow-x: hidden;
}

a {
    color: var(--text-link);
    text-decoration: none;
}
a:hover {
    text-decoration: underline;
}

/* ----- Scrollbar ----- */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}
::-webkit-scrollbar-track {
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background: var(--text-muted);
    border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}

/* ============================================================
   LAYOUT
   ============================================================ */
.app-container {
    display: flex;
    min-height: 100vh;
}

/* ----- Sidebar ----- */
.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-sidebar);
    color: var(--text-inverse);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 100;
    overflow-y: auto;
    box-shadow: var(--shadow-sidebar);
}

.sidebar-header {
    padding: 16px 20px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    flex-shrink: 0;
}

.sidebar-header h1 {
    font-size: 1.1rem;
    font-weight: 700;
    color: #ffffff;
    letter-spacing: 0.5px;
}

.sidebar-header .subtitle {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 2px;
}

/* Navigation groups */
.nav-group {
    padding: 8px 0;
}

.nav-group-title {
    padding: 8px 20px 4px;
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: rgba(255, 255, 255, 0.4);
    font-weight: 600;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 20px;
    color: rgba(255, 255, 255, 0.7);
    text-decoration: none;
    font-size: 0.85rem;
    transition: all var(--transition);
    cursor: pointer;
    border: none;
    background: none;
    width: 100%;
    text-align: left;
    font-family: inherit;
}

.nav-item:hover {
    background: var(--bg-sidebar-hover);
    color: #ffffff;
    text-decoration: none;
}

.nav-item.active {
    background: var(--bg-sidebar-active);
    color: #ffffff;
    font-weight: 600;
}

.nav-item i {
    width: 18px;
    text-align: center;
    font-size: 0.9rem;
    flex-shrink: 0;
}

/* ----- Main Content ----- */
.main-content {
    margin-left: var(--sidebar-width);
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* ----- Header ----- */
.header {
    height: var(--header-height);
    background: var(--bg-header);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    position: sticky;
    top: 0;
    z-index: 50;
    box-shadow: var(--shadow-xs);
}

.header-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.header-breadcrumb {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.header-breadcrumb span {
    color: var(--text-primary);
    font-weight: 600;
}

.header-search {
    display: flex; align-items: center; gap: 4px; margin: 0 auto; position: relative;
}
.header-search .search-input {
    width: 280px; height: 34px; padding: 0 12px; border: 1px solid var(--border); border-radius: 6px; font-size: 0.85rem; outline: none;
}
.header-search .search-input:focus { border-color: var(--primary); }
.header-search .search-btn {
    width: 34px; height: 34px; border: none; background: var(--primary); color: #fff; border-radius: 6px; cursor: pointer;
}
.header-search .search-dropdown {
    position: absolute; top: 100%; left: 0; right: 0; margin-top: 4px;
    background: rgba(255,255,255,0.92); border: 1px solid var(--border); border-radius: 8px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.12); z-index: 1000; max-height: 400px; overflow-y: auto;
}
.header-search .search-module { padding: 6px 0; border-bottom: 1px solid var(--bg-alt); }
.header-search .search-module:last-child { border-bottom: none; }
.header-search .search-module-label { display: block; padding: 2px 12px; font-size: 0.75rem; font-weight: 600; color: var(--primary); text-transform: uppercase; }
.header-search .search-item { padding: 6px 12px; cursor: pointer; font-size: 0.85rem; }
.header-search .search-item:hover { background: var(--bg-alt); }
.header-search .search-item small { color: var(--text-muted); margin-left: 8px; }
.header-search .search-empty { padding: 12px; text-align: center; color: var(--text-muted); font-size: 0.85rem; }

.header-right {
    display: flex;
    align-items: center;
    gap: 16px;
}

.header-user {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.85rem;
    color: var(--text-primary);
}

.header-user .avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--primary);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    font-weight: 600;
}

.header-date {
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* ----- Page Container ----- */
.page-container {
    padding: 20px 24px;
    flex: 1;
    min-width: 0;
    max-width: 100%;
    overflow-x: hidden;
}

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

.page-header h2 {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-primary);
}

.page-header-actions {
    display: flex;
    gap: 8px;
}

/* ============================================================
   SUB-NAV (子标签页导航)
   ============================================================ */
.sub-nav {
    display: flex;
    gap: 2px;
    background: var(--bg-subnav);
    border-radius: var(--radius);
    padding: 4px;
    margin-bottom: 20px;
    border: 1px solid var(--border);
    flex-wrap: wrap;
}

.sub-tab {
    padding: 8px 16px;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-secondary);
    background: transparent;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition);
    font-family: inherit;
    white-space: nowrap;
}

.sub-tab:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.sub-tab.active {
    background: var(--bg-content);
    color: var(--primary);
    font-weight: 600;
    box-shadow: var(--shadow-xs);
}

/* ============================================================
   BUTTONS
   ============================================================ */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    font-size: 0.85rem;
    font-weight: 500;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    cursor: pointer;
    transition: all var(--transition);
    font-family: inherit;
    white-space: nowrap;
    line-height: 1.4;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-primary {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}
.btn-primary:hover:not(:disabled) {
    background: var(--primary-hover);
    border-color: var(--primary-hover);
}

.btn-secondary {
    background: var(--bg-content);
    color: var(--text-primary);
    border-color: var(--border);
}
.btn-secondary:hover:not(:disabled) {
    background: var(--bg-hover);
    border-color: var(--text-muted);
}

.btn-success {
    background: var(--success);
    color: white;
    border-color: var(--success);
}
.btn-success:hover:not(:disabled) {
    background: #059669;
    border-color: #059669;
}

.btn-danger {
    background: var(--danger);
    color: white;
    border-color: var(--danger);
}
.btn-danger:hover:not(:disabled) {
    background: #dc2626;
    border-color: #dc2626;
}

.btn-sm {
    padding: 4px 10px;
    font-size: 0.8rem;
}

.btn-icon {
    padding: 6px 8px;
    min-width: 32px;
    justify-content: center;
}

.btn-icon-sm {
    background: none;
    border: none;
    color: #64748b;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 0.85rem;
    transition: all 0.15s;
}
.btn-icon-sm:hover { background: var(--bg-hover); color: var(--primary); }
.btn-icon-sm.danger:hover { color: var(--danger); }

/* ============================================================
   DATA TABLE
   ============================================================ */
.data-table-wrapper {
    background: var(--bg-card);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    max-width: 100%;
    box-shadow: var(--shadow-xs);
}

.data-table-scrollable {
    overflow-x: auto;
    overflow-y: hidden;
    min-width: 0;
    max-width: 100%;
}

.data-table-scrollable .data-table-toolbar {
    min-width: fit-content;
}

.data-table-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    gap: 12px;
    flex-wrap: wrap;
}

.data-table-toolbar-left {
    display: flex;
    align-items: center;
    gap: 8px;
}

.data-table-toolbar-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}

.data-table th {
    background: var(--bg-subnav);
    color: var(--text-secondary);
    font-weight: 600;
    text-align: left;
    padding: 10px 16px;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.data-table td {
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 300px;
    padding: 10px 16px;
    border-bottom: 1px solid var(--border-light);
    color: var(--text-primary);
    vertical-align: middle;
    word-break: keep-all;
    overflow-wrap: break-word;
}

.data-table tr:last-child td {
    border-bottom: none;
}

.data-table tbody tr:hover {
    background: var(--bg-table-hover);
}

.data-table tbody tr:nth-child(even) {
    background: var(--bg-table-stripe);
}
.data-table tbody tr:nth-child(even):hover {
    background: var(--bg-table-hover);
}

.data-table .col-actions {
    text-align: right;
    white-space: nowrap;
    width: 1%;
}

.data-table .col-actions .btn {
    margin-left: 4px;
}

.data-table .col-id {
    color: var(--text-muted);
    font-family: var(--font-mono);
    font-size: 0.75rem;
}

/* ============================================================
   SEARCH BAR
   ============================================================ */
.search-bar {
    display: flex;
    align-items: center;
    gap: 6px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 6px 12px;
    transition: border-color var(--transition);
    min-width: 240px;
}

.search-bar:focus-within {
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px var(--primary-light);
}

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

.search-bar input {
    border: none;
    background: none;
    outline: none;
    font-size: 0.85rem;
    color: var(--text-primary);
    width: 100%;
    font-family: inherit;
}

.search-bar input::placeholder {
    color: var(--text-placeholder);
}

/* ============================================================
   PAGINATION
   ============================================================ */
.pagination {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-top: 1px solid var(--border);
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.pagination-info {
    display: flex;
    align-items: center;
    gap: 8px;
}

.pagination-buttons {
    display: flex;
    align-items: center;
    gap: 2px;
}

.pagination-btn {
    padding: 4px 10px;
    border: 1px solid var(--border);
    background: var(--bg-content);
    color: var(--text-primary);
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 0.8rem;
    font-family: inherit;
    transition: all var(--transition);
}

.pagination-btn:hover:not(:disabled) {
    background: var(--bg-hover);
    border-color: var(--text-muted);
}

.pagination-btn.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

.pagination-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* ============================================================
   BADGE
   ============================================================ */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 10px;
    font-size: 0.75rem;
    font-weight: 600;
    border-radius: 100px;
    white-space: nowrap;
    line-height: 1.5;
}

.badge-primary { background: var(--primary-light); color: var(--primary-dark); }
.badge-success { background: var(--success-light); color: var(--success-dark); }
.badge-warning { background: var(--warning-light); color: var(--warning-dark); }
.badge-danger { background: var(--danger-light); color: var(--danger-dark); }
.badge-info { background: var(--info-light); color: var(--info-dark); }

/* Status-specific badges */
.badge-draft { background: #f1f5f9; color: #475569; }
.badge-ready { background: var(--primary-light); color: var(--primary-dark); }
.badge-in-progress { background: var(--warning-light); color: var(--warning-dark); }
.badge-completed { background: var(--success-light); color: var(--success-dark); }
.badge-cancelled { background: var(--danger-light); color: var(--danger-dark); }
.badge-orange { background: var(--orange-light); color: var(--orange-dark); }
.badge-purple { background: var(--purple-light); color: var(--purple-dark); }
.badge-muted { background: #e2e8f0; color: #64748b; }
.badge-neutral { background: #f1f5f9; color: #475569; }
.badge-secondary { background: #cbd5e1; color: #334155; }

/* ============================================================
   MODAL
   ============================================================ */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: var(--bg-overlay);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    animation: fadeIn 0.15s ease;
    overflow-y: auto;
    padding: 20px 0;
    overscroll-behavior: contain;
    user-select: none;
}

.modal {
    background: var(--bg-content);
    border-radius: var(--radius-lg);
    width: 560px;
    max-width: 90vw;
    max-height: 85vh;
    min-height: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-lg);
    animation: slideUp 0.2s ease;
    user-select: text;
    -webkit-user-select: text;
}

.modal.wide {
    width: 720px;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
}

.modal-header h3 {
    font-size: 1rem;
    font-weight: 600;
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.2rem;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px;
    line-height: 1;
    border-radius: var(--radius-sm);
    transition: all var(--transition);
}

.modal-close:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.modal-body {
    padding: 20px;
    overflow-y: auto;
    flex: 1 1 auto;
    min-height: 0;
    max-height: calc(85vh - 100px);
    overscroll-behavior: contain;
}

.modal-footer {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    padding: 12px 20px;
    border-top: 1px solid var(--border);
}

/* ============================================================
   READ-ONLY FIELD (详情查看)
   ============================================================ */
.readonly-field {
    padding: 8px 12px;
    background: var(--bg-input, #f8f9fa);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 0.85rem;
    line-height: 1.6;
    min-height: 36px;
}

/* ============================================================
   FORMS
   ============================================================ */
.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.form-row .third {
    grid-column: span 1;
}
.form-row .fourth {
    grid-column: span 1;
}

/* 表单复选框 */
.form-checkbox {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.85rem;
    color: var(--text-primary);
    cursor: pointer;
    padding: 4px 0;
}
.form-checkbox input[type="checkbox"] {
    width: 16px;
    height: 16px;
    cursor: pointer;
    accent-color: var(--primary);
}

.form-row-full {
    grid-column: 1 / -1;
}

.form-fieldset {
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 16px;
    margin: 12px 0;
}
.form-group .form-group { margin: 0; }
.form-group .form-group .form-input { margin-top: 0; }
.form-checkbox-wrapper { display: flex; align-items: flex-start; padding-top: 20px; }
.form-checkbox-wrapper .form-checkbox { padding: 0; margin: 0; }

.form-fieldset legend {
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--text-muted);
    padding: 0 8px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-bottom: 16px;
    position: relative;
}

.form-label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-primary);
}

.form-label .required {
    color: var(--danger);
    margin-left: 2px;
}

.form-control, .form-input {
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    color: var(--text-primary);
    background: var(--bg-input);
    font-family: inherit;
    transition: border-color var(--transition), box-shadow var(--transition);
    width: 100%;
    box-sizing: border-box;
}

.form-control:focus, .form-input:focus {
    outline: none;
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px var(--primary-light);
}

.form-control::placeholder, .form-input::placeholder {
    color: var(--text-placeholder);
}

.form-control:disabled, .form-input:disabled {
    background: var(--bg-disabled);
    cursor: not-allowed;
}

select.form-control, select.form-input {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%2364748b' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    padding-right: 32px;
}

textarea.form-control {
    min-height: 80px;
    resize: vertical;
}

.form-help {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.form-error {
    font-size: 0.75rem;
    color: var(--danger);
}

/* ============================================================
   STATS CARDS (Dashboard)
   ============================================================ */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.stat-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    padding: 20px;
    display: flex;
    align-items: flex-start;
    gap: 16px;
    box-shadow: var(--shadow-xs);
    transition: box-shadow var(--transition);
}

.stat-card:hover {
    box-shadow: var(--shadow);
}

.stat-card-icon {
    width: 44px;
    height: 44px;
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    flex-shrink: 0;
}

.stat-card-icon.blue { background: var(--primary-light); color: var(--primary); }
.stat-card-icon.green { background: var(--success-light); color: var(--success); }
.stat-card-icon.amber { background: var(--warning-light); color: var(--warning); }
.stat-card-icon.red { background: var(--danger-light); color: var(--danger); }
.stat-card-icon.purple { background: #ede9fe; color: #7c3aed; }

.stat-card-body {
    flex: 1;
    min-width: 0;
}

.stat-card-label {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

.stat-card-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1.2;
}

.stat-card-trend {
    font-size: 0.75rem;
    margin-top: 4px;
}

.stat-card-trend.up { color: var(--success); }
.stat-card-trend.down { color: var(--danger); }

/* Alert stats cards */
.stats-row {
    display: flex;
    gap: 16px;
}
.stats-card {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px 20px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--bg-card);
    min-width: 160px;
}
.stats-card i { font-size: 1.5rem; }
.stats-card .stat-num { font-size: 1.8rem; font-weight: 700; line-height: 1; }
.stats-card .stat-label { font-size: 0.8rem; color: var(--text-secondary); }
.stats-card.alert-low { border-left: 4px solid var(--danger); }
.stats-card.alert-low i { color: var(--danger); }
.stats-card.alert-low .stat-num { color: var(--danger); }
.stats-card.alert-high { border-left: 4px solid var(--warning); }
.stats-card.alert-high i { color: var(--warning); }
.stats-card.alert-high .stat-num { color: var(--warning); }

/* ============================================================
   TOAST
   ============================================================ */
.toast-container {
    position: fixed;
    top: 16px;
    right: 16px;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toast {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    border-radius: var(--radius);
    color: white;
    font-size: 0.85rem;
    box-shadow: var(--shadow-lg);
    min-width: 300px;
    max-width: 420px;
    animation: slideInRight 0.3s ease;
}

.toast-success { background: var(--success); }
.toast-error { background: var(--danger); }
.toast-warning { background: var(--warning); }
.toast-info { background: var(--info); }

.toast i {
    font-size: 1.1rem;
    flex-shrink: 0;
}

.toast-close {
    margin-left: auto;
    background: none;
    border: none;
    color: inherit;
    opacity: 0.8;
    cursor: pointer;
    padding: 2px;
    font-size: 1rem;
}

.toast-close:hover {
    opacity: 1;
}

/* ============================================================
   CONFIRM DIALOG
   ============================================================ */
.confirm-dialog .modal {
    width: 400px;
}

.confirm-dialog .modal-body {
    text-align: center;
    padding: 32px 20px;
}

.confirm-dialog .confirm-icon {
    font-size: 2.5rem;
    margin-bottom: 12px;
}

.confirm-dialog .confirm-icon.warning {
    color: var(--warning);
}

.confirm-dialog .confirm-icon.danger {
    color: var(--danger);
}

.confirm-dialog .confirm-message {
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-top: 8px;
}

/* ============================================================
   LOADING / EMPTY / ERROR STATES
   ============================================================ */
.loading-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 20px;
    color: var(--text-muted);
}

.loading-spinner {
    width: 36px;
    height: 36px;
    border: 3px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin-bottom: 12px;
}

.loading-state p {
    font-size: 0.85rem;
}

.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 20px;
    color: var(--text-muted);
}

.empty-state i {
    font-size: 3rem;
    margin-bottom: 12px;
    color: var(--border);
}

.empty-state p {
    font-size: 0.9rem;
}

.error-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 20px;
    color: var(--danger);
}

.error-state i {
    font-size: 2rem;
    margin-bottom: 8px;
}

.error-state p {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 12px;
}

/* Inline loading overlay for DataTable */
.table-loading-overlay {
    position: absolute;
    inset: 0;
    background: rgba(255, 255, 255, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
}

.data-table-wrapper {
    position: relative;
}

/* ============================================================
   LOGIN OVERLAY
   ============================================================ */
.login-overlay {
    position: fixed;
    inset: 0;
    background: var(--bg-body);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
}

/* 重建验证标记 — 仅用于 CI/CD 检测，位于登录页下方，用户不可见 */
#rebuild-v3-check {
    position: fixed;
    bottom: 0;
    right: 0;
    width: 1px;
    height: 1px;
    font-size: 1px;
    color: transparent;
    overflow: hidden;
    pointer-events: none;
    z-index: -1;
}

.login-card {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    padding: 40px;
    width: 400px;
    max-width: 90vw;
    box-shadow: var(--shadow-lg);
}

.login-card h1 {
    font-size: 1.25rem;
    font-weight: 700;
    text-align: center;
    margin-bottom: 4px;
    color: var(--text-primary);
}

.login-card .login-subtitle {
    text-align: center;
    color: var(--text-secondary);
    font-size: 0.85rem;
    margin-bottom: 24px;
}

.login-card .error-container {
    min-height: 34px;
    margin-bottom: 16px;
}

.login-card .login-error {
    background: var(--danger-light);
    color: var(--danger-dark);
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    font-size: 0.8rem;
    text-align: center;
}

.login-card .form-group {
    margin-bottom: 16px;
}

.login-card .btn {
    width: 100%;
    justify-content: center;
    padding: 10px;
    margin-top: 8px;
}

/* ============================================================
   CHARTS (simple CSS-based for dashboard)
   ============================================================ */
.chart-container {
    background: var(--bg-card);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    padding: 20px;
    box-shadow: var(--shadow-xs);
}

.chart-container h4 {
    font-size: 0.9rem;
    font-weight: 600;
    margin-bottom: 16px;
    color: var(--text-primary);
}

/* Simple bar chart */
.bar-chart {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    height: 160px;
    padding: 0 8px;
}

.bar-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    height: 100%;
    justify-content: flex-end;
}

.bar {
    width: 100%;
    max-width: 40px;
    border-radius: var(--radius-sm) var(--radius-sm) 0 0;
    background: var(--primary);
    transition: height 0.5s ease;
    min-height: 4px;
}

.bar-label {
    font-size: 0.7rem;
    color: var(--text-muted);
    white-space: nowrap;
}

/* Line chart */
.line-chart {
    width: 100%; padding: 4px 0;
}
.line-chart svg { overflow: visible; }

/* Donut chart */
.donut-chart {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 24px;
}

.donut-ring {
    width: 100px;
    height: 100px;
    border-radius: 50%;
    position: relative;
}

.donut-center {
    position: absolute;
    inset: 12px;
    border-radius: 50%;
    background: var(--bg-card);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--text-primary);
}

.donut-legend {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.donut-legend-item {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.donut-legend-item .dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}

/* ============================================================
   UTILITY CLASSES
   ============================================================ */
.text-primary { color: var(--primary) !important; }
.text-success { color: var(--success) !important; }
.text-warning { color: var(--warning) !important; }
.text-danger { color: var(--danger) !important; }
.text-muted { color: var(--text-muted) !important; }
.text-secondary { color: var(--text-secondary) !important; }

.text-center { text-align: center; }
.text-right { text-align: right; }

.mt-2 { margin-top: 8px; }
.mt-4 { margin-top: 16px; }
.mb-2 { margin-bottom: 8px; }
.mb-4 { margin-bottom: 16px; }
.ml-2 { margin-left: 8px; }
.mr-2 { margin-right: 8px; }

.flex { display: flex; }
.flex-center { display: flex; align-items: center; justify-content: center; }
.flex-between { display: flex; align-items: center; justify-content: space-between; }
.gap-2 { gap: 8px; }
.gap-4 { gap: 16px; }

.truncate {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.font-mono {
    font-family: var(--font-mono);
}

/* ============================================================
   ANIMATIONS
   ============================================================ */
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

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

@keyframes slideInRight {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ============================================================
   AMOUNT FIELD
   ============================================================ */
.amount-input-row {
    display: flex;
    align-items: center;
    gap: 6px;
}
.amount-input-row .amount-input {
    flex: 1;
    min-width: 0;
}
.amount-unit {
    color: var(--text-muted);
    font-size: 0.85rem;
    white-space: nowrap;
    flex-shrink: 0;
}

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 768px) {
    .sidebar {
        width: 60px;
    }
    .sidebar-header h1,
    .sidebar-header .subtitle,
    .nav-group-title,
    .nav-item span {
        display: none;
    }
    .nav-item {
        justify-content: center;
        padding: 12px;
    }
    .nav-item i {
        margin: 0;
    }
    .main-content {
        margin-left: 60px;
    }
    .form-row {
        grid-template-columns: 1fr;
    }
    .stats-grid {
        grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    }
    .page-container {
        padding: 16px;
    }
}

/* ============================================================
   DATA MANAGEMENT — 合一视图（设备树 + 内容面板）
   ============================================================ */
.dm-split-layout {
    display: flex;
    gap: 20px;
    align-items: flex-start;
}
.dm-tree-panel {
    flex: 0 0 410px;
    background: var(--bg-card);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    padding: 12px;
    max-height: 70vh;
    overflow-y: auto;
}
.dm-content-panel {
    flex: 1;
    min-width: 0;
}
.dm-tree-header {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    display: flex;
    align-items: center;
    justify-content: space-between;
    letter-spacing: 0.5px;
    padding: 4px 8px 8px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 8px;
}
.dm-tree-item {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 8px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 0.85rem;
    color: var(--text-primary);
    transition: background var(--transition);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.dm-tree-item:hover { background: var(--bg-hover); }
.dm-tree-item.selected { background: var(--primary-light); color: var(--primary); font-weight: 600; }
.dm-tree-item .tree-icon { flex-shrink: 0; width: 16px; text-align: center; font-size: 0.8rem; color: var(--text-secondary); }
.dm-tree-children { margin-left: 20px; border-left: 1px solid var(--border); padding-left: 8px; }
.dm-tree-customer-group { margin-top: 2px; margin-bottom: 2px; }
.dm-tree-customer-group .customer-group-header { font-weight: 600; color: var(--text-primary); cursor: pointer; background: var(--bg-subnav); border-radius: var(--radius-sm); padding: 4px 8px; margin-bottom: 2px; transition: background var(--transition); }
.dm-tree-customer-group .customer-group-header:hover { background: var(--bg-hover); }
.dm-tree-customer-group .customer-group-header .tree-icon { color: var(--primary); }
.dm-tree-customer-group .dm-tree-children { margin-left: 20px; border-left: 1px solid var(--border); padding-left: 8px; }
.dm-tree-customer-group .dm-tree-children .dm-tree-item { padding-left: 8px; }
.dm-tree-badge { font-size: 0.7rem; padding: 1px 6px; border-radius: 10px; background: var(--bg-subnav); color: var(--text-secondary); margin-left: auto; }
.dm-empty-tree { padding: 24px 8px; text-align: center; color: var(--text-secondary); font-size: 0.85rem; }
.dm-sample-header { background: var(--bg-card); border-radius: var(--radius); border: 1px solid var(--border); padding: 16px; margin-bottom: 16px; }
.dm-sample-header h3 { font-size: 1rem; font-weight: 600; margin-bottom: 4px; }
.dm-sample-meta { font-size: 0.82rem; color: var(--text-secondary); display: flex; gap: 16px; flex-wrap: wrap; margin-top: 8px; }
.dm-sample-meta span { display: inline-flex; align-items: center; gap: 4px; }
.dm-sample-actions { display: flex; gap: 8px; margin-top: 12px; }
.dm-section { background: var(--bg-card); border-radius: var(--radius); border: 1px solid var(--border); padding: 16px; margin-bottom: 16px; }
.dm-section h4 { font-size: 0.9rem; font-weight: 600; margin-bottom: 12px; display: flex; align-items: center; justify-content: space-between; }
.dm-empty-state { padding: 32px; text-align: center; color: var(--text-secondary); font-size: 0.85rem; }
.dm-select-hint { display: flex; align-items: center; justify-content: center; min-height: 300px; color: var(--text-secondary); font-size: 0.9rem; }
.dm-data-list { width: 100%; border-collapse: collapse; font-size: 0.83rem; }
.dm-data-list th { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--border); font-weight: 600; color: var(--text-secondary); font-size: 0.8rem; }
.dm-data-list td { padding: 6px 8px; border-bottom: 1px solid var(--border-light); }
.dm-data-list tr:last-child td { border-bottom: none; }
/* 操作列：按钮填满单元格宽度并右对齐 */
.dm-data-list .dm-actions { display: flex; gap: 4px; justify-content: flex-end; }
.dm-data-list th:last-child { text-align: right; padding-right: 12px; }
.dm-current-badge { font-size: 0.7rem; padding: 1px 6px; border-radius: 10px; background: var(--success); color: #fff; }
.field-error { border-color: var(--danger) !important; }
.field-error-msg { color: var(--danger); font-size: 0.75rem; position: absolute; top: 100%; left: 0; white-space: nowrap; }
.form-alert { background: #fff0f0; border: 1px solid var(--danger); border-radius: var(--radius); padding: 8px 12px; margin-bottom: 12px; font-size: 0.82rem; color: var(--danger); }

/* ===== 权限管理 ===== */
.perm-toolbar { display: flex; align-items: center; gap: 12px; margin-bottom: 4px; }
.perm-tables { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; max-height: 68vh; overflow-y: auto; padding: 2px; }
.perm-module { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; break-inside: avoid; }
.perm-module-title { padding: 8px 14px; font-size: 0.85rem; font-weight: 700; color: var(--primary); background: var(--bg-subnav); border-bottom: 1px solid var(--border); }
.perm-row { display: flex; align-items: center; gap: 10px; padding: 7px 14px; cursor: pointer; user-select: none; transition: background 0.15s, border-color 0.15s; border-bottom: 1px solid var(--border); border-left: 3px solid transparent; }
.perm-row:last-child { border-bottom: none; }
.perm-row:hover { background: var(--bg-hover); }
.perm-row.checked { background: var(--primary-light); border-left-color: var(--primary); }
.perm-row input[type="checkbox"] { margin: 0; flex-shrink: 0; accent-color: var(--primary); }
.perm-code { font-family: monospace; font-size: 0.78rem; min-width: 150px; color: var(--text-primary); }
.perm-name { color: var(--text-secondary); font-size: 0.78rem; }

/* ============================================================
   PRODUCT CATALOG — 产品型谱
   ============================================================ */
.tech-params-textarea {
    font-family: var(--font-mono, 'Consolas', 'Courier New', monospace);
    font-size: 0.85rem;
    line-height: 1.6;
    min-height: 140px;
    resize: vertical;
}

/* 技术状态管理 — 版本对比并排布局 */
.tech-compare {
    display: flex;
    gap: 0;
    align-items: stretch;
    overflow: hidden;
    min-width: 0;
}
.tech-compare-col {
    flex: 1;
    padding: 12px;
    border-radius: 6px;
    min-width: 0;
}
.tech-compare-before {
    background: #fff8f0;
    border: 1px solid #fde68a;
}
.tech-compare-after {
    background: #f0fdf4;
    border: 1px solid #86efac;
}
.tech-compare-header {
    font-weight: 700;
    font-size: 0.95rem;
    padding-bottom: 8px;
    margin-bottom: 12px;
    border-bottom: 2px solid;
    text-align: center;
}
.tech-compare-before .tech-compare-header {
    color: #92400e;
    border-color: #fde68a;
}
.tech-compare-after .tech-compare-header {
    color: #166534;
    border-color: #86efac;
}
.tech-compare-divider {
    width: 2px;
    background: var(--border-color, #e2e8f0);
    margin: 0 8px;
    align-self: stretch;
}
.tech-compare-col .form-group { margin-bottom: 8px; }
.tech-compare-col .form-group:last-child { margin-bottom: 0; }

/* ===== 报表看板 — 出差甘特图 ===== */
.gantt-wrapper {
    overflow-x: auto;
    border: 1px solid var(--border-color, #e2e8f0);
    border-radius: 6px;
    background: var(--bg-content, #fff);
}
.gantt-header {
    background: #f8fafc;
    border-bottom: 1px solid var(--border-color, #e2e8f0);
    font-size: 11px;
    color: var(--text-secondary, #64748b);
}
.gantt-row:hover {
    background: #f8fafc;
}
.gantt-row > div:first-child {
    position: sticky;
    left: 0;
    background: inherit;
    z-index: 1;
}
.phase-dot.done { opacity: 1; }
.phase-dot.active { opacity: 1; box-shadow: 0 0 0 2px var(--primary-light, #dbeafe); }
.phase-dot { transition: all 0.2s; }
.material-picker { position: relative; width: 100%; min-width: 0; }
.material-picker .picker-input-wrapper { width: 100%; min-width: 0; position: relative; }
.material-picker .picker-clear {
    position: absolute;
    right: 4px;
    top: 50%;
    transform: translateY(-50%);
    border: none;
    background: transparent;
    font-size: 1.2rem;
    cursor: pointer;
    color: var(--text-muted, #999);
    line-height: 1;
    padding: 0 4px;
    z-index: 2;
}
.material-picker .picker-search {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    padding-right: 24px;
    text-overflow: ellipsis;
    overflow: hidden;
    white-space: nowrap;
    box-sizing: border-box;
}
.picker-dropdown {
    position: absolute;
    left: 0;
    right: 0;
    top: calc(100% + 2px);
    z-index: 1050;
    background: rgba(255,255,255,0.92);
    border: 1px solid #d1d5db;
    border-radius: 6px;
    box-shadow: 0 6px 20px rgba(0,0,0,0.18);
    max-height: 280px;
    overflow-y: auto;
}

.picker-item {
    padding: 8px 12px;
    cursor: pointer;
    display: flex;
    gap: 8px;
    align-items: center;
    font-size: 0.82rem;
    border-bottom: 1px solid #f0f0f0;
    overflow: hidden;
    white-space: nowrap;
}
.picker-item:hover { background: #f5f5f5; }
.picker-item.active { background: #e8f0fe; }
.picker-item:last-child { border-bottom: none; }
.picker-sku { color: var(--text-muted, #999); min-width: 60px; overflow: hidden; text-overflow: ellipsis; }
.picker-name { flex: 1; overflow: hidden; text-overflow: ellipsis; }
.picker-spec { color: var(--text-muted, #999); max-width: 100px; overflow: hidden; text-overflow: ellipsis; }
.picker-unit { color: var(--text-muted, #999); width: 40px; text-align: right; }
.line-items-table { width: 100%; }
.line-items-table td.li-material { min-width: 200px; }

/* ===== Toggle Switch ===== */
.toggle-switch { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; user-select: none; }
.toggle-switch input[type="checkbox"] { display: none; }
.toggle-slider { position: relative; width: 44px; height: 24px; background: #ccc; border-radius: 12px; transition: background 0.2s; flex-shrink: 0; }
.toggle-slider::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; background: #fff; border-radius: 50%; transition: transform 0.2s; }
.toggle-switch input:checked + .toggle-slider { background: var(--primary, #0ea5e9); }
.toggle-switch input:checked + .toggle-slider::after { transform: translateX(20px); }
.toggle-label { font-size: 0.85rem; color: var(--text, #333); min-width: 2em; }

