:root {
    --ink: #272e3d;
    --ink-deep: #202633;
    --muted: #6b7180;
    --line: #e5e7eb;
    --paper: #ffffff;
    --ground: #f6f6f5;
    --red: #df332f;
    --red-dark: #c92522;
    --red-soft: #fff0ef;
    --green: #247558;
    --green-soft: #e7f4ee;
    --orange: #956015;
    --orange-soft: #fff4dc;
    --shadow: 0 12px 32px rgba(39, 46, 61, .07);
    --heading-font: "Fira Sans", "Arial Narrow", Arial, sans-serif;
    --body-font: "Myriad Pro", "Segoe UI", Arial, sans-serif;
}

* { box-sizing: border-box; }
html { min-width: 320px; }
body {
    margin: 0;
    color: var(--ink);
    background: var(--ground);
    font: 16px/1.45 var(--body-font);
    -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; }

.topbar {
    min-height: 96px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 36px;
    padding: 0 max(28px, calc((100vw - 1240px) / 2));
    background: var(--paper);
    border-bottom: 1px solid #ededed;
    position: sticky;
    top: 0;
    z-index: 10;
}
.brand { display: flex; align-items: center; gap: 16px; flex: 0 0 auto; }
.brand-mark {
    width: 92px;
    height: 54px;
    display: grid;
    place-items: center;
    color: #fff;
    background: var(--red);
    font-family: var(--heading-font);
    font-size: 18px;
    font-weight: 900;
    font-style: italic;
    letter-spacing: -.04em;
    line-height: 1;
    clip-path: polygon(12% 0, 88% 0, 100% 50%, 88% 100%, 12% 100%, 0 50%);
}
.brand-caption {
    max-width: 90px;
    color: var(--ink);
    font-family: var(--heading-font);
    font-size: 12px;
    font-weight: 700;
    line-height: 1.15;
    text-transform: uppercase;
}
.topbar nav { display: flex; align-items: center; gap: 34px; margin-left: auto; }
.topbar nav > a,
.link-button {
    position: relative;
    border: 0;
    background: none;
    padding: 10px 0;
    color: var(--ink);
    cursor: pointer;
    font-family: var(--heading-font);
    font-size: 13px;
    font-weight: 500;
    text-transform: uppercase;
}
.topbar nav > a::after {
    content: "";
    position: absolute;
    left: 0;
    right: 100%;
    bottom: 3px;
    height: 2px;
    background: var(--red);
    transition: right .2s ease;
}
.topbar nav > a:hover::after,
.topbar nav > a.active::after { right: 0; }
.topbar nav form { margin: 0; }
.link-button { color: var(--muted); }

.container { max-width: 1288px; margin: 0 auto; padding: 58px 24px 88px; }
.page-heading { display: flex; justify-content: space-between; align-items: end; gap: 28px; margin-bottom: 30px; }
h1, h2, p { margin-top: 0; }
h1, h2, h3 {
    color: var(--ink);
    font-family: var(--heading-font);
}
h1 {
    margin-bottom: 7px;
    font-size: clamp(34px, 4.2vw, 48px);
    font-weight: 900;
    line-height: 1.03;
    letter-spacing: -.035em;
    text-transform: uppercase;
}
h2 { margin-bottom: 3px; font-size: 20px; font-weight: 700; }
.eyebrow {
    color: var(--red);
    font-family: var(--heading-font);
    font-size: 13px;
    font-weight: 700;
    letter-spacing: .04em;
    text-transform: uppercase;
    margin-bottom: 10px;
}
.muted { color: var(--muted); margin-bottom: 0; }

