:root,
body[data-theme="dark"] {
    --bg: #071018;
    --surface: rgba(12, 22, 40, 0.88);
    --surface-strong: #0d1729;
    --surface2: rgba(18, 30, 52, 0.92);
    --surface3: #1e3358;
    --surface-accent: rgba(50, 92, 184, 0.14);
    --border: rgba(115, 144, 196, 0.2);
    --border2: rgba(115, 144, 196, 0.32);
    --blue: #6eb5ff;
    --blue-strong: #3d82f6;
    --cyan: #3ee0d0;
    --blue-glow: rgba(79, 134, 247, 0.28);
    --green: #3dd9a0;
    --amber: #ffbe4a;
    --red: #ff7b8a;
    --purple: #c084fc;
    --violet: #a78bfa;
    --emerald: #34d399;
    --text: #f5f7fb;
    --text2: #9eb0c9;
    --text3: #63748f;
    --shadow: 0 24px 60px rgba(2, 8, 23, 0.42);
    --page-gradient:
        radial-gradient(ellipse 80% 50% at 0% -10%, rgba(110, 181, 255, 0.22), transparent 55%),
        radial-gradient(ellipse 60% 40% at 100% 0%, rgba(62, 224, 208, 0.14), transparent 50%),
        radial-gradient(ellipse 50% 35% at 70% 100%, rgba(192, 132, 252, 0.12), transparent 45%),
        linear-gradient(180deg, #071018 0%, #050a12 100%);
}

body[data-theme="light"] {
    --bg: #edf3fb;
    --surface: rgba(255, 255, 255, 0.9);
    --surface-strong: #ffffff;
    --surface2: rgba(243, 247, 253, 0.96);
    --surface3: #dfeafb;
    --surface-accent: rgba(72, 112, 191, 0.1);
    --border: rgba(74, 101, 147, 0.16);
    --border2: rgba(74, 101, 147, 0.26);
    --blue: #1d5fd4;
    --blue-strong: #164fb3;
    --cyan: #0d9488;
    --blue-glow: rgba(36, 87, 197, 0.2);
    --green: #15803d;
    --amber: #b45309;
    --red: #be123c;
    --purple: #7e22ce;
    --violet: #6d28d9;
    --emerald: #047857;
    --text: #142033;
    --text2: #52627a;
    --text3: #7a889b;
    --shadow: 0 18px 48px rgba(81, 108, 149, 0.2);
    --page-gradient:
        radial-gradient(ellipse 80% 50% at 0% -10%, rgba(59, 130, 246, 0.2), transparent 55%),
        radial-gradient(ellipse 60% 40% at 100% 0%, rgba(13, 148, 136, 0.12), transparent 50%),
        radial-gradient(ellipse 50% 35% at 80% 100%, rgba(124, 58, 237, 0.1), transparent 45%),
        linear-gradient(180deg, #f4f8ff 0%, #e8f0fc 100%);
}

html,
body {
    background: var(--page-gradient);
    min-height: 100dvh;
}

body {
    position: relative;
    color: var(--text);
    transition: background 180ms ease, color 180ms ease;
    overscroll-behavior: none;
    touch-action: manipulation;
}

body::before,
body::after {
    content: "";
    position: fixed;
    inset: auto;
    width: 22rem;
    height: 22rem;
    border-radius: 50%;
    pointer-events: none;
    filter: blur(48px);
    opacity: 0.55;
    z-index: 0;
}

body::before {
    top: -8rem;
    right: -4rem;
    background: rgba(110, 181, 255, 0.22);
}

body::after {
    bottom: -10rem;
    left: -6rem;
    background: rgba(192, 132, 252, 0.16);
}

#auth-screen,
#app {
    position: relative;
    z-index: 1;
}

.app-shell {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    min-width: 0;
    overflow: hidden;
}

.setup-banner {
    margin-bottom: 0.25rem;
    align-items: center;
    background: linear-gradient(135deg, rgba(59, 130, 246, 0.16), rgba(62, 224, 208, 0.1));
    border-color: rgba(110, 181, 255, 0.35);
}

.setup-banner-icon {
    width: 2.5rem;
    height: 2.5rem;
    border-radius: 0.75rem;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    background: linear-gradient(135deg, rgba(110, 181, 255, 0.35), rgba(62, 224, 208, 0.25));
    color: var(--cyan);
}

.setup-banner-icon svg {
    width: 1.25rem;
    height: 1.25rem;
}

.topbar,
.sidebar,
.card,
.modal,
.mobile-nav,
.auth-card {
    backdrop-filter: blur(22px);
}

.topbar,
.sidebar,
.mobile-nav,
.card,
.modal,
.auth-card,
.tbl-wrap,
.stat,
.qa-card,
.conn-status {
    box-shadow: var(--shadow);
}

.topbar,
.sidebar,
.mobile-nav,
.card,
.modal,
.auth-card,
.tbl-wrap,
.stat,
.qa-card,
.conn-status {
    background: var(--surface);
    border-color: var(--border);
}

.topbar,
.mobile-nav {
    background: rgba(10, 19, 34, 0.74);
}

body[data-theme="light"] .topbar,
body[data-theme="light"] .mobile-nav {
    background: rgba(255, 255, 255, 0.9);
}

.sidebar {
    background: linear-gradient(180deg, rgba(10, 19, 34, 0.9), rgba(10, 19, 34, 0.78));
}

body[data-theme="light"] .sidebar {
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.96), rgba(245, 249, 255, 0.88));
}

