@import url('https://fonts.googleapis.com/css2?family=DM+Sans:wght@400;500;600;700&family=Instrument+Serif:ital@0;1&display=swap');

:root {
    color-scheme: light;
    --ink: #171716;
    --muted: #6f706c;
    --line: #dedfd9;
    --paper: #f4f5f1;
    --panel: #ffffff;
    --accent: #c9ff48;
    --accent-strong: #a8e80e;
    --danger: #b43c35;
    --radius: 18px;
    font-family: "DM Sans", sans-serif;
    font-size: 16px;
}

* { box-sizing: border-box; }
body { margin: 0; color: var(--ink); background: var(--paper); min-height: 100vh; }
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }
.muted, .hint { color: var(--muted); }
.hint { margin: -5px 0 16px; font-size: .875rem; }

.topbar { height: 72px; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; padding: 0 34px; background: rgba(255,255,255,.94); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; backdrop-filter: blur(14px); }
.brand { color: var(--ink); text-decoration: none; display: inline-flex; align-items: center; gap: 10px; font-weight: 700; letter-spacing: -.03em; font-size: 1.1rem; }
.brand span { width: 32px; height: 32px; display: grid; place-items: center; border-radius: 50%; background: var(--ink); color: var(--accent); }
.topbar nav { display: flex; gap: 6px; padding: 5px; background: var(--paper); border-radius: 12px; }
.nav-button, .icon-button { border: 0; background: transparent; color: var(--muted); border-radius: 9px; padding: 9px 14px; font-size: .875rem; }
.nav-button.active { background: white; color: var(--ink); box-shadow: 0 1px 4px rgba(0,0,0,.08); }
.icon-button { justify-self: end; }
.icon-button:hover { color: var(--ink); background: var(--paper); }

.page-shell { width: min(1560px, calc(100% - 32px)); margin: 0 auto; padding: 28px 0 56px; }
.view { display: none; }
.view.active { display: block; }
.intro-row { display: flex; justify-content: space-between; gap: 28px; align-items: end; margin-bottom: 18px; }
.eyebrow { text-transform: uppercase; letter-spacing: .14em; font-weight: 700; font-size: .72rem; margin: 0 0 8px; color: #797a73; }
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 0; font-family: "Instrument Serif", serif; font-weight: 400; font-size: clamp(2.05rem, 2.7vw, 2.85rem); line-height: 1; letter-spacing: -.035em; }
h2 { font-size: 1.18rem; letter-spacing: -.02em; }
h3 { font-size: .95rem; }
.intro-copy { max-width: 330px; color: var(--muted); line-height: 1.45; margin: 0; font-size: .9rem; }

