:root {
    --bg: #f0f0f1;
    --card: #ffffff;
    --line: #dcdcde;
    --text: #1d2327;
    --muted: #646970;
    --blue: #2271b1;
    --blue-strong: #135e96;
    --danger: #b32d2e;
}

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background: var(--bg);
}

body.admin-locked .app-shell {
    display: none;
}

.check-line {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 10px;
    min-height: 44px;
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: #f6f7f7;
}

.check-line input {
    width: auto;
}

.pill {
    display: inline-flex;
    margin-left: 6px;
    padding: 3px 7px;
    border-radius: 999px;
    background: #eef6fc;
    border: 1px solid #c5d9ed;
    color: var(--blue-strong);
    font-size: 10px;
    font-weight: 800;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

td select {
    min-width: 120px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: #fff;
    color: var(--text);
    padding: 8px 10px;
}

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

.preview-grid > div {
    border: 1px solid var(--line);
    border-radius: 4px;
    background: #f6f7f7;
    padding: 14px;
}

.preview-grid h3 {
    margin: 0 0 8px;
    font-size: 14px;
}

.preview-grid p {
    margin: 4px 0;
    color: var(--muted);
}

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

.hidden {
    display: none !important;
}

.app-shell {
    width: min(1500px, calc(100% - 24px));
    margin: 12px auto 30px;
}

.topbar {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 4px;
    padding: 12px 16px;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 12px;
}

.brand-eyebrow {
    margin: 0 0 4px;
    font-size: 12px;
    color: var(--muted);
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

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

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

.tabs {
    display: flex;
    gap: 8px;
    margin: 14px 0 10px;
}

.tab {
    border: 1px solid var(--line);
    border-radius: 3px;
    background: #fff;
    padding: 8px 16px;
    cursor: pointer;
    font-size: 14px;
}

.tab.is-active {
    border-color: var(--blue);
    color: var(--blue);
    box-shadow: 0 0 0 1px var(--blue) inset;
}

.status {
    margin: 0 0 12px;
    padding: 10px 12px;
    border-radius: 3px;
    border: 1px solid var(--line);
    background: #fff;
    color: var(--muted);
    font-size: 14px;
}

.status.success {
    color: #0f6b3d;
    border-color: #99d3b4;
}

.status.error {
    color: #8f1d1d;
    border-color: #e2a4a4;
}

.screen {
    display: none;
}

.screen.is-active {
    display: block;
}

.layout {
    display: grid;
    gap: 12px;
}

.layout.two-col {
    grid-template-columns: 420px minmax(0, 1fr);
}

.layout.two-col.product-two-col {
    grid-template-columns: 520px minmax(0, 1fr);
}

.layout.single-col {
    grid-template-columns: 1fr;
}

.card {
    border: 1px solid var(--line);
    background: var(--card);
    border-radius: 4px;
}

.card-title {
    margin: 0;
    font-size: 18px;
}

.card > .card-title,
.card-head {
    padding: 12px;
    border-bottom: 1px solid var(--line);
}

.card-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
}

.card-head-tools {
    display: flex;
    gap: 8px;
    align-items: center;
}

.sticker-filter-tools {
    flex-wrap: wrap;
    justify-content: flex-end;
}

.sticker-filter-tools select {
    width: auto;
    min-width: 120px;
}

.table-emoji {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 52px;
    height: 52px;
    border: 1px solid var(--line);
    border-radius: 3px;
    background: #f6f7f7;
    font-size: 28px;
}

.form-stack {
    display: grid;
    gap: 10px;
    padding: 12px;
}

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

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

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

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

.field-block {
    display: grid;
    gap: 6px;
}

.variant-editor {
    border: 1px solid var(--line);
    border-radius: 4px;
    padding: 10px;
    background: #fff;
}

.variant-editor-head,
.variant-grid-head,
.variant-row,
.option-grid-head,
.option-row {
    display: grid;
    grid-template-columns: minmax(90px, 1fr) 64px minmax(180px, 1.6fr) 34px;
    gap: 8px;
    align-items: center;
}

.variant-editor-head {
    grid-template-columns: minmax(0, 1fr) auto;
}

.variant-editor-head > div {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.variant-name-field {
    max-width: 240px;
}

.option-grid-head,
.variant-grid-head {
    color: var(--muted);
    font-size: 12px;
}

.variant-rows {
    display: grid;
    gap: 6px;
}

.variant-row input {
    width: 100%;
}

.variant-row input[type="color"] {
    min-width: 44px;
    height: 34px;
    padding: 2px;
    cursor: pointer;
}

.variant-image-cell {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 90px auto;
    gap: 6px;
    align-items: center;
}

.variant-image-cell .variant-upload {
    white-space: nowrap;
    padding-left: 9px;
    padding-right: 9px;
}

.variant-row .variant-remove {
    width: 34px;
    height: 34px;
    padding: 0;
}

/* Name-only option rows: dimension options carry just a name; SKU/price/image live on combinations. */
.variant-grid-head.option-name-only-head,
.variant-row.option-name-only {
    grid-template-columns: minmax(120px, 1fr) 34px;
}

.option-grid-head,
.option-row {
    grid-template-columns: 58px minmax(110px, 1fr) minmax(180px, 1.6fr) 34px;
}

.option-row input[type="checkbox"] {
    width: auto;
    justify-self: center;
}

.option-row input {
    width: 100%;
}

.option-row .option-remove {
    width: 34px;
    height: 34px;
    padding: 0;
}

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

.table-category-filters {
    width: min(560px, 52vw);
}

.table-category-filters label {
    gap: 4px;
}

label > span,
.field-block > span,
.thumb-label {
    font-size: 13px;
    color: var(--muted);
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="url"],
input[type="search"],
select,
textarea {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 3px;
    padding: 8px 10px;
    font-size: 14px;
    background: #fff;
    color: var(--text);
}

input:focus,
select:focus,
textarea:focus {
    border-color: var(--blue);
    outline: none;
    box-shadow: 0 0 0 1px var(--blue);
}

textarea {
    resize: vertical;
}

.check {
    display: flex;
    align-items: center;
    gap: 8px;
}

.check input {
    width: auto;
}

.btn {
    border: 1px solid transparent;
    border-radius: 3px;
    padding: 8px 12px;
    font-size: 14px;
    cursor: pointer;
    background: #fff;
    color: var(--text);
    text-decoration: none;
}

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

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

.btn.ghost {
    border-color: var(--line);
    background: #f6f7f7;
}

.btn.ghost:hover {
    background: #ececec;
}

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

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

.thumb-block {
    border: 1px dashed var(--line);
    border-radius: 4px;
    padding: 10px;
    display: grid;
    gap: 10px;
}

.thumb-preview-wrap {
    display: grid;
    grid-template-columns: 92px 1fr;
    gap: 10px;
    align-items: start;
}

.thumb-preview {
    width: 92px;
    height: 92px;
    border: 1px solid var(--line);
    border-radius: 3px;
    object-fit: cover;
    background: #f6f7f7;
    display: none;
}

.thumb-preview.is-visible {
    display: block;
}

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

.gallery-wrap {
    display: grid;
    gap: 8px;
}

.gallery-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(58px, 72px));
    gap: 6px;
}

