:root {
    --bg: #f5f7fa;
    --panel: #ffffff;
    --text: #17202a;
    --muted: #6b7280;
    --line: #d9e0e8;
    --primary: #176b87;
    --primary-strong: #0f5369;
    --accent: #d97706;
    --danger: #b42318;
    --success: #0f766e;
}

* {
    box-sizing: border-box;
}

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

a {
    color: inherit;
    text-decoration: none;
}

input,
select,
button {
    font: inherit;
}

code {
    padding: 2px 5px;
    border-radius: 4px;
    background: #eef2f7;
}

.app-shell {
    display: grid;
    grid-template-columns: 230px minmax(0, 1fr);
    min-height: 100vh;
}

.sidebar {
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
    background: #16232e;
    color: #fff;
    padding: 22px 18px;
}

.brand {
    font-size: 18px;
    font-weight: 700;
    margin-bottom: 22px;
}

.user-box {
    display: grid;
    gap: 4px;
    padding: 12px;
    border: 1px solid rgba(255, 255, 255, .12);
    border-radius: 8px;
    background: rgba(255, 255, 255, .06);
    margin-bottom: 18px;
}

.user-box span {
    color: rgba(255, 255, 255, .72);
    font-size: 12px;
}

.nav {
    display: grid;
    gap: 6px;
}

.nav a {
    padding: 10px 12px;
    border-radius: 7px;
    color: rgba(255, 255, 255, .78);
}

.nav a.active,
.nav a:hover {
    background: rgba(255, 255, 255, .12);
    color: #fff;
}

.nav-group {
    display: grid;
    gap: 6px;
}

.nav-toggle {
    width: 100%;
    min-height: 40px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 12px;
    border: 0;
    border-radius: 7px;
    background: transparent;
    color: rgba(255, 255, 255, .78);
    cursor: pointer;
    text-align: left;
}

.nav-toggle:hover,
.nav-toggle.active {
    background: rgba(255, 255, 255, .12);
    color: #fff;
}

.nav-toggle span {
    transition: transform .18s ease;
}

.nav-group.open > .nav-toggle span {
    transform: rotate(180deg);
}

.nav-sub {
    display: none;
    gap: 4px;
    padding-left: 10px;
}

.nav-group.open > .nav-sub {
    display: grid;
}

.nav-sub a {
    min-height: 34px;
    padding: 8px 12px 8px 18px;
    font-size: 13px;
}

/* 二级折叠 (营销策划 → 专属优惠/拉人进群) */
.nav-sub .nav-group .nav-toggle {
    min-height: 34px;
    padding: 6px 10px 6px 18px;
    font-size: 13px;
    color: rgba(255, 255, 255, .68);
}

.nav-sub .nav-sub a {
    padding-left: 32px;
    font-size: 12.5px;
    color: rgba(255, 255, 255, .62);
}

.main {
    min-width: 0;
}

.topbar {
    min-height: 68px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 0 28px;
    border-bottom: 1px solid var(--line);
    background: #fff;
}

.topbar h1 {
    margin: 0;
    font-size: 22px;
}

.content {
    padding: 24px 28px 40px;
}

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

.metric-grid {
    display: grid;
    grid-template-columns: repeat(6, minmax(140px, 1fr));
    gap: 14px;
    margin-bottom: 24px;
}

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

.metric,
.panel,
.auth-card {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
}

.metric {
    padding: 16px;
    display: grid;
    gap: 8px;
}

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

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

.panel {
    padding: 18px;
    margin-bottom: 20px;
}

.section-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    margin: 22px 0 12px;
}

.section-head.compact {
    margin: 0 0 12px;
}

.section-head h2 {
    margin: 0;
    font-size: 18px;
}

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

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

table {
    width: 100%;
    min-width: 980px;
    border-collapse: collapse;
}

th,
td {
    padding: 11px 12px;
    border-bottom: 1px solid var(--line);
    text-align: left;
    vertical-align: middle;
    white-space: nowrap;
}

th {
    background: #f0f4f8;
    color: #384454;
    font-weight: 650;
}

tbody tr:hover {
    background: #f8fafc;
}

