* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: #f5f6f8;
    color: #1f2937;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
    font-size: 14px;
}

a {
    color: #1455d9;
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

.topbar {
    align-items: center;
    background: #ffffff;
    border-bottom: 1px solid #e5e7eb;
    display: flex;
    justify-content: space-between;
    min-height: 68px;
    padding: 12px 28px;
}

.topbar-actions {
    align-items: center;
    display: flex;
    gap: 18px;
}

.admin-nav {
    align-items: center;
    display: flex;
    gap: 12px;
}

.admin-nav a {
    border-radius: 999px;
    color: #4b5563;
    font-weight: 600;
    padding: 8px 12px;
}

.admin-nav a.active,
.admin-nav a:hover {
    background: #eef2ff;
    color: #1f3a8a;
    text-decoration: none;
}

.brand {
    color: #111827;
    font-size: 18px;
    font-weight: 700;
}

.subtitle {
    color: #6b7280;
    margin-top: 4px;
}

.container {
    margin: 28px auto;
    max-width: 1760px;
    padding: 0 24px;
}

.panel {
    background: #ffffff;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
    overflow: hidden;
    padding: 24px;
}

.panel + .toolbar {
    margin-top: 24px;
}

.login-panel {
    margin: 72px auto 0;
    max-width: 420px;
}

.toolbar {
    display: flex;
    justify-content: flex-end;
    margin-bottom: 14px;
}

.source-list-toolbar {
    align-items: flex-start;
    gap: 16px;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    justify-content: initial;
}

.source-search-form {
    align-items: flex-end;
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    margin: 0;
}

.source-search-form label {
    display: grid;
    gap: 6px;
}

.source-search-form label:first-child {
    min-width: 280px;
}

.source-search-form span {
    color: #374151;
    font-size: 13px;
    font-weight: 600;
}

.source-list-summary {
    color: #6b7280;
    font-size: 13px;
    margin-bottom: 12px;
}

.source-list-footer {
    align-items: center;
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    justify-content: space-between;
    padding-top: 16px;
    margin-top: 18px;
    border-top: 1px solid #e5e7eb;
}

.source-list-footer .pagination {
    justify-content: flex-end;
    margin-left: auto;
}

.page-size-form {
    align-items: center;
    display: flex;
    gap: 10px;
    margin: 0;
}

.page-size-form label {
    align-items: center;
    display: flex;
    gap: 10px;
}

.page-size-form span {
    color: #374151;
    font-size: 13px;
    font-weight: 600;
}

.page-size-form select {
    min-width: 140px;
}

.toolbar-form {
    justify-content: flex-start;
}

.toolbar-with-title {
    display: grid;
    gap: 12px;
}

.toolbar-with-title h2 {
    font-size: 18px;
    margin: 0;
}

.inline-create-form {
    align-items: center;
    display: grid;
    gap: 10px;
    grid-template-columns: minmax(260px, 420px) auto;
    margin: 0;
}

.admin-create-form {
    grid-template-columns: minmax(150px, 1fr) minmax(150px, 1fr) minmax(150px, 1fr) minmax(150px, 220px) auto;
    max-width: 980px;
}

.inline-status-form {
    margin: 0;
}

.button {
    align-items: center;
    background: #1f6feb;
    border: 1px solid #1f6feb;
    border-radius: 6px;
    color: #ffffff;
    cursor: pointer;
    display: inline-flex;
    font: inherit;
    font-weight: 600;
    justify-content: center;
    min-height: 38px;
    padding: 0 16px;
}

.button:hover {
    background: #185abc;
    text-decoration: none;
}

.button-ghost {
    background: #ffffff;
    border-color: #d1d5db;
    color: #374151;
}

.button-ghost:hover {
    background: #f9fafb;
}

.form {
    display: grid;
    gap: 18px;
}

.form label {
    display: grid;
    gap: 8px;
}

.form span {
    color: #374151;
    font-weight: 600;
}

.form .field-note {
    color: #6b7280;
    font-size: 12px;
    font-weight: 400;
}

.form-field-title {
    color: #374151;
    font-weight: 600;
}

.readonly-input {
    background: #f3f4f6;
    color: #6b7280;
    cursor: not-allowed;
}

input,
select {
    border: 1px solid #d1d5db;
    border-radius: 6px;
    color: #111827;
    font: inherit;
    min-height: 40px;
    padding: 8px 10px;
    width: 100%;
}

input:focus,
select:focus {
    border-color: #1f6feb;
    box-shadow: 0 0 0 3px rgba(31, 111, 235, 0.14);
    outline: none;
}

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

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

.preview-modal {
    align-items: center;
    display: flex;
    inset: 0;
    justify-content: center;
    padding: 24px;
    position: fixed;
    z-index: 50;
}

.preview-modal-backdrop {
    background: rgba(15, 23, 42, 0.48);
    inset: 0;
    position: absolute;
}

.preview-modal-card {
    background: #ffffff;
    border-radius: 10px;
    box-shadow: 0 20px 45px rgba(15, 23, 42, 0.24);
    max-height: calc(100vh - 48px);
    max-width: 1120px;
    overflow: hidden;
    position: relative;
    width: min(1120px, 100%);
}

.preview-modal-header {
    align-items: center;
    border-bottom: 1px solid #e5e7eb;
    display: flex;
    justify-content: space-between;
    padding: 16px 20px;
}

.preview-modal-header h3 {
    font-size: 18px;
    margin: 0;
}

.preview-modal-close {
    background: transparent;
    border: 0;
    color: #6b7280;
    cursor: pointer;
    font-size: 26px;
    line-height: 1;
    padding: 0 4px;
}

.preview-modal-body {
    max-height: calc(100vh - 130px);
    overflow: auto;
    padding: 18px 20px 20px;
}

.preview-table {
    table-layout: fixed;
}

.preview-table th,
.preview-table td {
    font-size: 13px;
    white-space: pre-wrap;
    word-break: break-word;
}

.preview-table th:first-child,
.preview-table td:first-child {
    width: 120px;
}

.preview-field-name {
    color: #111827;
    font-weight: 700;
}

.preview-empty,
.preview-error {
    border-radius: 8px;
    padding: 14px 16px;
}

.preview-empty {
    background: #f9fafb;
    color: #6b7280;
}

.preview-error {
    background: #fef2f2;
    color: #b91c1c;
}

.preview-local-panel {
    display: grid;
    gap: 14px;
}

.preview-local-note {
    background: #eff6ff;
    border-radius: 8px;
    color: #1d4ed8;
    padding: 12px 14px;
}

.preview-local-upload {
    display: grid;
    gap: 8px;
}

.preview-local-file-name {
    color: #6b7280;
    font-size: 13px;
}

.preview-local-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.preview-local-result {
    border-top: 1px solid #e5e7eb;
    padding-top: 16px;
}

.file-current {
    color: #6b7280;
    line-height: 1.5;
}

table {
    border-collapse: collapse;
    width: 100%;
}

th,
td {
    border-bottom: 1px solid #e5e7eb;
    padding: 13px 12px;
    text-align: left;
    vertical-align: top;
}

th {
    background: #f9fafb;
    color: #374151;
    font-weight: 700;
    white-space: nowrap;
}

td {
    color: #1f2937;
}

td:nth-child(3) {
    max-width: 300px;
    word-break: break-all;
}

tr:last-child td {
    border-bottom: 0;
}

.pagination {
    align-items: center;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: flex-end;
    margin: 0;
}

.pagination a,
.pagination span {
    align-items: center;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    color: #374151;
    display: inline-flex;
    font-size: 13px;
    font-weight: 600;
    justify-content: center;
    min-height: 34px;
    min-width: 34px;
    padding: 0 10px;
}

.pagination a:hover,
.pagination .active {
    background: #eef4ff;
    border-color: #9bbcff;
    color: #1455d9;
    text-decoration: none;
}

.pagination .disabled,
.pagination .ellipsis {
    background: #f9fafb;
    color: #9ca3af;
}

.empty {
    color: #6b7280;
    padding: 36px 12px;
    text-align: center;
}

.actions {
    align-items: center;
    display: flex;
    gap: 12px;
    white-space: nowrap;
}

.actions form {
    margin: 0;
}

.link-button {
    background: none;
    border: 0;
    color: #1455d9;
    cursor: pointer;
    font: inherit;
    padding: 0;
}

.link-button:hover {
    text-decoration: underline;
}

.alert {
    border-radius: 6px;
    margin-bottom: 16px;
    padding: 12px 14px;
}

.alert-success {
    background: #ecfdf3;
    border: 1px solid #b7ebc6;
    color: #166534;
}

.alert-error {
    background: #fef2f2;
    border: 1px solid #fecaca;
    color: #991b1b;
}

.checkbox-label {
    align-items: center;
    display: inline-flex;
    gap: 8px;
    white-space: nowrap;
}

.checkbox-label input {
    accent-color: #3b72f6;
    min-height: auto;
    width: auto;
}

.inventory-layout {
    align-items: flex-start;
    display: grid;
    gap: 18px;
    grid-template-columns: 224px minmax(0, 1fr);
}

.inventory-sidebar {
    padding: 18px;
}

.inventory-sidebar h2,
.inventory-section h2 {
    color: #111827;
    font-size: 16px;
    margin: 0 0 14px;
}

.sidebar-search {
    font-size: 13px;
    margin: 0 0 12px;
    min-height: 36px;
    padding: 7px 10px;
}

.brand-list {
    display: grid;
    gap: 6px;
}

.brand-list a {
    border-radius: 6px;
    color: #374151;
    display: block;
    line-height: 1.35;
    padding: 10px 12px;
    word-break: break-word;
}

.brand-list a[hidden] {
    display: none;
}

.brand-list a:hover,
.brand-list a.active {
    background: #eef4ff;
    color: #1455d9;
    text-decoration: none;
}

.sidebar-empty {
    color: #6b7280;
    line-height: 1.6;
}

.sidebar-search-empty {
    color: #6b7280;
    font-size: 13px;
    line-height: 1.5;
    margin-top: 10px;
}

.inventory-main {
    min-width: 0;
}

.inventory-header {
    align-items: center;
    display: flex;
    justify-content: space-between;
    margin-bottom: 18px;
}

.inventory-header h1 {
    color: #111827;
    font-size: 22px;
    margin: 0;
}

.warehouse-tabs {
    border-bottom: 1px solid #e5e7eb;
    display: flex;
    gap: 6px;
    margin-bottom: 18px;
}

.warehouse-tabs a {
    border: 1px solid transparent;
    border-radius: 6px 6px 0 0;
    color: #4b5563;
    display: inline-flex;
    font-weight: 600;
    margin-bottom: -1px;
    min-height: 38px;
    padding: 9px 16px;
}

.warehouse-tabs a:hover,
.warehouse-tabs a.active {
    background: #ffffff;
    border-color: #e5e7eb #e5e7eb #ffffff;
    color: #1455d9;
    text-decoration: none;
}

.source-summary {
    align-items: center;
    background: #f9fafb;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    display: flex;
    gap: 16px;
    justify-content: space-between;
    margin-bottom: 22px;
    padding: 14px 16px;
}

.source-summary .label {
    color: #6b7280;
    display: block;
    font-size: 13px;
    margin-bottom: 5px;
}

.source-summary a {
    word-break: break-all;
}

.inventory-section {
    margin-top: 22px;
}

.inventory-bulk-actions {
    align-items: center;
    display: flex;
    gap: 10px;
    justify-content: flex-start;
    margin-bottom: 12px;
}

.diff-filter-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 12px;
}

