:root {
    --bg: #eef2f6;
    --panel: #ffffff;
    --line: #d6dee6;
    --text: #152238;
    --muted: #66768a;
    --primary: #175cd3;
    --primary-dark: #1247a6;
    --accent: #00857a;
    --danger: #c92a2a;
    --warning-bg: #fff4e6;
    --warning: #b05d00;
    --soft: #f8fafc;
    --shadow: 0 12px 30px rgba(21, 34, 56, 0.08);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    color: var(--text);
    background: var(--bg);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", Arial, sans-serif;
    font-size: 14px;
    line-height: 1.45;
}

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

a:hover {
    text-decoration: underline;
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 10;
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    gap: 24px;
    min-height: 62px;
    padding: 0 28px;
    background: #fff;
    border-bottom: 1px solid var(--line);
    box-shadow: 0 2px 10px rgba(21, 34, 56, 0.04);
}

.brand {
    color: var(--text);
    font-weight: 700;
    font-size: 16px;
    max-width: 320px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.brand:hover {
    text-decoration: none;
}

.nav {
    display: flex;
    gap: 4px;
}

.nav a {
    padding: 8px 12px;
    color: var(--muted);
    border-radius: 6px;
}

.nav a.active,
.nav a:hover {
    color: #0b4fc7;
    background: #e8f0ff;
    text-decoration: none;
}

.userbar {
    display: flex;
    align-items: center;
    gap: 12px;
    color: var(--muted);
}

.page {
    width: min(1500px, calc(100% - 48px));
    margin: 22px auto 48px;
}

.page-head {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 20px;
    margin-bottom: 18px;
}

.detail-head {
    align-items: flex-start;
}

h1 {
    margin: 0;
    font-size: 25px;
    line-height: 1.2;
}

p {
    margin: 6px 0 0;
    color: var(--muted);
}

.actions,
.sticky-actions {
    display: flex;
    gap: 10px;
    align-items: center;
}

.pager {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    margin-top: 12px;
    padding: 12px 4px 0;
    color: var(--muted);
}

.pager-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

.button.disabled {
    pointer-events: none;
    opacity: 0.45;
}

.button,
button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 34px;
    padding: 0 14px;
    border: 1px solid var(--line);
    border-radius: 7px;
    background: #fff;
    color: var(--text);
    cursor: pointer;
    font: inherit;
}

.button:hover,
button:hover {
    border-color: #b8c4cf;
    text-decoration: none;
}

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

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

.button.danger,
button.danger {
    color: #fff;
    background: var(--danger);
    border-color: var(--danger);
}

.button.small,
button.small {
    min-height: 28px;
    padding: 0 10px;
}

.full {
    width: 100%;
}

.messages {
    display: grid;
    gap: 10px;
    margin-bottom: 16px;
}

.message {
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: #fff;
}

.message.success {
    border-color: #b2dfc2;
    background: #edf9f0;
}

.message.warning {
    border-color: #ffd8a8;
    background: var(--warning-bg);
}

.message.danger {
    border-color: #ffc9c9;
    background: #fff5f5;
}

.metric-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(180px, 1fr));
    gap: 14px;
    margin-bottom: 18px;
}

.metric,
.panel {
    min-width: 0;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
}

.metric {
    padding: 16px;
}

.hero {
    display: grid;
    grid-template-columns: minmax(280px, 0.9fr) minmax(520px, 1.7fr);
    gap: 16px;
    align-items: stretch;
    margin-bottom: 16px;
}

.hero-copy,
.hero-metric,
.summary-card {
    min-width: 0;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
}

.hero-copy {
    padding: 22px;
}

.hero-copy h1 {
    margin-top: 8px;
    font-size: 30px;
}

.eyebrow {
    color: var(--accent);
    font-weight: 700;
}

.hero-metrics {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 12px;
}

.hero-metric,
.summary-card {
    padding: 16px;
}

.hero-metric span,
.summary-card span {
    display: block;
    color: var(--muted);
}

.hero-metric strong,
.summary-card strong {
    display: block;
    margin-top: 10px;
    font-size: 24px;
    line-height: 1.1;
}

.hero-metric.accent strong,
.summary-card.accent strong {
    color: var(--primary);
}

.hero-metric.warning strong,
.summary-card.warning strong {
    color: var(--warning);
}

.section-summary {
    margin-bottom: 14px;
}

.summary-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(160px, 1fr));
    gap: 12px;
}

.metric span {
    display: block;
    color: var(--muted);
}

.metric strong {
    display: block;
    margin-top: 8px;
    font-size: 28px;
    line-height: 1;
}

.metric.warning strong {
    color: var(--warning);
}

.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 14px;
}

.panel {
    padding: 16px;
}

.panel.wide {
    grid-column: span 2;
}

.panel.full {
    grid-column: 1 / -1;
}

.panel-title {
    margin-bottom: 12px;
    font-weight: 700;
}

.panel-title small {
    display: block;
    margin-top: 4px;
    color: var(--muted);
    font-weight: 400;
    line-height: 1.35;
}

.bar-row {
    display: grid;
    grid-template-columns: minmax(84px, 1fr) 1.2fr minmax(46px, auto);
    gap: 10px;
    align-items: center;
    margin: 10px 0;
}

.bar-row span {
    color: var(--muted);
}

.bar-row div {
    height: 9px;
    overflow: hidden;
    background: #edf1f5;
    border-radius: 999px;
}

.bar-row i {
    display: block;
    height: 100%;
    background: var(--accent);
}

.bar-row b {
    text-align: right;
    font-weight: 600;
}

