/* ─── Reset & base ──────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --blue:        #1a56db;
  --blue-dark:   #1245b0;
  --blue-light:  #e8f0fe;
  --green:       #057a55;
  --red:         #c81e1e;
  --amber:       #c27803;
  --bg:          #0f172a;
  --surface:     #1e293b;
  --surface2:    #273449;
  --text:        #f1f5f9;
  --text-muted:  #94a3b8;
  --border:      #334155;
  --header-h:    52px;
  --breadcrumb-h:52px;
  --actions-h:   96px;
  --radius:      12px;
}

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

/* ─── Screen system ─────────────────────────────────────────────────────── */
.screen {
  display: none;
  flex-direction: column;
  height: 100dvh;
  width: 100%;
  position: absolute;
  inset: 0;
}
.screen.active { display: flex; }

/* ─── Login ─────────────────────────────────────────────────────────────── */
#screen-login {
  align-items: center;
  justify-content: center;
  background: var(--bg);
}
.login-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 2rem;
  width: min(400px, 92vw);
  display: flex;
  flex-direction: column;
  gap: 0.875rem;
}
.logo      { font-size: 2rem; font-weight: 800; color: var(--blue); letter-spacing: -1px; }
.tagline   { color: var(--text-muted); font-size: 0.875rem; margin-bottom: 0.25rem; }
label      { font-size: 0.8125rem; font-weight: 500; color: var(--text-muted); }
input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
textarea {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.75rem 1rem;
  color: var(--text);
  font-size: 1rem;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s;
  resize: none;
}
input:focus, textarea:focus { border-color: var(--blue); }

/* ─── Buttons ───────────────────────────────────────────────────────────── */
.btn-primary {
  background: var(--blue);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 0.875rem;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  width: 100%;
  transition: background 0.15s;
}
.btn-primary:hover:not(:disabled) { background: var(--blue-dark); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.75rem;
  font-size: 0.9375rem;
  cursor: pointer;
  width: 100%;
}

.btn-icon {
  background: transparent;
  border: none;
  color: var(--text);
  font-size: 0.9375rem;
  cursor: pointer;
  padding: 0.5rem 0.75rem;
}

.error   { color: #fca5a5; font-size: 0.875rem; }
.hidden  { display: none !important; }
.optional { color: var(--text-muted); font-size: 0.75em; font-weight: 400; }

/* ─── App Header ────────────────────────────────────────────────────────── */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--header-h);
  padding: 0 0.875rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  position: relative;
  z-index: 30;
}

.user-chip {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
}

.avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--blue);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.875rem;
  font-weight: 700;
  flex-shrink: 0;
}

#user-name {
  font-size: 0.9375rem;
  font-weight: 600;
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.menu-btn {
  background: transparent;
  border: none;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 5px;
  padding: 0.5rem;
}
.menu-btn span {
  display: block;
  width: 20px;
  height: 2px;
  background: var(--text);
  border-radius: 1px;
}

.app-menu {
  position: absolute;
  top: var(--header-h);
  right: 0.5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  z-index: 50;
  min-width: 150px;
  overflow: hidden;
}
.app-menu button {
  display: block;
  width: 100%;
  background: transparent;
  border: none;
  color: var(--text);
  padding: 0.875rem 1rem;
  text-align: left;
  font-size: 0.9375rem;
  cursor: pointer;
}
.app-menu button:hover { background: var(--surface2); }