.logo,
.sidebar-logo {
    font-family: "Fraunces", serif;
    font-size: 1.18rem;
    letter-spacing: -0.04em;
}

.logo span,
.sidebar-logo span {
    background: linear-gradient(135deg, var(--blue) 0%, var(--cyan) 100%);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}

.sidebar-logo {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.screen-head,
.setup-intro {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
}

.screen-copy,
.setup-copy {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    max-width: 42rem;
}

.page-kicker,
.section-label {
    color: var(--text3);
    text-transform: uppercase;
    letter-spacing: 0.16em;
    font-size: 0.68rem;
    font-weight: 700;
}

.page-eyebrow {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    width: fit-content;
    padding: 0.28rem 0.65rem;
    border-radius: 999px;
    font-size: 0.65rem;
    font-weight: 700;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    background: var(--surface-accent);
    border: 1px solid var(--border);
    color: var(--text2);
}

.page-eyebrow.accent-sky {
    color: var(--blue);
    background: rgba(110, 181, 255, 0.14);
    border-color: rgba(110, 181, 255, 0.28);
}

.page-eyebrow.accent-violet {
    color: var(--violet);
    background: rgba(167, 139, 250, 0.14);
    border-color: rgba(167, 139, 250, 0.28);
}

.page-eyebrow.accent-emerald {
    color: var(--emerald);
    background: rgba(52, 211, 153, 0.14);
    border-color: rgba(52, 211, 153, 0.28);
}

.page-eyebrow.accent-amber {
    color: var(--amber);
    background: rgba(255, 190, 74, 0.14);
    border-color: rgba(255, 190, 74, 0.28);
}

.section-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.section-label::before {
    content: "";
    width: 3px;
    height: 0.85rem;
    border-radius: 99px;
    background: linear-gradient(180deg, var(--blue), var(--cyan));
    flex-shrink: 0;
}

.card-title {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}

.card-title-icon,
.card-title [data-lucide] {
    width: 1rem;
    height: 1rem;
    color: var(--blue);
}

.page-title {
    font-family: "Fraunces", serif;
    font-size: clamp(1.5rem, 3.2vw, 2.2rem);
    line-height: 1.02;
    letter-spacing: -0.045em;
}

.page-subtitle {
    font-size: 0.96rem;
    color: var(--text2);
    max-width: 40rem;
}

.icon-badge,
.theme-toggle,
.surface-pill,
.summary-chip,
.catalog-pill,
.inline-icon {
    display: inline-flex;
    align-items: center;
    gap: 0.55rem;
}

.icon-badge {
    width: 3.25rem;
    height: 3.25rem;
    justify-content: center;
    border-radius: 1rem;
    background: linear-gradient(135deg, rgba(123, 176, 255, 0.24), rgba(56, 199, 147, 0.16));
    color: var(--blue);
    border: 1px solid rgba(123, 176, 255, 0.22);
}

.theme-toggle {
    min-width: 8.75rem;
}

.theme-toggle .theme-label {
    white-space: nowrap;
}

.surface-pill,
.summary-chip,
.catalog-pill {
    padding: 0.55rem 0.8rem;
    border-radius: 999px;
    background: var(--surface-accent);
    border: 1px solid var(--border);
    color: var(--text2);
    font-size: 0.78rem;
}

.product-summary .summary-chip:nth-child(1) {
    background: rgba(110, 181, 255, 0.14);
    border-color: rgba(110, 181, 255, 0.28);
    color: var(--blue);
}

.product-summary .summary-chip:nth-child(2) {
    background: rgba(62, 224, 208, 0.12);
    border-color: rgba(62, 224, 208, 0.26);
    color: var(--cyan);
}

.product-summary .summary-chip:nth-child(3) {
    background: rgba(52, 211, 153, 0.12);
    border-color: rgba(52, 211, 153, 0.26);
    color: var(--emerald);
}

.product-summary .summary-chip:nth-child(4) {
    background: rgba(255, 190, 74, 0.12);
    border-color: rgba(255, 190, 74, 0.26);
    color: var(--amber);
}

.product-summary .summary-chip strong {
    color: var(--text);
}

.summary-chip strong,
.catalog-pill strong {
    color: var(--text);
    font-size: 0.86rem;
}

.product-summary {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.toolbar-stack {
    display: flex;
    flex-direction: column;
    gap: 0.9rem;
}

.toolbar-actions,
.button-cluster {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.product-layout {
    display: grid;
    gap: 1rem;
}

.product-cards {
    display: none;
    gap: 0.9rem;
}

.product-card {
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 1rem;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.85rem;
}

.product-card-top,
.product-card-bottom,
.meta-grid {
    display: flex;
    justify-content: space-between;
    gap: 0.9rem;
    flex-wrap: wrap;
}

.product-name {
    font-size: 0.98rem;
    font-weight: 600;
    color: var(--text);
}

.product-subline,
.muted-copy,
.meta-label {
    color: var(--text2);
    font-size: 0.8rem;
}

.price-value {
    font-family: "JetBrains Mono", monospace;
    font-weight: 700;
    color: var(--blue);
}

.source-badge[data-source="zk"] {
    background: rgba(123, 176, 255, 0.18);
    color: var(--blue);
}

.source-badge[data-source="merged"] {
    background: rgba(56, 199, 147, 0.18);
    color: var(--green);
}

.source-badge[data-source="local"] {
    background: rgba(246, 180, 79, 0.16);
    color: var(--amber);
}

.table-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1rem 0;
    gap: 1rem;
    flex-wrap: wrap;
}

.action-cell,
.action-cluster {
    display: flex;
    gap: 0.4rem;
    align-items: center;
}

.btn,
.btn-icon,
.nav-tab,
.sidebar-btn,
.qa-card,
.btn-secondary,
.btn-primary,
.btn-success,
.btn-danger {
    transition: transform 140ms ease, border-color 140ms ease, background 140ms ease, box-shadow 140ms ease, color 140ms ease;
}

.btn:hover,
.btn-icon:hover,
.nav-tab:hover,
.sidebar-btn:hover,
.qa-card:hover {
    transform: translateY(-1px);
}

.btn-primary {
    background: linear-gradient(135deg, var(--blue-strong) 0%, var(--cyan) 120%);
    border: 1px solid rgba(255, 255, 255, 0.12);
    box-shadow: 0 8px 24px rgba(61, 130, 246, 0.35);
    color: #fff;
}

.btn-primary:hover {
    box-shadow: 0 10px 28px rgba(61, 130, 246, 0.45);
}

.btn-success {
    background: linear-gradient(135deg, var(--emerald), var(--green));
    color: #fff;
    border: none;
}

.btn-secondary,
.btn-icon,
.nav-tab,
.sidebar-btn,
.inp,
.tbl-wrap,
.stat,
.qa-card,
.conn-status {
    background: var(--surface2);
}

.stats {
    gap: 0.9rem;
}

.stat {
    position: relative;
    border-radius: 1rem;
    padding: 1rem 1rem 1rem 1.1rem;
    overflow: hidden;
    border-left: 3px solid var(--border2);
}

.stat::after {
    content: "";
    position: absolute;
    top: 0;
    right: 0;
    width: 5rem;
    height: 5rem;
    border-radius: 50%;
    opacity: 0.35;
    transform: translate(30%, -30%);
    pointer-events: none;
}

.stat.blue {
    border-left-color: var(--blue);
    background: linear-gradient(145deg, rgba(110, 181, 255, 0.12), var(--surface2) 55%);
}

.stat.blue::after {
    background: var(--blue);
}

.stat.green {
    border-left-color: var(--green);
    background: linear-gradient(145deg, rgba(52, 211, 153, 0.12), var(--surface2) 55%);
}

.stat.green::after {
    background: var(--green);
}

.stat.amber {
    border-left-color: var(--amber);
    background: linear-gradient(145deg, rgba(255, 190, 74, 0.12), var(--surface2) 55%);
}

.stat.amber::after {
    background: var(--amber);
}

.stat.purple {
    border-left-color: var(--purple);
    background: linear-gradient(145deg, rgba(192, 132, 252, 0.12), var(--surface2) 55%);
}

.stat.purple::after {
    background: var(--purple);
}

.stat.purple .stat-val {
    color: var(--purple);
}

.stat-icon {
    width: 1.75rem;
    height: 1.75rem;
    border-radius: 0.55rem;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 0.35rem;
    background: rgba(255, 255, 255, 0.06);
}

.stat.blue .stat-icon {
    color: var(--blue);
    background: rgba(110, 181, 255, 0.18);
}

.stat.green .stat-icon {
    color: var(--green);
    background: rgba(52, 211, 153, 0.18);
}

.stat.amber .stat-icon {
    color: var(--amber);
    background: rgba(255, 190, 74, 0.18);
}

.stat.purple .stat-icon {
    color: var(--purple);
    background: rgba(192, 132, 252, 0.18);
}

.stat-icon svg {
    width: 1rem;
    height: 1rem;
}

.stat-lbl {
    font-size: 0.68rem;
    letter-spacing: 0.14em;
}

.qa-card {
    min-height: 9.4rem;
    justify-content: space-between;
    border-width: 1px;
    border-style: solid;
}

.qa-card .qa-icon {
    width: 2.5rem;
    height: 2.5rem;
    border-radius: 0.75rem;
    display: flex;
    align-items: center;
    justify-content: center;
}

.qa-emerald {
    border-color: rgba(52, 211, 153, 0.35);
    background: linear-gradient(160deg, rgba(52, 211, 153, 0.14), var(--surface2) 70%);
}

.qa-emerald .qa-icon {
    color: var(--emerald);
    background: rgba(52, 211, 153, 0.2);
}

.qa-emerald:hover {
    border-color: var(--emerald);
    box-shadow: 0 8px 24px rgba(52, 211, 153, 0.2);
}

.qa-sky {
    border-color: rgba(110, 181, 255, 0.35);
    background: linear-gradient(160deg, rgba(110, 181, 255, 0.14), var(--surface2) 70%);
}

.qa-sky .qa-icon {
    color: var(--blue);
    background: rgba(110, 181, 255, 0.2);
}

.qa-sky:hover {
    border-color: var(--blue);
    box-shadow: 0 8px 24px rgba(110, 181, 255, 0.2);
}

.qa-amber {
    border-color: rgba(255, 190, 74, 0.35);
    background: linear-gradient(160deg, rgba(255, 190, 74, 0.14), var(--surface2) 70%);
}

.qa-amber .qa-icon {
    color: var(--amber);
    background: rgba(255, 190, 74, 0.2);
}

.qa-amber:hover {
    border-color: var(--amber);
    box-shadow: 0 8px 24px rgba(255, 190, 74, 0.2);
}

.qa-violet {
    border-color: rgba(167, 139, 250, 0.35);
    background: linear-gradient(160deg, rgba(167, 139, 250, 0.14), var(--surface2) 70%);
}

.qa-violet .qa-icon {
    color: var(--violet);
    background: rgba(167, 139, 250, 0.2);
}

.qa-violet:hover {
    border-color: var(--violet);
    box-shadow: 0 8px 24px rgba(167, 139, 250, 0.2);
}

.qa-icon,
.s-icon,
.icon-btn i,
.btn i,
.btn-icon i,
.nav-tab i,
.theme-toggle i,
.empty-icon i,
.inline-icon i,
.icon-badge i {
    width: 1rem;
    height: 1rem;
    stroke-width: 2;
}

.qa-icon i,
.s-icon i,
.icon-badge i {
    width: 1.2rem;
    height: 1.2rem;
}

.mobile-nav-btn {
    background: transparent;
    border: none;
    transform: none;
}

.mobile-nav-btn:hover,
.mobile-nav-btn:active {
    transform: none;
}

.mnav-icon {
    width: 28px;
    height: 28px;
    flex-shrink: 0;
}

.mnav-icon svg {
    width: 22px;
    height: 22px;
    stroke-width: 2;
    display: block;
}

.sidebar-btn.active {
    font-weight: 600;
}

.sidebar-btn.active[data-nav="dashboard"] {
    background: rgba(110, 181, 255, 0.16);
    color: var(--blue);
    box-shadow: inset 3px 0 0 var(--blue);
}

.sidebar-btn.active[data-nav="products"] {
    background: rgba(167, 139, 250, 0.16);
    color: var(--violet);
    box-shadow: inset 3px 0 0 var(--violet);
}

.sidebar-btn.active[data-nav="bind"] {
    background: rgba(62, 224, 208, 0.14);
    color: var(--cyan);
    box-shadow: inset 3px 0 0 var(--cyan);
}

.sidebar-btn.active[data-nav="quick"] {
    background: rgba(52, 211, 153, 0.14);
    color: var(--emerald);
    box-shadow: inset 3px 0 0 var(--emerald);
}

.sidebar-btn.active[data-nav="settings"] {
    background: rgba(255, 190, 74, 0.14);
    color: var(--amber);
    box-shadow: inset 3px 0 0 var(--amber);
}

.mobile-nav-btn.active[data-nav="dashboard"] {
    color: var(--blue);
    background: rgba(110, 181, 255, 0.16);
}

.mobile-nav-btn.active[data-nav="products"] {
    color: var(--violet);
    background: rgba(167, 139, 250, 0.16);
}

.mobile-nav-btn.active[data-nav="bind"] {
    color: var(--cyan);
    background: rgba(62, 224, 208, 0.14);
}

.mobile-nav-btn.active[data-nav="quick"] {
    color: var(--emerald);
    background: rgba(52, 211, 153, 0.14);
}

.mobile-nav-btn.active[data-nav="settings"] {
    color: var(--amber);
    background: rgba(255, 190, 74, 0.14);
}

.mobile-nav-btn.active .mnav-label {
    color: inherit;
}

.auth-card {
    border-color: rgba(110, 181, 255, 0.25);
    background: linear-gradient(165deg, rgba(110, 181, 255, 0.08), var(--surface) 45%);
}

.auth-badge {
    background: linear-gradient(135deg, rgba(110, 181, 255, 0.2), rgba(62, 224, 208, 0.15));
    color: var(--cyan);
    border: 1px solid rgba(110, 181, 255, 0.25);
}

.card {
    border-color: var(--border);
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.03), transparent 40%), var(--surface);
}

