/* ====== ДубльЧЗ — основные стили (Phase 1 MVP) ====== */
:root {
  --color-primary: #2563eb;
  --color-primary-hover: #1d4ed8;
  --color-success: #10b981;
  --color-error: #ef4444;
  --color-warning: #f59e0b;
  --color-bg: #f9fafb;
  --color-card: #ffffff;
  --color-text: #111827;
  --color-muted: #6b7280;
  --color-border: #e5e7eb;
  --color-radius: 12px;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.07);
  --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.1);
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  font-family: var(--font-sans);
  background: var(--color-bg);
  color: var(--color-text);
  line-height: 1.5;
}

a { color: var(--color-primary); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3 { margin: 0 0 0.5em; line-height: 1.2; }
h1 { font-size: clamp(1.75rem, 4vw, 2.5rem); }
h2 { font-size: clamp(1.4rem, 3vw, 1.875rem); }
h3 { font-size: 1.125rem; }

.muted { color: var(--color-muted); }
.small { font-size: 0.875rem; }
.hidden { display: none !important; }

/* ====== Topbar ====== */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.875rem 1.25rem;
  background: var(--color-card);
  border-bottom: 1px solid var(--color-border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.logo {
  font-weight: 700;
  font-size: 1.125rem;
  color: var(--color-primary);
  text-decoration: none;
}
.topbar nav { display: flex; gap: 1.25rem; }
.topbar nav a { color: var(--color-text); }
@media (max-width: 640px) {
  .topbar nav { display: none; }
}

.limit-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: 999px;
  padding: 0.25rem 0.75rem;
  font-size: 0.875rem;
}
.limit-pill .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--color-success);
}
.limit-pill.exhausted .dot { background: var(--color-error); }

/* ====== Main / hero (index.html) ====== */
main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 1.5rem 1.25rem 4rem;
}

.hero {
  text-align: center;
  padding: 3rem 1rem;
}
.hero .lead {
  font-size: 1.125rem;
  color: var(--color-muted);
  max-width: 600px;
  margin: 0 auto 1.5rem;
}
.disclaimer {
  margin: 2rem auto 0;
  max-width: 700px;
  padding: 0.875rem 1rem;
  background: #fff7ed;
  border: 1px solid #fed7aa;
  border-radius: var(--color-radius);
  font-size: 0.8125rem;
  color: #7c2d12;
  text-align: left;
}

.steps, .pricing, .faq { padding: 3rem 0; }
.steps h2, .pricing h2, .faq h2 { text-align: center; margin-bottom: 2rem; }

.step-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 1.5rem;
}
.step {
  background: var(--color-card);
  padding: 1.5rem;
  border-radius: var(--color-radius);
  border: 1px solid var(--color-border);
  box-shadow: var(--shadow-sm);
}
.step-num {
  display: inline-flex;
  width: 36px;
  height: 36px;
  align-items: center;
  justify-content: center;
  background: var(--color-primary);
  color: white;
  border-radius: 50%;
  font-weight: 700;
  margin-bottom: 0.75rem;
}

.price-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 1.5rem;
  max-width: 720px;
  margin: 0 auto;
}
.price-card {
  background: var(--color-card);
  padding: 2rem 1.5rem;
  border-radius: var(--color-radius);
  border: 2px solid var(--color-border);
  text-align: center;
}
.price-card.highlight {
  border-color: var(--color-primary);
  box-shadow: var(--shadow-md);
}
.price {
  font-size: 2.5rem;
  font-weight: 700;
  color: var(--color-primary);
  margin: 0.5rem 0 1rem;
}
.price-card ul {
  list-style: none;
  padding: 0;
  margin: 1rem 0 1.5rem;
  text-align: left;
}
.price-card li {
  padding: 0.4rem 0;
  border-bottom: 1px solid var(--color-border);
}
.price-card li:last-child { border-bottom: 0; }

.faq details {
  background: var(--color-card);
  border: 1px solid var(--color-border);
  border-radius: var(--color-radius);
  padding: 1rem 1.25rem;
  margin-bottom: 0.75rem;
}
.faq summary {
  font-weight: 600;
  cursor: pointer;
}
.faq details[open] summary { margin-bottom: 0.5rem; }

.footer {
  text-align: center;
  padding: 2rem 1.25rem;
  color: var(--color-muted);
  font-size: 0.875rem;
  border-top: 1px solid var(--color-border);
}

