:root {
    --color-bg: #f7f5f2;
    --color-surface: #ffffff;
    --color-border: #e3ddd3;
    --color-text: #262220;
    --color-text-muted: #6b6259;
    --color-accent: #d99c2b;
    --color-accent-dark: #b9800f;
    --color-danger: #b3261e;
    --color-danger-bg: #fbeceb;
    --color-success: #2e6b3e;
    --color-success-bg: #eaf4ec;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background-color: var(--color-bg);
    color: var(--color-text);
    font-family: system-ui, -apple-system, 'Segoe UI', sans-serif;
    line-height: 1.5;
}

a {
    color: var(--color-accent-dark);
}

.app-header {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    gap: 1rem;
    padding: 0.6rem 1.5rem;
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    position: relative;
    z-index: 20;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 0.6rem;
}

.header-center {
    justify-self: center;
}

.header-right {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 1rem;
}

.header-link {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.9rem;
    text-decoration: none;
}

.brand {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 600;
    font-size: 0.95rem;
    color: var(--color-text-muted);
    text-decoration: none;
}

.brand img {
    height: 24px;
    width: 24px;
}

.org-title,
.brewery-switcher summary {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.6rem;
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--color-text);
    text-decoration: none;
}

.org-logo {
    height: 36px;
    width: auto;
    max-width: 160px;
    object-fit: contain;
}

.logo-preview {
    max-height: 80px;
    max-width: 240px;
}

.icon {
    width: 1.15rem;
    height: 1.15rem;
    flex: none;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.profile-menu {
    position: relative;
}

.profile-menu summary {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    list-style: none;
    padding: 0.3rem 0.6rem;
    border-radius: 999px;
    font-size: 0.9rem;
}

.profile-menu summary::-webkit-details-marker {
    display: none;
}

.profile-menu summary:hover,
.profile-menu[open] summary {
    background: var(--color-bg);
}

.profile-menu-list {
    position: absolute;
    right: 0;
    top: calc(100% + 4px);
    min-width: 190px;
    display: flex;
    flex-direction: column;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 6px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
    padding: 0.25rem;
    z-index: 30;
}

.profile-menu-list a {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.5rem 0.6rem;
    border-radius: 4px;
    text-decoration: none;
    color: var(--color-text);
}

.profile-menu-list a:hover {
    background: var(--color-bg);
}

.profile-menu-list .sign-out {
    margin-top: 0.25rem;
    border-top: 1px solid var(--color-border);
    border-radius: 0 0 4px 4px;
}

@media (max-width: 700px) {
    .brand-name,
    .profile-name {
        display: none;
    }
}

.brewery-switcher {
    position: relative;
}

.brewery-switcher summary {
    cursor: pointer;
    list-style: none;
    padding: 0.3rem 0.75rem;
    border: 1px solid var(--color-border);
    border-radius: 6px;
    background: var(--color-bg);
}

.brewery-switcher summary::-webkit-details-marker {
    display: none;
}

.brewery-switcher[open] summary {
    border-color: var(--color-accent);
}

.brewery-switcher-menu {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    top: calc(100% + 4px);
    min-width: 200px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 6px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
    padding: 0.25rem;
    z-index: 10;
}

.brewery-switcher-menu form {
    margin: 0;
}

.brewery-switcher-menu button {
    display: block;
    width: 100%;
    text-align: left;
    padding: 0.5rem 0.6rem;
    border: none;
    background: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.9rem;
    color: var(--color-text);
}

.brewery-switcher-menu button:hover {
    background: var(--color-bg);
}

.brewery-switcher-menu button[aria-current='true'] {
    font-weight: 600;
    color: var(--color-accent-dark);
}

.container {
    max-width: 1000px;
    margin: 0 auto;
    padding: 2rem 1.5rem;
}

.container.wide {
    max-width: 1400px;
}

.filter-form {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem 1rem;
    align-items: flex-end;
}

.filter-form label {
    margin: 0.5rem 0 0;
}

.filter-form label.check {
    font-weight: 400;
    padding-bottom: 0.4rem;
}

.table td.nowrap,
.table th.nowrap {
    white-space: nowrap;
}

.tiles {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    margin: 1rem 0;
}

.tile {
    flex: 1 1 200px;
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
    padding: 0.75rem 1rem;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 6px;
}

.tile strong {
    font-size: 1.25rem;
}

.chart {
    width: 100%;
    height: auto;
}

.low,
tr.low td {
    color: #b3472f;
}

.card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 8px;
    padding: 1.5rem;
    margin-bottom: 1.5rem;
}

h1 {
    font-size: 1.5rem;
    margin: 0 0 1rem;
}

h2 {
    font-size: 1.1rem;
    margin: 0 0 0.75rem;
}

