/* ── Reset ─────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* ── Tokens ────────────────────────────────────────────────────────────────── */
:root {
    --green:        #16a34a;
    --green-dark:   #15803d;
    --green-light:  #dcfce7;
    --green-mid:    #bbf7d0;
    --bg:           #f1f5f1;
    --surface:      #ffffff;
    --border:       #e2e8f0;
    --border-focus: #16a34a;
    --text:         #0f172a;
    --muted:        #64748b;
    --red:          #dc2626;
    --red-light:    #fef2f2;
    --radius-sm:    6px;
    --radius:       10px;
    --radius-lg:    14px;
    --shadow-sm:    0 1px 3px rgba(0,0,0,.06), 0 1px 2px rgba(0,0,0,.04);
    --shadow:       0 4px 12px rgba(0,0,0,.08);
    --shadow-lg:    0 8px 24px rgba(0,0,0,.12);
    --font:         -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    padding-bottom: 48px;
}

/* ── Brand header ──────────────────────────────────────────────────────────── */
.brand-header {
    background: var(--green);
    padding: 0 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 56px;
    position: sticky;
    top: 0;
    z-index: 50;
    box-shadow: 0 2px 8px rgba(22,163,74,.25);
}

.brand-logo {
    display: flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
}

.brand-icon {
    width: 32px;
    height: 32px;
    background: rgba(255,255,255,.2);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 800;
    color: #fff;
    letter-spacing: -0.5px;
    flex-shrink: 0;
}

.brand-name {
    font-size: 17px;
    font-weight: 700;
    color: #fff;
    letter-spacing: -0.3px;
}

.brand-tagline {
    font-size: 12px;
    color: rgba(255,255,255,.65);
    font-weight: 400;
}

/* ── Container ─────────────────────────────────────────────────────────────── */
.container {
    max-width: 820px;
    margin: 0 auto;
    padding: 28px 16px 0;
}

/* ── Tab navigation ────────────────────────────────────────────────────────── */
.tab-nav {
    display: flex;
    gap: 6px;
    margin-bottom: 24px;
    background: var(--surface);
    border-radius: var(--radius-lg);
    padding: 5px;
    box-shadow: var(--shadow-sm);
}

.tab-btn {
    flex: 1;
    padding: 10px 16px;
    border: none;
    border-radius: var(--radius);
    background: transparent;
    color: var(--muted);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all .18s ease;
    font-family: var(--font);
}

.tab-btn:hover:not(.active) {
    background: var(--bg);
    color: var(--text);
}

.tab-btn.active {
    background: var(--green);
    color: #fff;
    box-shadow: 0 2px 8px rgba(22,163,74,.3);
}

/* ── Product card ──────────────────────────────────────────────────────────── */
.product-card {
    background: var(--surface);
    border-radius: var(--radius-lg);
    padding: 24px;
    margin-bottom: 14px;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border);
    transition: box-shadow .2s;
}

.product-card:hover { box-shadow: var(--shadow); }

.product-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding-bottom: 14px;
    border-bottom: 1px solid var(--border);
}

.product-number {
    font-weight: 700;
    font-size: 14px;
    color: var(--green);
    text-transform: uppercase;
    letter-spacing: .5px;
}

.btn-remove {
    background: none;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 5px 12px;
    font-size: 12px;
    font-weight: 600;
    color: var(--muted);
    cursor: pointer;
    transition: all .15s;
    font-family: var(--font);
}

.btn-remove:hover {
    border-color: var(--red);
    color: var(--red);
    background: var(--red-light);
}

/* ── Form fields ───────────────────────────────────────────────────────────── */
.product-fields {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.field-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
}

.field-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.field-group label {
    font-size: 12px;
    font-weight: 700;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: .5px;
}

.field-group input,
.field-group textarea {
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    padding: 10px 13px;
    font-size: 14px;
    font-family: var(--font);
    color: var(--text);
    background: var(--surface);
    transition: border-color .15s, box-shadow .15s;
    width: 100%;
}

.field-group input:focus,
.field-group textarea:focus {
    outline: none;
    border-color: var(--green);
    box-shadow: 0 0 0 3px rgba(22,163,74,.12);
}

