:root {
    --bg: #f4f7fb;
    --panel: #ffffff;
    --text: #172033;
    --muted: #64748b;
    --line: #dbe3ee;
    --primary: #1f7a68;
    --primary-dark: #155f51;
    --accent: #b45309;
    --danger: #b91c1c;
    --shadow: 0 12px 30px rgba(15, 23, 42, 0.08);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    background: var(--bg);
    color: var(--text);
    font-family: Arial, "Microsoft YaHei", sans-serif;
    letter-spacing: 0;
}

body.login-body {
    display: grid;
    place-items: center;
    padding: 24px;
    background: #eef4f8;
}

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

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

button,
a.ghost-button,
a.primary-link,
.primary-button,
.secondary-button,
.text-button {
    min-height: 36px;
    border-radius: 7px;
    cursor: pointer;
}

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

.sidebar {
    display: flex;
    flex-direction: column;
    background: #172033;
    color: #fff;
    padding: 24px 18px;
}

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

.brand-mark {
    display: grid;
    width: 42px;
    height: 42px;
    place-items: center;
    border-radius: 8px;
    background: #1f7a68;
    font-weight: 700;
}

.brand strong,
.brand span {
    display: block;
}

.brand span:last-child {
    margin-top: 4px;
    color: #b6c4d8;
    font-size: 12px;
}

.sidebar nav {
    display: grid;
    gap: 8px;
}

.sidebar nav a {
    padding: 11px 12px;
    border-radius: 7px;
    color: #d8e2f0;
}

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

.sidebar-account {
    display: grid;
    gap: 6px;
    margin-top: auto;
    border-top: 1px solid rgba(255, 255, 255, 0.12);
    padding-top: 18px;
}

.sidebar-account span {
    color: #b6c4d8;
    font-size: 12px;
}

.sidebar-account strong {
    color: #fff;
    font-size: 14px;
}

.sidebar-account form {
    margin: 4px 0 0;
}

.sidebar-account button {
    width: 100%;
    min-height: 32px;
    border: 1px solid rgba(255, 255, 255, 0.16);
    border-radius: 7px;
    background: rgba(255, 255, 255, 0.08);
    color: #d8e2f0;
}

.sidebar-account button:hover {
    background: rgba(255, 255, 255, 0.14);
    color: #fff;
}

.login-shell {
    width: min(100%, 430px);
}

.login-card {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    padding: 28px;
    box-shadow: var(--shadow);
}

.login-brand {
    margin-bottom: 22px;
    color: var(--text);
}

.login-brand span:last-child {
    color: var(--muted);
}

.login-card h1 {
    margin: 0 0 8px;
    font-size: 26px;
}

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

.login-card .primary-button {
    width: 100%;
}

.login-hint {
    display: block;
    margin-top: 14px;
    color: var(--muted);
    line-height: 1.5;
}

.main {
    padding: 28px;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 22px;
}

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

.topbar p {
    margin: 0;
    color: var(--muted);
}

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

.ghost-button {
    display: inline-flex;
    align-items: center;
    border: 1px solid var(--line);
    padding: 0 14px;
    background: #fff;
    color: var(--text);
}

.primary-link {
    display: inline-flex;
    align-items: center;
    border: 0;
    padding: 0 14px;
    background: var(--primary);
    color: #fff;
}

.primary-link:hover {
    background: var(--primary-dark);
    color: #fff;
}

.flash {
    margin-bottom: 18px;
    padding: 12px 14px;
    border: 1px solid #9bd3c6;
    border-radius: 8px;
    background: #e9fbf5;
    color: #155f51;
}

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

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

.stat,
.panel {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    box-shadow: var(--shadow);
}

.stat {
    padding: 16px;
}

.stat span {
    color: var(--muted);
    font-size: 13px;
}

.stat strong {
    display: block;
    margin-top: 8px;
    font-size: 30px;
}

.list-workspace {
    display: block;
}

.form-workspace {
    max-width: 760px;
}

.panel {
    padding: 18px;
}

.panel-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 16px;
}

.panel-heading h2 {
    margin: 0;
    font-size: 18px;
}

.panel-heading span {
    color: var(--muted);
    font-size: 13px;
}

.stacked-form,
.category-form,
.user-form {
    display: grid;
    gap: 13px;
}

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

.product-image-field {
    display: grid;
    gap: 10px;
}

.field-title {
    display: block;
    color: #334155;
    font-size: 13px;
    font-weight: 700;
}

.file-input-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    border: 0;
}

.image-upload-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
}

