/* ==========================================================================
   Sticker Studio — base styles (mobile first)
   ========================================================================== */

:root {
    --bg: #f4f5f8;
    --surface: #ffffff;
    --surface-2: #f8f9fb;
    --text: #1b1f2a;
    --muted: #667085;
    --border: #e2e5ec;
    --border-strong: #cdd2dc;
    --primary: #2f5bea;
    --primary-hover: #2449c4;
    --primary-soft: #eaf0ff;
    --danger: #d92d20;
    --danger-soft: #fef0ee;
    --success: #12805c;
    --success-soft: #e8f7f0;
    --info: #2f5bea;
    --info-soft: #eaf0ff;
    --radius: 10px;
    --radius-sm: 7px;
    --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .06);
    --focus: 0 0 0 3px rgba(47, 91, 234, .25);
    --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }

/* The hidden attribute must win over any display rule. */
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 15px/1.5 var(--font);
}

h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 1.5rem; }
p { margin: 0; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; }

.muted { color: var(--muted); }

.container {
    width: 100%;
    max-width: 1160px;
    margin: 0 auto;
    padding: 0 16px;
}

.page { padding-top: 24px; padding-bottom: 48px; }

/* ---------- Top bar ---------- */

.topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}

.topbar-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 60px;
    position: relative;
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    color: var(--text);
    font-weight: 700;
    font-size: 1.05rem;
}
.brand:hover { text-decoration: none; }

.nav-toggle {
    display: inline-flex;
    flex-direction: column;
    justify-content: center;
    gap: 4px;
    width: 40px;
    height: 40px;
    padding: 0 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    cursor: pointer;
}
.nav-toggle span { display: block; height: 2px; background: var(--text); border-radius: 2px; }

.nav {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    flex-direction: column;
    padding: 8px 16px 16px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    box-shadow: 0 8px 16px rgba(16, 24, 40, .08);
}
.nav.is-open { display: flex; }

.nav a, .nav-link-btn {
    display: block;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    color: var(--text);
    font: inherit;
    text-align: left;
}
.nav a:hover, .nav-link-btn:hover { background: var(--surface-2); text-decoration: none; }
.nav a.is-active { color: var(--primary); background: var(--primary-soft); font-weight: 600; }
.nav-link-btn { width: 100%; border: 0; background: none; cursor: pointer; }

@media (min-width: 768px) {
    .nav-toggle { display: none; }
    .nav {
        display: flex;
        position: static;
        flex-direction: row;
        align-items: center;
        gap: 4px;
        padding: 0;
        border: 0;
        box-shadow: none;
    }
    .nav-link-btn { width: auto; }
}

/* ---------- Page header ---------- */

.page-head {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 20px;
}
.page-head h1 { word-break: break-word; }
.back-link { display: inline-block; margin-bottom: 4px; font-size: .9rem; }
.page-head-actions { display: flex; flex-wrap: wrap; gap: 8px; }

/* ---------- Cards ---------- */

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 20px;
}
.card.narrow { max-width: 480px; }
.section-title { font-size: 1rem; margin-bottom: 14px; }

/* ---------- Buttons ---------- */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-height: 40px;
    padding: 8px 16px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text);
    font: inherit;
    font-weight: 500;
    line-height: 1.2;
    cursor: pointer;
    white-space: nowrap;
    transition: background-color .15s, border-color .15s;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:focus-visible { outline: none; box-shadow: var(--focus); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-danger-ghost { color: var(--danger); }
.btn-danger-ghost:hover { background: var(--danger-soft); border-color: var(--danger); }
.btn-block { width: 100%; }
.btn-sm { min-height: 34px; padding: 6px 12px; font-size: .875rem; }
.btn-icon { width: 40px; padding: 0; font-size: 1.1rem; }

/* ---------- Forms ---------- */

.form { display: flex; flex-direction: column; gap: 16px; }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field label { font-weight: 600; font-size: .9rem; }
.hint { font-size: .82rem; color: var(--muted); }

input[type="text"], input[type="password"], input[type="search"], input[type="number"], input[type="date"], select {
    width: 100%;
    min-height: 42px;
    padding: 8px 12px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text);
    font: inherit;
}
input:focus, select:focus { outline: none; border-color: var(--primary); box-shadow: var(--focus); }

.has-error input, .has-error select { border-color: var(--danger); }
.field-error { color: var(--danger); font-size: .85rem; }

.input-unit { position: relative; }
.input-unit input { padding-right: 44px; }
.input-unit span {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--muted);
    font-size: .85rem;
    pointer-events: none;
}

.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
/* Spacing inside form sections (the .form flex gap handles top-level fields) */
section.card > .field-row + .field,
section.card > .field + .field-row,
section.card > .field + .field { margin-top: 16px; }

.field-row-size { grid-template-columns: 1fr auto 1fr; align-items: start; }
.swap-btn { margin-top: 28px; }

/* ---------- Alerts ---------- */

