:root {
    --bg: #eef1f8;
    --card: #ffffff;
    --ink: #0f172a;
    --muted: #64748b;
    --line: #e4e8f1;
    --accent: #4f46e5;
    --accent-2: #2563eb;
    --accent-ink: #ffffff;
    --ok: #16a34a;
    --warn: #d97706;
    --danger: #dc2626;
    --radius: 16px;
    --shadow: 0 1px 2px rgba(15, 23, 42, .05), 0 12px 30px -18px rgba(15, 23, 42, .35);
    --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body { margin: 0; padding: 0; }

body {
    font-family: "Segoe UI", system-ui, -apple-system, Roboto, Helvetica, Arial, sans-serif;
    color: var(--ink);
    background:
        radial-gradient(1000px 500px at 10% -10%, #e0e7ff 0%, transparent 60%),
        radial-gradient(900px 400px at 110% 0%, #cffafe 0%, transparent 55%),
        var(--bg);
    min-height: 100vh;
    font-size: 15px;
    line-height: 1.5;
}

a { color: var(--accent); text-decoration: none; }

code { font-family: var(--mono); font-size: .86em; }

/* ---------- top bar ---------- */
.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 14px 26px;
    background: rgba(255, 255, 255, .82);
    backdrop-filter: blur(8px);
    border-bottom: 1px solid var(--line);
    position: sticky;
    top: 0;
    z-index: 20;
}

.brand { display: flex; align-items: center; gap: 10px; font-size: 16px; }

.brand-mark {
    width: 36px;
    height: 36px;
    display: block;
    border-radius: 10px;
    overflow: hidden;
    box-shadow: 0 6px 16px -10px rgba(79, 70, 229, .9);
}

.brand-mark img { display: block; width: 36px; height: 36px; }

.brand-text strong { font-weight: 800; font-size: 20px; letter-spacing: -.03em; }

.topnav { display: flex; align-items: center; gap: 6px; }

.topnav a {
    padding: 7px 14px;
    border-radius: 999px;
    color: var(--muted);
    font-weight: 600;
    font-size: 14px;
}

.topnav a:hover { background: #eef2ff; color: var(--accent); }
.topnav a.active { background: var(--ink); color: #fff; }

.nav-form { margin: 0; }

.nav-btn {
    padding: 7px 14px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: #fff;
    color: var(--muted);
    font: inherit;
    font-weight: 600;
    font-size: 14px;
    cursor: pointer;
    transition: background .15s, color .15s, border-color .15s;
}

.nav-btn:hover { background: #fef2f2; border-color: #fecaca; color: var(--danger); }

.nav-user {
    padding: 7px 14px;
    border-radius: 999px;
    background: #eef2ff;
    color: #3730a3;
    font-size: 13.5px;
    font-weight: 700;
    max-width: 170px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.banner {
    margin: 14px 26px 0;
    padding: 10px 14px;
    border-radius: 10px;
    font-size: 14px;
}

.banner-error { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }
.banner-ok { background: #ecfdf5; color: #065f46; border: 1px solid #a7f3d0; }

/* ---------- layout ---------- */
.wrap { max-width: 1160px; margin: 0 auto; padding: 26px 20px 40px; }
.wrap-wide { max-width: 90%; }

.grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 400px;
    gap: 22px;
    align-items: start;
}

.card {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 22px;
}

.preview-card { position: sticky; top: 84px; }

.card-head h1 { margin: 0 0 4px; font-size: 22px; letter-spacing: -.02em; }
.card-head p { margin: 0 0 18px; color: var(--muted); font-size: 14px; }

/* ---------- tabs ---------- */
.tabs {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 6px;
    padding: 5px;
    background: #f1f4fb;
    border: 1px solid var(--line);
    border-radius: 14px;
}

.tab {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    padding: 9px 12px;
    border: 0;
    border-radius: 10px;
    background: transparent;
    color: var(--muted);
    font: inherit;
    font-size: 13.5px;
    font-weight: 600;
    cursor: pointer;
    transition: background .15s, color .15s, box-shadow .15s;
    white-space: nowrap;
}

.tab:hover { color: var(--ink); background: #fff; }

.tab.active {
    background: #fff;
    color: var(--ink);
    box-shadow: 0 1px 2px rgba(15, 23, 42, .1), 0 6px 14px -10px rgba(15, 23, 42, .5);
}

.tab.active svg { color: var(--accent); }

/* ---------- form ---------- */
.panels { margin-top: 18px; }
.panel { display: none; }
.panel.active { display: block; animation: fade .18s ease; }

@keyframes fade { from { opacity: 0; transform: translateY(3px); } to { opacity: 1; transform: none; } }

.row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.row + .row, .row + .field, .field + .row, .field + .field { margin-top: 14px; }
.row > .field { margin-top: 0; }
.panel > .field:first-child { margin-top: 0; }

.field { display: block; }

.field-label {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    font-size: 12.5px;
    font-weight: 600;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: .04em;
    margin-bottom: 6px;
}

.field-inline { margin-top: 0; }

.pw-wrap { position: relative; display: block; }
.pw-wrap input { padding-right: 64px; }

.pw-toggle {
    position: absolute;
    right: 6px;
    top: 50%;
    transform: translateY(-50%);
    padding: 5px 9px;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: var(--accent);
    font: inherit;
    font-size: 12.5px;
    font-weight: 700;
    letter-spacing: .03em;
    cursor: pointer;
}

.pw-toggle:hover { background: #eef0ff; }
.pw-toggle:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

input[type="text"],
input[type="url"],
input[type="email"],
input[type="tel"],
input[type="password"],
input[type="number"],
textarea,
select {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: #fbfcfe;
    color: var(--ink);
    font: inherit;
    font-size: 14.5px;
    transition: border-color .15s, box-shadow .15s, background .15s;
}

textarea { resize: vertical; min-height: 84px; }

input:focus, textarea:focus, select:focus {
    outline: none;
    border-color: var(--accent);
    background: #fff;
    box-shadow: 0 0 0 3px rgba(79, 70, 229, .13);
}

select { cursor: pointer; }

input[type="range"] {
    width: 100%;
    accent-color: var(--accent);
    height: 26px;
}

.hint { color: var(--muted); font-size: 13px; margin: 10px 0 0; }
.counter { color: var(--muted); font-size: 12.5px; margin-top: 8px; text-align: right; }

.check {
    display: inline-flex;
    align-items: center;
    gap: 9px;
    margin-top: 14px;
    font-size: 14px;
    cursor: pointer;
    color: var(--ink);
}

.check input { width: 16px; height: 16px; accent-color: var(--accent); }

.section-divider { height: 1px; background: var(--line); margin: 22px 0; }

.section-head, .sub-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 14px;
}

.section-head h2 { margin: 0; font-size: 17px; letter-spacing: -.01em; }
.sub-head h3 { margin: 0; font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.sub-head { margin-top: 20px; }

/* ---------- colors ---------- */
.colors { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }

.color-field {
    display: flex;
    flex-direction: column;
    gap: 7px;
    font-size: 12.5px;
    font-weight: 600;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: .04em;
}

.color-input {
    display: flex;
    align-items: center;
    gap: 8px;
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 6px 8px;
    background: #fbfcfe;
}

.color-input input[type="color"] {
    width: 30px; height: 26px;
    padding: 0; border: 0; background: none; cursor: pointer;
}

.color-input .hex {
    border: 0; background: transparent; padding: 0;
    font-family: var(--mono); font-size: 13px; text-transform: lowercase;
    color: var(--ink);
}
.color-input .hex:focus { box-shadow: none; }

.gradient-row { margin-top: 12px; }

/* ---------- shape pills ---------- */
.shape-groups { display: grid; gap: 14px; }
.shape-group { display: grid; grid-template-columns: 110px 1fr; align-items: center; gap: 12px; }
.shape-label { font-size: 13px; color: var(--muted); font-weight: 600; }

.pills { display: flex; flex-wrap: wrap; gap: 8px; }

.pill {
    width: 44px; height: 44px;
    display: grid; place-items: center;
    border: 1px solid var(--line);
    border-radius: 11px;
    background: #fbfcfe;
    cursor: pointer;
    transition: border-color .15s, background .15s, transform .1s;
}

.pill:hover { border-color: #c7cddb; transform: translateY(-1px); }
.pill.active { border-color: var(--accent); background: #eef2ff; box-shadow: 0 0 0 3px rgba(79, 70, 229, .12); }

.sw { width: 22px; height: 22px; background: var(--ink); display: block; }
.sw-square { border-radius: 0; }
.sw-rounded { border-radius: 6px; }
.sw-extra { border-radius: 11px; }
.sw-dots { border-radius: 50%; }
.sw-classy { border-radius: 60% 4px 60% 4px; }
.sw-classy-rounded { border-radius: 60% 24% 60% 24%; }

.eye {
    width: 24px; height: 24px;
    border: 3px solid var(--ink);
    display: block; position: relative;
}
.eye::after { content: ""; position: absolute; inset: 4px; background: var(--ink); }
.eye-square { border-radius: 0; }
.eye-square::after { border-radius: 0; }
.eye-extra { border-radius: 9px; }
.eye-extra::after { border-radius: 5px; }
.eye-dot { border-radius: 50%; }
.eye-dot::after { border-radius: 50%; }

.corner {
    width: 24px; height: 24px;
    border: 2px solid var(--ink);
    display: block; position: relative;
}
.corner::after { content: ""; position: absolute; inset: 4px; background: var(--ink); }
.corner-dot, .corner-dot::after { border-radius: 50%; }
.corner-square, .corner-square::after { border-radius: 0; }

/* ---------- file input ---------- */
.file-box {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    border: 1px dashed #cbd3e1;
    border-radius: 10px;
    padding: 11px 13px;
    background: #fbfcfe;
    cursor: pointer;
}

.file-box:hover { border-color: var(--accent); background: #f7f8ff; }
.file-box input[type="file"] { position: absolute; opacity: 0; width: 1px; height: 1px; }
.file-text { font-size: 13.5px; color: var(--muted); }

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

.logo-preview img { width: 42px; height: 42px; object-fit: contain; background: #fff; border-radius: 8px; border: 1px solid var(--line); }

/* ---------- preview ---------- */
.qr-stage {
    position: relative;
    display: grid;
    place-items: center;
    min-height: 336px;
    padding: 18px;
    border: 1px solid var(--line);
    border-radius: 14px;
    background:
        linear-gradient(45deg, #f4f6fb 25%, transparent 25%, transparent 75%, #f4f6fb 75%),
        linear-gradient(45deg, #f4f6fb 25%, #ffffff 25%, #ffffff 75%, #f4f6fb 75%);
    background-size: 18px 18px;
    background-position: 0 0, 9px 9px;
    overflow: hidden;
}

#qr-preview { display: grid; place-items: center; max-width: 100%; }
#qr-preview canvas, #qr-preview svg { max-width: 100%; height: auto; border-radius: 8px; display: block; }

.qr-error {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    text-align: center;
    padding: 24px;
    background: rgba(255, 255, 255, .98);
    border: 1px dashed #fca5a5;
    border-radius: 14px;
    color: #b91c1c;
    font-size: 14px;
    font-weight: 600;
}

.qr-error.neutral {
    background: #fff;
    border-color: #cbd5e1;
    color: #64748b;
    font-weight: 500;
}

.payload-box {
    margin-top: 14px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: #fbfcfe;
    padding: 11px 12px;
}

.payload-label {
    display: block;
    font-size: 11.5px;
    font-weight: 700;
    letter-spacing: .06em;
    text-transform: uppercase;
    color: var(--muted);
    margin-bottom: 5px;
}

#payload-preview {
    display: block;
    max-height: 76px;
    overflow: auto;
    word-break: break-all;
    font-family: var(--mono);
    font-size: 12.5px;
    color: #334155;
    white-space: pre-wrap;
}

.meta-chips { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 12px; }

.chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    border-radius: 999px;
    background: #eef2ff;
    color: #3730a3;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: .02em;
}

.chip.neutral { background: #f1f5f9; color: #475569; }
.chip.ok { background: #dcfce7; color: #166534; }
.chip.warn { background: #fef3c7; color: #92400e; }

.quota-chip {
    margin-left: auto;
    background: #eef2ff;
    color: #3730a3;
    border: 1px solid #c7d2fe;
    padding: 6px 12px;
    font-size: 12.5px;
}

.actions { display: flex; gap: 10px; margin-top: 16px; }

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 11px 18px;
    border-radius: 11px;
    border: 1px solid transparent;
    font: inherit;
    font-size: 14.5px;
    font-weight: 650;
    cursor: pointer;
    transition: transform .1s, box-shadow .15s, background .15s, opacity .15s;
}

.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.btn-primary {
    flex: 1;
    background: linear-gradient(135deg, var(--accent), var(--accent-2));
    color: #fff;
    box-shadow: 0 10px 22px -14px var(--accent);
}
.btn-primary:hover:not(:disabled) { box-shadow: 0 14px 26px -14px var(--accent); }

.btn-dark {
    flex: 1;
    background: var(--ink);
    color: #fff;
}
.btn-dark:hover:not(:disabled) { background: #1f2937; }

.btn-ghost {
    background: #fff;
    border-color: var(--line);
    color: var(--ink);
}
.btn-ghost:hover { background: #f6f8fd; border-color: #cbd3e1; }

.btn-sm { padding: 6px 12px; font-size: 13px; border-radius: 9px; }

.btn-danger { color: var(--danger); border-color: #fecaca; background: #fff; }
.btn-danger:hover:not(:disabled) { background: #fef2f2; border-color: #fca5a5; }

.row-actions { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }

.inline-form { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin: 0; }
.inline-form input[type="number"] { width: 100px; padding: 6px 9px; font-size: 13.5px; }

.log-note {
    display: flex;
    gap: 10px;
    align-items: flex-start;
    margin-top: 16px;
    padding: 11px 12px;
    border-radius: 12px;
    background: #f1f5f9;
    color: #475569;
    font-size: 12.8px;
}
.log-note svg { flex: none; margin-top: 2px; color: var(--accent); }

/* ---------- footer / toasts ---------- */
/* ---------- admin login ---------- */
.auth-body {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 30px 18px;
}

.auth-card {
    width: 100%;
    max-width: 400px;
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 20px;
    box-shadow: var(--shadow);
    padding: 30px 28px 24px;
}

.auth-brand { text-align: center; margin-bottom: 22px; }

.auth-brand img { border-radius: 14px; box-shadow: 0 12px 26px -16px rgba(79, 70, 229, .95); }

.auth-brand h1 {
    margin: 12px 0 2px;
    font-size: 26px;
    letter-spacing: -.03em;
}

.auth-brand p { margin: 0; color: var(--muted); font-size: 14px; }

.auth-card .field + .field { margin-top: 14px; }

.auth-error {
    margin-bottom: 16px;
    padding: 10px 12px;
    border-radius: 10px;
    background: #fef2f2;
    border: 1px solid #fecaca;
    color: #b91c1c;
    font-size: 13.5px;
    font-weight: 600;
}

.auth-btn { width: 100%; margin-top: 20px; }

.auth-note {
    margin: 18px 0 0;
    text-align: center;
    color: var(--muted);
    font-size: 12.5px;
}

.auth-back {
    display: block;
    margin-top: 14px;
    text-align: center;
    color: var(--muted);
    font-size: 13.5px;
    font-weight: 600;
}

.auth-back:hover { color: var(--accent); }

.toasts {
    position: fixed;
    right: 18px;
    bottom: 18px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    z-index: 60;
}

.toast {
    background: var(--ink);
    color: #fff;
    padding: 11px 15px;
    border-radius: 11px;
    font-size: 13.5px;
    box-shadow: 0 16px 30px -18px rgba(0, 0, 0, .8);
    animation: pop .2s ease;
    max-width: 340px;
}

.toast.error { background: #b91c1c; }
.toast.success { background: #15803d; }

@keyframes pop { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ---------- logs page ---------- */
.stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 14px;
    margin-bottom: 20px;
}

.stat {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 15px 16px;
    box-shadow: var(--shadow);
}

.stat b { display: block; font-size: 26px; letter-spacing: -.03em; }
.stat span { color: var(--muted); font-size: 12.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; }

.toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
    margin-bottom: 14px;
}

.toolbar select, .toolbar input { width: auto; min-width: 150px; }

.table-wrap {
    overflow: auto;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: var(--card);
}

table { width: 100%; border-collapse: collapse; font-size: 13.5px; }

th, td { text-align: left; padding: 11px 13px; border-bottom: 1px solid var(--line); vertical-align: top; }

th {
    background: #f8fafc;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: var(--muted);
    position: sticky;
    top: 0;
}

tbody tr:hover { background: #fafbff; }
tbody tr:last-child td { border-bottom: 0; }

td .payload {
    display: block;
    max-width: 340px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-family: var(--mono);
    font-size: 12.5px;
    color: #334155;
}

td.serial {
    font-family: var(--mono);
    font-size: 12.5px;
    color: #64748b;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
    width: 54px;
}

.badge {
    display: inline-block;
    padding: 2px 9px;
    border-radius: 999px;
    font-size: 11.5px;
    font-weight: 700;
}

.badge.generate { background: #eef2ff; color: #3730a3; }
.badge.download { background: #dcfce7; color: #166534; }

.pager { display: flex; gap: 10px; align-items: center; justify-content: space-between; margin-top: 14px; }

.empty { padding: 34px; text-align: center; color: var(--muted); }

@media (max-width: 1020px) {
    .grid { grid-template-columns: minmax(0, 1fr); }
    .preview-card { position: static; }
    .shape-group { grid-template-columns: 1fr; gap: 7px; }
}

@media (max-width: 620px) {
    .row { grid-template-columns: 1fr; }
    .tab span { display: none; }
    .tab { padding: 10px; }
    .topbar { padding: 12px 16px; }
    .card { padding: 16px; }
}