.diff-filter-tabs a {
    background: #ffffff;
    border: 1px solid #d1d5db;
    border-radius: 999px;
    color: #374151;
    font-size: 12px;
    font-weight: 700;
    padding: 6px 10px;
}

.diff-filter-tabs a.active,
.diff-filter-tabs a:hover {
    background: #eef4ff;
    border-color: #9bbcff;
    color: #1455d9;
    text-decoration: none;
}

.select-all {
    align-items: center;
    display: inline-flex;
    gap: 6px;
}

.select-all input,
.cell-select input {
    min-height: auto;
    width: auto;
}

.table-wrap {
    max-width: 100%;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    position: relative;
}

.inventory-table-scroll {
    min-width: 0;
}

.table-scrollbar-top {
    height: 16px;
    margin-bottom: 6px;
    overflow-x: scroll;
    overflow-y: hidden;
    scrollbar-color: #9ca3af #eef2f7;
}

.table-scrollbar-top-spacer {
    height: 1px;
}

.table-scrollbar-top::-webkit-scrollbar,
.table-wrap::-webkit-scrollbar {
    height: 12px;
}

.table-scrollbar-top::-webkit-scrollbar-track,
.table-wrap::-webkit-scrollbar-track {
    background: #eef2f7;
    border-radius: 999px;
}