tfoot th {
    background: #fff7ed;
}

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

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 36px;
    padding: 8px 13px;
    border: 1px solid var(--line);
    border-radius: 7px;
    background: #fff;
    color: var(--text);
    cursor: pointer;
}

.btn:hover {
    border-color: #b7c3cf;
    background: #f8fafc;
}

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

.btn.primary:hover {
    border-color: var(--primary-strong);
    background: var(--primary-strong);
}

.btn.active {
    border-color: var(--primary);
    background: #e8f5f8;
    color: var(--primary-strong);
}

.btn.danger-btn {
    border-color: #fecaca;
    color: var(--danger);
}

.btn.danger-btn:hover {
    border-color: #fca5a5;
    background: #fff1f2;
}

.btn.small {
    min-height: 30px;
    padding: 5px 9px;
    font-size: 12px;
}

.btn.full {
    width: 100%;
}

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

.form-stack {
    display: grid;
    gap: 16px;
}

.link-spend-field {
    max-width: 360px;
}

.grid-form {
    display: grid;
    grid-template-columns: repeat(4, minmax(160px, 1fr));
    gap: 14px;
    align-items: end;
}

.filter-bar {
    display: grid;
    grid-template-columns: minmax(180px, 1fr) minmax(180px, 1fr) auto;
    gap: 14px;
    align-items: end;
}

.paid-store-filter {
    grid-template-columns: minmax(220px, 360px) auto;
    margin: 14px 0 12px;
}

.filter-actions {
    display: flex;
    gap: 10px;
}

.loss-limit-form {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 190px;
}

.loss-limit-form input {
    min-width: 96px;
}

.sort-link {
    color: inherit;
    text-decoration: none;
    display: inline-block;
}
.sort-link:hover {
    color: #3498db;
}

.warning-row {
    background: #fff5f5;
}

.warning-row:hover {
    background: #ffecec;
}

.report-history-alert {
    border-color: #fca5a5;
    background: #fff7f7;
}

.report-history-alert h2,
.report-history-alert p,
.report-history-alert .tag {
    color: var(--danger);
}

.report-history-alert .tag {
    background: #fee2e2;
}

.grid-form.three {
    grid-template-columns: repeat(3, minmax(160px, 1fr));
}

.product-basic-form,
.product-fee-form {
    display: grid;
    max-width: 620px;
    gap: 14px;
}

.product-fee-form {
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #f8fafc;
}

label {
    display: grid;
    gap: 7px;
}

label span {
    color: #394453;
    font-weight: 600;
}

input,
select {
    width: 100%;
    min-height: 38px;
    padding: 8px 10px;
    border: 1px solid #cbd5e1;
    border-radius: 7px;
    background: #fff;
    color: var(--text);
}

textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #cbd5e1;
    border-radius: 7px;
    background: #fff;
    color: var(--text);
    resize: vertical;
    line-height: 1.7;
}

input:focus,
select:focus,
textarea:focus {
    outline: 2px solid rgba(23, 107, 135, .16);
    border-color: var(--primary);
}

.ai-answer {
    line-height: 1.8;
    white-space: normal;
}

.ai-loading {
    padding: 12px 14px;
    border: 1px solid #fde68a;
    border-radius: 8px;
    background: #fffbeb;
    color: #92400e;
}

.ai-record {
    display: grid;
    gap: 14px;
}

.ai-context-picker {
    display: grid;
    grid-template-columns: auto auto minmax(220px, 1fr);
    gap: 14px;
    align-items: end;
    padding: 12px 14px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #f8fafc;
}

.record-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
    color: var(--muted);
}

.qa-block {
    display: grid;
    gap: 8px;
}

.qa-block h3 {
    margin: 0;
    font-size: 15px;
}

.prompt-table table {
    min-width: 900px;
}

.prompt-snippet {
    max-width: 640px;
    margin-top: 5px;
    white-space: normal;
    line-height: 1.6;
}

.prompt-card-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 14px;
    align-items: stretch;
    margin-bottom: 22px;
}

.prompt-card {
    min-height: 190px;
    display: grid;
    grid-template-rows: 1fr auto;
    gap: 16px;
    padding: 18px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
}

.prompt-card h3 {
    margin: 0 0 10px;
    font-size: 17px;
}