.field-group textarea { resize: vertical; }

/* ── Type toggle ───────────────────────────────────────────────────────────── */
.type-toggle {
    display: flex;
    gap: 0;
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    width: fit-content;
    background: var(--bg);
}

.type-option {
    display: flex;
    align-items: center;
    cursor: pointer;
}

.type-option input[type=radio] { display: none; }

.type-option span {
    padding: 8px 20px;
    font-size: 13px;
    font-weight: 600;
    color: var(--muted);
    background: transparent;
    transition: background .15s, color .15s;
}

.type-option input:checked + span {
    background: var(--green);
    color: #fff;
}

/* ── Variable section ──────────────────────────────────────────────────────── */
.variable-section {
    border: 1.5px solid var(--green-mid);
    border-radius: var(--radius-lg);
    padding: 18px;
    background: #f0fdf4;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.variable-attrs { display: flex; flex-direction: column; gap: 12px; }

.btn-generate-vars {
    background: var(--green);
    color: #fff;
    border: none;
    border-radius: var(--radius);
    padding: 10px 20px;
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
    width: fit-content;
    transition: background .15s;
    font-family: var(--font);
}

.btn-generate-vars:hover { background: var(--green-dark); }

/* ── Fill all variations ───────────────────────────────────────────────────── */
.var-fill-all {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 6px;
}

.var-fill-inputs { display: flex; gap: 8px; }

.var-fill-all input {
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    padding: 8px 12px;
    font-size: 13px;
    width: 160px;
    font-family: var(--font);
}

.var-fill-all input:focus {
    outline: none;
    border-color: var(--green);
    box-shadow: 0 0 0 3px rgba(22,163,74,.12);
}

.btn-fill-all {
    background: var(--green-light);
    color: var(--green-dark);
    border: 1.5px solid var(--green-mid);
    border-radius: var(--radius);
    padding: 8px 16px;
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
    white-space: nowrap;
    transition: all .15s;
    font-family: var(--font);
}

.btn-fill-all:hover {
    background: var(--green);
    color: #fff;
    border-color: var(--green);
}

/* ── Variations table ──────────────────────────────────────────────────────── */
.variations-table {
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    background: var(--surface);
}

.var-header {
    display: grid;
    grid-template-columns: 1fr 120px 120px;
    gap: 8px;
    padding: 10px 14px;
    background: var(--bg);
    font-size: 11px;
    font-weight: 700;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: .5px;
}

.var-row {
    display: grid;
    grid-template-columns: 1fr 120px 120px;
    gap: 8px;
    padding: 8px 14px;
    align-items: center;
    border-top: 1px solid var(--border);
}

.var-row:hover { background: #fafafa; }

.var-label { font-size: 13px; font-weight: 500; color: var(--text); }

.var-price, .var-stock {
    border: 1.5px solid var(--border) !important;
    border-radius: var(--radius-sm) !important;
    padding: 6px 10px !important;
    font-size: 13px !important;
    width: 100% !important;
    font-family: var(--font) !important;
}

.var-price:focus, .var-stock:focus {
    border-color: var(--green) !important;
    outline: none !important;
    box-shadow: 0 0 0 3px rgba(22,163,74,.12) !important;
}

/* ── Multiselect ───────────────────────────────────────────────────────────── */
.multiselect { position: relative; }

.multiselect-box {
    min-height: 42px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    padding: 6px 10px;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 4px;
    cursor: text;
    background: var(--surface);
    transition: border-color .15s, box-shadow .15s;
}

.multiselect-box.open,
.multiselect-box:focus-within {
    border-color: var(--green);
    box-shadow: 0 0 0 3px rgba(22,163,74,.12);
}

.multiselect-tag {
    display: flex;
    align-items: center;
    gap: 4px;
    background: var(--green-light);
    color: var(--green-dark);
    border-radius: 20px;
    padding: 3px 10px;
    font-size: 12px;
    font-weight: 600;
}

.multiselect-tag-remove {
    cursor: pointer;
    font-size: 14px;
    line-height: 1;
    color: var(--green);
    background: none;
    border: none;
    padding: 0;
}

.multiselect-tag-remove:hover { color: var(--red); }

.multiselect-search {
    border: none !important;
    outline: none !important;
    padding: 2px 4px !important;
    font-size: 13px !important;
    flex: 1;
    min-width: 80px;
    background: transparent !important;
    font-family: var(--font) !important;
}

.multiselect-dropdown {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    background: var(--surface);
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    z-index: 100;
    max-height: 220px;
    overflow-y: auto;
}

.multiselect-option {
    padding: 9px 14px;
    font-size: 13px;
    cursor: pointer;
    transition: background .1s;
}

.multiselect-option:hover { background: var(--green-light); }

.multiselect-option.selected {
    background: var(--green-light);
    color: var(--green-dark);
    font-weight: 600;
}

.multiselect-empty {
    padding: 12px 14px;
    font-size: 13px;
    color: var(--muted);
}

.multiselect-create {
    color: var(--green) !important;
    border-top: 1px solid var(--border);
    font-size: 13px;
}

.multiselect-create:hover { background: var(--green-light) !important; }

.cat-arrow { color: var(--muted); font-size: 12px; margin-right: 2px; }

/* ── Photo upload ──────────────────────────────────────────────────────────── */
.image-inputs {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.photo-dropzone {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 28px 24px;
    border: 2px dashed var(--border);
    border-radius: var(--radius-lg);
    text-align: center;
    cursor: pointer;
    color: var(--muted);
    font-size: 14px;
    background: var(--bg);
    transition: all .15s;
}

.photo-dropzone:hover {
    border-color: var(--green);
    background: var(--green-light);
    color: var(--green-dark);
}

.photo-dropzone input[type="file"] { display: none; }
.photo-dropzone .upload-icon { font-size: 30px; }

.btn-add-photo {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 9px 16px;
    border: 2px dashed var(--green);
    border-radius: var(--radius);
    color: var(--green);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    background: var(--surface);
    transition: background .15s;
    width: fit-content;
}

.btn-add-photo:hover { background: var(--green-light); }
.btn-add-photo input[type="file"] { display: none; }

.image-previews {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
}

.image-thumb-wrap {
    position: relative;
    display: inline-block;
    cursor: grab;
    touch-action: none;
}

.image-thumb-wrap:active { cursor: grabbing; }
.image-thumb-wrap.dragging { opacity: 0.35; }

.image-thumb-wrap.drag-over .image-thumb {
    border-color: var(--green);
    box-shadow: 0 0 0 3px rgba(22,163,74,.3);
    transform: scale(1.05);
    transition: transform .1s;
}

.image-thumb {
    width: 80px;
    height: 80px;
    object-fit: cover;
    border-radius: var(--radius-sm);
    border: 2px solid var(--border);
}

.image-thumb-wrap:first-child .image-thumb {
    border-color: var(--green);
    width: 100px;
    height: 100px;
}

.thumb-remove {
    position: absolute;
    top: -6px;
    right: -6px;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--red);
    color: #fff;
    border: none;
    font-size: 13px;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    box-shadow: 0 1px 4px rgba(0,0,0,.2);
}

.thumb-badge {
    position: absolute;
    bottom: 4px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--green);
    color: #fff;
    font-size: 9px;
    font-weight: 700;
    padding: 2px 6px;
    border-radius: 20px;
    white-space: nowrap;
    letter-spacing: .3px;
}

/* ── Simple attrs section ──────────────────────────────────────────────────── */
.simple-attrs-section {
    border: 1.5px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 16px;
    background: var(--bg);
}

/* ── Buttons ───────────────────────────────────────────────────────────────── */
.hidden { display: none !important; }

.btn-add {
    display: block;
    width: 100%;
    padding: 14px;
    background: var(--surface);
    border: 2px dashed var(--green);
    border-radius: var(--radius-lg);
    color: var(--green);
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
    transition: background .15s;
    margin-bottom: 24px;
    font-family: var(--font);
}

.btn-add:hover { background: var(--green-light); }

.form-footer { text-align: center; margin-top: 8px; }

.btn-submit {
    background: var(--green);
    color: #fff;
    border: none;
    border-radius: var(--radius-lg);
    padding: 14px 56px;
    font-size: 15px;
    font-weight: 700;
    cursor: pointer;
    transition: background .15s, box-shadow .15s;
    box-shadow: 0 2px 8px rgba(22,163,74,.3);
    font-family: var(--font);
}

.btn-submit:hover {
    background: var(--green-dark);
    box-shadow: 0 4px 12px rgba(22,163,74,.4);
}

.btn-submit:disabled {
    background: #86efac;
    box-shadow: none;
    cursor: not-allowed;
}

/* ── Results ───────────────────────────────────────────────────────────────── */
.results {
    margin-top: 28px;
    background: var(--surface);
    border-radius: var(--radius-lg);
    padding: 24px;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border);
}