.image-upload-card {
    min-height: 132px;
    border: 1px solid #d9dee7;
    border-radius: 8px;
    background: #fff;
    display: grid;
    grid-template-columns: 42px minmax(0, 1fr);
    grid-template-rows: auto auto;
    align-items: center;
    gap: 8px 14px;
    padding: 20px;
    text-align: left;
    color: #1f2937;
    cursor: pointer;
    box-shadow: 0 1px 3px rgba(15, 23, 42, 0.05);
}

.image-upload-card:hover,
.image-upload-card:focus {
    border-color: #93b4f6;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
    outline: none;
}

.image-upload-card.paste {
    border-style: dashed;
    background: #fbfdff;
}

.product-image-field.is-paste-ready .image-upload-card.paste {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(31, 122, 104, 0.14);
}

.image-upload-card.has-image {
    align-content: start;
}

.image-action-icon {
    width: 42px;
    height: 42px;
    border-radius: 8px;
    background: #eff6ff;
    color: #2563eb;
    display: grid;
    place-items: center;
    font-size: 22px;
    font-weight: 700;
    line-height: 1;
}

.image-upload-card.paste .image-action-icon {
    background: #e9fbf5;
    color: var(--primary);
    font-size: 16px;
}

.image-card-copy {
    display: grid;
    gap: 4px;
    min-width: 0;
}

.image-upload-card strong {
    font-size: 16px;
    line-height: 22px;
}

.image-upload-card small {
    color: var(--muted);
    font-size: 13px;
    line-height: 18px;
}

.image-inline-preview {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(64px, 1fr));
    gap: 8px;
    width: 100%;
    margin-top: 8px;
}

.image-inline-preview:empty {
    display: none;
}

.image-preview-tile {
    position: relative;
    width: 100%;
    aspect-ratio: 1;
    border: 1px solid var(--line);
    border-radius: 8px;
    overflow: hidden;
    background: #f8fafc;
}

.image-preview-tile img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.image-remove {
    position: absolute;
    top: 5px;
    right: 5px;
    display: grid;
    width: 24px;
    height: 24px;
    min-height: 24px;
    place-items: center;
    border: 0;
    border-radius: 50%;
    background: rgba(15, 23, 42, 0.78);
    color: #fff;
    line-height: 1;
}

.image-upload-status {
    min-height: 20px;
    color: var(--muted);
    font-size: 12px;
}

.image-upload-status.is-ready {
    color: var(--primary);
}

.image-upload-status.is-warning {
    color: var(--danger);
}

.existing-image-panel {
    display: grid;
    gap: 10px;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 12px;
    background: #f8fafc;
}

.existing-image-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(92px, 1fr));
    gap: 10px;
}

.existing-image-card {
    position: relative;
    aspect-ratio: 1;
    border: 1px solid var(--line);
    border-radius: 8px;
    overflow: hidden;
    background: #e2e8f0;
}

