/* ============================================================
   备件存储管理系统 —— 全局样式
   设计要点：
     * 无外部依赖，字体与图标全部走系统本地资源（内网可用）
     * 配色克制，工业管理场景以清晰可读为第一优先
     * 低储备警戒色使用暖红，与「库存告警」语义一致
   ============================================================ */

:root {
    /* 主色：沉稳的钢蓝，贴合工业设备场景 */
    --c-primary: #1a5f9e;
    --c-primary-dark: #14497a;
    --c-primary-light: #e8f1f9;

    /* 语义色 */
    --c-danger: #c0392b;
    --c-danger-light: #fdecea;
    --c-warn: #d68910;
    --c-warn-light: #fef5e7;
    --c-success: #1e8449;
    --c-success-light: #eafaf1;

    /* 中性色 */
    --c-text: #1f2937;
    --c-text-sub: #6b7280;
    --c-text-mute: #9ca3af;
    --c-border: #dfe3e8;
    --c-bg: #f5f7fa;
    --c-surface: #ffffff;

    --radius: 6px;
    --shadow-sm: 0 1px 3px rgba(16, 24, 40, 0.08);
    --shadow-md: 0 4px 12px rgba(16, 24, 40, 0.10);

    --sidebar-w: 210px;
    --header-h: 56px;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html,
body {
    height: 100%;
}

body {
    font-family: "Microsoft YaHei", "PingFang SC", "Hiragino Sans GB",
                 -apple-system, "Segoe UI", sans-serif;
    font-size: 14px;
    line-height: 1.6;
    color: var(--c-text);
    background: var(--c-bg);
    -webkit-font-smoothing: antialiased;
}

/* ---------- 通用元素 ---------- */

button {
    font-family: inherit;
    font-size: 14px;
    cursor: pointer;
    border: none;
    border-radius: var(--radius);
    transition: background-color .15s, box-shadow .15s, opacity .15s;
}

button:disabled {
    cursor: not-allowed;
    opacity: .55;
}

input,
select,
textarea {
    font-family: inherit;
    font-size: 14px;
    color: var(--c-text);
    border: 1px solid var(--c-border);
    border-radius: var(--radius);
    padding: 7px 10px;
    background: #fff;
    outline: none;
    transition: border-color .15s, box-shadow .15s;
    width: 100%;
}

input:focus,
select:focus,
textarea:focus {
    border-color: var(--c-primary);
    box-shadow: 0 0 0 3px rgba(26, 95, 158, .12);
}

input[readonly] {
    background: #f2f4f7;
    color: var(--c-text-sub);
}

a {
    color: var(--c-primary);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

/* ---------- 按钮 ---------- */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    height: 34px;
    padding: 0 14px;
    font-weight: 500;
    white-space: nowrap;
    background: #fff;
    color: var(--c-text);
    border: 1px solid var(--c-border);
}

.btn:hover:not(:disabled) {
    background: #f7f9fb;
    border-color: #c9d1d9;
}

.btn-primary {
    background: var(--c-primary);
    color: #fff;
    border-color: var(--c-primary);
}

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

.btn-danger {
    background: var(--c-danger);
    color: #fff;
    border-color: var(--c-danger);
}

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

.btn-sm {
    height: 28px;
    padding: 0 10px;
    font-size: 13px;
}

.btn-block {
    width: 100%;
}

/* ---------- 布局骨架 ---------- */

#app {
    height: 100%;
}

.layout {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* 侧边导航 */
.sidebar {
    width: var(--sidebar-w);
    flex-shrink: 0;
    background: #1c2b3a;
    color: #cdd7e0;
    display: flex;
    flex-direction: column;
}

.sidebar-brand {
    height: var(--header-h);
    display: flex;
    align-items: center;
    padding: 0 18px;
    font-size: 15px;
    font-weight: 600;
    color: #fff;
    letter-spacing: .5px;
    background: rgba(0, 0, 0, .18);
    border-bottom: 1px solid rgba(255, 255, 255, .07);
}

.sidebar-brand .dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    margin-right: 8px;
    border-radius: 50%;
    background: #4aa3df;
}

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

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    height: 42px;
    padding: 0 18px;
    color: #b6c2cf;
    cursor: pointer;
    border-left: 3px solid transparent;
    transition: background .15s, color .15s;
    user-select: none;
}

