:root {
    color-scheme: light;
    --bg: #f7f6f1;
    --surface: #ffffff;
    --surface-alt: #f1f6f3;
    --ink: #26231f;
    --muted: #706a60;
    --line: #ddd7cc;
    --brand: #276749;
    --brand-dark: #1f4f39;
    --accent: #b84c2f;
    --amber: #c28a2e;
    --danger: #a33a34;
    --shadow: 0 12px 34px rgba(52, 45, 36, 0.12);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-width: 320px;
    background: var(--bg);
    color: var(--ink);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    line-height: 1.45;
}

[hidden] {
    display: none !important;
}

a {
    color: inherit;
}

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

.app-header {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 14px clamp(16px, 4vw, 36px);
    background: rgba(255, 255, 255, 0.92);
    border-bottom: 1px solid var(--line);
    backdrop-filter: blur(14px);
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
    text-decoration: none;
}

.brand-mark {
    display: grid;
    width: 42px;
    height: 42px;
    place-items: center;
    flex: 0 0 auto;
    border-radius: 8px;
    background: var(--brand);
    color: #fff;
    font-weight: 800;
}

.brand strong,
.brand small {
    display: block;
}

.brand strong {
    font-size: 15px;
}

.brand small {
    color: var(--muted);
    font-size: 12px;
}

.top-nav {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.top-nav a {
    padding: 9px 12px;
    border-radius: 8px;
    color: var(--muted);
    text-decoration: none;
    font-weight: 650;
}

.top-nav a.active,
.top-nav a:hover {
    background: var(--surface-alt);
    color: var(--brand-dark);
}

.nav-user {
    display: inline-flex;
    align-items: center;
    min-height: 40px;
    padding: 0 10px;
    color: var(--muted);
    font-size: 13px;
    font-weight: 750;
}

.page-shell {
    width: min(1240px, calc(100% - 32px));
    margin: 0 auto;
    padding: 28px 0 72px;
}

.page-title-row,
.detail-hero {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 20px;
    margin-bottom: 20px;
}

.page-title-row h1,
.detail-hero h1 {
    margin: 0;
    font-size: clamp(28px, 4vw, 42px);
    line-height: 1.08;
}

.detail-hero p,
.item-card p,
.long-note {
    color: var(--muted);
}

.hero-image,
.manual-image,
.menu-thumb {
    display: grid;
    place-items: center;
    object-fit: cover;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface-alt);
    color: var(--brand-dark);
    font-weight: 850;
}

.hero-image {
    width: 128px;
    height: 128px;
    flex: 0 0 auto;
}

.manual-image {
    width: 116px;
    height: 116px;
    flex: 0 0 auto;
}

.menu-thumb {
    width: 64px;
    height: 64px;
    font-size: 18px;
}

.eyebrow {
    margin: 0 0 6px;
    color: var(--accent);
    font-size: 12px;
    font-weight: 800;
    text-transform: uppercase;
}

.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 42px;
    padding: 9px 14px;
    border: 1px solid var(--brand);
    border-radius: 8px;
    background: var(--brand);
    color: #fff;
    text-decoration: none;
    font-weight: 750;
    cursor: pointer;
    white-space: nowrap;
}

.button:hover {
    background: var(--brand-dark);
}

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

.button.secondary:hover {
    background: var(--surface-alt);
}

.button.ghost {
    border-color: transparent;
    background: transparent;
    color: var(--muted);
}

.button.ghost:hover {
    background: #eee9df;
    color: var(--ink);
}

.button.danger,
.danger {
    color: var(--danger);
}

.button.danger {
    border-color: rgba(163, 58, 52, 0.22);
}

.icon-button {
    display: grid;
    width: 36px;
    height: 36px;
    place-items: center;
    border: 0;
    border-radius: 8px;
    background: #eee9df;
    color: var(--ink);
    cursor: pointer;
}

.toolbar,
.form-section,
.detail-section,
.empty-state {
    margin-bottom: 18px;
    padding: 18px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
}

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

