:root {
  --bg: #0b1120;
  --bg-soft: #111a2e;
  --bg-card: #151f36;
  --border: #22304d;
  --text: #e6edf9;
  --text-dim: #93a2bd;
  --accent: #3b82f6;
  --accent-2: #22d3ee;
  --ok: #22c55e;
  --warn: #f59e0b;
  --danger: #ef4444;
  --radius: 16px;
  --radius-sm: 10px;
  --tabbar-h: 62px;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

body {
  overflow: hidden;
}

.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  max-width: 720px;
  margin: 0 auto;
  position: relative;
}

/* ------------------------------- Topbar ------------------------------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: rgba(11, 17, 32, 0.92);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid rgba(34, 48, 77, 0.6);
  flex: 0 0 auto;
  z-index: 5;
}

.topbar__brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  letter-spacing: 0.2px;
}

.topbar__logo {
  border-radius: 7px;
  display: block;
}

.topbar__status {
  display: flex;
  align-items: center;
  gap: 6px;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  line-height: 1.4;
  border: 1px solid transparent;
  white-space: nowrap;
}

.pill--online {
  background: rgba(34, 197, 94, 0.14);
  color: #7ee2a8;
  border-color: rgba(34, 197, 94, 0.35);
}

.pill--offline {
  background: rgba(245, 158, 11, 0.14);
  color: #fbd38d;
  border-color: rgba(245, 158, 11, 0.35);
}

.pill--queue {
  background: rgba(59, 130, 246, 0.14);
  color: #93c5fd;
  border-color: rgba(59, 130, 246, 0.35);
}

.pill--queue.has-items {
  background: rgba(59, 130, 246, 0.28);
  color: #dbeafe;
}

/* -------------------------------- Main -------------------------------- */
.main {
  flex: 1 1 auto;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 14px 16px calc(var(--tabbar-h) + 26px + env(safe-area-inset-bottom));
}

.view h2 {
  font-size: 20px;
  margin: 2px 0 14px;
}

.view h3 {
  font-size: 15px;
  margin: 0 0 8px;
}

.hint {
  color: var(--text-dim);
  font-size: 12.5px;
  line-height: 1.5;
  margin: 10px 2px 0;
}

.empty {
  color: var(--text-dim);
  text-align: center;
  padding: 36px 12px;
  font-size: 14px;
}

/* ------------------------------- Camera ------------------------------- */
.camera {
  position: relative;
  width: 100%;
  aspect-ratio: 3 / 4;
  max-height: 62vh;
  background: #05080f;
  border: 1px solid var(--border);
  border-radius: 22px;
  overflow: hidden;
}

.camera__video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  background: #05080f;
}

.camera__watermark {
  position: absolute;
  top: 12px;
  right: 12px;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
  padding: 8px 12px;
  border-radius: 10px;
  background: rgba(8, 15, 30, 0.62);
  border: 1px solid rgba(255, 255, 255, 0.18);
  backdrop-filter: blur(4px);
  pointer-events: none;
  max-width: calc(100% - 24px);
}

.camera__watermark-date {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.2px;
}

.camera__watermark-fio {
  font-size: 11.5px;
  color: #dbe5f5;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.camera__empty {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 24px;
  text-align: center;
  background: radial-gradient(circle at 50% 40%, #14203a 0%, #05080f 70%);
  color: var(--text-dim);
}

.camera__empty[hidden] {
  display: none;
}

.camera__empty p {
  margin: 0;
  font-size: 14px;
  line-height: 1.5;
  max-width: 280px;
}

.camera__flash {
  position: absolute;
  inset: 0;
  background: #fff;
  opacity: 0;
  pointer-events: none;
}

.camera__flash.is-active {
  animation: flash 320ms ease-out;
}

@keyframes flash {
  0% {
    opacity: 0.85;
  }
  100% {
    opacity: 0;
  }
}

.shutter-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 16px 8px 4px;
}

