:root {
  --bg: #0b1120;
  --surface: #111827;
  --surface-elevated: #1e293b;
  --border: #334155;
  --text: #f8fafc;
  --text-muted: #94a3b8;
  --primary: #38bdf8;
  --primary-strong: #0284c7;
  --success: #22c55e;
  --success-bg: rgba(34, 197, 94, 0.14);
  --warning: #f59e0b;
  --warning-bg: rgba(245, 158, 11, 0.14);
  --danger: #ef4444;
  --danger-bg: rgba(239, 68, 68, 0.14);
  --radius: 14px;
  --radius-sm: 10px;
  --nav-height: 68px;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  min-height: 100%;
}

.app-shell {
  max-width: 720px;
  margin: 0 auto;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  background: rgba(15, 23, 42, 0.94);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--primary);
  box-shadow: 0 0 12px rgba(56, 189, 248, 0.65);
}

.app-header h1 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.header-subtitle {
  margin: 0;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.status-pill {
  font-size: 0.75rem;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid transparent;
}

.status-online {
  color: #86efac;
  background: var(--success-bg);
  border-color: rgba(34, 197, 94, 0.35);
}

.status-offline {
  color: #fcd34d;
  background: var(--warning-bg);
  border-color: rgba(245, 158, 11, 0.35);
}

.app-main {
  flex: 1;
  padding: 16px 14px calc(var(--nav-height) + 24px);
}

.view-section {
  display: none;
}

.view-section.active {
  display: block;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
}

.card-title {
  margin: 0 0 12px;
  font-size: 1rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.muted {
  color: var(--text-muted);
  font-size: 0.85rem;
}

.field-group {
  margin-bottom: 14px;
}

.field-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 6px;
  color: #e2e8f0;
}

.input-row {
  display: flex;
  gap: 8px;
  align-items: stretch;
}

.input-row > input,
.input-row > .input {
  flex: 1;
  min-width: 0;
}

input[type="text"],
input[type="number"],
input[type="url"],
input[type="search"],
textarea,
select {
  width: 100%;
  background: var(--surface-elevated);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 11px 12px;
  font-size: 0.96rem;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

input:focus,
textarea:focus,
select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.18);
}

input:disabled,
textarea:disabled,
button:disabled {
  opacity: 0.48;
  cursor: not-allowed;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 11px 14px;
  font-size: 0.92rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  background: var(--surface-elevated);
  color: var(--text);
  transition: transform 0.08s ease, opacity 0.15s ease, background 0.15s ease;
  white-space: nowrap;
}

.btn:active:not(:disabled) {
  transform: scale(0.98);
}

.btn-primary {
  background: var(--primary-strong);
  color: #ffffff;
}

.btn-success {
  background: #16a34a;
  color: #ffffff;
}

.btn-warning {
  background: #d97706;
  color: #ffffff;
}

.btn-danger {
  background: #dc2626;
  color: #ffffff;
}

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

.btn-sm {
  padding: 7px 10px;
  font-size: 0.82rem;
}

.btn-block {
  width: 100%;
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 0.74rem;
  font-weight: 600;
  background: var(--surface-elevated);
  border: 1px solid var(--border);
  color: var(--text-muted);
}

.badge-ok {
  color: #86efac;
  background: var(--success-bg);
  border-color: rgba(34, 197, 94, 0.35);
}

.badge-warn {
  color: #fcd34d;
  background: var(--warning-bg);
  border-color: rgba(245, 158, 11, 0.35);
}

.badge-danger {
  color: #fca5a5;
  background: var(--danger-bg);
  border-color: rgba(239, 68, 68, 0.35);
}

.locked-overlay {
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
  background: rgba(15, 23, 42, 0.55);
}

.scanner-box {
  margin-top: 10px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--primary);
  background: #000;
}

.scanner-box.hidden {
  display: none;
}

.photo-cam-box {
  margin: 8px 0 10px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--primary);
  background: #000;
}

.photo-cam-box video {
  display: block;
  width: 100%;
  max-height: 320px;
  object-fit: cover;
  background: #000;
}

.photo-cam-actions {
  display: flex;
  gap: 8px;
  padding: 8px;
  background: var(--surface-elevated);
}

.photo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(92px, 1fr));
  gap: 10px;
  margin-top: 10px;
}