.table-scrollbar-top::-webkit-scrollbar-thumb,
.table-wrap::-webkit-scrollbar-thumb {
    background: #9ca3af;
    border: 2px solid #eef2f7;
    border-radius: 999px;
}

.table-scrollbar-top::-webkit-scrollbar-thumb:hover,
.table-wrap::-webkit-scrollbar-thumb:hover {
    background: #6b7280;
}

.inventory-data-table {
    --inventory-actions-width: 78px;
    --inventory-brand-sku-width: 150px;
    --inventory-brand-stock-width: 92px;
    --inventory-diff-width: 84px;
    --inventory-external-sku-width: 116px;
    --inventory-external-stock-width: 106px;
    --inventory-product-id-width: 94px;
    --inventory-select-width: 42px;
    border-collapse: separate;
    border-spacing: 0;
    table-layout: fixed;
    min-width: 100%;
    width: max-content;
}

.inventory-data-table th,
.inventory-data-table td {
    background: #ffffff;
    font-size: 12px;
    line-height: 1.45;
    padding: 9px 7px;
    white-space: normal;
    word-break: break-word;
}

.inventory-data-table th {
    background: #f9fafb;
}

.inventory-data-table .cell-sku,
.inventory-data-table .cell-details {
    color: #111827;
}

.inventory-data-table .cell-details {
    min-width: 128px;
    width: 128px;
}

