:root {
    --ink: #17211d;
    --muted: #6d7772;
    --paper: #f5f6f2;
    --card: #ffffff;
    --line: #dfe4df;
    --green: #176b4b;
    --green-dark: #10543a;
    --lime: #d8f35b;
    --danger: #b73636;
    --shadow: 0 18px 50px rgba(23, 33, 29, .09);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    color: var(--ink);
    background: var(--paper);
}

* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; }
button, input, select, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; }
img { display: block; max-width: 100%; }
h1, h2, h3, p { margin-top: 0; }
h1 { font-size: clamp(2rem, 4vw, 3.7rem); line-height: 1.02; letter-spacing: -.045em; }
h2 { letter-spacing: -.025em; }

.public-shell {
    display: grid;
    place-items: center;
    padding: 32px;
    background:
        radial-gradient(circle at 15% 20%, rgba(216, 243, 91, .55), transparent 28%),
        radial-gradient(circle at 85% 80%, rgba(23, 107, 75, .22), transparent 30%),
        #eef2e9;
}
.access-card {
    width: min(100%, 480px);
    padding: clamp(32px, 7vw, 64px);
    background: rgba(255,255,255,.9);
    border: 1px solid rgba(255,255,255,.8);
    border-radius: 30px;
    box-shadow: var(--shadow);
}
.access-card h1 { font-size: clamp(2.2rem, 8vw, 4rem); }
.access-card > p:not(.eyebrow) { color: var(--muted); line-height: 1.6; }
.brand-mark {
    display: grid; place-items: center; width: 54px; height: 54px; margin-bottom: 36px;
    background: var(--ink); color: var(--lime); font-size: 30px; font-weight: 900;
    border-radius: 16px; transform: rotate(-5deg);
}
.eyebrow { margin-bottom: 10px; color: var(--green); font-size: 12px; font-weight: 800; letter-spacing: .16em; }
.text-link { color: var(--green); font-weight: 700; }

