/* ===================================================
   ERP 系统样式表
   严格遵循大亮ERP设计规范，不得偏离
   =================================================== */

/* --- Reset & Base --- */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: "Segoe UI", Arial, sans-serif;
    font-size: 14px;
    color: #222;
    background: #f3f5f9;
    line-height: 1.5;
}

a {
    color: #2563eb;
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

/* --- Layout --- */
.layout {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: 240px;
    min-width: 240px;
    background: #1f2937;
    color: #d1d5db;
    height: 100vh;
    position: fixed;
    top: 0;
    left: 0;
    overflow-y: auto;
    z-index: 100;
    transition: all 0.3s ease;
}

.content {
    margin-left: 240px;
    flex: 1;
    min-height: 100vh;
    padding: 0;
    transition: margin-left 0.2s;
}

/* --- Sidebar --- */
.sidebar-header {
    padding: 16px 16px;
    border-bottom: 1px solid #374151;
}

.sidebar-header h2 {
    color: #fff;
    font-size: 15px;
    font-weight: 600;
    line-height: 1.4;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-header .version {
    font-size: 11px;
    color: #9ca3af;
    margin-top: 2px;
}

/* 迷你侧边栏样式 */
@media (max-width: 1024px) {
    /* 隐藏所有 span 元素（文字），只显示 emoji 图标 */
    .sidebar.collapsed .sidebar-header h2,
    .sidebar.collapsed .sidebar-header .version,
    .sidebar.collapsed .nav-item span,
    .sidebar.collapsed .nav-group summary span,
    .sidebar.collapsed .nav-single span {
        display: none;
    }
    
    /* 让 emoji 图标居中显示 */
    .sidebar.collapsed .sidebar-header {
        padding: 20px 0;
        text-align: center;
    }
    
    .sidebar.collapsed .sidebar-header h2 {
        font-size: 16px;
    }
    
    .sidebar.collapsed .nav-group summary {
        padding: 10px 0;
        justify-content: center;
        font-size: 14px;
    }
    
    .sidebar.collapsed .nav-item {
        padding: 8px 0;
        text-align: center;
        font-size: 14px;
    }
    
    .sidebar.collapsed .nav-single {
        padding: 10px 0;
        text-align: center;
        font-size: 14px;
        font-weight: normal;
    }
    
    /* 迷你模式下导航项居中 */
    .sidebar.collapsed .nav-item.active {
        padding-left: 0;
        border-left: none;
        border-bottom: 3px solid #2563eb;
    }
}

.sidebar nav {
    padding: 8px 0;
}

.sidebar .nav-group {
    margin-bottom: 2px;
}

.sidebar .nav-group summary {
    padding: 10px 16px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 600;
    color: #d1d5db;
    list-style: none;
    display: flex;
    align-items: center;
    gap: 8px;
    user-select: none;
}

.sidebar .nav-group summary::-webkit-details-marker {
    display: none;
}

.sidebar .nav-group summary::before {
    content: '▸';
    font-size: 10px;
    transition: transform 0.2s;
    display: inline-block;
}

.sidebar .nav-group[open] summary::before {
    transform: rotate(90deg);
}

.sidebar .nav-group summary:hover {
    background: #374151;
}

.sidebar .nav-item {
    display: block;
    padding: 8px 16px 8px 40px;
    color: #d1d5db;
    font-size: 13px;
    transition: background 0.15s, color 0.15s;
}

.sidebar .nav-item:hover {
    background: #374151;
    color: #fff;
    text-decoration: none;
}

.sidebar .nav-item.active {
    background: #374151;
    color: #fff;
    border-left: 3px solid #2563eb;
    padding-left: 37px;
}

/* 迷你模式下导航项居中 */
@media (max-width: 1024px) {
    .sidebar.collapsed .nav-item {
        padding: 8px 0;
        text-align: center;
        font-size: 12px;
    }
    
    .sidebar.collapsed .nav-item.active {
        padding-left: 0;
        border-left: none;
        border-bottom: 3px solid #2563eb;
    }
}

.sidebar .nav-single {
    display: block;
    padding: 10px 16px;
    color: #d1d5db;
    font-size: 13px;
    font-weight: 600;
    transition: background 0.15s, color 0.15s;
}

.sidebar .nav-single:hover {
    background: #374151;
    color: #fff;
    text-decoration: none;
}

.sidebar .nav-single.active {
    background: #374151;
    color: #fff;
    border-left: 3px solid #2563eb;
    padding-left: 13px;
}

/* --- Page Header --- */
.page-header {
    background: #fff;
    padding: 16px 24px;
    border-bottom: 1px solid #e5e7eb;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.page-header h1 {
    font-size: 20px;
    font-weight: 600;
    color: #222;
}

.page-header .actions {
    display: flex;
    gap: 8px;
    align-items: center;
}

/* --- Content Section --- */
.content section {
    padding: 20px 24px;
}

/* --- Cards --- */
.card {
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    padding: 12px;
    margin-bottom: 16px;
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
    padding-bottom: 8px;
    border-bottom: 1px solid #f3f5f9;
}

.card-header h3 {
    font-size: 16px;
    font-weight: 600;
}

/* --- Stat Cards --- */
.stat-cards {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
    margin-bottom: 20px;
}

.stat-card {
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    padding: 16px;
    text-align: center;
}

.stat-card .stat-value {
    font-size: 28px;
    font-weight: 700;
    color: #2563eb;
}

.stat-card .stat-label {
    font-size: 13px;
    color: #6b7280;
    margin-top: 4px;
}

/* --- Product Color Tags --- */
.color-tag {
    display: inline-block;
    background: #e0f2fe;
    color: #0369a1;
    padding: 4px 10px;
    border-radius: 6px;
    font-size: 13px;
    margin-right: 6px;
    margin-bottom: 6px;
    font-weight: 500;
}

.color-tag .color-all {
    background: #dcfce7;
    color: #15803d;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 11px;
    margin-left: 4px;
    font-weight: 600;
}


.stat-card.warning .stat-value {
    color: #f59e0b;
}

.stat-card.danger .stat-value {
    color: #ef4444;
}

.stat-card.success .stat-value {
    color: #10b981;
}

/* --- Buttons --- */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 8px 16px;
    font-size: 13px;
    font-family: inherit;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    background: #fff;
    color: #374151;
    cursor: pointer;
    transition: all 0.15s;
    text-decoration: none;
    white-space: nowrap;
}

.btn:hover {
    background: #f9fafb;
    text-decoration: none;
}

.btn.primary {
    background: #2563eb;
    color: #fff;
    border-color: #2563eb;
}

.btn.primary:hover {
    background: #1d4ed8;
}

.btn.danger {
    background: #ef4444;
    color: #fff;
    border-color: #ef4444;
}

.btn.danger:hover {
    background: #dc2626;
}

.btn.success {
    background: #10b981;
    color: #fff;
    border-color: #10b981;
}

.btn.success:hover {
    background: #059669;
}

.btn.warning {
    background: #f59e0b;
    color: #fff;
    border-color: #f59e0b;
}

.btn.warning:hover {
    background: #d97706;
}

.btn.sm {
    padding: 4px 10px;
    font-size: 12px;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* --- Tags / Status Pills --- */
.tag {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 500;
}

.tag.draft {
    background: #fef3c7;
    color: #92400e;
}

.tag.released, .tag.active {
    background: #d1fae5;
    color: #065f46;
}

.tag.obsolete, .tag.cancelled {
    background: #fee2e2;
    color: #991b1b;
}

.tag.current, .tag.completed {
    background: #dbeafe;
    color: #1e40af;
}

.tag.producing {
    background: #e0e7ff;
    color: #3730a3;
}

.tag.shipped {
    background: #ccfbf1;
    color: #134e4a;
}

.tag.partial {
    background: #fef3c7;
    color: #92400e;
}

.tag.paid {
    background: #d1fae5;
    color: #065f46;
}

.tag.unpaid {
    background: #fee2e2;
    color: #991b1b;
}

.tag.overdue {
    background: #fee2e2;
    color: #991b1b;
}

.tag.today {
    background: #ffedd5;
    color: #9a3412;
}

.tag.soon {
    background: #fef3c7;
    color: #92400e;
}

/* --- Tables --- */
.table-wrapper {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

table th, table td {
    padding: 10px 12px;
    text-align: left;
    border-bottom: 1px solid #e5e7eb;
}

table th {
    background: #f9fafb;
    font-weight: 600;
    color: #374151;
    white-space: nowrap;
}

table tr:hover {
    background: #f9fafb;
}

table .actions {
    white-space: nowrap;
}

table .actions a, table .actions button {
    margin-right: 4px;
}

/* --- Forms --- */
.form-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
}

.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: #374151;
    margin-bottom: 4px;
}

.form-group label .required {
    color: #ef4444;
}

.form-group input[type="text"],
.form-group input[type="number"],
.form-group input[type="email"],
.form-group input[type="password"],
.form-group input[type="date"],
.form-group input[type="tel"],
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    font-size: 13px;
    font-family: inherit;
    color: #222;
    background: #fff;
    transition: border-color 0.15s;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: #2563eb;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.form-group textarea {
    resize: vertical;
    min-height: 80px;
}

