:root {
    --bg: #f5f1ec;
    --surface: #ffffff;
    --surface-2: #faf8f5;
    --ink: #20242a;
    --muted: #6d7278;
    --line: #e7e1d9;
    --red: #c8102e;
    --red-dark: #9f0c25;
    --red-soft: #fdeef0;
    --green: #167a52;
    --green-soft: #eaf7f1;
    --amber: #b45309;
    --amber-soft: #fdf3e7;
    --blue: #1d6fa5;
    --blue-soft: #eaf4fb;
    --gray-soft: #f0eef0;
    --radius: 8px;
    --shadow: 0 1px 2px rgba(32, 36, 42, 0.05), 0 8px 24px rgba(32, 36, 42, 0.05);
}

* {
    box-sizing: border-box;
}

html {
    -webkit-text-size-adjust: 100%;
}

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

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

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

button {
    cursor: pointer;
}

.app {
    min-height: 100vh;
}

.sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 50;
    width: 248px;
    display: flex;
    flex-direction: column;
    background: #1f2328;
    color: #f5f2ee;
    padding: 18px 14px;
    transform: translateX(0);
    transition: transform 0.22s ease;
}

.brand {
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 4px 8px 18px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.09);
}

.brand svg {
    color: #f8c3cb;
}

.brand strong {
    display: block;
    font-size: 16px;
    letter-spacing: 0;
}

.brand span {
    display: block;
    color: rgba(245, 242, 238, 0.62);
    font-size: 12px;
}

.nav {
    display: flex;
    flex-direction: column;
    gap: 3px;
    margin-top: 16px;
    flex: 1;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: var(--radius);
    color: rgba(245, 242, 238, 0.76);
    transition: background 0.15s ease, color 0.15s ease;
}

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

.nav-item.active {
    background: var(--red);
    color: #fff;
}

.sidebar-foot {
    border-top: 1px solid rgba(255, 255, 255, 0.09);
    padding-top: 12px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.user-chip {
    display: flex;
    align-items: center;
    gap: 8px;
    color: rgba(245, 242, 238, 0.78);
    padding: 0 8px;
    font-size: 13px;
}

.sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 40;
    background: rgba(18, 20, 23, 0.45);
}

.main {
    margin-left: 248px;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 30;
    display: flex;
    align-items: center;
    gap: 12px;
    min-height: 62px;
    padding: 0 24px;
    background: rgba(255, 255, 255, 0.92);
    border-bottom: 1px solid var(--line);
    backdrop-filter: blur(10px);
}

.menu-button {
    display: none;
}

.topbar-title h1 {
    margin: 0;
    font-size: 17px;
    font-weight: 650;
    letter-spacing: 0;
}

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

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-left: auto;
}

.content {
    width: 100%;
    max-width: 1440px;
    margin: 0 auto;
    padding: 22px 24px 48px;
}

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

.panel {
    min-width: 0;
}

.panel-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 15px 18px;
    border-bottom: 1px solid var(--line);
}

.panel-head h2 {
    margin: 0;
    font-size: 15px;
    font-weight: 650;
    letter-spacing: 0;
}

.panel-head-tools {
    flex-wrap: wrap;
}

.bulk-bar {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
}

.check-label {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: var(--muted);
    font-size: 13px;
    white-space: nowrap;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    min-height: 38px;
    padding: 0 15px;
    border: 1px solid transparent;
    border-radius: var(--radius);
    background: transparent;
    font-weight: 600;
    white-space: nowrap;
    transition: background 0.15s ease, border-color 0.15s ease, transform 0.05s ease;
}

.btn:active {
    transform: translateY(1px);
}

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

.btn-primary:hover {
    background: var(--red-dark);
}

.btn-danger {
    background: var(--red-soft);
    color: var(--red-dark);
    border-color: #f4c1c8;
}

.btn-danger:hover {
    background: #fbe1e5;
}

.btn-ghost {
    border-color: var(--line);
    color: var(--ink);
    background: var(--surface);
}

.btn-ghost:hover {
    border-color: #d5ccc2;
    background: var(--surface-2);
}

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

.btn-icon {
    width: 38px;
    padding: 0;
}

.btn-block {
    width: 100%;
}

.btn-danger-text {
    color: var(--red-dark);
}

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

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

