:root {
  --bg: var(--tg-theme-bg-color, #0f172a);
  --secondary-bg: var(--tg-theme-secondary-bg-color, #1e293b);
  --text: var(--tg-theme-text-color, #f8fafc);
  --hint: var(--tg-theme-hint-color, #94a3b8);
  --accent: var(--tg-theme-button-color, #3b82f6);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --success: #22c55e;
  --warning: #f59e0b;
  --danger: #ef4444;
  --border: rgba(148, 163, 184, 0.16);
  --radius: 14px;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  padding-bottom: 76px;
  font-size: 14px;
  line-height: 1.45;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(8px);
}

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

.logo {
  font-weight: 700;
  font-size: 17px;
  letter-spacing: -0.2px;
}

.badge {
  font-size: 11px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 999px;
  background: rgba(59, 130, 246, 0.18);
  color: var(--accent);
}

.badge-warn {
  background: rgba(245, 158, 11, 0.18);
  color: var(--warning);
}

.badge-danger {
  background: rgba(239, 68, 68, 0.18);
  color: var(--danger);
}

.badge-success {
  background: rgba(34, 197, 94, 0.18);
  color: var(--success);
}

.icon-btn {
  background: var(--secondary-bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  width: 34px;
  height: 34px;
  font-size: 16px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.app-content {
  padding: 14px 14px 24px;
  max-width: 640px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.card {
  background: var(--secondary-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.card-title {
  font-weight: 700;
  font-size: 15px;
}

.muted {
  color: var(--hint);
  font-size: 12px;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

.stat-box {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 12px;
}

.stat-label {
  font-size: 11px;
  color: var(--hint);
  margin-bottom: 4px;
}

.stat-value {
  font-size: 16px;
  font-weight: 700;
}

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

.list-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px;
  border-radius: 11px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border);
}

.list-item-main {
  flex: 1;
  min-width: 0;
}

.list-item-title {
  font-weight: 600;
  font-size: 14px;
}

.list-item-sub {
  font-size: 12px;
  color: var(--hint);
  margin-top: 2px;
}

.progress-track {
  height: 8px;
  border-radius: 999px;
  background: rgba(148, 163, 184, 0.2);
  overflow: hidden;
  margin: 6px 0;
}

.progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 999px;
  transition: width 0.25s ease;
}

.progress-fill.success {
  background: var(--success);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 14px;
  border-radius: 11px;
  border: none;
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
}

.btn:active {
  opacity: 0.85;
}

.btn-sm {
  padding: 6px 10px;
  font-size: 12px;
  border-radius: 9px;
}

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

.btn-success {
  background: var(--success);
  color: #052e16;
}

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

.btn-warn {
  background: var(--warning);
  color: #1c1917;
}

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

.btn-block {
  width: 100%;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 10px;
}

.form-group label {
  font-size: 12px;
  color: var(--hint);
  font-weight: 500;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

input, select, textarea {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
}

textarea {
  resize: vertical;
  min-height: 84px;
}

.segment {
  display: flex;
  gap: 6px;
  margin-bottom: 10px;
}

.segment button {
  flex: 1;
  padding: 8px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--hint);
  font-weight: 600;
  font-size: 12px;
  cursor: pointer;
}

.segment button.active {
  background: var(--accent);
  color: var(--accent-text);
  border-color: var(--accent);
}

.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 30;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  background: var(--secondary-bg);
  border-top: 1px solid var(--border);
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom, 0px));
}

.nav-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  background: transparent;
  border: none;
  color: var(--hint);
  cursor: pointer;
  padding: 4px 2px;
}

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

.nav-icon {
  font-size: 19px;
  line-height: 1.1;
}

.nav-label {
  font-size: 10px;
  font-weight: 600;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(0, 0, 0, 0.65);
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.modal-backdrop.hidden {
  display: none;
}

.modal-sheet {
  width: 100%;
  max-width: 640px;
  max-height: 88vh;
  overflow-y: auto;
  background: var(--secondary-bg);
  border-top-left-radius: 18px;
  border-top-right-radius: 18px;
  padding: 16px;
  border-top: 1px solid var(--border);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.toast {
  position: fixed;
  top: 64px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 60;
  background: #0f172a;
  color: #f8fafc;
  border: 1px solid var(--accent);
  padding: 10px 16px;
  border-radius: 12px;
  font-size: 13px;
  font-weight: 600;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  max-width: 90vw;
  text-align: center;
}

.toast.hidden {
  display: none;
}

.loader {
  text-align: center;
  color: var(--hint);
  padding: 40px 16px;
}

#barcode-reader {
  width: 100%;
  border-radius: 12px;
  overflow: hidden;
  margin-bottom: 10px;
}