body[data-theme="light"] .card {
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.95), rgba(255, 255, 255, 0.85));
}

.product-card {
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.product-card:hover {
    border-color: rgba(110, 181, 255, 0.4);
    box-shadow: 0 8px 20px rgba(61, 130, 246, 0.12);
}

.conn-status {
    border: 1px solid var(--border);
}

.log-item .log-dot.ok,
.log-dot.ok {
    background: var(--green);
    box-shadow: 0 0 8px rgba(52, 211, 153, 0.5);
}

.inp:focus {
    border-color: var(--blue);
    box-shadow: 0 0 0 3px var(--blue-glow);
}

.empty {
    padding: 3rem 1.2rem;
}

.empty-icon {
    width: 3rem;
    height: 3rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 1rem;
    background: var(--surface-accent);
    color: var(--blue);
    opacity: 1;
}

.toast-item i {
    width: 1rem;
    height: 1rem;
}

.catalog-note {
    font-size: 0.82rem;
    color: var(--text2);
}

.search-row {
    flex-wrap: wrap;
}

.search-wrap {
    min-width: min(26rem, 100%);
}

.setting-actions,
.topbar-actions {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.table-secondary {
    color: var(--text2);
    font-size: 0.78rem;
}

.table-name {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    min-width: 13rem;
}

.bind-result,
.quick-result {
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 0.85rem;
}

.battery-pill {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.78rem;
}

@media (max-width: 900px) {
    .tbl-wrap {
        display: none;
    }

    .product-cards,
    .products-mobile {
        display: grid;
    }

    .table-shell {
        display: none;
    }

    .screen-head,
    .setup-intro {
        flex-direction: column;
    }
}

@media (max-width: 1023px) {
    .qa-card:active,
    .mobile-nav-btn:active,
    .btn:active {
        transform: scale(0.98);
    }
}

@media (max-width: 600px) {
    .page-title {
        font-size: 1.38rem;
    }

    .theme-toggle .theme-label,
    .auth-user {
        display: none;
    }

    .toolbar-actions,
    .button-cluster,
    .topbar-actions {
        width: 100%;
    }

    .toolbar-actions .btn,
    .button-cluster .btn,
    .topbar-actions .btn {
        flex: 1 1 10rem;
    }

    .btn,
    .btn-icon,
    .inp {
        min-height: 44px;
    }

    .btn-sm,
    .btn-icon {
        min-height: 40px;
    }
}
/* ── Segmented control ───────────────────────────────────────────────────── */
.toolbar-stack {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.seg {
    display: inline-flex;
    gap: 4px;
    padding: 4px;
    border: 1px solid var(--border);
    border-radius: var(--r);
    background: var(--surface2);
    align-self: flex-start;
    max-width: 100%;
    overflow-x: auto;
}

.seg-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 14px;
    border: none;
    border-radius: calc(var(--r) - 4px);
    background: transparent;
    color: var(--text2);
    font: inherit;
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
    cursor: pointer;
}

.seg-btn svg {
    width: 14px;
    height: 14px;
}

.seg-btn.active {
    background: var(--surface);
    color: var(--blue);
    box-shadow: var(--shadow);
}

/* ── Template groups and cards ───────────────────────────────────────────── */
.tpl-group {
    margin-top: 14px;
}

.tpl-group-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 14px;
}

.tpl-group-title {
    font-size: 15px;
    font-weight: 700;
    color: var(--text);
}

.tpl-group-sub {
    font-size: 12px;
    color: var(--text2);
    margin-top: 2px;
}

.tpl-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
    align-items: stretch;
    gap: 12px;
}