.search-field {
    flex: 1 1 300px;
}

.flash {
    margin-bottom: 16px;
    padding: 12px 14px;
    border: 1px solid rgba(39, 103, 73, 0.24);
    border-radius: 8px;
    background: #edf7f1;
    color: var(--brand-dark);
    font-weight: 700;
}

.item-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(270px, 1fr));
    gap: 14px;
}

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

.report-card {
    display: flex;
    min-height: 250px;
    flex-direction: column;
    justify-content: space-between;
    gap: 18px;
    padding: 20px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    box-shadow: 0 8px 24px rgba(52, 45, 36, 0.06);
}

.report-card h2 {
    margin: 0 0 8px;
    font-size: 24px;
}

.report-card p {
    color: var(--muted);
}

.item-card {
    display: flex;
    min-height: 260px;
    flex-direction: column;
    padding: 18px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    box-shadow: 0 8px 24px rgba(52, 45, 36, 0.06);
}

.item-card h2 {
    margin: 14px 0 8px;
    font-size: 20px;
    line-height: 1.22;
}

.item-card p {
    margin: 0 0 14px;
}

.item-card-top,
.card-actions,
.hero-actions,
.section-head,
.modal-head,
.modal-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.hero-actions,
.card-actions,
.modal-actions {
    justify-content: flex-start;
    flex-wrap: wrap;
}

.card-actions {
    margin-top: auto;
}

.report-actions,
.report-actions-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.report-actions-bar {
    justify-content: space-between;
    margin-bottom: 18px;
    padding: 14px 18px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
}

.entry-day-panel {
    display: grid;
    grid-template-columns: minmax(190px, 0.7fr) minmax(0, 1.6fr) auto;
    gap: 14px;
    align-items: center;
    margin-bottom: 18px;
    padding: 16px 18px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
}

.entry-day-current h2 {
    margin: 0;
    font-size: 24px;
    line-height: 1.18;
}

.entry-day-controls,
.entry-date-form,
.entry-day-links,
.recent-date-strip {
    display: flex;
    align-items: end;
    gap: 10px;
    flex-wrap: wrap;
}

.entry-date-form .field {
    min-width: 170px;
}

.compact-button {
    min-height: 38px;
    padding-inline: 12px;
}

.entry-day-links {
    justify-content: flex-end;
}

.recent-date-strip {
    grid-column: 1 / -1;
    align-items: center;
    padding-top: 12px;
    border-top: 1px solid var(--line);
}

.recent-date-strip span {
    color: var(--muted);
    font-size: 12px;
    font-weight: 800;
    text-transform: uppercase;
}

.recent-date-strip a {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    min-height: 32px;
    padding: 5px 9px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fbfaf7;
    color: var(--ink);
    font-size: 13px;
    font-weight: 800;
    text-decoration: none;
}

.recent-date-strip a.active,
.recent-date-strip a:hover {
    border-color: rgba(39, 103, 73, 0.32);
    background: var(--surface-alt);
    color: var(--brand-dark);
}

.recent-date-strip small {
    display: grid;
    min-width: 22px;
    height: 22px;
    place-items: center;
    border-radius: 999px;
    background: #eee9df;
    color: var(--muted);
    font-size: 11px;
}

.entry-date-badge {
    display: inline-flex;
    align-items: center;
    min-height: 32px;
    padding: 5px 10px;
    border-radius: 8px;
    background: var(--surface-alt);
    color: var(--brand-dark);
    font-size: 13px;
    font-weight: 850;
}

.report-title-block {
    display: grid;
    grid-template-columns: minmax(220px, 0.8fr) minmax(0, 1.4fr);
    gap: 20px;
    align-items: center;
    margin-bottom: 18px;
    padding: 18px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
}

.report-title-block h1 {
    margin: 0;
    font-size: clamp(26px, 4vw, 38px);
}

.report-title-block p {
    margin: 8px 0 0;
    color: var(--muted);
}