.alert {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 16px;
    padding: 12px 14px;
    border: 1px solid;
    border-radius: var(--radius-sm);
    font-size: .92rem;
}
.alert-success { background: var(--success-soft); border-color: #b5e3cf; color: var(--success); }
.alert-error { background: var(--danger-soft); border-color: #f6c5bf; color: var(--danger); }
.alert-info { background: var(--info-soft); border-color: #c7d5ff; color: var(--info); }
.alert-close {
    border: 0;
    background: none;
    color: inherit;
    font-size: 1.2rem;
    line-height: 1;
    cursor: pointer;
    padding: 0 2px;
}

/* ---------- Guest pages ---------- */

.guest-wrap {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 32px 16px;
}
.guest-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 20px;
    font-size: 1.3rem;
    font-weight: 700;
}
.guest-card { width: 100%; max-width: 400px; padding: 28px 24px; }
.guest-card .form { margin-top: 18px; }
.guest-title { font-size: 1.35rem; margin-bottom: 6px; }
.guest-card > .btn { margin-top: 20px; }
.error-code { font-size: 2.5rem; font-weight: 800; color: var(--primary); line-height: 1; margin-bottom: 8px; }

/* ---------- Template list ---------- */

.search-bar { display: flex; gap: 8px; margin-bottom: 20px; }
.search-bar input { flex: 1; min-width: 0; }

.template-grid { display: grid; grid-template-columns: 1fr; gap: 16px; }
@media (min-width: 600px) { .template-grid { grid-template-columns: repeat(2, 1fr); } }
@media (min-width: 960px) { .template-grid { grid-template-columns: repeat(3, 1fr); } }

.template-card { display: flex; flex-direction: column; padding: 0; overflow: hidden; }

.label-thumb {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 150px;
    padding: 20px;
    background:
        radial-gradient(circle, #d6dae3 1px, transparent 1px) 0 0 / 14px 14px,
        var(--surface-2);
    border-bottom: 1px solid var(--border);
}
.label-shape {
    display: flex;
    align-items: center;
    justify-content: center;
    background: #fff;
    border: 1px solid var(--border-strong);
    border-radius: 6px;
    box-shadow: 0 2px 6px rgba(16, 24, 40, .1);
    color: var(--muted);
    font-size: .8rem;
    overflow: hidden;
}
.label-shape.is-wide { width: 100%; height: auto; }
.label-shape.is-tall { height: 100%; width: auto; }
.label-thumb img { max-width: 100%; max-height: 100%; }

.template-body { padding: 14px 16px 6px; flex: 1; }
.template-name { font-size: 1rem; word-break: break-word; }
.template-name a { color: var(--text); }
.template-meta { margin-top: 4px; font-size: .88rem; }
.template-date { margin-top: 2px; font-size: .8rem; }

.template-actions { display: flex; flex-wrap: wrap; gap: 8px; padding: 12px 16px 16px; }
.template-actions form { margin: 0; }

.empty-state { text-align: center; padding: 48px 20px; }
.empty-state h2 { font-size: 1.15rem; margin-bottom: 6px; }
.empty-state .btn { margin-top: 18px; }

.pagination { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 6px; margin-top: 28px; }
.pagination .is-current { background: var(--primary); border-color: var(--primary); color: #fff; cursor: default; }
.pagination-gap { color: var(--muted); padding: 0 4px; }

/* ---------- Template form ---------- */

.template-form { display: grid; grid-template-columns: 1fr; gap: 16px; }
.template-form-main, .template-form-side { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.form-actions { display: flex; flex-direction: column; gap: 8px; }

@media (min-width: 900px) {
    .template-form { grid-template-columns: minmax(0, 1fr) 340px; align-items: start; }
    .template-form-side { position: sticky; top: 84px; }
}

.roll-preview {
    display: flex;
    justify-content: center;
    padding: 16px 0;
    background:
        radial-gradient(circle, #d6dae3 1px, transparent 1px) 0 0 / 14px 14px,
        var(--surface-2);
    border-radius: var(--radius-sm);
    overflow: hidden;
}
.roll-liner {
    position: relative;
    background: #f1e9d8;
    border-radius: 3px;
    box-shadow: 0 1px 4px rgba(16, 24, 40, .15);
}
.roll-label {
    position: absolute;
    background: #fff;
    border-radius: 2px;
    box-shadow: 0 0 0 1px rgba(16, 24, 40, .12);
}
.roll-label.is-first {
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--muted);
    font-size: 11px;
    overflow: hidden;
    white-space: nowrap;
}

.preview-facts { margin: 14px 0 0; display: grid; gap: 6px; font-size: .88rem; }
.preview-facts div { display: flex; justify-content: space-between; gap: 12px; }
.preview-facts dt { color: var(--muted); }
.preview-facts dd { margin: 0; font-weight: 600; text-align: right; }

@media (max-width: 420px) {
    .field-row:not(.field-row-size) { grid-template-columns: 1fr; }
    .card:not(.template-card) { padding: 16px; }
}
