:root {
    --bg: #f7f8fa;
    --surface: #ffffff;
    --border: #d8dde5;
    --text: #20242c;
    --muted: #667085;
    --accent: #0f766e;
    --accent-strong: #115e59;
    --danger: #b42318;
    --warning: #b54708;
    --code-bg: #f2f4f7;
}

* {
    box-sizing: border-box;
}

html {
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    color: var(--text);
    background: var(--bg);
    letter-spacing: 0;
}

body {
    margin: 0;
}

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

a:hover {
    text-decoration: underline;
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 10;
    display: grid;
    grid-template-columns: auto minmax(280px, 980px) auto;
    gap: 24px;
    align-items: center;
    padding: 12px 24px;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
}

.brand {
    font-weight: 700;
    color: var(--text);
}

.top-search {
    display: grid;
    grid-template-columns: 160px minmax(160px, 1fr) 110px 145px 170px auto;
    gap: 8px;
}

.top-nav {
    display: flex;
    gap: 8px;
    align-items: center;
    justify-content: flex-end;
}

.top-nav form {
    margin: 0;
}

.top-user {
    color: var(--muted);
    font-size: 13px;
}

.page {
    width: min(1500px, 100%);
    margin: 0 auto;
    padding: 20px 24px 64px;
}

.section {
    margin: 0 0 20px;
    padding: 20px 0;
    border-bottom: 1px solid var(--border);
}

.section-header {
    display: flex;
    gap: 16px;
    align-items: flex-start;
    justify-content: space-between;
    margin-bottom: 16px;
}

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

.header-actions form {
    margin: 0;
}

.ajax-action-status {
    max-width: 360px;
    color: var(--muted);
    font-size: 13px;
    line-height: 1.35;
}

.ajax-action-status.is-error {
    color: var(--danger);
}

h1,
h2 {
    margin: 0;
    line-height: 1.2;
}

h1 {
    font-size: 28px;
}

h2 {
    font-size: 20px;
}

.subhead {
    margin: 18px 0 10px;
    font-size: 15px;
}

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

.empty {
    padding: 16px;
    border: 1px dashed var(--border);
    background: var(--surface);
}

.flash {
    margin-bottom: 16px;
    padding: 12px 14px;
    border: 1px solid #99f6e4;
    background: #ccfbf1;
    color: #134e4a;
}

.flash.error {
    border-color: #fecaca;
    background: #fee2e2;
    color: #7f1d1d;
}

.prestashop-lookup {
    margin-bottom: 18px;
}

.prestashop-lookup h2 {
    margin-bottom: 10px;
}

.status-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 12px;
}

.energy-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 12px;
    margin-bottom: 16px;
}

.stock-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 12px;
    margin-bottom: 16px;
}

.status-grid > div {
    min-width: 0;
    padding: 12px;
    border: 1px solid var(--border);
    background: var(--surface);
}

.energy-grid > div {
    min-width: 0;
    padding: 12px;
    border: 1px solid var(--border);
    background: var(--surface);
}

.energy-grid strong {
    overflow-wrap: anywhere;
}

.document-section {
    display: grid;
    gap: 10px;
    margin-top: 16px;
}

.document-section h3 {
    margin: 0;
    font-size: 16px;
}

.document-upload-groups {
    display: grid;
    gap: 16px;
    margin-top: 16px;
}

.document-upload-group {
    display: grid;
    gap: 10px;
}

.document-upload-group h4 {
    margin: 0;
    font-size: 14px;
}

.energy-upload-slot {
    display: grid;
    gap: 8px;
    min-width: 0;
}

.energy-upload-label {
    color: var(--muted);
    font-size: 13px;
}

.energy-current-asset {
    display: grid;
    grid-template-columns: 44px minmax(0, 1fr) auto;
    gap: 10px;
    align-items: center;
    min-width: 0;
    padding: 10px;
    border: 1px solid var(--border);
    background: var(--surface);
}

.energy-current-asset.is-empty {
    display: block;
    color: var(--muted);
    font-size: 13px;
}

.energy-current-asset-body {
    display: grid;
    gap: 2px;
    min-width: 0;
}

