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

:root {
  --bg: #f5f5f7;
  --surface: #ffffff;
  --text: #1d1d1f;
  --text-secondary: #6e6e73;
  --accent: #0071e3;
  --accent-hover: #0062cc;
  --danger: #ff3b30;
  --success: #34c759;
  --warning: #ff9500;
  --border: #d2d2d7;
  --shadow: 0 1px 3px rgba(0,0,0,0.08);
  --radius: 12px;
  --radius-sm: 8px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1c1c1e;
    --surface: #2c2c2e;
    --text: #f5f5f7;
    --text-secondary: #98989d;
    --border: #48484a;
    --shadow: 0 1px 3px rgba(0,0,0,0.3);
  }
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Helvetica Neue', sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
  padding-bottom: 80px;
}

/* Header */
.app-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 12px 16px;
  position: sticky;
  top: 0;
  z-index: 100;
}

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

.header-logo {
  width: 36px;
  height: 36px;
  border-radius: 8px;
}

.app-header h1 {
  font-size: 20px;
  font-weight: 700;
  text-align: center;
}

.header-stats {
  display: flex;
  justify-content: center;
  gap: 16px;
  margin-top: 4px;
  font-size: 13px;
  color: var(--text-secondary);
}

/* Tab Bar */
.tab-bar {
  display: flex;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 68px;
  z-index: 99;
}

.tab-btn {
  flex: 1;
  padding: 10px;
  border: none;
  background: none;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: all 0.2s;
}

.tab-btn.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.tab-btn .badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 10px;
  background: var(--accent);
  color: white;
  font-size: 11px;
  font-weight: 700;
  margin-left: 6px;
  vertical-align: middle;
}

/* Filters */
.filter-bar {
  padding: 10px 16px;
  display: flex;
  gap: 8px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--bg);
}

.filter-bar::-webkit-scrollbar { display: none; }

.search-wrap {
  padding: 8px 16px 0;
}

.search-input {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 16px;
  background: var(--surface);
  color: var(--text);
  -webkit-appearance: none;
}

.search-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(0,113,227,0.15);
}

.filter-chip {
  display: inline-flex;
  align-items: center;
  padding: 6px 14px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
  transition: all 0.15s;
  -webkit-tap-highlight-color: transparent;
}

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

.filter-chip select {
  border: none;
  background: transparent;
  color: inherit;
  font: inherit;
  cursor: pointer;
  -webkit-appearance: none;
  padding-right: 2px;
}

/* Stock filter buttons */
.stock-filter-bar {
  padding: 0 16px 8px;
  display: flex;
  gap: 8px;
}

.stock-chip {
  display: inline-flex;
  align-items: center;
  padding: 4px 12px;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.stock-chip.active {
  background: var(--warning);
  color: white;
  border-color: var(--warning);
}

/* Inventory List */
.inventory-list {
  padding: 8px 16px;
}

.filament-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  background: var(--surface);
  border-radius: var(--radius);
  margin-bottom: 8px;
  box-shadow: var(--shadow);
  transition: transform 0.1s;
  -webkit-tap-highlight-color: transparent;
}

.filament-card.out-of-stock {
  opacity: 0.7;
  border-left: 3px solid var(--warning);
}

.color-swatch {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  flex-shrink: 0;
  border: 1px solid var(--border);
}

.filament-info {
  flex: 1;
  min-width: 0;
}