.results h2 { font-size: 16px; font-weight: 700; margin-bottom: 16px; color: var(--text); }

.result-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
    font-size: 14px;
}

.result-item:last-child { border-bottom: none; }
.result-icon { font-size: 16px; flex-shrink: 0; }
.result-name { flex: 1; font-weight: 500; }
.result-error { color: var(--red); font-size: 12px; }

.summary {
    margin-top: 16px;
    padding-top: 14px;
    border-top: 2px solid var(--border);
    font-weight: 700;
    font-size: 14px;
    color: var(--text);
}

/* ── Loading overlay ───────────────────────────────────────────────────────── */
.loading-overlay {
    position: fixed;
    inset: 0;
    background: rgba(255,255,255,.92);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 999;
    gap: 14px;
}

.loading-step  { font-size: 16px; font-weight: 700; color: var(--green); }
.loading-sub   { font-size: 13px; font-weight: 600; color: var(--green); opacity: .7; }
.loading-count { font-size: 13px; color: var(--muted); }

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border);
    border-top-color: var(--green);
    border-radius: 50%;
    animation: spin .7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ── Edit tab ──────────────────────────────────────────────────────────────── */
.edit-search-wrap {
    position: relative;
    margin-bottom: 20px;
}

.edit-search-input {
    width: 100%;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 14px 18px;
    font-size: 15px;
    font-family: var(--font);
    color: var(--text);
    background: var(--surface);
    outline: none;
    transition: border-color .15s, box-shadow .15s;
    box-shadow: var(--shadow-sm);
}