.tpl-card {
    display: flex;
    flex-direction: column;
    border: 1px solid var(--border);
    border-radius: var(--r);
    background: var(--surface2);
    overflow: hidden;
}

.tpl-thumb {
    aspect-ratio: 5 / 3;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #fff;
    border-bottom: 1px solid var(--border);
    overflow: hidden;
    padding: 8px;
}

.tpl-thumb img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.tpl-thumb-empty {
    background: repeating-linear-gradient(45deg, var(--surface3) 0 8px, var(--surface2) 8px 16px);
}

.tpl-card-body {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 12px;
}

.tpl-card-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
    line-height: 1.35;
}

.tpl-card-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    align-items: center;
}

.tpl-card-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 2px;
}

.tpl-card-actions .btn {
    flex: 1 1 auto;
    justify-content: center;
}

/* ── Template editor ─────────────────────────────────────────────────────── */
.modal-wide {
    max-width: 40rem;
}

.modal-sub {
    font-size: 11px;
    color: var(--text3);
    margin-top: 3px;
}

.tplm-preview {
    display: flex;
    justify-content: center;
    padding: 12px;
    margin-bottom: 14px;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: var(--r);
}

.tplm-preview img {
    max-width: 100%;
    max-height: 180px;
    object-fit: contain;
}