.store-toolbar { display: flex; align-items: center; gap: 12px; margin-bottom: 8px; }
.store-toolbar > span { color: var(--muted); font-size: .75rem; font-weight: 700; text-transform: uppercase; letter-spacing: .1em; }
.store-tabs { display: flex; gap: 5px; padding: 4px; border-radius: 10px; background: #e9eae5; overflow-x: auto; }
.store-tab { border: 0; border-radius: 7px; padding: 7px 13px; background: transparent; color: var(--muted); font-size: .8rem; font-weight: 700; white-space: nowrap; }
.store-tab.active { background: var(--panel); color: var(--ink); box-shadow: 0 1px 4px rgba(0,0,0,.08); }

.url-bar { display: grid; grid-template-columns: auto 1fr auto; gap: 10px; align-items: center; padding: 7px 7px 7px 16px; border: 1px solid var(--line); background: white; border-radius: 14px; box-shadow: 0 8px 28px rgba(40,40,30,.05); }
.url-icon { font-size: 1.5rem; color: var(--muted); transform: rotate(-25deg); }
.url-bar input { border: 0; outline: 0; min-width: 0; font-size: .95rem; }
.button { border: 1px solid var(--line); padding: 10px 14px; border-radius: 10px; font-weight: 600; font-size: .88rem; background: white; color: var(--ink); transition: transform .15s, background .15s, opacity .15s; }
.button:hover:not(:disabled) { transform: translateY(-1px); }
.button:disabled { opacity: .4; cursor: default; }
.button.primary { background: var(--accent); border-color: var(--accent); }
.button.primary:hover { background: var(--accent-strong); }
.button.dark { background: var(--ink); border-color: var(--ink); color: white; }
.button.subtle { background: var(--paper); }
.button.wide { width: 100%; margin-top: 14px; }
.button-row { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; margin-top: 9px; }

.empty-state { min-height: 470px; display: grid; place-items: center; align-content: center; text-align: center; color: var(--muted); }
.empty-state h2 { color: var(--ink); margin: 20px 0 7px; }
.empty-state p { margin: 0; }
.empty-art { position: relative; width: 170px; height: 132px; }
.empty-art span { position: absolute; width: 88px; height: 108px; border-radius: 13px; border: 5px solid white; background: #dfe2db; box-shadow: 0 12px 24px rgba(0,0,0,.12); }
.empty-art span:nth-child(1) { left: 0; transform: rotate(-13deg); background: #d6c5b5; }
.empty-art span:nth-child(2) { left: 42px; top: -7px; z-index: 2; background: #b8c1b7; }
.empty-art span:nth-child(3) { right: 0; transform: rotate(13deg); background: var(--accent); }

.editor-grid { display: grid; grid-template-columns: minmax(540px, 1.45fr) minmax(290px, .68fr) minmax(290px, .68fr); gap: 14px; margin-top: 16px; align-items: start; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 15px; padding: 18px; box-shadow: 0 4px 16px rgba(30,30,20,.03); }
.panel-heading, .section-heading { display: flex; justify-content: space-between; align-items: start; gap: 16px; }
.panel-heading h2 { max-width: 700px; margin-bottom: 10px; }
.product-meta { display: flex; gap: 10px; align-items: center; color: var(--muted); padding-bottom: 16px; border-bottom: 1px solid var(--line); font-size: .88rem; }
.product-meta strong { color: var(--ink); }
.section-heading { margin: 17px 0 9px; align-items: center; }
.design-panel > .section-heading:first-child, .preview-panel > .section-heading:first-child { margin-top: 0; }
.section-heading h3 { margin: 0; }
.section-heading span, .section-heading select { color: var(--muted); font-size: .8rem; }
.section-heading select { border: 1px solid var(--line); background: var(--paper); border-radius: 8px; padding: 6px 28px 6px 9px; }
.status-chip { border-radius: 999px; background: #eaf7dc; color: #477116; padding: 7px 11px; font-size: .72rem; font-weight: 700; white-space: nowrap; }
.status-chip.unknown { background: #fff0d6; color: #8a5a00; }

.photo-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.photo-card { border: 2px solid transparent; border-radius: 11px; overflow: hidden; padding: 0; background: #f3f3f0; position: relative; aspect-ratio: 4/5; cursor: pointer; }
.photo-card img { width: 100%; height: 100%; display: block; object-fit: contain; }
.photo-card.selected { border-color: var(--ink); }
.photo-card.selected::after { content: attr(data-order); position: absolute; top: 8px; right: 8px; width: 28px; height: 28px; display: grid; place-items: center; border-radius: 50%; background: var(--ink); color: var(--accent); font-size: .75rem; font-weight: 700; }
.photo-card.dragging { opacity: .45; }
.sizes-list { display: flex; flex-wrap: wrap; gap: 8px; }
.size { border: 1px solid var(--line); border-radius: 8px; padding: 8px 11px; font-size: .82rem; min-width: 42px; text-align: center; }
.size.unavailable { color: #a5a5a0; text-decoration: line-through; background: #f3f3f1; }
.size.unknown { border-style: dashed; color: var(--muted); }

.template-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 7px; max-height: 310px; overflow-y: auto; padding-right: 3px; }
.template-grid label { cursor: pointer; }
.template-grid input { position: absolute; opacity: 0; pointer-events: none; }
.template-card { position: relative; border: 2px solid transparent; background: var(--collage-background, var(--paper)); color: var(--collage-text, var(--ink)); border-radius: 11px; padding: 6px; display: grid; grid-template-columns: 1.6fr 1fr; grid-template-rows: 24px 24px auto; gap: 3px; overflow: hidden; }
.template-grid input:checked + .template-card { border-color: var(--collage-accent, var(--ink)); box-shadow: inset 0 0 0 1px var(--collage-text, var(--ink)); }
.template-card i { background: color-mix(in srgb, var(--collage-text, #171716) 20%, var(--collage-background, #f4f5f1)); display: block; border-radius: 3px; }
.template-card i:first-child { grid-row: 1/3; }
.catalog-preview i:first-child { grid-column: 1/3; grid-row: 1; }
.editorial-preview { grid-template-columns: 1.35fr 1fr; }
.editorial-preview::after { content: ""; position: absolute; width: 4px; height: 70px; left: 56%; top: -5px; background: white; transform: rotate(15deg); }
.spotlight-preview { padding: 9px; border-color: #d5d6d0; }
.spotlight-preview i:first-child { grid-column: 1/3; grid-row: 1/2; }
.split-preview { grid-template-columns: repeat(3, 1fr); }
.split-preview i:first-child { grid-row: 1/3; }
.magazine-preview i:first-child { grid-column: 1/3; grid-row: 1; }
.magazine-preview i:nth-child(2), .magazine-preview i:nth-child(3) { grid-row: 2; }
.minimal-preview { grid-template-columns: repeat(3,1fr); }
.minimal-preview i:first-child { grid-row: 1/3; }
.template-card b { grid-column: 1/-1; font-size: .66rem; padding: 4px 2px 1px; text-align: center; }
.toggle-row { display: flex; flex-wrap: wrap; gap: 10px; margin: 14px 0; color: var(--muted); font-size: .8rem; }
.toggle-row label { display: flex; gap: 5px; align-items: center; }
.field { display: grid; gap: 6px; margin-top: 12px; color: var(--muted); font-size: .8rem; font-weight: 600; }
.field input, .field textarea, .field select { color: var(--ink); background: #fbfbf9; border: 1px solid var(--line); border-radius: 10px; padding: 11px 12px; outline: none; resize: vertical; }
.field input:focus, .field textarea:focus, .field select:focus { border-color: #888a82; box-shadow: 0 0 0 3px rgba(201,255,72,.28); }
.collage-preview { aspect-ratio: 1; background: var(--paper); border-radius: 11px; display: grid; place-items: center; overflow: hidden; text-align: center; }
.collage-preview p { max-width: 220px; color: var(--muted); font-size: .82rem; margin: 0; }
.collage-preview img { width: 100%; height: 100%; object-fit: contain; }

.history-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; }
.history-card { background: white; border: 1px solid var(--line); border-radius: 14px; overflow: hidden; text-align: left; padding: 0; }
.history-card .thumb { aspect-ratio: 1; display: grid; place-items: center; background: #e6e7e1; color: var(--muted); overflow: hidden; }
.history-card img { width: 100%; height: 100%; object-fit: cover; }
.history-card .info { padding: 14px; }
.history-card strong { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.history-card small { display: flex; justify-content: space-between; gap: 8px; color: var(--muted); margin-top: 8px; }
.settings-form { max-width: 760px; display: grid; grid-template-columns: 1fr 1fr; gap: 4px 18px; }
.settings-form .button { margin-top: 20px; align-self: end; }
.settings-section-title { grid-column: 1 / -1; margin: 28px 0 0; padding-top: 22px; border-top: 1px solid var(--line); }
.settings-section-copy { grid-column: 1 / -1; color: var(--muted); margin: -1px 0 4px; font-size: .84rem; }
.color-field > span { display: grid; grid-template-columns: 54px 1fr; gap: 8px; }
.color-field input[type="color"] { width: 54px; height: 42px; padding: 4px; cursor: pointer; }
.color-field .color-value { min-width: 0; text-transform: uppercase; }

.toast { position: fixed; right: 24px; bottom: 24px; max-width: 380px; background: var(--ink); color: white; padding: 13px 17px; border-radius: 11px; opacity: 0; transform: translateY(15px); pointer-events: none; transition: .2s; z-index: 50; }
.toast.show { opacity: 1; transform: none; }
.toast.error { background: var(--danger); }

.login-page { display: grid; place-items: center; background: radial-gradient(circle at 20% 20%, #e9ffd0 0, transparent 30%), var(--paper); padding: 24px; }
.login-card { width: min(440px, 100%); background: white; border: 1px solid var(--line); border-radius: 22px; padding: 36px; box-shadow: 0 25px 70px rgba(30,30,20,.1); }
.login-card .brand { margin-bottom: 50px; }
.login-card h1 { font-size: 3.2rem; margin-bottom: 14px; }
.stack-form { margin-top: 28px; display: grid; gap: 16px; }
.stack-form label { display: grid; gap: 7px; font-size: .83rem; color: var(--muted); font-weight: 600; }
.stack-form input { border: 1px solid var(--line); border-radius: 10px; padding: 12px; }
.form-error { color: var(--danger); min-height: 1.3em; margin: 0; font-size: .84rem; }

@media (max-width: 1240px) {
    .editor-grid { grid-template-columns: minmax(0, 1fr) minmax(320px, .68fr); }
    .product-panel { grid-row: 1 / span 2; }
    .design-panel, .preview-panel { grid-column: 2; }
    .history-grid { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 820px) {
    .topbar { height: auto; grid-template-columns: 1fr auto; padding: 14px 18px; }
    .topbar nav { grid-column: 1/3; grid-row: 2; margin-top: 12px; overflow-x: auto; }
    .nav-button { flex: 1; white-space: nowrap; }
    .page-shell { width: min(100% - 24px, 1560px); padding-top: 24px; }
    .intro-row { display: block; }
    .intro-copy { margin-top: 18px; }
    .store-toolbar { align-items: flex-start; flex-direction: column; gap: 6px; }
    .url-bar { grid-template-columns: auto 1fr; }
    .url-bar .button { grid-column: 1/3; }
    .editor-grid { grid-template-columns: 1fr; }
    .product-panel, .design-panel, .preview-panel { grid-column: 1; grid-row: auto; }
    .photo-grid { grid-template-columns: repeat(2, 1fr); }
    .history-grid { grid-template-columns: repeat(2, 1fr); }
    .settings-form { grid-template-columns: 1fr; }
    .settings-section-title, .settings-section-copy { grid-column: 1; }
}
@media (max-width: 450px) {
    .panel { padding: 18px; }
    .template-grid { grid-template-columns: 1fr; }
    .history-grid { grid-template-columns: 1fr; }
}

