/* ===== 进销存系统 - 企业级样式 v2 ===== */

:root {
    --sidebar-width: 250px;
    --sidebar-collapsed: 0px;
    --topbar-height: 56px;
    --primary: #3b82f6;
    --primary-hover: #2563eb;
    --primary-light: #eff6ff;
    --secondary: #64748b;
    --success: #10b981;
    --success-light: #ecfdf5;
    --info: #06b6d4;
    --warning: #f59e0b;
    --danger: #ef4444;
    --danger-light: #fef2f2;
    --light: #f8fafc;
    --dark: #1e293b;
    --border: #e2e8f0;
    --bg-body: #f1f5f9;
    --bg-card: #ffffff;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --text-muted: #94a3b8;
    --shadow-sm: 0 1px 2px rgba(0,0,0,.05);
    --shadow: 0 1px 3px rgba(0,0,0,.1), 0 1px 2px rgba(0,0,0,.06);
    --shadow-md: 0 4px 6px -1px rgba(0,0,0,.1), 0 2px 4px -2px rgba(0,0,0,.1);
    --shadow-lg: 0 10px 15px -3px rgba(0,0,0,.1), 0 4px 6px -4px rgba(0,0,0,.1);
    --radius: 0.5rem;
    --radius-lg: 0.75rem;
    --transition: all 0.2s ease;
}

* { box-sizing: border-box; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, 'Noto Sans SC', sans-serif;
    background: var(--bg-body);
    margin: 0;
    padding: 0;
    color: var(--text-primary);
    font-size: 0.9rem;
    line-height: 1.6;
}

/* ===== 侧边栏 ===== */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: var(--sidebar-width);
    height: 100vh;
    height: 100dvh;
    background: var(--dark);
    color: #fff;
    z-index: 1050;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    display: flex;
    flex-direction: column;
    contain: layout style;
}

.sidebar::-webkit-scrollbar {
    width: 4px;
}
.sidebar::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,.2);
    border-radius: 2px;
}

.sidebar .sidebar-brand {
    display: flex;
    align-items: center;
    justify-content: center;
    height: var(--topbar-height);
    min-height: var(--topbar-height);
    font-size: 1rem;
    font-weight: 700;
    letter-spacing: 0.05rem;
    text-decoration: none;
    color: #fff;
    border-bottom: 1px solid rgba(255,255,255,.08);
    gap: 0.5rem;
    flex-shrink: 0;
}

.sidebar .sidebar-brand i {
    font-size: 1.3rem;
    color: var(--primary);
}

.sidebar hr.sidebar-divider {
    border-top: 1px solid rgba(255,255,255,.08);
    margin: 0.4rem 1rem;
}

.sidebar .sidebar-heading {
    font-size: 0.65rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.12rem;
    color: rgba(255,255,255,.35);
    padding: 0.5rem 1.25rem 0.25rem;
}

.sidebar .nav-item .nav-link {
    display: flex;
    align-items: center;
    padding: 0.55rem 1.25rem;
    color: rgba(255,255,255,.6);
    text-decoration: none;
    font-size: 0.85rem;
    transition: var(--transition);
    gap: 0.65rem;
    border-left: 3px solid transparent;
}

.sidebar .nav-item .nav-link:hover {
    color: #fff;
    background: rgba(255,255,255,.06);
}

.sidebar .nav-item .nav-link.active {
    color: #fff;
    background: rgba(59, 130, 246, .2);
    border-left-color: var(--primary);
    font-weight: 600;
}

.sidebar .nav-item .nav-link.nav-parent.active {
    background: rgba(59, 130, 246, .12);
}

.sidebar .nav-item .nav-link.nav-sublink.active {
    color: #fff;
    background: rgba(59, 130, 246, .28);
    border-left-color: #60a5fa;
    font-weight: 600;
}

.sidebar .nav-item.nav-group-open > .nav-parent .nav-chevron {
    transform: rotate(180deg);
}

.sidebar .nav-chevron {
    font-size: 0.65rem;
    transition: transform 0.2s ease;
    opacity: 0.7;
}

