@font-face {
    font-family: "Noto Sans SC";
    src: url("fonts/NotoSansSC-Web.woff2") format("woff2");
    font-style: normal;
    font-weight: 100 900;
    font-display: swap;
}

@font-face {
    font-family: "Noto Serif SC";
    src: url("fonts/NotoSerifSC-Web.woff2") format("woff2");
    font-style: normal;
    font-weight: 100 900;
    font-display: swap;
}

:root {
    --ink: #152238;
    --muted: #6d788a;
    --line: #e5e9ef;
    --canvas: #f4f6f8;
    --panel: #ffffff;
    --navy: #15396f;
    --navy-dark: #0e294f;
    --blue: #2769df;
    --blue-soft: #eaf1ff;
    --green: #16866c;
    --orange: #d47b22;
    --red: #c83b4b;
    --shadow: 0 10px 30px rgba(27, 44, 72, .07);
    --radius: 16px;
}

* {
    box-sizing: border-box;
}

html {
    min-width: 320px;
    background: var(--canvas);
}

body {
    margin: 0;
    color: var(--ink);
    background: var(--canvas);
    font-family: "Noto Sans SC", "Microsoft YaHei", system-ui, sans-serif;
    font-size: 14px;
    -webkit-font-smoothing: antialiased;
}

body.is-booting {
    overflow: hidden;
}

body.is-booting #login-view,
body.is-booting #app-view,
body.is-booting #toast-region {
    visibility: hidden;
}