.inventory-data-table .cell-sku {
    width: var(--inventory-brand-sku-width);
}

.inventory-data-table .cell-select {
    max-width: var(--inventory-select-width);
    min-width: var(--inventory-select-width);
    text-align: center;
    width: var(--inventory-select-width);
}

.inventory-data-table .cell-diff {
    max-width: var(--inventory-diff-width);
    min-width: var(--inventory-diff-width);
    width: var(--inventory-diff-width);
}

.inventory-data-table .cell-brand-sku {
    max-width: var(--inventory-brand-sku-width);
    min-width: var(--inventory-brand-sku-width);
    width: var(--inventory-brand-sku-width);
}

.inventory-data-table .cell-description {
    min-width: 230px;
    width: 230px;
}

.inventory-data-table .cell-compact {
    min-width: 86px;
    width: 86px;
}

.inventory-data-table .cell-brand-stock {
    max-width: var(--inventory-brand-stock-width);
    min-width: var(--inventory-brand-stock-width);
    width: var(--inventory-brand-stock-width);
}

.inventory-data-table .cell-yd-product-id {
    max-width: var(--inventory-product-id-width);
    min-width: var(--inventory-product-id-width);
    width: var(--inventory-product-id-width);
}

.inventory-data-table .cell-yd-sku {
    max-width: var(--inventory-external-sku-width);
    min-width: var(--inventory-external-sku-width);
    width: var(--inventory-external-sku-width);
}

