:root {
  --brand: #4338ca; --brand-dark: #3730a3; --brand-soft: #eef2ff;
  --ink: #111827; --ink-2: #374151; --muted: #6b7280; --line: #e5e7eb; --bg: #f6f7fb; --card: #fff;
  --ok: #15803d; --ok-soft: #dcfce7; --warn: #b45309; --warn-soft: #fef3c7; --bad: #b91c1c; --bad-soft: #fee2e2;
  --radius: 10px; --shadow: 0 1px 2px rgba(16,24,40,.06), 0 4px 14px rgba(16,24,40,.06);
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font-size: 15px; line-height: 1.5; }
a { color: var(--brand); }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .5em; }
p { margin: 0 0 .8em; }
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }

/* buttons & inputs */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .4em; padding: .55em 1.05em; border-radius: 8px; border: 1px solid var(--line);
  background: #fff; color: var(--ink); cursor: pointer; text-decoration: none; font-weight: 600; white-space: nowrap; }
.btn:hover { background: #f9fafb; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-dark); }
.btn.danger { color: var(--bad); border-color: #fecaca; }
.btn.small { padding: .3em .7em; font-size: .88em; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.icon-btn { border: 1px solid transparent; background: transparent; border-radius: 6px; padding: .2em .45em; cursor: pointer; color: var(--ink-2); font-size: .9em; }
.icon-btn:hover { background: #f3f4f6; border-color: var(--line); }
.icon-btn.danger:hover { color: var(--bad); }
input[type=text], input[type=email], input[type=tel], input[type=month], input:not([type]), select, textarea {
  width: 100%; padding: .5em .65em; border: 1px solid #d1d5db; border-radius: 7px; background: #fff; }
input:focus, select:focus, textarea:focus { outline: 2px solid #c7d2fe; border-color: var(--brand); }
textarea { resize: vertical; min-height: 70px; }
label > span { display: block; font-size: .83em; font-weight: 600; color: var(--ink-2); margin-bottom: .2em; }
.muted { color: var(--muted); }
.small { font-size: .87em; }

/* layout */
.nav { display: flex; align-items: center; gap: 1rem; padding: .8rem 1.5rem; background: #fff; border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
.brand { font-weight: 800; font-size: 1.15rem; color: var(--ink); text-decoration: none; display: flex; align-items: center; gap: .45rem; }
.brand i { width: 26px; height: 26px; border-radius: 7px; background: var(--brand); display: inline-block; position: relative; }
.brand i::after { content: ""; position: absolute; inset: 6px 7px; border-top: 2px solid #fff; border-bottom: 2px solid #fff; }
.nav .spacer { flex: 1; }
.nav a.link { color: var(--ink-2); text-decoration: none; font-weight: 600; }
.wrap { max-width: 1180px; margin: 0 auto; padding: 1.5rem; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.25rem; }

/* auth */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 1.5rem; }
.auth .card { width: 100%; max-width: 420px; padding: 2rem; }
.auth h1 { font-size: 1.5rem; }
.auth form > * + * { margin-top: .9rem; }
.auth .btn { width: 100%; padding: .7em; }
.code-input { font-size: 1.6rem !important; letter-spacing: .5em; text-align: center; font-weight: 700; }
.alert { padding: .65em .85em; border-radius: 8px; font-size: .92em; }
.alert.error { background: var(--bad-soft); color: var(--bad); }
.alert.info { background: var(--brand-soft); color: var(--brand-dark); }
.alert.ok { background: var(--ok-soft); color: var(--ok); }

/* landing */
.hero { display: grid; grid-template-columns: 1.1fr 1fr; gap: 2.5rem; align-items: center; padding: 3.5rem 1.5rem 2rem; max-width: 1180px; margin: 0 auto; }
.hero h1 { font-size: clamp(2rem, 4.5vw, 3.2rem); letter-spacing: -.02em; }
.hero p.lead { font-size: 1.15rem; color: var(--ink-2); }
.hero .ctas { display: flex; gap: .75rem; flex-wrap: wrap; margin-top: 1.2rem; }
.hero-stack { position: relative; height: 420px; }
.hero-stack .thumb { position: absolute; box-shadow: 0 12px 40px rgba(17,24,39,.18); }
.features { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 1rem; max-width: 1180px; margin: 1rem auto 3rem; padding: 0 1.5rem; }
.features .card h3 { font-size: 1.05rem; }
.features .card p { color: var(--ink-2); margin: 0; font-size: .95em; }
footer.foot { text-align: center; color: var(--muted); padding: 2rem 1rem; font-size: .9em; }

/* thumbnails & gallery */
.thumb { background: #fff; overflow: hidden; border-radius: 6px; border: 1px solid var(--line); position: relative; }
.thumb > .thumb-inner { transform-origin: 0 0; position: absolute; left: 0; top: 0; pointer-events: none; }
.gallery-filters { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; margin-bottom: 1rem; }
.gallery-filters input { max-width: 220px; }
.gallery-filters select { width: auto; }
.chip { border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: .25em .75em; cursor: pointer; font-size: .87em; font-weight: 600; color: var(--ink-2); }
.chip.active { background: var(--brand); color: #fff; border-color: var(--brand); }
.swatch { width: 22px; height: 22px; border-radius: 50%; border: 2px solid #fff; box-shadow: 0 0 0 1px var(--line); cursor: pointer; padding: 0; }
.swatch.active { box-shadow: 0 0 0 2px var(--brand); }
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(var(--tw, 170px), 1fr)); gap: 1rem; }
.design-card { cursor: pointer; border-radius: 9px; padding: 6px; border: 2px solid transparent; background: transparent; text-align: left; }
.design-card:hover { background: #fff; border-color: #c7d2fe; }
.design-card.selected { border-color: var(--brand); background: var(--brand-soft); }
.design-card .meta { display: flex; justify-content: space-between; gap: .4rem; font-size: .83em; margin-top: .35rem; }
.design-card .meta b { font-weight: 600; }
.badge { display: inline-block; font-size: .72em; font-weight: 700; padding: .15em .55em; border-radius: 999px; background: var(--brand-soft); color: var(--brand-dark); text-transform: uppercase; letter-spacing: .03em; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }

/* dashboard */
.quota { display: flex; gap: 1rem; align-items: center; justify-content: space-between; flex-wrap: wrap; }
.quota.used { border-left: 4px solid var(--warn); }
.quota.free { border-left: 4px solid var(--ok); }
.kinds { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 1rem; }
.kind-card { text-align: left; cursor: pointer; border: 1px dashed #c7d2fe; background: #fff; border-radius: var(--radius); padding: 1rem 1.1rem; }
.kind-card:hover { border-style: solid; border-color: var(--brand); background: var(--brand-soft); }
.kind-card b { display: block; font-size: 1.02rem; }
.kind-card span { color: var(--muted); font-size: .9em; }
.docs { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 1.2rem; }
.doc-card { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: .7rem; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: .5rem; }
.doc-card .thumb { cursor: pointer; }
.doc-card .title { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.doc-card .row { display: flex; gap: .25rem; flex-wrap: wrap; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin: 2rem 0 1rem; }
.section-head h2 { margin: 0; font-size: 1.2rem; }
.empty { text-align: center; padding: 2.5rem; color: var(--muted); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: .8rem; }

/* modal */
.modal-back { position: fixed; inset: 0; background: rgba(17,24,39,.5); display: grid; place-items: center; z-index: 100; padding: 1rem; }
.modal { background: #fff; border-radius: 14px; width: 100%; max-width: 520px; max-height: calc(100vh - 2rem); display: flex; flex-direction: column; box-shadow: 0 25px 60px rgba(0,0,0,.25); }
.modal.wide { max-width: 1100px; }
.modal-head { padding: 1rem 1.25rem; border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.modal-head h2 { margin: 0; font-size: 1.15rem; }
.modal-body { padding: 1.25rem; overflow: auto; }
.modal-foot { padding: .9rem 1.25rem; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: .6rem; align-items: center; flex-wrap: wrap; }

/* toast */
.toasts { position: fixed; bottom: 1rem; left: 50%; transform: translateX(-50%); z-index: 200; display: flex; flex-direction: column; gap: .5rem; align-items: center; }
.toast { background: var(--ink); color: #fff; padding: .6em 1em; border-radius: 8px; box-shadow: var(--shadow); font-size: .92em; max-width: 90vw; }
.toast.error { background: var(--bad); }

/* editor */
body.editor-page { height: 100vh; overflow: hidden; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: .6rem; padding: .55rem 1rem; background: #fff; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.topbar .title-input { max-width: 340px; font-weight: 700; border-color: transparent; }
.topbar .title-input:hover { border-color: var(--line); }
.topbar .spacer { flex: 1; }
.save-state { font-size: .85em; color: var(--muted); min-width: 70px; }
.editor { flex: 1; display: grid; grid-template-columns: minmax(380px, 520px) 1fr; min-height: 0; }
.panel { background: #fff; border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.tabs { display: flex; border-bottom: 1px solid var(--line); }
.tabs button { flex: 1; padding: .75em; border: 0; background: transparent; cursor: pointer; font-weight: 600; color: var(--muted); border-bottom: 2px solid transparent; }
.tabs button.active { color: var(--brand); border-bottom-color: var(--brand); }
.tab-body { overflow: auto; padding: 1rem; flex: 1; }
.block { border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: .9rem; background: #fff; }
.block > summary { list-style: none; cursor: pointer; padding: .7rem .9rem; display: flex; align-items: center; gap: .5rem; font-weight: 700; }
.block > summary::-webkit-details-marker { display: none; }
.block > summary::before { content: "\25B8"; color: var(--muted); transition: transform .15s; }
.block[open] > summary::before { transform: rotate(90deg); }
.block > summary .stype { font-weight: 500; font-size: .8em; color: var(--muted); }
.block > summary .tools { margin-left: auto; display: flex; gap: .1rem; }
.block.hidden-sec > summary .name { color: var(--muted); text-decoration: line-through; }
.block-body { padding: 0 .9rem .9rem; }
.fields { display: grid; grid-template-columns: 1fr 1fr; gap: .65rem; }
.fields .wide { grid-column: 1 / -1; }
.check { display: flex; align-items: center; gap: .45rem; font-size: .9em; grid-column: 1 / -1; }
.item-card { border: 1px solid var(--line); border-radius: 8px; padding: .7rem; margin-bottom: .6rem; background: #fcfcfd; }
.item-card .item-top { display: flex; align-items: center; gap: .4rem; margin-bottom: .5rem; }
.item-card .item-top b { flex: 1; font-size: .92em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rich-tools { display: flex; gap: .3rem; margin-top: .3rem; flex-wrap: wrap; align-items: center; }
.rich-tools select { width: auto; font-size: .85em; padding: .2em .4em; }
.photo-row { display: flex; align-items: center; gap: .8rem; grid-column: 1 / -1; }
.photo-row img { width: 60px; height: 60px; border-radius: 50%; object-fit: cover; border: 1px solid var(--line); }
.photo-row .ph { width: 60px; height: 60px; border-radius: 50%; background: #f3f4f6; display: grid; place-items: center; color: var(--muted); font-size: .75em; }
.add-row { display: flex; gap: .5rem; }
.add-row select { flex: 1; }
.style-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .8rem 1rem; margin-bottom: 1.2rem; }
.style-grid .wide { grid-column: 1 / -1; }
.range-row { display: flex; align-items: center; gap: .5rem; }
.range-row input { flex: 1; }
.range-row output { min-width: 3.2em; text-align: right; font-size: .85em; color: var(--muted); }
.swatches { display: flex; gap: .4rem; flex-wrap: wrap; align-items: center; }
input[type=color] { width: 40px; height: 30px; padding: 0 2px; border: 1px solid var(--line); border-radius: 6px; background: #fff; cursor: pointer; }

.preview-pane { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: #e5e7eb; }
.preview-toolbar { display: flex; align-items: center; gap: .4rem; padding: .45rem .8rem; font-size: .88em; color: var(--ink-2); background: #f3f4f6; border-bottom: 1px solid var(--line); }
.preview-toolbar .spacer { flex: 1; }
.preview-scroll { flex: 1; overflow: auto; padding: 1.5rem; }
#sizer { overflow: hidden; padding: 0; }
.preview-stage { position: relative; transform-origin: top left; }
.style-grid .lbl { display: block; font-size: .83em; font-weight: 600; color: var(--ink-2); margin-bottom: .3em; }
.preview-stage .page-wrap { box-shadow: 0 8px 30px rgba(0,0,0,.15); background: #fff; position: relative; }
.page-guides { position: absolute; inset: 0; pointer-events: none; }
.page-guides .guide { position: absolute; left: -12px; right: -12px; border-top: 2px dashed #ef4444; opacity: .55; }
.page-guides .guide span { position: absolute; right: 0; top: -1.6em; background: #ef4444; color: #fff; font: 600 11px system-ui; padding: 1px 6px; border-radius: 4px; }

.dropdown { position: relative; }
.menu { position: absolute; right: 0; top: calc(100% + 6px); background: #fff; border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 12px 40px rgba(0,0,0,.15); width: 320px; padding: .5rem; z-index: 50; }
.menu button.opt { display: block; width: 100%; text-align: left; border: 0; background: transparent; padding: .6em .7em; border-radius: 7px; cursor: pointer; }
.menu button.opt:hover:not(:disabled) { background: var(--brand-soft); }
.menu button.opt b { display: block; }
.menu button.opt span { font-size: .83em; color: var(--muted); }
.menu button.opt:disabled { opacity: .5; cursor: not-allowed; }
.menu .note { font-size: .83em; padding: .5em .7em; border-radius: 7px; margin-bottom: .3rem; }

/* ATS */
.score { display: flex; align-items: center; gap: 1rem; margin: 1rem 0; }
.score-ring { --p: 0; width: 84px; height: 84px; border-radius: 50%; display: grid; place-items: center; font-size: 1.5rem; font-weight: 800;
  background: radial-gradient(closest-side, #fff 78%, transparent 80% 100%), conic-gradient(var(--c, var(--brand)) calc(var(--p) * 1%), #e5e7eb 0); }
.checks { list-style: none; padding: 0; margin: 0 0 1rem; }
.checks li { display: flex; gap: .55rem; padding: .45rem 0; border-bottom: 1px solid #f1f1f4; font-size: .92em; }
.checks li i { flex: none; width: 1.3em; height: 1.3em; border-radius: 50%; display: grid; place-items: center; font-style: normal; font-size: .78em; font-weight: 800; margin-top: .1em; }
.checks li.good i { background: var(--ok-soft); color: var(--ok); }
.checks li.warn i { background: var(--warn-soft); color: var(--warn); }
.checks li.bad i { background: var(--bad-soft); color: var(--bad); }
.kw { display: flex; flex-wrap: wrap; gap: .35rem; margin: .4rem 0 1rem; }
.kw span { font-size: .82em; padding: .15em .6em; border-radius: 999px; }
.kw .hit { background: var(--ok-soft); color: var(--ok); }
.kw .miss { background: var(--bad-soft); color: var(--bad); }

.mobile-switch { display: none; }
@media (max-width: 900px) {
  .hero { grid-template-columns: 1fr; padding-top: 2rem; }
  .hero-stack { display: none; }
  .editor { grid-template-columns: 1fr; }
  .editor.show-preview .panel { display: none; }
  .editor:not(.show-preview) .preview-pane { display: none; }
  .mobile-switch { display: flex; gap: .3rem; }
  .topbar .title-input { max-width: 160px; }
  .fields, .style-grid, .grid2 { grid-template-columns: 1fr; }
  .wrap { padding: 1rem; }
  .nav { padding: .7rem 1rem; }
}