label {
    display: block;
    font-size: 0.9rem;
    font-weight: 600;
    margin: 0.75rem 0 0.25rem;
}

input[type='email'],
input[type='password'],
input[type='text'] {
    width: 100%;
    padding: 0.5rem 0.6rem;
    border: 1px solid var(--color-border);
    border-radius: 6px;
    font-size: 1rem;
}

button,
.btn {
    display: inline-block;
    padding: 0.55rem 1rem;
    border: 1px solid var(--color-accent-dark);
    border-radius: 6px;
    background: var(--color-accent);
    color: #1a1a1a;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
}

button:hover,
.btn:hover {
    background: var(--color-accent-dark);
}

.brewery-choice-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.brewery-choice-list form {
    margin: 0;
}

.brewery-choice-list button {
    width: 100%;
    text-align: left;
    background: var(--color-bg);
    color: var(--color-text);
    border-color: var(--color-border);
}

.brewery-choice-list button:hover {
    background: var(--color-surface);
    border-color: var(--color-accent);
}

.teammate-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.teammate-list li {
    display: flex;
    justify-content: space-between;
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--color-border);
}

.teammate-list li:last-child {
    border-bottom: none;
}

.teammate-list .role {
    color: var(--color-text-muted);
    font-size: 0.9rem;
}

.teammate-list .suspended {
    color: var(--color-danger);
}

.flash,
.error {
    padding: 0.6rem 0.9rem;
    border-radius: 6px;
    font-size: 0.9rem;
    margin: 0 0 1rem;
}

.flash-success {
    background: var(--color-success-bg);
    color: var(--color-success);
}

.flash-error,
.error {
    background: var(--color-danger-bg);
    color: var(--color-danger);
}

/* Screens: navigation, lists, tables, the process chain */

.main-nav {
    display: flex;
    flex-direction: column;
    gap: 0.1rem;
}

.main-nav > a,
.nav-menu summary,
.nav-menu-list a {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.45rem 0.7rem;
    border-radius: 6px;
    text-decoration: none;
    color: var(--color-text);
}

.main-nav a:hover,
.nav-menu summary:hover {
    background: var(--color-bg);
}

.main-nav a[aria-current='page'] {
    background: var(--color-bg);
    font-weight: 700;
    color: var(--color-accent-dark);
}

/* Left-hand menu: a checkbox before the page toggles it, so it works without JavaScript */
.nav-collapse {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.nav-toggle {
    display: inline-flex;
    flex-direction: column;
    justify-content: center;
    gap: 4px;
    width: 34px;
    height: 34px;
    padding: 0 7px;
    border-radius: 6px;
    cursor: pointer;
    box-sizing: border-box;
}

.nav-toggle:hover {
    background: var(--color-bg);
}

.nav-toggle span,
.nav-toggle::before,
.nav-toggle::after {
    content: '';
    display: block;
    height: 2px;
    background: var(--color-text);
}

.app-shell {
    display: flex;
    align-items: flex-start;
}

.app-shell > .container {
    flex: 1;
    min-width: 0;
}

.sidebar {
    flex: 0 0 220px;
    position: sticky;
    top: 0;
    align-self: stretch;
    padding: 1rem 0.75rem;
    background: var(--color-surface);
    border-right: 1px solid var(--color-border);
}

.nav-collapse:checked ~ .app-shell .sidebar {
    display: none;
}

@media (max-width: 900px) {
    .app-shell {
        flex-direction: column;
    }

    .sidebar {
        flex: none;
        position: static;
        width: 100%;
        box-sizing: border-box;
        border-right: none;
        border-bottom: 1px solid var(--color-border);
    }
}

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

.count {
    font-weight: 400;
    font-size: 0.85rem;
    color: var(--color-text-muted);
}

.work-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.work-list li {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--color-border);
}

.work-list li:last-child {
    border-bottom: 0;
}

.due {
    color: var(--color-text-muted);
    white-space: nowrap;
}

.filters a[aria-current='true'] {
    font-weight: 700;
    color: var(--color-text);
}

.table {
    width: 100%;
    border-collapse: collapse;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
}

.table th,
.table td {
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid var(--color-border);
    text-align: left;
    vertical-align: top;
}

.table .num,
.table th.num {
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.facts {
    display: grid;
    grid-template-columns: max-content 1fr;
    gap: 0.35rem 1.5rem;
    margin: 0;
}

.facts dt {
    color: var(--color-text-muted);
}

.facts dd {
    margin: 0;
}

.btn-secondary {
    background: var(--color-surface);
}

/* The chain: an ordered list that reads fine unstyled; beads and lines are decoration on top. */
.chain {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    list-style: none;
    margin: 0 0 1.5rem;
    padding: 0;
}

.chain li {
    display: flex;
    flex-direction: column;
    flex: 1 1 8rem;
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--color-border);
    border-top-width: 4px;
    border-radius: 6px;
    background: var(--color-surface);
}