.tplm-fields {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.tplm-field label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: .03em;
    text-transform: uppercase;
    color: var(--text2);
    margin-bottom: 6px;
}

.tplm-hint {
    font-size: 11px;
    color: var(--text3);
    margin-top: 5px;
}

.tplm-image-row {
    display: flex;
    gap: 10px;
    align-items: flex-start;
}

.tplm-image-thumb {
    flex: 0 0 76px;
    height: 76px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: var(--r-sm);
    overflow: hidden;
}

.tplm-image-thumb img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

.tplm-image-side {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.tplm-upload {
    align-self: flex-start;
    cursor: pointer;
}

.tplm-siblings {
    margin-top: 18px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
}

/* ── Store switcher ──────────────────────────────────────────────────────── */
.store-now {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
}

.store-now-name {
    font-size: 15px;
    font-weight: 700;
    color: var(--text);
}

.store-now-id {
    font-size: 11px;
    color: var(--text3);
    margin-top: 2px;
}

.store-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.store-option {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: var(--r);
    background: var(--surface2);
    cursor: pointer;
}

.store-option:has(input:checked) {
    border-color: var(--blue);
    box-shadow: 0 0 0 1px var(--blue-dim);
}

.store-option.is-current {
    opacity: .7;
    cursor: default;
}

.store-option>div {
    flex: 1;
    min-width: 0;
}

.store-option-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
}