.form-group .hint {
    font-size: 12px;
    color: #6b7280;
    margin-top: 2px;
}

.form-group .error {
    font-size: 12px;
    color: #ef4444;
    margin-top: 2px;
}

.form-group.full-width {
    grid-column: 1 / -1;
}

.checkbox-group {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
}

.checkbox-group label {
    display: flex;
    align-items: center;
    gap: 4px;
    font-weight: normal;
    cursor: pointer;
}

/* --- Modal --- */

/* 模式1：.modal-overlay 直接作为弹窗容器（大部分页面使用） */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    justify-content: center;
    align-items: center;
    padding: 16px;
    overflow-y: auto;
}

.modal-overlay.active {
    display: flex;
}

/* 模式2：.modal 包裹 .modal-overlay（detail.php 等） */
.modal {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 1000;
    background: rgba(0, 0, 0, 0.5);
    justify-content: center;
    align-items: center;
    padding: 16px;
}

.modal > .modal-overlay {
    display: none;
}

.modal-body {
    background: #fff;
    border-radius: 8px;
    width: 95vw;
    max-width: 980px;
    max-height: 85vh;
    overflow-y: auto;
    padding: 24px;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
    padding-bottom: 12px;
    border-bottom: 1px solid #e5e7eb;
}

.modal-header h2 {
    font-size: 18px;
    font-weight: 600;
}

