/* L4 Інвентаризація — базові стилі. Mobile-first, без CDN. */
:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --border: #d9dee5;
  --text: #1c2430;
  --muted: #5e6b7a;
  --primary: #0b5fa5;
  --primary-dark: #084a80;
  --primary-soft: #e3effa;
  --success: #1f7a3f;
  --success-soft: #e2f3e8;
  --warning: #9a6200;
  --warning-soft: #fff3d6;
  --danger: #b42318;
  --danger-soft: #fde8e6;
  --radius: 8px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .1);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
* { box-sizing: border-box; }
html { font-size: 16px; }
body { margin: 0; font-family: var(--font); color: var(--text); background: var(--bg); line-height: 1.45; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.4rem; margin: 0 0 .75rem; }
h2 { font-size: 1.15rem; margin: 1.25rem 0 .5rem; }
h3 { font-size: 1rem; margin: 1rem 0 .4rem; }
small, .muted { color: var(--muted); }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .9em; }

/* Шапка */
.topbar { background: #11314f; color: #fff; position: sticky; top: 0; z-index: 50; }
.topbar .inner { display: flex; align-items: center; gap: .75rem; padding: .5rem .9rem; max-width: 1400px; margin: 0 auto; }
.topbar .brand { font-weight: 700; color: #fff; letter-spacing: .2px; white-space: nowrap; }
.topbar nav { display: none; gap: .25rem; margin-left: .5rem; }
.topbar nav a { color: #d6e4f3; padding: .4rem .6rem; border-radius: 6px; font-weight: 500; }
.topbar nav a:hover, .topbar nav a.active { background: rgba(255,255,255,.14); color: #fff; text-decoration: none; }
.topbar .spacer { flex: 1; }
.topbar .user { color: #d6e4f3; font-size: .9rem; white-space: nowrap; }
.topbar .user .user-name { display: none; }
@media (min-width: 900px) { .topbar .user .user-name { display: inline; } }
.topbar .menu-btn { background: none; border: 1px solid rgba(255,255,255,.35); color: #fff; border-radius: 6px; padding: .35rem .55rem; font-size: 1.05rem; }
.mobile-nav { display: none; background: #0e2a44; padding: .4rem .6rem .7rem; }
.mobile-nav a { display: block; color: #e8f0f8; padding: .55rem .5rem; border-radius: 6px; }
.mobile-nav a.active { background: rgba(255,255,255,.14); }
.mobile-nav.open { display: block; }
@media (min-width: 900px) {
  .topbar nav { display: flex; }
  .topbar .menu-btn { display: none; }
  .mobile-nav { display: none !important; }
}

/* Контейнер */
.container { max-width: 1400px; margin: 0 auto; padding: .9rem; }
.page-head { display: flex; flex-wrap: wrap; align-items: center; gap: .6rem; margin-bottom: .75rem; }
.page-head h1 { flex: 1 1 auto; margin: 0; }
.actions { display: flex; flex-wrap: wrap; gap: .4rem; }

/* Картки */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .9rem; box-shadow: var(--shadow); margin-bottom: .9rem; }
.card h2:first-child, .card h3:first-child { margin-top: 0; }
.grid { display: grid; gap: .9rem; }
.grid > * { min-width: 0; }
.card { min-width: 0; }
@media (min-width: 800px) { .grid.cols-2 { grid-template-columns: 1fr 1fr; } .grid.cols-3 { grid-template-columns: repeat(3, 1fr); } }
.kv { display: grid; grid-template-columns: minmax(120px, 38%) 1fr; gap: .3rem .8rem; font-size: .95rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; }

/* Кнопки */
.btn { display: inline-flex; align-items: center; gap: .35rem; padding: .5rem .85rem; border-radius: 6px; border: 1px solid var(--primary); background: var(--primary); color: #fff; font: inherit; font-weight: 500; cursor: pointer; text-decoration: none !important; line-height: 1.2; min-height: 40px; }
.btn:hover { background: var(--primary-dark); }
.btn.secondary { background: #fff; color: var(--primary); }
.btn.secondary:hover { background: var(--primary-soft); }
.btn.success { background: var(--success); border-color: var(--success); }
.btn.danger { background: var(--danger); border-color: var(--danger); }
.btn.warning { background: var(--warning); border-color: var(--warning); }
.btn.ghost { background: transparent; border-color: var(--border); color: var(--text); }
.btn.sm { padding: .3rem .6rem; min-height: 32px; font-size: .9rem; }
.btn.lg { padding: .8rem 1.2rem; font-size: 1.05rem; min-height: 48px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-row { display: flex; flex-wrap: wrap; gap: .5rem; }
.btn-row.sticky-bottom { position: sticky; bottom: 0; background: var(--bg); padding: .6rem 0; }

/* Форми */
form .field { margin-bottom: .8rem; }
label { display: block; font-size: .9rem; font-weight: 600; margin-bottom: .25rem; }
input[type=text], input[type=search], input[type=number], input[type=date], input[type=datetime-local], input[type=password], input[type=email], input[type=file], select, textarea {
  width: 100%; padding: .55rem .65rem; border: 1px solid var(--border); border-radius: 6px; font: inherit; background: #fff; min-height: 42px;
}
textarea { min-height: 80px; }
input:focus, select:focus, textarea:focus { outline: 2px solid #8fbcea; border-color: var(--primary); }
.help { font-size: .82rem; color: var(--muted); margin-top: .2rem; }
.errorlist { color: var(--danger); margin: .2rem 0 0; padding-left: 1.1rem; font-size: .88rem; }
.form-grid { display: grid; gap: .3rem .9rem; }
@media (min-width: 700px) { .form-grid { grid-template-columns: 1fr 1fr; } .form-grid .span-2 { grid-column: span 2; } }
.inline-form { display: flex; flex-wrap: wrap; gap: .5rem; align-items: end; }
.inline-form .field { margin: 0; flex: 1 1 160px; }
.checkbox { display: flex; align-items: center; gap: .5rem; font-weight: 500; }
.checkbox input { width: 1.15rem; height: 1.15rem; min-height: auto; }

/* Таблиці */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; border: 1px solid var(--border); border-radius: var(--radius); background: #fff; }
table { border-collapse: collapse; width: 100%; font-size: .92rem; }
th, td { padding: .5rem .6rem; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
th { background: #f0f3f7; font-weight: 600; white-space: nowrap; position: sticky; top: 0; }
tr:hover td { background: #f7fafd; }
td.num, th.num { text-align: right; white-space: nowrap; }
.table-wrap.compact th, .table-wrap.compact td { padding: .35rem .5rem; }

/* Мітки */
.badge { display: inline-block; padding: .12rem .5rem; border-radius: 999px; font-size: .78rem; font-weight: 600; white-space: nowrap; background: #e9edf2; color: #344054; }
.badge.ok, .badge.in_use, .badge.found { background: var(--success-soft); color: var(--success); }
.badge.in_stock { background: var(--primary-soft); color: var(--primary); }
.badge.reserve { background: #ede9fe; color: #5b21b6; }
.badge.repair, .badge.warn, .badge.discrepancy, .badge.pending { background: var(--warning-soft); color: var(--warning); }
.badge.written_off, .badge.lost, .badge.danger, .badge.not_found { background: var(--danger-soft); color: var(--danger); }
.badge.clarify { background: #fde8e6; color: #b42318; border: 1px dashed #b42318; }

/* Повідомлення */
.messages { margin-bottom: .8rem; }
.msg { padding: .6rem .8rem; border-radius: 6px; margin-bottom: .4rem; border: 1px solid transparent; }
.msg.success { background: var(--success-soft); color: var(--success); border-color: #b7e1c6; }
.msg.error { background: var(--danger-soft); color: var(--danger); border-color: #f3b5b0; }
.msg.warning { background: var(--warning-soft); color: var(--warning); border-color: #f1d79a; }
.msg.info { background: var(--primary-soft); color: var(--primary-dark); border-color: #b9d4ef; }

/* Фільтри */
.filters { display: grid; gap: .5rem; grid-template-columns: 1fr; margin-bottom: .8rem; }
@media (min-width: 700px) { .filters { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); } }
.filters .field { margin: 0; }
.filters label { font-size: .8rem; }
.filters input, .filters select { min-height: 38px; padding: .4rem .5rem; }

/* Списки на телефоні */
.list { display: flex; flex-direction: column; gap: .5rem; }
.list-item { background: #fff; border: 1px solid var(--border); border-radius: var(--radius); padding: .7rem .8rem; display: block; color: inherit; }
.list-item:hover { text-decoration: none; border-color: var(--primary); }
.list-item .title { font-weight: 600; }
.list-item .sub { color: var(--muted); font-size: .88rem; }
.list-item .row { display: flex; justify-content: space-between; gap: .5rem; align-items: center; }

/* Фото */
.thumbs { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: .5rem; }
.thumbs a { display: block; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; background: #fff; }
.thumbs img { width: 100%; height: 110px; object-fit: cover; display: block; }
.thumbs .doc { padding: .5rem; font-size: .82rem; word-break: break-all; height: 110px; overflow: hidden; }

/* Пагінація */
.pagination { display: flex; gap: .4rem; align-items: center; flex-wrap: wrap; margin: .8rem 0; }

/* Стат-плитки */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: .6rem; }
.stat { background: #fff; border: 1px solid var(--border); border-radius: var(--radius); padding: .7rem .8rem; }
.stat .n { font-size: 1.5rem; font-weight: 700; }
.stat .l { color: var(--muted); font-size: .85rem; }

/* Друк */
@media print {
  .topbar, .mobile-nav, .actions, .btn, .filters, .pagination, .no-print { display: none !important; }
  body { background: #fff; }
  .card { box-shadow: none; border: none; padding: 0; }
  .container { max-width: none; padding: 0; }
  th { position: static; }
}
.qr-sheet { display: grid; grid-template-columns: repeat(auto-fill, minmax(62mm, 1fr)); gap: 4mm; }
.qr-label { border: 1px dashed #999; padding: 3mm; display: flex; gap: 3mm; align-items: center; break-inside: avoid; }
.qr-label img { width: 26mm; height: 26mm; }
.qr-label .t { font-size: 11pt; font-weight: 700; }
.qr-label .s { font-size: 8.5pt; color: #333; }
.login-box { max-width: 380px; margin: 8vh auto; }
.tabs { display: flex; gap: .3rem; flex-wrap: wrap; border-bottom: 1px solid var(--border); margin-bottom: .8rem; }
.tabs a { padding: .5rem .7rem; border-bottom: 2px solid transparent; color: var(--muted); font-weight: 500; }
.tabs a.active { color: var(--primary); border-color: var(--primary); }
.htmx-indicator { display: none; }
.htmx-request .htmx-indicator { display: inline; }
details summary { cursor: pointer; font-weight: 600; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.big-check { font-size: 1.1rem; padding: 1rem; }
.sticky-actions { position: sticky; bottom: 0; background: linear-gradient(transparent, var(--bg) 30%); padding: .8rem 0 .4rem; }

/* Розділ «Майно»: підрозділи секції, масові дії, картка */
.subnav { display: flex; gap: .35rem; flex-wrap: wrap; margin-bottom: .8rem; }
.subnav a { padding: .35rem .75rem; border-radius: 999px; border: 1px solid var(--border); background: #fff; color: var(--text); font-size: .9rem; font-weight: 500; }
.subnav a:hover { text-decoration: none; border-color: var(--primary); }
.subnav a.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.tabs .n { color: var(--muted); font-size: .78rem; margin-left: .3rem; font-weight: 400; }
.tabs a.active .n { color: var(--primary); }
@media (max-width: 699px) { .desktop-only { display: none !important; } }
@media (min-width: 700px) { .mobile-only { display: none !important; } }
.search-row { display: flex; gap: .5rem; margin-bottom: .6rem; }
.search-row input[type=search] { flex: 1; }
.bulk-bar { display: flex; flex-wrap: wrap; gap: .4rem; align-items: center; background: var(--primary-soft); border: 1px solid #b9d4ef; border-radius: var(--radius); padding: .5rem .7rem; margin-bottom: .6rem; }
.bulk-bar .count { font-weight: 600; margin-right: .3rem; }
td.chk, th.chk { width: 2rem; text-align: center; }
td.chk input, .list-item input[type=checkbox] { width: 1.15rem; height: 1.15rem; min-height: auto; }
.list-item.sel { display: flex; gap: .6rem; align-items: flex-start; }
.list-item.sel .body { flex: 1; min-width: 0; }
.action-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: .5rem; }
.action-grid .btn, .action-grid form { width: 100%; }
.action-grid .btn { justify-content: center; }
.asset-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: .4rem .8rem; }
.asset-head .num { font-size: 1.5rem; font-weight: 700; letter-spacing: .3px; }
.asset-head .model { font-size: 1.1rem; }
.hist { list-style: none; margin: 0; padding: 0; }
.hist li { padding: .5rem 0; border-bottom: 1px solid var(--border); font-size: .92rem; }
.hist li:last-child { border-bottom: none; }
.hist .when { color: var(--muted); font-size: .82rem; }
.hist .arrow { color: var(--muted); }
.preview-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(80px, 1fr)); gap: .4rem; margin-top: .5rem; }
.preview-grid img { width: 100%; height: 80px; object-fit: cover; border-radius: 6px; border: 1px solid var(--border); }
.thumbs .thumb-wrap { position: relative; }
.thumbs .thumb-wrap form { position: absolute; top: 2px; right: 2px; }
.qr-box { text-align: center; }
.qr-box img { width: 160px; height: 160px; }
.warn-box { background: var(--warning-soft); border: 1px solid #f1d79a; color: var(--warning); border-radius: 6px; padding: .6rem .8rem; margin-bottom: .8rem; }
.owner-group h3 { display: flex; align-items: center; gap: .5rem; }
.sortlink { color: inherit; }
.sortlink.active { color: var(--primary); }
.detail-grid { display: grid; gap: .9rem; }
@media (min-width: 1000px) { .detail-grid { grid-template-columns: 2fr 1fr; align-items: start; } }

/* Звірки (apps.inventories) */
.progress { height: 8px; background: #e9edf2; border-radius: 999px; overflow: hidden; margin-top: .6rem; }
.progress > div { height: 100%; background: var(--success); }
.inv-line.status-found { border-left: 4px solid var(--success); }
.inv-line.status-not_found { border-left: 4px solid var(--danger); }
.inv-line.status-discrepancy { border-left: 4px solid var(--warning); }
.inv-line.status-pending { border-left: 4px solid var(--border); }
.inv-line .btn.success { min-height: 46px; }

/* --- L4 Живлення: доповнення --- */
.topbar { background: #1f2a44; }
.mobile-nav { background: #182238; }
.big { font-size: 1.6rem; font-weight: 700; line-height: 1.1; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: .6rem; margin-bottom: .9rem; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .6rem .8rem; }
.stat .label { font-size: .8rem; color: var(--muted); }
.stat.danger { border-color: var(--danger); background: var(--danger-soft); }
.stat.warn { border-color: var(--warning); background: var(--warning-soft); }
.row-overdue td { background: #fde8e6 !important; }
.row-outage td { background: #fff8e6 !important; }
.list { display: grid; gap: .5rem; }
.list-item { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .6rem .8rem; display: block; color: inherit; }
.list-item:hover { text-decoration: none; border-color: var(--primary); }
.list-item .title { font-weight: 600; }
.list-item.overdue { border-left: 4px solid var(--danger); }
.list-item.outage { border-left: 4px solid var(--warning); }
.list-item.grid_on { border-left: 4px solid var(--success); }
.msg { padding: .55rem .8rem; border-radius: 6px; margin-bottom: .6rem; background: var(--primary-soft); color: var(--primary-dark); }
.msg.success { background: var(--success-soft); color: var(--success); }
.msg.error { background: var(--danger-soft); color: var(--danger); }
.msg.warning { background: var(--warning-soft); color: var(--warning); }
.filters { display: flex; flex-wrap: wrap; gap: .5rem; align-items: end; margin-bottom: .7rem; }
.filters .field { margin: 0; flex: 1 1 140px; }
.pagination { display: flex; gap: .5rem; align-items: center; margin: .8rem 0; }
details.card summary { cursor: pointer; font-weight: 600; }
.assume { font-size: .85rem; color: var(--warning); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .85rem; white-space: pre-wrap; }
.service { display: inline-block; padding: .2rem .5rem; border-radius: 6px; font-size: .85rem; margin-right: .4rem; background: #e9edf2; }
.service.ok { background: var(--success-soft); color: var(--success); }
.service.fail { background: var(--danger-soft); color: var(--danger); }
.demo-banner { background: #ede9fe; color: #5b21b6; text-align: center; padding: .3rem; font-size: .85rem; }