.gallery-item {
    position: relative;
}

.gallery-item img {
    width: 100%;
    aspect-ratio: 1 / 1;
    object-fit: cover;
    border: 1px solid var(--line);
    border-radius: 3px;
}

.gallery-item span {
    display: block;
    margin-top: 4px;
    color: var(--muted);
    font-size: 10px;
    text-align: center;
}

.gallery-remove {
    position: absolute;
    right: 2px;
    top: 2px;
    border: 0;
    background: rgba(0, 0, 0, 0.65);
    color: #fff;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    cursor: pointer;
}

.checkbox-grid {
    display: grid;
    gap: 6px;
    max-height: 120px;
    overflow: auto;
    border: 1px solid var(--line);
    border-radius: 3px;
    padding: 8px;
    background: #fff;
}

.checkbox-grid label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
}

.template-grid {
    display: grid;
    gap: 8px;
    max-height: 280px;
    overflow: auto;
}

.template-pill {
    display: grid;
    gap: 3px;
    border: 1px solid var(--line);
    border-radius: 4px;
    padding: 9px 10px;
    background: #fff;
}

.template-pill strong {
    font-size: 13px;
}

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

.table-search {
    width: min(260px, 100%);
}

.table-wrap {
    overflow: auto;
}

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

th,
td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--line);
    text-align: left;
    font-size: 13px;
    vertical-align: middle;
}

