:root {
  --bg: #f2f4f7;
  --panel: #ffffff;
  --border: #d8dde4;
  --text: #1f2d3d;
  --muted: #6b778c;
  --accent: #f7c845;
  --success: #16a34a;
  --danger: #dc2626;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
  touch-action: manipulation;
  -webkit-text-size-adjust: 100%;
}

.page {
  padding: 12px 12px 92px;
  max-width: 680px;
  margin: 0 auto;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
}

.title-wrap h1 {
  margin: 0 0 2px 0;
  font-size: 20px;
}

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

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  margin-bottom: 10px;
}

.card h2 {
  margin: 0 0 10px 0;
  font-size: 15px;
}

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

.form-grid .full {
  grid-column: 1 / -1;
}

label {
  display: block;
  font-size: 12px;
  color: var(--muted);
}

input, select, button {
  width: 100%;
  margin-top: 4px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 15px;
  background: #fff;
  touch-action: manipulation;
}

.btn {
  font-weight: 700;
}

.btn.primary {
  background: var(--accent);
  border-color: #e0b52e;
}

.btn.success {
  background: #dcfce7;
  border-color: #86efac;
}

.btn.ghost {
  width: auto;
  min-width: 120px;
  text-align: center;
  text-decoration: none;
  color: var(--text);
  display: inline-block;
  margin-top: 0;
}

.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.scan-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.preview-wrap {
  margin-top: 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  background: #111827;
  aspect-ratio: 16 / 6;
  max-height: 190px;
  position: relative;
}

.scanner-card {
  position: sticky;
  top: 0;
  z-index: 15;
}

body.scanner-active .scanner-card {
  border-color: #c7d2e0;
  box-shadow: 0 6px 20px rgba(17, 24, 39, 0.12);
}

.lines-card {
  scroll-margin-top: 210px;
}

.lines-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

.lines-head h2 {
  margin: 0;
}

#m-add-new.btn {
  width: auto;
  margin-top: 0;
  white-space: nowrap;
}

#m-camera {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.scan-guide {
  position: absolute;
  inset: 0;
  pointer-events: none;
  display: flex;
  align-items: center;
  justify-content: center;
}

.scan-guide-band {
  width: 90%;
  height: 3px;
  border-radius: 999px;
  background: rgba(220, 38, 38, 0.98);
  box-shadow:
    0 0 0 9999px rgba(0, 0, 0, 0.16),
    0 0 12px rgba(220, 38, 38, 0.75);
}

.manual-add {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  margin-top: 8px;
}

.barcode-input-wrap {
  position: relative;
}

.barcode-input-wrap input {
  padding-right: 38px;
}

.clear-btn {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  width: 28px;
  height: 28px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: #fff;
  color: #991b1b;
  font-weight: 700;
  line-height: 1;
  margin: 0;
  padding: 0;
}

.clear-btn:disabled {
  opacity: 0.45;
}

.manual-add .btn {
  width: auto;
}

.errors {
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: #991b1b;
  border-radius: 8px;
  padding: 8px 10px;
  margin-bottom: 10px;
}

.errors ul {
  margin: 0;
  padding-left: 16px;
}

.line-card {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px;
  margin-bottom: 8px;
  background: #fff;
}

.line-top {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: flex-start;
}

.line-title {
  font-size: 14px;
  font-weight: 600;
  line-height: 1.35;
}

.line-sub {
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
}

.line-grid {
  margin-top: 8px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.line-grid .full {
  grid-column: 1 / -1;
}

.bottom-actions {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  padding: 10px 12px;
  background: rgba(255, 255, 255, 0.96);
  border-top: 1px solid var(--border);
  backdrop-filter: blur(6px);
  z-index: 20;
}

@media (max-width: 420px) {
  .form-grid,
  .scan-actions,
  .bottom-actions {
    grid-template-columns: 1fr;
  }
  .preview-wrap {
    aspect-ratio: 16 / 7;
  }
}