.inventory-data-table .cell-yd-stock {
    max-width: var(--inventory-external-stock-width);
    min-width: var(--inventory-external-stock-width);
    width: var(--inventory-external-stock-width);
}

.inventory-data-table .cell-actions {
    max-width: var(--inventory-actions-width);
    min-width: var(--inventory-actions-width);
    width: var(--inventory-actions-width);
}

.inventory-data-table .inventory-sticky-left,
.inventory-data-table .inventory-sticky-right {
    position: sticky;
    z-index: 2;
}

.inventory-data-table thead .inventory-sticky-left,
.inventory-data-table thead .inventory-sticky-right {
    background: #f9fafb;
    z-index: 4;
}

.inventory-data-table .sticky-left-select {
    left: 0;
}

.inventory-data-table .sticky-left-diff {
    left: var(--inventory-select-width);
}

.inventory-data-table .sticky-left-brand-sku {
    box-shadow: 7px 0 10px -10px rgba(15, 23, 42, 0.7);
    left: calc(var(--inventory-select-width) + var(--inventory-diff-width));
}

.inventory-data-table .sticky-right-actions {
    right: 0;
}

.inventory-data-table .sticky-right-external-stock {
    right: var(--inventory-actions-width);
}

.inventory-data-table .sticky-right-product-id {
    right: calc(var(--inventory-actions-width) + var(--inventory-external-stock-width));
}

.inventory-data-table .sticky-right-external-sku {
    right: calc(
        var(--inventory-actions-width) +
        var(--inventory-external-stock-width) +
        var(--inventory-product-id-width)
    );
}

.inventory-data-table .sticky-right-brand-stock {
    box-shadow: -7px 0 10px -10px rgba(15, 23, 42, 0.7);
    right: calc(
        var(--inventory-actions-width) +
        var(--inventory-external-stock-width) +
        var(--inventory-product-id-width) +
        var(--inventory-external-sku-width)
    );
}

.inventory-data-table .inventory-sticky-left.cell-changed,
.inventory-data-table .inventory-sticky-right.cell-changed {
    background: #fff7ed;
}

.inventory-data-table .inventory-row-deleted .inventory-sticky-left,
.inventory-data-table .inventory-row-deleted .inventory-sticky-right {
    background: #f9fafb;
}

.inventory-data-table .cell-number,
.inventory-data-table .cell-price {
    white-space: normal;
}

.inventory-data-table .cell-input input {
    font-size: 12px;
    min-height: 32px;
    padding: 6px 7px;
}

.inventory-data-table .cell-yd-stock input {
    box-sizing: border-box;
    font-size: 12px;
    min-height: 32px;
    padding: 6px 7px;
    width: 100%;
}

.inventory-data-table .cell-input form {
    margin: 0;
}

.inventory-data-table td.cell-input,
.inventory-data-table td.cell-yd-stock {
    vertical-align: top;
}

.inventory-data-table .inline-stock-form,
.inventory-data-table .cell-yd-sku form {
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    min-height: 76px;
}

.inventory-data-table .cell-yd-sku .button-small,
.inventory-data-table .cell-yd-stock .button-small {
    margin-top: 6px;
}

.inventory-data-table .yd-stock-control {
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-height: 76px;
}

.diff-badge {
    background: transparent;
    border-radius: 0;
    display: inline-flex;
    font-size: 11px;
    font-weight: 700;
    line-height: 1.2;
    padding: 0;
}

.diff-badge-empty {
    color: #9ca3af;
    padding-left: 0;
}

.diff-badge-added_sku {
    color: #b91c1c;
}

.diff-badge-deleted_sku {
    color: #4b5563;
}

.diff-badge-changed_attribute {
    color: #1455d9;
}

.inventory-row-deleted td {
    background: #f9fafb;
    color: #6b7280;
}

.cell-changed {
    background: #fff7ed;
}

.changed-new-value {
    color: #b91c1c;
    font-weight: 700;
}

.changed-old-value {
    color: #b91c1c;
    font-size: 11px;
    line-height: 1.45;
    margin-top: 5px;
}