.edit-search-input:focus {
    border-color: var(--green);
    box-shadow: 0 0 0 3px rgba(22,163,74,.12);
}

.edit-search-results {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    right: 0;
    background: var(--surface);
    border: 1.5px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    z-index: 200;
    max-height: 340px;
    overflow-y: auto;
}

.edit-result-item {
    display: flex;
    flex-direction: column;
    gap: 3px;
    padding: 13px 16px;
    cursor: pointer;
    border-bottom: 1px solid var(--border);
    transition: background .1s;
}

.edit-result-item:last-child { border-bottom: none; }
.edit-result-item:hover { background: var(--green-light); }

.edit-result-name { font-size: 14px; font-weight: 600; color: var(--text); }
.edit-result-meta { font-size: 12px; color: var(--muted); }

.edit-search-loading,
.edit-search-empty {
    padding: 16px;
    font-size: 13px;
    color: var(--muted);
    text-align: center;
    line-height: 1.6;
}

.edit-product-form {
    background: var(--surface);
    border-radius: var(--radius-lg);
    padding: 24px;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.edit-product-header {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border);
}

.edit-product-title {
    font-size: 16px;
    font-weight: 700;
    color: var(--text);
    flex: 1;
}

.edit-product-badge {
    background: var(--green-light);
    color: var(--green-dark);
    font-size: 11px;
    font-weight: 700;
    padding: 3px 10px;
    border-radius: 20px;
    text-transform: uppercase;
    letter-spacing: .4px;
    white-space: nowrap;
}

.edit-fields { display: flex; flex-direction: column; gap: 16px; }

.edit-actions { display: flex; gap: 10px; }

