:root {
    --ink: #1b2430;
    --ink-soft: #5b6572;
    --line: #e2e6ea;
    --bg: #f5f6f8;
    --panel: #ffffff;
    --accent: #16a34a;
    --accent-dark: #0f7a38;
    --accent-soft: #e7f6ec;
    --red: #d0342c;
    --red-soft: #fbe9e6;
    --amber: #92600a;
    --amber-soft: #fbf0dc;
    --blue: #1d5fa8;
    --blue-soft: #e6eff8;
    --gray-soft: #eceef0;
    --radius: 10px;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    color: var(--ink);
    background: var(--bg);
    font-size: 14px;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

h1 { font-size: 22px; margin: 0 0 4px; }
h2 { font-size: 17px; margin: 0 0 12px; }

/* --- Auth page --- */
.auth-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: radial-gradient(circle at 30% 20%, #16351f 0%, #050a06 65%);
}
.auth-form {
    background: var(--panel);
    padding: 36px;
    border-radius: 12px;
    width: 320px;
    box-shadow: 0 20px 50px rgba(0,0,0,0.25);
}
.auth-form h1 { text-align: center; margin-bottom: 20px; }
.auth-form label {
    display: block;
    margin-bottom: 14px;
    font-size: 13px;
    color: var(--ink-soft);
}
.auth-form input {
    width: 100%;
    margin-top: 6px;
    padding: 9px 10px;
    border: 1px solid var(--line);
    border-radius: 6px;
    font-size: 14px;
}
.auth-form button {
    width: 100%;
    padding: 10px;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    cursor: pointer;
    margin-top: 6px;
}
.auth-form button:hover { background: var(--accent-dark); }
.error { color: var(--red); font-size: 13px; margin-bottom: 10px; }
.hint { color: var(--ink-soft); font-size: 12px; margin-top: 14px; text-align: center; }

/* --- App shell --- */
.app-shell { display: flex; min-height: 100vh; }
.sidebar {
    width: 232px;
    background: #0b0e13;
    color: #aab3bd;
    display: flex;
    flex-direction: column;
    padding: 18px 0;
    flex-shrink: 0;
}
.brand {
    font-weight: 700;
    font-size: 16px;
    color: #ffffff;
    padding: 0 20px 18px;
    border-bottom: 1px solid rgba(255,255,255,0.08);
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    gap: 8px;
}
.brand-mark {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
    background: var(--accent);
    color: #fff;
    border-radius: 7px;
    font-size: 13px;
    font-weight: 800;
}
.sidebar nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.sidebar nav a {
    display: flex;
    align-items: center;
    gap: 10px;
    color: #aab3bd;
    padding: 10px 20px;
    text-decoration: none;
    border-left: 3px solid transparent;
    font-size: 13px;
}
.sidebar nav a .icon { flex-shrink: 0; opacity: 0.85; }
.sidebar nav a:hover { background: rgba(255,255,255,0.05); color: #fff; text-decoration: none; }
.sidebar nav a.active {
    background: rgba(22,163,74,0.18);
    border-left-color: var(--accent);
    color: #ffffff;
    font-weight: 600;
}
.sidebar nav a.active .icon { opacity: 1; color: var(--accent); }
.sidebar-footer {
    padding: 14px 20px 0;
    border-top: 1px solid rgba(255,255,255,0.08);
    margin-top: 10px;
}
.who-name { font-weight: 600; color: #ffffff; font-size: 13px; }
.who-role { font-size: 12px; color: #6b7684; margin-bottom: 8px; }
.logout-link { font-size: 12px; color: #6b7684; }
.icon { display: inline-block; vertical-align: middle; }

.content { flex: 1; padding: 28px 32px; max-width: 1180px; }

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

.btn {
    display: inline-block;
    background: var(--accent);
    color: #fff;
    padding: 8px 16px;
    border-radius: 6px;
    border: none;
    font-size: 13px;
    cursor: pointer;
}
.btn:hover { background: var(--accent-dark); text-decoration: none; }
.btn-secondary { background: var(--gray-soft); color: var(--ink); }
.btn-secondary:hover { background: #dfe2e5; }
.btn-danger { background: var(--red); }
.btn-danger:hover { background: #a3271f; }
.btn-small { padding: 5px 10px; font-size: 12px; }

.panel {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 20px;
}

.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 14px;
    margin-bottom: 24px;
}
.stat-card {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 16px;
}
.stat-value { font-size: 26px; font-weight: 700; }
.stat-label { font-size: 12px; color: var(--ink-soft); margin-top: 2px; }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--line); }
th { color: var(--ink-soft); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: 0.03em; }
tr:hover td { background: #fafbfb; }

.badge {
    display: inline-block;
    padding: 3px 9px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
}
.badge-blue { background: var(--blue-soft); color: var(--blue); }
.badge-amber { background: var(--amber-soft); color: var(--amber); }
.badge-green { background: var(--accent-soft); color: var(--accent); }
.badge-gray { background: var(--gray-soft); color: var(--ink-soft); }
.badge-red { background: var(--red-soft); color: var(--red); }
.badge-purple { background: #ece4fb; color: #5b31a8; }
.badge-orange { background: #fde7d9; color: #a34f0d; }

.checklist-item { display: grid; grid-template-columns: 1fr auto auto auto 1fr; gap: 8px; align-items: center; padding: 7px 0; border-bottom: 1px solid var(--line); font-size: 13px; }
.checklist-item label.radio { display: flex; align-items: center; gap: 4px; font-size: 12px; color: var(--ink-soft); font-weight: normal; margin: 0; }
.checklist-item input[type=text] { font-size: 12px; padding: 5px 8px; }
.checkbox-list { display: flex; flex-direction: column; gap: 6px; max-height: 260px; overflow-y: auto; border: 1px solid var(--line); border-radius: 6px; padding: 10px; }
.checkbox-list .group-label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.03em; color: var(--ink-soft); margin-top: 8px; }
.checkbox-list .group-label:first-child { margin-top: 0; }
.checkbox-list label { display: flex; align-items: center; gap: 6px; font-weight: normal; font-size: 13px; margin: 0; }
.checkbox-list input[type=checkbox] { width: auto; }
.tag-list { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.tag { background: var(--accent-soft); color: var(--accent); padding: 3px 10px; border-radius: 20px; font-size: 12px; }
.print-actions { margin-bottom: 16px; }
@media print {
    .no-print { display: none !important; }
    body { background: #fff; }
}

.cat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 12px;
    margin-bottom: 22px;
}
.cat-card {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 14px;
    border-radius: 12px;
    text-decoration: none;
    color: #fff;
    font-size: 13px;
    font-weight: 600;
    box-shadow: 0 2px 6px rgba(0,0,0,0.08);
    transition: transform .12s ease;
}
.cat-card:hover { text-decoration: none; transform: translateY(-2px); }
.cat-card .icon { flex-shrink: 0; opacity: 0.95; }
.cat-card .cat-count { display: block; font-weight: 400; opacity: 0.85; font-size: 11px; margin-top: 2px; }
.cat-card.active { outline: 3px solid rgba(0,0,0,0.15); }
.cat-card.all { background: #2c3542; }
.cat-blue   { background: linear-gradient(135deg, #2f8fe8, #1463c9); }
.cat-green  { background: linear-gradient(135deg, #34c778, #1f9e5c); }
.cat-purple { background: linear-gradient(135deg, #9b6df0, #7440d6); }
.cat-orange { background: linear-gradient(135deg, #ffa24d, #e67d1f); }
.cat-pink   { background: linear-gradient(135deg, #ff6fa5, #dd3f80); }
.cat-teal   { background: linear-gradient(135deg, #33c3c9, #16949c); }
.cat-red    { background: linear-gradient(135deg, #ff6b60, #d6362b); }
.cat-slate  { background: linear-gradient(135deg, #7c8aa0, #566178); }

.variant-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}
.variant-pill {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 9px 14px;
    border-radius: 999px;
    background: var(--accent-soft);
    color: var(--accent-dark);
    font-size: 13px;
    font-weight: 600;
    text-decoration: none;
    border: 1px solid transparent;
}
.variant-pill:hover { text-decoration: none; border-color: var(--accent); }
.variant-pill-count {
    background: rgba(255,255,255,0.7);
    color: var(--accent-dark);
    border-radius: 999px;
    padding: 1px 8px;
    font-size: 11px;
    font-weight: 700;
}

.table-scroll { overflow-x: auto; }
table.donor-matrix { min-width: 900px; }
table.donor-matrix th, table.donor-matrix td { text-align: center; }
table.donor-matrix th:first-child, table.donor-matrix td:first-child { text-align: left; }
.donor-col-head { display: table-cell; }
.donor-col-head .icon { display: block; margin: 0 auto 4px; color: var(--ink-soft); }
.donor-col-head span { display: block; font-size: 10px; text-transform: none; letter-spacing: 0; white-space: normal; max-width: 90px; margin: 0 auto; }
.donor-cell { font-size: 14px; }

.color-dot {
    display: inline-block;
    width: 13px;
    height: 13px;
    border-radius: 50%;
    margin-right: 8px;
    vertical-align: middle;
    border: 1px solid rgba(0,0,0,0.15);
}

.part-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
    gap: 12px;
}
.part-card {
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 12px;
    background: #fbfbfc;
}
.part-card-top { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 8px; }
.part-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border-radius: 9px;
    color: #fff;
}
.part-delete button { background: none; border: none; color: var(--ink-soft); cursor: pointer; font-size: 13px; padding: 2px 4px; }
.part-delete button:hover { color: var(--red); }
.part-card-name { font-size: 13px; font-weight: 600; line-height: 1.35; margin-bottom: 4px; min-height: 36px; }
.part-card-notes { font-size: 11px; margin-bottom: 8px; }
.part-card-qty { display: flex; gap: 6px; }
.part-card-qty input[type=number] { width: 70px; padding: 5px 7px; }

/* Нульовий залишок — червона підсвітка скрізь у складі */
input.qty-zero {
    border-color: var(--red) !important;
    background: var(--red-soft);
    color: var(--red);
    font-weight: 700;
}
.cat-zero { background: linear-gradient(135deg, #ff6b60, #c22a1f) !important; }
.zero-count-pill {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: var(--red-soft);
    color: var(--red);
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 700;
}
.zero-alert-btn {
    background: var(--red);
    color: #fff;
}
.zero-alert-btn:hover { background: #a3271f; }

table.pivot-table th, table.pivot-table td { text-align: center; }
table.pivot-table th:first-child, table.pivot-table td:first-child { text-align: left; font-weight: 600; }
.pivot-cell-form { display: inline-flex; gap: 4px; align-items: center; }
.pivot-cell-form input[type=number] { width: 56px; padding: 4px 6px; }

.cat-icon-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: 8px;
    color: #fff;
}
.cat-icon-badge.cat-blue   { background: linear-gradient(135deg, #2f8fe8, #1463c9); }
.cat-icon-badge.cat-green  { background: linear-gradient(135deg, #34c778, #1f9e5c); }
.cat-icon-badge.cat-purple { background: linear-gradient(135deg, #9b6df0, #7440d6); }
.cat-icon-badge.cat-orange { background: linear-gradient(135deg, #ffa24d, #e67d1f); }
.cat-icon-badge.cat-pink   { background: linear-gradient(135deg, #ff6fa5, #dd3f80); }
.cat-icon-badge.cat-teal   { background: linear-gradient(135deg, #33c3c9, #16949c); }
.cat-icon-badge.cat-red    { background: linear-gradient(135deg, #ff6b60, #d6362b); }
.cat-icon-badge.cat-slate  { background: linear-gradient(135deg, #7c8aa0, #566178); }

.filters { display: flex; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; align-items: end; }
.filters label { font-size: 12px; color: var(--ink-soft); display: flex; flex-direction: column; gap: 4px; }

form .field { margin-bottom: 14px; }
form label { font-size: 13px; color: var(--ink-soft); display: block; margin-bottom: 4px; }
input[type=text], input[type=tel], input[type=email], input[type=number], input[type=password], select, textarea {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid var(--line);
    border-radius: 6px;
    font-size: 14px;
    font-family: inherit;
}
textarea { resize: vertical; min-height: 70px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 14px; }

.flash { padding: 10px 14px; border-radius: 6px; margin-bottom: 16px; font-size: 13px; }
.flash-ok { background: var(--accent-soft); color: var(--accent); }
.flash-error { background: var(--red-soft); color: var(--red); }

.comment { padding: 10px 0; border-bottom: 1px solid var(--line); }
.comment-meta { font-size: 12px; color: var(--ink-soft); margin-bottom: 3px; }

.muted { color: var(--ink-soft); }
.empty { color: var(--ink-soft); padding: 30px 0; text-align: center; }

.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
.detail-item { margin-bottom: 10px; font-size: 13px; }
.detail-item .label { color: var(--ink-soft); font-size: 12px; }

@media (max-width: 800px) {
    .app-shell { flex-direction: column; }
    .sidebar { width: 100%; }
    .form-row, .form-row-3, .detail-grid { grid-template-columns: 1fr; }
    .content { padding: 18px; }
}
