:root {
    --bg: #f5f7fb;
    --surface: #ffffff;
    --surface-2: #eef2f7;
    --text: #172033;
    --muted: #667085;
    --line: #d8dee9;
    --primary: #0f766e;
    --primary-strong: #115e59;
    --accent: #2563eb;
    --danger: #dc2626;
    --warning: #b7791f;
    --success: #15803d;
    --shadow: 0 12px 34px rgba(15, 23, 42, .08);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    font-size: 14px;
}

body.menu-open {
    overflow: hidden;
}

a {
    color: inherit;
    text-decoration: none;
}

.sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: 255px;
    background: #0b1220;
    color: #e5e7eb;
    padding: 22px 16px;
    overflow-y: auto;
}

.mobile-overlay,
.mobile-topbar {
    display: none;
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 26px;
}

.brand-mark {
    display: grid;
    place-items: center;
    width: 42px;
    height: 42px;
    border-radius: 8px;
    background: #14b8a6;
    color: #052e2b;
    font-weight: 800;
}

.brand small {
    display: block;
    color: #94a3b8;
    font-size: 12px;
    margin-top: 2px;
}

.nav {
    display: grid;
    gap: 5px;
}

.nav a {
    border-radius: 8px;
    color: #cbd5e1;
    padding: 11px 12px;
}

.nav a:hover,
.nav a.active {
    background: rgba(20, 184, 166, .14);
    color: #ffffff;
}

.app-shell {
    margin-left: 255px;
    min-height: 100vh;
    padding: 28px;
}

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

.topbar h1,
.install-box h1 {
    margin: 2px 0 0;
    font-size: 28px;
    letter-spacing: 0;
}

.eyebrow {
    margin: 0;
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
    letter-spacing: .08em;
    text-transform: uppercase;
}

.grid {
    display: grid;
    gap: 16px;
}

.grid.two {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
}

.grid.three {
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

.grid.four {
    grid-template-columns: repeat(4, minmax(0, 1fr));
}

.panel,
.metric,
.install-box {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
}

.panel {
    padding: 18px;
}

.panel-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 14px;
}

.panel-header h2,
.panel h2,
.section-title {
    margin: 0;
    font-size: 17px;
}

.panel-header p,
.muted {
    color: var(--muted);
}

.metric {
    padding: 16px;
}

.metric span {
    color: var(--muted);
    display: block;
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
}

.metric strong {
    display: block;
    font-size: 24px;
    margin-top: 8px;
}

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

.metric.positive strong {
    color: var(--success);
}

.metric.negative strong {
    color: var(--danger);
}

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

table {
    width: 100%;
    border-collapse: collapse;
}

th,
td {
    border-bottom: 1px solid var(--line);
    padding: 11px 9px;
    text-align: left;
    vertical-align: top;
}

th {
    color: var(--muted);
    font-size: 12px;
    font-weight: 800;
    text-transform: uppercase;
}

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

.number {
    text-align: right;
    white-space: nowrap;
}

.form-grid {
    align-items: start;
    display: grid;
    gap: 14px;
    grid-template-columns: repeat(4, minmax(0, 1fr));
}

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