.input,
select.input,
textarea {
    width: 100%;
    min-height: 40px;
    padding: 8px 11px;
    border: 1px solid #d8d2ca;
    border-radius: var(--radius);
    background: #fff;
    outline: none;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.input:focus,
select.input:focus,
textarea:focus {
    border-color: var(--red);
    box-shadow: 0 0 0 3px rgba(200, 16, 46, 0.12);
}

textarea {
    min-height: 92px;
    resize: vertical;
    line-height: 1.5;
}

.input-sm {
    width: auto;
    min-height: 32px;
    padding: 4px 8px;
    font-size: 13px;
}

.field-inline {
    flex-direction: row;
    align-items: center;
    gap: 9px;
}

.field-inline > span {
    white-space: nowrap;
}

.field-inline .input {
    width: auto;
    min-width: 180px;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 13px;
    padding: 16px 18px;
}

.form-stack {
    display: flex;
    flex-direction: column;
    gap: 13px;
    padding: 16px 18px;
}

.form-actions {
    display: flex;
    align-items: end;
    gap: 10px;
}

.form-actions .btn {
    align-self: end;
}

.form-divider {
    border-top: 1px solid var(--line);
}

.inline-form {
    display: inline-block;
}

.hidden-form {
    display: none;
}

.filter-bar {
    display: flex;
    align-items: end;
    flex-wrap: wrap;
    gap: 10px;
    padding: 14px 16px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin-bottom: 18px;
}

.filter-inner {
    display: flex;
    align-items: end;
    flex-wrap: wrap;
    gap: 10px;
    flex: 1;
}

.bulk-bar-inside {
    padding: 10px 18px;
    border-bottom: 1px solid var(--line);
    background: var(--surface-2);
}

.page-tools {
    margin-bottom: 18px;
}

.page-tools .filter-bar {
    margin-bottom: 0;
}

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

.action-grid .card {
    margin-bottom: 0;
}

.panel-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 18px;
}

.panel-grid .card {
    margin-bottom: 0;
}

.status-grid {
    grid-template-columns: minmax(320px, 0.8fr) minmax(0, 1.2fr);
}

.settings-grid {
    grid-template-columns: minmax(0, 1.4fr) minmax(300px, 0.6fr);
}

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

.metric-card {
    display: flex;
    align-items: center;
    gap: 13px;
    padding: 18px;
    margin: 0;
}

.metric-icon {
    width: 44px;
    height: 44px;
    display: grid;
    place-items: center;
    border-radius: 50%;
    flex: 0 0 auto;
}

.metric-red {
    background: var(--red-soft);
    color: var(--red);
}

.metric-teal {
    background: var(--green-soft);
    color: var(--green);
}

.metric-amber {
    background: var(--amber-soft);
    color: var(--amber);
}

.metric-blue {
    background: var(--blue-soft);
    color: var(--blue);
}

.metric-label {
    display: block;
    color: var(--muted);
    font-size: 13px;
}

.metric-value {
    display: block;
    font-size: 24px;
    font-weight: 700;
    line-height: 1.2;
}

.table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

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

.table-wide {
    min-width: 1600px;
}

.table-resizable {
    table-layout: fixed;
    width: 100%;
    min-width: 960px;
}

.table-resizable th {
    position: relative;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.table-resizable td {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.resizer {
    position: absolute;
    top: 0;
    right: -4px;
    width: 8px;
    height: 100%;
    cursor: col-resize;
    z-index: 2;
}

.resizer:hover,
.resizer.active {
    background: rgba(200, 16, 46, 0.18);
}

body.resizing {
    user-select: none;
    cursor: col-resize;
}

.copyable-cell {
    user-select: text;
    cursor: text;
}

.copy-toast {
    position: fixed;
    left: 50%;
    bottom: 26px;
    transform: translateX(-50%);
    background: #20242a;
    color: #fff;
    padding: 8px 14px;
    border-radius: 6px;
    font-size: 13px;
    z-index: 100;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.18s ease;
}

.copy-toast.show {
    opacity: 1;
}

.order-cards {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
    padding: 14px;
}

.order-card {
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
    padding: 14px;
}

.order-card-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    flex-wrap: wrap;
    margin-bottom: 12px;
}

.order-card-title {
    display: flex;
    align-items: center;
    gap: 9px;
    flex-wrap: wrap;
}

.order-card-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px 16px;
    margin: 0;
}

.order-card-grid div {
    min-width: 0;
}

.order-card-grid dt {
    color: var(--muted);
    font-size: 12px;
    margin-bottom: 2px;
}

