:root {
    --page-bg: #eef7ff;
    --panel-bg: rgba(255, 255, 255, 0.88);
    --panel-border: rgba(71, 127, 180, 0.16);
    --ink-strong: #17385c;
    --ink-muted: #5f7e9c;
    --accent: #4f97d1;
    --accent-soft: #d9ecfb;
    --line-soft: rgba(71, 127, 180, 0.1);
    --paper: #ffffff;
    --shadow-soft: 0 20px 60px rgba(53, 102, 153, 0.14);
    --sheet-width: 210mm;
    --sheet-height: 297mm;
    --sheet-padding-x: 9.75mm;
    --sheet-padding-y: 10.7mm;
    --label-width: 38.1mm;
    --label-height: 21.2mm;
    --sheet-columns: 5;
    --footer-height: 42px;
    --footer-figure-width: 150px;
    --footer-bg: #050505;
    --footer-border: rgba(255, 255, 255, 0.16);
    --footer-link-color: #ffffff;
    --remove-tint: rgba(122, 18, 34, 0.28);
    --remove-slot: rgba(180, 184, 194, 0.75);
    --remove-slot-border: rgba(130, 136, 148, 0.95);
}

* {
    box-sizing: border-box;
}

html {
    font-size: 16px;
}

body {
    margin: 0;
    min-height: 100vh;
    padding-bottom: calc(var(--footer-height) + 0.75rem);
    font-family: "Trebuchet MS", "Segoe UI", sans-serif;
    color: var(--ink-strong);
    background:
        radial-gradient(circle at top left, rgba(123, 187, 233, 0.28), transparent 26%),
        radial-gradient(circle at bottom right, rgba(208, 236, 255, 0.85), transparent 32%),
        linear-gradient(135deg, #f9fcff 0%, #e2f1ff 100%);
}

body[data-theme="dark"] {
    --page-bg: #09131f;
    --panel-bg: rgba(12, 23, 39, 0.84);
    --panel-border: rgba(106, 162, 212, 0.18);
    --ink-strong: #e7f3ff;
    --ink-muted: #a3bfd8;
    --accent: #77bfff;
    --accent-soft: rgba(119, 191, 255, 0.14);
    --line-soft: rgba(140, 195, 245, 0.12);
    --paper: #ffffff;
    --shadow-soft: 0 22px 70px rgba(0, 0, 0, 0.38);
    background:
        radial-gradient(circle at top left, rgba(50, 109, 168, 0.34), transparent 24%),
        radial-gradient(circle at bottom right, rgba(18, 40, 69, 0.75), transparent 30%),
        linear-gradient(135deg, #08111c 0%, #0e2238 100%);
}

    body.remove-mode {
        --panel-bg: rgba(48, 13, 20, 0.9);
        --panel-border: rgba(231, 105, 123, 0.24);
        --ink-strong: #fff0f2;
        --ink-muted: #e4bbc2;
        --accent: #ff8a98;
        --accent-soft: rgba(255, 138, 152, 0.18);
        --line-soft: rgba(230, 112, 128, 0.16);
        --shadow-soft: 0 22px 70px rgba(46, 7, 14, 0.44);
        background:
            radial-gradient(circle at top left, rgba(206, 78, 98, 0.34), transparent 24%),
            radial-gradient(circle at bottom right, rgba(113, 21, 34, 0.74), transparent 30%),
            linear-gradient(135deg, #21080d 0%, #3e1118 100%);
    }

body::before {
    content: "";
    position: fixed;
    inset: 0;
    background-image: linear-gradient(rgba(79, 151, 209, 0.05) 1px, transparent 1px), linear-gradient(90deg, rgba(79, 151, 209, 0.05) 1px, transparent 1px);
    background-size: 32px 32px;
    mask-image: radial-gradient(circle at center, black 40%, transparent 90%);
    pointer-events: none;
}

body[data-theme="dark"]::before {
    background-image: linear-gradient(rgba(122, 188, 245, 0.06) 1px, transparent 1px), linear-gradient(90deg, rgba(122, 188, 245, 0.06) 1px, transparent 1px);
}

body.remove-mode::before {
    background-image: linear-gradient(rgba(241, 130, 146, 0.07) 1px, transparent 1px), linear-gradient(90deg, rgba(241, 130, 146, 0.07) 1px, transparent 1px);
}

body.remove-mode,
body.remove-mode * {
    cursor: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='32' height='32' viewBox='0 0 32 32'%3E%3Cpath fill='%23ffb0ba' d='M21.6 3.2l7.2 7.2c.9.9.9 2.4 0 3.3L15 27.5c-.5.5-1.1.8-1.8.9l-6.7.8.8-6.7c.1-.7.4-1.3.9-1.8L22 3.2c.9-.9 2.4-.9 3.3 0z'/%3E%3Cpath fill='%239a2738' d='M23.7 5.3l3 3-14.8 14.8-3.6.4.4-3.6z'/%3E%3Cpath fill='%23ffffff' d='M5.4 27.6h10.2v2H5.4z'/%3E%3C/svg%3E") 4 28, auto !important;
}

.app-shell {
    position: relative;
    display: grid;
    grid-template-columns: minmax(380px, 450px) minmax(0, 1fr);
    gap: 2rem;
    padding: 2rem 2rem 0;
}

.app-footer {
    position: fixed;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    min-height: var(--footer-height);
    padding: 0.35rem calc(var(--footer-figure-width)) 0.35rem 1rem;
    color: #eaf6ff;
    background: var(--footer-bg);
    border-top: 1px solid var(--footer-border);
    box-shadow: 0 -18px 42px rgba(0, 0, 0, 0.28);
}

.footer-figure {
    position: fixed;
    right: 0.7rem;
    bottom: -2rem;
    z-index: 21;
    width: var(--footer-figure-width);
    height: auto;
    pointer-events: none;
    filter: drop-shadow(0 16px 24px rgba(0, 0, 0, 0.28));
}

.footer-slot {
    margin: 0;
    min-width: 0;
    font-size: 0.8rem;
    line-height: 1.2;
}

.footer-link {
    color: var(--footer-link-color);
    font-weight: 800;
    text-decoration: none;
    transition: opacity 180ms ease, transform 180ms ease;
}

.footer-link:hover,
.footer-link:focus-visible {
    opacity: 0.84;
}

.footer-link:focus-visible,
.theme-toggle:focus-visible {
    outline: 2px solid rgba(255, 255, 255, 0.8);
    outline-offset: 4px;
}

.control-panel,
.preview-header {
    backdrop-filter: blur(14px);
}

.control-panel {
    position: sticky;
    top: 2rem;
    align-self: start;
    display: grid;
    gap: 1.5rem;
    padding: 1.75rem;
    border: 1px solid var(--panel-border);
    border-radius: 28px;
    background: var(--panel-bg);
    box-shadow: var(--shadow-soft);
}

.theme-switcher {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.85rem 1rem;
    border-radius: 18px;
    background: rgba(255, 255, 255, 0.55);
    border: 1px solid var(--panel-border);
}

body[data-theme="dark"] .theme-switcher {
    background: rgba(255, 255, 255, 0.04);
}

body.remove-mode .theme-switcher,
body.remove-mode .sheet-specs div,
body.remove-mode .preview-header,
body.remove-mode .sheet-stage {
    background: rgba(255, 255, 255, 0.04);
}

.theme-switcher-label {
    font-size: 0.92rem;
    font-weight: 700;
}

.theme-toggle {
    padding: 0;
    border-radius: 999px;
    background: transparent;
    box-shadow: none;
}

.theme-toggle-track {
    display: flex;
    align-items: center;
    width: 54px;
    padding: 3px;
    border-radius: 999px;
    background: rgba(79, 151, 209, 0.2);
    box-shadow: inset 0 0 0 1px rgba(79, 151, 209, 0.22);
    transition: background 180ms ease, box-shadow 180ms ease;
}

body[data-theme="dark"] .theme-toggle-track {
    background: rgba(119, 191, 255, 0.18);
    box-shadow: inset 0 0 0 1px rgba(119, 191, 255, 0.26);
}

.theme-toggle-thumb {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: #ffffff;
    box-shadow: 0 3px 10px rgba(24, 60, 95, 0.2);
    transform: translateX(0);
    transition: transform 180ms ease, background 180ms ease;
}

.theme-toggle[aria-checked="true"] .theme-toggle-thumb {
    transform: translateX(26px);
    background: #d5ebff;
}

.remove-action {
    color: #ffffff;
    background: linear-gradient(135deg, #8f2636 0%, #b8394d 100%);
    box-shadow: 0 12px 28px rgba(132, 29, 45, 0.24);
}

body.remove-mode .remove-action {
    background: linear-gradient(135deg, #bf3348 0%, #e14b61 100%);
    box-shadow: 0 12px 28px rgba(177, 43, 64, 0.34);
}

.eyebrow {
    margin: 0 0 0.4rem;
    font-family: "Consolas", "Courier New", monospace;
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    color: var(--accent);
}

.brand-block h1,
.preview-header h2 {
    margin: 0;
    font-size: clamp(1.8rem, 2vw, 2.5rem);
    line-height: 1;
}

.panel-copy,
.preview-summary {
    margin: 0.75rem 0 0;
    color: var(--ink-muted);
    line-height: 1.6;
}

.generator-form {
    display: grid;
    gap: 1rem;
}

.field {
    display: grid;
    gap: 0.45rem;
}

.field span {
    font-size: 0.92rem;
    font-weight: 700;
}

.field input {
    width: 100%;
    border: 1px solid rgba(79, 151, 209, 0.18);
    border-radius: 16px;
    padding: 0.9rem 1rem;
    font: inherit;
    color: var(--ink-strong);
    background: rgba(255, 255, 255, 0.94);
    transition: border-color 180ms ease, transform 180ms ease, box-shadow 180ms ease;
}

body[data-theme="dark"] .field input {
    background: rgba(8, 18, 31, 0.76);
}

.field input:focus {
    outline: none;
    border-color: rgba(79, 151, 209, 0.72);
    box-shadow: 0 0 0 4px rgba(79, 151, 209, 0.16);
    transform: translateY(-1px);
}

.actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
    margin-top: 0.35rem;
}

button {
    appearance: none;
    border: 0;
    border-radius: 999px;
    padding: 0.95rem 1.15rem;
    font: inherit;
    font-weight: 800;
    cursor: pointer;
    transition: transform 180ms ease, box-shadow 180ms ease, opacity 180ms ease;
}

button:hover {
    transform: translateY(-1px);
}

button:active {
    transform: translateY(0);
}

.primary-action {
    color: #ffffff;
    background: linear-gradient(135deg, #4a90cb 0%, #76b7ea 100%);
    box-shadow: 0 14px 30px rgba(79, 151, 209, 0.24);
}

.secondary-action {
    color: var(--ink-strong);
    background: rgba(255, 255, 255, 0.96);
    box-shadow: inset 0 0 0 1px rgba(79, 151, 209, 0.16);
}

body[data-theme="dark"] .secondary-action {
    background: rgba(255, 255, 255, 0.08);
    box-shadow: inset 0 0 0 1px rgba(122, 188, 245, 0.14);
}

.primary-action:disabled {
    color: #f3f3f3;
    background: linear-gradient(135deg, #777777 0%, #9a9a9a 100%);
    box-shadow: 0 10px 24px rgba(70, 70, 70, 0.18);
}

.secondary-action:disabled {
    color: #f3f3f3;
    background: rgba(128, 128, 128, 0.32);
    box-shadow: inset 0 0 0 1px rgba(210, 210, 210, 0.18);
}

button:disabled {
    cursor: not-allowed;
    opacity: 0.88;
    transform: none;
}

button:disabled:hover,
button:disabled:active {
    transform: none;
}

body.remove-mode:not([data-theme="dark"]) .field input {
    color: #ffffff;
}

.sheet-specs {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    margin: 0;
}

.sheet-specs div {
    padding: 0.9rem 1rem;
    border-radius: 18px;
    background: rgba(242, 249, 255, 0.88);
    border: 1px solid rgba(79, 151, 209, 0.1);
}

body[data-theme="dark"] .sheet-specs div {
    background: rgba(255, 255, 255, 0.04);
}

.sheet-specs dt {
    margin-bottom: 0.35rem;
    font-size: 0.78rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--ink-muted);
}

.sheet-specs dd {
    margin: 0;
    font-weight: 700;
}

.spec-select {
    width: 100%;
    border: 1px solid rgba(79, 151, 209, 0.18);
    border-radius: 12px;
    padding: 0.72rem 0.9rem;
    font: inherit;
    font-weight: 700;
    color: var(--ink-strong);
    background: rgba(255, 255, 255, 0.92);
    cursor: pointer;
    transition: border-color 180ms ease, box-shadow 180ms ease, background 180ms ease;
}

body[data-theme="dark"] .spec-select,
body.remove-mode .spec-select {
    background: rgba(10, 18, 29, 0.82);
}

body.remove-mode:not([data-theme="dark"]) .spec-select {
    color: #ffffff;
}

.spec-select:focus {
    outline: none;
    border-color: rgba(79, 151, 209, 0.72);
    box-shadow: 0 0 0 4px rgba(79, 151, 209, 0.16);
}

.preview-area {
    display: grid;
    gap: 1rem;
    min-width: 0;
}

.preview-header {
    display: flex;
    align-items: end;
    justify-content: space-between;
    gap: 1rem;
    padding: 1.25rem 1.4rem;
    border-radius: 24px;
    background: rgba(255, 255, 255, 0.72);
    border: 1px solid rgba(79, 151, 209, 0.12);
}

body[data-theme="dark"] .preview-header {
    background: rgba(255, 255, 255, 0.05);
}

.sheet-stage {
    overflow: auto;
    padding: 1.5rem;
    border-radius: 32px;
    border: 1px solid rgba(79, 151, 209, 0.12);
    background: rgba(255, 255, 255, 0.68);
    box-shadow: var(--shadow-soft);
}

body[data-theme="dark"] .sheet-stage {
    background: rgba(255, 255, 255, 0.04);
}

.sheet-stack {
    display: grid;
    justify-items: start;
    gap: 1.5rem;
}

.label-sheet {
    width: var(--sheet-width);
    min-width: var(--sheet-width);
    min-height: var(--sheet-height);
    padding: var(--sheet-padding-y) var(--sheet-padding-x);
    display: grid;
    grid-template-columns: repeat(var(--sheet-columns), var(--label-width));
    grid-auto-rows: var(--label-height);
    gap: 0;
    background: var(--paper);
    box-shadow: 0 30px 90px rgba(79, 151, 209, 0.16);
    transform-origin: top left;
    animation: none;
}

body.remove-mode .label-sheet {
    box-shadow: 0 30px 90px rgba(123, 28, 44, 0.26);
}

.label-card {
    display: grid;
    grid-template-rows: auto auto 1fr;
    align-items: start;
    align-content: start;
    justify-items: center;
    width: var(--label-width);
    height: var(--label-height);
    padding: 1.1mm 1.35mm 0.85mm;
    row-gap: 0.05mm;
    border-radius: 2.2mm;
    overflow: hidden;
    text-align: center;
    color: #111111;
}

.label-card.has-qr {
    grid-template-rows: auto auto 1fr;
    padding-top: 0.8mm;
    row-gap: 0.2mm;
}

body.remove-mode .label-card {
    box-shadow: inset 0 0 0 1px rgba(255, 148, 162, 0.12);
    transition: opacity 150ms ease, background 140ms ease, box-shadow 140ms ease, transform 140ms ease;
}

body.remove-mode .label-card:hover {
    background: rgba(166, 48, 68, 0.18);
    box-shadow: inset 0 0 0 1px rgba(255, 182, 191, 0.42);
}

body.remove-mode .label-card.is-fading-out {
    opacity: 0.18;
    transform: scale(0.985);
}

.label-company,
.label-tag {
    margin: 0;
    width: 100%;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.1;
}

.label-company {
    font-size: 2.05mm;
    font-weight: 700;
    letter-spacing: 0.02em;
    color: #111111;
}

.label-tag {
    margin-top: 0;
    font-size: 4.15mm;
    font-weight: 800;
    line-height: 1;
    color: #111111;
}

.label-barcode {
    display: grid;
    place-items: center;
    align-self: stretch;
    margin-top: 0;
    width: 100%;
    height: 100%;
}

.label-barcode svg,
.label-barcode canvas {
    display: block;
    max-width: 100%;
    max-height: 100%;
}

.label-barcode svg {
    width: 100%;
    height: 100%;
    margin-inline: auto;
}

.label-card.has-qr .label-company {
    font-size: 1.95mm;
}

.label-card.has-qr .label-tag {
    margin-top: 0;
    font-size: 3.15mm;
    line-height: 1;
}

.label-card.has-qr[data-sheet-type="L7659"] {
    grid-template-rows: auto auto 1fr;
    padding: 0.7mm 1mm 0.85mm;
    row-gap: 0.2mm;
}

.label-card.has-qr[data-sheet-type="L7659"] .label-company {
    font-size: 1.95mm;
}

.label-card.has-qr[data-sheet-type="L7659"] .label-tag {
    font-size: 3.35mm;
}

.label-card.has-qr[data-sheet-type="L7659"] .label-barcode {
    align-self: center;
    justify-self: center;
    display: grid;
    place-items: center;
    width: min(100%, 23.8mm);
    height: min(calc(var(--label-height) - 5.8mm), 23.8mm);
    margin-top: 0;
    padding: 0.35mm;
    border-radius: 1.6mm;
    background: #ffffff;
}

.label-card.has-qr[data-sheet-type="L7659"] .label-barcode canvas {
    width: 100%;
    height: 100%;
    image-rendering: pixelated;
}

.label-card.has-qr:not([data-sheet-type="L7659"]) {
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-rows: auto auto;
    grid-template-areas:
        "company barcode"
        "tag barcode";
    align-items: center;
    justify-items: stretch;
    padding: 0.3mm 0.08mm 0.3mm 0.9mm;
    column-gap: 0.45mm;
    row-gap: 0.1mm;
    text-align: left;
}

.label-card.has-qr:not([data-sheet-type="L7659"]) .label-company {
    grid-area: company;
    align-self: end;
    width: 100%;
    font-size: 2.05mm;
    line-height: 1;
}

.label-card.has-qr:not([data-sheet-type="L7659"]) .label-tag {
    grid-area: tag;
    align-self: start;
    width: 100%;
    font-size: 3.75mm;
    line-height: 0.98;
}

.label-card.has-qr:not([data-sheet-type="L7659"]) .label-barcode {
    grid-area: barcode;
    align-self: stretch;
    justify-self: end;
    display: grid;
    place-items: center;
    width: min(calc(var(--label-width) * 0.5), calc(var(--label-height) - 0.7mm));
    height: min(calc(var(--label-width) * 0.5), calc(var(--label-height) - 0.7mm));
    margin: 0;
    padding: 0.12mm;
    border-radius: 1.1mm;
    background: #ffffff;
}

.label-card.has-qr[data-sheet-type="L4614"] .label-barcode {
    width: min(calc(var(--label-width) * 0.46), calc(var(--label-height) - 0.7mm));
    height: min(calc(var(--label-width) * 0.46), calc(var(--label-height) - 0.7mm));
}

.label-card.has-qr:not([data-sheet-type="L7659"]) .label-barcode canvas {
    width: 100%;
    height: 100%;
    image-rendering: pixelated;
}

.label-barcode text {
    display: none;
}

.label-card.is-missing {
    position: relative;
    background: linear-gradient(180deg, rgba(223, 227, 234, 0.9) 0%, rgba(195, 201, 211, 0.9) 100%);
    box-shadow: inset 0 0 0 1px rgba(142, 148, 160, 0.95);
}

.label-card.is-missing .label-company,
.label-card.is-missing .label-tag,
.label-card.is-missing .label-barcode {
    visibility: hidden;
}

.label-card.is-missing::after {
    content: "Missing";
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    font-size: 2.2mm;
    font-weight: 800;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: rgba(96, 102, 112, 0.92);
}

body.remove-mode .label-card.is-missing {
    background: linear-gradient(180deg, rgba(208, 212, 220, 0.92) 0%, rgba(178, 184, 194, 0.92) 100%);
    box-shadow: inset 0 0 0 1px var(--remove-slot-border), 0 0 0 1px rgba(255, 186, 196, 0.24);
}

.is-invalid {
    border-color: #c45858;
    box-shadow: 0 0 0 4px rgba(196, 88, 88, 0.12);
}

@keyframes sheet-arrival {
    from {
        opacity: 0;
        transform: translateY(18px) scale(0.985);
    }

    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

@media (max-width: 1180px) {
    .app-shell {
        grid-template-columns: 1fr;
    }

    .control-panel {
        position: static;
    }

    .preview-header {
        align-items: start;
        flex-direction: column;
    }

    .app-footer {
        justify-content: center;
        text-align: center;
        padding-right: calc(var(--footer-figure-width) + 1.25rem);
    }

    .footer-figure {
        right: 0.25rem;
    }

    .footer-link {
        margin-left: auto;
    }
}

@media (max-width: 720px) {
    .app-shell {
        padding: 1rem;
        gap: 1rem;
    }

    .control-panel,
    .preview-header,
    .sheet-stage {
        border-radius: 22px;
    }

    .actions,
    .sheet-specs {
        grid-template-columns: 1fr;
    }

    .sheet-stage {
        padding: 0.8rem;
    }

    .sheet-stack {
        gap: 0.8rem;
    }

    .app-footer {
        padding: 0.55rem 1rem calc(0.55rem + env(safe-area-inset-bottom));
    }

    .footer-figure {
        right: 0.2rem;
    }
}

@page {
    size: A4 portrait;
    margin: 0;
}

@media print {
    :root {
        --sheet-width: 210mm;
        --sheet-height: 297mm;
    }

    html,
    body {
        margin: 0;
        padding: 0;
        min-height: auto;
        background: #ffffff;
        overflow: visible;
    }

    body::before,
    .no-print,
    .footer-figure {
        display: none !important;
    }

    .app-shell,
    .preview-area,
    .sheet-stage,
    .sheet-stack {
        display: block;
        padding: 0;
        margin: 0;
        border: 0;
        box-shadow: none;
        background: transparent;
    }

    .label-sheet {
        width: 210mm;
        min-width: 210mm;
        min-height: 297mm;
        padding: var(--sheet-padding-y) var(--sheet-padding-x);
        box-shadow: none;
        animation: none;
        break-after: auto;
        page-break-after: auto;
    }

    .label-card {
        border-radius: 0;
        box-shadow: none;
    }

    .label-card.is-missing {
        background: transparent;
        box-shadow: none;
    }

    .label-card.is-missing::after {
        display: none;
    }

    .label-sheet:not(:last-child) {
        break-after: page;
        page-break-after: always;
    }
}