.icon-btn {
  width: 54px;
  height: 54px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  color: var(--text);
  background: var(--bg-card);
  border: 1px solid var(--border);
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.icon-btn:active {
  transform: scale(0.96);
}

.icon-btn--file {
  cursor: pointer;
}

.shutter {
  width: 76px;
  height: 76px;
  border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.85);
  background: transparent;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

.shutter:active .shutter__inner {
  transform: scale(0.9);
}

.shutter__inner {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: #fff;
  transition: transform 120ms ease;
}

/* -------------------------------- Queue -------------------------------- */
.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.section-head h2 {
  margin: 0;
}

.section-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.segmented {
  display: flex;
  gap: 4px;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 4px;
  margin-bottom: 10px;
}

.segmented__btn {
  flex: 1 1 0;
  border: 0;
  background: transparent;
  color: var(--text-dim);
  font-size: 12px;
  font-weight: 600;
  padding: 8px 6px;
  border-radius: 9px;
  cursor: pointer;
  white-space: nowrap;
}

.segmented__btn span {
  display: inline-block;
  margin-left: 2px;
  opacity: 0.8;
}

.segmented__btn.is-active {
  background: var(--bg-card);
  color: var(--text);
  box-shadow: inset 0 0 0 1px var(--border);
}

.queue-status {
  margin: 0 2px 10px;
  font-size: 12.5px;
  color: var(--text-dim);
}

.photo-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.photo-item {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  padding: 10px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.photo-item__thumb {
  width: 76px;
  height: 76px;
  border-radius: 8px;
  object-fit: cover;
  background: #05080f;
  flex: 0 0 auto;
}

.photo-item__body {
  flex: 1 1 auto;
  min-width: 0;
}

.photo-item__name {
  font-size: 12.5px;
  font-weight: 600;
  word-break: break-all;
}

.photo-item__meta {
  font-size: 11.5px;
  color: var(--text-dim);
  margin-top: 3px;
  line-height: 1.45;
}

.photo-item__error {
  font-size: 11.5px;
  color: #fca5a5;
  margin-top: 3px;
}

.photo-item__actions {
  display: flex;
  gap: 6px;
  margin-top: 8px;
  flex-wrap: wrap;
}

.badge {
  display: inline-block;
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  padding: 2px 7px;
  border-radius: 999px;
}

.badge--pending {
  background: rgba(59, 130, 246, 0.2);
  color: #93c5fd;
}

.badge--uploaded {
  background: rgba(34, 197, 94, 0.18);
  color: #86efac;
}

.badge--error {
  background: rgba(239, 68, 68, 0.2);
  color: #fca5a5;
}

/* ------------------------------- Settings ------------------------------ */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 12px;
}

.card__text {
  margin: 0 0 10px;
  font-size: 13px;
  color: var(--text-dim);
  line-height: 1.5;
}

.card__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.field {
  display: block;
  margin-bottom: 14px;
}

.field:last-child {
  margin-bottom: 0;
}

.field__label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 6px;
}

.field input {
  width: 100%;
  padding: 12px;
  font-size: 15px;
  color: var(--text);
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  outline: none;
  font-family: inherit;
}

.field input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.18);
}

.field__hint {
  display: block;
  margin-top: 6px;
  font-size: 11.5px;
  color: var(--text-dim);
  line-height: 1.45;
}

.lock {
  font-size: 11px;
  opacity: 0.8;
}

/* -------------------------------- Buttons ------------------------------ */
.btn {
  appearance: none;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 11px 16px;
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  background: var(--bg-soft);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
  transition: filter 120ms ease, transform 80ms ease;
}

.btn:active {
  transform: scale(0.985);
}

.btn:disabled {
  opacity: 0.5;
  pointer-events: none;
}

.btn--sm {
  padding: 8px 12px;
  font-size: 12.5px;
}

.btn--primary {
  background: linear-gradient(135deg, var(--accent), #2563eb);
  color: #fff;
}

.btn--ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--text);
}

.btn--danger {
  background: rgba(239, 68, 68, 0.12);
  border-color: rgba(239, 68, 68, 0.4);
  color: #fca5a5;
}

.btn:hover {
  filter: brightness(1.08);
}

/* -------------------------------- Tabbar ------------------------------- */
.tabbar {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: rgba(11, 17, 32, 0.96);
  backdrop-filter: blur(14px);
  border-top: 1px solid rgba(34, 48, 77, 0.7);
  z-index: 10;
}

.tabbar__btn {
  flex: 1 1 0;
  border: 0;
  background: transparent;
  color: var(--text-dim);
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  cursor: pointer;
  position: relative;
}

.tabbar__btn.is-active {
  color: var(--text);
}

.tabbar__btn.is-active::after {
  content: '';
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 28px;
  height: 3px;
  border-radius: 0 0 3px 3px;
  background: var(--accent);
}

.tabbar__badge {
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  background: var(--accent);
  color: #fff;
  font-size: 11px;
  line-height: 18px;
  text-align: center;
}

/* -------------------------------- Toast -------------------------------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--tabbar-h) + 22px + env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(8px);
  max-width: min(92vw, 520px);
  padding: 11px 16px;
  background: rgba(21, 31, 54, 0.97);
  border: 1px solid var(--border);
  border-radius: 12px;
  font-size: 13px;
  line-height: 1.4;
  box-shadow: 0 12px 34px rgba(0, 0, 0, 0.45);
  z-index: 50;
  opacity: 0;
  transition: opacity 180ms ease, transform 180ms ease;
  text-align: center;
}

.toast.is-visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.toast[hidden] {
  display: none;
}

.toast--error {
  border-color: rgba(239, 68, 68, 0.5);
  color: #fecaca;
}

/* -------------------------------- Busy -------------------------------- */
.busy {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: rgba(5, 8, 15, 0.62);
  backdrop-filter: blur(2px);
  z-index: 60;
  font-size: 13px;
  color: var(--text);
}

.busy[hidden] {
  display: none;
}

.spinner {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.18);
  border-top-color: var(--accent-2);
  animation: spin 0.8s linear infinite;
}

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

@media (min-width: 560px) {
  .main {
    padding-left: 22px;
    padding-right: 22px;
  }

  .camera {
    max-height: 56vh;
    aspect-ratio: 4 / 3;
  }
}
