:root {
  --bg: #eef2f7;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --text: #111827;
  --muted: #64748b;
  --line: #d7dee8;
  --line-strong: #b8c4d2;
  --brand: #155d9c;
  --brand-dark: #0f3558;
  --primary: #2563eb;
  --primary-600: #1d4ed8;
  --success: #15803d;
  --warn: #b45309;
  --danger: #b91c1c;
  --radius: 8px;
  --shadow: 0 10px 24px rgba(15, 23, 42, .08), 0 1px 2px rgba(15, 23, 42, .06);
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  --font: Inter, system-ui, -apple-system, Segoe UI, Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { min-height: 100%; }
body.tk {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  line-height: 1.45;
}

button, input, select, textarea { font: inherit; }
button { white-space: nowrap; }
button:disabled { opacity: .48; cursor: not-allowed; }

.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: #e8eef6;
}
.login-card {
  width: min(400px, 100%);
  display: grid;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 28px;
}
.login-brand {
  color: var(--primary);
  font-size: 30px;
  font-weight: 900;
  line-height: 1;
}
.login-brand span { color: var(--brand-dark); }
.login-title { font-size: 18px; font-weight: 850; margin-bottom: 6px; }
.login-error {
  border: 1px solid #fecaca;
  border-radius: 6px;
  background: #fef2f2;
  color: #991b1b;
  padding: 9px 10px;
  font-size: 13px;
  font-weight: 750;
}

.tk-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: #fff;
  border-bottom: 1px solid var(--line);
  box-shadow: 0 1px 5px rgba(15, 23, 42, .05);
}
.tk-header-inner {
  width: 100%;
  min-height: 64px;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 18px;
  padding: 10px 22px;
}
.tk-brand { text-decoration: none; flex: 0 0 auto; }
.brand-mark {
  display: inline-flex;
  align-items: baseline;
  min-width: 160px;
  color: var(--primary);
  font-size: 28px;
  font-weight: 900;
  line-height: 1;
}
.brand-mark span { color: var(--brand-dark); }
.tk-nav {
  display: flex;
  gap: 4px;
  align-items: center;
  justify-content: flex-start;
  min-width: 0;
}
.tk-nav-link {
  min-height: 40px;
  border: 0;
  border-bottom: 3px solid transparent;
  background: transparent;
  color: #475569;
  text-decoration: none;
  padding: 8px 12px 5px;
  font-weight: 800;
  cursor: pointer;
}
.tk-nav-link:hover { color: var(--text); background: #f1f5f9; }
.tk-nav-link.active { color: var(--brand-dark); border-bottom-color: var(--primary); }
.tk-session {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  min-width: 0;
}
.session-person {
  display: grid;
  gap: 1px;
  text-align: right;
  font-size: 12px;
  color: var(--muted);
}
.session-person span:first-child {
  max-width: 170px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text);
  font-weight: 850;
  font-size: 13px;
}

.tk-container {
  width: 100%;
  margin: 16px auto;
  padding: 0 18px 24px;
}
.page-wide { width: 100%; }
.app-view { display: none; }
.app-view.active { display: block; }

.operations-layout {
  display: grid;
  grid-template-columns: minmax(320px, 370px) minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}
.inventory-workspace { display: grid; gap: 12px; min-width: 0; }
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px;
}
.panel-title {
  font-weight: 850;
  font-size: 18px;
  line-height: 1.15;
  margin-bottom: 5px;
}
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}
.compact-head { align-items: flex-start; }
.muted { color: var(--muted); font-size: 13px; }
.mono { font-family: var(--mono); }
.w-full { width: 100%; }