.muted-text {
    color: #9ca3af;
    font-size: 12px;
}

.inline-stock-form {
    display: grid;
    gap: 6px;
}

.row-actions {
    display: grid;
    gap: 6px;
    margin: 0;
}

.link-button.danger {
    color: #b91c1c;
}

.button-small {
    font-size: 12px;
    margin-top: 6px;
    min-height: 30px;
    padding: 0 10px;
    width: 100%;
}

.rule-box {
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    display: grid;
    gap: 16px;
    margin: 0;
    padding: 18px;
}

.rule-box legend {
    color: #111827;
    font-weight: 700;
    padding: 0 6px;
}

.radio-row {
    display: flex;
    gap: 18px;
}

.radio-row label {
    align-items: center;
    display: inline-flex;
    gap: 7px;
}

.google-parse-rule-row {
    display: grid;
    gap: 8px;
}

.radio-row input {
    min-height: auto;
    width: auto;
}

.field-rule-list {
    display: grid;
    gap: 10px;
}

.field-rule-title,
.field-rule-header,
.field-rule-row {
    align-items: center;
    display: grid;
    gap: 10px;
    grid-template-columns: 1fr 1fr 132px;
}

.field-rule-title {
    grid-template-columns: 1fr 74px;
}

.field-rule-help {
    color: #b91c1c;
    font-size: 13px;
    line-height: 1.5;
}

.field-rule-header {
    color: #374151;
    font-size: 13px;
    font-weight: 700;
}

.field-rule-actions {
    display: grid;
    gap: 6px;
    grid-template-columns: 34px 34px 58px;
}

.field-rule-actions .button-small {
    margin-top: 0;
    min-height: 30px;
    padding: 0 8px;
}

.field-rule-actions button:disabled {
    cursor: not-allowed;
    opacity: 0.45;
}

@media (max-width: 860px) {
    .topbar {
        align-items: flex-start;
        flex-direction: column;
        gap: 14px;
        padding: 14px 18px;
    }

    .topbar-actions,
    .admin-nav {
        align-items: flex-start;
        flex-direction: column;
    }

    .container {
        padding: 0 14px;
    }

    .panel {
        overflow-x: auto;
    }

    .inventory-main {
        overflow-x: visible;
    }

    .form-actions {
        flex-direction: column;
    }

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

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

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

    .source-summary {
        align-items: stretch;
        flex-direction: column;
    }

    .source-list-toolbar {
        grid-template-columns: 1fr;
    }

    .source-list-toolbar > .button {
        justify-self: start;
    }

    .source-list-footer {
        align-items: flex-start;
        flex-direction: column;
    }

    .source-list-footer .pagination {
        margin-left: 0;
    }

    .inventory-data-table th,
    .inventory-data-table td {
        font-size: 11px;
        padding: 7px 5px;
    }
}

@media (max-width: 640px) {
    .inventory-data-table,
    .inventory-data-table tbody,
    .inventory-data-table tr,
    .inventory-data-table td {
        display: block;
        width: 100%;
    }

    .inventory-data-table thead {
        display: none;
    }

    .inventory-data-table tr {
        border: 1px solid #e5e7eb;
        border-radius: 8px;
        margin-bottom: 12px;
        overflow: hidden;
    }

    .inventory-data-table td {
        border-bottom: 1px solid #eef0f3;
        padding: 9px 10px;
    }

    .inventory-data-table .inventory-sticky-left,
    .inventory-data-table .inventory-sticky-right {
        box-shadow: none;
        left: auto;
        max-width: none;
        min-width: 0;
        position: static;
        right: auto;
        width: 100%;
    }

    .inventory-data-table td:last-child {
        border-bottom: 0;
    }

    .inventory-data-table td::before {
        color: #6b7280;
        content: attr(data-label);
        display: block;
        font-size: 11px;
        font-weight: 700;
        margin-bottom: 5px;
    }

    .inventory-data-table .empty::before {
        content: "";
        display: none;
    }
}