.form-grid.three {
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

.field {
    align-content: start;
    display: grid;
    gap: 7px;
}

.field.full {
    grid-column: 1 / -1;
}

label {
    color: #344054;
    font-size: 12px;
    font-weight: 800;
    text-transform: uppercase;
}

input,
select,
textarea {
    width: 100%;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    color: var(--text);
    font: inherit;
    padding: 10px 11px;
}

input,
select {
    min-height: 47px;
}

.field small {
    display: block;
    line-height: 1.42;
}

textarea {
    min-height: 82px;
    resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
    border-color: var(--primary);
    outline: 3px solid rgba(20, 184, 166, .16);
}

.button,
button {
    align-items: center;
    border: 0;
    border-radius: 8px;
    cursor: pointer;
    display: inline-flex;
    font: inherit;
    font-weight: 800;
    justify-content: center;
    min-height: 40px;
    padding: 10px 14px;
}

.button.primary,
button.primary {
    background: var(--primary);
    color: #ffffff;
}

.button.primary:hover,
button.primary:hover {
    background: var(--primary-strong);
}

.button.subtle,
button.subtle {
    background: var(--surface-2);
    color: var(--text);
}

.button.danger,
button.danger {
    background: #fee2e2;
    color: #991b1b;
}

.actions {
    display: flex;
    flex-wrap: wrap;
    gap: 9px;
    margin-top: 14px;
}

.row-actions {
    align-items: center;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: flex-end;
}

.inline-form {
    display: inline-flex;
    margin: 0;
}

.image-thumb {
    background: transparent;
    border: 0;
    min-height: 0;
    padding: 0;
}

.image-thumb img {
    border: 1px solid var(--line);
    border-radius: 8px;
    display: block;
    height: 72px;
    object-fit: cover;
    width: 72px;
}

.image-modal {
    display: grid;
    inset: 0;
    place-items: center;
    position: fixed;
    z-index: 80;
}

.image-modal[hidden] {
    display: none !important;
}

.image-modal-backdrop {
    background: rgba(15, 23, 42, .72);
    border-radius: 0;
    inset: 0;
    min-height: 0;
    padding: 0;
    position: absolute;
    width: 100%;
}

.image-modal-dialog {
    background: var(--surface);
    border-radius: 8px;
    box-shadow: 0 22px 70px rgba(15, 23, 42, .34);
    max-height: 92vh;
    max-width: min(92vw, 980px);
    overflow: hidden;
    position: relative;
    width: max-content;
}

.image-modal-header {
    align-items: center;
    border-bottom: 1px solid var(--line);
    display: flex;
    gap: 12px;
    justify-content: space-between;
    padding: 11px 12px;
}

.image-modal-close {
    background: var(--surface-2);
    color: var(--text);
    height: 36px;
    min-height: 36px;
    padding: 0;
    width: 36px;
}

.image-modal-dialog img {
    display: block;
    max-height: calc(92vh - 59px);
    max-width: min(92vw, 980px);
    object-fit: contain;
}

.alert {
    border-radius: 8px;
    margin-bottom: 16px;
    padding: 12px 14px;
}

.alert.success {
    background: #dcfce7;
    color: #166534;
}

.alert.error,
.alert.danger {
    background: #fee2e2;
    color: #991b1b;
}

.alert.warning {
    background: #fef3c7;
    color: #92400e;
}

.badge {
    border-radius: 999px;
    display: inline-flex;
    font-size: 12px;
    font-weight: 800;
    padding: 4px 9px;
}

.badge.success {
    background: #dcfce7;
    color: #166534;
}

.badge.warning {
    background: #fef3c7;
    color: #92400e;
}

.badge.danger {
    background: #fee2e2;
    color: #991b1b;
}

.stat-list {
    display: grid;
    gap: 10px;
}

.stat-row {
    align-items: center;
    display: grid;
    gap: 12px;
    grid-template-columns: minmax(120px, 1fr) minmax(140px, 2fr) auto;
}

.bar {
    background: #e2e8f0;
    border-radius: 999px;
    height: 9px;
    overflow: hidden;
}

.bar span {
    background: var(--accent);
    display: block;
    height: 100%;
}

.product-showcase {
    display: grid;
    gap: 16px;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
}

.product-card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-left: 5px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
    display: grid;
    gap: 14px;
    padding: 16px;
}

.product-card.positive {
    border-left-color: var(--success);
}

.product-card.negative {
    border-left-color: var(--danger);
}

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

.product-card-header h2 {
    font-size: 16px;
    margin: 0;
}

.product-card-header p {
    margin: 5px 0 0;
}

.product-money span,
.product-stats span {
    color: var(--muted);
    display: block;
    font-size: 11px;
    font-weight: 800;
    text-transform: uppercase;
}

.product-money strong {
    display: block;
    font-size: 24px;
    margin-top: 5px;
}

.product-money small {
    color: var(--muted);
}

.product-money.positive strong,
.profit-positive {
    color: var(--success);
}

.product-money.negative strong,
.profit-negative {
    color: var(--danger);
}

.product-stats {
    display: grid;
    gap: 10px;
    grid-template-columns: 1fr 1fr;
}

.product-stats div {
    background: var(--surface-2);
    border-radius: 8px;
    padding: 10px;
}

.product-stats strong {
    display: block;
    margin-top: 4px;
}

.chart-box {
    height: 300px;
    width: 100%;
}

.chart-box canvas {
    display: block;
    height: 100%;
    width: 100%;
}

.toolbar {
    align-items: end;
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
}

.toolbar .field {
    min-width: 180px;
}

.recipe-lines {
    display: grid;
    gap: 10px;
}

.recipe-line {
    display: grid;
    gap: 10px;
    grid-template-columns: minmax(260px, 2fr) minmax(110px, .8fr) minmax(90px, .7fr) 70px;
}

.ingredient-combobox,
.select-combobox {
    position: relative;
}

.ingredient-combo-input,
.select-combo-input {
    padding-right: 34px;
}