.prompt-card p {
    margin: 0 0 14px;
    color: #475569;
    line-height: 1.7;
}

.prompt-use-intro {
    margin-bottom: 16px;
    padding: 12px 14px;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    background: #f8fafc;
    color: #475569;
    line-height: 1.7;
}

.align-end {
    align-self: end;
}

.fee-grid {
    display: grid;
    grid-template-columns: minmax(180px, 260px) minmax(160px, 1fr) minmax(180px, 260px) minmax(160px, 1fr);
    gap: 14px;
    align-items: end;
}

.check-row {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-height: 38px;
}

.check-row input {
    width: 16px;
    min-height: 16px;
}

.check-row.slim {
    min-height: auto;
}

.field-label {
    color: #394453;
    font-weight: 650;
}

.store-check-list {
    display: flex;
    flex-wrap: wrap;
    align-content: flex-start;
    gap: 8px 12px;
    max-height: 150px;
    overflow: auto;
    padding: 9px 10px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #f8fafc;
}

.store-check-list.compact {
    max-width: 420px;
    max-height: 110px;
    margin: 8px 0;
}

.store-bind-form {
    display: grid;
    gap: 8px;
    margin-top: 8px;
}

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

.tab-row,
.warning-list {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin: 12px 0;
}

.sub-tabs {
    margin-top: 4px;
}

.sku-import-modal[hidden] {
    display: none;
}

.sku-import-modal {
    position: fixed;
    inset: 0;
    z-index: 30;
    display: grid;
    place-items: center;
    padding: 24px;
    background: rgba(15, 23, 42, .42);
}

.sku-import-dialog {
    width: min(720px, 100%);
    display: grid;
    gap: 14px;
    padding: 20px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    box-shadow: 0 24px 70px rgba(15, 23, 42, .22);
}

.sku-import-dialog p {
    margin: 0;
    line-height: 1.7;
}

.alert {
    padding: 12px 14px;
    margin-bottom: 16px;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    background: #fff;
}

.alert.success {
    border-color: #99f6e4;
    background: #f0fdfa;
    color: var(--success);
}

.alert.danger {
    border-color: #fecaca;
    background: #fff1f2;
    color: var(--danger);
}

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

.tag,
.status {
    display: inline-flex;
    align-items: center;
    min-height: 24px;
    padding: 3px 8px;
    border-radius: 999px;
    background: #eef2f7;
    color: #344054;
    font-size: 12px;
    margin-right: 4px;
}

.danger-tag {
    background: #fee2e2;
    color: #991b1b;
}

.warning-note {
    max-width: 360px;
    white-space: normal;
    line-height: 1.45;
    border-radius: 8px;
}

.status.on {
    background: #dcfce7;
    color: #166534;
}

.status.off {
    background: #fee2e2;
    color: #991b1b;
}

.inline-form {
    display: inline;
}

.product-summary {
    display: grid;
    grid-template-columns: repeat(5, minmax(130px, 1fr));
    gap: 14px;
}

.product-summary div {
    display: grid;
    gap: 6px;
}

.product-data-switch {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 14px;
    margin: 16px 0 20px;
}

.product-data-option {
    display: grid;
    gap: 8px;
    padding: 18px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
}

.product-data-option:hover,
.product-data-option.active {
    border-color: rgba(23, 107, 135, .5);
    background: #f8fbfc;
}

.product-data-option strong {
    font-size: 17px;
}

.product-data-option span {
    color: var(--muted);
    line-height: 1.7;
}

.product-data-dropzone {
    display: grid;
    gap: 14px;
    place-items: center;
    min-height: 230px;
    padding: 26px;
    border: 1px dashed #9fb3c8;
    border-radius: 8px;
    background: #f8fafc;
    text-align: center;
}

.product-data-dropzone.is-dragging {
    border-color: var(--primary);
    background: #eef7fa;
}

.product-data-dropzone strong {
    display: block;
    margin-bottom: 8px;
    font-size: 18px;
}

.product-data-dropzone span {
    color: var(--muted);
}

.product-data-upload-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 10px;
}

.product-data-history-table table {
    min-width: 2200px;
}