.modal-close {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: #6b7280;
    padding: 4px;
}

.modal-close:hover {
    color: #222;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 20px;
    padding-top: 16px;
    border-top: 1px solid #e5e7eb;
}

/* --- Filter Bar --- */
.filter-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: center;
    margin-bottom: 16px;
}

.filter-group {
    display: flex;
    align-items: center;
    gap: 8px;
}

.filter-group label {
    font-size: 13px;
    font-weight: 600;
    color: #374151;
    white-space: nowrap;
}

.filter-form {
    display: flex;
    align-items: center;
    gap: 6px;
}

.filter-input {
    padding: 6px 12px;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    font-size: 13px;
    font-family: inherit;
    min-width: 200px;
}

.filter-bar select,
.filter-bar input[type="text"] {
    padding: 6px 12px;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    font-size: 13px;
    font-family: inherit;
}

/* --- Pagination --- */
.pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 4px;
    margin-top: 16px;
}

.pagination a, .pagination span {
    padding: 6px 12px;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    font-size: 13px;
    color: #374151;
}

.pagination a:hover {
    background: #f9fafb;
    text-decoration: none;
}

.pagination .active {
    background: #2563eb;
    color: #fff;
    border-color: #2563eb;
}

.pagination .disabled {
    opacity: 0.5;
    pointer-events: none;
}

/* --- Alert / Message --- */
.alert {
    padding: 12px 16px;
    border-radius: 6px;
    margin-bottom: 16px;
    font-size: 13px;
}

.alert.success {
    background: #d1fae5;
    color: #065f46;
    border: 1px solid #a7f3d0;
}

.alert.error {
    background: #fee2e2;
    color: #991b1b;
    border: 1px solid #fecaca;
}

.alert.warning {
    background: #fef3c7;
    color: #92400e;
    border: 1px solid #fde68a;
}

.alert.info {
    background: #dbeafe;
    color: #1e40af;
    border: 1px solid #bfdbfe;
}

/* --- Empty State --- */
.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: #6b7280;
}

.empty-state .icon {
    font-size: 48px;
    margin-bottom: 12px;
}

.empty-state p {
    font-size: 14px;
}

/* --- Tabs --- */
.tabs {
    display: flex;
    border-bottom: 2px solid #e5e7eb;
    margin-bottom: 16px;
}

.tabs a {
    padding: 8px 16px;
    font-size: 13px;
    color: #6b7280;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
}

.tabs a:hover {
    color: #2563eb;
    text-decoration: none;
}

.tabs a.active {
    color: #2563eb;
    border-bottom-color: #2563eb;
    font-weight: 600;
}

/* --- Detail View --- */
.detail-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
}

.detail-item {
    background: #f8fafc;
    border-radius: 12px;
    padding: 16px;
    transition: all 0.3s;
    border: 1px solid #e2e8f0;
}

.detail-item:hover {
    background: #f1f5f9;
    border-color: #cbd5e1;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}

.detail-item .label {
    font-size: 12px;
    color: #64748b;
    font-weight: 500;
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.detail-item .value {
    font-size: 16px;
    color: #1e293b;
    font-weight: 600;
}

/* ================================
   订单号卡片特殊样式
   ================================ */
.detail-item.order-number {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    position: relative;
    overflow: hidden;
}

.detail-item.order-number::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23ffffff' fill-opacity='0.05'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V2h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V2H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3A");
    opacity: 0.3;
}

.detail-item.order-number .label {
    color: rgba(255, 255, 255, 0.8);
}

.detail-item.order-number .value {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 20px;
    font-weight: 700;
}

.order-number-display {
    font-family: 'Monaco', 'Consolas', monospace;
    letter-spacing: 1px;
}

.copy-btn {
    background: rgba(255, 255, 255, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.3);
    color: white;
    padding: 6px 12px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 4px;
}

.copy-btn:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: scale(1.05);
}