.energy-current-asset-body strong,
.energy-current-asset-body small {
    display: block;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.energy-current-asset-body small {
    color: var(--muted);
}

.energy-current-asset-actions {
    margin-top: 0;
}

.stock-grid > div {
    min-width: 0;
    padding: 12px;
    border: 1px solid var(--border);
    background: var(--surface);
}

.label {
    display: block;
    margin-bottom: 4px;
    color: var(--muted);
    font-size: 12px;
}

.status-detail {
    display: block;
    margin-top: 4px;
    color: var(--muted);
    font-size: 12px;
}

.table-wrap {
    width: 100%;
    overflow-x: auto;
    border: 1px solid var(--border);
    background: var(--surface);
}

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

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

thead th {
    background: #eef2f6;
    font-size: 12px;
    font-weight: 700;
    color: #344054;
}

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

.product-list-table table {
    min-width: 1120px;
}

.product-identity-cell,
.product-sync-cell,
.product-source-state-cell,
.product-names-cell {
    min-width: 180px;
}

.product-identity-cell span,
.product-sync-cell span,
.product-source-state-cell span,
.product-names-cell span {
    display: block;
    line-height: 1.35;
}

.product-identity-cell span {
    margin-top: 4px;
    color: var(--muted);
    font-size: 12px;
    overflow-wrap: anywhere;
}

.product-activation-cell {
    min-width: 150px;
}

.product-activation-cell .status-detail {
    display: none;
}

.product-activation-cell:hover .status-detail,
.product-activation-cell:focus-within .status-detail {
    display: block;
}

.product-sync-cell span + span,
.product-source-state-cell span + span,
.product-names-cell span + span {
    margin-top: 4px;
}

.product-sync-cell strong,
.product-source-state-cell strong,
.product-names-cell strong {
    display: inline-block;
    min-width: 24px;
    margin-right: 6px;
    color: var(--muted);
    font-size: 11px;
}

.product-source-state-cell strong {
    min-width: 48px;
}

.product-sync-cell strong {
    min-width: 52px;
}

.field-table table {
    min-width: 860px;
}

.energy-field-table {
    margin-bottom: 16px;
}

.energy-field-table table {
    min-width: 860px;
}

.field-table th:first-child {
    width: 190px;
}

.downstream-sync-table table {
    min-width: 1180px;
}

.stock-table {
    margin-top: 12px;
}

.stock-table table {
    min-width: 980px;
}

.downstream-targets {
    display: grid;
    gap: 10px;
}

.downstream-target {
    border: 1px solid var(--border);
    background: var(--surface);
}

.downstream-target summary {
    display: flex;
    gap: 12px;
    align-items: center;
    justify-content: space-between;
    padding: 12px 14px;
    cursor: pointer;
}

.downstream-target summary small,
.target-meta {
    color: var(--muted);
    font-size: 12px;
    font-weight: 400;
}

.downstream-target summary small {
    display: block;
    margin-top: 2px;
}

.downstream-target-body {
    padding: 0 14px 14px;
}

.downstream-target-body h4 {
    margin: 10px 0 8px;
    font-size: 14px;
}

.downstream-output-table {
    margin-bottom: 10px;
}

.downstream-output-table table {
    min-width: 680px;
}

.downstream-output-table th:first-child {
    width: 260px;
}

.downstream-output-table pre {
    max-width: 720px;
}

.downstream-payload-actions {
    display: flex;
    gap: 10px;
    align-items: center;
    padding-top: 10px;
}

.downstream-payload-preview {
    max-width: none;
    max-height: 520px;
    margin-top: 10px;
    padding: 12px;
    border: 1px solid var(--border);
    background: var(--code-bg);
}

.downstream-payload-preview.is-error {
    color: var(--danger);
}

.downstream-sync-table pre {
    max-width: 360px;
    max-height: 110px;
}

.source-cell {
    width: 150px;
}

.source-badge {
    display: inline-block;
    padding: 3px 8px;
    border-radius: 6px;
    background: #eef2f6;
    color: #344054;
    font-size: 12px;
    font-weight: 700;
}

.field-key {
    display: block;
    margin-top: 4px;
    color: var(--muted);
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 12px;
    font-weight: 400;
}

pre,
code {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

pre {
    max-width: 340px;
    max-height: 170px;
    margin: 0;
    overflow: auto;
    white-space: pre-wrap;
    word-break: break-word;
}

.payload-preview {
    max-width: none;
    max-height: 560px;
    padding: 16px;
    border: 1px solid var(--border);
    background: var(--code-bg);
}

input,
select,
textarea,
button,
.button {
    min-height: 36px;
    border-radius: 6px;
    font: inherit;
}

input,
select,
textarea {
    width: 100%;
    border: 1px solid var(--border);
    padding: 8px 10px;
    background: var(--surface);
    color: var(--text);
}

textarea {
    resize: vertical;
}

button,
.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 8px 12px;
    border: 1px solid var(--accent);
    background: var(--accent);
    color: #ffffff;
    cursor: pointer;
}

button:hover,
.button:hover {
    background: var(--accent-strong);
    text-decoration: none;
}

.button.secondary,
button.secondary {
    border-color: var(--border);
    background: var(--surface);
    color: var(--text);
}

button.compact {
    min-height: 30px;
    padding: 5px 9px;
}

.button.compact {
    min-height: 30px;
    padding: 5px 9px;
    margin-right: 8px;
}

.danger {
    border-color: var(--danger);
    background: var(--danger);
}

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

.auth-section {
    display: flex;
    justify-content: center;
}

.auth-panel {
    width: min(420px, 100%);
    padding: 20px;
    border: 1px solid var(--border);
    background: var(--surface);
}

.auth-panel h1 {
    margin-bottom: 16px;
}

.auth-form,
.user-form {
    display: grid;
    gap: 12px;
}

.auth-form label,
.user-form label {
    display: grid;
    gap: 6px;
    color: var(--muted);
    font-size: 13px;
}

.user-form {
    grid-template-columns: minmax(180px, 1fr) minmax(180px, 1fr) auto;
    align-items: end;
    margin-bottom: 20px;
}

.user-table table {
    min-width: 860px;
}

.user-row-form {
    margin: 0 0 6px;
}

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

.user-actions form {
    margin: 0;
}

.override-cell {
    min-width: 260px;
}

.override-cell > * + * {
    margin-top: 8px;
}

.check {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: var(--muted);
}

.check input,
.media-row input {
    width: auto;
    min-height: auto;
}

.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 999px;
    background: #fef0c7;
    color: var(--warning);
    font-size: 12px;
    font-weight: 700;
}