/* ─── Breadcrumb ─────────────────────────────────────────────────────────── */
.breadcrumb-section {
  height: var(--breadcrumb-h);
  background: var(--surface2);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.breadcrumb-scroll {
  height: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.breadcrumb-scroll::-webkit-scrollbar { display: none; }

.breadcrumb-inner {
  display: flex;
  align-items: center;
  height: 100%;
  padding: 0 0.75rem;
  gap: 0;
  white-space: nowrap;
  min-width: max-content;
}

.breadcrumb-empty {
  color: var(--text-muted);
  font-size: 0.875rem;
  padding: 0 0.25rem;
  font-style: italic;
}
.breadcrumb-pick-btn {
  background: transparent;
  border: 1px dashed var(--border);
  border-radius: 20px;
  cursor: pointer;
  padding: 0.3125rem 0.875rem;
}

.crumb {
  display: inline-flex;
  align-items: center;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 0.3125rem 0.75rem;
  font-size: 0.875rem;
  color: var(--text-muted);
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, color 0.15s;
}
.crumb:hover { background: var(--surface); color: var(--text); }
.crumb.active {
  background: var(--blue);
  border-color: var(--blue);
  color: #fff;
  font-weight: 600;
}

.crumb-sep {
  color: var(--text-muted);
  padding: 0 0.25rem;
  font-size: 1rem;
  user-select: none;
}

/* ─── Action Buttons ─────────────────────────────────────────────────────── */
.action-buttons {
  flex-shrink: 0;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0.5rem 0.625rem;
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
}

.action-row-top {
  display: flex;
  gap: 0.375rem;
}

.action-btn {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex: 1;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.625rem 0.75rem;
  color: var(--text);
  font-size: 0.8125rem;
  font-weight: 500;
  line-height: 1.3;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
  text-align: left;
}
.action-btn:hover { background: var(--surface); border-color: var(--blue); }
.action-btn.active {
  background: rgba(26, 86, 219, 0.15);
  border-color: var(--blue);
  color: #93bbff;
}
.action-btn.full { flex: 1; }

.action-icon {
  font-size: 1.25rem;
  flex-shrink: 0;
}

/* ─── Camera Section ─────────────────────────────────────────────────────── */
.camera-section {
  flex: 1;
  display: flex;
  overflow: hidden;
  min-height: 0;
}

.camera-view-wrap {
  flex: 1;
  position: relative;
  overflow: hidden;
  background: #000;
}

#camera-feed {
  width: 100% !important;
  height: 100% !important;
}

/* Suppress html5-qrcode chrome */
#camera-feed > * > img,
#camera-feed button,
#camera-feed select { display: none !important; }
#camera-feed video  { object-fit: cover !important; width: 100% !important; height: 100% !important; }
#camera-feed__scan_region { background: transparent !important; border: none !important; }

/* QR targeting frame */
.scan-frame {
  position: absolute;
  inset: 0;
  pointer-events: none;
  display: flex;
  align-items: center;
  justify-content: center;
}
.scan-corner {
  position: absolute;
  width: 22px; height: 22px;
  border-color: rgba(255,255,255,0.9);
  border-style: solid;
}
.tl { top: calc(50% - 90px); left:  calc(50% - 90px); border-width: 3px 0 0 3px; border-radius: 4px 0 0 0; }
.tr { top: calc(50% - 90px); right: calc(50% - 90px); border-width: 3px 3px 0 0; border-radius: 0 4px 0 0; }
.bl { bottom: calc(50% - 90px); left:  calc(50% - 90px); border-width: 0 0 3px 3px; border-radius: 0 0 0 4px; }
.br { bottom: calc(50% - 90px); right: calc(50% - 90px); border-width: 0 3px 3px 0; border-radius: 0 0 4px 0; }

.scan-mode-label {
  position: absolute;
  bottom: calc(50% - 110px);
  background: rgba(0,0,0,0.65);
  color: #fff;
  font-size: 0.8125rem;
  padding: 0.25rem 0.75rem;
  border-radius: 99px;
}

/* Camera controls panel */
.camera-controls {
  width: 80px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #000;
  flex-shrink: 0;
}

.take-photo-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.375rem;
  background: transparent;
  border: none;
  color: rgba(255,255,255,0.5);
  cursor: pointer;
  font-size: 0.6875rem;
  transition: color 0.15s;
}
.take-photo-btn:not(:disabled) { color: #fff; }

.shutter-outer {
  width: 44px; height: 44px;
  border-radius: 50%;
  border: 3px solid currentColor;
  display: flex;
  align-items: center;
  justify-content: center;
}
.shutter-inner {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: currentColor;
  transition: transform 0.1s;
}
.take-photo-btn:not(:disabled):active .shutter-inner { transform: scale(0.85); }

/* ─── Photo Strip ────────────────────────────────────────────────────────── */
.photo-strip {
  flex-shrink: 0;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 0.5rem 0.625rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.photo-strip-inner {
  display: flex;
  gap: 0.375rem;
  overflow-x: auto;
  flex: 1;
  scrollbar-width: none;
}
.photo-strip-inner::-webkit-scrollbar { display: none; }

.photo-thumb {
  width: 48px;
  height: 48px;
  border-radius: 6px;
  object-fit: cover;
  flex-shrink: 0;
  border: 2px solid var(--border);
}

.photo-strip-next {
  background: var(--blue);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 0.5rem 0.875rem;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
}

/* ─── Toast ─────────────────────────────────────────────────────────────── */
.toast {
  position: absolute;
  bottom: 0.75rem;
  left: 0.75rem;
  right: 0.75rem;
  background: rgba(15, 23, 42, 0.92);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.75rem 1rem;
  border-radius: 10px;
  font-size: 0.9375rem;
  z-index: 60;
  backdrop-filter: blur(4px);
  text-align: center;
}
.toast.success { border-color: var(--green); }
.toast.error   { border-color: var(--red); }

/* ─── Asset Details Screen ───────────────────────────────────────────────── */
#screen-details {
  background: var(--bg);
  overflow-y: auto;
}

.detail-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem 0.5rem 0.75rem 0.25rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 5;
  flex-shrink: 0;
}
.detail-header h2 { font-size: 1rem; font-weight: 700; }

.detail-form {
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding-bottom: 2rem;
}

