:root {
  --bg: #0b1220;
  --panel: #131d31;
  --panel-2: #1a2740;
  --line: #26344f;
  --text: #e6edf7;
  --muted: #8aa0bf;
  --brand: #38bdf8;
  --ok: #10b981;
  --warn: #f59e0b;
  --err: #ef4444;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
}

.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  padding-top: calc(12px + env(safe-area-inset-top));
  background: #0e1729;
  border-bottom: 1px solid var(--line);
  flex: 0 0 auto;
}

.brand { font-weight: 700; letter-spacing: .3px; }
.brand .dot { color: var(--brand); }

.top-actions { display: flex; align-items: center; gap: 10px; }
.context { color: var(--muted); font-size: 12px; max-width: 45vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

main { flex: 1 1 auto; min-height: 0; display: flex; }
.view { flex: 1 1 auto; min-height: 0; overflow-y: auto; padding: 18px 16px; }
.capture { display: flex; flex-direction: column; padding: 0; overflow: hidden; }
.hidden { display: none !important; }
.grow { flex: 1 1 auto; min-width: 0; }

h1 { font-size: 22px; margin: 0 0 6px; }
h2 { font-size: 17px; margin: 0; }
.muted { color: var(--muted); font-size: 13px; margin: 4px 0; }
.error { color: var(--err); font-size: 13px; margin: 8px 0 0; }

.login-card {
  max-width: 380px;
  margin: 8vh auto 0;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 22px;
}

label { display: block; margin-top: 14px; font-size: 13px; color: var(--muted); }
input[type="text"], input[type="password"], input:not([type]) {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  font-size: 16px;
}

input:focus { outline: 2px solid var(--brand); outline-offset: 1px; }

.turnstile { margin-top: 16px; min-height: 65px; }

.primary-btn, .next-btn {
  border: 0;
  border-radius: 10px;
  background: var(--brand);
  color: #04202d;
  font-weight: 700;
  font-size: 15px;
  padding: 12px 18px;
  cursor: pointer;
}
.primary-btn { width: 100%; margin-top: 18px; }
.primary-btn:disabled { opacity: .55; }
.next-btn { min-width: 118px; }

.ghost-btn {
  border: 1px solid var(--line);
  background: transparent;
  color: var(--text);
  border-radius: 9px;
  padding: 8px 12px;
  font-size: 13px;
  cursor: pointer;
}
.ghost-btn:disabled, .next-btn:disabled { opacity: .45; cursor: not-allowed; }

.head-actions { display: flex; align-items: center; gap: 8px; }
.head-actions .primary-btn { width: auto; margin-top: 0; }

.section-head { display: flex; align-items: flex-end; gap: 12px; margin-bottom: 12px; }

.search {
  width: 100%;
  padding: 11px 14px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  font-size: 15px;
  margin-bottom: 12px;
}

.list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }

.list li {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
}
.list li:active { background: var(--panel-2); }
.list li.disabled { opacity: .5; cursor: not-allowed; }

.list .title { font-weight: 600; font-size: 15px; }
.list .sub { color: var(--muted); font-size: 12px; margin-top: 2px; }
.list .fill { flex: 1 1 auto; min-width: 0; }
.list .ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.pill {
  font-size: 12px;
  border-radius: 999px;
  padding: 4px 10px;
  background: var(--panel-2);
  color: var(--muted);
  white-space: nowrap;
}
.pill.ok { background: rgba(16, 185, 129, .16); color: var(--ok); }
.pill.pending { background: rgba(245, 158, 11, .16); color: var(--warn); }
.pill.off { background: rgba(239, 68, 68, .14); color: var(--err); }

.progress-track { height: 8px; border-radius: 999px; background: var(--panel-2); overflow: hidden; margin-bottom: 16px; }
.progress-bar { height: 100%; width: 0; background: var(--ok); transition: width .25s ease; }

.products li { padding: 14px; }

.capture-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  background: #0e1729;
  flex: 0 0 auto;
}
.capture-product { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; }
.capture-product strong { font-size: 14px; }
.capture-product span { color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.camera-container {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  background: #000;
  overflow: hidden;
}
#viewfinder { width: 100%; height: 100%; object-fit: cover; display: block; }

.camera-notice {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 24px;
  text-align: center;
  color: var(--muted);
  font-size: 14px;
}

.thumbnails-strip {
  display: flex;
  gap: 8px;
  padding: 10px 12px;
  overflow-x: auto;
  background: #0e1729;
  border-top: 1px solid var(--line);
  min-height: 76px;
  flex: 0 0 auto;
}
.thumb {
  position: relative;
  flex: 0 0 auto;
  width: 58px;
  height: 58px;
  border-radius: 9px;
  overflow: hidden;
  border: 1px solid var(--line);
  background: var(--panel-2);
}
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb .badge {
  position: absolute;
  right: 3px;
  bottom: 3px;
  width: 18px;
  height: 18px;
  border-radius: 999px;
  background: var(--ok);
  color: #04241a;
  font-size: 11px;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
}
.thumb.existing { display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: 11px; }
.thumb.failed { border-color: var(--err); cursor: pointer; }
.thumb .badge.error { background: var(--err); color: #fff; }

.bottom-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 12px 18px;
  padding-bottom: calc(12px + env(safe-area-inset-bottom));
  background: #0e1729;
  border-top: 1px solid var(--line);
  flex: 0 0 auto;
}

.control-btn {
  width: 48px;
  height: 48px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  font-size: 18px;
}

.shutter-btn {
  width: 74px;
  height: 74px;
  border-radius: 999px;
  border: 4px solid rgba(255, 255, 255, .8);
  background: transparent;
  padding: 5px;
  cursor: pointer;
}
.shutter-btn span { display: block; width: 100%; height: 100%; border-radius: 999px; background: #fff; }
.shutter-btn:disabled { opacity: .5; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 108px;
  transform: translateX(-50%);
  max-width: 88vw;
  padding: 10px 16px;
  border-radius: 10px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  font-size: 13px;
  z-index: 20;
}
.toast.ok { border-color: var(--ok); color: var(--ok); }
.toast.error { border-color: var(--err); color: var(--err); }