.store-option-meta {
    font-size: 11px;
    color: var(--text3);
    margin-top: 2px;
    overflow-wrap: anywhere;
}

.danger-note {
    margin-top: 14px;
    padding: 12px;
    border: 1px solid var(--red);
    border-radius: var(--r);
    background: color-mix(in srgb, var(--red) 10%, transparent);
    font-size: 12px;
    color: var(--text2);
    line-height: 1.6;
}

.danger-note-title {
    display: flex;
    align-items: center;
    gap: 6px;
    font-weight: 700;
    color: var(--red);
    margin-bottom: 6px;
}

.danger-note-title svg {
    width: 15px;
    height: 15px;
}

.confirm-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 10px;
    font-size: 12px;
    color: var(--text);
    cursor: pointer;
}

.confirm-row input {
    width: 16px;
    height: 16px;
    accent-color: var(--blue);
    flex: 0 0 auto;
}

/* ── API diagnostics ─────────────────────────────────────────────────────── */
.probe-row {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
}

.probe-row:last-child {
    border-bottom: none;
}

.probe-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
}

.probe-detail {
    font-size: 11px;
    color: var(--text3);
    margin-top: 4px;
    line-height: 1.7;
    overflow-wrap: anywhere;
}

/* ── Template card extras ────────────────────────────────────────────────── */
.tpl-card-sub {
    font-size: 11px;
    color: var(--text3);
}

.tpl-card-links {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid var(--border);
}

.tpl-link {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 0;
    border: none;
    background: none;
    color: var(--text2);
    font: inherit;
    font-size: 11px;
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
}

.tpl-link:hover {
    color: var(--blue);
}

.tpl-link svg {
    width: 13px;
    height: 13px;
}

/* ── Template editor extras ──────────────────────────────────────────────── */
.tplm-layout {
    padding-top: 8px;
}

.tplm-images {
    margin-top: 18px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.tplm-image-name {
    font-size: 11px;
    color: var(--text2);
    overflow-wrap: anywhere;
}

.tplm-fallback {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 18px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
}

.tplm-fallback .btn {
    text-decoration: none;
}

/* ── Devices grid ────────────────────────────────────────────────────────── */
.dev-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    align-items: stretch;
    gap: 12px;
}

.dev-card {
    display: flex;
    flex-direction: column;
    padding: 0;
    text-align: left;
    border: 1px solid var(--border);
    border-radius: var(--r);
    background: var(--surface);
    box-shadow: var(--shadow);
    cursor: pointer;
    overflow: hidden;
    font: inherit;
    color: inherit;
    transition: border-color .15s ease, transform .15s ease;
}

.dev-card:hover {
    border-color: var(--blue);
    transform: translateY(-2px);
}

/* The screen thumbnail is the point of the card — give it real estate and a
   white ground, because e-ink artwork is drawn for white. */
.dev-screen {
    aspect-ratio: 5 / 3;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #fff;
    border-bottom: 1px solid var(--border);
    overflow: hidden;
    padding: 8px;
}

.dev-screen img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    image-rendering: pixelated;
}

.dev-screen-ph {
    color: #c7d2e0;
}

.dev-screen-ph svg {
    width: 26px;
    height: 26px;
}

.dev-card-body {
    display: flex;
    flex: 1;
    flex-direction: column;
    gap: 4px;
    padding: 10px 12px 12px;
}

/* Push the spec line to the bottom so cards line up whatever metadata exists. */
.dev-card-meta {
    margin-top: auto;
}

.dev-card-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.dev-code {
    font-size: 11px;
    color: var(--text3);
}

.dev-shelf {
    font-size: 10px;
    font-weight: 700;
    padding: 2px 6px;
    border-radius: 999px;
    background: var(--surface2);
    color: var(--text2);
}

.dev-product {
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
    line-height: 1.35;
}

.dev-price {
    font-size: 13px;
    font-weight: 700;
    color: var(--green);
}

.dev-empty-label {
    font-size: 12px;
    color: var(--text3);
    font-style: italic;
}

.dev-card-meta {
    font-size: 11px;
    color: var(--text3);
}

/* ── Device panel ────────────────────────────────────────────────────────── */
.devm-screen {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 140px;
    padding: 14px;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: var(--r);
    /* The modal body is a column flexbox, so without this the frame is shrunk
       to its min-height while the preview inside keeps its full size and spills
       over the edges. Only showed up once portrait panels arrived: a landscape
       render is shorter than the frame, a 300x400 one is not. */
    flex-shrink: 0;
}

.devm-screen img {
    max-width: 100%;
    max-height: 240px;
    object-fit: contain;
    image-rendering: pixelated;
}

.devm-screen-ph {
    font-size: 12px;
    color: #94a3b8;
}

.devm-status {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    margin-top: 10px;
}