.order-card-grid dd {
    margin: 0;
    font-size: 13px;
    word-break: break-all;
}

.table th {
    position: sticky;
    top: 0;
    z-index: 1;
    text-align: left;
    padding: 10px 14px;
    color: var(--muted);
    background: var(--surface-2);
    border-bottom: 1px solid var(--line);
    font-weight: 600;
    white-space: nowrap;
}

.table td {
    padding: 10px 14px;
    border-bottom: 1px solid var(--line);
    vertical-align: middle;
}

.table tbody tr:hover {
    background: #fcfaf7;
}

.col-check {
    width: 40px;
}

.mono {
    font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
    font-size: 12.5px;
    word-break: break-all;
}

.token-cell {
    max-width: 300px;
}

.badge {
    display: inline-flex;
    align-items: center;
    min-height: 24px;
    padding: 2px 9px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
}

.badge-red {
    background: var(--red-soft);
    color: var(--red-dark);
}

.badge-green {
    background: var(--green-soft);
    color: var(--green);
}

.badge-blue {
    background: var(--blue-soft);
    color: var(--blue);
}

.badge-orange {
    background: var(--amber-soft);
    color: var(--amber);
}

.badge-gray {
    background: var(--gray-soft);
    color: #555b63;
}

.row-actions {
    display: flex;
    align-items: center;
    gap: 6px;
}

.row-form {
    display: flex;
    align-items: center;
    gap: 6px;
}

.flash {
    display: flex;
    align-items: flex-start;
    gap: 9px;
    padding: 11px 13px;
    border-radius: var(--radius);
    border: 1px solid;
    margin-bottom: 16px;
    font-size: 13.5px;
}

.flash svg {
    flex: 0 0 auto;
    margin-top: 2px;
}

.flash span {
    flex: 1;
}

.flash-success {
    background: var(--green-soft);
    border-color: #bfe6d3;
    color: #145d40;
}

.flash-danger {
    background: var(--red-soft);
    border-color: #f3c4cb;
    color: #8d0b21;
}

.flash-warning {
    background: var(--amber-soft);
    border-color: #f0d5b4;
    color: #7c3a08;
}

.flash-info {
    background: var(--blue-soft);
    border-color: #c3dfef;
    color: #15557b;
}

.flash-close {
    border: 0;
    background: transparent;
    color: inherit;
    opacity: 0.65;
    line-height: 1;
    padding: 0;
}

.banner {
    display: flex;
    align-items: center;
    gap: 13px;
    padding: 15px 17px;
    border-radius: var(--radius);
    border: 1px solid;
    margin-bottom: 18px;
}

.banner-icon {
    flex: 0 0 auto;
}

.banner-body {
    flex: 1;
    min-width: 0;
}

.banner-body strong {
    display: block;
}

.banner-body p {
    margin: 2px 0 0;
    font-size: 13px;
}

.banner-warning {
    background: var(--amber-soft);
    border-color: #f0d5b4;
    color: #7c3a08;
}

.banner-danger {
    background: var(--red-soft);
    border-color: #f3c4cb;
    color: #8d0b21;
}

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

.log-list {
    display: flex;
    flex-direction: column;
}

.log-item {
    display: grid;
    grid-template-columns: minmax(110px, 0.8fr) minmax(0, 1.6fr) auto;
    gap: 12px;
    align-items: center;
    padding: 11px 18px;
    border-bottom: 1px solid var(--line);
}

.log-item:last-child {
    border-bottom: 0;
}

.log-item p {
    margin: 0;
    color: #424850;
    word-break: break-word;
}

.log-item time {
    color: var(--muted);
    font-size: 12px;
    white-space: nowrap;
}

.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 14px;
    padding: 14px 18px;
    color: var(--muted);
    font-size: 13px;
}

.btn-row {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.raw-result {
    margin: 0;
    padding: 15px 18px;
    overflow-x: auto;
    background: #17191c;
    color: #dce5ec;
    border-radius: 0 0 var(--radius) var(--radius);
    font-family: "SFMono-Regular", Consolas, monospace;
    font-size: 12.5px;
    line-height: 1.55;
    max-height: 520px;
    overflow-y: auto;
}

.status-summary {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
    padding: 15px 18px;
}

.status-summary-item {
    min-width: 0;
}

.status-summary-item span {
    display: block;
    color: var(--muted);
    font-size: 12px;
    margin-bottom: 3px;
}

.status-summary-item b {
    display: block;
    word-break: break-all;
    font-weight: 600;
    font-size: 13.5px;
}

.generated-box {
    border-top: 1px solid var(--line);
    padding: 14px 18px;
    background: var(--surface-2);
}

.generated-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 9px;
}