.app-loading {
    display: grid;
    position: fixed;
    z-index: 1000;
    inset: 0;
    padding: 24px;
    color: #fff;
    background:
        radial-gradient(circle at 50% 20%, rgba(65, 123, 223, .28), transparent 34%),
        linear-gradient(145deg, #0b2344, #153f78);
    place-items: center;
    opacity: 1;
    transition: opacity .2s ease, visibility .2s ease;
}

.app-loading.is-ready {
    visibility: hidden;
    opacity: 0;
    pointer-events: none;
}

.app-loading-card {
    width: min(440px, 100%);
    padding: 38px 36px;
    border: 1px solid rgba(255, 255, 255, .13);
    border-radius: 20px;
    background: rgba(9, 31, 61, .72);
    box-shadow: 0 24px 70px rgba(4, 16, 34, .32);
    text-align: center;
    backdrop-filter: blur(12px);
}

.app-loading-mark {
    display: grid;
    width: 58px;
    height: 58px;
    margin: 0 auto 24px;
    border: 1px solid rgba(255, 255, 255, .28);
    border-radius: 15px;
    background: rgba(255, 255, 255, .1);
    font-size: 20px;
    font-weight: 900;
    place-items: center;
}

.app-loading .eyebrow {
    color: #9fc4ff;
}

.app-loading h1 {
    margin-bottom: 12px;
    color: #fff;
    font-size: 27px;
}

.app-loading-status {
    margin-bottom: 24px;
    color: #d5e4f8;
    font-size: 15px;
    line-height: 1.7;
}

.app-loading-progress {
    display: flex;
    height: 32px;
    margin-bottom: 18px;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.app-loading-progress span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #78aaff;
    animation: app-loading-pulse 1s ease-in-out infinite;
}

.app-loading-progress span:nth-child(2) {
    animation-delay: .14s;
}

.app-loading-progress span:nth-child(3) {
    animation-delay: .28s;
}

.app-loading-detail,
.app-loading-error {
    margin-bottom: 0;
    color: #9fb5d2;
    font-size: 12px;
    line-height: 1.7;
}

.app-loading.is-error .app-loading-progress {
    display: none;
}

.app-loading.is-error .app-loading-status,
.app-loading-error {
    color: #ffd7dc;
}

.app-loading.is-error .app-loading-detail {
    margin-bottom: 20px;
}

@keyframes app-loading-pulse {
    0%,
    100% {
        opacity: .35;
        transform: translateY(0);
    }

    50% {
        opacity: 1;
        transform: translateY(-6px);
    }
}

button,
input,
select,
textarea {
    color: inherit;
    font: inherit;
}

button,
a {
    -webkit-tap-highlight-color: transparent;
}

button {
    cursor: pointer;
}

[hidden] {
    display: none !important;
}

h1,
h2,
h3,
p {
    margin-top: 0;
}

h1,
h2,
h3 {
    letter-spacing: -.025em;
}

h1 {
    margin-bottom: 4px;
    font-size: 24px;
}

h2 {
    margin-bottom: 8px;
    font-size: 25px;
}

h3 {
    margin-bottom: 6px;
    font-size: 17px;
}

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

.eyebrow {
    margin-bottom: 5px;
    color: #76849a;
    font-size: 10px;
    font-weight: 800;
    letter-spacing: .18em;
    text-transform: uppercase;
}

.login-layout {
    display: grid;
    position: relative;
    min-height: 100vh;
    grid-template-columns: minmax(420px, 1.15fr) minmax(420px, .85fr);
    background: #fff;
}

.login-footer {
    display: flex;
    position: absolute;
    left: 24px;
    bottom: 18px;
    z-index: 5;
    align-items: center;
    gap: 12px;
}

.login-footer span {
    color: rgba(255,255,255,.75);
    font-size: 12px;
    letter-spacing: .02em;
}

.login-footer a {
    color: rgba(255,255,255,.75);
    font-size: 12px;
    letter-spacing: .02em;
    text-decoration: none;
}

.login-footer a:hover,
.login-footer a:focus {
    color: #fff;
    text-decoration: underline;
}

.login-brand {
    display: flex;
    position: relative;
    overflow: hidden;
    padding: clamp(48px, 8vw, 120px);
    color: #fff;
    background:
        linear-gradient(145deg, rgba(13, 41, 79, .95), rgba(19, 63, 123, .94)),
        repeating-linear-gradient(90deg, #fff 0 2px, transparent 2px 8px);
    flex-direction: column;
    justify-content: center;
}

.login-brand::before,
.login-brand::after {
    position: absolute;
    border: 1px solid rgba(255,255,255,.1);
    border-radius: 50%;
    content: "";
}

.login-brand::before {
    width: 420px;
    height: 420px;
    right: -160px;
    top: -120px;
}

.login-brand::after {
    width: 220px;
    height: 220px;
    right: 40px;
    bottom: -100px;
}

.brand-mark {
    display: grid;
    width: 42px;
    height: 42px;
    color: #fff;
    border-radius: 11px;
    background: var(--blue);
    font-weight: 900;
    place-items: center;
}

.brand-mark-large {
    width: 64px;
    height: 64px;
    margin-bottom: 36px;
    border: 1px solid rgba(255,255,255,.3);
    background: rgba(255,255,255,.12);
    font-size: 22px;
    backdrop-filter: blur(10px);
}

.login-brand .eyebrow {
    color: #a9c9ff;
}

.login-brand h1 {
    max-width: 560px;
    margin-bottom: 20px;
    font-size: clamp(38px, 5vw, 64px);
    line-height: 1.13;
}

.login-intro {
    max-width: 510px;
    color: #c7d7ed;
    font-size: 17px;
    line-height: 1.8;
}

.formula-card {
    display: flex;
    max-width: 530px;
    margin-top: 46px;
    padding: 18px 22px;
    border: 1px solid rgba(255,255,255,.14);
    border-radius: 13px;
    background: rgba(255,255,255,.07);
    flex-direction: column;
    gap: 6px;
}

.formula-card span {
    color: #9eb8dc;
    font-size: 11px;
}

.formula-card strong {
    font-size: 15px;
    letter-spacing: .04em;
}

.login-panel {
    display: grid;
    padding: 48px;
    place-items: center;
}

.login-form {
    width: min(380px, 100%);
}

.login-form h2 {
    margin-bottom: 8px;
    font-size: 34px;
}

.login-form > .muted {
    margin-bottom: 34px;
}

label {
    display: flex;
    color: #4f5a6c;
    font-size: 12px;
    font-weight: 700;
    flex-direction: column;
    gap: 8px;
}

input,
select,
textarea {
    width: 100%;
    padding: 11px 13px;
    border: 1px solid #dce2e9;
    border-radius: 9px;
    outline: none;
    background: #fff;
    font-size: 14px;
    font-weight: 500;
    transition: border-color .18s, box-shadow .18s;
}

input:focus,
select:focus,
textarea:focus {
    border-color: #6a95e4;
    box-shadow: 0 0 0 3px rgba(39,105,223,.11);
}

input[type="checkbox"],
input[type="radio"] {
    width: 17px;
    height: 17px;
    padding: 0;
    accent-color: var(--blue);
}

.login-form label {
    margin-bottom: 20px;
}

.button {
    display: inline-flex;
    min-height: 39px;
    padding: 9px 15px;
    border: 1px solid transparent;
    border-radius: 9px;
    align-items: center;
    justify-content: center;
    gap: 8px;
    text-decoration: none;
    font-size: 13px;
    font-weight: 800;
    transition: transform .15s, box-shadow .15s, background .15s;
}

.button:hover {
    transform: translateY(-1px);
}

.button:disabled {
    cursor: wait;
    opacity: .6;
    transform: none;
}

.button-primary {
    color: #fff;
    background: var(--blue);
    box-shadow: 0 6px 14px rgba(39,105,223,.2);
}

.button-primary:hover {
    background: #1e5ecb;
}

.button-dark {
    color: #fff;
    background: var(--navy-dark);
}

.button-secondary {
    color: #334157;
    border-color: #dbe1e9;
    background: #fff;
}

.button-danger {
    color: #fff;
    background: var(--red);
}

.button-block {
    width: 100%;
    min-height: 47px;
}

.form-error {
    min-height: 20px;
    margin: 10px 0 0;
    color: var(--red);
    font-size: 12px;
}

.app-layout {
    display: grid;
    min-height: 100vh;
    grid-template-columns: 236px minmax(0, 1fr);
}

.sidebar {
    display: flex;
    position: fixed;
    z-index: 30;
    width: 236px;
    height: 100vh;
    color: #d8e3f1;
    background: #102a50;
    flex-direction: column;
}

.sidebar-brand {
    display: flex;
    height: 82px;
    padding: 0 22px;
    border-bottom: 1px solid rgba(255,255,255,.08);
    align-items: center;
    gap: 12px;
}

.sidebar-brand strong,
.sidebar-brand span {
    display: block;
}

.sidebar-brand strong {
    color: #fff;
    font-size: 15px;
}

.sidebar-brand span {
    margin-top: 2px;
    color: #7f9aba;
    font-size: 10px;
    letter-spacing: .08em;
    text-transform: uppercase;
}

.nav-list {
    display: flex;
    padding: 22px 12px;
    flex: 1;
    flex-direction: column;
    gap: 4px;
}

.nav-item {
    display: flex;
    width: 100%;
    padding: 11px 12px;
    color: #aebed2;
    border: 0;
    border-radius: 9px;
    background: transparent;
    align-items: center;
    gap: 11px;
    font-size: 13px;
    text-align: left;
}

.nav-item:hover {
    color: #fff;
    background: rgba(255,255,255,.06);
}

.nav-item.active {
    color: #fff;
    background: #245aa8;
    box-shadow: inset 3px 0 #84b4ff;
}

.nav-icon {
    display: grid;
    width: 23px;
    height: 23px;
    color: currentColor;
    border: 1px solid currentColor;
    border-radius: 6px;
    font-size: 11px;
    place-items: center;
    opacity: .85;
}

.sidebar-user {
    display: grid;
    padding: 17px 15px;
    border-top: 1px solid rgba(255,255,255,.08);
    align-items: center;
    grid-template-columns: 34px 1fr 30px;
    gap: 9px;
}

.sidebar-user strong,
.sidebar-user span {
    display: block;
}

.sidebar-user strong {
    overflow: hidden;
    color: #fff;
    font-size: 12px;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sidebar-user span {
    margin-top: 2px;
    color: #869fbd;
    font-size: 10px;
}

.avatar {
    display: grid;
    width: 34px;
    height: 34px;
    color: #15396f;
    border-radius: 9px;
    background: #dbe9ff;
    font-weight: 900;
    place-items: center;
}

.icon-button {
    display: inline-grid;
    width: 32px;
    height: 32px;
    padding: 0;
    color: inherit;
    border: 1px solid #dce2e9;
    border-radius: 8px;
    background: transparent;
    font-weight: 800;
    place-items: center;
}

.sidebar .icon-button {
    border-color: rgba(255,255,255,.1);
}

.workspace {
    min-width: 0;
    grid-column: 2;
}

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

.topbar h1 {
    margin: 0;
    font-size: 20px;
}

.topbar .eyebrow {
    margin-bottom: 2px;
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

.date-badge {
    padding: 9px 12px;
    color: #637086;
    border: 1px solid var(--line);
    border-radius: 9px;
    background: #fafbfc;
    font-size: 12px;
}

.content {
    padding: 28px 32px 48px;
}

.page {
    display: none;
    max-width: 1500px;
    margin: 0 auto;
}

.page.active {
    display: block;
    animation: page-in .22s ease-out;
}

@keyframes page-in {
    from { opacity: 0; transform: translateY(4px); }
    to { opacity: 1; transform: none; }
}

.welcome-row,
.section-heading {
    display: flex;
    margin-bottom: 24px;
    align-items: flex-end;
    justify-content: space-between;
    gap: 24px;
}

.welcome-row {
    padding: 28px 30px;
    color: #fff;
    border-radius: var(--radius);
    background: linear-gradient(105deg, #143766 0%, #1c4e91 65%, #2360ad 100%);
    box-shadow: var(--shadow);
}

.welcome-row .eyebrow,
.welcome-row .muted {
    color: #b7cdec;
}

.welcome-row h2 {
    font-size: 27px;
}

.welcome-row p:last-child {
    margin-bottom: 0;
}

.welcome-row .button-dark {
    border: 1px solid rgba(255,255,255,.18);
    background: rgba(7,25,51,.55);
}

.section-heading > div > p:last-child {
    margin-bottom: 0;
    color: var(--muted);
}

.section-heading h2 {
    margin-bottom: 5px;
}

.stats-grid {
    display: grid;
    margin-bottom: 22px;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 16px;
}

.stat-card {
    position: relative;
    overflow: hidden;
    padding: 21px 22px;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: var(--panel);
    box-shadow: var(--shadow);
}

.stat-card::after {
    position: absolute;
    width: 70px;
    height: 70px;
    right: -20px;
    top: -22px;
    border-radius: 50%;
    background: currentColor;
    content: "";
    opacity: .06;
}

.stat-card span,
.stat-card small,
.stat-card strong {
    display: block;
}

.stat-card span {
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
}

.stat-card strong {
    margin: 9px 0 4px;
    color: var(--ink);
    font-size: 30px;
    line-height: 1;
}

.stat-card small {
    color: #98a2b2;
    font-size: 10px;
}

.stat-blue { color: var(--blue); border-top: 3px solid var(--blue); }
.stat-green { color: var(--green); border-top: 3px solid var(--green); }
.stat-orange { color: var(--orange); border-top: 3px solid var(--orange); }
.stat-slate { color: var(--navy); border-top: 3px solid var(--navy); }

.dashboard-grid {
    display: grid;
    grid-template-columns: minmax(0, 1.35fr) minmax(330px, .65fr);
    gap: 20px;
}

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

.panel-header {
    display: flex;
    padding: 20px 22px;
    border-bottom: 1px solid var(--line);
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}

.panel-header h3,
.panel-header p {
    margin-bottom: 0;
}

.text-button {
    padding: 5px;
    color: var(--blue);
    border: 0;
    background: transparent;
    font-size: 12px;
    font-weight: 800;
}

.recent-list {
    min-height: 220px;
}

.recent-row {
    display: grid;
    padding: 15px 22px;
    border-bottom: 1px solid #edf0f4;
    align-items: center;
    grid-template-columns: 38px minmax(120px, 1fr) minmax(180px, 1.2fr) 90px;
    gap: 12px;
}

.recent-row:last-child {
    border-bottom: 0;
}

.record-icon {
    display: grid;
    width: 34px;
    height: 34px;
    color: var(--navy);
    border-radius: 9px;
    background: #edf3fb;
    font-size: 11px;
    font-weight: 900;
    place-items: center;
}

.recent-row strong,
.recent-row small {
    display: block;
}

.recent-row small {
    margin-top: 2px;
    color: #96a0af;
    font-size: 10px;
}

.barcode-text {
    color: #34435a;
    font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
    font-size: 12px;
    letter-spacing: .04em;
}

.rule-panel {
    padding-bottom: 22px;
}

.rule-panel .panel-header {
    border: 0;
}

.rule-visual {
    display: flex;
    margin: 6px 22px 20px;
    border-radius: 10px;
    background: #f5f7fa;
    gap: 3px;
}

.segment {
    display: flex;
    min-width: 0;
    padding: 17px 7px 13px;
    color: #21314a;
    background: #e9eef5;
    align-items: center;
    flex: 1;
    flex-direction: column;
    font-family: ui-monospace, monospace;
    font-weight: 900;
}

.segment:first-child {
    border-radius: 9px 0 0 9px;
}

.segment:last-child {
    border-radius: 0 9px 9px 0;
}

.segment small {
    margin-top: 9px;
    color: #758196;
    font-family: "Noto Sans SC", sans-serif;
    font-size: 8px;
    font-weight: 600;
    white-space: nowrap;
}

.segment.product { flex: 1.7; background: #e2ebfb; color: #1955aa; }
.segment.date { flex: 1.25; background: #e5f4ef; color: #10705a; }
.segment.check { background: #fff0dd; color: #a45d12; }

.rule-note {
    margin: 0 22px;
    color: var(--muted);
    font-size: 12px;
    line-height: 1.8;
}

.format-chip {
    padding: 10px 14px;
    color: #29538c;
    border: 1px solid #ceddf2;
    border-radius: 9px;
    background: #eef4fc;
    font-family: ui-monospace, monospace;
    font-size: 12px;
    font-weight: 800;
}

.generator-grid {
    display: grid;
    grid-template-columns: minmax(480px, .9fr) minmax(420px, 1.1fr);
    gap: 20px;
}

.form-panel {
    padding: 22px;
}

.step-title {
    display: flex;
    margin-bottom: 18px;
    align-items: center;
    gap: 11px;
}

.step-title > span {
    display: grid;
    width: 34px;
    height: 34px;
    color: #fff;
    border-radius: 9px;
    background: var(--navy);
    font-size: 11px;
    font-weight: 900;
    place-items: center;
}

.step-title strong,
.step-title small {
    display: block;
}

.step-title small {
    margin-top: 2px;
    color: var(--muted);
    font-size: 10px;
}

.step-spaced {
    margin-top: 28px;
    padding-top: 24px;
    border-top: 1px solid var(--line);
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
}

.form-grid.compact {
    gap: 12px;
}

.span-2 {
    grid-column: span 2;
}

.inline-note {
    margin-top: 14px;
    padding: 10px 12px;
    color: #54647b;
    border-left: 3px solid #7da2dd;
    background: #f3f7fc;
    font-size: 11px;
    line-height: 1.6;
}

.layout-offset-group {
    display: flex;
    margin-top: 14px;
    padding: 12px 14px;
    border: 1px dashed #c9d5e6;
    border-radius: 10px;
    background: #f8fafd;
    align-items: center;
    gap: 18px;
}

.layout-offset-title {
    display: grid;
    min-width: 0;
    gap: 4px;
}

.layout-offset-title strong {
    font-size: 13px;
    color: #1d2c42;
}

.layout-offset-title small {
    color: #64748b;
    font-size: 11px;
    line-height: 1.5;
}

.layout-offset-controls {
    display: flex;
    flex: 1;
    align-items: center;
    justify-content: flex-end;
    gap: 16px;
}

.offset-pad {
    display: grid;
    justify-items: center;
    gap: 4px;
}

.offset-pad .icon-button {
    width: 28px;
    height: 28px;
    font-size: 13px;
}

.offset-pad-row {
    display: flex;
    gap: 4px;
}

.offset-pad .offset-reset {
    color: #54647b;
    border-style: dashed;
}

.offset-inputs {
    display: flex;
    gap: 12px;
}

.offset-inputs label {
    display: grid;
    gap: 4px;
    color: #54647b;
    font-size: 11px;
    white-space: nowrap;
}

.offset-inputs input {
    width: 96px;
    padding: 7px 8px;
    border: 1px solid #dce2e9;
    border-radius: 8px;
    font-size: 12px;
}

@media (max-width: 900px) {
    .layout-offset-group {
        flex-direction: column;
        align-items: stretch;
    }

    .layout-offset-controls {
        justify-content: space-between;
    }
}

.list-toolbar,
.selection-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.list-toolbar input {
    flex: 1;
    max-width: 330px;
}

.list-toolbar select {
    width: min(180px, 40%);
}

.selection-list {
    overflow: auto;
    min-height: 210px;
    max-height: 340px;
    margin: 12px 0 16px;
    border: 1px solid var(--line);
    border-radius: 10px;
}

.selection-row {
    display: grid;
    padding: 11px 13px;
    border-bottom: 1px solid #edf0f4;
    align-items: center;
    grid-template-columns: 22px minmax(120px, 1fr) 90px;
    gap: 10px;
    cursor: pointer;
}

.selection-row:last-child {
    border-bottom: 0;
}

.selection-row:hover {
    background: #f8faff;
}

.selection-row strong,
.selection-row small {
    display: block;
}

.selection-row small {
    margin-top: 2px;
    color: var(--muted);
    font-size: 10px;
}

.selection-row code {
    color: #3d4b61;
    font-size: 11px;
}

.selection-footer {
    padding-top: 15px;
    border-top: 1px solid var(--line);
}

.preview-panel {
    display: flex;
    overflow: hidden;
    min-height: 620px;
    flex-direction: column;
}

.zoom-controls {
    display: flex;
    align-items: center;
    gap: 8px;
}

.zoom-controls span {
    min-width: 40px;
    color: var(--muted);
    font-size: 10px;
    text-align: center;
}

.preview-stage {
    display: flex;
    overflow: auto;
    min-height: 440px;
    padding: 36px;
    background-color: #e9edf2;
    background-image: radial-gradient(#c8d0da 0.7px, transparent 0.7px);
    background-size: 12px 12px;
    align-items: flex-start;
    flex: 1;
    justify-content: center;
}

.preview-labels {
    display: flex;
    width: 100%;
    align-items: center;
    flex-direction: column;
    gap: 22px;
    transform-origin: top center;
    transition: transform .15s;
}

.preview-item {
    display: flex;
    max-width: 100%;
    align-items: stretch;
    flex-direction: column;
}

.generated-label-preview {
    display: block;
    max-width: 100%;
    border: 0;
    background: #eef2f7;
}

.preview-item .template-card-actions {
    width: 100%;
}

.preview-label {
    position: relative;
    overflow: hidden;
    flex: 0 0 auto;
    color: #111;
    background: #fff;
    box-shadow: 0 8px 24px rgba(29,41,59,.18);
}

.food-preview-content {
    position: absolute;
    overflow: hidden;
    top: 1%;
    left: 1.7%;
    width: 96.6%;
    height: 72.8%;
    color: #050505;
    line-height: 1.2;
    white-space: nowrap;
}

.food-preview-title {
    height: 16%;
    font-size: 1.9em;
    font-weight: 800;
    line-height: 1.15;
    text-align: center;
}

.food-preview-grid {
    display: grid;
    height: 48%;
    grid-template-columns: 52% 48%;
    grid-template-rows: repeat(4, 25%);
}

.food-preview-grid > * {
    display: flex;
    overflow: hidden;
    min-width: 0;
    align-items: center;
    line-height: 1.2;
    text-overflow: clip;
    white-space: nowrap;
}

.food-preview-grid strong {
    justify-content: center;
    font-size: 1.3em;
    text-align: center;
}

.food-preview-content > div:not(.food-preview-title):not(.food-preview-grid) {
    display: flex;
    overflow: hidden;
    height: 12%;
    align-items: center;
    white-space: nowrap;
}

.preview-label .label-extra {
    display: flex;
    position: absolute;
    overflow: hidden;
    top: 5%;
    left: 3%;
    right: auto;
    width: 94%;
    align-items: center;
    justify-content: center;
    text-align: center;
    white-space: nowrap;
}

.preview-label .label-barcode {
    position: absolute;
    text-align: center;
}

.preview-label .label-element-text {
    display: flex;
    position: absolute;
    overflow: hidden;
    align-items: center;
    line-height: 1.1;
    white-space: nowrap;
}

.fit-text-content {
    display: inline-block;
    min-width: 0;
    flex: 0 0 auto;
    line-height: 1.1;
    white-space: nowrap;
    transform-origin: left center;
}

.preview-label img {
    display: block;
    width: 100%;
    height: 78%;
    object-fit: fill;
}

.preview-label .label-value {
    overflow: hidden;
    height: 22%;
    font-family: ui-monospace, monospace;
    letter-spacing: .06em;
    white-space: nowrap;
}

.ean13-value {
    display: grid;
    width: 100%;
    font-family: Arial, Helvetica, sans-serif;
    font-variant-numeric: tabular-nums;
    letter-spacing: .12em;
    line-height: 1;
    grid-template-columns: 11fr 47.5fr 47.5fr 7fr;
}

.ean13-value > span {
    min-width: 0;
    text-align: center;
}

.ean13-value > span:first-child {
    letter-spacing: 0;
}

.ean13-value > i {
    display: block;
}

.empty-state {
    display: flex;
    margin: auto;
    color: #7e8999;
    align-items: center;
    flex-direction: column;
    text-align: center;
}

.empty-state strong {
    color: #556173;
}

.empty-state p {
    margin: 6px 0 0;
    font-size: 11px;
}

.empty-icon {
    display: grid;
    width: 54px;
    height: 54px;
    margin-bottom: 14px;
    color: #617086;
    border: 1px solid #cbd3de;
    border-radius: 13px;
    background: rgba(255,255,255,.55);
    font-size: 22px;
    place-items: center;
}

.preview-actions {
    display: flex;
    padding: 16px 20px;
    border-top: 1px solid var(--line);
    background: #fff;
    justify-content: flex-end;
    gap: 10px;
}

.filter-bar {
    display: flex;
    padding: 17px 19px;
    border-bottom: 1px solid var(--line);
    align-items: center;
    gap: 10px;
}

.filter-bar input {
    max-width: 320px;
}

.filter-bar select {
    width: 170px;
}

.history-filter label {
    display: flex;
    align-items: center;
    flex-direction: row;
    white-space: nowrap;
}

.history-filter label input {
    width: 150px;
}

.table-wrap {
    overflow-x: auto;
}

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

th {
    padding: 12px 16px;
    color: #748094;
    border-bottom: 1px solid var(--line);
    background: #fafbfc;
    font-size: 10px;
    letter-spacing: .04em;
    text-align: left;
    white-space: nowrap;
}

td {
    padding: 14px 16px;
    border-bottom: 1px solid #edf0f4;
    vertical-align: middle;
}

tbody tr:hover {
    background: #fbfcfe;
}

tbody tr:last-child td {
    border-bottom: 0;
}

.align-right {
    text-align: right;
}

.section-heading-actions {
    display: inline-flex;
    gap: 10px;
    align-items: center;
}

.checkbox-cell {
    width: 36px;
    text-align: center;
}

.checkbox-cell input[type="checkbox"] {
    width: 16px;
    height: 16px;
    cursor: pointer;
    vertical-align: middle;
}

.table-actions {
    display: flex;
    justify-content: flex-end;
    gap: 5px;
}

.history-label-data {
    min-width: 110px;
}

.history-label-data summary {
    color: var(--blue);
    cursor: pointer;
    font-weight: 800;
    white-space: nowrap;
}

.history-label-preview {
    width: min(580px, 78vw);
    margin-top: 10px;
    padding: 10px;
    border: 1px solid #dfe5ee;
    border-radius: 10px;
    background: #eef2f7;
}

.history-label-preview iframe {
    display: block;
    width: 100%;
    height: 380px;
    margin: 0 auto;
    border: 0;
    background: #fff;
    box-shadow: 0 4px 14px rgba(22, 34, 52, .12);
}

.history-label-data-list {
    display: grid;
    width: min(580px, 78vw);
    max-height: 320px;
    margin-top: 10px;
    overflow-y: auto;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
}

.history-label-data-list > div {
    display: grid;
    padding: 8px 10px;
    border-bottom: 1px solid #edf0f4;
    grid-template-columns: 90px minmax(0, 1fr);
    gap: 10px;
}

.history-label-data-list > div:last-child {
    border-bottom: 0;
}

.history-label-data-list span {
    color: var(--muted);
}

.history-label-data-list strong {
    color: var(--ink);
    font-weight: 600;
    overflow-wrap: anywhere;
}

.mini-button {
    padding: 5px 7px;
    color: #536178;
    border: 1px solid #dfe4eb;
    border-radius: 6px;
    background: #fff;
    font-size: 10px;
    text-decoration: none;
    white-space: nowrap;
}

.mini-button:hover {
    color: var(--blue);
    border-color: #b8cae8;
}

.mini-button.danger:hover {
    color: var(--red);
    border-color: #e9b8bf;
}

.status {
    display: inline-flex;
    padding: 3px 8px;
    border-radius: 99px;
    background: #e6f4ef;
    color: #14735e;
    font-size: 9px;
    font-weight: 800;
}

.status.off {
    color: #7b8492;
    background: #eef0f3;
}

.pagination {
    display: flex;
    min-height: 56px;
    padding: 12px 18px;
    border-top: 1px solid var(--line);
    align-items: center;
    justify-content: flex-end;
    gap: 7px;
}

.pagination span {
    margin-right: auto;
    color: var(--muted);
    font-size: 11px;
}

.pagination button {
    min-width: 30px;
    height: 30px;
    color: #58667b;
    border: 1px solid #dfe4eb;
    border-radius: 7px;
    background: #fff;
    font-size: 11px;
}

.pagination button.active {
    color: #fff;
    border-color: var(--blue);
    background: var(--blue);
}

.pagination button:disabled {
    opacity: .4;
}

.template-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(290px, 1fr));
    gap: 18px;
}

.template-card {
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: #fff;
    box-shadow: var(--shadow);
}

.template-card-preview {
    display: grid;
    min-height: 190px;
    padding: 25px;
    background:
        linear-gradient(45deg, #eef1f5 25%, transparent 25%),
        linear-gradient(-45deg, #eef1f5 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, #eef1f5 75%),
        linear-gradient(-45deg, transparent 75%, #eef1f5 75%);
    background-color: #f7f8fa;
    background-position: 0 0, 0 5px, 5px -5px, -5px 0;
    background-size: 10px 10px;
    place-items: center;
}

.template-paper {
    display: grid;
    width: min(240px, 100%);
    min-height: 115px;
    padding: 16px;
    background: #fff;
    box-shadow: 0 7px 18px rgba(37,48,65,.17);
    place-items: center;
}

.template-paper img {
    width: 90%;
    height: 65px;
}

.template-card-value {
    width: 90%;
    color: #111;
    font-family: ui-monospace, monospace;
    font-size: 12px;
    letter-spacing: .06em;
    text-align: center;
}

.template-paper.food-thumbnail {
    position: relative;
    display: flex;
    min-height: 145px;
    padding: 9px 12px;
    flex-direction: column;
}

.template-paper.food-thumbnail img {
    width: 92%;
    height: 42px;
    margin-top: auto;
}

.food-card-sample {
    display: flex;
    overflow: hidden;
    width: 100%;
    color: #111;
    flex-direction: column;
    font-size: 6px;
    line-height: 1.35;
}

.food-card-sample strong {
    margin-bottom: 2px;
    font-size: 12px;
    text-align: center;
}

.template-card-body {
    padding: 18px 19px;
}

.template-title {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 10px;
}

.template-title h3 {
    margin: 0;
}

.default-badge {
    padding: 3px 7px;
    color: #225aa8;
    border-radius: 99px;
    background: #e7f0ff;
    font-size: 9px;
    font-weight: 800;
}

.template-meta {
    display: flex;
    margin: 12px 0 16px;
    color: var(--muted);
    flex-wrap: wrap;
    gap: 6px 13px;
    font-size: 10px;
}

.template-card-actions {
    display: flex;
    padding-top: 13px;
    border-top: 1px solid var(--line);
    justify-content: flex-end;
    gap: 7px;
}

.tool-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 20px;
}

.tool-card {
    position: relative;
    overflow: hidden;
    padding: 28px;
}

.tool-card > p {
    margin-bottom: 24px;
    color: var(--muted);
}

.tool-card label {
    margin-bottom: 16px;
}

.tool-card input {
    padding: 15px;
    font-family: ui-monospace, monospace;
    font-size: 17px;
    letter-spacing: .08em;
}

.tool-number {
    position: absolute;
    right: 22px;
    top: 18px;
    color: #e3e8ef;
    font-size: 48px;
    font-weight: 900;
}

.calculation-result {
    margin-top: 20px;
    padding: 16px;
    border: 1px solid #dce5f1;
    border-radius: 10px;
    background: #f7faff;
    line-height: 1.8;
}

.calculation-result strong {
    color: var(--blue);
    font-size: 20px;
}

.result-valid {
    color: var(--green) !important;
}

.result-invalid {
    color: var(--red) !important;
}

.algorithm-panel {
    margin-top: 20px;
    padding: 24px 28px;
}

.algorithm-formula {
    overflow-x: auto;
    margin: 18px 0 12px;
    padding: 17px 20px;
    color: #15396f;
    border-left: 4px solid var(--blue);
    background: #f1f5fb;
    font-family: ui-monospace, monospace;
    font-size: 15px;
    font-weight: 800;
    white-space: nowrap;
}

.algorithm-panel > p:last-child {
    margin-bottom: 0;
    color: var(--muted);
}

.maintenance-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 18px;
}

.maintenance-card {
    display: flex;
    padding: 25px;
    align-items: flex-start;
    flex-direction: column;
}

.maintenance-card > p {
    min-height: 70px;
    color: var(--muted);
    line-height: 1.7;
}

.maintenance-card .button {
    margin-top: auto;
}

.maintenance-card label {
    width: 100%;
    margin-bottom: 12px;
}

.maintenance-icon {
    display: grid;
    width: 42px;
    height: 42px;
    margin-bottom: 17px;
    color: #165eaa;
    border-radius: 11px;
    background: #e7f1ff;
    font-size: 19px;
    font-weight: 900;
    place-items: center;
}

.maintenance-icon.warning {
    color: #a76016;
    background: #fff0dc;
}

.maintenance-icon.neutral {
    color: #43536a;
    background: #edf0f4;
}

.account-grid {
    display: grid;
    grid-template-columns: minmax(280px, 340px) minmax(0, 1fr);
    gap: 18px;
}

.account-password-card {
    height: fit-content;
}

.account-password-card > p {
    min-height: 82px;
}

.user-management {
    min-width: 0;
}

.permission-tags {
    display: flex;
    max-width: 460px;
    flex-wrap: wrap;
    gap: 5px;
}

.permission-tags span {
    padding: 3px 7px;
    color: #31567f;
    border-radius: 99px;
    background: #edf3fb;
    font-size: 9px;
    white-space: nowrap;
}

.permission-tags .permission-all {
    color: #14735e;
    background: #e6f4ef;
}

.permission-fieldset {
    min-width: 0;
    margin: 4px 0 0;
    padding: 16px;
    border: 1px solid var(--line);
    border-radius: 10px;
}

.permission-fieldset legend {
    padding: 0 7px;
    color: var(--ink);
    font-size: 12px;
    font-weight: 800;
}

.permission-fieldset > p {
    margin: 0 0 12px;
    color: var(--muted);
    font-size: 11px;
}

.permission-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
}

.permission-grid label {
    display: flex;
    min-width: 0;
    padding: 10px;
    border: 1px solid #e2e7ed;
    border-radius: 8px;
    background: #fafbfc;
    align-items: center;
    flex-direction: row;
    gap: 8px;
}

.permission-grid input {
    width: auto;
    flex: 0 0 auto;
}

.permission-grid label.permission-sub {
    margin-left: 30px;
    background: #fff6ec;
    border-color: #f2dfc2;
    grid-column: 2 / 3;
}

.permission-grid label.permission-sub::before {
    content: "↳";
    color: #c98842;
    font-weight: 700;
}

.permissions-locked .permission-grid {
    opacity: .65;
}

.file-field input {
    padding: 9px;
    font-size: 11px;
}

.help-grid {
    display: grid;
    grid-template-columns: 220px minmax(0, 1fr);
    gap: 18px;
}

.help-nav {
    display: flex;
    height: fit-content;
    padding: 10px;
    flex-direction: column;
}

.help-nav button {
    padding: 11px 13px;
    color: var(--muted);
    border: 0;
    border-radius: 8px;
    background: transparent;
    text-align: left;
}

.help-nav button.active {
    color: var(--navy);
    background: #edf3fb;
    font-weight: 800;
}

.help-content {
    min-height: 430px;
    padding: 30px;
    line-height: 1.8;
}

.help-content h3 {
    margin-top: 27px;
}

.help-content h3:first-child {
    margin-top: 0;
}

.help-content code {
    padding: 2px 5px;
    color: #164d92;
    border-radius: 4px;
    background: #edf3fb;
}

.modal {
    width: min(650px, calc(100vw - 30px));
    padding: 0;
    border: 0;
    border-radius: 17px;
    box-shadow: 0 28px 80px rgba(15,29,49,.25);
}

.modal::backdrop {
    background: rgba(13,25,43,.56);
    backdrop-filter: blur(3px);
}

.modal form {
    overflow-y: auto;
    max-height: calc(100vh - 30px);
    padding: 25px;
}

.modal-wide {
    width: min(1050px, calc(100vw - 30px));
}

.modal-designer {
    width: min(1400px, calc(100vw - 20px));
}

.modal-header,
.modal-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.modal-header {
    margin-bottom: 22px;
}

.modal-header h2 {
    margin: 0;
    font-size: 22px;
}

.modal-actions {
    margin: 10px -25px -25px;
    padding: 16px 25px;
    border-top: 1px solid var(--line);
    background: #fafbfc;
    justify-content: flex-end;
}

.switch-field {
    display: flex;
    min-height: 40px;
    align-items: center;
    flex-direction: row;
}

.template-editor {
    display: grid;
    grid-template-columns: minmax(270px, .72fr) minmax(390px, 1.2fr) minmax(270px, .72fr);
    gap: 18px;
}

.template-settings,
.element-inspector {
    min-width: 0;
    padding: 16px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: #fff;
}

.element-toolbar,
.inspector-actions {
    display: flex;
    gap: 8px;
}

.element-toolbar {
    margin: 10px 0;
    flex-wrap: wrap;
}

.element-list {
    display: flex;
    overflow-y: auto;
    max-height: 240px;
    flex-direction: column;
    gap: 6px;
}

.element-list-item {
    display: flex;
    width: 100%;
    padding: 9px 10px;
    color: var(--navy);
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    align-items: center;
    justify-content: space-between;
    text-align: left;
}

.element-list-item.active {
    color: #fff;
    border-color: var(--blue);
    background: var(--blue);
}

.element-list-item small {
    opacity: .75;
}

.element-type-label {
    padding: 9px 10px;
    color: var(--blue);
    border-radius: 7px;
    background: #edf3fb;
    font-weight: 800;
}

.compact-empty {
    min-height: 150px;
    padding: 30px 10px;
}

.dynamic-fields-heading {
    display: flex;
    margin-top: 4px;
    padding-bottom: 7px;
    border-bottom: 1px solid var(--line);
    align-items: baseline;
    justify-content: space-between;
}

.dynamic-fields-heading small {
    color: var(--muted);
}

.dynamic-fields {
    padding: 2px 0 5px;
}

.editor-section-title {
    margin: 6px 0 -2px;
    padding-bottom: 5px;
    color: var(--navy);
    border-bottom: 1px solid var(--line);
    font-size: 11px;
    font-weight: 900;
}

.editor-preview {
    display: flex;
    min-width: 0;
    padding: 18px;
    border-radius: 12px;
    background: #edf0f4;
    align-items: center;
    flex-direction: column;
    justify-content: flex-start;
}

.editor-preview > small {
    margin-top: 14px;
    color: var(--muted);
    font-size: 9px;
}

.template-canvas {
    position: relative;
    overflow: hidden;
    width: 350px;
    height: 200px;
    max-width: 100%;
    color: #111;
    background: #fff;
    box-shadow: 0 8px 24px rgba(22,34,51,.15);
}

.template-extra {
    position: absolute;
    overflow: hidden;
    top: 5%;
    left: 3%;
    width: 94%;
    height: 15%;
    text-align: center;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.template-barcode {
    position: absolute;
    z-index: 2;
    display: flex;
    left: 7.14%;
    top: 20%;
    width: 85.71%;
    height: 50%;
    align-items: stretch;
    flex-direction: column;
    text-align: center;
}

.template-barcode img {
    width: 100%;
    min-height: 0;
    flex: 1;
    object-fit: fill;
}

.template-element-value {
    font-family: ui-monospace, monospace;
    font-size: 12px;
    letter-spacing: .06em;
}

.template-text-element {
    display: flex;
    position: absolute;
    z-index: 2;
    overflow: hidden;
    align-items: center;
    line-height: 1.1;
    white-space: nowrap;
}

.template-text-element.is-multiline,
.template-text-element.is-multiline .fit-text-content {
    line-height: var(--text-line-height, 1.3);
}

.template-border-element {
    position: absolute;
    z-index: 1;
    background: transparent;
}

.template-element {
    cursor: move;
    touch-action: none;
    user-select: none;
}

.template-element.is-active {
    z-index: 5;
    outline: 2px solid var(--blue);
    outline-offset: 1px;
}

.template-border-element.is-active {
    z-index: 1;
}

.resize-handle {
    position: absolute;
    z-index: 7;
    right: 0;
    bottom: 0;
    width: 11px;
    height: 11px;
    border: 2px solid #fff;
    border-radius: 2px 0 0;
    background: var(--blue);
    box-shadow: 0 0 0 1px rgba(14, 41, 79, .35);
    cursor: nwse-resize;
}

.toast-region {
    display: flex;
    position: fixed;
    z-index: 100;
    right: 20px;
    top: 20px;
    align-items: flex-end;
    flex-direction: column;
    gap: 9px;
    pointer-events: none;
}

.toast {
    min-width: 250px;
    max-width: 380px;
    padding: 13px 16px;
    color: #fff;
    border-radius: 10px;
    background: #26364e;
    box-shadow: 0 10px 30px rgba(12,26,45,.25);
    font-size: 12px;
    animation: toast-in .2s ease-out;
}

.toast.error {
    background: #a93140;
}

@keyframes toast-in {
    from { opacity: 0; transform: translateY(-8px); }
}

.mobile-only {
    display: none;
}

.loading-row,
.empty-row {
    padding: 32px !important;
    color: var(--muted);
    text-align: center;
}

@media (max-width: 1180px) {
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .dashboard-grid,
    .generator-grid {
        grid-template-columns: 1fr;
    }

    .preview-panel {
        min-height: 540px;
    }

    .template-grid {
        grid-template-columns: repeat(2, 1fr);
    }

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

    .template-editor {
        grid-template-columns: minmax(260px, .75fr) minmax(390px, 1.25fr);
    }

    .element-inspector {
        grid-column: 1 / -1;
    }
}

@media (max-width: 820px) {
    .login-layout {
        grid-template-columns: 1fr;
    }

    .login-brand {
        display: none;
    }

    .login-panel {
        min-height: 100vh;
        padding: 28px;
    }

    .login-footer span,
    .login-footer a {
        color: #8291a5;
    }

    .login-footer a:hover,
    .login-footer a:focus {
        color: #4a5a70;
    }

    .app-layout {
        display: block;
    }

    .sidebar {
        width: 250px;
        transform: translateX(-100%);
        transition: transform .2s;
    }

    .sidebar.open {
        transform: translateX(0);
        box-shadow: 20px 0 50px rgba(10,25,48,.25);
    }

    .workspace {
        margin-left: 0;
    }

    .topbar {
        height: 72px;
        padding: 0 18px;
        justify-content: flex-start;
        gap: 12px;
    }

    .topbar-actions {
        margin-left: auto;
    }

    .date-badge,
    .topbar-actions .button {
        display: none;
    }

    .mobile-only {
        display: inline-grid;
    }

    .content {
        padding: 20px 16px 40px;
    }

    .welcome-row,
    .section-heading {
        align-items: flex-start;
        flex-direction: column;
    }

    .welcome-row .button {
        width: 100%;
    }

    .generator-grid {
        display: block;
    }

    .preview-panel {
        margin-top: 18px;
    }

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

    .element-inspector {
        grid-column: auto;
    }

    .tool-grid,
    .maintenance-grid,
    .account-grid {
        grid-template-columns: 1fr;
    }

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

    .help-nav {
        overflow-x: auto;
        flex-direction: row;
    }

    .help-nav button {
        white-space: nowrap;
    }

    .history-filter {
        align-items: stretch;
        flex-direction: column;
    }

    .history-filter input,
    .history-filter label,
    .history-filter label input {
        width: 100%;
        max-width: none;
    }

    .history-filter label {
        align-items: flex-start;
        flex-direction: column;
    }

    .history-label-preview iframe {
        height: 280px;
    }
}

@media (max-width: 600px) {
    .app-loading-card {
        padding: 32px 22px;
    }

    .stats-grid,
    .template-grid,
    .form-grid,
    .permission-grid {
        grid-template-columns: 1fr;
    }

    .span-2 {
        grid-column: auto;
    }

    .recent-row {
        grid-template-columns: 34px minmax(100px, 1fr) 75px;
    }

    .recent-row .barcode-text {
        display: none;
    }

    .filter-bar {
        align-items: stretch;
        flex-direction: column;
    }

    .filter-bar input,
    .filter-bar select {
        width: 100%;
        max-width: none;
    }

    .list-toolbar {
        align-items: stretch;
        flex-direction: column;
    }

    .list-toolbar input,
    .list-toolbar select {
        width: 100%;
        max-width: none;
    }

    .format-chip {
        font-size: 10px;
    }

    .preview-stage {
        padding: 25px 12px;
    }

    .template-canvas {
        width: 300px;
        height: 171px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .app-loading-progress span {
        animation: none;
    }
}