/* ====== Buttons ====== */
.btn {
  display: inline-block;
  padding: 0.625rem 1.25rem;
  border-radius: 8px;
  border: 1px solid transparent;
  font-size: 1rem;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  transition: all 0.15s ease;
  font-family: inherit;
}
.btn:hover { text-decoration: none; }
.btn-primary {
  background: var(--color-primary);
  color: white;
}
.btn-primary:hover { background: var(--color-primary-hover); }
.btn-secondary {
  background: var(--color-card);
  color: var(--color-text);
  border-color: var(--color-border);
}
.btn-secondary:hover { background: var(--color-bg); }
.btn-lg { padding: 0.875rem 1.5rem; font-size: 1.125rem; }
.btn-block { display: block; width: 100%; }
.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ====== App page (/app) ====== */
.page-app { background: var(--color-bg); }
.app-main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1.25rem;
}
.app-grid {
  display: grid;
  grid-template-columns: 1.45fr 1fr;
  gap: 1.25rem;
  align-items: stretch;
}
@media (max-width: 860px) {
  .app-grid { grid-template-columns: 1fr; }
}
.card {
  background: var(--color-card);
  border: 1px solid var(--color-border);
  border-radius: var(--color-radius);
  padding: 1.25rem;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
}
.scanner-card { min-height: 480px; }
.card h2 { margin-top: 0; font-size: 1.25rem; }

/* Scanner */
.scanner-wrap {
  position: relative;
  width: 100%;
  background: #111827;
  border-radius: var(--color-radius);
  overflow: hidden;
  aspect-ratio: 4/3;
  display: flex;
  align-items: center;
  justify-content: center;
}
#reader {
  width: 100%;
  height: 100%;
}
#reader video {
  width: 100% !important;
  height: 100% !important;
  object-fit: cover;
}
.scanner-empty {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: white;
  padding: 1.5rem;
  background: rgba(17, 24, 39, 0.95);
}
.scanner-actions {
  display: flex;
  gap: 0.5rem;
  margin: 1rem 0;
}
.scanner-actions .btn { flex: 1; }
.scanned-list {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
}
.scanned-list h3 {
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--color-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.scanned-list ol {
  list-style: none;
  padding: 0;
  margin: 0.5rem 0 0;
  flex: 1 1 auto;
  min-height: 120px;
  overflow-y: auto;
}
.scanned-list > #btnClearAll {
  margin-top: auto;
  padding-top: 0.75rem;
}
.scanned-list li {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  background: var(--color-bg);
  border-radius: 8px;
  margin-bottom: 0.375rem;
  font-family: "SF Mono", Consolas, monospace;
  font-size: 0.8125rem;
}
.scanned-list .num {
  color: var(--color-muted);
  font-weight: 600;
  min-width: 1.75rem;
}
.scanned-list .code {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.scanned-list .remove {
  background: none;
  border: 0;
  color: var(--color-error);
  cursor: pointer;
  font-size: 1.125rem;
  padding: 0 0.25rem;
  line-height: 1;
}

/* Settings */
fieldset {
  border: 1px solid var(--color-border);
  border-radius: 8px;
  padding: 0.75rem 1rem;
  margin: 0 0 1rem;
}
legend {
  padding: 0 0.5rem;
  font-weight: 600;
  font-size: 0.875rem;
  color: var(--color-muted);
}
.radio {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  margin-right: 1.25rem;
  cursor: pointer;
}
input[type="range"] {
  width: 100%;
  margin: 0.5rem 0;
}
.scale-hint {
  display: flex;
  justify-content: space-between;
  font-size: 0.75rem;
  color: var(--color-muted);
}

.preview-wrap {
  margin: 1.5rem 0;
  text-align: center;
}
.preview-wrap h3 {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--color-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.5rem;
}
#previewCanvas {
  display: block;
  width: 240px;
  max-width: 100%;
  aspect-ratio: 1;
  margin: 0 auto;
  background: white;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  image-rendering: pixelated;
  image-rendering: -moz-crisp-edges;
  image-rendering: crisp-edges;
}

/* Exhausted */
.exhausted-banner {
  margin-top: 1.5rem;
  padding: 1.25rem;
  background: #fef2f2;
  border: 1px solid #fecaca;
  border-radius: var(--color-radius);
  text-align: center;
}
.exhausted-banner h3 {
  color: var(--color-error);
  margin: 0 0 0.5rem;
}