.sidebar .nav-link.nav-parent:not(.collapsed) .nav-chevron {
    transform: rotate(180deg);
}

.sidebar .nav-item .nav-link i {
    font-size: 1rem;
    width: 1.25rem;
    text-align: center;
    flex-shrink: 0;
}

.sidebar .nav-item .collapse,
.sidebar .nav-item .nav-submenu {
    background: rgba(0,0,0,.15);
}
.sidebar .nav-item .collapse .nav-link,
.sidebar .nav-item .nav-submenu .nav-link {
    padding-left: 2.5rem;
    font-size: 0.82rem;
}

/* 侧边栏遮罩 */
.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,.5);
    z-index: 1040;
}
.sidebar-overlay.show {
    display: block;
}

body.sidebar-open {
    overflow: hidden;
    touch-action: none;
}

body.sidebar-open .main-content {
    touch-action: none;
}

/* ===== 主内容区 ===== */
.main-content {
    margin-left: var(--sidebar-width);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    transition: margin-left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ===== 顶部栏 ===== */
.topbar {
    height: var(--topbar-height);
    min-height: var(--topbar-height);
    background: var(--bg-card);
    box-shadow: var(--shadow-sm);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.5rem;
    position: sticky;
    top: 0;
    z-index: 1020;
}

.topbar .page-title {
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--text-primary);
    margin: 0;
}

.topbar .user-dropdown {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    color: var(--text-secondary);
    font-size: 0.85rem;
}

.topbar .user-avatar {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: var(--primary);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.8rem;
}

#sidebarToggle {
    display: none;
    background: none;
    border: none;
    font-size: 1.3rem;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0.25rem;
}

/* ===== 面包屑 ===== */
.breadcrumb-wrapper {
    padding: 0.6rem 0;
    margin-bottom: 0.5rem;
}

.breadcrumb-wrapper .breadcrumb {
    margin: 0;
    padding: 0;
    background: none;
    font-size: 0.82rem;
}

.breadcrumb-wrapper .breadcrumb-item a {
    color: var(--primary);
    text-decoration: none;
}

.breadcrumb-wrapper .breadcrumb-item a:hover {
    text-decoration: underline;
}

.breadcrumb-wrapper .breadcrumb-item.active {
    color: var(--text-secondary);
}

/* ===== 页面内容 ===== */
.content-wrapper {
    flex: 1;
    padding: 1.25rem 1.5rem;
}

/* ===== 统计卡片 ===== */
.stat-card {
    border: none;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    transition: var(--transition);
    margin-bottom: 1rem;
    background: var(--bg-card);
    overflow: hidden;
}

.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.stat-card .card-body {
    padding: 1.15rem;
}

.stat-card .stat-icon {
    width: 2.75rem;
    height: 2.75rem;
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    color: #fff;
    flex-shrink: 0;
}

.stat-card .stat-label {
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04rem;
    color: var(--text-muted);
    margin-bottom: 0.15rem;
}

.stat-card .stat-value {
    font-size: 1.35rem;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1.2;
}