.existing-image-card img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.image-delete-button {
    position: absolute;
    top: 6px;
    right: 6px;
    min-height: 28px;
    border: 0;
    border-radius: 7px;
    padding: 0 9px;
    background: rgba(185, 28, 28, 0.9);
    color: #fff;
    font-size: 12px;
    font-weight: 700;
    box-shadow: 0 8px 18px rgba(15, 23, 42, 0.18);
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

label span {
    display: block;
    margin-bottom: 7px;
    color: #334155;
    font-size: 13px;
    font-weight: 700;
}

input,
select,
textarea {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 7px;
    padding: 10px 11px;
    background: #fff;
    color: var(--text);
    outline: none;
}

input[type="file"] {
    padding: 8px;
}

textarea {
    resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(31, 122, 104, 0.14);
}

.switch-line {
    display: inline-flex;
    align-items: center;
    gap: 9px;
}

.switch-line input {
    width: 18px;
    height: 18px;
}

.switch-line span {
    margin: 0;
}

.primary-button,
.secondary-button {
    border: 0;
    padding: 0 14px;
    color: #fff;
}

.primary-button {
    background: var(--primary);
}

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

.secondary-button {
    background: #334155;
}

.secondary-button:hover {
    background: #1e293b;
}

.text-button {
    display: inline-flex;
    align-items: center;
    padding: 0 8px;
}

.filters {
    display: grid;
    grid-template-columns: minmax(180px, 1fr) 150px 150px auto auto;
    gap: 10px;
    align-items: center;
    margin-bottom: 14px;
}

.table-wrap {
    overflow-x: auto;
}

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

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

th {
    color: #475569;
    font-size: 13px;
    font-weight: 700;
    background: #f8fafc;
}

.product-table th,
.product-table td {
    text-align: center;
}

.product-table td:nth-child(1),
.product-table td:nth-child(2),
.product-table td:nth-child(3),
.product-table td:nth-child(4),
.product-table td:nth-child(5) {
    align-content: center;
}

.product-table td:nth-child(2) {
    min-width: 180px;
}

.product-table td:nth-child(2) strong,
.product-table td:nth-child(2) small,
.product-table td:nth-child(2) em {
    margin-right: auto;
    margin-left: auto;
    text-align: center;
}

.product-table td:nth-child(2) em {
    max-width: 260px;
}

.product-table .inline-update-form {
    display: flex;
    justify-content: center;
}

.product-table .tag,
.product-table .muted,
.product-table .product-thumb-button,
.product-table .product-thumb,
.product-table .image-empty {
    margin-right: auto;
    margin-left: auto;
}

td strong,
td small,
td em {
    display: block;
}

td small,
.muted {
    margin-top: 4px;
    color: var(--muted);
}

td em {
    max-width: 360px;
    margin-top: 7px;
    color: #475569;
    font-size: 12px;
    font-style: normal;
    line-height: 1.5;
}

.product-thumb,
.image-empty {
    display: inline-flex;
    width: 72px;
    height: 72px;
    border-radius: 8px;
}

.product-thumb-button {
    display: inline-flex;
    width: 72px;
    height: 72px;
    min-height: 72px;
    border: 0;
    border-radius: 8px;
    padding: 0;
    background: transparent;
    cursor: zoom-in;
}

.product-thumb-button:hover,
.product-thumb-button:focus {
    box-shadow: 0 0 0 3px rgba(31, 122, 104, 0.16);
    outline: none;
}

.product-thumb {
    width: 100%;
    height: 100%;
    object-fit: cover;
    background: #e2e8f0;
}

.image-empty {
    align-items: center;
    justify-content: center;
    border: 1px dashed #cbd5e1;
    background: #f8fafc;
    color: var(--muted);
    font-size: 12px;
}

.tag {
    display: inline-flex;
    align-items: center;
    min-height: 26px;
    border-radius: 999px;
    padding: 0 10px;
    background: color-mix(in srgb, var(--tag-color) 15%, #fff);
    color: var(--tag-color);
    font-size: 12px;
    font-weight: 700;
}

.status {
    display: inline-flex;
    align-items: center;
    min-height: 26px;
    border-radius: 999px;
    padding: 0 10px;
    font-size: 12px;
    font-weight: 700;
}

.status.on {
    background: #e9fbf5;
    color: #0f766e;
}

.status.off {
    background: #f1f5f9;
    color: #475569;
}

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

.inline-select {
    appearance: none;
    width: 126px;
    min-height: 34px;
    border: 1px solid #d8e2ee;
    border-radius: 999px;
    padding: 7px 30px 7px 12px;
    color: #334155;
    background-color: #fff;
    background-image:
        linear-gradient(45deg, transparent 50%, currentColor 50%),
        linear-gradient(135deg, currentColor 50%, transparent 50%);
    background-position:
        calc(100% - 17px) 14px,
        calc(100% - 12px) 14px;
    background-size: 5px 5px, 5px 5px;
    background-repeat: no-repeat;
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.05);
    font-size: 12px;
    font-weight: 700;
    line-height: 1.3;
    cursor: pointer;
}

.inline-select:hover {
    border-color: #aebfd2;
    box-shadow: 0 4px 12px rgba(15, 23, 42, 0.08);
}

.inline-select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(31, 122, 104, 0.14);
}

.status-select.is-dev {
    border-color: #99d9cc;
    background-color: #e9fbf5;
    color: #0f766e;
}

.status-select.is-wait {
    border-color: #fed7aa;
    background-color: #fff7ed;
    color: #9a3412;
}

.status-select.is-complete {
    border-color: #bfdbfe;
    background-color: #eff6ff;
    color: #1d4ed8;
}