thead th {
    background: #f6f7f7;
}

.table-thumb {
    width: 46px;
    height: 46px;
    border: 1px solid var(--line);
    border-radius: 2px;
    object-fit: cover;
    background: #f6f7f7;
}

.badge {
    display: inline-flex;
    align-items: center;
    border: 1px solid var(--line);
    border-radius: 999px;
    padding: 2px 8px;
    font-size: 12px;
    color: var(--muted);
    margin-right: 6px;
    margin-bottom: 4px;
}

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

.row-link {
    border: 0;
    padding: 0;
    background: transparent;
    color: var(--blue);
    cursor: pointer;
    font-size: 13px;
}

.row-link.danger {
    color: var(--danger);
}

.sort-handle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border: 1px solid var(--line);
    border-radius: 4px;
    background: transparent;
    color: var(--muted);
    cursor: grab;
    font-size: 14px;
    line-height: 1;
    padding: 0;
    touch-action: none;
}

.sort-handle:disabled {
    cursor: not-allowed;
    opacity: 0.45;
}

.sort-handle:active {
    cursor: grabbing;
}

#categoryTableBody tr.dragging {
    opacity: 0.6;
    background: #f0f6ff;
}

#categoryTableBody tr.drop-before td:first-child {
    box-shadow: inset 0 2px 0 0 var(--blue);
}

#categoryTableBody tr.drop-after td:first-child {
    box-shadow: inset 0 -2px 0 0 var(--blue);
}
    color: var(--muted);
    text-align: center;
    padding: 22px;
}

.back-to-top-btn {
    position: fixed;
    right: 18px;
    bottom: 18px;
    z-index: 1000;
    width: 48px;
    height: 48px;
    border: 1px solid var(--line);
    border-radius: 50%;
    background: #fff;
    color: var(--text);
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    box-shadow: 0 10px 26px rgba(0, 0, 0, 0.16);
    opacity: 0;
    transform: translateY(10px);
    pointer-events: none;
    transition: opacity 0.18s ease, transform 0.18s ease;
}

.back-to-top-btn.is-visible {
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
}

