:root {
    --ink: #17211f;
    --muted: #65716e;
    --line: #dce7e3;
    --paper: #fbfdfb;
    --soft: #eef7f4;
    --brand: #0f766e;
    --brand-dark: #115e59;
    --accent: #b7791f;
    --danger: #b42318;
    --radius: 8px;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    color: var(--ink);
    background: var(--paper);
}

a { color: inherit; text-decoration: none; }
img { display: block; max-width: 100%; }

main {
    width: min(1120px, calc(100% - 28px));
    margin: 0 auto;
    padding: 20px 0 80px;
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 14px;
    background: rgba(251, 253, 251, .94);
    border-bottom: 1px solid var(--line);
    backdrop-filter: blur(12px);
}

.brand, .nav { display: flex; align-items: center; gap: 10px; }
.brand { font-weight: 800; }
.brand-mark {
    display: grid;
    place-items: center;
    width: 36px;
    height: 36px;
    border-radius: var(--radius);
    background: var(--brand);
    color: #fff;
    font-size: 13px;
}
.nav a { color: var(--muted); font-size: 14px; font-weight: 650; }

.hero {
    display: grid;
    gap: 18px;
    min-height: calc(100svh - 88px);
    align-items: center;
    padding: 24px 0;
}

.hero-copy h1, .page-head h1 {
    margin: 0;
    max-width: 760px;
    font-size: clamp(36px, 8vw, 72px);
    line-height: .95;
    letter-spacing: 0;
}

.hero-copy p:not(.eyebrow) {
    max-width: 660px;
    color: var(--muted);
    font-size: 18px;
    line-height: 1.6;
}

.eyebrow {
    margin: 0 0 10px;
    color: var(--accent);
    font-weight: 800;
    text-transform: uppercase;
    font-size: 12px;
}

.upload-panel, .admin-form, .state-card {
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: #fff;
    padding: 14px;
}

.upload-zone {
    display: grid;
    place-items: center;
    min-height: 250px;
    padding: 24px;
    text-align: center;
    border: 2px dashed #9ac8bf;
    border-radius: var(--radius);
    background: var(--soft);
    cursor: pointer;
}

.upload-zone input { position: absolute; opacity: 0; pointer-events: none; }
.upload-icon {
    display: grid;
    place-items: center;
    width: 64px;
    height: 64px;
    margin-bottom: 12px;
    border-radius: 50%;
    background: var(--brand);
    color: #fff;
    font-size: 42px;
    line-height: 1;
}
.upload-zone small, .hint, .rug-card p, .rug-summary p { color: var(--muted); }

.upload-preview {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-top: 12px;
    padding: 10px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: #f9fbfa;
}

.upload-preview img {
    width: 72px;
    height: 72px;
    border-radius: 10px;
    object-fit: cover;
    background: #e9f2f0;
}

.upload-preview p {
    margin: 4px 0 0;
    color: var(--muted);
    font-size: 13px;
    line-height: 1.4;
}

.primary-button, .ghost-button, .whatsapp-button, .danger-button, .install-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    min-height: 46px;
    border: 0;
    border-radius: var(--radius);
    padding: 0 16px;
    font-weight: 800;
    cursor: pointer;
}