.captured-photos-preview {
  display: flex;
  gap: 0.5rem;
  overflow-x: auto;
  padding-bottom: 0.25rem;
  scrollbar-width: none;
}
.captured-photos-preview::-webkit-scrollbar { display: none; }
.captured-photos-preview:empty { display: none; }
.captured-photos-preview img {
  width: 80px;
  height: 80px;
  border-radius: 8px;
  object-fit: cover;
  border: 2px solid var(--border);
  flex-shrink: 0;
}

.qty-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}
.qty-row label  { white-space: nowrap; }
.qty-row input  { width: 90px; flex-shrink: 0; }
.qty-hint { color: var(--text-muted); font-size: 0.8125rem; }

.location-confirm {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.625rem 0.875rem;
  font-size: 0.875rem;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}
.location-confirm-label { color: var(--text-muted); font-size: 0.75rem; }
.location-confirm-path  { color: var(--text); font-weight: 500; }

/* ─── Location Picker Bottom Sheet ──────────────────────────────────────── */
.picker-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 70;
  display: flex;
  align-items: flex-end;
}

.picker-sheet {
  background: var(--surface);
  border-radius: var(--radius) var(--radius) 0 0;
  width: 100%;
  max-height: 70dvh;
  display: flex;
  flex-direction: column;
  padding: 0 1rem 1.5rem;
  overflow: hidden;
}

.picker-handle {
  width: 40px; height: 4px;
  background: var(--border);
  border-radius: 2px;
  margin: 0.75rem auto 0;
  flex-shrink: 0;
}

.picker-title {
  font-size: 1rem;
  font-weight: 700;
  padding: 0.75rem 0 0.5rem;
  flex-shrink: 0;
  color: var(--text-muted);
}

.picker-list {
  overflow-y: auto;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.picker-item {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.75rem 1rem;
  color: var(--text);
  font-size: 0.9375rem;
  cursor: pointer;
  text-align: left;
  width: 100%;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.picker-item:hover { background: var(--surface); border-color: var(--blue); }
.picker-item-icon { color: var(--text-muted); }

.picker-loading { color: var(--text-muted); text-align: center; padding: 1rem; font-size: 0.875rem; }
.picker-empty   { color: var(--text-muted); text-align: center; padding: 1rem; font-size: 0.875rem; }

.picker-cancel {
  margin-top: 0.5rem;
  flex-shrink: 0;
}

/* ─── View Assets button ─────────────────────────────────────────────────── */
.action-btn-view {
  background: rgba(26, 86, 219, 0.08);
  border-color: rgba(26, 86, 219, 0.4);
  color: #93bbff;
}
.action-btn-view:hover {
  background: rgba(26, 86, 219, 0.18);
  border-color: var(--blue);
}

/* ─── Asset List Screen ──────────────────────────────────────────────────── */
#screen-list { background: var(--bg); }

.list-subtree-toggle {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  color: var(--text-muted);
  font-size: 0.8125rem;
  cursor: pointer;
  white-space: nowrap;
  padding-right: 0.25rem;
  flex-shrink: 0;
}
.list-subtree-toggle input { accent-color: var(--blue); cursor: pointer; }

.list-container {
  flex: 1;
  overflow-y: auto;
  padding: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.list-empty {
  color: var(--text-muted);
  text-align: center;
  padding: 3rem 1rem;
  font-size: 0.9375rem;
  line-height: 1.6;
}

.asset-card {
  display: flex;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.asset-thumb {
  width: 72px;
  height: 72px;
  object-fit: cover;
  flex-shrink: 0;
}

.asset-thumb-placeholder {
  width: 72px;
  height: 72px;
  background: var(--surface2);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 1.5rem;
}

.asset-card-body {
  flex: 1;
  padding: 0.625rem 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  min-width: 0;
}

.asset-card-name {
  font-weight: 600;
  font-size: 0.9375rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.asset-card-meta {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.asset-qty-badge {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 99px;
  padding: 0.1rem 0.45rem;
  font-weight: 600;
  font-size: 0.7rem;
  color: var(--text);
}

.asset-card-desc {
  font-size: 0.8125rem;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ─── Location Tree (accordion) ─────────────────────────────────────── */
.location-tree-sheet { max-height: 80dvh; }

.tree-node-row {
  display: flex;
  align-items: stretch;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 0.25rem;
  overflow: hidden;
}
.tree-node-row:hover { border-color: var(--blue); }

.tree-toggle {
  background: transparent;
  border: none;
  border-right: 1px solid var(--border);
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.7rem;
  padding: 0 0.75rem;
  flex-shrink: 0;
  transition: color 0.15s, background 0.15s;
}
.tree-toggle:hover { color: var(--text); background: rgba(255,255,255,0.05); }

.tree-toggle-spacer {
  width: 36px;
  flex-shrink: 0;
}

.tree-node-name {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text);
  cursor: pointer;
  font-size: 0.9375rem;
  padding: 0.75rem 0.875rem;
  text-align: left;
  transition: color 0.15s;
}
.tree-node-name:hover { color: #93bbff; }

.tree-children {
  display: none;
  padding-left: 1rem;
  padding-top: 0.125rem;
}
.tree-children.open { display: block; }