.report-brand {
    display: flex;
    align-items: center;
    gap: 12px;
}

.report-brand strong,
.report-brand small {
    display: block;
}

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

.mobile-report-list {
    display: none;
    gap: 12px;
}

.mobile-report-card {
    display: grid;
    grid-template-columns: 72px minmax(0, 1fr);
    gap: 12px;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fbfaf7;
}

.mobile-report-card h2 {
    margin: 8px 0 6px;
    font-size: 18px;
}

.manual-report {
    display: grid;
    gap: 18px;
}

.manual-item {
    padding: 20px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
}

.manual-item-header {
    display: flex;
    gap: 16px;
    align-items: center;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--line);
}

.manual-item-header h2 {
    margin: 0;
    font-size: 28px;
}

.manual-item-header p {
    color: var(--muted);
}

.manual-section {
    margin-top: 16px;
    break-inside: avoid;
    page-break-inside: avoid;
}

.manual-section h3 {
    margin: 0 0 10px;
    padding-bottom: 7px;
    border-bottom: 1px solid var(--line);
    font-size: 18px;
}

.manual-table {
    break-inside: avoid;
    page-break-inside: avoid;
}

.phase-list {
    margin: 0 0 12px;
    padding-left: 22px;
}

.phase-list li + li {
    margin-top: 6px;
}

.phase-flow {
    margin: 0;
    padding: 10px 12px;
    border-radius: 8px;
    background: var(--surface-alt);
    color: var(--brand-dark);
    font-weight: 700;
}

.sop-checklist {
    display: grid;
    gap: 8px;
    margin: 0;
    padding: 0;
    list-style: none;
}

.sop-checklist li {
    display: grid;
    gap: 4px;
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fbfaf7;
}

.sop-checklist li::before {
    content: "";
    width: 14px;
    height: 14px;
    border: 1px solid var(--brand);
    border-radius: 3px;
    grid-row: 1 / span 2;
}

.sop-checklist li {
    grid-template-columns: 18px minmax(0, 1fr);
}

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

.pill {
    display: inline-flex;
    align-items: center;
    min-height: 28px;
    padding: 4px 9px;
    border-radius: 999px;
    background: #f7eadb;
    color: #884521;
    font-size: 12px;
    font-weight: 800;
}

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

.mini-meta,
.detail-meta {
    display: grid;
    gap: 10px;
    margin: 0 0 16px;
}

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

.detail-meta {
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}

.mini-meta div,
.detail-meta div {
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fbfaf7;
}

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

dd {
    margin: 4px 0 0;
    font-weight: 750;
}

.detail-section h2,
.form-section h2 {
    margin: 0 0 14px;
    font-size: 20px;
}

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

.detail-table {
    width: 100%;
    border-collapse: collapse;
    min-width: 640px;
}

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

.detail-table th {
    color: var(--muted);
    font-size: 12px;
    text-transform: uppercase;
}

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

.field {
    display: grid;
    gap: 6px;
    min-width: 0;
}

.field > span,
.check-field span {
    color: var(--muted);
    font-size: 12px;
    font-weight: 800;
    text-transform: uppercase;
}

.field-label-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.field-label-actions span {
    color: var(--muted);
    font-size: 12px;
    font-weight: 800;
    text-transform: uppercase;
}

.field-label-actions a {
    color: var(--brand-dark);
    font-size: 12px;
    font-weight: 800;
    text-decoration: none;
}

.field-label-actions a:hover {
    text-decoration: underline;
}

.field input,
.field select,
.field textarea {
    width: 100%;
    min-height: 42px;
    padding: 9px 10px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    color: var(--ink);
}

.field textarea {
    resize: vertical;
}

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

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

.field.short {
    min-width: 120px;
}

.check-field {
    display: inline-flex;
    align-items: center;
    align-self: end;
    min-height: 42px;
    gap: 9px;
    padding: 8px 10px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fbfaf7;
}

.check-field.compact {
    align-self: center;
}

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

