:root {
  --bg: #f8fafc;
  --surface: #ffffff;
  --surface-2: #f1f5f9;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --primary: #e11d48;
  --primary-dark: #be123c;
  --primary-soft: #ffe4e6;
  --accent: #0ea5e9;
  --success: #16a34a;
  --warning: #d97706;
  --danger: #dc2626;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.06), 0 8px 24px rgba(15, 23, 42, 0.06);
  --font: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
img, svg { max-width: 100%; }
h1, h2, h3 { line-height: 1.2; margin: 0 0 0.5em; }
h1 { font-size: clamp(1.8rem, 4vw, 3rem); letter-spacing: -0.02em; }
h2 { font-size: clamp(1.4rem, 2.6vw, 2rem); letter-spacing: -0.01em; }
h3 { font-size: 1.1rem; }
p { margin: 0 0 1em; }
.muted { color: var(--muted); }
.small { font-size: 0.875rem; }
.container { width: 100%; max-width: 1200px; margin: 0 auto; padding: 0 16px; }
.hidden { display: none !important; }

/* ---------- Header ---------- */
.site-header {
  position: sticky; top: 0; z-index: 20;
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.site-header .container { display: flex; align-items: center; justify-content: space-between; height: 64px; gap: 16px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 1.2rem; color: var(--text); }
.brand:hover { text-decoration: none; }
.brand-mark {
  width: 32px; height: 32px; border-radius: 9px;
  background: conic-gradient(from 200deg, #06b6d4, #e11d48, #facc15, #06b6d4);
}
.nav { display: flex; gap: 18px; align-items: center; flex-wrap: wrap; }
.nav a { color: var(--text); font-weight: 500; font-size: 0.95rem; }
@media (max-width: 640px) { .nav .hide-sm { display: none; } }

/* ---------- Buttons & forms ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 18px; border-radius: 10px; border: 1px solid transparent;
  font: inherit; font-weight: 600; cursor: pointer;
  background: var(--primary); color: #fff; transition: background 0.15s, transform 0.05s;
}
.btn:hover { background: var(--primary-dark); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn.secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn.secondary:hover { background: var(--surface-2); }
.btn.ghost { background: transparent; color: var(--text); }
.btn.ghost:hover { background: var(--surface-2); }
.btn.danger { background: var(--danger); }
.btn.small { padding: 6px 12px; font-size: 0.85rem; border-radius: 8px; }
.btn.block { width: 100%; }
.btn.lg { padding: 14px 24px; font-size: 1.05rem; }

label { font-weight: 600; font-size: 0.9rem; display: block; margin-bottom: 6px; }
input[type='text'], input[type='number'], input[type='email'], input[type='password'], input[type='tel'], select, textarea {
  width: 100%; padding: 10px 12px; font: inherit; color: var(--text);
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary-soft); border-color: var(--primary); }
textarea { resize: vertical; min-height: 70px; }
input[type='color'] { width: 44px; height: 36px; padding: 2px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); cursor: pointer; }
.field { margin-bottom: 16px; }
.row { display: flex; gap: 12px; flex-wrap: wrap; }
.row > * { flex: 1 1 120px; min-width: 0; }
.help { font-size: 0.8rem; color: var(--muted); margin-top: 4px; }
.error-text { color: var(--danger); font-size: 0.875rem; }

/* option chips */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { position: relative; }
.chip input { position: absolute; opacity: 0; pointer-events: none; }
.chip span {
  display: block; padding: 8px 14px; border: 1px solid var(--border); border-radius: 999px;
  background: var(--surface); cursor: pointer; font-size: 0.9rem; font-weight: 500;
}
.chip input:checked + span { border-color: var(--primary); background: var(--primary-soft); color: var(--primary-dark); }
.chip input:focus-visible + span { outline: 2px solid var(--primary); }

/* ---------- Cards / layout ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; }
.grid { display: grid; gap: 20px; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
section { padding: 56px 0; }
.section-head { display: flex; justify-content: space-between; align-items: end; gap: 16px; margin-bottom: 24px; flex-wrap: wrap; }

.hero { padding: 72px 0 56px; background: radial-gradient(1200px 400px at 80% -10%, #ffe4e6, transparent), radial-gradient(900px 400px at 0% 0%, #e0f2fe, transparent); }
.hero .container { display: grid; grid-template-columns: 1.1fr 1fr; gap: 40px; align-items: center; }
.hero p.lead { font-size: 1.15rem; color: var(--muted); max-width: 34em; }
.hero-art { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.hero-art .design-thumb { box-shadow: var(--shadow); }
@media (max-width: 860px) { .hero .container { grid-template-columns: minmax(0, 1fr); } }

.product-card { display: flex; flex-direction: column; gap: 8px; color: var(--text); transition: transform 0.15s, box-shadow 0.15s; }
.product-card:hover { transform: translateY(-2px); text-decoration: none; box-shadow: 0 12px 28px rgba(15, 23, 42, 0.1); }
.product-icon { font-size: 2.2rem; width: 56px; height: 56px; display: grid; place-items: center; background: var(--surface-2); border-radius: 12px; }
.product-card .from { margin-top: auto; font-weight: 700; color: var(--primary); }

.steps { display: grid; gap: 20px; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); counter-reset: step; }
.step::before { counter-increment: step; content: counter(step); display: grid; place-items: center; width: 34px; height: 34px; border-radius: 50%; background: var(--primary); color: #fff; font-weight: 700; margin-bottom: 10px; }

/* ---------- Templates ---------- */
.template-card { padding: 12px; display: flex; flex-direction: column; gap: 10px; }
.design-thumb {
  background: repeating-conic-gradient(#f1f5f9 0 25%, #fff 0 50%) 0 0 / 16px 16px;
  border-radius: 10px; aspect-ratio: 4 / 3; display: grid; place-items: center; padding: 12px; overflow: hidden;
}
.design-thumb svg { max-height: 100%; width: auto; max-width: 100%; box-shadow: 0 4px 14px rgba(15, 23, 42, 0.18); border-radius: 2px; }
.template-meta { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.badge { display: inline-block; padding: 2px 8px; font-size: 0.75rem; font-weight: 600; border-radius: 999px; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.badge.good { background: #dcfce7; color: #166534; }
.badge.ok { background: #fef3c7; color: #92400e; }
.badge.poor { background: #fee2e2; color: #991b1b; }
.badge.status-new { background: #dbeafe; color: #1e40af; }
.badge.status-in_production { background: #fef3c7; color: #92400e; }
.badge.status-ready, .badge.status-shipped { background: #e0e7ff; color: #3730a3; }
.badge.status-completed { background: #dcfce7; color: #166534; }
.badge.status-cancelled { background: #fee2e2; color: #991b1b; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- Configurator ---------- */
.config-layout { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 24px; align-items: start; padding: 32px 0 56px; }
@media (max-width: 960px) { .config-layout { grid-template-columns: minmax(0, 1fr); } }
.config-section { margin-bottom: 20px; }
.config-section h3 { display: flex; align-items: center; gap: 8px; }
.price-panel { position: sticky; top: 84px; }
.price-total { font-size: 2.2rem; font-weight: 800; letter-spacing: -0.02em; }
.price-lines { list-style: none; padding: 0; margin: 12px 0; font-size: 0.92rem; }
.price-lines li { display: flex; justify-content: space-between; gap: 12px; padding: 5px 0; border-bottom: 1px dashed var(--border); }
.price-lines li.discount span:last-child { color: var(--success); }
.size-preview { display: grid; place-items: center; background: var(--surface-2); border-radius: 12px; height: 180px; padding: 16px; }
.size-preview .paper { background: #fff; border: 2px solid var(--text); border-radius: 3px; display: grid; place-items: center; font-size: 0.8rem; color: var(--muted); max-width: 100%; max-height: 100%; }
.tier-table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
.tier-table td, .tier-table th { padding: 6px 4px; text-align: left; border-bottom: 1px solid var(--border); }
.tier-table tr.active { background: var(--primary-soft); font-weight: 600; }

/* ---------- Designer ---------- */
.designer { display: grid; grid-template-columns: 320px minmax(0, 1fr) 320px; gap: 20px; padding: 24px 0 56px; align-items: start; }
@media (max-width: 1100px) { .designer { grid-template-columns: 1fr 1fr; } .designer .canvas-col { grid-column: 1 / -1; order: -1; } }
@media (max-width: 700px) { .designer { grid-template-columns: minmax(0, 1fr); } }
.canvas-wrap {
  background: repeating-conic-gradient(#e2e8f0 0 25%, #f8fafc 0 50%) 0 0 / 20px 20px;
  border-radius: var(--radius); border: 1px solid var(--border);
  min-height: 420px; display: grid; place-items: center; padding: 24px;
}
.canvas-wrap svg { width: 100%; max-height: 70vh; box-shadow: 0 10px 30px rgba(15, 23, 42, 0.25); background: #fff; }
.design-svg .is-selected { outline: 3px dashed var(--accent); outline-offset: 4px; }
.layer { border: 1px solid var(--border); border-radius: 10px; padding: 10px; margin-bottom: 10px; background: var(--surface); }
.layer.selected { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(14, 165, 233, 0.15); }
.layer-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 6px; }
.layer-head strong { font-size: 0.85rem; }
.layer-controls { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 8px; }
.layer-controls input[type='range'] { flex: 1; min-width: 80px; }

/* ---------- Modal ---------- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(15, 23, 42, 0.5); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal { background: var(--surface); border-radius: var(--radius); max-width: 560px; width: 100%; max-height: 90vh; overflow: auto; padding: 24px; box-shadow: 0 20px 50px rgba(0, 0, 0, 0.3); }
.modal.wide { max-width: 980px; }

/* ---------- Footer ---------- */
.site-footer { border-top: 1px solid var(--border); padding: 32px 0; color: var(--muted); font-size: 0.9rem; background: var(--surface); }
.site-footer .container { display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap; }

/* ---------- Toasts ---------- */
.toasts { position: fixed; bottom: 16px; right: 16px; left: 16px; display: flex; flex-direction: column; align-items: flex-end; gap: 8px; z-index: 100; pointer-events: none; }
.toast { background: var(--text); color: #fff; padding: 10px 16px; border-radius: 10px; box-shadow: var(--shadow); max-width: 420px; pointer-events: auto; }
.toast.error { background: var(--danger); }
.toast.success { background: var(--success); }

/* ---------- Admin ---------- */
.admin-shell { display: grid; grid-template-columns: 230px minmax(0, 1fr); min-height: 100vh; }
.admin-side { background: #0f172a; color: #cbd5e1; padding: 20px 14px; display: flex; flex-direction: column; gap: 4px; }
.admin-side .brand { color: #fff; margin-bottom: 20px; }
.admin-side button { all: unset; cursor: pointer; padding: 10px 12px; border-radius: 8px; font-weight: 500; }
.admin-side button:hover { background: rgba(255, 255, 255, 0.06); }
.admin-side button.active { background: var(--primary); color: #fff; }
.admin-side .spacer { flex: 1; }
.admin-main { padding: 28px; min-width: 0; }
@media (max-width: 800px) {
  .admin-shell { grid-template-columns: minmax(0, 1fr); }
  .admin-side { flex-direction: row; flex-wrap: wrap; padding: 10px; }
  .admin-side .brand { margin: 0 12px 0 0; }
  .admin-side .spacer { display: none; }
  .admin-main { padding: 16px; }
}
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat .value { font-size: 1.8rem; font-weight: 800; }
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
table.data th, table.data td { padding: 10px 8px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; }
table.data th { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
table.data input, table.data select { padding: 6px 8px; border-radius: 7px; min-width: 70px; }
.editor-section { margin-bottom: 24px; }
.editor-section > h3 { display: flex; justify-content: space-between; align-items: center; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.split { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 24px; align-items: start; }
@media (max-width: 1100px) { .split { grid-template-columns: minmax(0, 1fr); } }
.sticky { position: sticky; top: 16px; }
.login-box { max-width: 380px; margin: 12vh auto; }
.admin-main h1 { font-size: 1.8rem; }

/* ---------- Mobile ---------- */
.mobile-bar { display: none; }
@media (max-width: 960px) {
  /* Keeps the live price and the next step visible while scrolling through options. */
  .mobile-bar {
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
    padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
    background: var(--surface); border-top: 1px solid var(--border);
    box-shadow: 0 -6px 20px rgba(15, 23, 42, 0.08);
  }
  .mobile-bar .mb-total { font-size: 1.3rem; font-weight: 800; line-height: 1.1; }
  .mobile-bar .mb-sub { font-size: 0.78rem; color: var(--muted); }
  .mobile-bar .btn { flex: 0 0 auto; }
  body.has-mobile-bar { padding-bottom: 76px; }
  body.has-mobile-bar .toasts { bottom: 88px; }
  .price-panel { position: static; }
}
@media (max-width: 640px) {
  .site-header .container { height: 56px; }
  .brand { font-size: 1.05rem; }
  .brand-mark { width: 28px; height: 28px; }
  .site-header .container { gap: 8px; }
  .nav { gap: 12px; flex-wrap: nowrap; }
  .nav a { font-size: 0.85rem; white-space: nowrap; }
  section { padding: 40px 0; }
  .hero { padding: 40px 0 32px; }
  .card { padding: 16px; }
  .canvas-wrap { min-height: 0; padding: 12px; }
  .modal { padding: 18px; }
  .price-total { font-size: 1.9rem; }
}
@media (max-width: 374px) {
  .brand-mark { display: none; }
  .nav { gap: 10px; }
}
@media (pointer: coarse) {
  .btn.small { min-height: 38px; padding: 8px 12px; }
  .chip span { padding: 10px 14px; }
  input[type='color'] { width: 48px; height: 40px; }
}