.filament-name {
  font-weight: 600;
  font-size: 15px;
  line-height: 1.3;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.filament-meta {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 1px;
}

.filament-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.stock-count {
  font-size: 20px;
  font-weight: 700;
  min-width: 28px;
  text-align: center;
}

.stock-count.zero { color: var(--danger); }
.stock-count.low { color: var(--warning); }

.btn-use {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: white;
  font-size: 20px;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.btn-use:active {
  transform: scale(0.9);
}

.btn-use:disabled {
  background: var(--border);
  cursor: not-allowed;
}

.btn-delete-filament {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-size: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
  -webkit-tap-highlight-color: transparent;
  opacity: 0.5;
}

.btn-delete-filament:hover,
.btn-delete-filament:active {
  opacity: 1;
  color: var(--danger);
}

.btn-order-add {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid var(--accent);
  background: transparent;
  color: var(--accent);
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.btn-order-add:active {
  transform: scale(0.9);
  background: var(--accent);
  color: white;
}

.btn-order-add.on-list {
  background: var(--success);
  border-color: var(--success);
  color: white;
  font-size: 14px;
}

/* Order List View */
.order-view { padding: 8px 16px; }

.vendor-group {
  margin-bottom: 16px;
}

.vendor-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  background: var(--surface);
  border-radius: var(--radius) var(--radius) 0 0;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.vendor-name {
  font-weight: 700;
  font-size: 16px;
}

.vendor-count {
  font-size: 13px;
  color: var(--text-secondary);
}

.vendor-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.btn-sm {
  padding: 6px 12px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
}

.btn-sm.danger {
  color: var(--danger);
  border-color: var(--danger);
}

.btn-sm.danger:active {
  background: var(--danger);
  color: white;
}

.order-items {
  background: var(--surface);
  border-radius: 0 0 var(--radius) var(--radius);
  overflow: hidden;
}

.order-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}

.order-item:last-child { border-bottom: none; }

.order-item .color-swatch {
  width: 32px;
  height: 32px;
  border-radius: 8px;
}

.order-item-info {
  flex: 1;
  min-width: 0;
}

.order-item-name {
  font-weight: 600;
  font-size: 14px;
}

.order-item-meta {
  font-size: 12px;
  color: var(--text-secondary);
}

.qty-control {
  display: flex;
  align-items: center;
  gap: 6px;
}

.qty-btn {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.qty-value {
  font-weight: 700;
  font-size: 16px;
  min-width: 20px;
  text-align: center;
}

.btn-remove {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: none;
  background: var(--danger);
  color: white;
  font-size: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 90px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: #333;
  color: white;
  padding: 12px 20px;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 500;
  z-index: 200;
  transition: transform 0.3s ease;
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: calc(100vw - 32px);
}

.toast.show {
  transform: translateX(-50%) translateY(0);
}

.toast-undo {
  background: none;
  border: none;
  color: var(--accent);
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
  padding: 4px 8px;
  white-space: nowrap;
}

/* Empty state */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-secondary);
}

.empty-state-icon {
  font-size: 48px;
  margin-bottom: 12px;
}

.empty-state-text {
  font-size: 15px;
  font-weight: 500;
}

/* Loading */
.loading {
  text-align: center;
  padding: 40px;
  color: var(--text-secondary);
  font-size: 15px;
}

.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto 12px;
}

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

/* Modal / Add to Order overlay */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 150;
  display: none;
  align-items: flex-end;
  justify-content: center;
}

.modal-overlay.show { display: flex; }

.modal-sheet {
  background: var(--surface);
  border-radius: var(--radius) var(--radius) 0 0;
  width: 100%;
  max-width: 500px;
  padding: 20px;
  animation: slideUp 0.3s ease;
}

@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

.modal-sheet h2 {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 16px;
}

.modal-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}

.modal-row label {
  font-size: 14px;
  font-weight: 500;
  min-width: 60px;
}

.modal-row input, .modal-row select {
  flex: 1;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 16px;
  background: var(--bg);
  color: var(--text);
}

.modal-buttons {
  display: flex;
  gap: 10px;
  margin-top: 16px;
}

.modal-buttons button {
  flex: 1;
  padding: 12px;
  border-radius: var(--radius-sm);
  border: none;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
}

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

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

/* Search row with Add button */
.search-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.search-row .search-input {
  flex: 1;
}

.btn-add-filament {
  padding: 10px 14px;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: white;
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  transition: background 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.btn-add-filament:active {
  background: var(--accent-hover);
}

/* Hex color input group */
.hex-input-group {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
}

.hex-input-group input[type="color"] {
  width: 44px;
  height: 44px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 2px;
  cursor: pointer;
  background: var(--bg);
  flex-shrink: 0;
}

.hex-input-group input[type="text"],
.hex-input-group input:not([type]) {
  flex: 1;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 16px;
  background: var(--bg);
  color: var(--text);
}

/* Section headers in inventory */
.section-header {
  padding: 8px 4px 4px;
  font-size: 13px;
  font-weight: 700;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* Responsive - wider screens */
@media (min-width: 768px) {
  .inventory-list {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
  }
  .section-header { grid-column: 1 / -1; }
  .order-view { max-width: 600px; margin: 0 auto; }
}

@media (min-width: 1024px) {
  .inventory-list {
    grid-template-columns: repeat(3, 1fr);
    max-width: 1000px;
    margin: 0 auto;
  }
}
