@import url('https://fonts.googleapis.com/css2?family=Barlow+Condensed:wght@400;600;700;900&family=Barlow:wght@400;500;600&display=swap');

:root {
  --bg: #0f1117;
  --surface: #181c27;
  --surface2: #1f2435;
  --border: #2a3048;
  --accent: #f5a623;
  --accent2: #e8441a;
  --green: #22c55e;
  --red: #ef4444;
  --yellow: #eab308;
  --blue: #3b82f6;
  --text: #e8eaf0;
  --muted: #6b7280;
}

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Barlow', sans-serif;
  font-size: 15px;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
}

#root {
  min-height: 100vh;
}

#app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

main {
  flex: 1;
  padding: 20px;
  max-width: 1400px;
  margin: 0 auto;
  width: 100%;
}

h1, h2, h3, h4 {
  font-family: 'Barlow Condensed', sans-serif;
}

a {
  color: var(--accent);
  text-decoration: none;
}

/* Inputs & Selects */

input, select, textarea {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-family: 'Barlow', sans-serif;
  /* 16px prevents iOS Safari from auto-zooming on focus */
  font-size: 16px;
  padding: 8px 12px;
  outline: none;
  transition: border-color 0.15s;
  width: 100%;
  /* Remove iOS default styling */
  -webkit-appearance: none;
  appearance: none;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
}

input::placeholder, textarea::placeholder {
  color: var(--muted);
}

select option {
  background: var(--surface2);
  color: var(--text);
}

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

/* Buttons */

.btn {
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-family: 'Barlow Condensed', sans-serif;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.5px;
  /* 44px min height for touch targets (Apple HIG / Material guidelines) */
  min-height: 44px;
  padding: 8px 16px;
  transition: opacity 0.15s, background 0.15s, transform 0.1s;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
  /* Eliminates 300ms tap delay on mobile */
  touch-action: manipulation;
  /* Prevent text selection on tap-hold */
  -webkit-user-select: none;
  user-select: none;
}

.btn:hover:not(:disabled) {
  opacity: 0.88;
}

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

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

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

.btn-success {
  background: var(--green);
  color: #111;
}

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

.btn-blue {
  background: var(--blue);
  color: #fff;
}

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

.btn-ghost:hover:not(:disabled) {
  color: var(--text);
  border-color: var(--text);
  opacity: 1;
}

.btn-sm {
  padding: 5px 10px;
  font-size: 12px;
  min-height: 36px;
}

.btn-lg {
  padding: 12px 24px;
  font-size: 16px;
}

.btn-full {
  width: 100%;
  justify-content: center;
}

/* Card */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 18px;
}

/* Badge */

.badge {
  background: var(--accent);
  color: #111;
  border-radius: 4px;
  font-family: 'Barlow Condensed', monospace;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.5px;
  padding: 2px 8px;
  display: inline-block;
}

.badge-muted {
  background: var(--surface2);
  color: var(--muted);
  border: 1px solid var(--border);
}

.badge-blue {
  background: rgba(59, 130, 246, 0.2);
  color: var(--blue);
  border: 1px solid rgba(59, 130, 246, 0.3);
}

.badge-green {
  background: rgba(34, 197, 94, 0.15);
  color: var(--green);
  border: 1px solid rgba(34, 197, 94, 0.3);
}

.badge-red {
  background: rgba(239, 68, 68, 0.15);
  color: var(--red);
  border: 1px solid rgba(239, 68, 68, 0.3);
}

/* Pill */

.pill {
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  font-weight: 600;
  padding: 3px 10px;
}

.pill-green {
  background: rgba(34, 197, 94, 0.15);
  color: var(--green);
}

.pill-yellow {
  background: rgba(234, 179, 8, 0.15);
  color: var(--yellow);
}

.pill-red {
  background: rgba(239, 68, 68, 0.15);
  color: var(--red);
}

.pill-muted {
  background: var(--surface2);
  color: var(--muted);
}

/* Modal */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  z-index: 1000;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0;
  backdrop-filter: blur(2px);
}

@media (min-width: 600px) {
  .modal-overlay {
    align-items: center;
    padding: 16px;
  }
}

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px 16px 0 0;
  padding: 24px 20px;
  padding-bottom: calc(24px + env(safe-area-inset-bottom));
  width: 100%;
  max-width: 100%;
  max-height: 92vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  position: relative;
  box-shadow: 0 -8px 40px rgba(0, 0, 0, 0.5);
}

@media (min-width: 600px) {
  .modal {
    border-radius: 12px;
    padding: 28px;
    max-width: 520px;
    max-height: 90vh;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  }
}

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

.modal-title {
  font-family: 'Barlow Condensed', sans-serif;
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
}

.modal-close {
  background: transparent;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 20px;
  line-height: 1;
  padding: 4px;
  border-radius: 4px;
  transition: color 0.15s;
}

.modal-close:hover {
  color: var(--text);
}

.modal-footer {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 24px;
}