.stack-form { display: grid; gap: 18px; }
label { display: grid; gap: 7px; color: #4f5b55; font-size: 13px; font-weight: 700; }
input, select, textarea {
    width: 100%; min-height: 44px; padding: 10px 12px; color: var(--ink); background: #fff;
    border: 1px solid #cfd7d1; border-radius: 10px; outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgba(23,107,75,.12); }
input[type="file"] { padding: 8px; }
input[type="checkbox"] { width: 18px; min-height: 18px; accent-color: var(--green); }
.check-row { display: flex; align-items: center; gap: 9px; }
.button {
    display: inline-flex; justify-content: center; align-items: center; min-height: 46px; padding: 0 20px;
    border: 0; border-radius: 11px; color: #fff; background: var(--green); font-weight: 800;
    text-decoration: none; transition: .18s ease;
}
.button:hover { background: var(--green-dark); transform: translateY(-1px); }
.button.secondary { color: var(--ink); background: var(--lime); }
.ghost-button, .text-button, .icon-button {
    padding: 7px 10px; border: 0; background: none; color: var(--green); font-weight: 750;
}
.text-button.danger { color: var(--danger); }
.alert { margin-bottom: 18px; padding: 13px 15px; border-radius: 10px; font-size: 14px; font-weight: 650; }
.alert.success { color: #14583e; background: #dcf3e8; }
.alert.error { color: #8f2929; background: #f9dddd; }

.topbar {
    position: sticky; z-index: 20; top: 0; display: flex; justify-content: space-between; align-items: center;
    min-height: 68px; padding: 0 clamp(20px, 4vw, 60px); background: rgba(255,255,255,.9);
    border-bottom: 1px solid var(--line); backdrop-filter: blur(12px);
}
.topbar form { margin: 0; }
.topbar-actions { display: flex; align-items: center; gap: 8px; }
.logo { color: var(--ink); font-size: 21px; font-weight: 900; text-decoration: none; letter-spacing: -.04em; }
.logo span { color: var(--green); }
.admin-layout { width: min(1420px, calc(100% - 40px)); margin: 50px auto 100px; }
.page-heading, .section-heading { display: flex; justify-content: space-between; align-items: end; gap: 20px; }
.page-heading { margin-bottom: 32px; }
.page-heading h1 { margin: 0; }
.section-heading h2 { margin: 0; font-size: 28px; }
.section-heading.compact { align-items: center; }
.section-heading.compact h2 { font-size: 19px; }
.card-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 18px; }
.client-card { padding: 24px; background: var(--card); border: 1px solid var(--line); border-radius: 18px; box-shadow: 0 8px 30px rgba(23,33,29,.04); }
.card-row { display: flex; justify-content: space-between; gap: 20px; }
.card-row h2 { display: inline; margin-right: 8px; }
.card-row > strong { font-size: 25px; color: var(--green); }
.card-row small { display: block; color: var(--muted); font-size: 11px; font-weight: 600; }
.status { display: inline-block; padding: 4px 7px; color: #7a4747; background: #f4e5e5; border-radius: 99px; font-size: 10px; text-transform: uppercase; }
.status.active { color: #176143; background: #def2e8; }
.share-link { margin: 22px 0; }
.share-link span { display: flex; }
.share-link input { border-radius: 9px 0 0 9px; background: #f7f8f6; font-size: 12px; }
.share-link button { padding: 0 14px; border: 0; color: white; background: var(--ink); border-radius: 0 9px 9px 0; font-size: 12px; font-weight: 800; }
.card-actions { display: flex; justify-content: space-between; align-items: center; border-top: 1px solid var(--line); padding-top: 12px; }
.card-actions form { margin: 0; }
.section-block { margin-top: 65px; }
.template-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 18px; margin-top: 24px; }
.template-card { overflow: hidden; color: var(--ink); background: white; border: 1px solid var(--line); border-radius: 14px; text-decoration: none; transition: .18s; }
.template-card:hover { transform: translateY(-3px); box-shadow: var(--shadow); }
.template-thumb { overflow: hidden; height: 220px; padding: 12px; background: #e8ebe6; }
.template-thumb img { width: 100%; height: 100%; object-fit: contain; }
.template-card > div:last-child { padding: 15px; }
.template-card span, .template-card small { color: var(--muted); font-size: 11px; }
.template-card h3 { margin: 4px 0; font-size: 15px; }
.modal { width: min(92vw, 480px); padding: 25px; border: 0; border-radius: 18px; box-shadow: var(--shadow); }
.modal.wide { width: min(92vw, 640px); }
.modal textarea { min-height: 180px; resize: vertical; font-size: 13px; line-height: 1.45; font-weight: 500; }
.modal::backdrop { background: rgba(14,25,20,.65); backdrop-filter: blur(3px); }
.modal-title { display: flex; justify-content: space-between; align-items: center; }
.modal-title h2 { margin: 0; }
.modal-title button { border: 0; background: none; font-size: 27px; }
.scraper-settings { display: grid; gap: 13px; margin: 0; padding: 15px; border: 1px solid var(--line); border-radius: 12px; }
.scraper-settings legend { padding: 0 6px; font-size: 13px; font-weight: 800; }
.scraper-settings small { color: var(--muted); line-height: 1.4; }

.mapper-layout { display: grid; grid-template-columns: 380px 1fr; height: calc(100vh - 68px); }
.mapper-sidebar { position: relative; z-index: 3; overflow-y: auto; padding: 26px; background: white; border-right: 1px solid var(--line); }
.mapper-sidebar > label { margin-bottom: 14px; }
.mapper-sidebar hr { margin: 24px 0; border: 0; border-top: 1px solid var(--line); }
.group-notice { margin-bottom: 16px; padding: 10px 12px; color: #17543e; background: #e5f3ec; border-radius: 9px; font-size: 12px; line-height: 1.45; }
.icon-button { min-width: 38px; color: var(--ink); background: #eef1ed; border-radius: 8px; }
.field-list { display: grid; gap: 7px; margin: 15px 0; }
.field-item { display: flex; align-items: center; gap: 10px; padding: 10px; border: 1px solid var(--line); border-radius: 9px; background: white; text-align: left; }
.field-item.active { border-color: var(--green); background: #edf6f1; }
.field-item span:first-child { flex: 1; font-size: 13px; font-weight: 700; }
.field-item small { color: var(--muted); }
.field-properties { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; padding: 14px; background: #f5f7f4; border-radius: 12px; }
.field-properties .full, .field-properties .muted { grid-column: 1 / -1; }
.field-properties label { font-size: 11px; }
.field-properties input, .field-properties select { min-height: 38px; padding: 7px 9px; font-size: 12px; }
.delete-field { grid-column: 1 / -1; color: var(--danger); border: 0; background: none; font-weight: 700; }
.sticky-save { position: sticky; bottom: 0; width: 100%; margin-top: 18px; box-shadow: 0 -8px 20px white; }
.mapper-workspace { overflow: auto; display: grid; place-items: start center; padding: 70px 50px; background: #dfe3dd; }
.mapper-help { position: fixed; z-index: 4; top: 82px; right: 20px; max-width: calc(100% - 430px); padding: 9px 13px; color: #e8edea; background: rgba(23,33,29,.82); border-radius: 9px; font-size: 12px; }
.canvas-stage { position: relative; line-height: 0; box-shadow: 0 20px 60px rgba(23,33,29,.24); }
.canvas-stage canvas { display: block; width: 100%; height: 100%; }
#mapper-stage { width: min(70vw, 760px); }

.editor-page { background: #eef1ec; }
html:has(body.editor-page) { height: 100%; }
body.editor-page {
    display: flex;
    flex-direction: column;
    height: 100dvh;
    overflow: hidden;
    background: #eef1ec;
}
.editor-header {
    flex: 0 0 auto;
    display: flex; justify-content: space-between; align-items: center; gap: 20px;
    padding: 14px clamp(18px, 4vw, 40px);
    background: var(--ink); color: white;
}
.editor-header h1 { margin: 0; font-size: clamp(1.35rem, 2.2vw, 2rem); }
.editor-header .eyebrow { color: var(--lime); margin-bottom: 4px; }
.step-pills { display: flex; gap: 8px; flex-wrap: wrap; }
.step-pills span { padding: 8px 12px; color: #aab4af; border: 1px solid #45514b; border-radius: 99px; font-size: 12px; font-weight: 700; }
.step-pills .active { color: var(--ink); background: var(--lime); border-color: var(--lime); }
.editor-layout {
    flex: 1;
    min-height: 0;
    display: grid;
    grid-template-columns: minmax(300px, 380px) minmax(0, 1fr);
    overflow: hidden;
}
.editor-panel {
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 20px 20px 28px;
    background: white;
    border-right: 1px solid var(--line);
}
.editor-panel section + section { margin-top: 35px; }
.editor-panel h2 { font-size: 18px; }
.product-import,
.product-catalog,
.gemini-copy { padding: 18px; background: #edf6f1; border: 1px solid #cfe5d9; border-radius: 14px; }
.product-import .eyebrow,
.product-catalog .eyebrow,
.gemini-copy .eyebrow { margin-bottom: 5px; }
.product-import h2,
.product-catalog h2,
.gemini-copy h2 { margin-bottom: 12px; }
.catalog-search input { width: 100%; }
.catalog-selected { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 10px; -webkit-overflow-scrolling: touch; }
.catalog-selected .chip {
    display: flex; align-items: center; gap: 8px; flex: 0 0 auto; padding: 6px 10px 6px 6px;
    border: 1px solid #cfe5d9; border-radius: 999px; background: white; font-size: 12px; font-weight: 700;
}
.catalog-selected .chip.active { border-color: var(--green); background: #e7f6ee; }
.catalog-selected .chip img { width: 28px; height: 28px; object-fit: cover; border-radius: 99px; background: #dde3dd; }
.catalog-results {
    max-height: 21.5rem;
    overflow-y: auto;
    overscroll-behavior: contain;
    margin-top: 10px;
    padding-right: 4px;
    -webkit-overflow-scrolling: touch;
}
.catalog-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.catalog-card {
    display: grid; gap: 4px; padding: 6px; text-align: left; background: white;
    border: 2px solid transparent; border-radius: 10px; box-shadow: 0 6px 16px rgba(23,33,29,.05);
}
.catalog-card.selected { border-color: var(--green); }
.catalog-card img { width: 100%; height: 68px; object-fit: cover; border-radius: 7px; background: #e8ebe6; }
.catalog-card strong {
    font-size: 11px; line-height: 1.2;
    display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.catalog-card em { color: #3d9ad6; font-size: 9px; font-style: normal; font-weight: 800; letter-spacing: .04em; }
.catalog-card small {
    color: var(--muted); font-size: 10px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.catalog-more {
    position: sticky; bottom: 0; width: 100%; margin-top: 6px; padding: 8px 0 2px;
    background: linear-gradient(transparent, #edf6f1 42%);
}
.soon-card { opacity: .55; cursor: not-allowed; }
.soon-thumb {
    display: grid; place-items: center; aspect-ratio: 4 / 5; color: #7d877f;
    background: repeating-linear-gradient(-45deg, #eceee9, #eceee9 8px, #e3e6e0 8px, #e3e6e0 16px);
    font-size: 11px; font-weight: 800; letter-spacing: .04em; text-transform: uppercase;
}
.gemini-copy textarea {
    width: 100%; min-height: 140px; margin-top: 12px; padding: 12px; resize: vertical;
    border: 1px solid #cfd7d1; border-radius: 10px; font-size: 14px; line-height: 1.45;
}
.import-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; }
.import-row .button { min-height: 44px; padding: 0 14px; }
.import-status { margin: 9px 0 0; color: var(--muted); font-size: 12px; line-height: 1.4; }
.import-status.loading { color: var(--green); }
.import-status.success { color: #176143; font-weight: 700; }
.import-status.error { color: var(--danger); font-weight: 700; }
.template-picker { display: grid; grid-template-columns: repeat(3, 1fr); gap: 9px; }
.template-picker button { overflow: hidden; padding: 0; background: #f3f4f1; border: 2px solid transparent; border-radius: 9px; }
.template-picker button.active { border-color: var(--green); box-shadow: 0 0 0 2px rgba(23,107,75,.15); }
.template-picker img,
.template-picker .thumb-canvas { width: 100%; aspect-ratio: 4 / 5; object-fit: contain; display: block; background: #e8ebe6; }
.template-picker .thumb-canvas { height: auto; }
.template-picker span { display: block; overflow: hidden; padding: 7px; font-size: 10px; font-weight: 700; white-space: nowrap; text-overflow: ellipsis; }
.dynamic-image { position: relative; padding: 11px; border: 1px dashed #aab6af; border-radius: 10px; background: #f7f9f6; }
.dynamic-image input { border: 0; padding: 0; background: none; }
.image-preview { display: flex; align-items: center; gap: 10px; margin-top: 10px; }
.image-preview[hidden] { display: none; }
.image-preview img { width: 54px; height: 54px; object-fit: cover; border-radius: 8px; background: #dde3dd; }
.image-preview span { color: var(--muted); font-size: 12px; font-weight: 650; }
.image-fit { display: grid; gap: 8px; }
.image-fit > span { color: #4f5b55; font-size: 13px; font-weight: 700; }
.image-fit small { color: var(--muted); font-size: 12px; font-weight: 500; line-height: 1.35; }
.image-fit-toggle { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 6px; }
.image-fit-toggle button {
    min-height: 40px; border: 1px solid #cfd7d1; border-radius: 10px;
    background: #fff; color: var(--ink); font-size: 12px; font-weight: 800;
}
.image-fit-toggle button.active { color: #fff; background: var(--ink); border-color: var(--ink); }
.image-fit-zoom { gap: 6px; }
.image-fit-zoom input[type="range"] { width: 100%; min-height: 28px; padding: 0; accent-color: var(--green); }
.preview-stage.is-zoomable canvas { cursor: grab; touch-action: none; }
.preview-stage.is-zoomable.is-dragging canvas { cursor: grabbing; }
.download-button { width: 100%; margin-top: 30px; background: var(--ink); }
.download-secondary { display: flex; justify-content: center; gap: 12px; margin-top: 8px; }
.preview-area {
    min-width: 0;
    min-height: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    padding: 16px 20px 18px;
}
.preview-heading { display: flex; justify-content: space-between; gap: 20px; margin: 0 0 10px; color: var(--ink); font-weight: 800; }
.preview-heading small { color: var(--muted); font-weight: 500; }
.dual-preview {
    flex: 1;
    min-height: 0;
    display: grid;
    grid-template-columns: minmax(0, 1.43fr) minmax(0, 1fr);
    align-items: stretch;
    gap: 16px;
}
.preview-card {
    min-width: 0;
    min-height: 0;
    display: flex;
    flex-direction: column;
    padding: 12px;
    background: rgba(255,255,255,.65);
    border: 1px solid var(--line);
    border-radius: 16px;
}
.preview-label { display: flex; justify-content: space-between; flex: 0 0 auto; width: 100%; margin: 0 0 8px; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .08em; }
.preview-fit {
    flex: 1;
    min-height: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}
.preview-stage {
    width: auto;
    height: auto;
    max-width: 100%;
    max-height: 100%;
    margin: 0;
}
.story-preview { width: auto; }
.empty-state { margin: auto; padding: 60px; text-align: center; }
.muted { color: var(--muted); font-size: 12px; line-height: 1.5; }

@media (max-width: 1180px) {
    .preview-area { padding: 12px 14px 14px; }
    .dual-preview { gap: 10px; }
}

@media (max-width: 900px) {
    .mapper-layout { grid-template-columns: 320px 1fr; }
    .mapper-help { display: none; }
    html:has(body.editor-page) { height: auto; }
    body.editor-page {
        display: block;
        height: auto;
        overflow: visible;
    }
    .editor-layout { display: block; overflow: visible; height: auto; }
    .editor-panel { overflow: visible; border-right: 0; border-bottom: 1px solid var(--line); }
    .preview-heading { flex-direction: column; gap: 4px; }
    .preview-area { overflow: visible; display: block; height: auto; }
    .dual-preview { display: grid; grid-template-columns: minmax(0, 1.43fr) minmax(0, 1fr); gap: 12px; height: auto; }
    .preview-card { padding: 10px; height: auto; }
    .preview-fit { min-height: 0; height: auto; }
    .preview-stage, .story-preview { width: 100%; height: auto; }
    .preview-label { font-size: 10px; }
    .preview-label strong { display: none; }
}

@media (max-width: 680px) {
    .admin-layout { width: min(100% - 24px, 1420px); margin-top: 28px; }
    .page-heading, .section-heading { align-items: stretch; flex-direction: column; }
    .page-heading .button, .section-heading .button { width: 100%; }
    .card-grid { grid-template-columns: 1fr; }
    .mapper-layout { display: block; height: auto; }
    .mapper-sidebar { overflow: visible; }
    .mapper-workspace { padding: 24px 12px; }
    #mapper-stage { width: 100%; }
    .editor-header { align-items: start; flex-direction: column; gap: 12px; padding: 22px 20px; }
    .editor-header h1 { font-size: 1.7rem; }
    .step-pills { display: none; }
    .editor-panel, .preview-area { padding: 18px 14px; }
    .template-picker { grid-template-columns: repeat(3, 1fr); }
    .import-row { grid-template-columns: 1fr; }
    .catalog-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
    .gemini-copy textarea { font-size: 16px; }
    .import-row .button { width: 100%; }
    .download-button { position: sticky; bottom: 12px; z-index: 5; box-shadow: 0 10px 26px rgba(23,33,29,.35); }
}

#mapper-canvas { touch-action: none; }
