/* ================= DESIGN TOKENS ================= */
:root {
    --bg-canvas: #f8fafc;
    --bg-surface: #ffffff;
    --bg-subtle: #f1f5f9;
    --border-hairline: #e2e8f0;
    --border-strong: #cbd5e1;
    --text-primary: #0f172a;
    --text-secondary: #475569;
    --text-muted: #94a3b8;
    --accent-brand: #0f172a;
    --accent-brand-hover: #1e293b;
    --accent-blue: #2563eb;
    --accent-blue-soft: #eff6ff;
    --accent-blue-border: #bfdbfe;
    --accent-green: #059669;
    --accent-green-soft: #ecfdf5;
    --accent-green-border: #a7f3d0;
    --accent-amber-soft: #fffbeb;
    --accent-amber-border: #fde68a;
    --accent-red: #dc2626;
    --accent-red-soft: #fef2f2;
    --sidebar-w: 236px;
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 14px;
    --shadow-card: 0 1px 3px rgba(15, 23, 42, 0.04), 0 1px 2px rgba(15, 23, 42, 0.03);
    --shadow-float: 0 10px 25px -5px rgba(15, 23, 42, 0.08), 0 4px 10px -6px rgba(15, 23, 42, 0.04);
}

* {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

body {
    margin: 0;
    font-family: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, sans-serif;
    background-color: var(--bg-canvas);
    color: var(--text-primary);
    -webkit-font-smoothing: antialiased;
    min-height: 100vh;
}

/* ================= APP SHELL WITH LEFT SIDEBAR ================= */
.app-shell {
    display: flex;
    min-height: 100vh;
    width: 100%;
}

.app-sidebar {
    width: var(--sidebar-w);
    background: var(--bg-surface);
    border-right: 1px solid var(--border-hairline);
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: 20px 14px;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 200;
    transition: transform 0.22s cubic-bezier(0.16, 1, 0.3, 1);
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 4px 8px 18px 8px;
    border-bottom: 1px solid var(--border-hairline);
    margin-bottom: 16px;
    text-decoration: none;
    color: var(--text-primary);
}

.brand-mark {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    background: var(--accent-brand);
    color: #ffffff;
    display: grid;
    place-items: center;
    font-family: 'Outfit', sans-serif;
    font-weight: 800;
    font-size: 1rem;
    flex-shrink: 0;
}

.brand-text-wrap {
    display: flex;
    flex-direction: column;
}

.brand-title {
    font-family: 'Outfit', sans-serif;
    font-weight: 800;
    font-size: 1.02rem;
    line-height: 1.1;
    letter-spacing: -0.02em;
}

.brand-sub {
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--text-muted);
    margin-top: 2px;
}

.nav-section-title {
    font-size: 0.68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    color: var(--text-muted);
    padding: 0 10px 8px 10px;
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 10px 12px;
    border-radius: 8px;
    text-decoration: none;
    color: var(--text-secondary);
    font-size: 0.88rem;
    font-weight: 600;
    transition: all 0.15s ease;
}

.sidebar-link svg {
    width: 18px;
    height: 18px;
    stroke: currentColor;
    fill: none;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
    flex-shrink: 0;
}

.sidebar-link:hover {
    background: var(--bg-subtle);
    color: var(--text-primary);
}

.sidebar-link.active {
    background: var(--accent-brand);
    color: #ffffff;
    box-shadow: 0 2px 6px rgba(15, 23, 42, 0.14);
}

.sidebar-footer {
    padding: 12px 10px 4px 10px;
    border-top: 1px solid var(--border-hairline);
    font-size: 0.74rem;
    color: var(--text-muted);
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.sidebar-footer strong {
    color: var(--text-secondary);
    font-weight: 700;
}

.app-main {
    margin-left: var(--sidebar-w);
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.mobile-topbar {
    display: none;
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border-hairline);
    padding: 0 14px;
    height: 54px;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 150;
}

.menu-toggle-btn {
    background: var(--bg-subtle);
    border: 1px solid var(--border-hairline);
    color: var(--text-primary);
    width: 36px;
    height: 36px;
    border-radius: 8px;
    display: grid;
    place-items: center;
    cursor: pointer;
    padding: 0;
}

.sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.45);
    backdrop-filter: blur(2px);
    z-index: 190;
}

.sidebar-backdrop.visible {
    display: block;
}

