:root {
    --bg: #09090b; --card: #141417; --bdr: #27272a; --ac: #10b981; --txt: #fafafa; --txt2: #a1a1aa;
    --input: #1c1c1f; --hover: rgba(255,255,255,0.03); --modal-bg: #141417; --modal-btn: #27272a;
}
body.light-theme {
    --bg: #f4f4f5; --card: #ffffff; --bdr: #e4e4e7; --ac: #059669; --txt: #09090b; --txt2: #71717a;
    --input: #ffffff; --hover: rgba(0,0,0,0.04); --modal-bg: #ffffff; --modal-btn: #e4e4e7;
}
body { font-family: 'Inter', sans-serif; background: var(--bg); color: var(--txt); -webkit-tap-highlight-color: transparent; margin: 0; transition: background 0.2s, color 0.2s; overflow-x: hidden; }

.section { display: none; padding-bottom: 140px; }
.section.active { display: block; animation: fadeIn 0.2s ease-out; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.tbl-wrap { width: 100%; background: var(--card); border: 1px solid var(--bdr); border-radius: 16px; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; table-layout: auto; }
th { background: var(--hover); padding: 12px; text-align: left !important; font-size: 11px; text-transform: uppercase; color: var(--txt2); border-bottom: 1px solid var(--bdr); font-weight: 700; }
td { padding: 14px 12px; border-bottom: 1px solid var(--bdr); font-size: 14px; cursor: pointer; }

.cell-qty { text-align: right !important; padding-right: 14px !important; font-weight: 800; font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace; font-variant-numeric: tabular-nums; white-space: nowrap !important; min-width: 60px; font-size: 15px; letter-spacing: -0.02em; }
.cell-name { word-break: normal; overflow-wrap: break-word; line-height: 1.3; }

.active-row { background: rgba(16, 185, 129, 0.15) !important; position: relative; }
.active-row td:first-child { box-shadow: inset 4px 0 0 var(--ac); }

.row-cat {
  background: rgba(34, 197, 94, 0.08);
  color: #4ade80;
  font-weight: 800;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  opacity: 0.9;
}
.row-sub {
  background: rgba(167, 139, 250, 0.07);
  color: #a78bfa;
  font-weight: 700;
  font-size: 10px;
  text-transform: uppercase;
  opacity: 0.85;
  padding-left: 12px !important;
}
body.light-theme .row-cat {
  background: rgba(5, 150, 105, 0.08);
  color: #059669;
}
body.light-theme .row-sub {
  background: rgba(124, 58, 237, 0.07);
  color: #7c3aed;
}
.item-name-text {
  font-weight: 700;
  font-size: 14px;
  line-height: 1.25;
  color: var(--txt);
}
.item-path-line {
  font-size: 9px;
  text-transform: uppercase;
  margin-top: 3px;
  line-height: 1.35;
}
.item-path-line .path-cat {
  color: #4ade80;
  opacity: 0.75;
  font-weight: 700;
}
.item-path-line .path-sub {
  color: #a78bfa;
  opacity: 0.75;
  font-weight: 600;
}
.item-path-line .path-sep {
  color: var(--txt2);
  opacity: 0.45;
}
body.light-theme .item-path-line .path-cat { color: #059669; opacity: 0.8; }
body.light-theme .item-path-line .path-sub { color: #7c3aed; opacity: 0.8; }
.cell-qty {
  text-align: right !important;
  padding-right: 14px !important;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace !important;
  font-weight: 800 !important;
  font-size: 15px !important;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}
.cell-qty.qty-ok {
  color: var(--txt) !important;
}
.cell-qty.qty-low {
  color: #f87171 !important;
}
body.light-theme .cell-qty.qty-ok { color: var(--txt) !important; }
body.light-theme .cell-qty.qty-low { color: #dc2626 !important; }
.item-row td { vertical-align: middle; }


.field { background: var(--input); border: 1.5px solid var(--bdr); border-radius: 10px; padding: 10px 14px; color: var(--txt); width: 100%; outline: none; transition: 0.2s; font-size: 14px; height: 44px; }
.field:focus { border-color: var(--ac); }

.filter-chip { padding: 6px 12px; border-radius: 10px; font-size: 11px; background: var(--input); cursor: pointer; border: 1.5px solid var(--bdr); white-space: nowrap; transition: 0.2s; color: var(--txt2); font-weight: 600; margin-bottom: 4px; display: inline-flex; align-items: center; }
.filter-chip.active { background: var(--ac) !important; color: #000 !important; border-color: var(--ac) !important; }
body.light-theme .filter-chip.active { color: #fff !important; }
.filter-sub-chip.active { background: #8b5cf6 !important; color: #fff !important; border-color: #8b5cf6 !important; }

.filter-crit { background: rgba(239, 68, 68, 0.1); color: #ef4444; border: 1.5px solid rgba(239, 68, 68, 0.2); }
.filter-crit.active { background: #ef4444 !important; color: #fff !important; border-color: #ef4444 !important; }
.filter-reset { background: var(--modal-btn); color: var(--txt2); border-color: var(--bdr); }

.btn-excel { background: #10b98115; color: #10b981; border: 1.5px solid #10b98140; border-radius: 10px; padding: 0 12px; transition: 0.2s; display: flex; align-items: center; justify-content: center; gap: 6px; font-size: 10px; font-weight: 800; height: 44px; cursor: pointer; }

.nav-mobile { position: fixed; bottom: 0; left: 0; right: 0; background: var(--card); border-top: 1px solid var(--bdr); display: flex; padding: 8px 0 24px; z-index: 100; }
.nav-item { flex: 1; display: flex; flex-direction: column; align-items: center; font-size: 10px; color: var(--txt2); border: none; background: none; }
.nav-item.active { color: var(--ac); }

.modal-back { position: fixed; inset: 0; background: rgba(0,0,0,0.85); backdrop-filter: blur(10px); z-index: 2000; display: none; align-items: center; justify-content: center; padding: 16px; }
.modal-card { background: var(--modal-bg); border: 1px solid var(--bdr); border-radius: 28px; width: 100%; max-width: 400px; padding: 20px; color: var(--txt); box-shadow: 0 20px 40px rgba(0,0,0,0.3); }
#status-toast { position: fixed; bottom: 100px; left: 50%; transform: translateX(-50%); background: #18181b; color: #fff; padding: 12px 20px; border-radius: 12px; font-weight: 600; z-index: 9999; display: none; border: 1px solid #27272a; }

.action-menu-btn { display: flex; align-items: center; gap: 12px; padding: 12px; width: 100%; border-radius: 12px; border: 1px solid var(--bdr); background: var(--input); transition: 0.2s; margin-bottom: 8px; }
.action-footer-btn { flex: 1; display: flex; align-items: center; justify-content: center; gap: 8px; padding: 12px; border-radius: 14px; font-weight: 700; font-size: 12px; border: 1px solid var(--bdr); }

.search-container { position: relative; flex: 1; height: 44px; }
.field-search { padding-left: 40px; padding-right: 40px; height: 100%; }
.clear-btn { position: absolute; right: 10px; top: 50%; transform: translateY(-50%); color: var(--txt2); cursor: pointer; display: none; font-size: 18px; z-index: 10; }
.scan-btn { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--ac); cursor: pointer; font-size: 20px; z-index: 10; }

#reader { width: 100%; border-radius: 20px; overflow: hidden; background: #000; min-height: 250px; position: relative; }
#reader video { width: 100% !important; height: auto !important; object-fit: cover !important; border-radius: 20px; }

    
/* === FIX: mobile layout + solid dark theme (no white buttons) === */
.sidebar {
    display: none !important;
}
.nav-mobile {
    display: flex !important;
}
@media (min-width: 768px) {
    .sidebar {
        display: flex !important;
    }
    .nav-mobile {
        display: none !important;
    }
}

/* Nav buttons never white */
.nav-btn {
    background: transparent !important;
    color: var(--txt2) !important;
    border: none !important;
}
.nav-btn.active {
    background: rgba(16, 185, 129, 0.12) !important;
    color: var(--ac) !important;
}

/* Bottom mobile nav solid */
.nav-mobile {
    background: var(--card) !important;
    border-top: 1px solid var(--bdr) !important;
}
.nav-item {
    background: transparent !important;
    color: var(--txt2) !important;
}
.nav-item.active {
    color: var(--ac) !important;
}

/* Force dark inputs/buttons if theme vars fail */
button, .field, .filter-chip, .btn-excel {
    color: inherit;
}
body:not(.light-theme) {
    background: #09090b !important;
    color: #fafafa !important;
}
body:not(.light-theme) .sidebar,
body:not(.light-theme) .nav-mobile,
body:not(.light-theme) .tbl-wrap,
body:not(.light-theme) .modal-card {
    background: #141417 !important;
}

    
/* History group/subgroup colors */
.hist-cat { color: #34d399 !important; opacity: 0.8; font-weight: 700; }
.hist-sub { color: #a78bfa !important; opacity: 0.8; font-weight: 600; }
.cell-name span { max-width: 100%; }


/* History cards (стиль как в Pulse) */
.hist-card-list {
  background: var(--card);
  border: 1px solid var(--bdr);
  border-radius: 16px;
  overflow: hidden;
}
.hist-row {
  display: grid;
  grid-template-columns: 72px 1fr auto;
  gap: 10px;
  align-items: start;
  padding: 12px 14px;
  border-bottom: 1px solid var(--bdr);
  cursor: default;
}
.hist-row.multi { cursor: pointer; }
.hist-row:last-child { border-bottom: none; }
.hist-row .h-date {
  font-size: 10px;
  color: var(--txt2);
  font-variant-numeric: tabular-nums;
  line-height: 1.35;
}
.hist-row .h-date .ops-count {
  opacity: 0.6;
  display: block;
  margin-top: 2px;
}
.hist-row .h-type {
  font-size: 10px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 2px;
}
.hist-row .h-type.in { color: #34d399; }
.hist-row .h-type.out { color: #fb923c; }
.hist-row .h-type.add { color: #a78bfa; }
.hist-row .h-name {
  font-size: 13px;
  font-weight: 700;
  line-height: 1.3;
  overflow-wrap: break-word;
  word-break: break-word;
}
.hist-row .h-path {
  font-size: 9px;
  text-transform: uppercase;
  margin-top: 3px;
  line-height: 1.35;
}
.hist-row .h-path .c { color: #4ade80; opacity: 0.75; font-weight: 700; }
.hist-row .h-path .s { color: #a78bfa; opacity: 0.75; font-weight: 600; }
.hist-row .h-note {
  font-size: 10px;
  color: var(--txt2);
  font-style: italic;
  margin-top: 4px;
}
.hist-row .h-qty {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-weight: 800;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.hist-row .h-qty.in { color: #34d399; }
.hist-row .h-qty.out { color: #fb923c; }
.hist-detail-row {
  background: var(--hover);
  padding: 8px 14px 10px 82px;
  border-bottom: 1px solid var(--bdr);
  font-size: 11px;
  color: var(--txt2);
  display: flex;
  justify-content: space-between;
  gap: 8px;
}
.hist-empty {
  text-align: center;
  padding: 48px 16px;
  color: var(--txt2);
}
