:root {
    --page: #f4f6f5;
    --surface: #ffffff;
    --surface-soft: #f8faf9;
    --sidebar: #202522;
    --sidebar-muted: #aeb9b2;
    --text: #1d2420;
    --muted: #6a746e;
    --border: #dce2de;
    --brand: #267052;
    --brand-dark: #1d5a41;
    --blue: #376a89;
    --amber: #9b661f;
    --red: #a94141;
    --shadow: 0 8px 24px rgba(27, 37, 31, 0.06);
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
    background: var(--page);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", Arial, sans-serif;
    font-size: 14px;
    line-height: 1.55;
    letter-spacing: 0;
}
a { color: inherit; }
button, input, select, textarea { font: inherit; letter-spacing: 0; }
button { cursor: pointer; }
img { max-width: 100%; display: block; }

.auth-page {
    min-height: 100vh;
    display: grid;
    grid-template-columns: minmax(320px, 42%) minmax(420px, 1fr);
    background: var(--surface);
}
.auth-brand {
    background: var(--sidebar);
    color: #fff;
    padding: 52px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    min-height: 100vh;
}
.brand-lockup { display: flex; align-items: center; gap: 13px; }
.brand-mark {
    width: 42px;
    height: 42px;
    display: grid;
    place-items: center;
    border-radius: 6px;
    background: var(--brand);
    color: #fff;
    font-size: 15px;
    font-weight: 800;
}
.brand-lockup strong, .brand-lockup small { display: block; }
.brand-lockup strong { font-size: 17px; }
.brand-lockup small { margin-top: 2px; color: var(--sidebar-muted); }
.auth-signal { max-width: 420px; }
.auth-signal h1 { margin: 0 0 14px; font-size: 34px; line-height: 1.25; }
.auth-signal p { margin: 0; color: #c7d0ca; font-size: 15px; }
.auth-meta { display: flex; gap: 26px; color: var(--sidebar-muted); font-size: 13px; }
.auth-meta strong { display: block; margin-top: 4px; color: #fff; font-size: 16px; }
.auth-main { display: grid; place-items: center; padding: 44px 24px; }
.auth-card { width: min(440px, 100%); }
.auth-card .eyebrow { color: var(--brand); font-weight: 700; margin-bottom: 9px; }
.auth-card h2 { margin: 0; font-size: 28px; }
.auth-card > p { margin: 8px 0 28px; color: var(--muted); }
.auth-switch { margin-top: 20px; color: var(--muted); text-align: center; }
.auth-switch a { color: var(--brand-dark); font-weight: 700; text-decoration: none; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 244px minmax(0, 1fr); }
.side-nav {
    position: sticky;
    top: 0;
    height: 100vh;
    background: var(--sidebar);
    color: #fff;
    padding: 22px 16px;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
}
.side-nav .brand-lockup { padding: 0 8px 20px; border-bottom: 1px solid #343a36; }
.nav-label { color: #748079; font-size: 12px; font-weight: 700; margin: 22px 10px 8px; }
.nav-list { display: grid; gap: 4px; }
.nav-list a {
    min-height: 42px;
    padding: 10px 12px;
    border-radius: 5px;
    color: var(--sidebar-muted);
    display: flex;
    align-items: center;
    justify-content: space-between;
    text-decoration: none;
}
.nav-list a:hover, .nav-list a.active { background: #303833; color: #fff; }
.nav-list a.active::after { content: ""; width: 3px; height: 18px; background: #4ca47d; border-radius: 2px; }
.side-account { margin-top: auto; border-top: 1px solid #343a36; padding: 18px 9px 0; }
.side-account strong, .side-account small { display: block; overflow-wrap: anywhere; }
.side-account small { color: var(--sidebar-muted); margin-top: 3px; }
.side-account form { margin-top: 12px; }
.logout-button { border: 0; background: transparent; color: #d4dbd7; padding: 0; }

.app-main { min-width: 0; }
.top-bar {
    min-height: 68px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 0 28px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
}
.top-bar h1 { margin: 0; font-size: 20px; }
.breadcrumb { color: var(--muted); font-size: 13px; margin-top: 2px; }
.top-balance { text-align: right; }
.top-balance small, .top-balance strong { display: block; }
.top-balance small { color: var(--muted); }
.top-balance strong { color: var(--brand-dark); font-size: 18px; }
.page-content { padding: 24px 28px 42px; }
.page-actions { display: flex; justify-content: space-between; gap: 16px; align-items: center; margin-bottom: 18px; }
.page-actions h2 { margin: 0; font-size: 18px; }
.page-actions p { margin: 3px 0 0; color: var(--muted); }
.button-row { display: flex; flex-wrap: wrap; gap: 9px; align-items: center; }

.button, button.button {
    min-height: 38px;
    border: 1px solid var(--border);
    border-radius: 5px;
    padding: 8px 14px;
    background: var(--surface);
    color: var(--text);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    text-decoration: none;
    font-weight: 650;
}
.button:hover { border-color: #adb8b1; background: var(--surface-soft); }
.button.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.button.primary:hover { background: var(--brand-dark); }
.button.danger { color: var(--red); border-color: #e4bcbc; }
.button.warning { color: var(--amber); border-color: #dfc698; }
.button.small { min-height: 32px; padding: 5px 10px; font-size: 13px; }
.button:disabled { opacity: .55; cursor: not-allowed; }

.flash { margin: 0 0 18px; padding: 12px 14px; border: 1px solid; border-radius: 5px; }
.flash.success { color: #1d6043; background: #eef8f2; border-color: #bcdcc9; }
.flash.error { color: #8f3333; background: #fff1f1; border-color: #e7baba; }

.stats-grid { display: grid; grid-template-columns: repeat(4, minmax(150px, 1fr)); gap: 14px; margin-bottom: 18px; }
.stat {
    min-height: 112px;
    padding: 17px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 6px;
    box-shadow: var(--shadow);
}
.stat small { color: var(--muted); }
.stat strong { display: block; margin: 9px 0 5px; font-size: 28px; line-height: 1; }
.stat span { color: var(--muted); font-size: 13px; }
.stat.green strong { color: var(--brand-dark); }
.stat.blue strong { color: var(--blue); }
.stat.amber strong { color: var(--amber); }

.content-grid { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(280px, .65fr); gap: 18px; }
.panel {
    min-width: 0;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 6px;
    box-shadow: var(--shadow);
}
.panel + .panel { margin-top: 18px; }
.panel-header { min-height: 58px; padding: 14px 17px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; gap: 14px; align-items: center; }
.panel-header h3 { margin: 0; font-size: 16px; }
.panel-header p { margin: 2px 0 0; color: var(--muted); font-size: 13px; }
.panel-body { padding: 18px; }
.panel.full { grid-column: 1 / -1; }

.data-table { width: 100%; border-collapse: collapse; }
.data-table th, .data-table td { padding: 12px 14px; text-align: left; border-bottom: 1px solid #e8ece9; vertical-align: middle; }
.data-table th { background: #f7f9f8; color: #5e6962; font-size: 12px; font-weight: 700; white-space: nowrap; }
.data-table tr:last-child td { border-bottom: 0; }
.data-table td strong, .data-table td small { display: block; }
.data-table td small { margin-top: 3px; color: var(--muted); }
.table-wrap { overflow-x: auto; }
.table-actions { display: flex; gap: 7px; align-items: center; white-space: nowrap; }
.table-actions form { margin: 0; }

.badge { display: inline-flex; min-height: 26px; align-items: center; padding: 3px 9px; border-radius: 999px; font-size: 12px; font-weight: 700; background: #eef2ef; color: #536159; white-space: nowrap; }
.badge.active, .badge.completed, .badge.matched { background: #e9f5ee; color: #246344; }
.badge.queued, .badge.running { background: #eaf2f7; color: var(--blue); }
.badge.pending_gateway, .badge.pending { background: #fbf1df; color: var(--amber); }
.badge.failed, .badge.suspended, .badge.deleted { background: #fbeaea; color: var(--red); }

.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 17px; }
.form-field { display: grid; gap: 7px; min-width: 0; }
.form-field.full { grid-column: 1 / -1; }
.form-field label, .field-label { font-weight: 700; color: #36403a; }
.form-field small { color: var(--muted); }
.input, input.input, select.input, textarea.input {
    width: 100%;
    border: 1px solid #cfd7d2;
    border-radius: 5px;
    background: #fff;
    color: var(--text);
    outline: none;
}
input.input, select.input { min-height: 42px; padding: 8px 11px; }
textarea.input { min-height: 100px; padding: 10px 11px; resize: vertical; }
.input:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(38, 112, 82, .11); }
.form-footer { display: flex; justify-content: flex-end; gap: 9px; margin-top: 20px; padding-top: 18px; border-top: 1px solid var(--border); }
.choice-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 9px; }
.choice {
    min-height: 42px;
    border: 1px solid var(--border);
    border-radius: 5px;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    background: var(--surface-soft);
}
.choice input { accent-color: var(--brand); }
.search-bar { display: flex; flex-wrap: wrap; gap: 9px; }
.search-bar .input { width: auto; min-width: 210px; }

.empty-state { padding: 48px 20px; text-align: center; color: var(--muted); }
.empty-state strong { display: block; color: var(--text); font-size: 16px; margin-bottom: 5px; }
.empty-state .button { margin-top: 16px; }
.detail-list { display: grid; gap: 0; }
.detail-row { min-height: 48px; display: grid; grid-template-columns: 150px minmax(0, 1fr); gap: 18px; align-items: center; border-bottom: 1px solid #e8ece9; }
.detail-row:last-child { border-bottom: 0; }
.detail-row span { color: var(--muted); }
.detail-row strong { overflow-wrap: anywhere; }

.asset-grid { display: grid; grid-template-columns: repeat(4, minmax(180px, 1fr)); gap: 14px; }
.asset-card { border: 1px solid var(--border); border-radius: 6px; overflow: hidden; background: var(--surface); }
.asset-image { aspect-ratio: 4 / 3; background: #edf1ee; }
.asset-image img { width: 100%; height: 100%; object-fit: cover; }
.asset-info { padding: 12px; }
.asset-info strong, .asset-info small { display: block; }
.asset-info small { color: var(--muted); margin-top: 3px; }
.asset-controls { padding: 0 12px 12px; display: flex; gap: 7px; }
.sku-thumb { width: 54px; height: 54px; object-fit: cover; border-radius: 4px; background: #edf1ee; }
.sku-cell { display: flex; align-items: center; gap: 10px; min-width: 220px; }

.gateway-state { border-left: 4px solid var(--amber); padding: 14px 16px; background: #fffaf0; }
.gateway-state.configured { border-left-color: var(--brand); background: #f1f8f4; }
.gateway-state strong { display: block; margin-bottom: 3px; }
.gateway-state p { margin: 0; color: var(--muted); }
.code-value { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; overflow-wrap: anywhere; }

@media (max-width: 1120px) {
    .stats-grid { grid-template-columns: repeat(2, minmax(150px, 1fr)); }
    .asset-grid { grid-template-columns: repeat(3, minmax(160px, 1fr)); }
}
@media (max-width: 860px) {
    .auth-page { grid-template-columns: 1fr; }
    .auth-brand { min-height: 240px; padding: 28px; }
    .auth-signal { margin: 40px 0 20px; }
    .auth-signal h1 { font-size: 27px; }
    .auth-meta { display: none; }
    .app-shell { grid-template-columns: 1fr; }
    .side-nav { position: static; height: auto; padding: 14px; }
    .side-nav .brand-lockup { border-bottom: 0; padding-bottom: 10px; }
    .nav-label, .side-account { display: none; }
    .nav-list { display: flex; overflow-x: auto; padding-bottom: 3px; }
    .nav-list a { flex: 0 0 auto; }
    .nav-list a.active::after { display: none; }
    .content-grid { grid-template-columns: 1fr; }
    .panel.full { grid-column: auto; }
    .asset-grid { grid-template-columns: repeat(2, minmax(145px, 1fr)); }
}
@media (max-width: 620px) {
    .top-bar { padding: 12px 16px; align-items: flex-start; }
    .top-balance { display: none; }
    .page-content { padding: 18px 14px 32px; }
    .page-actions { align-items: flex-start; flex-direction: column; }
    .stats-grid, .form-grid { grid-template-columns: 1fr; }
    .form-field.full { grid-column: auto; }
    .choice-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .asset-grid { grid-template-columns: 1fr; }
    .search-bar, .search-bar .input, .search-bar .button { width: 100%; }
    .detail-row { grid-template-columns: 1fr; gap: 2px; padding: 10px 0; }
}