.ingredient-combobox::after,
.select-combobox::after {
    border-left: 5px solid transparent;
    border-right: 5px solid transparent;
    border-top: 6px solid var(--muted);
    content: "";
    pointer-events: none;
    position: absolute;
    right: 14px;
    top: 21px;
}

.ingredient-options,
.select-combo-options {
    background: var(--surface);
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    box-shadow: 0 14px 34px rgba(15, 23, 42, .16);
    left: 0;
    max-height: 260px;
    overflow-y: auto;
    padding: 6px;
    position: absolute;
    right: 0;
    top: calc(100% + 5px);
    z-index: 25;
}

.ingredient-options[hidden],
.ingredient-options button[hidden],
.ingredient-empty[hidden],
.select-combo-options[hidden],
.select-combo-options button[hidden],
.select-combo-empty[hidden] {
    display: none !important;
}

.ingredient-options button,
.select-combo-options button {
    background: transparent;
    border-radius: 6px;
    color: var(--text);
    display: flex;
    justify-content: space-between;
    min-height: 38px;
    padding: 8px 10px;
    text-align: left;
    width: 100%;
}

.ingredient-options button:hover,
.ingredient-options button:focus,
.select-combo-options button:hover,
.select-combo-options button:focus {
    background: var(--surface-2);
    outline: 0;
}

.ingredient-options small {
    color: var(--muted);
    font-weight: 700;
}

.ingredient-empty,
.select-combo-empty {
    color: var(--muted);
    padding: 12px 10px;
    text-align: center;
}

.native-combo-select {
    clip-path: inset(50%);
    height: 1px !important;
    margin: -1px;
    opacity: 0;
    overflow: hidden;
    pointer-events: none;
    position: absolute !important;
    white-space: nowrap;
    width: 1px !important;
}

.install-page {
    display: grid;
    min-height: 100vh;
    place-items: center;
}

.install-box {
    max-width: 520px;
    padding: 28px;
}

.empty-state {
    border: 1px dashed var(--line);
    border-radius: 8px;
    color: var(--muted);
    padding: 24px;
    text-align: center;
}

.is-hidden {
    display: none !important;
}

@media (max-width: 1000px) {
    .grid.four,
    .grid.three,
    .grid.two,
    .form-grid,
    .form-grid.two,
    .form-grid.three {
        grid-template-columns: 1fr 1fr;
    }

    .recipe-line {
        grid-template-columns: 1fr 1fr;
    }
}

@media (max-width: 760px) {
    .sidebar {
        height: 100vh;
        left: 0;
        padding: 20px 16px;
        position: fixed;
        top: 0;
        transform: translateX(-104%);
        transition: transform .22s ease;
        width: min(82vw, 310px);
        z-index: 40;
    }

    body.menu-open .sidebar {
        transform: translateX(0);
    }

    .mobile-overlay {
        background: rgba(15, 23, 42, .48);
        display: block;
        inset: 0;
        opacity: 0;
        pointer-events: none;
        position: fixed;
        transition: opacity .22s ease;
        z-index: 30;
    }

    body.menu-open .mobile-overlay {
        opacity: 1;
        pointer-events: auto;
    }

    .app-shell {
        margin-left: 0;
        padding: 14px;
        padding-top: 74px;
    }

    .mobile-topbar {
        align-items: center;
        background: #ffffff;
        border-bottom: 1px solid var(--line);
        box-shadow: 0 8px 24px rgba(15, 23, 42, .08);
        display: flex;
        gap: 12px;
        height: 58px;
        left: 0;
        padding: 0 14px;
        position: fixed;
        right: 0;
        top: 0;
        z-index: 20;
    }

    .menu-toggle {
        background: var(--surface-2);
        display: inline-grid;
        gap: 4px;
        height: 42px;
        min-height: 42px;
        padding: 10px;
        width: 42px;
    }

    .menu-toggle span {
        background: var(--text);
        border-radius: 999px;
        display: block;
        height: 2px;
        width: 20px;
    }

    .mobile-brand {
        font-size: 16px;
        font-weight: 900;
    }

    .topbar {
        align-items: stretch;
        flex-direction: column;
        margin-bottom: 14px;
    }

    .topbar h1 {
        font-size: 30px;
        line-height: 1.16;
        overflow-wrap: anywhere;
    }

    .grid.four,
    .grid.three,
    .grid.two,
    .form-grid,
    .form-grid.two,
    .form-grid.three,
    .recipe-line {
        grid-template-columns: 1fr;
    }

    .stat-row {
        grid-template-columns: 1fr;
    }
}