.nav-item:hover {
    background: rgba(255, 255, 255, .06);
    color: #fff;
}

.nav-item.active {
    background: rgba(74, 163, 223, .16);
    color: #fff;
    border-left-color: #4aa3df;
}

.nav-item .ico {
    width: 18px;
    text-align: center;
    font-size: 15px;
    opacity: .9;
}

.sidebar-foot {
    padding: 12px 18px;
    font-size: 12px;
    color: #8595a6;
    border-top: 1px solid rgba(255, 255, 255, .07);
}

/* 主区域 */
.main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.topbar {
    height: var(--header-h);
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    background: var(--c-surface);
    border-bottom: 1px solid var(--c-border);
    box-shadow: var(--shadow-sm);
    z-index: 10;
}

.topbar-title {
    font-size: 16px;
    font-weight: 600;
}

.topbar-user {
    display: flex;
    align-items: center;
    gap: 14px;
    font-size: 13px;
    color: var(--c-text-sub);
}

.role-badge {
    display: inline-block;
    padding: 2px 8px;
    font-size: 12px;
    border-radius: 10px;
    background: var(--c-primary-light);
    color: var(--c-primary-dark);
    font-weight: 500;
}

.content {
    flex: 1;
    padding: 18px 20px;
    overflow-y: auto;
}

/* ---------- 卡片 / 面板 ---------- */

.card {
    background: var(--c-surface);
    border: 1px solid var(--c-border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    margin-bottom: 16px;
}

.card-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--c-border);
    font-weight: 600;
    font-size: 14px;
}

.card-head .sub {
    font-weight: 400;
    font-size: 12px;
    color: var(--c-text-mute);
}

.card-body {
    padding: 16px;
}

/* ---------- 统计块 ---------- */

.stat-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 12px;
    margin-bottom: 16px;
}

.stat {
    background: var(--c-surface);
    border: 1px solid var(--c-border);
    border-radius: var(--radius);
    padding: 14px 16px;
    box-shadow: var(--shadow-sm);
}

.stat-label {
    font-size: 12px;
    color: var(--c-text-sub);
    margin-bottom: 6px;
}

.stat-value {
    font-size: 24px;
    font-weight: 600;
    line-height: 1.2;
    font-variant-numeric: tabular-nums;
}

.stat-value.danger {
    color: var(--c-danger);
}

.stat-value.warn {
    color: var(--c-warn);
}

.stat-value.success {
    color: var(--c-success);
}

.stat-unit {
    font-size: 13px;
    font-weight: 400;
    color: var(--c-text-mute);
    margin-left: 4px;
}

/* ---------- 表单 ---------- */

.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 14px 18px;
}

.form-item {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.form-item label {
    font-size: 13px;
    color: var(--c-text-sub);
    font-weight: 500;
}

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

.form-item .hint {
    font-size: 12px;
    color: var(--c-text-mute);
}

.form-actions {
    display: flex;
    gap: 10px;
    padding: 14px 16px;
    border-top: 1px solid var(--c-border);
    background: #fafbfc;
}

/* ---------- 检索条 ---------- */

.toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 10px;
    margin-bottom: 14px;
}

.toolbar .field {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 140px;
}

.toolbar .field.grow {
    flex: 1;
    min-width: 220px;
}

.toolbar .field label {
    font-size: 12px;
    color: var(--c-text-sub);
}

.toolbar .spacer {
    flex: 1;
}

/* ---------- 表格 ---------- */