.state-pill {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 999px;
    background: #eef2f6;
    color: #344054;
    font-size: 12px;
    font-weight: 700;
    white-space: nowrap;
}

.state-pill-active {
    background: #dcfae6;
    color: #067647;
}

.state-pill-inactive,
.state-pill-not-found {
    background: #fee4e2;
    color: var(--danger);
}

.state-pill-error {
    background: #fef0c7;
    color: var(--warning);
}

.state-pill-unknown {
    background: #eef2f6;
    color: var(--muted);
}

.media-list {
    display: grid;
    gap: 8px;
}

.media-grid {
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
}

.image-sort-list {
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    align-items: start;
}

.document-sort-list {
    grid-template-columns: minmax(0, 1fr);
}

.media-row {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    gap: 10px;
    align-items: start;
    padding: 10px;
    border: 1px solid var(--border);
    background: var(--surface);
}

.media-card {
    grid-template-columns: 96px minmax(0, 1fr);
}

.document-row {
    grid-template-columns: 56px minmax(0, 1fr);
    align-items: stretch;
}

.document-row:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.document-file-badge {
    display: grid;
    width: 44px;
    min-height: 56px;
    place-items: center;
    align-self: start;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: #f8fafc;
    color: var(--accent-strong);
    font-size: 12px;
    font-weight: 800;
    letter-spacing: 0;
}

.document-row-body {
    display: grid;
    gap: 10px;
    min-width: 0;
}

.document-row-header {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 12px;
    align-items: flex-start;
    justify-content: space-between;
}

.document-row-actions {
    margin-top: 0;
}

.document-row-controls {
    margin-top: 0;
}

.image-card {
    position: relative;
    display: block;
    padding: 0;
    overflow: hidden;
    cursor: grab;
    transition: border-color 0.15s ease, box-shadow 0.15s ease, opacity 0.15s ease;
}