.scanner-panel {
  position: sticky;
  top: 80px;
}
.inventory-summary {
  margin: 0;
}
.summary-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(130px, 1fr));
  gap: 10px;
}
.stat-card {
  min-height: 86px;
  display: grid;
  align-content: space-between;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
}
.stat-label { color: var(--muted); font-size: 12px; font-weight: 850; text-transform: uppercase; }
.stat-value { font-size: 30px; line-height: 1; font-weight: 900; }
.stat-note { color: #475569; font-size: 12px; }

.scan-form { display: grid; gap: 10px; }
.form-row.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.span-2 { grid-column: span 2; }
.label {
  display: block;
  margin: 0 0 5px;
  color: #334155;
  font-size: 12px;
  font-weight: 850;
}
.input, .select, .textarea {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  padding: 8px 10px;
  outline: none;
}
.input:focus, .select:focus, .textarea:focus {
  border-color: #7aa7f7;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, .13);
}
.scan-input { font-size: 21px; font-weight: 850; }
.textarea { resize: vertical; min-height: 40px; }

body:not(.scanner-only) .camera-box,
body:not(.scanner-only) .camera-actions {
  display: none;
}
.camera-box {
  position: relative;
  width: 100%;
  aspect-ratio: 4 / 3;
  display: grid;
  place-items: center;
  overflow: hidden;
  border: 1px solid #1f2937;
  border-radius: var(--radius);
  background: #0f172a;
  margin-bottom: 10px;
}
.camera-box::after {
  content: "";
  position: absolute;
  left: 12%;
  right: 12%;
  top: 44%;
  height: 2px;
  background: rgba(96, 165, 250, .9);
  pointer-events: none;
}
.camera-box video { width: 100%; height: 100%; object-fit: cover; }
.camera-empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 8px;
  padding: 22px;
  color: #f8fafc;
  text-align: center;
}
.camera-empty .muted { color: #cbd5e1; }
.camera-title { font-size: 20px; font-weight: 850; }
.camera-actions { display: grid; grid-template-columns: 1fr auto; gap: 10px; margin-bottom: 12px; }
.record-scan-btn { margin-top: 2px; }

.segmented {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  overflow: hidden;
  background: #fff;
}
.segment {
  min-width: 0;
  height: 38px;
  border: 0;
  border-right: 1px solid var(--line);
  background: #fff;
  color: #334155;
  font-size: 13px;
  font-weight: 850;
  cursor: pointer;
}
.segment:last-child { border-right: 0; }
.segment.active { background: #e8f0ff; color: var(--primary-600); }

.btn, .file-btn {
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: #fff;
  color: #1e293b;
  padding: 8px 12px;
  text-decoration: none;
  font-weight: 850;
  cursor: pointer;
}
.btn.sm { min-height: 30px; padding: 5px 9px; font-size: 12px; }
.btn:hover, .file-btn:hover { background: #f8fafc; border-color: #8fa2ba; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-600); }
.btn.primary-soft { background: #e8f0ff; border-color: #bfdbfe; color: var(--primary-600); }
.file-btn input { display: none; }
.toolbar { display: flex; align-items: center; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
.filters { display: grid; grid-template-columns: minmax(240px, 1fr) 170px 190px 180px; gap: 10px; margin-bottom: 12px; }

.table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
}
.table { width: 100%; min-width: 1320px; border-collapse: separate; border-spacing: 0; font-size: 13px; }
.table th, .table td { padding: 9px 10px; border-bottom: 1px solid #e6edf5; text-align: left; vertical-align: middle; }
.table th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #f1f5f9;
  color: #475569;
  font-size: 12px;
  text-transform: uppercase;
  white-space: nowrap;
}
.table tr:last-child td { border-bottom: 0; }
.table tr:hover td { background: #f8fbff; }
.table tr.selected td { background: #eff6ff; }
.select-col { width: 42px; text-align: center !important; }
.asset-link {
  border: 0;
  background: transparent;
  color: var(--primary-600);
  font-family: var(--mono);
  font-weight: 900;
  cursor: pointer;
  padding: 0;
}
.description-cell { max-width: 330px; min-width: 230px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.empty-cell { padding: 18px !important; color: var(--muted); text-align: center !important; }
.strong-cell { font-weight: 850; }
.actions-cell { display: flex; gap: 8px; flex-wrap: wrap; }
.status-pill, .role-pill, .user-status, .self-label {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 12px;
  font-weight: 850;
  border: 1px solid #cbd5e1;
  background: #f8fafc;
  color: #334155;
}
.status-available, .user-status.active { border-color: #bbf7d0; background: #ecfdf3; color: #15803d; }
.status-checked_out { border-color: #bfdbfe; background: #eff6ff; color: #1d4ed8; }
.status-maintenance { border-color: #fde68a; background: #fffbeb; color: #b45309; }
.status-retired, .user-status.inactive { border-color: #fecaca; background: #fef2f2; color: #b91c1c; }
.role-admin { border-color: #bae6fd; background: #eff8ff; color: #075985; }
.role-user { border-color: #d8b4fe; background: #faf5ff; color: #6b21a8; }
.self-label { min-height: 20px; margin-left: 6px; border-color: #d9e2ec; background: #f8fafc; color: #475569; }

.scan-result {
  margin-top: 12px;
  border: 1px solid #bfdbfe;
  border-radius: var(--radius);
  background: #eff6ff;
  padding: 10px;
}
.scan-result.error { border-color: #fecaca; background: #fef2f2; color: #991b1b; }
.scan-result-title { font-weight: 850; }

.admin-layout {
  display: grid;
  grid-template-columns: minmax(280px, 340px) minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}
.admin-create-panel { display: grid; gap: 10px; }
.admin-table { min-width: 920px; }

.label-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 12px;
}
.barcode-label {
  min-height: 150px;
  display: grid;
  gap: 6px;
  align-content: start;
  border: 1px solid #111827;
  border-radius: var(--radius);
  background: #fff;
  padding: 10px;
  page-break-inside: avoid;
}
.qr-label {
  min-height: 124px;
  grid-template-columns: 104px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
}
.qr-code-wrap { display: grid; place-items: center; }
.qr-svg { width: 104px; height: 104px; display: block; background: #fff; }
.label-content { min-width: 0; display: grid; gap: 4px; align-content: center; }
.label-org { font-size: 12px; font-weight: 900; color: var(--brand-dark); }
.label-desc { min-height: 34px; font-size: 12px; line-height: 1.25; overflow: hidden; }
.label-meta { display: flex; justify-content: space-between; gap: 8px; color: #475569; font-size: 11px; }
.label-code { font-family: var(--mono); font-size: 14px; font-weight: 900; text-align: center; }
.barcode-svg { width: 100%; height: 54px; display: block; background: #fff; }

.activity-list { display: grid; gap: 10px; }
.activity-list.compact .activity-row { grid-template-columns: 110px minmax(0, 1fr); }
.activity-list.compact .activity-time { display: none; }
.activity-row {
  display: grid;
  grid-template-columns: 130px 150px minmax(0, 1fr) 180px;
  gap: 10px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  padding: 10px;
}
.activity-action { font-weight: 900; color: var(--brand-dark); }
.activity-main { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.activity-time { color: var(--muted); font-size: 12px; text-align: right; }

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 22px;
  background: rgba(15, 23, 42, .42);
}
.modal {
  width: min(920px, 100%);
  max-height: calc(100vh - 44px);
  overflow: auto;
  border: 1px solid #d7e3f1;
  border-radius: var(--radius);
  background: #fff;
  box-shadow: 0 24px 80px rgba(15, 23, 42, .22);
  padding: 18px;
}
.small-modal { width: min(420px, 100%); }
.modal-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 14px; }
.modal-title { font-size: 20px; font-weight: 850; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 16px; }
.icon-btn {
  width: 34px;
  height: 34px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: #fff;
  color: #334155;
  font-weight: 900;
  cursor: pointer;
}
.toast {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 200;
  background: #059669;
  color: #fff;
  padding: 10px 14px;
  border-radius: 6px;
  box-shadow: 0 8px 24px rgba(2, 6, 23, .25);
  font-weight: 850;
}
.toast.error { background: var(--danger); }

body.scanner-only .tk-nav,
body.scanner-only .inventory-workspace {
  display: none !important;
}
body.scanner-only .tk-container {
  max-width: 620px;
  margin-top: 14px;
}
body.scanner-only .operations-layout {
  display: block;
}
body.scanner-only .scanner-mobile-link { display: none; }
body.scanner-only .scanner-panel { position: static; }
body.scanner-only .camera-box {
  display: grid;
  aspect-ratio: 3 / 4;
}
body.scanner-only .camera-actions { display: grid; }

@media (max-width: 1180px) {
  .operations-layout, .admin-layout { grid-template-columns: 1fr; }
  .scanner-panel { position: static; }
  .summary-grid { grid-template-columns: repeat(2, minmax(150px, 1fr)); }
  .filters { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 760px) {
  .tk-header-inner { grid-template-columns: 1fr; align-items: start; padding: 10px 14px; gap: 10px; }
  .brand-mark { min-width: 140px; font-size: 25px; }
  .tk-nav { width: 100%; overflow-x: auto; }
  .tk-nav-link { padding: 8px 9px 5px; }
  .tk-session { width: 100%; justify-content: space-between; }
  .session-person { text-align: left; }
  .tk-container { padding: 0 12px 20px; margin-top: 12px; }
  .summary-grid, .filters, .form-grid, .form-row.two { grid-template-columns: 1fr; }
  .span-2 { grid-column: span 1; }
  .panel-head { align-items: stretch; flex-direction: column; }
  .toolbar { justify-content: flex-start; }
  .segmented { grid-template-columns: repeat(3, 1fr); }
  .activity-row, .activity-list.compact .activity-row { grid-template-columns: 1fr; }
  .activity-time { text-align: left; }
  .mobile-scanner-panel { padding: 14px; }
  body:not(.scanner-only) .camera-box,
  body:not(.scanner-only) .camera-actions {
    display: grid;
  }
  .camera-box { aspect-ratio: 3 / 4; }
  .camera-actions { grid-template-columns: 1fr 1fr; }
  .scan-input { font-size: 20px; }
  .login-card { padding: 22px; }
}

@media print {
  body.tk { background: #fff; }
  .login-screen, .tk-header, .tk-container > .app-view:not(#labelsView), .print-head, .toast, .modal-backdrop { display: none !important; }
  .tk-container { margin: 0; padding: 0; }
  #labelsView { display: block !important; }
  .labels-panel { border: 0; box-shadow: none; padding: 0; }
  @page { size: 3.5in 1.125in; margin: 0; }
  .label-grid { display: block; }
  .barcode-label { width: 3.5in; height: 1.125in; min-height: 0; border: 0; border-radius: 0; padding: .08in; box-sizing: border-box; break-after: page; page-break-after: always; }
  .qr-label { grid-template-columns: .88in minmax(0, 1fr); gap: .08in; }
  .qr-svg { width: .86in; height: .86in; }
  .label-org { font-size: 7.5pt; }
  .label-code { font-size: 13pt; text-align: left; line-height: 1; }
  .label-desc { min-height: 0; max-height: .28in; font-size: 7pt; line-height: 1.08; }
  .label-meta { font-size: 6.5pt; line-height: 1; }
}