.table-wrap {
    overflow-x: auto;
    border: 1px solid var(--c-border);
    border-radius: var(--radius);
    background: #fff;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

thead th {
    background: #f6f8fa;
    color: #44506b;
    font-weight: 600;
    text-align: left;
    padding: 10px 12px;
    white-space: nowrap;
    border-bottom: 1px solid var(--c-border);
    position: sticky;
    top: 0;
    z-index: 2;
}

tbody td {
    padding: 9px 12px;
    border-bottom: 1px solid #eef1f4;
    vertical-align: middle;
}

tbody tr:last-child td {
    border-bottom: none;
}

tbody tr:hover {
    background: #f9fbfd;
}

td.num,
th.num {
    text-align: right;
    font-variant-numeric: tabular-nums;
}

td.mono {
    font-family: Consolas, "Courier New", monospace;
    font-size: 12.5px;
}

/* 低储备行高亮 */
tr.low-stock {
    background: var(--c-danger-light) !important;
}

tr.low-stock:hover {
    background: #fbdcd7 !important;
}

.qty-low {
    color: var(--c-danger);
    font-weight: 600;
}

.qty-zero {
    color: var(--c-text-mute);
}

/* ---------- 标签 ---------- */

.tag {
    display: inline-block;
    padding: 1px 7px;
    font-size: 12px;
    border-radius: 3px;
    line-height: 1.6;
    white-space: nowrap;
}

.tag-in {
    background: var(--c-success-light);
    color: var(--c-success);
}

.tag-out {
    background: var(--c-warn-light);
    color: var(--c-warn);
}

.tag-low {
    background: var(--c-danger-light);
    color: var(--c-danger);
}

.tag-mute {
    background: #f0f2f5;
    color: var(--c-text-sub);
}

/* ---------- 分页 ---------- */

.pager {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    padding: 12px 2px 2px;
    font-size: 13px;
    color: var(--c-text-sub);
}

.pager .pages {
    display: flex;
    gap: 4px;
}

.pager button {
    min-width: 30px;
    height: 30px;
    padding: 0 8px;
    background: #fff;
    border: 1px solid var(--c-border);
    font-size: 13px;
}

.pager button.active {
    background: var(--c-primary);
    color: #fff;
    border-color: var(--c-primary);
}

/* ---------- 提示与空态 ---------- */

.empty {
    padding: 44px 20px;
    text-align: center;
    color: var(--c-text-mute);
    font-size: 13px;
}

.empty .big {
    display: block;
    font-size: 30px;
    margin-bottom: 8px;
    opacity: .45;
}

.loading {
    padding: 30px;
    text-align: center;
    color: var(--c-text-mute);
    font-size: 13px;
}

.spinner {
    display: inline-block;
    width: 15px;
    height: 15px;
    margin-right: 8px;
    vertical-align: -2px;
    border: 2px solid var(--c-border);
    border-top-color: var(--c-primary);
    border-radius: 50%;
    animation: spin .7s linear infinite;
}

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

/* 全局 Toast */
#toast-box {
    position: fixed;
    top: 18px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 8px;
    align-items: center;
    pointer-events: none;
}

.toast {
    min-width: 220px;
    max-width: 480px;
    padding: 10px 16px;
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    background: #fff;
    border-left: 4px solid var(--c-primary);
    font-size: 13.5px;
    animation: slideDown .22s ease-out;
}

.toast.success {
    border-left-color: var(--c-success);
}

.toast.error {
    border-left-color: var(--c-danger);
}