.photo-item {
  position: relative;
  aspect-ratio: 1 / 1;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--border);
  background: #fff;
}

.photo-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.photo-index {
  position: absolute;
  left: 5px;
  top: 5px;
  background: rgba(15, 23, 42, 0.85);
  color: #fff;
  font-size: 0.7rem;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 999px;
}

.photo-remove {
  position: absolute;
  right: 5px;
  top: 5px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: none;
  background: rgba(220, 38, 38, 0.92);
  color: #fff;
  font-weight: 700;
  cursor: pointer;
  line-height: 1;
}

.video-preview-wrap {
  margin-top: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px;
  background: var(--surface-elevated);
}

.video-preview-wrap video {
  width: 100%;
  max-height: 240px;
  border-radius: 8px;
  background: #000;
}

.folder-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.8rem;
  padding: 6px 10px;
  border-radius: 8px;
  background: rgba(56, 189, 248, 0.12);
  border: 1px solid rgba(56, 189, 248, 0.3);
  color: #7dd3fc;
  word-break: break-all;
}

/* Contagem */
.counted-product-card {
  display: grid;
  grid-template-columns: 88px 1fr;
  gap: 12px;
  align-items: start;
}

.counted-thumb {
  width: 88px;
  height: 88px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: #fff;
  object-fit: cover;
}

.counted-thumb.empty {
  background: var(--surface-elevated);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 0.72rem;
  text-align: center;
  padding: 6px;
}

.qty-editor {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
}

.qty-editor .btn {
  min-width: 44px;
  min-height: 44px;
  font-size: 1.15rem;
}

.qty-editor input {
  text-align: center;
  font-size: 1.2rem;
  font-weight: 700;
  max-width: 110px;
}

.session-log {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.session-log li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 9px 11px;
  border-radius: var(--radius-sm);
  background: var(--surface-elevated);
  font-size: 0.86rem;
}

/* Estoque */
.stats-bar {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 12px;
}

.stat-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
}

.stat-box strong {
  display: block;
  font-size: 1.2rem;
  color: var(--primary);
}

.stock-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.stock-item {
  display: grid;
  grid-template-columns: 64px 1fr;
  gap: 12px;
  padding: 12px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border);
  align-items: center;
}

.stock-img {
  width: 64px;
  height: 64px;
  border-radius: 10px;
  object-fit: cover;
  border: 1px solid var(--border);
  background: #fff;
}

.stock-img.empty {
  background: var(--surface-elevated);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 0.68rem;
  text-align: center;
}

.stock-meta {
  min-width: 0;
}

.stock-title {
  font-weight: 700;
  font-size: 0.95rem;
  margin: 0 0 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.stock-codes {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.stock-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

.stock-qty-pill {
  font-weight: 700;
  font-size: 0.92rem;
  color: #86efac;
  background: var(--success-bg);
  border: 1px solid rgba(34, 197, 94, 0.35);
  padding: 4px 10px;
  border-radius: 999px;
}

.btn-group {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

/* Bottom nav */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 720px;
  height: var(--nav-height);
  background: rgba(15, 23, 42, 0.97);
  backdrop-filter: blur(10px);
  border-top: 1px solid var(--border);
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  z-index: 30;
  padding-bottom: env(safe-area-inset-bottom);
}

.nav-btn {
  border: none;
  background: transparent;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  font-size: 0.74rem;
  font-weight: 600;
  cursor: pointer;
  padding: 6px 4px;
}

.nav-btn svg {
  width: 22px;
  height: 22px;
}

.nav-btn.active {
  color: var(--primary);
}

/* Toasts */
.toast-container {
  position: fixed;
  top: 66px;
  left: 50%;
  transform: translateX(-50%);
  width: min(92vw, 440px);
  z-index: 50;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  padding: 11px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
  font-weight: 600;
  color: #fff;
  background: #1e293b;
  border: 1px solid var(--border);
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.45);
}

.toast-success {
  background: #14532d;
  border-color: #22c55e;
}

.toast-error {
  background: #7f1d1d;
  border-color: #ef4444;
}

.toast-warning {
  background: #78350f;
  border-color: #f59e0b;
}

.hidden {
  display: none !important;
}

.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.divider {
  border: 0;
  border-top: 1px solid var(--border);
  margin: 14px 0;
}