.auth-page {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
    background: linear-gradient(135deg, #f5f7fa 0%, #e7edf4 100%);
}

.auth-card {
    width: min(420px, 100%);
    padding: 26px;
}

.auth-card h1 {
    margin: 0 0 8px;
    font-size: 24px;
}

.auth-card p {
    margin: 0 0 20px;
}

.draw-workbench {
    display: grid;
    grid-template-columns: minmax(620px, 1fr) 450px;
    gap: 18px;
    height: calc(100vh - 132px);
    min-height: 720px;
}

.draw-canvas-shell,
.draw-panel {
    min-width: 0;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
}

.draw-canvas-shell {
    display: grid;
    grid-template-rows: 54px minmax(0, 1fr);
    overflow: hidden;
}

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

.draw-canvas-top div:first-child,
.draw-panel-head div {
    display: grid;
    gap: 3px;
}

.draw-canvas-top span,
.draw-panel-head span {
    color: var(--muted);
    font-size: 12px;
}

.draw-canvas-top .save-saving {
    color: #92400e;
}

.draw-canvas-top .save-saved {
    color: var(--success);
}

.draw-canvas-top .save-error {
    color: var(--danger);
}

.draw-zoom-pill {
    display: inline-flex;
    align-items: center;
    min-height: 30px;
    padding: 4px 10px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: #f8fafc;
    color: #334155;
}

.draw-stage {
    position: relative;
    overflow: hidden;
    cursor: grab;
    touch-action: none;
    background-color: #f8fafc;
    background-image: radial-gradient(#dbe3ee 1px, transparent 1px);
    background-size: 24px 24px;
}

.draw-stage:active {
    cursor: grabbing;
}

.draw-world {
    position: absolute;
    inset: 0;
    transform-origin: 0 0;
    will-change: transform;
}

.canvas-image-node {
    position: absolute;
    overflow: hidden;
    border: 2px solid rgba(255, 255, 255, .9);
    border-radius: 8px;
    background: #fff;
    box-shadow: 0 14px 32px rgba(15, 23, 42, .14);
    cursor: move;
    user-select: none;
}

.canvas-image-node img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
    pointer-events: none;
}

.canvas-image-node.selected {
    border-color: #2f80ed;
    box-shadow: 0 0 0 3px rgba(47, 128, 237, .18), 0 14px 32px rgba(15, 23, 42, .18);
}

.canvas-image-node.guide-highlight {
    border-color: #22c55e;
    box-shadow: 0 0 0 5px rgba(34, 197, 94, .22), 0 14px 32px rgba(15, 23, 42, .18);
}

.draw-marquee {
    position: absolute;
    z-index: 20;
    border: 1px solid #2f80ed;
    background: rgba(47, 128, 237, .14);
    pointer-events: none;
}

.draw-guide {
    position: absolute;
    z-index: 32;
    padding: 8px 12px;
    border-radius: 999px;
    background: #0f766e;
    color: #fff;
    box-shadow: 0 10px 26px rgba(15, 118, 110, .26);
    pointer-events: none;
}

.selection-bar {
    position: absolute;
    z-index: 34;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px;
    border: 1px solid rgba(15, 23, 42, .1);
    border-radius: 8px;
    background: rgba(255, 255, 255, .95);
    box-shadow: 0 12px 32px rgba(15, 23, 42, .16);
}

.selection-bar span {
    padding: 0 6px;
    color: #334155;
    font-weight: 650;
}

.selection-bar button,
.draw-toolbar button,
.output-actions button {
    min-height: 32px;
    padding: 6px 10px;
    border: 1px solid var(--line);
    border-radius: 7px;
    background: #fff;
    color: #17202a;
    cursor: pointer;
}

.selection-bar button:hover,
.draw-toolbar button:hover,
.output-actions button:hover {
    border-color: #b7c3cf;
    background: #f8fafc;
}

.draw-toolbar {
    position: absolute;
    left: 50%;
    bottom: 18px;
    z-index: 30;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 8px;
    max-width: min(720px, calc(100% - 36px));
    padding: 8px;
    border: 1px solid rgba(15, 23, 42, .1);
    border-radius: 8px;
    background: rgba(255, 255, 255, .94);
    box-shadow: 0 14px 36px rgba(15, 23, 42, .16);
    transform: translateX(-50%);
}

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

.draw-panel {
    display: grid;
    grid-template-rows: 54px minmax(0, 1fr) auto;
    overflow: hidden;
}

.output-list {
    min-height: 0;
    overflow-y: auto;
    padding: 14px;
    background: #f8fafc;
}

.draw-empty {
    display: grid;
    place-items: center;
    min-height: 160px;
    color: var(--muted);
    text-align: center;
}

.output-card {
    display: grid;
    gap: 10px;
    margin-bottom: 12px;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
}

.output-title {
    display: flex;
    justify-content: space-between;
    gap: 10px;
}

.output-title span,
.output-meta,
.output-prompt {
    color: var(--muted);
    font-size: 12px;
}

.output-prompt {
    display: -webkit-box;
    overflow: hidden;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    line-height: 1.6;
}

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

.output-thumbs button {
    overflow: hidden;
    padding: 0;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    cursor: pointer;
    aspect-ratio: 1;
}

.output-thumbs img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

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

.draw-composer {
    display: grid;
    gap: 12px;
    padding: 14px;
    border-top: 1px solid var(--line);
    background: #fff;
}

.composer-label {
    margin-bottom: 8px;
    color: #394453;
    font-weight: 650;
}

.ref-strip {
    display: flex;
    min-height: 74px;
    gap: 8px;
    overflow-x: auto;
    padding-bottom: 2px;
}

.ref-thumb,
.ref-add {
    position: relative;
    flex: 0 0 68px;
    width: 68px;
    height: 68px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #f8fafc;
}

.ref-thumb img {
    width: 100%;
    height: 100%;
    display: block;
    object-fit: cover;
    border-radius: 8px;
}

.ref-thumb button {
    position: absolute;
    top: -7px;
    right: -7px;
    width: 22px;
    height: 22px;
    border: 0;
    border-radius: 999px;
    background: #17202a;
    color: #fff;
    cursor: pointer;
}

.ref-add {
    display: grid;
    place-items: center;
    color: var(--primary);
    font-size: 24px;
    cursor: pointer;
}

.prompt-box {
    display: grid;
    gap: 7px;
}

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

.draw-control-grid label span,
.prompt-box span {
    color: #394453;
    font-weight: 650;
}

.draw-generate {
    grid-column: 1 / -1;
}

.draw-generating {
    padding: 10px 12px;
    border: 1px solid #fde68a;
    border-radius: 8px;
    background: #fffbeb;
    color: #92400e;
}

@media (max-width: 1100px) {
    .metric-grid {
        grid-template-columns: repeat(3, minmax(140px, 1fr));
    }

    .preview-grid {
        grid-template-columns: repeat(2, minmax(150px, 1fr));
    }

    .grid-form,
    .grid-form.three,
    .filter-bar,
    .fee-grid,
    .product-summary {
        grid-template-columns: repeat(2, minmax(160px, 1fr));
    }
}

@media (max-width: 1180px) {
    .draw-workbench {
        grid-template-columns: 1fr;
        height: auto;
        min-height: 0;
    }

    .draw-canvas-shell {
        height: 680px;
    }

    .draw-panel {
        min-height: 720px;
    }
}

@media (max-width: 760px) {
    .app-shell {
        grid-template-columns: 1fr;
    }

    .sidebar {
        position: static;
    }

    .topbar {
        padding: 16px;
    }

    .content {
        padding: 18px 16px 30px;
    }

    .metric-grid,
    .preview-grid,
    .grid-form,
    .grid-form.three,
    .filter-bar,
    .fee-grid,
    .product-summary,
    .ai-context-picker {
        grid-template-columns: 1fr;
    }

    .section-head,
    .form-actions {
        align-items: stretch;
        flex-direction: column;
    }

    .draw-canvas-shell {
        height: 620px;
    }

    .draw-panel {
        min-height: 680px;
    }

    .draw-control-grid {
        grid-template-columns: 1fr;
    }

    .selection-bar {
        max-width: calc(100% - 24px);
        flex-wrap: wrap;
    }
}
