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

:root {
    --bg: #f3f5f8;
    --surface: #ffffff;
    --surface-weak: #f8fafc;
    --line: #d8dee6;
    --line-strong: #c8d1dd;
    --text: #1f2d3d;
    --text-sub: #5a6b7f;
    --brand: #1f4f8c;
    --brand-strong: #173f70;
    --success: #2f7d4b;
    --warning: #a2681e;
    --danger: #b83a3a;
    --info: #2f67aa;
    --shadow-sm: 0 4px 14px rgba(17, 36, 69, 0.06);
    --shadow-md: 0 10px 28px rgba(17, 36, 69, 0.1);
    --radius-lg: 16px;
    --radius-md: 12px;
    --radius-sm: 10px;
    --safe-top: env(safe-area-inset-top);
    --safe-bottom: env(safe-area-inset-bottom);
}

html,
body {
    min-height: 100%;
}

body {
    font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
    color: var(--text);
    background: var(--bg);
    line-height: 1.5;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
    -webkit-text-size-adjust: 100%;
}

#app {
    max-width: 1180px;
    margin: 0 auto;
    padding: 20px 16px 28px;
}

button,
input,
textarea,
select {
    font: inherit;
}

button,
[role="button"] {
    touch-action: manipulation;
}

.page {
    display: none;
}

.page.active {
    display: block;
}

.panel {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
}

.top-nav {
    position: sticky;
    top: 12px;
    z-index: 20;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
    padding: 8px;
    margin-bottom: 16px;
}

.nav-btn {
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-sub);
    font-size: 14px;
    font-weight: 700;
    line-height: 1;
    height: 42px;
    cursor: pointer;
    transition: background 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}

.nav-btn:hover {
    border-color: var(--line);
    background: var(--surface-weak);
    color: var(--brand);
}

.nav-btn.active {
    border-color: #d1dded;
    background: #ecf3fb;
    color: var(--brand);
}

.hero-panel {
    margin-bottom: 14px;
    padding: 22px;
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
}

.hero-main h1 {
    font-size: 32px;
    line-height: 1.2;
    letter-spacing: 0.02em;
    margin-bottom: 6px;
}

.hero-tag {
    display: inline-flex;
    align-items: center;
    padding: 3px 10px;
    border-radius: 999px;
    border: 1px solid #d6e0ef;
    background: #eef4fb;
    color: var(--brand);
    font-size: 12px;
    font-weight: 700;
    margin-bottom: 9px;
}

.hero-subtitle {
    color: var(--text-sub);
    font-size: 14px;
}

.hero-main h1,
.employee-name,
.item-name,
.item-stat-name,
.history-user {
    overflow-wrap: break-word;
    word-break: break-word;
}

.hero-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.content-panel {
    padding: 16px;
}

.toolbar {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    gap: 12px;
    margin-bottom: 14px;
}

.search-box {
    flex: 1;
}

.search-label {
    display: block;
    font-size: 12px;
    color: var(--text-sub);
    margin-bottom: 6px;
    font-weight: 600;
}