.image-card:focus-visible,
.image-card.is-editing {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.image-card.is-dragging {
    opacity: 0.4;
}

.image-card.is-drop-before {
    border-left: 4px solid var(--accent);
}

.image-card.is-drop-after {
    border-right: 4px solid var(--accent);
}

.image-card.is-editing {
    cursor: default;
    box-shadow: 0 10px 24px rgba(16, 24, 40, 0.14);
}

.media-card-body {
    min-width: 0;
}

.media-row.is-muted {
    opacity: 0.65;
}

.media-preview {
    display: grid;
    width: 96px;
    height: 96px;
    place-items: center;
    overflow: hidden;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: #eef2f6;
    color: var(--muted);
    font-size: 12px;
    text-align: center;
}

.image-card-preview {
    position: relative;
    width: 100%;
    height: auto;
    aspect-ratio: 1 / 1;
    border: 0;
    border-radius: 0;
}

.media-preview img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.image-card-overlay {
    position: absolute;
    inset: 0;
    display: grid;
    align-content: space-between;
    gap: 8px;
    padding: 8px;
    opacity: 0;
    color: #ffffff;
    background: linear-gradient(to top, rgba(32, 36, 44, 0.88), rgba(32, 36, 44, 0.18));
    pointer-events: none;
    transition: opacity 0.15s ease;
}

.image-card:hover .image-card-overlay,
.image-card:focus-within .image-card-overlay,
.image-card.is-editing .image-card-overlay {
    opacity: 1;
    pointer-events: auto;
}

.image-card-summary,
.image-card-values {
    display: grid;
    gap: 3px;
    min-width: 0;
}

.image-card-summary {
    grid-template-columns: auto auto 1fr;
    align-items: center;
    font-size: 12px;
}

.image-card-summary .badge {
    justify-self: end;
}

.image-card-values {
    align-self: end;
    font-size: 12px;
}

.image-card-values span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.image-size-detail {
    color: var(--muted);
    font-size: 12px;
}

.image-card-actions {
    align-self: end;
}

.image-card-actions .button.secondary {
    background: rgba(255, 255, 255, 0.9);
}

.image-card .media-card-editor {
    display: none;
    padding: 10px;
}

.image-card.is-editing .media-card-editor {
    display: block;
}

.media-row code {
    display: block;
    margin: 4px 0;
    word-break: break-word;
}

.media-row small {
    display: block;
    color: var(--muted);
    word-break: break-word;
}

.media-title,
.media-controls {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
}

.media-controls {
    margin-top: 8px;
}

.media-position {
    display: inline-flex;
    gap: 6px;
    align-items: center;
    color: var(--muted);
    font-size: 12px;
}

.media-position input {
    width: 70px;
    min-height: 30px;
    padding: 5px 8px;
}

.media-legend-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 8px;
    margin-top: 8px;
    min-width: 0;
}

.media-legend-grid label {
    display: grid;
    gap: 4px;
    color: var(--muted);
    font-size: 12px;
    min-width: 0;
}

.media-legend-grid input {
    width: 100%;
    min-width: 0;
    min-height: 30px;
    padding: 5px 8px;
}

.document-card-values {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 4px;
    min-width: 0;
}

.document-card-values > div {
    min-width: 0;
}

.document-card-values strong,
.document-card-values small {
    display: block;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.document-card-values small {
    color: var(--muted);
}

.open-link {
    display: inline-block;
    margin-top: 8px;
    font-weight: 700;
}

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

.media-actions .button.compact {
    margin-right: 0;
}

.upload-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(180px, 1fr));
    gap: 12px;
    margin-top: 16px;
}

.upload-grid label {
    display: grid;
    gap: 6px;
    color: var(--muted);
    font-size: 13px;
}

.sticky-actions {
    position: sticky;
    bottom: 0;
    display: flex;
    justify-content: flex-end;
    padding: 12px 0;
    background: linear-gradient(to top, var(--bg) 70%, rgba(247, 248, 250, 0));
}

.inline-form {
    margin: 0;
}

.hidden-form {
    display: none;
}

.inline-action {
    display: inline-block;
}

.pagination {
    display: flex;
    gap: 12px;
    align-items: center;
    justify-content: flex-end;
    padding: 14px 0 0;
}

.pagination-top {
    padding: 0 0 14px;
}

.page-status {
    color: var(--muted);
}

.button.disabled {
    opacity: 0.45;
    pointer-events: none;
}

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

@media (max-width: 900px) {
    .topbar,
    .top-search,
    .top-nav,
    .status-grid,
    .energy-grid,
    .stock-grid,
    .upload-grid,
    .user-form {
        grid-template-columns: 1fr;
    }

    .section-header {
        display: grid;
    }

    .header-actions {
        justify-content: stretch;
    }

    .header-actions,
    .header-actions form,
    .header-actions button,
    .header-actions .button {
        width: 100%;
    }

    .document-card-values {
        grid-template-columns: 1fr;
    }

    .energy-current-asset {
        grid-template-columns: 44px minmax(0, 1fr);
    }

    .energy-current-asset-actions {
        grid-column: 1 / -1;
    }

}