.devm-section {
    margin-top: 18px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
}

.devm-section .row {
    margin-top: 12px;
}

.devm-section .tplm-field + .row,
.devm-section .row + .tplm-field {
    margin-top: 12px;
}

/* Big, obvious drop target — this is the one action most users want. */
.devm-drop {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 22px 16px;
    border: 2px dashed var(--border2);
    border-radius: var(--r);
    background: var(--surface2);
    color: var(--text2);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: border-color .15s ease, color .15s ease;
}

.devm-drop:hover {
    border-color: var(--blue);
    color: var(--blue);
}

.devm-drop svg {
    width: 20px;
    height: 20px;
}

.devm-drop.is-busy {
    opacity: .6;
    pointer-events: none;
}

.devm-drop:has(input:disabled) {
    opacity: .5;
    cursor: not-allowed;
}

/* The picture a label is currently wearing, shown next to the control that
   replaces it — a thumbnail is the fastest way to tell "wrong picture" from
   "right picture, wrong way up". */
.devm-imgnow {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 10px 0;
    padding: 10px;
    border: 1px solid var(--border);
    border-radius: var(--r-sm);
    background: var(--surface2);
}

.devm-imgnow img {
    width: 88px;
    height: 88px;
    object-fit: contain;
    border-radius: var(--r-sm);
    background: #fff;
    flex-shrink: 0;
}

.devm-warn {
    margin-top: 8px;
    padding: 10px;
    border: 1px solid var(--amber);
    border-radius: var(--r-sm);
    background: color-mix(in srgb, var(--amber) 12%, transparent);
    font-size: 12px;
    color: var(--text2);
}

/* Seven tabs have to fit a 360px phone without truncating. */
@media (max-width: 420px) {
    .mobile-nav-inner {
        gap: 2px;
    }

    .mobile-nav-btn {
        padding: 6px 2px 4px;
    }

    .mnav-label {
        font-size: 9px;
        letter-spacing: 0;
    }
}

/* ── Device panel: image mode + advanced options ─────────────────────────── */
.devm-modes {
    width: 100%;
    margin-bottom: 8px;
}

.devm-modes .seg-btn {
    flex: 1;
    justify-content: center;
}

.devm-modes .seg-btn:disabled {
    opacity: .4;
    cursor: not-allowed;
}

/* Size and colour are correction dials, not everyday controls — folded away
   so the common case is just "choose an image". */
.devm-advanced {
    margin-top: 12px;
    border: 1px solid var(--border);
    border-radius: var(--r-sm);
    background: var(--surface2);
}

.devm-advanced summary {
    padding: 10px 12px;
    font-size: 12px;
    font-weight: 600;
    color: var(--text2);
    cursor: pointer;
    list-style: none;
}

.devm-advanced summary::-webkit-details-marker {
    display: none;
}

.devm-advanced summary::before {
    content: "▸ ";
    color: var(--text3);
}

.devm-advanced[open] summary::before {
    content: "▾ ";
}

.devm-advanced-body {
    display: flex;
    flex-direction: column;
    gap: 14px;
    padding: 4px 12px 14px;
}

.devm-advanced-body .field label {
    display: block;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: .03em;
    text-transform: uppercase;
    color: var(--text2);
    margin-bottom: 6px;
}

.devm-advanced-body select {
    width: 100%;
}

/* ── Device panel: this label's template fields ──────────────────────────── */
.devt-template {
    font-size: 11px;
    color: var(--text3);
    margin-bottom: 12px;
    overflow-wrap: anywhere;
}

.devt-rows {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.devt-label {
    display: block;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: .03em;
    text-transform: uppercase;
    color: var(--text2);
    margin-bottom: 6px;
}

.devt-note {
    font-size: 11px;
    color: var(--text3);
    margin-top: 4px;
}

.devt-readonly .devt-value {
    padding: 9px 12px;
    border: 1px dashed var(--border);
    border-radius: var(--r-sm);
    background: var(--surface2);
    font-size: 12px;
    color: var(--text2);
    overflow-wrap: anywhere;
}

/* Fixed text belongs to the template, not the device — visually separated so
   nobody expects editing it here to affect one label. */
.devt-fixed {
    margin-top: 14px;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: var(--r-sm);
    background: var(--surface2);
}

.devt-fixed-title {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: .03em;
    text-transform: uppercase;
    color: var(--text2);
    margin-bottom: 4px;
}

.devt-fixed-title svg {
    width: 13px;
    height: 13px;
}

.devt-fixed-item {
    margin-top: 6px;
    padding: 6px 8px;
    border-radius: var(--r-sm);
    background: var(--surface);
    font-size: 12px;
    color: var(--text2);
    overflow-wrap: anywhere;
}

/* ── Device panel: switch template ───────────────────────────────────────── */
.devt-switch {
    margin-top: 14px;
}

.devt-choice {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 10px;
    border: 1px solid var(--border);
    border-radius: var(--r-sm);
    background: var(--surface);
    cursor: pointer;
}

.devt-choice:has(input:checked) {
    border-color: var(--blue);
    box-shadow: 0 0 0 1px var(--blue-dim);
}

.devt-choice input {
    width: 16px;
    height: 16px;
    margin-top: 2px;
    accent-color: var(--blue);
    flex: 0 0 auto;
}

.devt-choice-body {
    min-width: 0;
    flex: 1;
}

.devt-choice-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
    overflow-wrap: anywhere;
}

