/**
 * components.css
 * Reusable UI components: buttons, inputs, search bar, cards, badges,
 * tables, modals, forms, empty states. Organized in the order a
 * developer would scan the app's screens.
 */

/* =========================================================
   Buttons
   ========================================================= */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  height: 44px;
  padding: 0 var(--space-5);
  border-radius: var(--radius-md);
  font-weight: 700;
  font-size: var(--text-base);
  white-space: nowrap;
  transition: background var(--duration-fast) var(--ease-standard),
              border-color var(--duration-fast) var(--ease-standard),
              transform var(--duration-fast) var(--ease-standard);
}

.btn:active {
  transform: scale(0.98);
}

.btn-primary {
  background: var(--color-primary);
  color: #FFFFFF;
}
.btn-primary:hover { background: var(--color-primary-dark); }

.btn-secondary {
  background: var(--color-primary-light);
  color: var(--color-primary-dark);
}
.btn-secondary:hover { background: #DCE6DA; }

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

.btn-danger {
  background: var(--color-danger-bg);
  color: #8A3F3F;
}
.btn-danger:hover { background: #F2DCDC; }

.btn-ghost {
  background: transparent;
  color: var(--color-text-muted);
  height: auto;
  padding: var(--space-2);
}

.btn-sm {
  height: 36px;
  padding: 0 var(--space-3);
  font-size: var(--text-sm);
  border-radius: var(--radius-sm);
}

.btn-block { width: 100%; }

.btn-icon {
  width: 40px;
  height: 40px;
  padding: 0;
  border-radius: var(--radius-md);
  color: var(--color-text-muted);
  background: transparent;
}
.btn-icon:hover { background: var(--color-primary-light); color: var(--color-primary-dark); }

.btn[disabled] {
  opacity: 0.5;
  pointer-events: none;
}

/* =========================================================
   Form fields
   ========================================================= */
.field {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.field__label {
  font-size: var(--text-sm);
  font-weight: 700;
  color: var(--color-text);
}

.field__hint {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
}

.field__error {
  font-size: var(--text-xs);
  color: #8A3F3F;
}

.input, .select, .textarea {
  width: 100%;
  height: 46px;
  padding: 0 var(--space-4);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  color: var(--color-text);
  transition: border-color var(--duration-fast) var(--ease-standard),
              box-shadow var(--duration-fast) var(--ease-standard);
}

.textarea {
  height: auto;
  min-height: 88px;
  padding: var(--space-3) var(--space-4);
  resize: vertical;
}

.input:focus, .select:focus, .textarea:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 4px var(--color-focus-ring);
}

.input.has-error, .select.has-error, .textarea.has-error {
  border-color: var(--color-danger);
}

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

.select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23849087' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right var(--space-3) center;
  padding-right: var(--space-8);
}

.input-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-3);
}

/* =========================================================
   Search bar (home screen priority element)
   ========================================================= */
.search-bar {
  position: relative;
  display: flex;
  align-items: center;
}

.search-bar__icon {
  position: absolute;
  left: var(--space-4);
  color: var(--color-text-muted);
  pointer-events: none;
}

.search-bar__input {
  width: 100%;
  height: 56px;
  padding: 0 var(--space-10) 0 var(--space-10);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  font-size: var(--text-md);
  font-weight: 600;
  color: var(--color-text);
  box-shadow: var(--shadow-sm);
}

.search-bar__input:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 4px var(--color-focus-ring);
}

.search-bar__clear {
  position: absolute;
  right: var(--space-3);
  width: 32px;
  height: 32px;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-text-muted);
}
.search-bar__clear:hover { background: var(--color-bg); }

.search-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin-top: var(--space-3);
}

.search-suggestion-chip {
  padding: var(--space-2) var(--space-4);
  background: var(--color-primary-light);
  color: var(--color-primary-dark);
  border-radius: var(--radius-full);
  font-size: var(--text-sm);
  font-weight: 600;
}
.search-suggestion-chip:hover { background: #DCE6DA; }

/* =========================================================
   Category shortcuts (home screen)
   ========================================================= */
.category-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
  gap: var(--space-3);
}

.category-tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-3);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  text-align: center;
}
.category-tile:hover { border-color: var(--color-secondary); }

.category-tile__icon {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  background: var(--color-beige);
  color: var(--color-primary-dark);
  display: flex;
  align-items: center;
  justify-content: center;
}

.category-tile__label {
  font-size: var(--text-xs);
  font-weight: 700;
  color: var(--color-text);
  line-height: var(--leading-tight);
}

/* =========================================================
   Product cards (search results, lists)
   ========================================================= */
.product-card {
  display: block;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
  box-shadow: var(--shadow-sm);
}

.product-card__header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-3);
}

.product-card__name {
  font-family: var(--font-display);
  font-size: var(--text-md);
  font-weight: 700;
  color: var(--color-text);
}

.product-card__meta {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  margin-top: 2px;
}

.product-card__meta strong {
  color: var(--color-text);
  font-weight: 600;
}

.product-card__sizes {
  margin-top: var(--space-3);
  border-top: 1px solid var(--color-border);
  padding-top: var(--space-3);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.product-card__size-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: var(--text-base);
}

.product-card__size-label {
  color: var(--color-text-muted);
  font-weight: 600;
}

.product-card__size-price {
  font-family: var(--font-display);
  font-weight: 700;
  color: var(--color-text);
  font-variant-numeric: tabular-nums;
}