.relation-row {
    display: grid;
    grid-template-columns: minmax(210px, 1.3fr) minmax(100px, 0.5fr) minmax(150px, 0.8fr) minmax(220px, 1.4fr) auto;
    gap: 10px;
    align-items: end;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fbfaf7;
}

.relation-row.simple-row {
    grid-template-columns: minmax(230px, 1fr) minmax(260px, 2fr) auto;
}

.entry-form-grid {
    grid-template-columns: minmax(150px, 0.7fr) minmax(260px, 1.5fr) minmax(120px, 0.6fr) minmax(130px, 0.7fr);
    align-items: end;
}

.sales-entry-grid {
    grid-template-columns: minmax(150px, 0.7fr) minmax(300px, 1.8fr) minmax(130px, 0.7fr) minmax(130px, 0.7fr);
}

.summary-entry-grid {
    grid-template-columns: repeat(3, minmax(180px, 1fr));
    align-items: end;
}

.summary-entry-grid .field.wide {
    grid-column: 1 / -1;
}

.summary-total-field input[readonly] {
    border-color: rgba(39, 103, 73, 0.38);
    background: var(--surface-alt);
    color: var(--brand-dark);
    font-size: 18px;
    font-weight: 850;
}

.summary-metrics dd {
    font-size: 18px;
}

.summary-metrics div:nth-child(4) dd,
.summary-saved-panel .summary-metrics div:last-child dd,
.summary-report-table td:nth-child(4) {
    color: var(--brand-dark);
}

.entry-form-actions,
.inline-filter,
.table-actions {
    display: flex;
    align-items: end;
    gap: 10px;
    flex-wrap: wrap;
}

.entry-form-actions {
    grid-column: 1 / -1;
    justify-content: flex-end;
}

.inline-filter {
    justify-content: flex-end;
}

.table-actions {
    align-items: center;
}

.table-actions form {
    margin: 0;
}

.sticky-actions {
    position: sticky;
    bottom: 0;
    z-index: 10;
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 18px;
    padding: 14px 0 0;
    background: linear-gradient(to top, var(--bg) 72%, rgba(247, 246, 241, 0));
}

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

.master-tabs {
    display: grid;
    align-content: start;
    gap: 6px;
    padding: 10px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
}

.master-tabs a {
    padding: 9px 10px;
    border-radius: 8px;
    color: var(--muted);
    text-decoration: none;
    font-weight: 700;
}

.master-tabs a.active,
.master-tabs a:hover {
    background: var(--surface-alt);
    color: var(--brand-dark);
}

.master-content {
    min-width: 0;
}

.master-add-form,
.master-row,
.master-row-form {
    display: grid;
    gap: 10px;
    align-items: end;
}

.master-add-form {
    grid-template-columns: minmax(220px, 1fr) minmax(260px, 2fr) auto;
}

.master-add-form.with-ingredient-type {
    grid-template-columns: minmax(180px, 1fr) minmax(180px, 0.8fr) minmax(220px, 1.4fr) auto;
}

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

.master-row {
    grid-template-columns: minmax(0, 1fr) auto auto;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fbfaf7;
}

.master-row-form {
    grid-template-columns: minmax(180px, 1fr) minmax(220px, 1.4fr) auto auto;
}

.master-row-form.with-ingredient-type {
    grid-template-columns: minmax(160px, 1fr) minmax(170px, 0.8fr) minmax(200px, 1.2fr) auto auto;
}

.modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: 50;
    display: grid;
    place-items: center;
    padding: 20px;
    background: rgba(22, 20, 18, 0.52);
}

.modal-backdrop[hidden] {
    display: none;
}

.modal-panel {
    width: min(480px, 100%);
    padding: 18px;
    border-radius: 8px;
    background: var(--surface);
    box-shadow: var(--shadow);
}

.modal-head h2 {
    margin: 0;
}

.modal-panel form {
    display: grid;
    gap: 14px;
}

