:root {
    --bg: #eef2f7;
    --ink: #111827;
    --brand: #1d4ed8;
    --brand-soft: #dbeafe;
    --btn-secondary: #6b7280;
    --btn-disabled: #9ca3af;
    --muted: #4b5563;
    --card: #ffffff;
    --line: #cfd8e3;
    --hero-h: 72px;
    --footer-h: 44px;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    height: 100dvh;
    font-family: "Trebuchet MS", Verdana, sans-serif;
    color: var(--ink);
    background: var(--bg);
    overflow: hidden;
}

.hero {
    padding: 0.85rem 1rem 0.65rem;
    border-bottom: 1px solid var(--line);
    background: #f8fafc;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 1200;
}

.compact-hero {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.8rem;
}

.hero-actions {
    display: flex;
    align-items: center;
    gap: 0.45rem;
}

h1 {
    margin: 0;
    font-size: clamp(1.65rem, 6vw, 2.2rem);
    line-height: 1;
}

.subtitle {
    margin: 0.25rem 0 0;
    max-width: 34rem;
    color: var(--muted);
}

.icon-btn {
    min-width: 42px;
    width: 42px;
    height: 42px;
    padding: 0;
    font-size: 1.25rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.container {
    margin-top: var(--hero-h);
    height: calc(100dvh - var(--hero-h) - var(--footer-h));
    overflow-y: auto;
    overscroll-behavior-y: contain;
    padding: 0.75rem 1rem 1rem;
    display: grid;
    align-content: start;
    gap: 0.75rem;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
}

.event-headline {
    padding: 0.1rem 0.2rem 0;
}

.event-title {
    margin: 0;
    text-align: center;
    line-height: 1.2;
}

.event-title-main {
    font-size: 1.5rem;
    font-weight: 800;
    color: var(--ink);
}

.event-title-sub {
    margin-top: 0.18rem;
    font-size: 1.4rem;
    color: var(--muted);
}

.single-column {
    grid-template-columns: minmax(280px, 760px);
    justify-content: center;
    align-content: start;
    row-gap: 0.34rem;
}

.card {
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 1rem;
    background: var(--card);
    box-shadow: 0 3px 12px rgba(17, 24, 39, 0.08);
}

.card h2 {
    margin-top: 0;
    font-size: 1.1rem;
}

.field-label {
    display: block;
    margin: 0.65rem 0 0.25rem;
    font-weight: 700;
    font-size: 0.92rem;
}

.field {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 0.55rem 0.65rem;
    font: inherit;
    background: #fff;
}

.color-control {
    display: grid;
    grid-template-columns: 3.2rem minmax(0, 1fr);
    gap: 0.6rem;
    align-items: center;
}

.color-swatch-input {
    width: 3.2rem;
    height: 2.65rem;
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 0.22rem;
    background: #fff;
    cursor: pointer;
}

.color-swatch-input::-webkit-color-swatch-wrapper {
    padding: 0;
}

.color-swatch-input::-webkit-color-swatch {
    border: 0;
    border-radius: 7px;
}

.color-swatch-input::-moz-color-swatch {
    border: 0;
    border-radius: 7px;
}

.color-hex-input {
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

textarea.field {
    resize: vertical;
}

.row {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
}

.choice-grid {
    display: grid;
    gap: 0.65rem;
    grid-template-columns: repeat(2, minmax(120px, 1fr));
}

.category-tabs-wrap {
    margin-top: 0.25rem;
    margin-bottom: 0;
    position: relative;
    z-index: 2;
}

.category-tabs {
    display: flex;
    align-items: flex-end;
    gap: 0.4rem;
    position: relative;
    padding: 0;
    border-bottom: 0;
}

.category-tabs-wrap+.card {
    margin-top: -7px;
    padding-top: 1rem;
    border-width: 5px;
    border-top-left-radius: 0;
    border-top-right-radius: 0;
    border-color: var(--brand);
    position: relative;
    z-index: 2;
}

.category-tabs::after {
    content: none;
}

.choice-btn {
    min-height: 78px;
    font-size: 1.1rem;
}

.category-tabs .tab-btn {
    flex: 1 1 0;
    border-radius: 12px 12px 0 0;
    min-height: 52px;
    height: 52px;
    margin: 0;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    background: var(--btn-secondary);
    color: #e5e7eb;
    font-weight: 780;
    font-size: 1.1rem;
    border: 1px solid color-mix(in srgb, var(--btn-secondary) 64%, #0f172a 36%);
    border-bottom-color: color-mix(in srgb, var(--brand) 62%, var(--line) 38%);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08);
    position: relative;
    z-index: 1;
    transform: none;
    filter: none;
    transition: background-color 120ms ease, color 120ms ease, border-color 120ms ease;
}

.category-tabs .tab-btn:not(:disabled):hover {
    transform: none;
    filter: none;
}

.category-tabs .tab-btn:focus,
.category-tabs .tab-btn:focus-visible {
    outline: none;
    box-shadow: none;
    transform: none;
    filter: none;
}

.category-tabs .tab-btn::-moz-focus-inner {
    border: 0;
}

.tab-btn+.tab-btn {
    border-left: 1px solid color-mix(in srgb, var(--line) 35%, transparent 65%);
}

.category-tabs .tab-btn.is-active {
    background: var(--brand);
    color: #fff;
    font-weight: 780;
    border-color: var(--brand);
    border-bottom-color: var(--brand);
    box-shadow: none;
    z-index: 1;
    transform: none;
    filter: none;
}

.category-tabs .tab-btn.is-active:focus,
.category-tabs .tab-btn.is-active:focus-visible {
    filter: none;
}

.field-label input[type="checkbox"] {
    margin-right: 0.5rem;
    transform: translateY(1px);
}

.product-grid {
    margin-top: 0.75rem;
}

.radio-inline {
    font-size: 0.95rem;
}

.reconnect-status {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    margin: 0.4rem 0 0.8rem;
}

.reconnect-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    display: inline-block;
    flex: 0 0 auto;
    position: relative;
}

.state-trying {
    background: #22c55e;
    box-shadow: 0 0 0 1px rgba(15, 23, 42, 0.12), 0 0 4px rgba(34, 197, 94, 0.35);
    animation: blink-fast 1s step-start infinite;
}

.state-connected {
    background: #22c55e;
    box-shadow: 0 0 0 1px rgba(15, 23, 42, 0.12), 0 0 5px rgba(34, 197, 94, 0.4);
    animation: none;
}

.state-manual {
    background: var(--btn-disabled);
    animation: blink-fast 1s step-start infinite;
}

@keyframes blink-fast {
    50% {
        opacity: 0.2;
    }
}

.status-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.status-list li {
    display: flex;
    justify-content: space-between;
    border-bottom: 1px dashed var(--line);
    padding: 0.55rem 0;
}

.status-list li:last-child {
    border-bottom: 0;
}

.btn {
    appearance: none;
    border: 0;
    border-radius: 10px;
    background: var(--brand);
    color: white;
    padding: 0.68rem 1rem;
    font-weight: 700;
    cursor: pointer;
    transition: transform 140ms ease, filter 140ms ease;
}

.btn-secondary {
    background: var(--btn-secondary);
}

.btn:disabled {
    background: var(--btn-disabled);
    cursor: not-allowed;
}

.btn:not(:disabled):hover {
    transform: translateY(-1px);
    filter: brightness(1.05);
}

.card .btn+.btn {
    margin-left: 0.5rem;
}

.category-tabs .btn+.btn {
    margin-left: 0;
}

.card .field+.btn,
.card .row+.field-label,
.card .field+.field-label {
    margin-top: 0.65rem;
}

.settings-actions {
    margin-top: 0.75rem;
}

.printer-app-actions {
    display: grid;
    gap: 0.55rem;
    margin-top: 0.6rem;
}

.printer-app-actions .btn {
    width: 100%;
}

.card .printer-app-actions .btn+.btn {
    margin-left: 0;
}

.split-line {
    border: 0;
    border-top: 1px dashed var(--line);
    margin: 1rem 0;
}

.scan-modal {
    position: fixed;
    inset: 0;
    background: rgba(10, 15, 13, 0.82);
    display: none;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    z-index: 2100;
}

.scan-modal.is-open {
    display: flex;
}

.scan-card {
    width: min(520px, 100%);
    border: 1px solid var(--line);
    border-radius: 16px;
    background: #fffef9;
    padding: 1rem;
}

#settings-modal .scan-card {
    max-height: calc(100dvh - 2rem);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.scan-video-wrap {
    position: relative;
}

#scan-video {
    width: 100%;
    border-radius: 10px;
    border: 1px solid var(--line);
    background: #0f1312;
    min-height: 240px;
}