.search-box input {
    width: 100%;
    height: 44px;
    border: 1px solid var(--line-strong);
    border-radius: var(--radius-sm);
    background: #fff;
    padding: 0 13px;
    font-size: 15px;
    color: var(--text);
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.search-box input:focus {
    outline: none;
    border-color: #8ca8cb;
    box-shadow: 0 0 0 3px rgba(31, 79, 140, 0.12);
}

.toolbar-meta {
    color: var(--text-sub);
    font-size: 13px;
    white-space: nowrap;
}

.toolbar-meta span {
    color: var(--brand);
    font-weight: 700;
}

.btn {
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    padding: 0 16px;
    min-height: 42px;
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
    transition: background 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}

.btn-primary {
    color: #fff;
    background: linear-gradient(180deg, #2a5f9f 0%, #1f4f8c 100%);
    box-shadow: 0 6px 14px rgba(31, 79, 140, 0.2);
}

.btn-primary:hover {
    background: linear-gradient(180deg, #24568f 0%, #1a467d 100%);
}

.btn-secondary {
    color: #fff;
    background: linear-gradient(180deg, #415f86 0%, #334f74 100%);
    box-shadow: 0 6px 14px rgba(51, 79, 116, 0.2);
}

.btn-secondary:hover {
    background: linear-gradient(180deg, #385678 0%, #2d4869 100%);
}

.btn-ghost {
    color: var(--brand);
    border-color: #bfd0e7;
    background: #f4f8fd;
}

.btn-ghost:hover {
    border-color: #aac2df;
    background: #edf4fb;
}

.btn-danger {
    color: #fff;
    background: linear-gradient(180deg, #c94d4d 0%, #b83a3a 100%);
    box-shadow: 0 6px 14px rgba(184, 58, 58, 0.18);
}

.btn-danger:hover {
    background: linear-gradient(180deg, #bc4747 0%, #a73636 100%);
}

.btn-sm {
    min-height: 36px;
    padding: 0 12px;
    font-size: 13px;
}

.employee-list,
.stats-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(265px, 1fr));
    gap: 12px;
}

.employee-card,
.item-stat-card,
.item-card,
.history-item,
.data-stat {
    border: 1px solid var(--line);
    border-radius: var(--radius-md);
    background: #fff;
}

.employee-card {
    border-left: 3px solid #ccd6e5;
    padding: 14px;
    cursor: pointer;
    box-shadow: var(--shadow-sm);
    transition: box-shadow 0.2s ease, transform 0.2s ease, border-color 0.2s ease;
}

.employee-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.employee-card.completed {
    border-left-color: var(--success);
}

.employee-card.pending {
    border-left-color: var(--warning);
}

.employee-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
    min-width: 0;
}

.employee-name {
    font-size: 17px;
    font-weight: 700;
}

.status-chip {
    border-radius: 999px;
    font-size: 12px;
    font-weight: 700;
    padding: 3px 8px;
}

.status-chip.completed {
    color: var(--success);
    background: #eaf5ee;
}

.status-chip.pending {
    color: var(--warning);
    background: #fbf2e8;
}

.employee-meta {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    font-size: 13px;
    color: var(--text-sub);
    margin-bottom: 8px;
}

.progress-bar {
    width: 100%;
    height: 8px;
    border-radius: 999px;
    background: #e9eef5;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    width: 0;
    background: linear-gradient(90deg, #2b5f9e 0%, #3f7bc2 100%);
    transition: width 0.3s ease;
}

.employee-card.pending .progress-fill,
.item-card.pending .progress-fill {
    background: linear-gradient(90deg, #a9732b 0%, #c48d3d 100%);
}

.employee-status {
    margin-top: 8px;
    color: var(--text-sub);
    font-size: 12px;
    text-align: right;
}

.detail-header {
    margin-bottom: 12px;
    padding: 16px 18px;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 12px;
}

.detail-title-wrap {
    min-width: 0;
}

.detail-title-wrap h2 {
    font-size: 28px;
    line-height: 1.2;
    margin-bottom: 4px;
}

.detail-subtitle {
    color: var(--text-sub);
    font-size: 13px;
}

.summary-cards {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
    margin-bottom: 12px;
}

.metric-card {
    background: #fff;
    border: 1px solid var(--line);
    border-radius: var(--radius-md);
    padding: 14px;
    box-shadow: var(--shadow-sm);
}

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

.card-value {
    font-size: 28px;
    line-height: 1;
    font-weight: 700;
}

.metric-total .card-value {
    color: var(--brand);
}

.metric-claimed .card-value {
    color: var(--success);
}

.metric-pending .card-value {
    color: var(--warning);
}

.items-list,
.history-list {
    display: grid;
    gap: 10px;
}

.item-card {
    border-left: 3px solid #ccd6e5;
    padding: 14px;
    box-shadow: var(--shadow-sm);
}

.item-card.pending {
    border-left-color: var(--warning);
}

.item-card.partial {
    border-left-color: var(--info);
}

.item-card.claimed {
    border-left-color: var(--success);
    background: #fbfdfb;
}

.item-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    min-width: 0;
}

.item-name {
    font-size: 16px;
    font-weight: 700;
}

.item-badge {
    border-radius: 999px;
    font-size: 12px;
    font-weight: 700;
    padding: 3px 8px;
}

.item-badge.pending {
    color: var(--warning);
    background: #fbf2e8;
}

.item-badge.partial {
    color: var(--info);
    background: #ebf2fb;
}

.item-badge.claimed {
    color: var(--success);
    background: #eaf5ee;
}

.item-progress {
    margin: 9px 0 8px;
}

.item-progress .progress-bar {
    margin-bottom: 5px;
}

.item-progress-text,
.quantity-label {
    font-size: 13px;
    color: var(--text-sub);
}

.item-actions,
.data-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.stats-panel,
.history-panel {
    margin-bottom: 12px;
}

.item-stat-card {
    width: 100%;
    padding: 14px;
    text-align: left;
    font: inherit;
    border-left: 3px solid #ccd6e5;
    cursor: pointer;
    transition: box-shadow 0.2s ease, border-color 0.2s ease;
}

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

.item-stat-card.active {
    border-left-color: var(--brand);
    box-shadow: var(--shadow-md);
}

.item-stat-name {
    font-size: 15px;
    font-weight: 700;
    margin-bottom: 8px;
}

.item-stat-meta {
    margin-top: 8px;
    font-size: 13px;
    color: var(--text-sub);
    display: flex;
    justify-content: space-between;
}

.history-header h3 {
    font-size: 18px;
    margin-bottom: 4px;
}

.history-header p {
    font-size: 13px;
    color: var(--text-sub);
    margin-bottom: 10px;
}

.history-item {
    display: grid;
    grid-template-columns: 140px 1fr auto;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
}

.history-time {
    font-size: 12px;
    color: var(--text-sub);
}

.history-user {
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
}

.history-action {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.action-tag {
    padding: 3px 8px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 700;
}

.action-tag.claim {
    color: var(--success);
    background: #eaf5ee;
}

.action-tag.revert {
    color: var(--danger);
    background: #f9e9e9;
}

.history-qty {
    font-size: 13px;
    color: var(--text-sub);
}

.history-modal {
    position: fixed;
    inset: 0;
    z-index: 11000;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.history-modal.open {
    display: flex;
}

.history-modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(15, 27, 45, 0.46);
}

.history-modal-dialog {
    position: relative;
    z-index: 1;
    width: min(860px, calc(100vw - 40px));
    max-height: min(84vh, 760px);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.history-modal-header {
    border-bottom: 1px solid var(--line);
    padding: 14px 16px;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 10px;
}

.history-modal-headtext h3 {
    font-size: 18px;
    margin-bottom: 4px;
}

.history-modal-headtext p {
    font-size: 13px;
    color: var(--text-sub);
}

.history-modal-close {
    min-height: 36px;
    padding: 0 12px;
}

.history-modal-body {
    padding: 12px;
    overflow: auto;
}

.history-modal-list {
    min-height: 80px;
}

.data-panel {
    padding-top: 18px;
}

.data-note {
    font-size: 13px;
    color: var(--text-sub);
    margin: 2px 0 12px;
}

.data-stats {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
    margin-bottom: 12px;
}

.data-stat {
    padding: 12px;
}

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

.data-stat-value {
    font-size: 22px;
    font-weight: 700;
    color: var(--brand);
}

.operation-log {
    border: 1px dashed var(--line-strong);
    border-radius: var(--radius-sm);
    background: var(--surface-weak);
    color: var(--text-sub);
    padding: 10px 12px;
    font-size: 13px;
}

.empty-state {
    width: 100%;
    border: 1px dashed var(--line-strong);
    border-radius: var(--radius-md);
    background: var(--surface-weak);
    text-align: center;
    padding: 28px 14px;
}

.empty-icon {
    font-size: 24px;
    color: var(--text-sub);
    margin-bottom: 6px;
}

.empty-text {
    font-size: 16px;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 4px;
}

.empty-hint {
    font-size: 13px;
    color: var(--text-sub);
}

.loading {
    position: fixed;
    inset: 0;
    z-index: 9999;
    background: rgba(243, 245, 248, 0.86);
    backdrop-filter: blur(1px);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.spinner {
    width: 42px;
    height: 42px;
    border: 3px solid #d8e2ef;
    border-top-color: var(--brand);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

.loading-text {
    margin-top: 10px;
    font-size: 14px;
    color: var(--brand);
    font-weight: 700;
}

.toast {
    position: fixed;
    left: 50%;
    bottom: 24px;
    transform: translateX(-50%);
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    color: #fff;
    font-size: 13px;
    font-weight: 700;
    box-shadow: var(--shadow-md);
    z-index: 10000;
}

.toast.success {
    background: var(--success);
}

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

.toast.info {
    background: var(--info);
}

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

@media (max-width: 1024px) {
    .hero-panel {
        flex-direction: column;
    }

    .hero-actions {
        justify-content: flex-start;
    }

    .summary-cards {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 768px) {
    #app {
        padding: calc(10px + var(--safe-top)) 10px calc(98px + var(--safe-bottom));
    }

    .top-nav {
        position: fixed;
        left: 10px;
        right: 10px;
        bottom: calc(8px + var(--safe-bottom));
        top: auto;
        margin: 0;
        padding: 6px;
        gap: 6px;
        border-radius: 14px;
        border-color: #d2dbe8;
        background: rgba(255, 255, 255, 0.95);
        backdrop-filter: blur(8px);
        box-shadow: 0 12px 28px rgba(17, 36, 69, 0.18);
    }

    .nav-btn {
        height: 46px;
        min-width: 0;
        font-size: 12px;
        font-weight: 600;
        padding: 0 6px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        border-radius: 10px;
    }

    .panel {
        border-radius: 14px;
    }

    .hero-panel,
    .detail-header,
    .content-panel {
        padding: 14px;
    }

    .hero-panel {
        gap: 10px;
    }

    .hero-main h1 {
        font-size: 22px;
        line-height: 1.3;
    }

    .hero-subtitle {
        font-size: 13px;
    }

    .detail-title-wrap h2 {
        font-size: 21px;
        line-height: 1.3;
    }

    .detail-header {
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
    }

    .detail-title-wrap {
        width: 100%;
    }

    .detail-title-wrap .hero-tag {
        margin-bottom: 6px;
    }

    .detail-header > .btn {
        align-self: flex-start;
        width: auto;
        min-height: 40px;
    }

    #detail-page .detail-header > .btn {
        width: 100%;
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }

    #detail-page .detail-title-wrap h2 {
        white-space: normal;
        word-break: keep-all;
        overflow-wrap: normal;
    }

    .toolbar {
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
        margin-bottom: 12px;
    }

    .search-box input {
        height: 46px;
        font-size: 16px;
    }

    .toolbar-meta {
        white-space: normal;
        font-size: 12px;
        text-align: left;
    }

    .employee-list,
    .stats-list {
        grid-template-columns: 1fr;
        gap: 10px;
    }

    .summary-cards,
    .data-stats {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 8px;
    }

    .metric-card {
        padding: 12px;
    }

    .card-value {
        font-size: 24px;
    }

    .employee-card,
    .item-card,
    .item-stat-card,
    .history-item,
    .data-stat {
        padding: 12px;
    }

    .employee-meta {
        font-size: 12px;
    }

    .employee-status {
        font-size: 11px;
    }

    .item-progress-text,
    .quantity-label,
    .item-stat-meta {
        font-size: 12px;
    }

    .item-stat-meta {
        gap: 8px;
        flex-wrap: wrap;
    }

    .history-item {
        grid-template-columns: 1fr auto;
        align-items: center;
        gap: 6px 8px;
    }

    .history-time {
        grid-column: 1 / -1;
    }

    .history-action {
        justify-self: end;
    }

    .item-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .item-actions,
    .data-actions {
        flex-direction: column;
        gap: 8px;
    }

    .item-actions .btn,
    .data-actions .btn,
    #stats-page .detail-header > .btn {
        width: 100%;
        min-height: 42px;
    }

    .history-modal {
        align-items: flex-end;
        padding: 0;
    }

    .history-modal-dialog {
        width: 100%;
        max-height: min(88vh, 100vh);
        border-bottom-left-radius: 0;
        border-bottom-right-radius: 0;
        border-left: 0;
        border-right: 0;
    }

    .history-modal-dialog::before {
        content: "";
        position: absolute;
        top: 7px;
        left: 50%;
        transform: translateX(-50%);
        width: 42px;
        height: 4px;
        border-radius: 999px;
        background: #cfd8e4;
    }

    .history-modal-header {
        position: sticky;
        top: 0;
        z-index: 2;
        background: var(--surface);
        padding: 18px 12px 10px;
    }

    .history-modal-body {
        padding: 10px;
        padding-bottom: calc(10px + var(--safe-bottom));
        overscroll-behavior: contain;
        -webkit-overflow-scrolling: touch;
    }

    .history-modal-close {
        min-height: 40px;
    }

    .history-modal-headtext p {
        font-size: 12px;
    }

    .data-note {
        font-size: 12px;
        line-height: 1.6;
    }

    .operation-log {
        min-height: 44px;
    }

    .toast {
        left: 10px;
        right: 10px;
        width: auto;
        transform: none;
        text-align: center;
        bottom: calc(86px + var(--safe-bottom));
    }
}

@media (max-width: 480px) {
    #app {
        padding: calc(8px + var(--safe-top)) 8px calc(96px + var(--safe-bottom));
    }

    .top-nav {
        left: 8px;
        right: 8px;
        bottom: calc(6px + var(--safe-bottom));
    }

    .hero-panel,
    .detail-header,
    .content-panel {
        padding: 12px;
    }

    .hero-main h1 {
        font-size: 20px;
    }

    .detail-title-wrap h2 {
        font-size: 19px;
    }

    .summary-cards,
    .data-stats {
        grid-template-columns: 1fr;
        gap: 8px;
    }

    .employee-meta {
        flex-direction: column;
        align-items: flex-start;
        gap: 4px;
    }

    .item-stat-meta {
        flex-direction: column;
        align-items: flex-start;
        gap: 4px;
    }

    .history-modal-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .history-modal-close {
        width: 100%;
    }

    .history-item {
        grid-template-columns: 1fr;
        align-items: flex-start;
    }

    .history-action {
        justify-self: start;
    }
}

@media print {
    .top-nav,
    .hero-actions,
    .item-actions,
    .data-actions,
    .btn,
    .loading,
    .toast {
        display: none !important;
    }

    body {
        background: #fff;
    }

    .panel,
    .metric-card,
    .employee-card,
    .item-card,
    .item-stat-card,
    .history-item {
        box-shadow: none;
        border: 1px solid #d0d6de;
    }
}

/* 实时刷新模式：禁用所有动画/过渡，界面静止更新 */
body.realtime-static *,
body.realtime-static *::before,
body.realtime-static *::after {
    animation: none !important;
    transition: none !important;
}

body.realtime-static .loading {
    display: none !important;
}

body.modal-open {
    overflow: hidden;
}