.devt-choice-meta {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    margin-top: 5px;
}

.devt-choice-attrs {
    font-size: 11px;
    color: var(--text3);
}

/* ── Device panel: picture slots sit with the text fields ────────────────── */
.devt-slot {
    padding: 18px 14px;
}

.devt-slot-opts {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-top: 6px;
    flex-wrap: wrap;
}

/* Allergens are a short, fixed list that is read at a glance and ticked — a
   multi-select listbox would hide most of it behind a scroll. */
.lf-multi {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.lf-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    border: 1px solid var(--border2);
    border-radius: 999px;
    background: var(--surface2);
    font-size: 12px;
    font-weight: 600;
    color: var(--text2);
    cursor: pointer;
    user-select: none;
}

.lf-chip:hover {
    border-color: var(--blue);
}

.lf-chip:has(input:checked) {
    border-color: var(--blue);
    background: color-mix(in srgb, var(--blue) 16%, transparent);
    color: var(--text);
}

.lf-chip input {
    margin: 0;
    accent-color: var(--blue);
}

.lf-choice {
    align-self: flex-start;
}

/* Fit and rotation are one decision — how the picture sits on the panel — so
   they wrap together instead of stranding one on a line of its own. */
.devm-img-dials {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.devt-fit {
    width: auto;
    min-width: 9rem;
    padding: 6px 10px;
    font-size: 12px;
}

/* ── Bulk bind ─────────────────────────────────────────────────────────────
   A list arriving off a supplier's spreadsheet is mostly rows that need no
   attention, so the panel is built to surface the few that do. */
.bulk-panel {
    margin-top: 14px;
    padding: 14px;
    border: 1px solid var(--border);
    border-radius: var(--r);
    background: var(--surface2);
}

.bulk-text {
    width: 100%;
    margin: 10px 0;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 12px;
    line-height: 1.5;
    resize: vertical;
}

.bulk-summary {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 12px;
}

.bulk-rows {
    max-height: 260px;
    overflow-y: auto;
    margin-top: 10px;
    border: 1px solid var(--border);
    border-radius: var(--r-sm);
    background: var(--surface);
}

.bulk-row {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    padding: 8px 10px;
    border-bottom: 1px solid var(--border);
    font-size: 12px;
}

.bulk-row:last-child {
    border-bottom: none;
}

.bulk-row .muted {
    color: var(--text3);
}

/* While waiting for ZKong to redraw, the old picture stays put but dimmed —
   blanking it would suggest the label had gone dark. */
.devm-screen.is-waiting {
    position: relative;
    opacity: .55;
}

.devm-screen.is-waiting::after {
    content: "redrawing…";
    position: absolute;
    bottom: 8px;
    right: 10px;
    padding: 3px 8px;
    border-radius: 999px;
    background: var(--surface2);
    border: 1px solid var(--border);
    color: var(--text2);
    font-size: 11px;
    font-weight: 600;
}

/* Two ways to save a shared product — laid out as a choice rather than a
   confirm, because neither option is the obvious default. */
.scope-options {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 14px;
}

.scope-opt {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 14px;
    text-align: left;
    border: 1px solid var(--border2);
    border-radius: var(--r);
    background: var(--surface2);
    color: var(--text);
    font: inherit;
    cursor: pointer;
    transition: border-color .15s ease, background .15s ease;
}

.scope-opt:hover {
    border-color: var(--blue);
    background: var(--surface-accent);
}

.scope-opt svg {
    width: 18px;
    height: 18px;
    color: var(--blue);
    flex-shrink: 0;
    margin-top: 2px;
}

.scope-opt-body {
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.scope-opt-name {
    font-weight: 700;
    font-size: 13px;
}

.scope-opt-note {
    font-size: 12px;
    color: var(--text2);
    line-height: 1.45;
}

/* The "which label moves" picker sits under the copy option it belongs to. */
.scope-picker {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin: -4px 0 2px 42px;
}

/* ── Users ─────────────────────────────────────────────────────────────────
   An account is an address, a role and a set of labels; the row shows those
   three and nothing else. */
.badge-violet {
    background: rgba(167, 139, 250, 0.16);
    border-color: rgba(167, 139, 250, 0.34);
    color: var(--violet);
}

.user-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px;
    padding: 12px 14px;
    border: 1px solid var(--border);
    border-radius: var(--r-sm);
    background: var(--surface2);
    margin-bottom: 8px;
}

.user-row.is-disabled {
    opacity: .6;
}

.user-email {
    font-weight: 700;
    font-size: 13px;
}

.user-meta {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 4px;
}

.user-actions {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

/* The label picker can run to dozens of chips, so it scrolls rather than
   pushing the create button off the screen. */
.device-picker {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    max-height: 220px;
    overflow-y: auto;
    margin-top: 8px;
    padding: 10px;
    border: 1px solid var(--border);
    border-radius: var(--r-sm);
    background: var(--surface);
}