/* Result */
.result {
  margin-top: 1.5rem;
  background: #ecfdf5;
  border: 1px solid #a7f3d0;
  border-radius: var(--color-radius);
  padding: 1.5rem;
  text-align: center;
}
.result h2 { color: var(--color-success); }
.result-actions {
  display: flex;
  gap: 0.75rem;
  margin-top: 1rem;
  justify-content: center;
  flex-wrap: wrap;
}

/* === Preset grid for label size === */
.preset-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.375rem;
  margin-bottom: 0.75rem;
}
.preset-btn {
  background: var(--color-card);
  border: 1px solid var(--color-border);
  border-radius: 6px;
  padding: 0.5rem 0.25rem;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.12s ease;
  font-family: inherit;
  color: var(--color-text);
}
.preset-btn:hover {
  border-color: var(--color-primary);
  background: #eff6ff;
}
.preset-btn.active {
  background: var(--color-primary);
  color: white;
  border-color: var(--color-primary);
}
.custom-size {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  font-size: 0.875rem;
  color: var(--color-muted);
}
.custom-size input[type="number"] {
  width: 60px;
  padding: 0.375rem 0.5rem;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  font-family: inherit;
  font-size: 0.875rem;
}
.custom-size input[type="number"]:focus {
  outline: none;
  border-color: var(--color-primary);
}

/* === Input group (manual scan) === */
.input-group {
  display: flex;
  gap: 0.5rem;
  margin: 0.5rem 0 1rem;
}
.input-group input {
  flex: 1;
  padding: 0.75rem 1rem;
  border: 2px solid var(--color-border);
  border-radius: 8px;
  font-size: 1rem;
  font-family: "SF Mono", Consolas, monospace;
  transition: border-color 0.12s ease;
}
.input-group input:focus {
  outline: none;
  border-color: var(--color-primary);
}

.input-mode {
  display: flex;
  gap: 1rem;
  margin-bottom: 1rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--color-border);
}

/* App footer with version */
.app-footer {
  position: fixed;
  bottom: 0.5rem;
  right: 0.75rem;
  font-size: 0.75rem;
  color: var(--color-muted);
  background: rgba(255, 255, 255, 0.85);
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
  pointer-events: none;
}

/* Autoprint fieldset */
.autoprint-fieldset { background: #eff6ff; border-color: #93c5fd; }
.autoprint-fieldset .checkbox { display: flex; align-items: center; gap: 0.5rem; cursor: pointer; font-weight: 500; }
.autoprint-fieldset input[type="checkbox"] { width: 18px; height: 18px; cursor: pointer; }
.autoprint-fieldset .muted { margin: 0.5rem 0 0 1.75rem; }

/* Иконка "i" для tooltip на autoPrint */
.info-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.1rem;
  height: 1.1rem;
  border-radius: 50%;
  background: #93c5fd;
  color: #1e3a8a;
  font-size: 0.7rem;
  font-weight: 700;
  font-style: italic;
  font-family: "Georgia", serif;
  cursor: help;
  user-select: none;
  flex-shrink: 0;
}
.info-icon:hover { background: #60a5fa; }

/* === Auth pages === */
.auth-main { display: flex; align-items: center; justify-content: center; min-height: 70vh; padding: 1.5rem 1rem; }
.auth-card { background: var(--color-card); border: 1px solid var(--color-border); border-radius: var(--color-radius); padding: 2rem; max-width: 480px; width: 100%; box-shadow: var(--shadow-md); }
.auth-card h1 { margin: 0 0 0.5rem; font-size: 1.5rem; }
.auth-card .form-group { margin-bottom: 1rem; }
.auth-card label { display: block; font-weight: 500; margin-bottom: 0.375rem; }
.auth-card input[type="email"], .auth-card input[type="password"], .auth-card input[type="text"] { width: 100%; padding: 0.625rem 0.75rem; border: 1px solid var(--color-border); border-radius: 6px; font-size: 1rem; font-family: inherit; box-sizing: border-box; }
.auth-card input:focus { outline: none; border-color: var(--color-primary); }
.auth-card .checkbox { display: flex; align-items: flex-start; gap: 0.5rem; font-weight: 400; cursor: pointer; }
.auth-card .checkbox input { margin-top: 0.25rem; flex-shrink: 0; }
.auth-card .checkbox a { color: var(--color-primary); }
.center { text-align: center; }
.error { margin-top: 1rem; padding: 0.75rem; background: #fef2f2; border: 1px solid #fecaca; border-radius: 6px; color: #991b1b; font-size: 0.875rem; }
.user-info p { margin: 0.5rem 0; }