.button {
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0 22px;
    border: 1px solid #d8dbe1;
    border-radius: 2px;
    background: var(--paper);
    color: var(--ink);
    cursor: pointer;
    font-family: var(--heading-font);
    font-size: 14px;
    font-weight: 500;
    transition: background .2s ease, border-color .2s ease, color .2s ease;
}
.button:hover { border-color: var(--ink); }
.button.primary { background: var(--red); border-color: var(--red); color: #fff; }
.button.primary:hover { background: var(--red-dark); border-color: var(--red-dark); }

.metrics { display: grid; grid-template-columns: repeat(3, 1fr); gap: 18px; margin-bottom: 24px; }
.metric {
    position: relative;
    min-height: 120px;
    padding: 24px 26px;
    background: var(--paper);
    border: 1px solid var(--line);
    border-top: 4px solid var(--ink);
    border-radius: 2px;
    box-shadow: var(--shadow);
}
.metric span {
    display: block;
    color: var(--muted);
    font-family: var(--heading-font);
    font-size: 13px;
    text-transform: uppercase;
    margin-bottom: 10px;
}
.metric strong { font-family: var(--heading-font); font-size: 36px; line-height: 1; }
.metric.accent { color: var(--ink); background: var(--paper); border-color: var(--line); border-top-color: var(--red); }
.metric.accent span { color: var(--red); }

.panel {
    background: var(--paper);
    border: 1px solid var(--line);
    border-radius: 2px;
    box-shadow: var(--shadow);
    overflow: hidden;
    margin-bottom: 24px;
}
.panel-heading {
    min-height: 84px;
    padding: 18px 22px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    border-bottom: 1px solid var(--line);
}
.search-form { display: flex; gap: 8px; }
input, select, textarea {
    width: 100%;
    min-height: 44px;
    border: 1px solid #cfd2d8;
    border-radius: 2px;
    padding: 9px 12px;
    color: var(--ink);
    background: white;
    outline: none;
    transition: border-color .2s ease, box-shadow .2s ease;
}
input:focus, select:focus, textarea:focus { border-color: var(--red); box-shadow: 0 0 0 3px rgba(223, 51, 47, .1); }
.search-form input { width: 280px; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 14px 18px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th {
    color: var(--ink);
    background: #f3f1ed;
    font-family: var(--heading-font);
    font-size: 11px;
    font-weight: 700;
    letter-spacing: .05em;
    text-transform: uppercase;
}
tbody tr { transition: background .15s ease; }
tbody tr:hover { background: #fafafa; }
tbody tr:last-child td { border-bottom: 0; }
code { padding: 3px 6px; border-radius: 2px; background: #f1f2f4; font: 12px ui-monospace, SFMono-Regular, Menlo, monospace; }
.badge { display: inline-flex; align-items: center; padding: 4px 8px; border-radius: 2px; font-size: 12px; background: #eef0f2; }
.badge.success, .status-reserved { background: var(--green-soft); color: var(--green); }
.badge.warning, .status-shortage, .status-unmatched { background: var(--orange-soft); color: var(--orange); }
.status-cancelled { background: var(--red-soft); color: var(--red-dark); }

.grid-two { display: grid; grid-template-columns: 1.15fr .85fr; gap: 24px; }
.compact th, .compact td { padding: 12px 14px; }
.actions { display: flex; gap: 6px; }
.actions form { margin: 0; }
.mini-button { border: 0; border-radius: 2px; background: var(--green-soft); color: var(--green); padding: 6px 8px; cursor: pointer; font-size: 12px; }
.mini-button.danger { background: var(--red-soft); color: var(--red-dark); }
.movement-list article { display: grid; grid-template-columns: 34px 1fr auto; align-items: center; gap: 12px; padding: 13px 18px; border-bottom: 1px solid var(--line); }
.movement-list article:last-child { border-bottom: 0; }
.movement-list p { margin: 2px 0 0; color: var(--muted); font-size: 13px; }
.movement-list time { color: var(--muted); font-size: 12px; }
.movement-icon { width: 30px; height: 30px; display: grid; place-items: center; border-radius: 2px; color: #fff; background: var(--red); font-weight: 900; }

.form-card, .auth-card {
    max-width: 680px;
    padding: 32px;
    background: var(--paper);
    border: 1px solid var(--line);
    border-top: 4px solid var(--red);
    border-radius: 2px;
    box-shadow: var(--shadow);
}
.stack-form p { margin-bottom: 18px; }
.stack-form label { display: block; margin-bottom: 6px; color: var(--ink); font-family: var(--heading-font); font-size: 14px; font-weight: 600; }
.helptext { display: block; color: var(--muted); font-size: 12px; margin-top: 4px; }
.errorlist { color: var(--red-dark); }
.form-actions { display: flex; gap: 10px; margin-top: 24px; }
.form-section { padding: 4px 0 18px; margin-bottom: 18px; border-bottom: 1px solid var(--line); }
.form-section.secondary { padding: 22px; border: 1px solid var(--line); border-radius: 2px; background: #f8f7f5; }
.form-section summary { cursor: pointer; color: var(--ink); font-family: var(--heading-font); font-weight: 700; margin-bottom: 14px; }
.form-section h2 { margin-bottom: 12px; }
.message { padding: 13px 16px; margin-bottom: 18px; border-left: 4px solid var(--green); border-radius: 2px; background: var(--green-soft); color: var(--green); }
.message.error { border-color: var(--red); background: var(--red-soft); color: var(--red-dark); }
.empty { padding: 24px; color: var(--muted); text-align: center; }

.auth-page {
    min-height: 100vh;
    background:
        linear-gradient(rgba(32, 38, 51, .84), rgba(32, 38, 51, .84)),
        repeating-linear-gradient(135deg, #3a4252 0, #3a4252 2px, #313847 2px, #313847 12px);
}
.auth-page .topbar { display: none; }
.auth-page .container { min-height: 100vh; display: grid; place-items: center; padding-top: 40px; padding-bottom: 40px; }
.auth-card { width: min(100%, 500px); max-width: 500px; margin: 0; padding: 42px; }
.auth-brand { margin-bottom: 32px; }
.auth-card h1 { font-size: clamp(32px, 6vw, 43px); }
.auth-card .button { width: 100%; margin-top: 4px; }

@media (max-width: 900px) {
    .topbar { min-height: 76px; padding: 0 18px; gap: 18px; }
    .brand { gap: 10px; }
    .brand-mark { width: 76px; height: 44px; font-size: 15px; }
    .brand-caption { display: none; }
    .topbar nav { gap: 18px; }
    .grid-two { grid-template-columns: 1fr; }
}

@media (max-width: 700px) {
    .topbar nav > a { font-size: 12px; }
    .topbar nav > a[href*="admin"] { display: none; }
    .link-button { font-size: 0; }
    .link-button::after { content: "Выход"; font-size: 12px; }
    .container { padding: 36px 14px 60px; }
    .page-heading, .panel-heading { align-items: stretch; flex-direction: column; }
    .metrics { grid-template-columns: 1fr; gap: 10px; }
    .metric { min-height: 104px; }
    .search-form input { width: 100%; }
    .form-card, .auth-card { padding: 24px; }
}

@media (max-width: 480px) {
    .topbar nav { gap: 12px; }
    .topbar nav > a { padding: 8px 0; }
    .topbar nav > a[href*="receipts"] { display: none; }
    h1 { font-size: 32px; }
    .search-form { flex-direction: column; }
    .button { width: 100%; }
    .form-actions { flex-direction: column; }
}