/* Form */

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-group label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}

.form-group label .required {
  color: var(--accent);
  margin-left: 3px;
}

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

.form-stack {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* Table */

table {
  width: 100%;
  border-collapse: collapse;
  /* Prevent table text from being tiny on mobile */
  font-size: 14px;
}

thead th {
  background: var(--surface2);
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.8px;
  padding: 10px 12px;
  text-align: left;
  text-transform: uppercase;
  border-bottom: 1px solid var(--border);
}

tbody td {
  border-bottom: 1px solid var(--border);
  padding: 10px 12px;
  vertical-align: middle;
}

tbody tr:last-child td {
  border-bottom: none;
}

tbody tr:hover {
  background: rgba(255, 255, 255, 0.02);
}

/* Scrollbar */

::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: var(--bg);
}

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--muted);
}

/* Progress bar */

.progress-bar {
  background: var(--surface2);
  border-radius: 999px;
  height: 6px;
  overflow: hidden;
  width: 100%;
}

.progress-bar-fill {
  height: 100%;
  border-radius: 999px;
  transition: width 0.3s;
}

/* Divider */

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

/* Stat card */

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 18px;
  text-align: center;
}

.stat-card .stat-value {
  font-family: 'Barlow Condensed', sans-serif;
  font-size: 36px;
  font-weight: 700;
  line-height: 1;
}

.stat-card .stat-label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.5px;
  margin-top: 6px;
  text-transform: uppercase;
}

/* Bar chart row */

.bar-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}

.bar-row .bar-label {
  font-size: 13px;
  min-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bar-row .bar-track {
  flex: 1;
  background: var(--surface2);
  border-radius: 999px;
  height: 8px;
  overflow: hidden;
}

.bar-row .bar-fill {
  background: var(--accent);
  height: 100%;
  border-radius: 999px;
}

.bar-row .bar-qty {
  color: var(--muted);
  font-size: 12px;
  min-width: 40px;
  text-align: right;
}

/* Section header */

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

.section-title {
  font-family: 'Barlow Condensed', sans-serif;
  font-size: 22px;
  font-weight: 700;
}

/* Grid layouts */

.grid-4 {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
}

.grid-3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

/* Input with orange border (required) */

input.required-field {
  border-color: var(--accent);
}

/* Empty state */

.empty-state {
  color: var(--muted);
  font-size: 14px;
  padding: 32px;
  text-align: center;
}

/* Scan box */

.scan-box {
  background: var(--surface2);
  border: 2px dashed var(--border);
  border-radius: 10px;
  cursor: pointer;
  min-height: 160px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  transition: border-color 0.2s;
  position: relative;
  overflow: hidden;
}

.scan-box:hover {
  border-color: var(--accent);
}

.scan-box video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 8px;
}

/* Label card for printing */

.label-card {
  background: #fff;
  border: 1px solid #ccc;
  border-radius: 4px;
  color: #000;
  display: flex;
  flex-direction: column;
  font-family: 'Barlow Condensed', sans-serif;
  overflow: hidden;
  padding: 4px;
}

/* 3×3 inch labels at screen 96dpi */

.label-card.size-small {
  width: 216px;
  height: 216px;
}

.label-card.size-medium {
  width: 288px;
  height: 288px;
}

.label-card.size-large {
  width: 360px;
  height: 360px;
}

/* Print styles handled in the bottom @media print block */

#label-print-area {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 8px;
}

/* Filter chips */

.filter-chip {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--muted);
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  padding: 5px 14px;
  transition: all 0.15s;
}

.filter-chip:hover {
  border-color: var(--accent);
  color: var(--text);
}

.filter-chip.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #111;
}

/* Safe area support (iPhone X+ notch / home bar) */

#app header {
  padding-top: env(safe-area-inset-top);
}

main {
  padding-bottom: calc(20px + env(safe-area-inset-bottom));
}

/* Scrollable containers */

.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* Filter chips */

.filter-chips {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  -webkit-overflow-scrolling: touch;
}

/* Media queries */

@media (max-width: 700px) {
  main {
    padding: 12px;
    padding-bottom: calc(16px + env(safe-area-inset-bottom));
  }

  .form-row {
    grid-template-columns: 1fr;
  }

  .grid-4 {
    grid-template-columns: repeat(2, 1fr);
  }

  .grid-3 {
    grid-template-columns: repeat(2, 1fr);
  }

  .grid-2 {
    grid-template-columns: 1fr;
  }

  table {
    font-size: 13px;
  }

  thead th, tbody td {
    padding: 8px;
  }

  /* Ensure touch targets stay reachable in table */
  tbody td .btn {
    min-height: 36px;
  }

  /* Bar chart label truncation on small screens */
  .bar-row .bar-label {
    min-width: 80px;
    font-size: 12px;
  }
}

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

/* Print styles */

/* Print is handled by the popup window opened by handlePrint in LabelsView */
/* App-level styles — minimal, all main styles in index.css */