.form-error {
    margin: 0;
    color: var(--danger);
    font-weight: 700;
}

.empty-state {
    text-align: center;
}

.empty-state h1,
.empty-state h2 {
    margin-top: 0;
}

.login-body {
    display: grid;
    min-height: 100vh;
    place-items: center;
    padding: 20px;
    background: linear-gradient(135deg, #f7f6f1 0%, #edf7f1 55%, #f8eadf 100%);
}

.login-shell {
    width: min(460px, 100%);
}

.login-card {
    display: grid;
    gap: 18px;
    padding: 24px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.95);
    box-shadow: var(--shadow);
}

.login-card form {
    display: grid;
    gap: 14px;
}

.login-brand {
    display: flex;
    gap: 14px;
    align-items: center;
}

.login-brand h1 {
    margin: 0;
    font-size: 25px;
    line-height: 1.16;
}

.login-hint {
    margin: 0;
    color: var(--muted);
    font-size: 13px;
}

@media (max-width: 980px) {
    .form-grid,
    .relation-row,
    .relation-row.simple-row,
    .entry-form-grid,
    .sales-entry-grid,
    .summary-entry-grid,
    .master-layout,
    .master-add-form,
    .master-row,
    .master-row-form {
        grid-template-columns: 1fr;
    }

    .field.wide {
        grid-column: auto;
    }

    .report-title-block {
        grid-template-columns: 1fr;
    }

    .entry-day-panel {
        grid-template-columns: 1fr;
        align-items: stretch;
    }

    .entry-day-links {
        justify-content: flex-start;
    }

    .report-table-wrap {
        display: none;
    }

    .mobile-report-list {
        display: grid;
    }
}

@media (max-width: 720px) {
    .app-header,
    .page-title-row,
    .detail-hero,
    .section-head {
        align-items: stretch;
        flex-direction: column;
    }

    .app-header {
        position: static;
    }

    .top-nav {
        justify-content: flex-start;
    }

    .page-shell {
        width: min(100% - 20px, 1240px);
        padding-top: 18px;
    }

    .toolbar,
    .card-actions,
    .hero-actions,
    .sticky-actions,
    .entry-form-actions,
    .inline-filter,
    .entry-day-controls,
    .entry-date-form,
    .entry-day-links,
    .recent-date-strip {
        align-items: stretch;
        flex-direction: column;
    }

    .entry-date-form .field {
        min-width: 0;
    }

    .button {
        width: 100%;
    }

    .mini-meta {
        grid-template-columns: 1fr;
    }

    .manual-item-header,
    .detail-hero {
        align-items: stretch;
    }

    .hero-image,
    .manual-image {
        width: 100%;
        height: 150px;
    }
}

@page {
    margin: 14mm;
    @bottom-right {
        content: "Page " counter(page);
    }
}

@media print {
    body {
        background: #fff;
        color: #000;
        font-size: 11px;
    }

    .app-header,
    .no-print,
    .modal-backdrop,
    .sticky-actions {
        display: none !important;
    }

    .page-shell {
        width: 100%;
        padding: 0;
    }

    .report-title-block,
    .detail-section,
    .manual-item,
    .manual-section {
        box-shadow: none;
        border-color: #bbb;
    }

    .report-title-block {
        grid-template-columns: 1fr 2fr;
    }

    .report-table {
        min-width: 0;
        font-size: 10px;
    }

    .detail-table th,
    .detail-table td {
        padding: 6px;
    }

    .manual-item {
        break-before: page;
        page-break-before: always;
        margin: 0;
        padding: 0;
        border: 0;
    }

    .manual-item:first-child {
        break-before: auto;
        page-break-before: auto;
    }

    .manual-item-header,
    .manual-section,
    .overall-section,
    tr,
    table {
        break-inside: avoid;
        page-break-inside: avoid;
    }

    .mobile-report-list {
        display: none !important;
    }

    .report-table-wrap {
        display: block !important;
        overflow: visible;
    }
}