.copy-btn.copied {
    background: #16a34a;
    border-color: #16a34a;
}

/* 订单金额卡片特殊样式 */
.detail-item.amount {
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
    color: white;
    border: none;
}

.detail-item.amount .label {
    color: rgba(255, 255, 255, 0.85);
}

.detail-item.amount .value {
    font-size: 20px;
    font-weight: 700;
}

/* --- BOM Tree --- */
.bom-tree {
    padding-left: 20px;
}

.bom-tree li {
    list-style: none;
    padding: 4px 0;
}

.bom-tree .bom-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    border-radius: 6px;
}

.bom-tree .bom-item:hover {
    background: #f9fafb;
}

/* --- Responsive --- */
@media (max-width: 1280px) {
    .form-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .stat-cards {
        grid-template-columns: repeat(2, 1fr);
    }

    .detail-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 768px) {
    .form-grid {
        grid-template-columns: 1fr;
    }

    .stat-cards {
        grid-template-columns: 1fr;
    }

    .detail-grid {
        grid-template-columns: 1fr;
    }
}

/* --- Login Page --- */
.login-wrapper {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    background: #f3f5f9;
}

.login-box {
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    padding: 32px;
    width: 400px;
    max-width: 95vw;
}

.login-box h1 {
    text-align: center;
    font-size: 22px;
    margin-bottom: 24px;
    color: #222;
}

.login-box .form-group {
    margin-bottom: 16px;
}

.login-box .btn {
    width: 100%;
    justify-content: center;
    padding: 10px;
}

/* --- Utility --- */
.text-right { text-align: right; }
.text-center { text-align: center; }
.text-muted { color: #6b7280; }
.text-danger { color: #ef4444; }
.text-success { color: #10b981; }
.text-warning { color: #f59e0b; }
.mt-0 { margin-top: 0; }
.mt-2 { margin-top: 8px; }
.mt-4 { margin-top: 16px; }
.mb-0 { margin-bottom: 0; }
.mb-2 { margin-bottom: 8px; }
.mb-4 { margin-bottom: 16px; }
.gap-2 { gap: 8px; }
.flex { display: flex; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }

/* --- Sidebar Collapse --- */
.sidebar-toggle {
    position: absolute;
    top: 10px;
    left: 10px;
    width: 32px;
    height: 32px;
    border: none;
    border-radius: 4px;
    background: #374151;
    color: #d1d5db;
    font-size: 18px;
    cursor: pointer;
    z-index: 102;
    transition: all 0.2s;
    display: none;
}

.sidebar-toggle:hover {
    background: #4b5563;
    color: #fff;
}

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 99;
}

.sidebar-overlay.active {
    display: block;
}

.sidebar.collapsed {
    width: 0 !important;
    min-width: 0 !important;
    overflow: hidden;
    padding: 0 !important;
}

/* 侧边栏折叠时，主内容区扩展 */
.content {
    transition: margin-left 0.3s ease;
}

.sidebar.collapsed ~ .content,
.sidebar.collapsed + .content {
    margin-left: 0;
}

@media (max-width: 1024px) {
    .sidebar-toggle {
        display: block;
    }
    
    /* 窄屏默认展开 */
    .sidebar {
        width: 240px;
        min-width: 240px;
    }
    
    /* 折叠状态 - 保留迷你宽度 */
    .sidebar.collapsed {
        width: 60px !important;
        min-width: 60px !important;
        overflow: hidden;
        padding: 0 !important;
    }
    
    /* 折叠时主内容区扩展 */
    .sidebar.collapsed ~ .content,
    .sidebar.collapsed + .content {
        margin-left: 60px;
    }
    
    /* 展开时按钮在右上角 */
    .sidebar-toggle {
        right: 10px;
        left: auto;
    }
    
    /* 收缩时按钮在左侧 */
    .sidebar.collapsed .sidebar-toggle {
        left: 10px;
        right: auto;
    }
}

/* --- Product Cards in Modal --- */
.product-card {
    cursor: pointer;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    padding: 10px;
    background: #fff;
    transition: all 0.2s;
    position: relative;
}

.product-card:hover {
    border-color: #2563eb;
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.1);
}

.product-card img {
    width: 100%;
    height: 110px;
    object-fit: contain;
}