.bg-primary-gradient { background: linear-gradient(135deg, #3b82f6, #1d4ed8); }
.bg-success-gradient { background: linear-gradient(135deg, #10b981, #059669); }
.bg-info-gradient { background: linear-gradient(135deg, #06b6d4, #0891b2); }
.bg-warning-gradient { background: linear-gradient(135deg, #f59e0b, #d97706); }
.bg-danger-gradient { background: linear-gradient(135deg, #ef4444, #dc2626); }
.bg-purple-gradient { background: linear-gradient(135deg, #8b5cf6, #6d28d9); }
.bg-indigo-gradient { background: linear-gradient(135deg, #6366f1, #4f46e5); }
.bg-teal-gradient { background: linear-gradient(135deg, #14b8a6, #0d9488); }

/* ===== 表格卡片 ===== */
.table-card {
    border: none;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    margin-bottom: 1.25rem;
    background: var(--bg-card);
    overflow: hidden;
}

.table-card .card-header {
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    font-weight: 600;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1.15rem;
    font-size: 0.9rem;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.table-card .table {
    margin: 0;
    font-size: 0.85rem;
}

.table-card .table thead th {
    background: var(--light);
    border-bottom: 1px solid var(--border);
    color: var(--text-secondary);
    font-weight: 600;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.03rem;
    padding: 0.65rem 0.85rem;
    white-space: nowrap;
}

.table-card .table td {
    vertical-align: middle;
    padding: 0.6rem 0.85rem;
    border-bottom: 1px solid var(--border);
    color: var(--text-primary);
}

.table-card .table tbody tr:last-child td {
    border-bottom: none;
}

.table-card .table tbody tr:hover {
    background: var(--primary-light);
}

.table-card .table td a.fw-bold {
    color: var(--primary);
}

.table-card .card-footer {
    background: var(--bg-card);
    border-top: 1px solid var(--border);
    padding: 0.6rem 1.15rem;
}

/* ===== 表单卡片 ===== */
.form-card {
    border: none;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    margin-bottom: 1.25rem;
    background: var(--bg-card);
}

.form-card .card-header {
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    font-weight: 600;
    color: var(--text-primary);
    padding: 0.75rem 1.15rem;
    font-size: 0.9rem;
}

.form-card .card-body {
    padding: 1.25rem;
}

.form-card .form-label {
    font-weight: 600;
    font-size: 0.82rem;
    color: var(--text-primary);
    margin-bottom: 0.3rem;
}

.form-card .form-control,
.form-card .form-select {
    font-size: 0.85rem;
    border-color: var(--border);
    border-radius: var(--radius);
    padding: 0.45rem 0.75rem;
}

.form-card .form-control:focus,
.form-card .form-select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, .15);
}

/* 字段分组 */
.field-group {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem;
    margin-bottom: 1rem;
    background: var(--light);
}

.field-group-title {
    font-size: 0.82rem;
    font-weight: 700;
    color: var(--primary);
    margin-bottom: 0.75rem;
    padding-bottom: 0.4rem;
    border-bottom: 1px dashed var(--border);
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

/* ===== 详情卡片 ===== */
.detail-card {
    border: none;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    margin-bottom: 1.25rem;
    background: var(--bg-card);
}

.detail-card .card-header {
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    font-weight: 600;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1.15rem;
    font-size: 0.9rem;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.detail-info dt {
    color: var(--text-muted);
    font-weight: 500;
    font-size: 0.78rem;
    margin-bottom: 0.15rem;
}

.detail-info dd {
    color: var(--text-primary);
    margin-bottom: 0.65rem;
    font-size: 0.88rem;
}

/* ===== 状态标签 ===== */
.badge-status {
    font-size: 0.72rem;
    font-weight: 600;
    padding: 0.25em 0.65em;
    border-radius: 9999px;
}

.badge-draft { background: #e2e8f0; color: #475569; }
.badge-pending { background: #fef3c7; color: #92400e; }
.badge-approved { background: #dbeafe; color: #1e40af; }
.badge-ordered { background: #dbeafe; color: #1e40af; }
.badge-in_progress { background: #dbeafe; color: #1e40af; }
.badge-shipping { background: #dbeafe; color: #1e40af; }
.badge-partial_received { background: #dbeafe; color: #1e40af; }
.badge-completed, .badge-received, .badge-shipped, .badge-delivered { background: #d1fae5; color: #065f46; }
.badge-cancelled { background: #fee2e2; color: #991b1b; }

/* ===== 工具栏 ===== */
.toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    flex-wrap: wrap;
    margin-bottom: 1rem;
}

.toolbar .search-form {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    align-items: center;
}

.toolbar .search-form .form-control,
.toolbar .search-form .form-select {
    font-size: 0.82rem;
    border-color: var(--border);
    border-radius: var(--radius);
}

/* ===== 分页 ===== */
.pagination-wrapper {
    display: flex;
    justify-content: center;
    margin-top: 1rem;
}

.pagination .page-link {
    font-size: 0.82rem;
    color: var(--primary);
    border-color: var(--border);
    padding: 0.35rem 0.65rem;
}

.pagination .page-item.active .page-link {
    background-color: var(--primary);
    border-color: var(--primary);
}

/* ===== 空状态 ===== */
.empty-state {
    text-align: center;
    padding: 2.5rem 1rem;
    color: var(--text-muted);
}

.empty-state i {
    font-size: 2.5rem;
    margin-bottom: 0.75rem;
    opacity: 0.4;
}

/* ===== 登录页 ===== */
.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #0f172a 0%, #1e3a5f 50%, #0f172a 100%);
    position: relative;
    overflow: hidden;
}

.login-page::before {
    content: '';
    position: absolute;
    width: 600px;
    height: 600px;
    background: radial-gradient(circle, rgba(59,130,246,.15), transparent 70%);
    top: -100px;
    right: -100px;
    border-radius: 50%;
}

.login-page::after {
    content: '';
    position: absolute;
    width: 400px;
    height: 400px;
    background: radial-gradient(circle, rgba(16,185,129,.1), transparent 70%);
    bottom: -50px;
    left: -50px;
    border-radius: 50%;
}

.login-card {
    width: 100%;
    max-width: 400px;
    border: none;
    border-radius: var(--radius-lg);
    box-shadow: 0 25px 50px -12px rgba(0,0,0,.4);
    overflow: hidden;
    position: relative;
    z-index: 1;
    background: rgba(255,255,255,.95);
    backdrop-filter: blur(20px);
}

.login-card .card-header {
    background: transparent;
    text-align: center;
    padding: 2rem 1.5rem 0.5rem;
    border-bottom: none;
}

.login-card .card-header .login-logo {
    width: 56px;
    height: 56px;
    border-radius: var(--radius);
    background: var(--primary);
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    margin-bottom: 0.75rem;
}

.login-card .card-header h1 {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-primary);
    margin: 0;
}

.login-card .card-header p {
    color: var(--text-muted);
    font-size: 0.82rem;
    margin-top: 0.2rem;
}

.login-card .card-body {
    padding: 1.25rem 2rem 2rem;
}

.login-card .form-label {
    font-weight: 600;
    font-size: 0.82rem;
    color: var(--text-primary);
}

.login-card .form-control {
    padding: 0.6rem 0.75rem;
    border-color: var(--border);
    border-radius: var(--radius);
}

.login-card .form-control:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, .15);
}

.login-card .btn-primary {
    width: 100%;
    padding: 0.65rem;
    font-weight: 600;
    border-radius: var(--radius);
    background: var(--primary);
    border-color: var(--primary);
    margin-top: 0.5rem;
}

.login-card .btn-primary:hover {
    background: var(--primary-hover);
    border-color: var(--primary-hover);
}

/* ===== 按钮 ===== */
.btn {
    font-size: 0.85rem;
    font-weight: 500;
    border-radius: var(--radius);
    padding: 0.4rem 0.9rem;
    transition: var(--transition);
}

.btn-sm {
    font-size: 0.8rem;
    padding: 0.3rem 0.7rem;
}

.btn-primary {
    background: var(--primary);
    border-color: var(--primary);
}

.btn-primary:hover {
    background: var(--primary-hover);
    border-color: var(--primary-hover);
}

.btn-outline-primary {
    color: var(--primary);
    border-color: var(--primary);
}

.btn-outline-primary:hover {
    background: var(--primary);
    border-color: var(--primary);
}

.btn-sm-action {
    padding: 0.2rem 0.45rem;
    font-size: 0.78rem;
    border-radius: 0.375rem;
}

/* 操作按钮组 */
.action-btns {
    display: flex;
    gap: 0.3rem;
    white-space: nowrap;
}

/* ===== 金额格式 ===== */
.amount {
    font-family: 'SF Mono', Consolas, 'Liberation Mono', Menlo, monospace;
    font-weight: 600;
}

/* ===== 动画 ===== */
.fade-in {
    animation: fadeIn 0.3s ease-in;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ===== Alert 优化 ===== */
.alert {
    border-radius: var(--radius);
    font-size: 0.85rem;
    border: none;
    padding: 0.65rem 1rem;
}

.alert-success { background: var(--success-light); color: #065f46; }
.alert-danger { background: var(--danger-light); color: #991b1b; }
.alert-warning { background: #fffbeb; color: #92400e; }
.alert-info { background: #ecfeff; color: #155e75; }

/* ===== 看板样式 ===== */
.kanban-tabs .nav-link {
    color: var(--text-secondary);
    font-weight: 600;
    font-size: 0.82rem;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: var(--radius);
}

.kanban-tabs .nav-link.active {
    background: var(--primary);
    color: #fff;
}

.chart-container {
    position: relative;
    height: 300px;
}

/* ===== 自定义字段管理 ===== */
.field-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.65rem 0.85rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 0.5rem;
    background: var(--bg-card);
    transition: var(--transition);
}

.field-item:hover {
    box-shadow: var(--shadow-sm);
    border-color: var(--primary);
}

.field-item .field-drag {
    color: var(--text-muted);
    cursor: grab;
}

/* ===== 可点击表格行 ===== */
.cursor-pointer {
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}
.cursor-pointer:active {
    background: rgba(59, 130, 246, .06);
}

.sidebar-toggle-btn {
    touch-action: manipulation;
}

/* ===== 响应式 ===== */
@media (max-width: 992px) {
    .sidebar {
        transform: translateX(-100%);
    }
    .sidebar.show {
        transform: translateX(0);
    }
    .main-content {
        margin-left: 0;
    }
    #sidebarToggle {
        display: block;
    }
    .topbar {
        padding: 0 1rem;
    }
}

@media (max-width: 768px) {
    .content-wrapper {
        padding: 0.75rem 1rem;
    }
    .toolbar {
        flex-direction: column;
        align-items: stretch;
    }
    .toolbar .search-form {
        flex-wrap: wrap;
    }
    .toolbar .search-form .form-control,
    .toolbar .search-form .form-select {
        width: 100%;
        min-width: 0;
    }
    .stat-card .stat-value {
        font-size: 1.1rem;
    }
    .table-card .table-responsive {
        font-size: 0.8rem;
    }
    /* 移动端表格卡片化 */
    .table-card .table thead {
        display: none;
    }
    .table-card .table tbody tr {
        display: flex;
        flex-wrap: wrap;
        padding: 0.6rem;
        border-bottom: 1px solid var(--border);
        gap: 0.25rem 0;
    }
    .table-card .table tbody td {
        border: none;
        padding: 0.15rem 0.5rem;
        font-size: 0.82rem;
    }
    .form-card .field-group {
        padding: 0.75rem;
    }
    .form-card .row > [class*="col-"] {
        flex: 0 0 100%;
        max-width: 100%;
    }
}

@media (max-width: 576px) {
    .content-wrapper {
        padding: 0.5rem 0.75rem;
    }
    .topbar {
        padding: 0 0.75rem;
    }
    .topbar .page-title {
        font-size: 0.9rem;
    }
    .form-card .card-body,
    .detail-card .card-body {
        padding: 1rem;
    }
    .stat-card .card-body {
        padding: 0.85rem;
    }
    .detail-card .card-header {
        flex-direction: column;
        align-items: flex-start;
    }
    .login-card {
        margin: 0.5rem;
    }
    .login-card .card-body {
        padding: 1rem 1.25rem 1.5rem;
    }
    .chart-container {
        height: 220px;
    }
}

/* ===== 物料宽表 ===== */
.material-table-scroll {
    overflow-x: auto;
    max-width: 100%;
}
.material-table {
    min-width: 1600px;
    font-size: 0.82rem;
    white-space: nowrap;
}
.material-table .col-seq {
    width: 40px;
    text-align: center;
}
.material-table .sticky-col {
    position: sticky;
    right: 0;
    background: #fff;
    box-shadow: -4px 0 8px rgba(0,0,0,0.06);
}
.material-detail-table th {
    background: var(--bg-body);
    font-weight: 600;
}

/* ===== 工具类 ===== */
.text-primary { color: var(--primary) !important; }
.bg-body { background: var(--bg-body); }
.border-bottom-custom { border-bottom: 1px solid var(--border); }