/* ================= SHARED SURFACES & FORMS ================= */
.page-container {
    max-width: 1040px;
    width: 100%;
    margin: 26px auto;
    padding: 0 22px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

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

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 12px;
    margin-bottom: 18px;
}

.card-title {
    margin: 0;
    font-family: 'Outfit', sans-serif;
    font-size: 1.12rem;
    font-weight: 800;
    letter-spacing: -0.01em;
    color: var(--text-primary);
}

.card-subtitle {
    margin: 3px 0 0 0;
    font-size: 0.82rem;
    color: var(--text-secondary);
}

.section-label {
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
    margin-bottom: 8px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.form-row-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.form-row-3 {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 10px;
}

label.field-label {
    font-size: 0.73rem;
    font-weight: 700;
    color: var(--text-secondary);
    letter-spacing: 0.02em;
}

input[type="text"],
input[type="date"],
input[type="number"],
select,
textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    font-family: 'Plus Jakarta Sans', sans-serif;
    font-size: 0.9rem;
    color: var(--text-primary);
    background: var(--bg-surface);
    transition: border-color 0.15s, box-shadow 0.15s;
}

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--accent-brand);
    box-shadow: 0 0 0 3px rgba(15, 23, 42, 0.08);
}

textarea {
    resize: vertical;
    min-height: 66px;
    line-height: 1.4;
}

.mono {
    font-family: 'JetBrains Mono', monospace;
    font-variant-numeric: tabular-nums;
}

/* ================= BUTTONS ================= */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    border: none;
    border-radius: var(--radius-sm);
    padding: 11px 16px;
    font-family: 'Plus Jakarta Sans', sans-serif;
    font-weight: 700;
    font-size: 0.88rem;
    cursor: pointer;
    transition: all 0.15s ease;
}

.btn:active { transform: scale(0.99); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }

.btn-primary {
    background: var(--accent-brand);
    color: #ffffff;
}
.btn-primary:hover:not(:disabled) { background: var(--accent-brand-hover); }

.btn-secondary {
    background: var(--bg-subtle);
    color: var(--text-primary);
    border: 1px solid var(--border-hairline);
}
.btn-secondary:hover:not(:disabled) { background: #e2e8f0; }

.btn-bt {
    background: var(--accent-blue);
    color: #ffffff;
    width: 100%;
}
.btn-bt.connected {
    background: var(--accent-green);
}

.btn-xs {
    padding: 5px 10px;
    font-size: 0.75rem;
    border-radius: 5px;
    font-weight: 700;
    border: none;
    cursor: pointer;
}
.btn-xs-edit { background: var(--accent-blue-soft); color: var(--accent-blue); }
.btn-xs-del { background: var(--accent-red-soft); color: var(--accent-red); }

/* ================= STATUS TOAST ================= */
.toast {
    font-size: 0.82rem;
    font-weight: 600;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    display: none;
    line-height: 1.4;
}
.toast.ok {
    display: block;
    background: var(--accent-green-soft);
    color: #065f46;
    border: 1px solid var(--accent-green-border);
}
.toast.err {
    display: block;
    background: var(--accent-red-soft);
    color: #991b1b;
    border: 1px solid #fecaca;
}

/* ================= TABLES ================= */
.table-wrap {
    overflow-x: auto;
}

table.clean-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}

table.clean-table th {
    text-align: left;
    padding: 10px 14px;
    font-size: 0.71rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    background: var(--bg-canvas);
    border-bottom: 1px solid var(--border-hairline);
}

table.clean-table td {
    padding: 12px 14px;
    border-bottom: 1px solid var(--border-hairline);
    vertical-align: middle;
}

table.clean-table tr:last-child td {
    border-bottom: none;
}

.chip {
    display: inline-flex;
    align-items: center;
    padding: 3px 8px;
    border-radius: 5px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.76rem;
    font-weight: 700;
}
.chip-neutral { background: var(--bg-subtle); color: var(--text-primary); }
.chip-blue { background: var(--accent-blue-soft); color: var(--accent-blue); border: 1px solid var(--accent-blue-border); }
.chip-green { background: var(--accent-green-soft); color: var(--accent-green); border: 1px solid var(--accent-green-border); }