@media (max-width: 1140px) {
    .layout.two-col {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 760px) {
    .app-shell {
        width: calc(100% - 12px);
        margin: 6px auto 20px;
    }

    .topbar {
        flex-direction: column;
    }

    .row,
    .row.row-3,
    .row.row-2,
    .category-select-grid,
    .option-grid-head,
    .option-row,
    .variant-editor-head,
    .variant-grid-head,
    .variant-row {
        grid-template-columns: 1fr;
    }

    .card-head {
        flex-direction: column;
        align-items: stretch;
    }

    .card-head-tools {
        flex-direction: column;
        align-items: stretch;
    }
}

/* Language switcher (shared with storefront) */
.lang-switcher { position: fixed; left: 18px; bottom: 18px; z-index: 400; font-family: Montserrat, "Noto Sans SC", system-ui, sans-serif; }
.lang-switcher-toggle { display: inline-flex; align-items: center; gap: 8px; padding: 9px 14px; border-radius: 999px; border: 1px solid rgba(255,255,255,.22); background: rgba(20,20,28,.72); backdrop-filter: blur(8px); color: #fff; font-size: 13px; font-weight: 600; letter-spacing: .03em; cursor: pointer; box-shadow: 0 6px 20px rgba(0,0,0,.35); transition: background .2s, transform .15s; }
.lang-switcher-toggle:hover { background: rgba(40,40,52,.85); transform: translateY(-1px); }
.lang-switcher-flag { display: inline-flex; align-items: center; justify-content: center; min-width: 22px; height: 22px; padding: 0 4px; border-radius: 6px; background: rgba(255,255,255,.12); font-size: 11px; font-weight: 700; }
.lang-switcher-caret { font-size: 10px; opacity: .7; }
.lang-switcher-menu { list-style: none; margin: 8px 0 0; padding: 6px; border-radius: 14px; border: 1px solid rgba(255,255,255,.16); background: rgba(20,20,28,.92); backdrop-filter: blur(10px); box-shadow: 0 10px 30px rgba(0,0,0,.45); display: none; min-width: 168px; }
.lang-switcher-menu.is-open { display: block; }
.lang-switcher-item { display: flex; align-items: center; gap: 10px; width: 100%; padding: 9px 10px; border: 0; background: transparent; color: rgba(255,255,255,.88); font-size: 13px; font-weight: 500; text-align: left; border-radius: 9px; cursor: pointer; transition: background .15s; }
.lang-switcher-item:hover { background: rgba(255,255,255,.1); }
.lang-switcher-item.is-active { background: rgba(35,213,171,.18); color: #fff; font-weight: 700; }

/* Admin panel UI is fixed to Chinese; hide the language switcher. */
#langSwitcher { display: none !important; }

/* ---- Combination variant matrix ---- */
.combination-block {
    margin-top: 14px;
    border-top: 1px dashed var(--line);
    padding-top: 10px;
}
.combination-grid-head,
.combination-rows .variant-row {
    display: grid;
    grid-template-columns: minmax(120px, 1fr) minmax(160px, 1.4fr) 54px 90px 34px;
    gap: 8px;
    align-items: center;
}
.combination-rows { display: grid; gap: 6px; }
.combo-summary { font-size: 12px; color: var(--muted); line-height: 1.3; }
.option-image-cell { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; gap: 6px; align-items: center; }
.option-image-cell .variant-upload { white-space: nowrap; padding-left: 9px; padding-right: 9px; }
.option-image-cell .variant-option-thumb { width: 40px; height: 40px; object-fit: cover; border-radius: 4px; border: 1px solid var(--line); background: #fff; }
.combo-stock-cell { display: flex; align-items: center; justify-content: center; cursor: pointer; }
.combo-stock-cell input { margin: 0; }

/* ---- Bulk combo price/stock ---- */
.combo-bulk-controls {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}
.combo-bulk-label {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 12px;
    color: var(--muted, #666);
    white-space: nowrap;
}
.combo-bulk-label span { white-space: nowrap; }
.combo-bulk-input {
    width: 64px;
    padding: 2px 5px;
    border: 1px solid var(--line, #ccc);
    border-radius: 3px;
    font-size: 12px;
    text-align: right;
}
.combo-bulk-input:focus { outline: none; border-color: var(--accent, #2563eb); box-shadow: 0 0 0 1px var(--accent, #2563eb); }

/* ---- Variant dimensions ---- */
.variant-dimensions { display: grid; gap: 12px; margin: 4px 0 2px; }
.variant-dimension {
    border: 1px solid var(--line);
    border-radius: 4px;
    padding: 10px;
    background: #fafafa;
}
.variant-dimension-head { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; }
.dimension-name-input { font-weight: 600; min-width: 180px; }
.variant-dimension-options { display: grid; gap: 6px; margin-bottom: 6px; }
.dimension-add-option { margin-top: 2px; justify-self: start; }
.variant-option-item { display: flex; gap: 6px; align-items: center; }
.variant-option-item [data-variant-name] { flex: 1; min-width: 0; }
.variant-option-head { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.4fr) 34px; gap: 8px; }
.dimension-name-input[readonly] { background: #f0f0f0; color: var(--muted); }
.dimension-type-select { min-width: 110px; }
.variant-add-controls { display: inline-flex; gap: 6px; align-items: center; }

/* ---- Storefront combination chips ---- */
.variant-dimension-chips { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 8px; }
.variant-dimension-chips .dim-label { font-size: 12px; color: var(--muted); margin-right: 2px; }
.variant-dimension-chips .chip-row { display: flex; flex-wrap: wrap; gap: 6px; }
.variant-chip {
    border: 1px solid rgba(255, 255, 255, 0.25);
    background: rgba(255, 255, 255, 0.06);
    color: inherit;
    border-radius: 999px;
    padding: 4px 12px;
    font-size: 12px;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
}
.variant-chip.is-selected { background: #fff; color: #111; border-color: #fff; font-weight: 700; }

/* ---- WooCommerce-style product editor (tabs + sidebar) ---- */
.wc-product-editor .wc-editor-layout {
    display: flex;
    align-items: flex-start;
    gap: 16px;
}
.wc-editor-main {
    flex: 1 1 auto;
    min-width: 0;
    display: flex;
    gap: 0;
    border: 1px solid var(--line);
    border-radius: 6px;
    overflow: hidden;
    background: var(--card);
}
.wc-data-tabs {
    flex: 0 0 160px;
    background: #f6f7f7;
    border-right: 1px solid var(--line);
    padding: 0;
    display: flex;
    flex-direction: column;
}
.wc-data-tab {
    appearance: none;
    text-align: left;
    background: transparent;
    border: 0;
    border-bottom: 1px solid var(--line);
    padding: 12px 14px;
    font-size: 13px;
    color: var(--text);
    cursor: pointer;
}
.wc-data-tab:hover { background: #eef0f0; }
.wc-data-tab.is-active {
    background: var(--card);
    border-right: 2px solid var(--blue);
    font-weight: 700;
    color: var(--blue-strong);
    margin-right: -1px;
}
.wc-data-panels { flex: 1 1 auto; min-width: 0; padding: 16px; }
.wc-data-panel { display: none; }
.wc-data-panel.is-active { display: block; }
.wc-data-panel .row,
.wc-data-panel label { margin-bottom: 12px; }
.wc-editor-side {
    flex: 0 0 280px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}
.wc-editor-side .field-block,
.wc-editor-side .thumb-block {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 14px;
}
.wc-editor-side .field-block > span { display: block; font-weight: 600; margin-bottom: 8px; }
.wc-product-editor .form-actions { margin-top: 16px; }
@media (max-width: 980px) {
    .wc-product-editor .wc-editor-layout { flex-direction: column; }
    .wc-data-tabs { flex-direction: row; flex-basis: auto; border-right: 0; border-bottom: 1px solid var(--line); overflow-x: auto; }
    .wc-data-tab { border-bottom: 0; border-right: 1px solid var(--line); white-space: nowrap; }
    .wc-data-tab.is-active { border-right: 1px solid var(--line); border-bottom: 2px solid var(--blue); margin-right: 0; margin-bottom: -1px; }
    .wc-editor-side { flex-basis: auto; width: 100%; }
}

.bulk-product-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    border-top: 1px solid var(--line);
    background: #f6f7f7;
}

.bulk-product-toolbar label:not(.check-line) {
    display: flex;
    align-items: center;
    gap: 7px;
    color: var(--muted);
    font-size: 13px;
}

.bulk-product-toolbar select,
.bulk-product-toolbar input[type="number"] {
    min-height: 36px;
    min-width: 150px;
    border: 1px solid var(--line);
    border-radius: 4px;
    padding: 6px 9px;
    background: #fff;
}

.product-select-col { width: 42px; text-align: center; }

@media (max-width: 800px) {
    .bulk-product-toolbar { align-items: stretch; }
    .bulk-product-toolbar label:not(.check-line) { justify-content: space-between; }
}
