:root {
    --bg: #f4f6f9;
    --card: #ffffff;
    --border: #e3e8ef;
    --text: #1f2937;
    --muted: #8a94a6;
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --success: #059669;
    --danger: #dc2626;
    --radius: 10px;
    --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 8px 24px rgba(16, 24, 40, .06);
}

* {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--text);
    font: 14px/1.5 "PingFang SC", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
}

.hidden {
    display: none !important;
}

.muted {
    color: var(--muted);
    font-size: 12px;
}

.error {
    color: var(--danger);
    background: #fef2f2;
    border: 1px solid #fecaca;
    border-radius: 8px;
    padding: 8px 10px;
    margin: 8px 0;
    font-size: 13px;
}

.req {
    color: var(--danger);
}

/* ---------- 通用控件 ---------- */
button {
    font: inherit;
    border-radius: 8px;
    border: 1px solid transparent;
    padding: 8px 14px;
    cursor: pointer;
    transition: background .15s ease, border-color .15s ease, color .15s ease;
}

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

button.primary {
    background: var(--primary);
    color: #fff;
}

button.primary:hover:not(:disabled) {
    background: var(--primary-dark);
}

button.success {
    background: var(--success);
    color: #fff;
}

button.ghost {
    background: #fff;
    border-color: var(--border);
    color: var(--text);
}

button.ghost:hover:not(:disabled) {
    border-color: #cbd5e1;
    background: #f8fafc;
}

button.block {
    width: 100%;
}

button.icon {
    border: none;
    background: transparent;
    font-size: 22px;
    line-height: 1;
    padding: 0 6px;
    color: var(--muted);
}

button.link {
    border: none;
    background: none;
    color: var(--primary);
    padding: 0 6px;
    font-size: 13px;
}

button.link.danger {
    color: var(--danger);
}

a.link {
    color: var(--primary);
    text-decoration: none;
    font-size: 13px;
}

a.link:hover {
    text-decoration: underline;
}

input {
    font: inherit;
    color: inherit;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 8px 10px;
    width: 100%;
}

input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, .12);
}

.card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.field {
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: 0;
}

.field > span {
    font-size: 12px;
    color: var(--muted);
}

/* ---------- 登录 ---------- */
.login-wrap {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.login-card {
    width: 100%;
    max-width: 360px;
    padding: 28px;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.login-card h1 {
    font-size: 20px;
    margin: 0;
}

.login-card p {
    margin: 0;
}

/* ---------- 顶栏 ---------- */
.topbar {
    height: 56px;
    background: #fff;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    position: sticky;
    top: 0;
    z-index: 20;
}

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

.topbar .user {
    display: flex;
    align-items: center;
    gap: 12px;
    color: var(--muted);
    font-size: 13px;
}

main {
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

/* ---------- 查询条件 ---------- */
.filters {
    padding: 16px;
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: flex-end;
}

.filters .field {
    width: 180px;
}

.filter-actions {
    display: flex;
    gap: 8px;
    margin-left: auto;
}

/* ---------- 表格 ---------- */
.table-card {
    padding: 8px 0 0;
}

.range-hint {
    padding: 0 16px 8px;
}

.table-scroll {
    max-height: calc(100vh - 320px);
    min-height: 240px;
    overflow: auto;
}

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

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

thead th.num {
    text-align: right;
}

thead th .muted {
    font-weight: 400;
}

tbody td {
    padding: 10px 12px;
    border-bottom: 1px solid #f1f5f9;
    vertical-align: top;
}

tbody tr:hover td {
    background: #fafbfd;
}

td.num {
    text-align: right;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

td.num .sub {
    color: var(--muted);
    font-size: 12px;
}

td.nowrap {
    white-space: nowrap;
}

.empty {
    text-align: center;
    color: var(--muted);
    padding: 48px 0;
}

tfoot td {
    position: sticky;
    bottom: 0;
    z-index: 2;
    background: #f8fafc;
    border-top: 1px solid var(--border);
    padding: 12px;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

tfoot td.num {
    text-align: right;
    white-space: nowrap;
}

tfoot td .tax {
    font-weight: 400;
    color: var(--muted);
    font-size: 12px;
}

.pager {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-top: 1px solid var(--border);
}

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

/* ---------- 弹窗 ---------- */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, .45);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    z-index: 50;
}

.modal-card {
    width: 100%;
    max-width: 820px;
    max-height: 92vh;
    display: flex;
    flex-direction: column;
    padding: 0;
}

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

.modal-head h2 {
    margin: 0;
    font-size: 16px;
}

.modal-body {
    padding: 16px 20px;
    overflow: auto;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
}

.modal-body .span2 {
    grid-column: span 2;
}

.modal-body .upload {
    flex-direction: row;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.modal-body .upload input[type=file] {
    width: auto;
    flex: 1 1 200px;
    padding: 5px;
    font-size: 12px;
    background: #f8fafc;
}

.upload-status {
    flex-basis: 100%;
    word-break: break-all;
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
}

.upload-status.ok {
    color: var(--success);
}

.upload-status.error {
    color: var(--danger);
}

/* ---------- 缩略图 / 图片放大 ---------- */
.thumb {
    width: 56px;
    height: 40px;
    object-fit: cover;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: #f8fafc;
    cursor: zoom-in;
    display: block;
}

.thumb:hover {
    border-color: var(--primary);
}

.thumb-sm {
    width: 72px;
    height: 72px;
    display: inline-block;
}

.thumb-broken {
    color: var(--muted);
    font-size: 12px;
    white-space: nowrap;
}

.lightbox {
    position: fixed;
    inset: 0;
    z-index: 120;
    background: rgba(15, 23, 42, .82);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    cursor: zoom-out;
}

.lightbox img {
    max-width: 92vw;
    max-height: 92vh;
    border-radius: 8px;
    background: #fff;
    box-shadow: 0 24px 64px rgba(0, 0, 0, .45);
}

.modal-foot {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    padding: 14px 20px;
    border-top: 1px solid var(--border);
}

#form-error {
    margin: 0 20px 10px;
}

/* ---------- 提示条 ---------- */
.toast {
    position: fixed;
    right: 20px;
    bottom: 20px;
    z-index: 80;
    background: #111827;
    color: #fff;
    padding: 10px 16px;
    border-radius: 8px;
    box-shadow: var(--shadow);
    max-width: 420px;
    font-size: 13px;
}

.toast.error {
    background: var(--danger);
    border: none;
    color: #fff;
}

@media (max-width: 720px) {
    .filters .field {
        width: 100%;
    }

    .filter-actions {
        margin-left: 0;
        width: 100%;
    }

    .filter-actions button {
        flex: 1;
    }

    .modal-body {
        grid-template-columns: 1fr;
    }

    .modal-body .span2 {
        grid-column: span 1;
    }
}