/* ================= DRAFTING STAGE & EXACT THERMAL LABEL ================= */
.drafting-stage {
    background-color: #f1f5f9;
    background-image: radial-gradient(#cbd5e1 1px, transparent 1px);
    background-size: 18px 18px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: hidden;
}

.stage-pill {
    background: rgba(15, 23, 42, 0.88);
    backdrop-filter: blur(6px);
    color: #ffffff;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.7rem;
    font-weight: 700;
    padding: 5px 12px;
    border-radius: 999px;
    letter-spacing: 0.03em;
    margin-bottom: 28px;
}

.preview-scaler {
    transform-origin: center;
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: var(--col-gap, 0in);
}

.preview-scaler.zero-gap-2up .label-box:first-child {
    border-top-right-radius: 0;
    border-bottom-right-radius: 0;
    border-right-color: #cbd5e1;
}

.preview-scaler.zero-gap-2up .label-box:last-child {
    border-top-left-radius: 0;
    border-bottom-left-radius: 0;
    border-left: none;
}

#capture-stage {
    position: fixed;
    left: -9999px;
    top: 0;
    background: #ffffff;
}

.label-box {
    width: var(--label-w, 2in);
    height: var(--label-h, 1in);
    background-color: #ffffff;
    border: 1px dashed #94a3b8;
    border-radius: 0.1in;
    box-shadow: var(--shadow-float);
    box-sizing: border-box;
    padding: calc(var(--top-mm, 1) * 1mm + 0.02in) 0.05in 0.04in 0.05in;
    display: flex;
    flex-direction: row;
    justify-content: space-between;
    color: #000000;
    overflow: hidden;
    flex-shrink: 0;
}

.label-box.thermal-clean {
    border: none !important;
    border-radius: 0 !important;
    box-shadow: none !important;
}

.main-content {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    width: 85%;
    padding-right: 0.08in;
    border-right: 1.5px solid #000000;
    overflow: hidden;
    position: relative;
}

.main-content.full-width {
    width: 100%;
    padding-right: 0;
    border-right: none;
}

.company-name {
    font-family: 'Plus Jakarta Sans', sans-serif;
    font-size: 4.5pt;
    font-weight: 700;
    text-align: center;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    color: #000000;
}

.item-name {
    font-family: 'Outfit', sans-serif;
    font-size: 7.5pt;
    font-weight: 800;
    text-align: center;
    text-transform: uppercase;
    letter-spacing: 0.2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-top: 1px;
}

/* Eggless indicator placed behind the barcode with zero vertical padding */
.eggless-indicator {
    position: absolute;
    bottom: 0;
    right: 0.04in;
    background-color: transparent;
    padding: 0;
    line-height: 1;
    z-index: 1;
    pointer-events: none;
}

.eggless-text {
    font-family: 'Plus Jakarta Sans', sans-serif;
    font-size: 4pt;
    font-weight: 700;
    letter-spacing: 0.6px;
}

.dates-sidebar {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    width: 15%;
    height: 100%;
    gap: 1px;
}

.date-line {
    font-family: 'JetBrains Mono', monospace;
    writing-mode: vertical-rl;
    font-size: 5pt;
    font-weight: 700;
    white-space: nowrap;
    line-height: 1;
}

.label-box.thermal-clean .date-line {
    visibility: hidden;
}

.barcode-section {
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-end;
    flex-grow: 1;
    padding-top: 1px;
    width: 100%;
    position: relative;
    z-index: 5;
    background-color: transparent;
}

.barcode-svg {
    width: 100%;
    height: 0.37in;
    display: block;
    position: relative;
    z-index: 6;
}

.ingredients-text {
    font-family: 'Plus Jakarta Sans', sans-serif;
    font-size: 4pt;
    font-weight: 400;
    text-align: center;
    width: 100%;
    margin: 1px 0 0 0;
    line-height: 1.15;
}

.product-id-text {
    font-family: 'JetBrains Mono', monospace;
    font-size: 4.5pt;
    font-weight: 700;
    letter-spacing: 1.2px;
    white-space: nowrap;
    margin-top: 1mm;
    background-color: transparent;
    position: relative;
    z-index: 6;
    line-height: 1;
}

/* ================= RESPONSIVE MOBILE SIDEBAR DRAWER ================= */
@media (max-width: 860px) {
    .app-sidebar {
        transform: translateX(-100%);
        width: 260px;
        box-shadow: 0 20px 40px rgba(15, 23, 42, 0.25);
    }
    .app-sidebar.open {
        transform: translateX(0);
    }
    .app-main {
        margin-left: 0;
    }
    .mobile-topbar {
        display: flex;
    }
    .page-container {
        margin: 16px auto;
        padding: 0 12px;
    }
}