.scan-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
    opacity: 0;
    transition: opacity 140ms ease;
}

.scan-overlay.is-visible {
    opacity: 1;
}

.scan-overlay-badge {
    width: 96px;
    height: 96px;
    border-radius: 999px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 3rem;
    font-weight: 800;
    color: #fff;
    box-shadow: 0 6px 22px rgba(15, 23, 42, 0.35);
}

.scan-overlay-icon {
    width: 56px;
    height: 56px;
    display: block;
}

.scan-overlay-ok {
    background: rgba(22, 163, 74, 0.9);
}

.scan-overlay-error {
    background: rgba(220, 38, 38, 0.9);
}

#scan-status.scan-status-ok {
    color: #15803d;
    font-weight: 700;
}

#scan-status.scan-status-error {
    color: #b91c1c;
    font-weight: 700;
}

#import-preview-list {
    margin-top: 0.75rem;
}

#import-preview-list li {
    align-items: baseline;
}

.diagnostics-output {
    margin: 0.75rem 0 0;
    padding: 0.75rem;
    max-height: 46vh;
    overflow: auto;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: #f8fafc;
    color: var(--ink);
    white-space: pre-wrap;
    word-break: break-word;
    font-size: 0.88rem;
    line-height: 1.35;
}

.hint {
    margin-top: 0.7rem;
    color: var(--muted);
    font-size: 0.95rem;
}

.printer-status-bar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    height: 44px;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0 0.8rem;
    border-top: 1px solid var(--line);
    background: #f8fafc;
    font-size: 0.88rem;
    z-index: 1100;
}

.printer-status-text {
    flex: 1;
    min-width: 0;
    color: var(--muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.footer-connect-btn {
    padding: 0.3rem 0.6rem;
    font-size: 0.8rem;
    line-height: 1;
    white-space: nowrap;
}

@media (max-width: 520px) {
    .compact-hero {
        flex-direction: row;
    }

    .choice-grid {
        grid-template-columns: 1fr;
    }

    .card .btn {
        width: 100%;
    }

    .card .btn+.btn {
        margin-left: 0;
        margin-top: 0.5rem;
    }

    .printer-status-bar {
        font-size: 0.82rem;
        gap: 0.4rem;
    }

    .footer-connect-btn {
        padding: 0.28rem 0.5rem;
        font-size: 0.76rem;
    }

    .container {
        grid-template-columns: 1fr;
    }
}