.primary-button { background: var(--brand); color: #fff; margin-top: 12px; }
.primary-button:disabled { background: #9db8b3; cursor: not-allowed; }
.ghost-button { width: auto; border: 1px solid var(--line); background: #fff; color: var(--ink); }
.whatsapp-button { background: #25d366; color: #073b1d; }
.danger-button { background: #fff0ed; color: var(--danger); border: 1px solid #ffd1cb; }

.section, .page-head { margin-top: 26px; }
.page-head, .section-heading {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 18px;
}
.section-heading h2 { margin: 0; font-size: 28px; }
.section-heading a { color: var(--brand); font-weight: 800; }

.rug-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
    gap: 14px;
}

.rug-card, .admin-rug {
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: #fff;
}
.rug-card img {
    width: 100%;
    aspect-ratio: 4 / 3;
    object-fit: cover;
}
.rug-card-body { padding: 12px; }
.rug-card h3 { margin: 0 0 6px; font-size: 18px; }
.rug-card p { margin: 0 0 12px; }

.filters { margin-bottom: 16px; }
select, input {
    width: 100%;
    min-height: 44px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 10px 12px;
    background: #fff;
    color: var(--ink);
    font: inherit;
}

.flash, .empty-state {
    margin: 14px 0;
    border-radius: var(--radius);
    padding: 12px 14px;
}
.flash.success { background: #e8f8f1; color: #075e3f; }
.flash.error, .error-state { background: #fff0ed; color: var(--danger); }
.empty-state { border: 1px dashed var(--line); color: var(--muted); }

.result-layout {
    display: grid;
    gap: 16px;
}

.visualizer-grid {
    display: grid;
    gap: 16px;
}

.picker-card, .summary-card {
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: #fff;
    padding: 14px;
}

.picker-help {
    margin: 0 0 12px;
    color: var(--muted);
    line-height: 1.5;
}

.point-count {
    display: inline-flex;
    align-items: center;
    min-height: 28px;
    padding: 0 10px;
    border-radius: 999px;
    background: #edf7f5;
    color: var(--brand);
    font-weight: 800;
}

.picker-form {
    display: grid;
    gap: 12px;
}

.picker-stage {
    position: relative;
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: #f8fbfa;
    aspect-ratio: 4 / 3;
    cursor: crosshair;
}

.picker-stage img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    user-select: none;
    -webkit-user-drag: none;
}

.picker-overlay {
    position: absolute;
    inset: 0;
}

.point-marker {
    position: absolute;
    transform: translate(-50%, -50%);
    display: grid;
    place-items: center;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: rgba(15, 118, 110, 0.92);
    color: #fff;
    font-size: 12px;
    font-weight: 800;
    border: 2px solid #fff;
    box-shadow: 0 8px 20px rgba(15, 23, 42, 0.2);
}

.picker-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.summary-card {
    display: grid;
    gap: 14px;
    align-content: start;
}

.summary-meta {
    display: grid;
    gap: 12px;
    padding-top: 6px;
    border-top: 1px solid var(--line);
}

.summary-meta strong {
    display: block;
    margin-bottom: 4px;
    font-size: 14px;
}

.summary-meta p {
    margin: 0;
    color: var(--muted);
}

.before-after {
    position: relative;
    overflow: hidden;
    border-radius: var(--radius);
    background: #111;
    aspect-ratio: 4 / 3;
}
.before-after img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}
.before-img { position: absolute; inset: 0; }
.after-wrap {
    position: absolute;
    inset: 0;
    width: 50%;
    overflow: hidden;
}
.after-img {
    max-width: none;
    width: calc(100vw - 28px);
}
.before-after input[type="range"] {
    position: absolute;
    inset: auto 14px 14px;
    width: calc(100% - 28px);
    accent-color: var(--brand);
}

.result-actions {
    display: grid;
    gap: 10px;
    align-content: start;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: #fff;
    padding: 14px;
}
.rug-summary { display: flex; align-items: center; gap: 12px; }
.rug-summary img { width: 74px; height: 74px; border-radius: var(--radius); object-fit: cover; }
.rug-summary h2 { margin: 0; font-size: 20px; }

.image-pair {
    display: grid;
    grid-template-columns: 1fr;
    gap: 14px;
    margin-top: 16px;
}
.image-pair figure { margin: 0; }
.image-pair img { width: 100%; border-radius: var(--radius); }
.image-pair figcaption { margin-top: 6px; color: var(--muted); font-weight: 700; }

.admin-layout { display: grid; gap: 16px; }
.admin-form, .admin-rug form { display: grid; gap: 10px; }
.admin-form h2 { margin: 0 0 8px; }
.two-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.check-row { display: flex; align-items: center; gap: 10px; color: var(--muted); }
.check-row input { width: 18px; min-height: 18px; }
.admin-list { display: grid; gap: 12px; }
.admin-rug { display: grid; gap: 12px; padding: 12px; }
.admin-rug > img { width: 100%; aspect-ratio: 5 / 3; object-fit: cover; border-radius: var(--radius); }
.admin-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.install-button {
    position: fixed;
    right: 14px;
    bottom: 14px;
    z-index: 50;
    width: auto;
    background: var(--ink);
    color: #fff;
    box-shadow: 0 16px 40px rgba(15, 23, 42, .2);
}

.spinner {
    width: 44px;
    height: 44px;
    border: 4px solid #cfe6e1;
    border-top-color: var(--brand);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

@media (min-width: 760px) {
    .hero { grid-template-columns: 1.05fr .95fr; }
    .visualizer-grid { grid-template-columns: minmax(0, 1fr) 320px; align-items: start; }
    .result-layout { grid-template-columns: minmax(0, 1fr) 340px; align-items: start; }
    .image-pair { grid-template-columns: 1fr 1fr; }
    .admin-layout { grid-template-columns: 360px minmax(0, 1fr); align-items: start; }
    .admin-rug { grid-template-columns: 170px minmax(0, 1fr); }
    .after-img { width: calc(min(1120px, 100vw - 28px) - 356px); }
}

@media (max-width: 520px) {
    .page-head { align-items: stretch; flex-direction: column; }
    .ghost-button { width: 100%; }
    .nav { gap: 8px; }
    .nav a { font-size: 13px; }
}