.toast.warn {
    border-left-color: var(--c-warn);
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* 模态框 */
.modal-mask {
    position: fixed;
    inset: 0;
    background: rgba(16, 24, 40, .45);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 20px;
}

.modal {
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 12px 32px rgba(16, 24, 40, .22);
    width: 100%;
    max-width: 560px;
    max-height: 88vh;
    display: flex;
    flex-direction: column;
    animation: pop .18s ease-out;
}

.modal.wide {
    max-width: 860px;
}

@keyframes pop {
    from {
        opacity: 0;
        transform: scale(.97);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

.modal-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 18px;
    border-bottom: 1px solid var(--c-border);
    font-weight: 600;
}

.modal-head .close {
    background: none;
    border: none;
    font-size: 20px;
    line-height: 1;
    color: var(--c-text-mute);
    padding: 0 4px;
}

.modal-head .close:hover {
    color: var(--c-text);
}

.modal-body {
    padding: 18px;
    overflow-y: auto;
}

.modal-foot {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    padding: 12px 18px;
    border-top: 1px solid var(--c-border);
    background: #fafbfc;
}

/* ---------- 登录页 ---------- */

.login-wrap {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #1c2b3a 0%, #1a5f9e 100%);
    padding: 20px;
}

.login-card {
    width: 100%;
    max-width: 400px;
    background: #fff;
    border-radius: 10px;
    box-shadow: 0 16px 44px rgba(0, 0, 0, .28);
    overflow: hidden;
}

.login-head {
    padding: 30px 32px 22px;
    text-align: center;
    border-bottom: 1px solid var(--c-border);
}

.login-head h1 {
    font-size: 19px;
    font-weight: 600;
    color: var(--c-text);
    margin-bottom: 6px;
}

.login-head p {
    font-size: 13px;
    color: var(--c-text-sub);
}

.login-body {
    padding: 26px 32px 30px;
}

.login-body .form-item {
    margin-bottom: 16px;
}

.login-body input {
    height: 38px;
}

.login-body .btn-primary {
    height: 38px;
    margin-top: 6px;
}

.login-foot {
    padding: 12px 32px 18px;
    text-align: center;
    font-size: 12px;
    color: var(--c-text-mute);
}

.login-err {
    margin-bottom: 14px;
    padding: 9px 12px;
    background: var(--c-danger-light);
    color: var(--c-danger);
    border-radius: var(--radius);
    font-size: 13px;
    border-left: 3px solid var(--c-danger);
}

/* ---------- 导入向导 ---------- */

.import-steps {
    display: flex;
    gap: 0;
    margin-bottom: 18px;
}

.import-step {
    flex: 1;
    text-align: center;
    padding: 10px 6px;
    font-size: 13px;
    color: var(--c-text-mute);
    border-bottom: 2px solid var(--c-border);
}

.import-step.active {
    color: var(--c-primary);
    font-weight: 600;
    border-bottom-color: var(--c-primary);
}

.import-step.done {
    color: var(--c-success);
    border-bottom-color: var(--c-success);
}

.dropzone {
    border: 2px dashed var(--c-border);
    border-radius: var(--radius);
    padding: 34px 20px;
    text-align: center;
    background: #fafbfc;
    cursor: pointer;
    transition: border-color .15s, background .15s;
}

.dropzone:hover,
.dropzone.over {
    border-color: var(--c-primary);
    background: var(--c-primary-light);
}

.dropzone .big {
    display: block;
    font-size: 32px;
    margin-bottom: 8px;
    opacity: .6;
}

.dropzone .fname {
    margin-top: 8px;
    font-size: 13px;
    color: var(--c-primary);
    font-weight: 500;
    word-break: break-all;
}

.import-summary {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
    gap: 10px;
    margin-bottom: 14px;
}

.import-summary .box {
    padding: 10px;
    text-align: center;
    border-radius: var(--radius);
    background: #f6f8fa;
}

.import-summary .box .n {
    font-size: 20px;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

.import-summary .box .t {
    font-size: 12px;
    color: var(--c-text-sub);
}

.import-summary .box.ok .n {
    color: var(--c-success);
}

.import-summary .box.err .n {
    color: var(--c-danger);
}

.import-summary .box.upd .n {
    color: var(--c-warn);
}

.err-list {
    max-height: 240px;
    overflow-y: auto;
    border: 1px solid var(--c-border);
    border-radius: var(--radius);
    font-size: 13px;
}

.err-list .row {
    display: flex;
    gap: 10px;
    padding: 7px 12px;
    border-bottom: 1px solid #eef1f4;
}

.err-list .row:last-child {
    border-bottom: none;
}

.err-list .row .ln {
    color: var(--c-danger);
    font-weight: 600;
    white-space: nowrap;
    min-width: 62px;
}

/* ---------- 报表图 ---------- */

.chart-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: 16px;
}

.bar-list {
    display: flex;
    flex-direction: column;
    gap: 9px;
}

.bar-item {
    font-size: 13px;
}

.bar-item .top {
    display: flex;
    justify-content: space-between;
    margin-bottom: 3px;
    color: var(--c-text-sub);
}

.bar-item .top b {
    color: var(--c-text);
    font-variant-numeric: tabular-nums;
}

.bar-track {
    height: 8px;
    background: #eef1f4;
    border-radius: 4px;
    overflow: hidden;
}

.bar-fill {
    height: 100%;
    border-radius: 4px;
    background: var(--c-primary);
    transition: width .5s ease;
}

.bar-fill.in {
    background: var(--c-success);
}

.bar-fill.out {
    background: var(--c-warn);
}

.bar-fill.danger {
    background: var(--c-danger);
}

/* ---------- 响应式 ---------- */

@media (max-width: 860px) {
    :root {
        --sidebar-w: 60px;
    }

    .sidebar-brand span.txt,
    .nav-item span.txt,
    .sidebar-foot {
        display: none;
    }

    .nav-item {
        justify-content: center;
        padding: 0;
    }

    .form-grid {
        grid-template-columns: 1fr;
    }
}
