:root {
    --bg: #f5f6f8;
    --surface: #ffffff;
    --line: #d8dde4;
    --text: #1f2933;
    --muted: #627080;
    --primary: #146c75;
    --primary-dark: #0d4f56;
    --danger: #b42318;
    --warning: #9a6700;
    --success: #177245;
}

* {
    box-sizing: border-box;
}

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

a {
    color: var(--primary);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

.topbar {
    align-items: center;
    background: #101820;
    color: #fff;
    display: flex;
    gap: 22px;
    min-height: 64px;
    padding: 0 28px;
}

.brand {
    color: #fff;
    font-size: 20px;
    font-weight: 800;
    letter-spacing: 0;
    text-decoration: none;
}

.brand:hover {
    text-decoration: none;
}

.nav {
    align-items: center;
    display: flex;
    flex: 1;
    gap: 4px;
    overflow: visible;
}

.nav a,
.nav-group summary {
    border-radius: 6px;
    color: #dce3ea;
    cursor: pointer;
    display: block;
    padding: 10px 12px;
    white-space: nowrap;
}

.nav a.active,
.nav a:hover,
.nav-group.active summary,
.nav-group[open] summary,
.nav-group summary:hover {
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
    text-decoration: none;
}

.nav-group {
    position: relative;
}

.nav-group summary {
    list-style: none;
}

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

.nav-menu {
    background: #14212b;
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 8px;
    box-shadow: 0 12px 26px rgba(0, 0, 0, 0.24);
    display: grid;
    gap: 2px;
    left: 0;
    min-width: 220px;
    padding: 6px;
    position: absolute;
    top: calc(100% + 8px);
    z-index: 30;
}

.nav-menu-right {
    left: auto;
    right: 0;
}

.nav-menu a {
    padding: 9px 10px;
}

.nav-group:not([open]) .nav-menu {
    display: none;
}

.userbox {
    align-items: center;
    display: flex;
    gap: 12px;
    white-space: nowrap;
}

.userbox a {
    color: #b8dbe0;
}

.page {
    margin: 0 auto;
    max-width: 1220px;
    padding: 28px;
}

.page-title {
    align-items: center;
    display: flex;
    justify-content: space-between;
    margin-bottom: 18px;
}

h1 {
    font-size: 28px;
    line-height: 1.2;
    margin: 0;
}

h2 {
    font-size: 18px;
    margin: 0 0 14px;
}

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

.grid.metrics {
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    margin-bottom: 20px;
}

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

.metric {
    padding: 18px;
}

.metric.metric-alert {
    background: #fff4f4;
    border-color: #d92d20;
    box-shadow: 0 0 0 3px rgba(217, 45, 32, 0.08);
}

.metric span {
    color: var(--muted);
    display: block;
    font-size: 13px;
    margin-bottom: 8px;
}

.metric.metric-alert span,
.metric.metric-alert small {
    color: #9f1f18;
}

.metric strong {
    font-size: 30px;
}

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

.metric small {
    display: block;
    font-size: 12px;
    font-weight: 800;
    margin-top: 8px;
    text-transform: uppercase;
}

.panel {
    margin-bottom: 18px;
    padding: 18px;
}

.request-alert-panel {
    background: #fff7f7;
    border-color: #d92d20;
    box-shadow: 0 0 0 3px rgba(217, 45, 32, 0.08);
}

.request-alert-panel h2 {
    color: var(--danger);
}

.request-alert-panel .table-wrap {
    border-color: #efb0aa;
}

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

.filters {
    align-items: end;
    display: grid;
    gap: 12px;
    grid-template-columns: 2fr 1fr 1fr auto;
    margin-bottom: 16px;
}

label {
    color: var(--muted);
    display: block;
    font-size: 13px;
    font-weight: 700;
    margin-bottom: 6px;
}

input,
select,
textarea {
    background: #fff;
    border: 1px solid #c9d1dc;
    border-radius: 6px;
    color: var(--text);
    font: inherit;
    min-height: 40px;
    padding: 9px 10px;
    width: 100%;
}

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

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

.form-grid .wide {
    grid-column: 1 / -1;
}

.permission-grid {
    display: grid;
    gap: 12px;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

.permission-group {
    border: 1px solid var(--line);
    border-radius: 8px;
    margin: 0;
    padding: 12px;
}

.permission-group legend {
    color: var(--text);
    font-weight: 800;
    padding: 0 4px;
}

.checkbox-row {
    align-items: center;
    color: var(--text);
    display: flex;
    gap: 8px;
    font-weight: 500;
    margin: 8px 0 0;
}

.checkbox-row input {
    min-height: auto;
    width: auto;
}

.location-fields {
    display: grid;
    gap: 10px;
    grid-template-columns: 1fr 120px 120px;
}

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

.button:hover,
button:hover {
    background: var(--primary-dark);
    border-color: var(--primary-dark);
    text-decoration: none;
}

button:disabled,
button:disabled:hover {
    background: #9aa6b2;
    border-color: #9aa6b2;
    cursor: not-allowed;
}

.button.secondary {
    background: #fff;
    border-color: #b8c2cc;
    color: var(--text);
}

.button.secondary:hover {
    background: #eef2f5;
}

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

.table-wrap {
    border: 1px solid var(--line);
    border-radius: 8px;
    overflow-x: auto;
}

table {
    background: #fff;
    border-collapse: collapse;
    min-width: 820px;
    width: 100%;
}

.compact-table {
    table-layout: fixed;
}

.compact-table th,
.compact-table td {
    overflow: hidden;
}

.materials-table {
    min-width: 1720px;
}

.inventory-table {
    min-width: 1680px;
}

.materials-table th:nth-child(1),
.materials-table td:nth-child(1) {
    width: 44px;
}

.materials-table th:nth-child(2),
.materials-table td:nth-child(2) {
    width: 130px;
}

.materials-table th:nth-child(3),
.materials-table td:nth-child(3) {
    width: 190px;
}

.materials-table th:nth-child(4),
.materials-table td:nth-child(4) {
    width: 260px;
}

.materials-table th:nth-child(5),
.materials-table td:nth-child(5),
.materials-table th:nth-child(11),
.materials-table td:nth-child(11) {
    width: 130px;
}

.materials-table th:nth-child(6),
.materials-table td:nth-child(6),
.materials-table th:nth-child(8),
.materials-table td:nth-child(8),
.materials-table th:nth-child(10),
.materials-table td:nth-child(10) {
    width: 90px;
}

.materials-table th:nth-child(7),
.materials-table td:nth-child(7),
.materials-table th:nth-child(9),
.materials-table td:nth-child(9) {
    width: 150px;
}

.materials-table th:nth-child(12),
.materials-table td:nth-child(12) {
    width: 220px;
}

.materials-table th:nth-child(13),
.materials-table td:nth-child(13) {
    width: 120px;
}

.inventory-table th:nth-child(1),
.inventory-table td:nth-child(1) {
    width: 130px;
}

.inventory-table th:nth-child(2),
.inventory-table td:nth-child(2) {
    width: 190px;
}

.inventory-table th:nth-child(3),
.inventory-table td:nth-child(3) {
    width: 260px;
}

.inventory-table th:nth-child(4),
.inventory-table td:nth-child(4),
.inventory-table th:nth-child(10),
.inventory-table td:nth-child(10),
.inventory-table th:nth-child(12),
.inventory-table td:nth-child(12) {
    width: 130px;
}

.inventory-table th:nth-child(5),
.inventory-table td:nth-child(5),
.inventory-table th:nth-child(6),
.inventory-table td:nth-child(6),
.inventory-table th:nth-child(7),
.inventory-table td:nth-child(7),
.inventory-table th:nth-child(8),
.inventory-table td:nth-child(8),
.inventory-table th:nth-child(9),
.inventory-table td:nth-child(9),
.inventory-table th:nth-child(11),
.inventory-table td:nth-child(11) {
    width: 90px;
}

.inventory-table th:nth-child(13),
.inventory-table td:nth-child(13) {
    width: 220px;
}

.request-table {
    min-width: 1260px;
}

.request-table th:nth-child(1),
.request-table td:nth-child(1) {
    width: 130px;
}

.request-table th:nth-child(2),
.request-table td:nth-child(2) {
    width: 120px;
}

.request-table th:nth-child(3),
.request-table td:nth-child(3),
.request-table th:nth-child(4),
.request-table td:nth-child(4) {
    width: 150px;
}

.request-table th:nth-child(5),
.request-table td:nth-child(5),
.request-table th:nth-child(6),
.request-table td:nth-child(6),
.request-table th:nth-child(8),
.request-table td:nth-child(8),
.request-table th:nth-child(9),
.request-table td:nth-child(9) {
    width: 110px;
}

.request-table th:nth-child(7),
.request-table td:nth-child(7) {
    width: 230px;
}

.request-table th:nth-child(10),
.request-table td:nth-child(10) {
    width: 130px;
}

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

th {
    background: #eef2f5;
    color: #364453;
    font-size: 13px;
}

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

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

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

.badge.ok {
    background: #e9f7ef;
    color: var(--success);
}

.badge.low {
    background: #fff4e5;
    color: var(--warning);
}

.badge.danger {
    background: #fdecec;
    color: var(--danger);
}

.flash {
    border-radius: 8px;
    font-weight: 700;
    margin-bottom: 18px;
    padding: 12px 14px;
}

.flash.success {
    background: #e9f7ef;
    border: 1px solid #bfe7cf;
    color: var(--success);
}

.flash.error {
    background: #fdecec;
    border: 1px solid #f5b9b4;
    color: var(--danger);
}

.errors {
    background: #fdecec;
    border: 1px solid #f5b9b4;
    border-radius: 8px;
    color: var(--danger);
    margin-bottom: 16px;
    padding: 12px 14px;
}

.errors ul {
    margin: 0;
    padding-left: 18px;
}

.login-page {
    display: grid;
    min-height: calc(100vh - 64px);
    place-items: center;
}

.login-box {
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 8px;
    max-width: 420px;
    padding: 24px;
    width: 100%;
}

.inline-form {
    display: inline;
}

.audit-detail {
    background: #f4f6f8;
    border: 1px solid var(--line);
    border-radius: 6px;
    margin: 8px 0 0;
    max-width: 520px;
    overflow: auto;
    padding: 10px;
    white-space: pre-wrap;
}

@media (max-width: 880px) {
    .topbar {
        align-items: stretch;
        flex-direction: column;
        gap: 8px;
        padding: 14px;
    }

    .nav,
    .userbox {
        width: 100%;
    }

    .nav {
        flex-wrap: wrap;
    }

    .nav-group {
        width: 100%;
    }

    .nav-menu,
    .nav-menu-right {
        box-shadow: none;
        left: auto;
        margin-top: 4px;
        min-width: 0;
        position: static;
        right: auto;
        width: 100%;
    }

    .grid.metrics,
    .filters,
    .form-grid,
    .location-fields {
        grid-template-columns: 1fr;
    }

    .page {
        padding: 18px;
    }
}


.filters.inventory {
    grid-template-columns: 2fr 1fr 1fr 1fr;
}

.filters .wide-checks {
    align-items: center;
    display: flex;
    gap: 16px;
    grid-column: 1 / -1;
}

.inventory-metrics {
    margin-bottom: 20px;
}

.inventory-heading {
    align-items: start;
    display: flex;
    justify-content: space-between;
    margin-bottom: 14px;
}

.print-only {
    display: none;
}

@media print {
    .topbar,
    .no-print,
    .flash {
        display: none !important;
    }

    body {
        background: #fff;
        font-size: 12px;
    }

    .page {
        max-width: none;
        padding: 0;
    }

    .panel,
    .metric {
        border: 0;
        padding: 0;
    }

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

    .table-wrap {
        border: 0;
        overflow: visible;
    }

    table {
        min-width: 0;
    }

    th,
    td {
        padding: 6px;
    }

    .badge {
        border: 1px solid #c9d1dc;
    }

    .print-only {
        display: block;
    }

    .text-clip,
    .description-clip {
        max-width: none;
        overflow: visible;
        white-space: normal;
    }
}


.bulk-actions {
    align-items: center;
    background: #eef2f5;
    border: 1px solid var(--line);
    border-radius: 8px;
    display: grid;
    gap: 10px;
    grid-template-columns: auto 1fr auto auto;
    margin-bottom: 12px;
    padding: 12px;
}

.bulk-actions .select-all {
    align-items: center;
    color: var(--text);
    display: flex;
    font-size: 14px;
    gap: 8px;
    margin: 0;
    white-space: nowrap;
}

.bulk-actions input[type="checkbox"] {
    min-height: auto;
    width: auto;
}

@media (max-width: 880px) {
    .bulk-actions {
        grid-template-columns: 1fr;
    }
}


.stock-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 12px;
}

.stock-summary {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 12px;
}

.stock-summary div {
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 12px;
    background: var(--bg);
}

.stock-summary span {
    display: block;
    color: var(--muted);
    font-size: 13px;
    margin-bottom: 4px;
}

.stock-summary strong {
    font-size: 20px;
}

.small-text {
    font-size: 13px;
    line-height: 1.35;
}

.text-clip,
.description-clip {
    cursor: text;
    display: block;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}


.vertical-actions {
    align-items: flex-start;
    flex-direction: column;
}

.stacked-form {
    align-items: stretch;
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: min(220px, 100%);
}

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

.delivery-number {
    border: 1px solid var(--line);
    border-radius: 8px;
    min-width: 0;
    padding: 8px 10px;
    text-align: right;
}

.delivery-number span,
.delivery-grid span,
.signature-grid span {
    color: var(--muted);
    display: block;
    font-size: 12px;
    font-weight: 700;
    margin-bottom: 4px;
    text-transform: uppercase;
}

.delivery-number strong {
    font-size: 16px;
}

.delivery-grid {
    display: grid;
    gap: 8px;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    margin-bottom: 12px;
}

.delivery-grid div {
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 8px 10px;
}

.signature-grid {
    display: grid;
    gap: 22px;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    margin-top: 28px;
}

.signature-line {
    border-bottom: 1px solid var(--text);
    height: 42px;
    margin-bottom: 8px;
}

.delivery-lines-head {
    align-items: center;
    display: flex;
    justify-content: space-between;
    margin: 22px 0 12px;
}

.delivery-lines {
    display: grid;
    gap: 12px;
}

.delivery-line {
    align-items: end;
    background: #f8fafc;
    border: 1px solid var(--line);
    border-radius: 8px;
    display: grid;
    gap: 10px;
    grid-template-columns: 1.1fr 1.3fr 1.5fr 1fr 120px 1fr auto;
    padding: 12px;
}

.delivery-line .line-remove {
    align-items: end;
    display: flex;
}

.delivery-line .line-remove button {
    min-width: 74px;
}

.request-line {
    align-items: end;
    background: #f8fafc;
    border: 1px solid var(--line);
    border-radius: 8px;
    display: grid;
    gap: 10px;
    grid-template-columns: 1.1fr 1.3fr 1.7fr 120px 1.2fr auto;
    padding: 12px;
}

.request-line .line-remove {
    align-items: end;
    display: flex;
}

.request-line .line-remove button {
    min-width: 74px;
}

.branded-delivery-head {
    align-items: center;
}

.delivery-top {
    align-items: start;
    display: grid;
    gap: 14px;
    grid-template-columns: minmax(260px, 1fr) 330px;
    margin-bottom: 12px;
}

.company-address {
    color: var(--text);
    font-size: 12px;
    line-height: 1.45;
}

.company-address strong,
.company-address span {
    display: block;
}

.delivery-top-right {
    align-items: stretch;
    display: grid;
    gap: 8px;
    grid-template-columns: 1fr;
}

.recipient-box {
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 7px 9px 9px;
}

.recipient-box .box-title {
    color: var(--muted);
    display: block;
    font-size: 11px;
    font-weight: 800;
    margin-bottom: 5px;
    text-transform: uppercase;
}

.recipient-fields {
    display: grid;
    gap: 5px 8px;
    grid-template-columns: 1fr 1fr;
}

.recipient-fields div {
    min-width: 0;
}

.recipient-fields span {
    color: var(--muted);
    display: block;
    font-size: 9px;
    font-weight: 800;
    text-transform: uppercase;
}

.recipient-fields strong {
    border-bottom: 1px solid #9aa6b2;
    display: block;
    font-size: 11px;
    font-weight: 700;
    line-height: 1.2;
    min-height: 16px;
    overflow: hidden;
    padding-top: 1px;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.delivery-brand-box {
    align-items: center;
    display: grid;
    gap: 8px;
    grid-template-columns: 1fr 150px;
}

.delivery-logo-box {
    align-items: center;
    display: flex;
    justify-content: flex-start;
    min-height: 38px;
}

.delivery-logo-box img {
    display: block;
    max-height: 38px;
    max-width: 135px;
    object-fit: contain;
}

.delivery-items-table {
    table-layout: fixed;
}

.delivery-items-table th:nth-child(1),
.delivery-items-table td:nth-child(1) {
    width: 115px;
}

.delivery-items-table th:nth-child(2),
.delivery-items-table td:nth-child(2) {
    width: 165px;
}

.delivery-items-table th:nth-child(4),
.delivery-items-table td:nth-child(4),
.delivery-items-table th:nth-child(6),
.delivery-items-table td:nth-child(6) {
    width: 125px;
}

.delivery-items-table th:nth-child(5),
.delivery-items-table td:nth-child(5) {
    width: 78px;
}

.delivery-items-table th,
.delivery-items-table td {
    overflow-wrap: anywhere;
}

.request-items-table th:nth-child(1),
.request-items-table td:nth-child(1) {
    width: 120px;
}

.request-items-table th:nth-child(2),
.request-items-table td:nth-child(2) {
    width: 170px;
}

.request-items-table th:nth-child(4),
.request-items-table td:nth-child(4) {
    width: 85px;
}

.request-items-table th:nth-child(5),
.request-items-table td:nth-child(5) {
    width: 160px;
}

@media print {
    @page {
        margin: 8mm;
        size: A4;
    }

    .page-title {
        display: none;
    }

    body {
        font-size: 10.5px;
    }

    .delivery-note {
        padding: 0;
    }

    .delivery-note p {
        margin: 6px 0;
    }

    .delivery-head,
    .delivery-grid,
    .delivery-top,
    .signature-grid {
        break-inside: avoid;
    }

    .delivery-top {
        grid-template-columns: 1fr 315px;
        margin-bottom: 8px;
    }

    .company-address {
        font-size: 10px;
    }

    .delivery-number {
        padding: 5px 7px;
    }

    .delivery-number span,
    .delivery-grid span,
    .signature-grid span {
        font-size: 9px;
        margin-bottom: 2px;
    }

    .delivery-number strong {
        font-size: 13px;
    }

    .recipient-box {
        padding: 5px 7px 7px;
    }

    .recipient-fields {
        gap: 3px 6px;
    }

    .recipient-fields strong {
        min-height: 14px;
    }

    .delivery-grid {
        margin-bottom: 8px;
    }

    .delivery-grid div {
        padding: 5px 7px;
    }

    .delivery-note th,
    .delivery-note td {
        padding: 4px 5px;
    }

    .signature-grid {
        margin-top: 18px;
    }

    .signature-line {
        height: 32px;
        margin-bottom: 5px;
    }

    .delivery-logo-box img {
        max-height: 32px;
        max-width: 120px;
    }
}

@media (max-width: 880px) {
    .delivery-head,
    .signature-grid {
        grid-template-columns: 1fr;
    }

    .delivery-head {
        display: grid;
    }

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

    .delivery-top,
    .delivery-top-right,
    .recipient-fields {
        grid-template-columns: 1fr;
    }

    .delivery-logo-box {
        justify-content: flex-start;
    }

    .delivery-lines-head {
        align-items: stretch;
        flex-direction: column;
        gap: 10px;
    }

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

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

    .delivery-line .line-remove button {
        width: 100%;
    }

    .request-line .line-remove button {
        width: 100%;
    }
}
