/* public/css/app.css */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --accent: #D85A30;
  --accent-light: #FAEEDA;
  --green: #1D9E75;
  --green-light: #E1F5EE;
  --red: #A32D2D;
  --red-light: #FCEBEB;
  --amber: #854F0B;
  --amber-light: #FAEEDA;
  --blue: #185FA5;
  --blue-light: #E6F1FB;
  --gray: #5F5E5A;
  --gray-light: #F1EFE8;
  --bg: #F9F8F6;
  --surface: #FFFFFF;
  --border: rgba(0,0,0,0.1);
  --border-strong: rgba(0,0,0,0.2);
  --text: #1a1a18;
  --text2: #5F5E5A;
  --text3: #888780;
  --radius: 10px;
  --radius-sm: 6px;
  --navbar-h: 52px;
  --stats-h: 68px;
  --tabs-h: 46px;
}

html, body { height: 100%; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; background: var(--bg); color: var(--text); font-size: 15px; -webkit-tap-highlight-color: transparent; }

/* LOGIN */
.login-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 1rem; background: var(--bg); }
.login-card { background: var(--surface); border-radius: 16px; border: 0.5px solid var(--border); padding: 2rem; width: 100%; max-width: 360px; }
.login-logo { display: flex; align-items: center; gap: 12px; margin-bottom: 1.75rem; }
.login-icon { width: 48px; height: 48px; border-radius: 12px; background: var(--accent); display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.login-title { font-size: 20px; font-weight: 600; }
.login-sub { font-size: 12px; color: var(--text2); }
.form-group { margin-bottom: 12px; }
.form-group label { display: block; font-size: 12px; color: var(--text2); margin-bottom: 4px; font-weight: 500; }
.form-group input, .form-group select, .form-group textarea { width: 100%; padding: 9px 12px; border: 0.5px solid var(--border-strong); border-radius: var(--radius-sm); font-size: 14px; background: var(--surface); color: var(--text); outline: none; transition: border-color .15s; }
.form-group input:focus, .form-group select:focus, .form-group textarea:focus { border-color: var(--accent); }
.form-group textarea { min-height: 70px; resize: vertical; }
.error-msg { color: var(--red); font-size: 13px; padding: 8px 12px; background: var(--red-light); border-radius: var(--radius-sm); margin-bottom: 10px; }

/* BUTTONS */
.btn-primary { display: inline-flex; align-items: center; gap: 6px; padding: 9px 16px; background: var(--accent); color: #fff; border: none; border-radius: var(--radius-sm); font-size: 14px; font-weight: 500; cursor: pointer; transition: opacity .15s; }
.btn-primary:hover { opacity: .88; }
.btn-primary.full { width: 100%; justify-content: center; }
.btn-sec { display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; background: var(--surface); color: var(--text); border: 0.5px solid var(--border-strong); border-radius: var(--radius-sm); font-size: 13px; cursor: pointer; transition: background .12s; }
.btn-sec:hover { background: var(--gray-light); }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-danger { background: var(--red-light); color: var(--red); border-color: var(--red); }

/* NAVBAR */
.navbar { height: var(--navbar-h); background: var(--accent); display: flex; align-items: center; justify-content: space-between; padding: 0 1rem; position: sticky; top: 0; z-index: 100; }
.nav-brand { display: flex; align-items: center; gap: 10px; }
.nav-icon { width: 32px; height: 32px; background: rgba(255,255,255,0.2); border-radius: 8px; display: flex; align-items: center; justify-content: center; }
.nav-title { color: #fff; font-size: 16px; font-weight: 600; }
.nav-actions { display: flex; align-items: center; gap: 10px; }
.nav-user { color: rgba(255,255,255,0.85); font-size: 13px; }
.nav-btn { background: rgba(255,255,255,0.15); border: none; color: #fff; width: 32px; height: 32px; border-radius: 6px; cursor: pointer; display: flex; align-items: center; justify-content: center; }
.nav-btn:hover { background: rgba(255,255,255,0.25); }
.nav-admin-link { background: rgba(255,255,255,0.15); border: none; color: #fff; height: 32px; padding: 0 10px; border-radius: 6px; cursor: pointer; display: flex; align-items: center; gap: 6px; font-size: 13px; text-decoration: none; white-space: nowrap; }
.nav-admin-link:hover { background: rgba(255,255,255,0.25); }
.sync-dot { width: 8px; height: 8px; border-radius: 50%; background: #ccc; display: inline-block; }
.sync-dot.connected { background: #5DCAA5; }
.sync-dot.disconnected { background: #F09595; }

/* STATS */
.stats-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(90px, 1fr)); gap: 6px; padding: 10px 12px 0; }
.stat-card { background: var(--surface); border-radius: var(--radius-sm); padding: 8px 10px; border: 0.5px solid var(--border); }
.stat-label { font-size: 10px; color: var(--text3); margin-bottom: 2px; }
.stat-val { font-size: 20px; font-weight: 600; }
.stat-val.g { color: var(--green); }
.stat-val.o { color: var(--accent); }
.stat-val.r { color: var(--red); }
.stat-val.b { color: var(--blue); }

/* TABS */
.tabs-bar { display: flex; background: var(--surface); border-bottom: 0.5px solid var(--border); overflow-x: auto; padding: 0 4px; position: sticky; top: var(--navbar-h); z-index: 90; -ms-overflow-style: none; scrollbar-width: none; }
.tabs-bar::-webkit-scrollbar { display: none; }
.tab { display: flex; align-items: center; gap: 5px; padding: 12px 14px; font-size: 13px; color: var(--text2); background: none; border: none; border-bottom: 2px solid transparent; cursor: pointer; white-space: nowrap; transition: all .15s; flex-shrink: 0; }
.tab:hover { color: var(--text); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 500; }

/* PAGE */
.page-content { padding: 12px; max-width: 1200px; margin: 0 auto; }

/* TOOLBAR */
.toolbar { display: flex; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.toolbar input, .toolbar select { flex: 1; min-width: 120px; padding: 8px 10px; border: 0.5px solid var(--border-strong); border-radius: var(--radius-sm); font-size: 13px; background: var(--surface); color: var(--text); outline: none; }
.toolbar input:focus, .toolbar select:focus { border-color: var(--accent); }

/* TABLE */
.tbl-wrap { overflow-x: auto; background: var(--surface); border-radius: var(--radius); border: 0.5px solid var(--border); }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; font-size: 11px; font-weight: 600; color: var(--text2); padding: 8px 12px; border-bottom: 0.5px solid var(--border); background: var(--bg); text-transform: uppercase; letter-spacing: 0.03em; }
td { padding: 10px 12px; border-bottom: 0.5px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--bg); }

/* BADGES */
.badge { display: inline-block; padding: 2px 8px; border-radius: 20px; font-size: 11px; font-weight: 500; white-space: nowrap; }
.b-free    { background: var(--green-light); color: #085041; }
.b-out     { background: var(--amber-light); color: var(--amber); }
.b-repair  { background: var(--red-light); color: var(--red); }
.b-lost    { background: var(--gray-light); color: var(--gray); }
.b-broken  { background: var(--red-light); color: var(--red); }
.b-written_off { background: var(--gray-light); color: var(--gray); }

/* COND BAR */
.cond-bar { display: flex; align-items: center; gap: 5px; min-width: 80px; }
.cond-track { flex: 1; height: 4px; background: var(--border); border-radius: 2px; overflow: hidden; }
.cond-fill { height: 100%; border-radius: 2px; }
.cond-val { font-size: 11px; color: var(--text3); min-width: 28px; text-align: right; }

/* CARDS (mobile) */
.eq-card { background: var(--surface); border-radius: var(--radius); border: 0.5px solid var(--border); padding: 12px; margin-bottom: 8px; }
.eq-card-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; margin-bottom: 8px; }
.eq-card-name { font-weight: 600; font-size: 14px; }
.eq-card-id { font-size: 11px; color: var(--text3); font-family: monospace; }
.eq-card-row { display: flex; justify-content: space-between; font-size: 12px; color: var(--text2); margin-bottom: 4px; }
.eq-card-actions { display: flex; gap: 6px; margin-top: 10px; flex-wrap: wrap; }

/* SCAN PAGE */
.scan-cam-box { width: 100%; max-width: 360px; margin: 0 auto 16px; border-radius: var(--radius); overflow: hidden; background: #000; }
#qr-reader { width: 100% !important; }
#qr-reader video { width: 100% !important; height: auto !important; }
#qr-reader img { display: none; }
.scan-result-card { background: var(--surface); border-radius: var(--radius); border: 0.5px solid var(--border); padding: 14px; margin-bottom: 12px; }
.scan-result-title { font-size: 16px; font-weight: 600; margin-bottom: 4px; }
.scan-result-sub { font-size: 13px; color: var(--text2); }
.scan-actions { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.manual-row { display: flex; gap: 8px; margin-bottom: 12px; }
.manual-row input { flex: 1; }

/* EMPLOYEE CARD */
.emp-card { display: flex; align-items: center; gap: 12px; padding: 12px; background: var(--surface); border-radius: var(--radius); border: 0.5px solid var(--border); margin-bottom: 8px; }
.emp-ava { width: 40px; height: 40px; border-radius: 50%; background: var(--amber-light); color: var(--amber); display: flex; align-items: center; justify-content: center; font-weight: 600; font-size: 13px; flex-shrink: 0; }
.emp-info { flex: 1; }
.emp-name { font-weight: 500; font-size: 14px; }
.emp-role { font-size: 12px; color: var(--text2); }
.emp-cnt { font-size: 12px; color: var(--accent); font-weight: 500; background: none; border: none; cursor: pointer; padding: 4px; }
.emp-cnt:hover { text-decoration: underline; }

/* ON-HAND MODAL (что сейчас на руках у сотрудника) */
.onhand-list { max-height: 60vh; overflow-y: auto; }
.onhand-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 0; border-bottom: 0.5px solid var(--border); }
.onhand-row:last-child { border-bottom: none; }
.onhand-name { font-size: 14px; font-weight: 500; }
.onhand-meta { font-size: 12px; color: var(--text3); margin-top: 2px; }

/* HISTORY MODAL — свёрнутый список остальных записей под последней */
.history-details { margin-top: 10px; border-top: 0.5px solid var(--border); padding-top: 10px; }
.history-details summary { cursor: pointer; font-size: 13px; color: var(--accent); font-weight: 500; list-style: none; user-select: none; }
.history-details summary::-webkit-details-marker { display: none; }
.history-details summary::before { content: '▸ '; display: inline-block; width: 12px; }
.history-details[open] summary::before { content: '▾ '; }

/* MAINTENANCE */
.to-item { display: flex; align-items: center; gap: 10px; padding: 10px 12px; background: var(--surface); border-radius: var(--radius); border: 0.5px solid var(--border); margin-bottom: 6px; }
.to-item.overdue { border-color: #F09595; background: var(--red-light); }
.to-item.soon { border-color: #EF9F27; background: var(--amber-light); }

/* MODAL */
.modal-ov { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 200; align-items: flex-end; justify-content: center; padding-bottom: env(safe-area-inset-bottom); }
.modal-ov.open { display: flex; }
.modal { background: var(--surface); border-radius: 16px 16px 0 0; width: 100%; max-width: 480px; padding: 1.25rem 1.25rem calc(1.25rem + env(safe-area-inset-bottom)); max-height: 90vh; overflow-y: auto; }
/* Шире обычного — для контента с таблицами в несколько колонок (история). */
.modal.modal-wide { max-width: 760px; }
.modal-handle { width: 36px; height: 4px; background: var(--border-strong); border-radius: 2px; margin: 0 auto 16px; }
.modal-title { font-size: 16px; font-weight: 600; margin-bottom: 16px; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }

/* QR PRINT PAGE */
@media print {
  .navbar, .stats-row, .tabs-bar, .toolbar, button { display: none !important; }
  .qr-print-grid { display: grid !important; grid-template-columns: repeat(3, 1fr); gap: 10px; padding: 0; }
  .qr-print-card { border: 1px solid #ccc; border-radius: 8px; padding: 10px; text-align: center; page-break-inside: avoid; }
}
.qr-print-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; }
.qr-print-card { background: var(--surface); border-radius: var(--radius); border: 0.5px solid var(--border); padding: 12px; text-align: center; }
.qr-print-card canvas, .qr-print-card img { max-width: 100%; height: auto; }
.qr-card-name { font-size: 12px; font-weight: 500; margin-top: 6px; }
.qr-card-id { font-size: 10px; color: var(--text3); font-family: monospace; }

/* SPINNER */
@keyframes spin { to { transform: rotate(360deg); } }

/* HISTORY */
.hist-action { font-weight: 500; }
.hist-issue { color: var(--amber); }
.hist-return { color: var(--green); }
.hist-lost, .hist-broken { color: var(--red); }
.hist-maintenance { color: var(--blue); }

/* LABEL PRINT (термопринтер, напр. TSC TE200) */
.label-size-controls { display: flex; gap: 12px; }
.label-size-controls .form-group { flex: 1; margin-bottom: 0; }
.label-preset-row { display: flex; gap: 8px; margin-top: 8px; }
.label-preview-wrap { display: flex; justify-content: center; align-items: center; padding: 16px; margin: 12px 0; background: var(--gray-light); border-radius: var(--radius); overflow: auto; }

/* Горизонтальная раскладка: QR по высоте слева, текст справа — большинство
   рулонов термопринтера (58×40, 60×40, 70×40...) альбомные (шире, чем выше),
   вертикальный стек с QR сверху там физически не влезает по высоте. */
/* container-type:size — img/шрифты ниже в cq*-юнитах реально пересчитываются
   от текущего размера .label-box (ширина/высота выставляются инлайново из
   printLabel()/updatePreview() в мм), а не от вьюпорта — так один и тот же
   CSS остаётся читаемым и на 30×20, и на 43×25, и на 52×70, без обрезания. */
.label-box { container-type: size; display: flex; flex-direction: row; align-items: center; gap: 1.2mm; padding: 1.2mm; background: #fff; box-sizing: border-box; font-family: Arial, Helvetica, sans-serif; overflow: hidden; }
.label-box img { height: 90cqh; width: auto; max-width: 45cqw; flex-shrink: 0; display: block; }
.label-box .label-text { display: flex; flex-direction: column; justify-content: center; gap: 0.6mm; min-width: 0; overflow: hidden; }
.label-box .label-code { font-size: 14cqw; font-weight: 700; letter-spacing: .1mm; white-space: nowrap; }
.label-box .label-name { font-size: 9cqw; line-height: 1.15; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; }

#printLabelRoot { display: none; }

/* Печать одной этикетки — активна только пока на <body> висит .label-printing
   (выставляется в printLabel() перед window.print() и снимается по afterprint),
   чтобы не конфликтовать с существующей печатью QR-сетки выше.
   ВАЖНО: убираем соседей через display:none (реально схлопывает высоту
   документа), а не visibility:hidden + position:fixed — Chrome повторяет
   fixed-элементы на КАЖДОЙ странице печати, а visibility:hidden не убирает
   контент из потока, так что при большой скрытой высоте страницы плодились
   дублирующиеся страницы с одной и той же этикеткой. */
@media print {
  body.label-printing > *:not(#printLabelRoot) { display: none !important; }
  body.label-printing #printLabelRoot { display: block !important; }
}

/* RESPONSIVE */
@media (max-width: 600px) {
  .page-content { padding: 8px; }
  .stats-row { grid-template-columns: repeat(3, 1fr); gap: 5px; padding: 8px 8px 0; }
  .stat-val { font-size: 18px; }
  .tbl-wrap { display: none; }
  .eq-cards { display: block; }
  .modal { border-radius: 20px 20px 0 0; }
}
@media (min-width: 601px) {
  .eq-cards { display: none; }
  .modal-ov { align-items: center; }
  .modal { border-radius: 16px; max-height: 80vh; }
}