.grade-select {
    border-color: color-mix(in srgb, var(--select-color) 38%, #d8e2ee);
    background-color: color-mix(in srgb, var(--select-color) 10%, #fff);
    color: var(--select-color);
}

.actions {
    text-align: center;
    vertical-align: middle;
}

.action-buttons {
    display: inline-flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
    justify-content: center;
}

.action-buttons form,
.category-item form {
    margin: 0;
}

.action-buttons a,
.action-buttons button,
.category-item a,
.category-item button {
    border: 1px solid var(--line);
    border-radius: 7px;
    background: #fff;
    color: var(--text);
    padding: 6px 9px;
    font-size: 12px;
}

button.danger,
.action-buttons button.danger,
.category-item button.danger {
    border-color: #fecaca;
    color: var(--danger);
}

button:disabled,
button.danger:disabled {
    cursor: not-allowed;
    opacity: 0.45;
}

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

.categories-panel,
.users-panel {
    margin-top: 18px;
}

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

.category-list,
.user-list {
    display: grid;
    gap: 10px;
}

.category-item {
    display: grid;
    grid-template-columns: 18px minmax(120px, 1fr) 90px auto auto;
    gap: 10px;
    align-items: center;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 10px;
}

.swatch {
    width: 18px;
    height: 18px;
    border-radius: 50%;
}

.category-item small {
    color: var(--muted);
}

.user-item {
    display: grid;
    grid-template-columns: minmax(150px, 1fr) 86px 130px auto auto;
    gap: 10px;
    align-items: center;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 10px;
}

.user-main {
    display: grid;
    gap: 4px;
}

.user-main small,
.user-item > small {
    color: var(--muted);
}

.user-status {
    display: inline-flex;
    justify-content: center;
    min-height: 26px;
    border-radius: 999px;
    padding: 6px 10px;
    font-size: 12px;
    font-weight: 700;
}

.user-status.is-active {
    background: #e9fbf5;
    color: #0f766e;
}

.user-status.is-disabled {
    background: #f1f5f9;
    color: #64748b;
}

.user-item form {
    margin: 0;
}

.user-item a,
.user-item button {
    border: 1px solid var(--line);
    border-radius: 7px;
    background: #fff;
    color: var(--text);
    padding: 6px 9px;
    font-size: 12px;
}

.user-item button.danger {
    border-color: #fecaca;
    color: var(--danger);
}

.image-lightbox[hidden] {
    display: none;
}

.image-lightbox {
    position: fixed;
    inset: 0;
    z-index: 80;
    display: grid;
    place-items: center;
    padding: 28px;
}

.image-lightbox-backdrop {
    position: absolute;
    inset: 0;
    min-height: 0;
    border: 0;
    border-radius: 0;
    background: rgba(15, 23, 42, 0.72);
    cursor: zoom-out;
}

.image-lightbox-dialog {
    position: relative;
    z-index: 1;
    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
    width: min(1120px, 94vw);
    max-height: 92vh;
    overflow: hidden;
    border-radius: 8px;
    background: #0f172a;
    box-shadow: 0 24px 60px rgba(0, 0, 0, 0.34);
}

.image-lightbox-dialog {
    user-select: none;
}

.image-lightbox-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    padding: 12px 14px;
    color: #fff;
}

.image-lightbox-head strong {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.image-lightbox-close {
    display: grid;
    width: 34px;
    height: 34px;
    min-height: 34px;
    place-items: center;
    border: 1px solid rgba(255, 255, 255, 0.18);
    border-radius: 7px;
    background: rgba(255, 255, 255, 0.08);
    color: #fff;
    font-size: 20px;
    line-height: 1;
}

.image-lightbox-close:hover {
    background: rgba(255, 255, 255, 0.16);
}

.image-lightbox-dialog img {
    display: block;
    width: 100%;
    max-height: calc(92vh - 59px);
    object-fit: contain;
    background: #0f172a;
    cursor: zoom-in;
    transform-origin: center center;
    transition: transform 0.08s ease-out;
    will-change: transform;
}

.image-lightbox-dialog img.is-zoomed {
    cursor: grab;
}

.image-lightbox-dialog img.is-dragging {
    cursor: grabbing;
    transition: none;
}

body.is-preview-open {
    overflow: hidden;
}

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

    .sidebar {
        position: static;
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 16px;
    }

    .sidebar nav {
        grid-auto-flow: column;
    }

    .form-workspace,
    .list-workspace,
    .category-layout,
    .user-layout {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 760px) {
    .main {
        padding: 18px;
    }

    .topbar,
    .sidebar {
        align-items: flex-start;
        flex-direction: column;
    }

    .stats-grid,
    .form-row,
    .image-upload-actions,
    .filters {
        grid-template-columns: 1fr;
    }

    .category-item {
        grid-template-columns: 18px minmax(0, 1fr);
    }

    .category-item small,
    .category-item a,
    .category-item form {
        grid-column: 2;
    }

    .user-item {
        grid-template-columns: 1fr;
        align-items: stretch;
    }
}
