:root {
    --ink: #172026;
    --muted: #64707a;
    --line: #d9e0e5;
    --surface: #ffffff;
    --page: #f4f6f7;
    --blue: #1c6dd0;
    --green: #207a48;
    --amber: #a86400;
    --red: #b42318;
}
* { box-sizing: border-box; }
body { margin: 0; color: var(--ink); background: var(--page); font-family: Arial, Helvetica, sans-serif; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 24px; padding: 14px 22px; background: #172026; color: #fff; position: sticky; top: 0; z-index: 10; }
.brand { color: #fff; font-size: 22px; font-weight: 700; text-decoration: none; }
nav { display: flex; flex-wrap: wrap; gap: 8px; }
nav a { color: #e8eef2; padding: 8px 10px; text-decoration: none; border-radius: 6px; }
nav a:hover { background: rgba(255,255,255,.14); }
.page { max-width: 1180px; margin: 0 auto; padding: 24px; }
h1 { margin: 0 0 18px; font-size: 30px; }
h2 { margin: 0 0 12px; font-size: 20px; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; margin-bottom: 18px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 16px; margin-bottom: 14px; }
.metric { font-size: 34px; font-weight: 700; margin-top: 6px; }
.muted { color: var(--muted); }
table { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--line); }
th, td { text-align: left; padding: 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { background: #e9eef2; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 14px 0; }
.button, button, input[type=submit] { display: inline-block; border: 0; border-radius: 6px; background: var(--blue); color: #fff; min-height: 40px; padding: 9px 12px; font-size: 15px; line-height: 1.2; text-decoration: none; cursor: pointer; touch-action: manipulation; }
.button.secondary, button.secondary { background: #4d5b66; }
.button.danger-button, button.danger-button, input[type=submit].danger-button { background: var(--red); }
.small-button { min-height: 34px; padding: 6px 9px; font-size: 13px; margin-top: 5px; }
.status { display: inline-block; border-radius: 999px; padding: 3px 8px; font-size: 13px; font-weight: 700; }
.status.available, .status.confirmed, .status.completed, .status.resolved, .status.received, .status.finalized, .status.exported, .status.invoiced { color: #fff; background: var(--green); }
.status.warning, .status.draft, .status.needed, .status.requested { color: #fff; background: var(--amber); }
.status.cancelled,
.status.inactive { color: #fff; background: #4d5b66; }
.status.fault, .status.workshop, .status.critical, .status.faultreported, .status.awaitingparts { color: #fff; background: var(--red); }
.status-line { margin: 0 0 16px; }
.status-picker { display: inline-block; margin-left: 6px; position: relative; vertical-align: middle; }
.status-button { border: 0; cursor: pointer; min-height: 0; padding: 3px 8px; }
.status-popover { background: #fff; border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 12px 28px rgba(23,32,38,.18); display: none; left: 0; min-width: 150px; padding: 6px; position: absolute; top: calc(100% + 6px); z-index: 12; }
.status-popover.is-open { display: block; }
.status-popover form { display: block; }
.status-option { background: transparent; border-radius: 6px; color: var(--ink); display: block; font-size: 14px; min-height: 34px; padding: 7px 9px; text-align: left; width: 100%; }
.status-option:hover { background: #eef3f7; }
.status-option:disabled { color: var(--muted); cursor: default; font-weight: 700; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 12px; }
.form-grid p { position: relative; }
label { display: block; font-weight: 700; margin-bottom: 6px; }
label input[type=checkbox] { margin: 0 7px 0 0; min-height: 0; width: auto; vertical-align: middle; }
input, select, textarea { width: 100%; border: 1px solid #b8c3cc; border-radius: 6px; min-height: 42px; padding: 9px; font: inherit; }
textarea { min-height: 84px; }
.category-suggest { background: #fff; border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 12px 28px rgba(23,32,38,.16); display: none; margin-top: 4px; max-height: 180px; overflow: auto; padding: 5px; position: absolute; width: min(320px, 100%); z-index: 30; }
.category-suggest.is-open { display: block; }
.category-suggest button { background: transparent; border-radius: 6px; color: var(--ink); display: block; min-height: 32px; padding: 6px 8px; text-align: left; width: 100%; }
.category-suggest button:hover { background: #eef3f7; }
.notice { border-left: 5px solid var(--amber); background: #fff7e8; padding: 12px; margin-bottom: 14px; }
.danger-row td { background: #ffe9e7; border-bottom-color: #f1aaa4; }
.money-good { color: var(--green); font-weight: 700; }
.money-bad { color: var(--red); font-weight: 700; }
.danger-note { background: #ffe9e7; border-left: 5px solid var(--red); color: var(--red); font-weight: 700; margin-bottom: 14px; padding: 12px; }
.inline-form { display: inline; }
.link-button { display: inline; background: transparent; color: var(--red); padding: 0 0 0 6px; font-size: 13px; text-decoration: underline; }
.compact-form { min-width: 260px; max-width: 380px; }
.wide { grid-column: 1 / -1; }
summary { cursor: pointer; color: var(--blue); font-weight: 700; }
.modal-backdrop { align-items: center; background: rgba(23,32,38,.54); bottom: 0; display: none; justify-content: center; left: 0; padding: 24px; position: fixed; right: 0; top: 0; z-index: 20; }
.modal-backdrop.is-open { display: flex; }
.modal-window { background: #fff; border-radius: 8px; box-shadow: 0 18px 48px rgba(0,0,0,.28); max-height: 90vh; max-width: 760px; overflow: auto; padding: 18px; width: min(760px, 100%); }
.modal-header { align-items: center; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; margin: -4px 0 14px; padding-bottom: 10px; }
.modal-close { background: #4d5b66; padding: 6px 10px; }
.history-block { border-top: 1px solid var(--line); margin-top: 16px; padding-top: 12px; }
.history-block h3 { font-size: 16px; margin: 0 0 10px; }
.history-block p { margin: 0 0 10px; }
@media (max-width: 720px) {
    body { font-size: 16px; }
    .topbar { align-items: stretch; flex-direction: column; gap: 10px; padding: 12px; }
    .brand { font-size: 20px; }
    nav { flex-wrap: nowrap; gap: 6px; margin: 0 -12px; overflow-x: auto; padding: 0 12px 2px; scrollbar-width: thin; }
    nav a { background: rgba(255,255,255,.08); flex: 0 0 auto; min-height: 40px; padding: 10px 12px; white-space: nowrap; }
    .topbar span { color: #cfd9df; font-size: 14px; }
    .page { padding: 12px; }
    h1 { font-size: 24px; margin-bottom: 12px; }
    h2 { font-size: 18px; }
    .grid { grid-template-columns: 1fr; gap: 10px; margin-bottom: 12px; }
    .card { border-radius: 6px; margin-bottom: 10px; padding: 12px; }
    .metric { font-size: 28px; }
    .actions { gap: 8px; margin: 10px 0; }
    .actions .button, .actions button, .actions input[type=submit] { flex: 1 1 auto; }
    .button, button, input[type=submit] { min-height: 44px; padding: 11px 13px; }
    .small-button { min-height: 40px; padding: 9px 10px; }
    table { display: block; font-size: 14px; max-width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
    th, td { padding: 9px 8px; min-width: 110px; }
    td:first-child, th:first-child { min-width: 150px; }
    .form-grid { grid-template-columns: 1fr; gap: 8px; }
    .compact-form { max-width: none; min-width: 0; width: 100%; }
    .inline-form { display: inline-block; margin-top: 4px; }
    .link-button { min-height: 34px; padding: 4px 0 4px 6px; }
    .modal-backdrop { align-items: flex-start; padding: 0; }
    .modal-window { border-radius: 0; box-shadow: none; max-height: 100vh; min-height: 100vh; padding: 14px; width: 100%; }
    .modal-header { position: sticky; top: -14px; z-index: 1; background: #fff; margin: -14px -14px 12px; padding: 12px 14px; }
    .modal-header h2 { margin: 0; padding-right: 8px; }
    .modal-close { flex: 0 0 auto; min-height: 40px; }
    .status { font-size: 12px; }
}
