:root {
    --primary: #1e481e;
    --primary-dark: #153415;
    --primary-faded: rgba(30, 72, 30, .08);
    --text: #1a1a1a;
    --muted: #6b7280;
    --bg: #f4f6f4;
    --border: #d1e0d1;
    --danger: #a5281c;
    --radius: 10px;
}

* { box-sizing: border-box; }
body { margin: 0; font-family: 'Segoe UI', system-ui, -apple-system, sans-serif; background: var(--bg); color: var(--text); font-size: 14px; }
a { color: var(--primary); }
h1 { font-size: 22px; margin: 0 0 4px; }
h2 { font-size: 17px; margin: 0 0 12px; }
.muted { color: var(--muted); }
.opt { color: var(--muted); font-weight: 400; }
[hidden] { display: none !important; }

.topbar { display: flex; align-items: center; gap: 22px; padding: 10px 22px; background: var(--primary); color: #fff; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 10px; color: #fff; text-decoration: none; font-weight: 700; font-size: 16px; }
.brand img { width: 32px; height: 32px; border-radius: 7px; }
.brand small { font-weight: 400; opacity: .75; margin-left: 4px; }
.nav { display: flex; gap: 4px; flex: 1; flex-wrap: wrap; }
.nav a { color: #fff; text-decoration: none; padding: 7px 12px; border-radius: 8px; opacity: .85; }
.nav a:hover, .nav a.is-on { background: rgba(255,255,255,.14); opacity: 1; }
.user { display: flex; align-items: center; gap: 10px; margin: 0; }
.user span { opacity: .85; }

.page { max-width: 1400px; margin: 0 auto; padding: 20px 22px 40px; }
.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 16px; flex-wrap: wrap; }
.page-head > div:last-child { display: flex; gap: 8px; align-items: center; }

.card { background: #fff; border-radius: var(--radius); padding: 18px 20px; margin-bottom: 16px; box-shadow: 0 2px 12px rgba(30, 72, 30, .08); }
.card.narrow { max-width: 460px; margin: 40px auto; }
.card.highlight { border: 2px solid var(--primary); }
.code-big { font-family: Consolas, monospace; font-size: 40px; letter-spacing: .12em; font-weight: 700; margin: 6px 0 10px; }

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 16px; margin-bottom: 16px; }
.tile { background: #fff; border-radius: var(--radius); padding: 18px 20px; box-shadow: 0 2px 12px rgba(30, 72, 30, .08); border-top: 4px solid var(--primary); }
.tile-nums { display: flex; gap: 30px; }
.tile-nums strong { display: block; font-size: 34px; color: var(--primary); }
.tile-nums span { color: var(--muted); }
.tile-links { display: flex; gap: 16px; margin-top: 12px; }

input, select, textarea { font: inherit; padding: 8px 10px; border: 1px solid #cfd8cf; border-radius: 8px; background: #fff; width: 100%; }
textarea { font-family: Consolas, monospace; font-size: 13px; line-height: 1.45; }
label { display: flex; flex-direction: column; gap: 4px; font-weight: 600; font-size: 13px; }
label.check { flex-direction: row; align-items: flex-start; gap: 8px; font-weight: 400; font-size: 14px; }
label.check input { width: auto; margin-top: 3px; }
.input-code { font-family: Consolas, monospace; font-size: 22px; letter-spacing: .1em; text-transform: uppercase; }

.stack { display: flex; flex-direction: column; gap: 12px; }
.grid-form { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px 16px; }
.grid-form .wide { grid-column: 1 / -1; }
.doc-form { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 16px; }
.doc-form .wide { grid-column: 1 / -1; }
.filters { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; margin-bottom: 14px; }
.filters label { min-width: 160px; }
.inline { display: inline; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--primary); border-radius: 8px; padding: 8px 16px; font: inherit; font-weight: 700; cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-outline { background: #fff; color: var(--primary); }
.btn-ghost { background: transparent; color: #fff; border-color: rgba(255,255,255,.5); padding: 5px 12px; }
.btn-danger { background: #fff; color: var(--danger); border-color: #e3b1ab; }
.btn-small { padding: 4px 10px; font-size: 12px; }
.btn-wide { width: 100%; padding: 12px; }

.alert { padding: 10px 14px; border-radius: 8px; margin-bottom: 12px; }
.alert-ok { background: #e3f1e2; color: #1e481e; }
.alert-err { background: #fbe3e0; color: var(--danger); }

.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th { background: var(--primary); color: #fff; text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .03em; padding: 9px 10px; white-space: nowrap; }
.table th:first-child { border-top-left-radius: 8px; }
.table th:last-child { border-top-right-radius: 8px; }
.table td { padding: 8px 10px; border-bottom: 1px solid #edf1ed; vertical-align: middle; }
.table-dense td { padding: 6px 8px; font-size: 13px; }
.table tr.row-in td { background: #f3faf2; }
.actions { display: flex; gap: 6px; }
.actions form { margin: 0; }
img.sig { height: 30px; max-width: 90px; background: #fff; border: 1px solid #eee; border-radius: 4px; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 700; background: #eef1ee; color: #444; white-space: nowrap; }
.badge-ok { background: #dff0de; color: #1e481e; }
.badge-wait { background: #f6ecd6; color: #6b4a1a; }
.badge-warn { background: #fbe7cf; color: #8a4b00; }
.badge-muted { background: #eee; color: #888; }

.field { display: flex; flex-direction: column; gap: 4px; position: relative; }
.field label { font-weight: 600; font-size: 13px; }
.ref-list { position: absolute; top: 100%; left: 0; right: 0; z-index: 5; background: #fff; border: 1px solid var(--border); border-radius: 8px; box-shadow: 0 8px 24px rgba(0,0,0,.12); max-height: 280px; overflow-y: auto; }
.ref-list button { display: block; width: 100%; text-align: left; border: 0; background: #fff; padding: 9px 12px; cursor: pointer; font: inherit; }
.ref-list button:hover { background: var(--primary-faded); }
.ref-list small { color: var(--muted); margin-left: 6px; }

.check-col { width: 70px; text-align: center; }
.box { display: inline-block; width: 18px; height: 18px; border: 1.5px solid #333; border-radius: 3px; }

@media (max-width: 800px) {
    .grid-form, .doc-form { grid-template-columns: 1fr; }
}

@media print {
    .topbar, .no-print, .alert { display: none !important; }
    body { background: #fff; }
    .page { padding: 0; }
    .card { box-shadow: none; padding: 0; margin-bottom: 18px; }
    .print-block { break-inside: avoid; }
    .table th { background: #ddd !important; color: #000; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