.chain .state,
.chain .actor {
    font-size: 0.8rem;
    color: var(--color-text-muted);
}

.chain-done {
    border-top-color: var(--color-success);
}

.chain-current {
    border-top-color: var(--color-accent);
    background: #fff8e8;
}

.chain-upcoming {
    border-top-color: var(--color-border);
}

/* Grouped navigation: plain details menus, no JavaScript */
.nav-menu summary {
    cursor: pointer;
    list-style: none;
}

.nav-menu summary::-webkit-details-marker {
    display: none;
}

.nav-menu[open] summary {
    font-weight: 700;
}

.nav-menu-list {
    display: flex;
    flex-direction: column;
    padding-left: 0.9rem;
}

.nav-menu-list a:hover {
    background: var(--color-bg);
}

.badge {
    display: inline-block;
    min-width: 1.4em;
    padding: 0 0.4em;
    border-radius: 999px;
    background: var(--color-accent);
    color: #1a1a1a;
    font-size: 0.75rem;
    font-weight: 700;
    text-align: center;
}

.item-actions {
    display: flex;
    gap: 0.35rem;
    align-items: center;
    flex-wrap: wrap;
}

.item-actions select,
.item-actions button {
    font-size: 0.8rem;
    padding: 0.2rem 0.5rem;
}

/* Allocation and stock grids: one row per beer, a column per destination or package shape. */
.table-scroll {
    overflow-x: auto;
    margin-bottom: 1rem;
}

.allocation-matrix td,
.allocation-matrix th,
.stock-grid td,
.stock-grid th {
    padding: 0.35rem 0.5rem;
}

.allocation-matrix input[type='text'],
.stock-grid input[type='text'] {
    width: 4.5rem;
    text-align: right;
    padding: 0.15rem 0.3rem;
}

.allocation-matrix tr.batch-start td {
    border-top: 2px solid var(--color-border);
}

.allocation-matrix td.proposed input,
.allocation-matrix td.proposed {
    background: #fff7e0;
}

.allocation-matrix td.over,
.stock-grid td.over {
    color: var(--color-danger);
    font-weight: 700;
}

form.filters {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem 1rem;
    align-items: end;
    margin: 0 0 1rem;
}

/* Money lights on the dashboard: green, yellow, red by an invoice's age. */
.light {
    font-size: 0.8em;
}

.light-green .light {
    color: var(--color-success);
}

.light-yellow {
    background: #fff7e0;
}

.light-yellow .light {
    color: #c98a00;
}

.light-red {
    background: var(--color-danger-bg);
    font-weight: 700;
}

.light-red .light {
    color: var(--color-danger);
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
}

/* Orders and inventory sheets: dense, one row per beer, the package-size columns repeated in groups. */
.orders-sheet {
    font-size: 0.78rem;
    line-height: 1.25;
}

.orders-sheet td,
.orders-sheet th {
    padding: 0.15rem 0.3rem;
}

.orders-sheet td.num,
.orders-sheet th.num {
    white-space: nowrap;
}

.orders-sheet tr.group-head th {
    text-align: center;
    border-bottom: 1px solid var(--color-border);
}

.orders-sheet .group-start {
    border-left: 1px solid var(--color-border);
}

.orders-sheet tr.tranche-head th {
    text-align: left;
    padding-top: 0.9rem;
    border-top: 3px solid var(--color-border);
}

.orders-sheet tr.batch-start td {
    border-top: 1px solid var(--color-border);
}

.orders-sheet tr.tranche-total th,
.orders-sheet tr.tranche-total td {
    font-weight: 700;
    border-top: 2px solid var(--color-border);
}

.orders-sheet td.editable {
    cursor: text;
}

.orders-sheet td.editable:hover {
    outline: 1px dashed var(--color-text-muted);
    outline-offset: -2px;
}

.orders-sheet .cell-input {
    width: 5em;
    text-align: right;
}

.orders-sheet td.var {
    color: var(--color-text-muted);
}

.orders-sheet td.over {
    color: var(--color-danger);
    font-weight: 700;
}

.orders-sheet td.layer-planned {
    font-style: italic;
    color: var(--color-text-muted);
}

.orders-sheet td.layer-shipped {
    font-weight: 700;
}

.orders-sheet td.auto {
    font-style: italic;
    background: #f3efe6;
}

.orders-sheet tr.short td {
    background: #fdecea;
}

.layer-switch a[aria-current] {
    font-weight: 700;
    text-decoration: none;
}