.filters {
    display: grid;
    grid-template-columns: minmax(240px, 1.5fr) repeat(4, minmax(130px, 1fr)) auto auto;
    gap: 10px;
    margin-bottom: 14px;
    padding: 12px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
}

input,
select,
textarea {
    width: 100%;
    min-height: 34px;
    padding: 7px 9px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: #fff;
    color: var(--text);
    font: inherit;
}

textarea {
    min-height: 72px;
    resize: vertical;
}

label {
    display: grid;
    gap: 6px;
    color: var(--muted);
}

label input,
label select,
label textarea {
    color: var(--text);
}

.table-wrap {
    overflow: auto;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
}

.data-table,
.compact {
    width: 100%;
    border-collapse: collapse;
}

.data-table th,
.data-table td,
.compact th,
.compact td {
    padding: 9px 11px;
    border-bottom: 1px solid var(--line);
    text-align: left;
    vertical-align: top;
}

.data-table th,
.compact th {
    color: var(--muted);
    background: var(--soft);
    font-weight: 600;
    white-space: nowrap;
}

.data-table tr:last-child td,
.compact tr:last-child td {
    border-bottom: 0;
}

.num {
    text-align: right !important;
    white-space: nowrap;
}

.name-cell {
    min-width: 260px;
}

.tag {
    display: inline-flex;
    align-items: center;
    min-height: 24px;
    padding: 0 8px;
    border-radius: 999px;
    background: #eef5fb;
    color: #245070;
    white-space: nowrap;
}

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

.empty {
    padding: 28px !important;
    color: var(--muted);
    text-align: center !important;
}

.edit-form {
    display: grid;
    gap: 14px;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 14px;
}

.compact-grid {
    gap: 10px;
}

.span-2 {
    grid-column: span 2;
}

.sticky-actions {
    position: sticky;
    bottom: 0;
    padding: 12px 0;
    background: linear-gradient(to top, var(--bg), rgba(245, 247, 250, 0.9));
}

.login-shell {
    min-height: calc(100vh - 48px);
    display: grid;
    place-items: center;
}

.login-box {
    width: min(380px, 100%);
    display: grid;
    gap: 16px;
    padding: 28px;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 8px;
}

.login-box h1 {
    margin-bottom: 8px;
}

.type-section {
    position: relative;
    overflow: hidden;
}

.type-section::before {
    content: "";
    position: absolute;
    inset: 0 auto 0 0;
    width: 4px;
    background: var(--line);
}

.type-section-slow::before {
    background: linear-gradient(to bottom, #175cd3, #5aa7ff);
}

.type-section-terminal::before {
    background: linear-gradient(to bottom, #00857a, #59c8ba);
}

.type-section-giftbox::before {
    background: linear-gradient(to bottom, #8b5cf6, #c084fc);
}

.form-panel .panel-title {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.inline-form,
.upload-form {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
}

.inline-form input,
.inline-form select,
.upload-form input {
    width: auto;
    min-width: 180px;
}

.row-actions form {
    margin: 0;
}

@media (max-width: 1100px) {
    .hero {
        grid-template-columns: 1fr;
    }

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

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

    .filters {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }

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

@media (max-width: 720px) {
    .topbar,
    .page-head {
        display: block;
    }

    .topbar {
        padding: 12px 14px 10px;
    }

    .nav {
        margin: 10px -2px 0;
        gap: 2px;
        flex-wrap: nowrap;
        overflow-x: auto;
        padding-bottom: 4px;
        scrollbar-width: none;
    }

    .nav::-webkit-scrollbar {
        display: none;
    }

    .nav a {
        flex: 0 0 auto;
        white-space: nowrap;
    }

    .userbar {
        margin-top: 10px;
        justify-content: space-between;
    }

    .page {
        width: calc(100% - 16px);
        margin-top: 12px;
    }

    .metric-grid,
    .dashboard-grid,
    .hero-metrics,
    .summary-grid,
    .filters,
    .form-grid {
        grid-template-columns: minmax(0, 1fr);
    }

    .panel.wide,
    .span-2 {
        grid-column: auto;
    }

    .page-head {
        margin-bottom: 14px;
    }

    .page-head .actions,
    .sticky-actions,
    .pager-actions,
    .inline-form,
    .upload-form {
        flex-wrap: wrap;
    }

    .page-head .actions {
        margin-top: 12px;
    }

    .page-head .actions .button,
    .sticky-actions .button,
    .pager-actions .button {
        flex: 1 1 0;
        min-width: 0;
    }

    .filters {
        padding: 10px;
        gap: 8px;
    }

    .filters .button {
        width: 100%;
    }

    .table-wrap {
        border-radius: 7px;
    }

    .dashboard-grid > .panel {
        overflow-x: auto;
    }

    .dashboard-grid > .panel > .data-table {
        min-width: 620px;
    }

    .data-table th,
    .data-table td,
    .compact th,
    .compact td {
        padding: 8px 9px;
        font-size: 13px;
    }

    .name-cell {
        min-width: 180px;
    }

    .hero-copy,
    .hero-metric,
    .summary-card,
    .panel {
        padding: 14px;
    }

    .hero-copy h1 {
        font-size: 24px;
    }

    .hero-metric strong,
    .summary-card strong {
        font-size: 20px;
    }

    .metric strong {
        font-size: 22px;
    }

    input,
    select,
    textarea,
    .button,
    button {
        min-height: 38px;
    }

    .edit-form {
        gap: 12px;
    }

    .form-grid {
        gap: 10px;
    }

    textarea {
        min-height: 68px;
    }
}