.btn-edit-save {
    flex: 1;
    padding: 13px;
    background: var(--green);
    color: #fff;
    border: none;
    border-radius: var(--radius-lg);
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
    transition: background .15s, box-shadow .15s;
    font-family: var(--font);
    box-shadow: 0 2px 8px rgba(22,163,74,.25);
}

.btn-edit-save:hover { background: var(--green-dark); }
.btn-edit-save:disabled { background: #86efac; cursor: not-allowed; box-shadow: none; }

.btn-edit-cancel {
    padding: 13px 20px;
    background: var(--surface);
    color: var(--muted);
    border: 1.5px solid var(--border);
    border-radius: var(--radius-lg);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all .15s;
    font-family: var(--font);
}

.btn-edit-cancel:hover { background: var(--bg); color: var(--text); }

.edit-msg {
    padding: 12px 16px;
    border-radius: var(--radius);
    font-size: 13px;
    font-weight: 600;
    text-align: center;
}

.edit-msg-ok    { background: var(--green-light); color: var(--green-dark); }
.edit-msg-error { background: var(--red-light);   color: var(--red); }

.edit-discount-wrap {
    background: var(--bg);
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    padding: 14px 16px;
}

.edit-discount-preview {
    font-size: 13px;
    font-weight: 700;
    color: var(--green-dark);
}

.btn-clear-discount {
    background: none;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 5px 12px;
    font-size: 12px;
    font-weight: 600;
    color: var(--muted);
    cursor: pointer;
    transition: all .15s;
    font-family: var(--font);
    white-space: nowrap;
}

.btn-clear-discount:hover {
    border-color: var(--red);
    color: var(--red);
    background: var(--red-light);
}

.edit-var-sale {
    border: 1.5px solid var(--green-mid);
    border-radius: var(--radius-sm);
    padding: 7px 10px;
    font-size: 13px;
    width: 100%;
    box-sizing: border-box;
    font-family: var(--font);
    color: var(--green-dark);
    background: var(--green-light);
}

.edit-var-sale:focus {
    outline: none;
    border-color: var(--green);
    box-shadow: 0 0 0 3px rgba(22,163,74,.12);
}

/* ── Edit variations table ─────────────────────────────────────────────────── */
.edit-var-table {
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    background: var(--surface);
}

.edit-var-header {
    display: grid;
    grid-template-columns: 1fr 130px 130px;
    gap: 8px;
    padding: 10px 14px;
    background: var(--bg);
    font-size: 11px;
    font-weight: 700;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: .5px;
}

.edit-var-row {
    display: grid;
    grid-template-columns: 1fr 130px 130px;
    gap: 8px;
    padding: 8px 14px;
    align-items: center;
    border-top: 1px solid var(--border);
}

.edit-var-row:hover { background: #fafafa; }

.edit-var-label { font-size: 13px; font-weight: 500; color: var(--text); }

.edit-var-price,
.edit-var-stock {
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 7px 10px;
    font-size: 13px;
    width: 100%;
    box-sizing: border-box;
    font-family: var(--font);
    color: var(--text);
}

.edit-var-price:focus,
.edit-var-stock:focus {
    outline: none;
    border-color: var(--green);
    box-shadow: 0 0 0 3px rgba(22,163,74,.12);
}

/* ── Footer ────────────────────────────────────────────────────────────────── */
.brand-footer {
    text-align: center;
    padding: 32px 16px 16px;
    font-size: 12px;
    color: var(--muted);
}

.brand-footer a {
    color: var(--green);
    text-decoration: none;
    font-weight: 600;
}

.brand-footer a:hover { text-decoration: underline; }

/* ── Responsive ────────────────────────────────────────────────────────────── */
@media (max-width: 600px) {
    .field-row { grid-template-columns: 1fr; }

    .tab-btn { font-size: 13px; padding: 10px 10px; }

    .edit-var-header { grid-template-columns: 1fr 85px 85px; gap: 6px; font-size: 10px; }
    .edit-var-row    { grid-template-columns: 1fr 85px 85px; gap: 6px; }

    .btn-submit { padding: 13px 32px; }

    .brand-header { height: 52px; }
}