.generated-head > span {
    color: var(--muted);
    font-size: 13px;
    font-weight: 600;
}

.generated-textarea {
    width: 100%;
    min-height: 56px;
    max-height: 220px;
    overflow: auto;
    resize: vertical;
    font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
    font-size: 12.5px;
    line-height: 1.5;
    background: var(--surface);
}

.security-list {
    list-style: none;
    margin: 0;
    padding: 6px 18px 14px;
}

.security-list li {
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 10px 0;
    border-bottom: 1px solid var(--line);
}

.security-list li:last-child {
    border-bottom: 0;
}

.security-list li span {
    flex: 1;
}

.security-list li b {
    font-size: 12px;
}

.security-list .ok {
    color: var(--green);
}

.muted {
    color: var(--muted);
}

.small {
    font-size: 12px;
}

.login-body {
    min-height: 100vh;
    display: grid;
    place-items: center;
    background: linear-gradient(150deg, #f6f1ec 0%, #ece4da 100%);
    padding: 20px;
}

.login-shell {
    width: 100%;
    max-width: 420px;
}

.login-card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 10px;
    box-shadow: 0 18px 50px rgba(32, 36, 42, 0.12);
    padding: 28px;
}

.login-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 20px;
}

.brand-mark {
    width: 46px;
    height: 46px;
    display: grid;
    place-items: center;
    border-radius: 10px;
    background: var(--red);
    color: #fff;
    flex: 0 0 auto;
}

.login-brand h1 {
    margin: 0;
    font-size: 20px;
    letter-spacing: 0;
}

.login-brand p {
    margin: 0;
    color: var(--muted);
    font-size: 13px;
}

.login-form {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.login-secure {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    margin-top: 18px;
    color: var(--muted);
    font-size: 12px;
    text-align: center;
}

.error-page {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 20px;
}

.error-card {
    width: 100%;
    max-width: 420px;
    text-align: center;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 32px 24px;
    box-shadow: var(--shadow);
}

.error-card .brand-mark {
    margin: 0 auto 14px;
}

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

.error-card p {
    color: var(--muted);
    margin: 0 0 18px;
}

@media (max-width: 1080px) {
    .metric-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .action-grid,
    .panel-grid,
    .status-grid,
    .settings-grid {
        grid-template-columns: 1fr;
    }

}

@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
        box-shadow: none;
    }

    body.sidebar-open {
        overflow: hidden;
    }

    body.sidebar-open .sidebar {
        transform: translateX(0);
        box-shadow: 0 0 50px rgba(0, 0, 0, 0.3);
    }

    body.sidebar-open .sidebar-backdrop {
        display: block;
    }

    .main {
        margin-left: 0;
    }

    .menu-button {
        display: inline-flex;
    }

    .topbar {
        padding: 0 14px;
    }

    .topbar-title span {
        display: none;
    }

    .content {
        padding: 16px 14px 40px;
    }

    .filter-bar {
        align-items: stretch;
    }

    .filter-bar .field-inline {
        width: 100%;
    }

    .filter-bar .field-inline .input {
        width: 100%;
        min-width: 0;
        flex: 1;
    }

    .filter-inner {
        width: 100%;
    }

    .filter-inner .btn {
        flex: 1;
    }

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

    .metric-grid {
        grid-template-columns: 1fr 1fr;
        gap: 12px;
    }

    .metric-card {
        padding: 14px;
    }

    .metric-value {
        font-size: 20px;
    }

    .log-item {
        grid-template-columns: 1fr;
        gap: 4px;
    }

    .log-item time {
        white-space: normal;
    }

    .bulk-bar {
        width: 100%;
    }

    .bulk-bar .input-sm,
    .bulk-bar .btn-sm {
        flex: 1;
    }

    .order-cards {
        grid-template-columns: 1fr;
    }

}

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

    .login-card {
        padding: 22px 18px;
    }

    .btn-row {
        flex-direction: column;
    }

    .btn-row .btn {
        width: 100%;
    }

    .status-summary {
        grid-template-columns: 1fr;
    }

    .order-card-grid {
        grid-template-columns: 1fr;
    }
}
