:root {
    --bg: #f7f3ee;
    --surface: #ffffff;
    --ink: #2c2420;
    --muted: #7a7068;
    --line: #e8e2db;
    --accent: #8b5e3c;
    --accent-dark: #6f4a2f;
    --ok: #2f6b45;
    --ok-bg: #e8f5ec;
    --warn: #8a5a12;
    --warn-bg: #fff4e0;
    --err: #8b2e2e;
    --err-bg: #fdecec;
    --radius: 12px;
    --font: "Segoe UI", system-ui, -apple-system, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }

body {
    margin: 0;
    font-family: var(--font);
    background:
        radial-gradient(1200px 500px at 10% -10%, #efe6db 0%, transparent 55%),
        radial-gradient(900px 400px at 100% 0%, #f0ebe4 0%, transparent 50%),
        var(--bg);
    color: var(--ink);
    min-height: 100vh;
    line-height: 1.5;
}

.brand {
    margin: 0;
    font-size: 0.8rem;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--accent);
    font-weight: 700;
}

h1, h2 { margin: 0.2rem 0 0; font-weight: 650; }
h1 { font-size: 1.45rem; }
h2 { font-size: 1.1rem; }

.muted { color: var(--muted); }
.small { font-size: 0.85rem; display: inline-block; margin-top: 0.25rem; }

.topbar {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    align-items: flex-start;
    padding: 1.25rem 1.5rem;
    background: rgba(255,255,255,0.85);
    border-bottom: 1px solid var(--line);
    backdrop-filter: blur(8px);
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.container {
    max-width: 840px;
    margin: 0 auto;
    padding: 1.5rem;
}

.panel {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 1.25rem 1.35rem;
    margin-bottom: 1rem;
}

.panel-muted { background: #fbf9f6; }

.status-list {
    list-style: none;
    padding: 0;
    margin: 1rem 0;
}

.status-list li {
    padding: 0.85rem 0;
    border-top: 1px solid var(--line);
}

.status-list li:last-child { border-bottom: 1px solid var(--line); }

.badge {
    display: inline-block;
    margin-left: 0.5rem;
    padding: 0.15rem 0.55rem;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 700;
}

.badge-ok { background: var(--ok-bg); color: var(--ok); }
.badge-warn { background: var(--warn-bg); color: var(--warn); }
.badge-old { background: #fde8e4; color: #9a3b2f; }
.badge-local { background: #e8eef8; color: #2f4f7a; }

.actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.65rem;
    margin: 1rem 0 0.5rem;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid transparent;
    border-radius: 8px;
    padding: 0.65rem 1rem;
    font: inherit;
    font-weight: 650;
    text-decoration: none;
    cursor: pointer;
}

.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--accent-dark); }
.btn-secondary { background: #fff; border-color: var(--line); color: var(--ink); }
.btn-ghost { background: transparent; border-color: var(--line); color: var(--ink); }

.alert {
    padding: 0.85rem 1rem;
    border-radius: 8px;
    margin: 1rem 0;
}

.alert-success { background: var(--ok-bg); color: var(--ok); }
.alert-error { background: var(--err-bg); color: var(--err); }

code, code.block {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 0.86rem;
}

code.block {
    display: block;
    margin: 0.75rem 0;
    padding: 0.85rem 1rem;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 8px;
    word-break: break-all;
}

.auth-page {
    display: grid;
    place-items: center;
    padding: 1.5rem;
}

.auth-card {
    width: 100%;
    max-width: 400px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 1.75rem 1.5rem;
    box-shadow: 0 16px 40px rgba(44, 36, 32, 0.06);
}

.auth-card form {
    display: grid;
    gap: 0.9rem;
    margin-top: 1.25rem;
}

.auth-card label {
    display: grid;
    gap: 0.35rem;
    font-size: 0.9rem;
    font-weight: 600;
}

.auth-card input {
    width: 100%;
    padding: 0.7rem 0.8rem;
    border: 1px solid var(--line);
    border-radius: 8px;
    font: inherit;
    background: #fff;
}

.auth-card .btn { width: 100%; }

.container-wide { max-width: 1180px; }

.oauth-panel summary {
    cursor: pointer;
    list-style: none;
    display: flex;
    align-items: center;
    gap: 0.65rem;
    font-size: 1rem;
}

.oauth-panel summary::-webkit-details-marker { display: none; }

.panel-head {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    align-items: flex-start;
    margin-bottom: 1rem;
}

.filters {
    display: grid;
    grid-template-columns: 2fr 1fr 1fr 1fr auto;
    gap: 0.75rem;
    align-items: end;
    margin-bottom: 1rem;
}

.filters label {
    display: grid;
    gap: 0.3rem;
    font-size: 0.82rem;
    font-weight: 650;
    color: var(--muted);
}

.filters input,
.filters select {
    width: 100%;
    padding: 0.65rem 0.75rem;
    border: 1px solid var(--line);
    border-radius: 8px;
    font: inherit;
    color: var(--ink);
    background: #fff;
}

.filter-actions {
    display: flex;
    gap: 0.45rem;
    flex-wrap: wrap;
}

.list-status { margin: 0 0 0.75rem; }
.status-error { color: var(--err); }

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

.products-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

.products-table th,
.products-table td {
    padding: 0.7rem 0.75rem;
    border-bottom: 1px solid var(--line);
    text-align: left;
    vertical-align: middle;
}

.products-table th {
    background: #fbf9f6;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--muted);
}

.products-table tr:last-child td { border-bottom: none; }

.row-no-image {
    background: #fff8ef;
}

.row-old-url {
    background: #fff5f3;
}

.row-local {
    background: #f3f6fb;
}

.col-thumb { width: 72px; }

.thumb {
    width: 56px;
    height: 56px;
    border-radius: 8px;
    overflow: hidden;
    background: #f3efe9;
    display: grid;
    place-items: center;
}

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

.thumb-empty {
    font-size: 0.65rem;
    color: var(--muted);
    text-align: center;
    padding: 0.25rem;
    line-height: 1.2;
}

.col-name { min-width: 180px; font-weight: 600; }

.empty-row {
    text-align: center;
    color: var(--muted);
    padding: 2rem 1rem !important;
}

.pager {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.85rem;
    margin-top: 1rem;
}

.alert-warn { background: var(--warn-bg); color: var(--warn); }

.btn-sm {
    padding: 0.4rem 0.7rem;
    font-size: 0.8rem;
    white-space: nowrap;
}

.col-actions {
    width: 1%;
    white-space: nowrap;
}

.col-actions .btn { margin: 0.15rem 0.15rem 0.15rem 0; }

.sync-option {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin: 0.75rem 0 0.25rem;
    font-size: 0.9rem;
    font-weight: 650;
    color: var(--ink);
    cursor: pointer;
}

.sync-option input { width: 1rem; height: 1rem; }

.dialog-card {
    width: min(440px, 100%);
}

.dialog-title-wrap {
    display: grid;
    gap: 0.15rem;
}

.dialog-brand {
    font-size: 0.72rem;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--accent);
    font-weight: 700;
}

.dialog-message {
    margin: 0;
    color: var(--ink);
    white-space: pre-wrap;
    line-height: 1.55;
    font-size: 0.98rem;
}

.dialog-modal.is-success .dialog-brand { color: var(--ok); }
.dialog-modal.is-error .dialog-brand { color: var(--err); }
.dialog-modal.is-warn .dialog-brand { color: var(--warn); }

.dialog-modal.is-success #dialog-ok { background: var(--ok); }
.dialog-modal.is-error #dialog-ok { background: var(--err); }
.dialog-modal.is-warn #dialog-ok { background: var(--accent); }


.modal[hidden] { display: none !important; }

.modal {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: grid;
    place-items: center;
    padding: 1rem;
}

.dialog-modal {
    z-index: 1200;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(44, 36, 32, 0.45);
}

.modal-card {
    position: relative;
    z-index: 1;
    width: min(640px, 100%);
    max-height: calc(100vh - 2rem);
    overflow: auto;
    background: #fff;
    border-radius: 14px;
    border: 1px solid var(--line);
    box-shadow: 0 24px 60px rgba(44, 36, 32, 0.18);
}

.modal-head,
.modal-foot {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 1rem 1.15rem;
    border-bottom: 1px solid var(--line);
}

.modal-foot {
    border-bottom: none;
    border-top: 1px solid var(--line);
    justify-content: flex-end;
}

.modal-close {
    font-size: 1.4rem;
    line-height: 1;
    padding: 0.2rem 0.55rem;
}

.modal-body { padding: 1rem 1.15rem 1.25rem; }

.upload-meta p { margin: 0.25rem 0; }

.file-picker {
    display: grid;
    gap: 0.4rem;
    margin: 1rem 0;
    font-size: 0.88rem;
    font-weight: 650;
    color: var(--muted);
}

.file-picker input {
    font: inherit;
    font-weight: 400;
    color: var(--ink);
}

.dropzone {
    margin: 1rem 0;
    border: 2px dashed #d4c9be;
    border-radius: 12px;
    background:
        linear-gradient(180deg, #fcfaf7 0%, #f7f3ee 100%);
    cursor: pointer;
    outline: none;
    transition: border-color 0.15s ease, background 0.15s ease, box-shadow 0.15s ease;
}

.dropzone:hover,
.dropzone:focus-visible {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(139, 94, 60, 0.12);
}

.dropzone.is-dragover {
    border-color: var(--accent);
    background: #fff8ef;
    box-shadow: 0 0 0 3px rgba(139, 94, 60, 0.18);
}

.dropzone-inner {
    display: grid;
    gap: 0.35rem;
    place-items: center;
    text-align: center;
    padding: 1.6rem 1rem;
    color: var(--ink);
}

.dropzone-inner strong {
    font-size: 1rem;
}

.dropzone-inner span {
    color: var(--muted);
    font-size: 0.88rem;
}

.dropzone-hint {
    margin-top: 0.35rem !important;
    font-size: 0.8rem !important;
}

.dropzone kbd {
    display: inline-block;
    padding: 0.05rem 0.35rem;
    border: 1px solid #d4c9be;
    border-bottom-width: 2px;
    border-radius: 4px;
    background: #fff;
    font-size: 0.75rem;
    font-family: inherit;
    color: var(--ink);
}


.upload-planned {
    margin: 0.75rem 0 1rem;
    padding: 0.75rem 0.9rem;
    background: #fbf9f6;
    border: 1px solid var(--line);
    border-radius: 10px;
}

.upload-planned h3 {
    margin: 0 0 0.45rem;
    font-size: 0.9rem;
}

.upload-planned ul {
    margin: 0;
    padding-left: 1.1rem;
}

.upload-planned li { margin: 0.25rem 0; word-break: break-all; }

.upload-preview {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
    gap: 0.75rem;
}

.preview-card {
    border: 1px solid var(--line);
    border-radius: 10px;
    overflow: hidden;
    background: #f7f3ee;
}

.preview-card img {
    width: 100%;
    aspect-ratio: 1;
    object-fit: cover;
    display: block;
}

.preview-cap {
    padding: 0.4rem 0.45rem;
    font-size: 0.7rem;
    word-break: break-all;
    color: var(--muted);
}

#upload-msg {
    white-space: pre-wrap;
    margin-top: 1rem;
}

#upload-msg[hidden] { display: none !important; }

.btn-small {
    padding: 0.4rem 0.65rem;
    font-size: 0.82rem;
}

.btn-danger {
    background: #fff;
    border-color: #e8caca;
    color: var(--err);
}

.btn-danger:hover:not(:disabled) {
    background: var(--err-bg);
}

.user-create-form {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 0.85rem 1rem;
    align-items: end;
    margin-top: 0.5rem;
}

.user-create-form label {
    display: grid;
    gap: 0.35rem;
    font-size: 0.9rem;
    font-weight: 600;
}

.user-create-form input,
.user-create-form select,
.inline-form input,
.inline-form select {
    width: 100%;
    padding: 0.55rem 0.65rem;
    border: 1px solid var(--line);
    border-radius: 8px;
    font: inherit;
}

.user-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.45rem;
    align-items: center;
}

.inline-form {
    display: inline-flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    align-items: center;
}

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

.user-action-details summary {
    list-style: none;
}

.user-action-details summary::-webkit-details-marker {
    display: none;
}

.user-action-details[open] .inline-form {
    margin-top: 0.45rem;
    padding: 0.65rem;
    background: #fbf9f6;
    border: 1px solid var(--line);
    border-radius: 8px;
}

.users-table td:last-child {
    min-width: 280px;
}


@media (max-width: 960px) {
    .filters {
        grid-template-columns: 1fr 1fr;
    }
    .filter-search { grid-column: 1 / -1; }
    .filter-actions { grid-column: 1 / -1; }
}

@media (max-width: 640px) {
    .topbar { flex-direction: column; }
    .filters { grid-template-columns: 1fr; }
    .panel-head { flex-direction: column; }
}