.product-card__footer {
  margin-top: var(--space-3);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
}

.product-card__updated {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
}

/* =========================================================
   Badges / status pills
   ========================================================= */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px var(--space-2);
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
  font-weight: 700;
}

.badge-success { background: var(--color-success-bg); color: #3F6B46; }
.badge-warning { background: var(--color-warning-bg); color: #8A6A2A; }
.badge-danger  { background: var(--color-danger-bg);  color: #8A3F3F; }
.badge-neutral { background: var(--color-bg); color: var(--color-text-muted); border: 1px solid var(--color-border); }

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.status-dot.online { background: var(--color-success); }
.status-dot.offline { background: var(--color-warning); }

/* =========================================================
   Category pill (category badge shown on cards)
   ========================================================= */
.pill {
  display: inline-block;
  padding: 2px var(--space-2);
  background: var(--color-beige);
  color: var(--color-text);
  border-radius: var(--radius-sm);
  font-size: var(--text-xs);
  font-weight: 600;
}

/* =========================================================
   Surface / panel
   ========================================================= */
.panel {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
}

.panel-flat {
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-4);
}

/* =========================================================
   Variant editor row (Add Product step 2 / Product Details)
   ========================================================= */
.variant-row {
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-4);
}

.variant-row__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-3);
}

.variant-row__title {
  font-weight: 700;
  font-size: var(--text-sm);
  color: var(--color-text-muted);
}

.variant-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--space-3);
}

@media (min-width: 560px) {
  .variant-grid { grid-template-columns: repeat(3, 1fr); }
}

/* =========================================================
   Table (Price History, desktop)
   ========================================================= */
.data-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  background: var(--color-surface);
}

.data-table {
  width: 100%;
  font-size: var(--text-sm);
}

.data-table th {
  text-align: left;
  font-size: var(--text-xs);
  text-transform: none;
  color: var(--color-text-muted);
  font-weight: 700;
  padding: var(--space-3) var(--space-4);
  background: var(--color-bg);
  border-bottom: 1px solid var(--color-border);
  white-space: nowrap;
}

.data-table td {
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--color-border);
  white-space: nowrap;
}

.data-table tr:last-child td {
  border-bottom: none;
}

.price-delta {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.price-delta.up { color: #3F6B46; }
.price-delta.down { color: #8A3F3F; }

/* History cards (mobile) */
.history-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-4);
}

.history-card__row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: var(--text-sm);
}

.history-card__row + .history-card__row {
  margin-top: var(--space-2);
}

/* =========================================================
   Modal / confirmation dialog
   ========================================================= */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: var(--color-overlay);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 100;
  padding: var(--space-4);
}

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

.modal {
  width: 100%;
  max-width: 420px;
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  box-shadow: var(--shadow-md);
}

.modal__title {
  margin-bottom: var(--space-2);
}

.modal__body {
  color: var(--color-text-muted);
  font-size: var(--text-sm);
  line-height: var(--leading-normal);
}

.modal__compare {
  margin: var(--space-4) 0;
  padding: var(--space-3) var(--space-4);
  background: var(--color-bg);
  border-radius: var(--radius-md);
}

.modal__compare-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: var(--text-sm);
}
.modal__compare-row + .modal__compare-row {
  margin-top: var(--space-2);
}

.modal__actions {
  display: flex;
  gap: var(--space-3);
  margin-top: var(--space-5);
}
.modal__actions .btn { flex: 1; }

/* =========================================================
   Empty / offline states
   ========================================================= */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: var(--space-10) var(--space-5);
  color: var(--color-text-muted);
}

.empty-state__icon {
  width: 48px;
  height: 48px;
  color: var(--color-secondary);
  margin-bottom: var(--space-4);
}

.empty-state__title {
  color: var(--color-text);
  font-weight: 700;
  margin-bottom: var(--space-1);
}

.offline-banner {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-4);
  background: var(--color-warning-bg);
  color: #8A6A2A;
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  font-weight: 600;
}

/* =========================================================
   Toast notifications
   ========================================================= */
.toast-stack {
  position: fixed;
  left: 50%;
  bottom: calc(var(--bottom-nav-height) + var(--safe-bottom) + var(--space-4));
  transform: translateX(-50%);
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  width: calc(100% - var(--space-8));
  max-width: 400px;
}

.toast {
  background: var(--color-text);
  color: #FFFFFF;
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  font-weight: 600;
  box-shadow: var(--shadow-md);
  text-align: center;
}

.toast.success { background: #3F6B46; }
.toast.error { background: #8A3F3F; }

/* =========================================================
   Steps indicator (Add Product)
   ========================================================= */
.steps {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin-bottom: var(--space-5);
}

.steps__item {
  flex: 1;
  height: 4px;
  border-radius: var(--radius-full);
  background: var(--color-border);
}

.steps__item.is-active,
.steps__item.is-done {
  background: var(--color-primary);
}

/* =========================================================
   Favorite toggle
   ========================================================= */
.fav-toggle {
  color: var(--color-text-muted);
}
.fav-toggle.is-active {
  color: var(--color-warning);
}

/* =========================================================
   Install prompt banner
   ========================================================= */
.install-banner {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-4);
  background: var(--color-primary-light);
  border-radius: var(--radius-lg);
}

.install-banner__text {
  flex: 1;
}

.install-banner__title {
  font-weight: 700;
  font-size: var(--text-sm);
  color: var(--color-text);
}

.install-banner__subtitle {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
}
