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

html {
  touch-action: manipulation;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  font-family: "IBM Plex Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  overscroll-behavior: none;
}

.precivo-app-shell {
  padding-top: env(safe-area-inset-top, 0px);
  padding-left: env(safe-area-inset-left, 0px);
  padding-right: env(safe-area-inset-right, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

.precivo-app-header {
  top: 0;
}

.precivo-mobile-tabs {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.5rem;
  padding: 0.625rem 1rem 0.75rem;
  border-top: 1px solid #e4e4e7;
}

.precivo-mobile-tab {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 2.25rem;
  padding: 0.375rem 0.5rem;
  font-size: 0.75rem;
  font-weight: 600;
  text-align: center;
  text-decoration: none;
  color: #71717a;
  border: 1px solid #e4e4e7;
  background: #fff;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.precivo-mobile-tab.is-active {
  color: #09090b;
  border-color: #09090b;
  background: #f4f4f5;
}

code, .font-mono {
  font-family: "IBM Plex Mono", Menlo, Monaco, Consolas, monospace;
}

.font-display {
  font-family: "Cabinet Grotesk", "IBM Plex Sans", sans-serif;
}

::selection {
  background: #09090b;
  color: #fff;
}

.grid-bg {
  background-image:
    linear-gradient(#e4e4e7 1px, transparent 1px),
    linear-gradient(90deg, #e4e4e7 1px, transparent 1px);
  background-size: 32px 32px;
}

/* Form controls */
.precivo-input {
  display: block;
  width: 100%;
  max-width: 100%;
  padding: 0.5rem 0.75rem;
  border: 1px solid #e4e4e7;
  border-radius: 0;
  font-size: 0.875rem;
  line-height: 1.25rem;
  color: #09090b;
  background: #fff;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.precivo-input:focus {
  outline: none;
  border-color: #09090b;
  box-shadow: 0 0 0 1px #09090b;
}

.precivo-checkbox {
  width: 1rem;
  height: 1rem;
  accent-color: #09090b;
  border-radius: 0;
  cursor: pointer;
}

.precivo-btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.5rem 1rem;
  border: none;
  border-radius: 0;
  font-size: 0.875rem;
  font-weight: 500;
  color: #fff;
  background: #09090b;
  cursor: pointer;
  transition: background 0.15s;
}

.precivo-btn-primary:hover {
  background: #27272a;
}

.precivo-btn-outline {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.5rem 1rem;
  border: 1px solid #e4e4e7;
  border-radius: 0;
  font-size: 0.875rem;
  font-weight: 500;
  color: #09090b;
  background: #fff;
  cursor: pointer;
  transition: background 0.15s;
}

.precivo-btn-outline:hover {
  background: #f4f4f5;
}

.precivo-badge-green {
  display: inline-flex;
  align-items: center;
  padding: 0.125rem 0.5rem;
  font-size: 0.75rem;
  font-weight: 500;
  color: #fff;
  background: #16a34a;
  border-radius: 0;
}

.precivo-table {
  border-collapse: collapse;
}

.precivo-table th,
.precivo-table td {
  vertical-align: middle;
}

.store-logo {
  display: inline-block;
  object-fit: contain;
  border: 1px solid #e4e4e7;
  background: #fff;
  padding: 2px;
  flex-shrink: 0;
}

.store-logo-fallback {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: #f4f4f5;
  border: 1px solid #e4e4e7;
}

.product-thumb {
  background: #fff;
}

.product-thumb-empty {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: #f4f4f5;
  border: 1px solid #e4e4e7;
}

.store-logo-lg {
  width: 3rem;
  height: 3rem;
}

.btn-danger-text {
  color: #71717a;
}

.btn-danger-text:hover {
  color: #dc2626;
}

.table-icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  color: #71717a;
  border: 1px solid transparent;
  background: transparent;
  cursor: pointer;
  transition: color 0.15s ease, background 0.15s ease, border-color 0.15s ease;
}

.table-icon-btn:hover {
  color: #09090b;
  background: #f4f4f5;
  border-color: #e4e4e7;
}

.table-icon-btn-danger:hover {
  color: #dc2626;
  background: #fef2f2;
  border-color: #fecaca;
}

.product-row-removing {
  opacity: 0;
  transform: translateX(-6px);
  transition: opacity 0.18s ease, transform 0.18s ease;
}

.detail-store-row.is-active {
  background: #f4f4f5;
}

.compare-card-removing {
  opacity: 0;
  transform: translateY(-6px);
  transition: opacity 0.18s ease, transform 0.18s ease;
}

.precivo-table tbody tr {
  transition: opacity 0.18s ease, transform 0.18s ease;
}

/* Modals */
.precivo-modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.precivo-modal.hidden {
  display: none;
}

.precivo-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
}

.precivo-modal-panel {
  position: relative;
  z-index: 1;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  background: #fff;
  border: 1px solid #e4e4e7;
  padding: 1.5rem;
}

/* Toast */
.precivo-toast {
  pointer-events: auto;
  padding: 0.75rem 1rem;
  background: #09090b;
  color: #fff;
  font-size: 0.875rem;
  border: 1px solid #09090b;
  animation: precivo-toast-in 0.2s ease;
}

@keyframes precivo-toast-in {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (max-width: 899px) {
  .precivo-app-header .max-w-7xl {
    min-height: 4rem;
    height: auto;
    padding-top: 0.25rem;
    padding-bottom: 0.25rem;
  }

  #price-record-form input[type="date"],
  #price-record-form input[type="number"] {
    width: 100%;
    max-width: 100%;
    display: block;
    min-height: 48px;
  }

  #price-record-form input[type="date"] {
    -webkit-appearance: none;
    appearance: none;
  }
}

/* User menu dropdown */
.user-menu-dropdown {
  position: absolute;
  right: 0;
  top: calc(100% + 0.5rem);
  min-width: 12rem;
  background: #fff;
  border: 1px solid #e4e4e7;
  box-shadow: 0 10px 30px rgba(9, 9, 11, 0.08);
  z-index: 50;
}

.user-menu-item {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  padding: 0.625rem 0.875rem;
  font-size: 0.875rem;
  color: #09090b;
  text-decoration: none;
  transition: background 0.15s ease;
}

.user-menu-item:hover,
.user-menu-item.is-active {
  background: #f4f4f5;
}

.user-menu-item-danger {
  color: #dc2626;
  border-top: 1px solid #e4e4e7;
}

.user-menu-item-danger:hover {
  background: #fef2f2;
}

/* Products view toggle */
.products-view-toggle {
  display: inline-flex;
  border: 1px solid #e4e4e7;
  height: 2.5rem;
}

.products-view-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.5rem;
  height: 100%;
  background: #fff;
  border: none;
  color: #71717a;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.products-view-btn + .products-view-btn {
  border-left: 1px solid #e4e4e7;
}

.products-view-btn.is-active {
  background: #09090b;
  color: #fff;
}

.products-view-btn:hover:not(.is-active) {
  background: #f4f4f5;
  color: #09090b;
}

/* Products grid */
.products-grid {
  display: grid;
  grid-template-columns: repeat(1, minmax(0, 1fr));
  gap: 1rem;
}

@media (min-width: 640px) {
  .products-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (min-width: 1024px) {
  .products-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (min-width: 1280px) {
  .products-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

.product-grid-card {
  border: 1px solid #e4e4e7;
  display: flex;
  flex-direction: column;
  background: #fff;
}

.product-grid-card-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  text-align: left;
  padding: 1rem;
  background: transparent;
  border: none;
  cursor: pointer;
  color: inherit;
  font: inherit;
}

.product-grid-card-main:hover {
  background: rgba(244, 244, 245, 0.5);
}

.product-grid-card-image {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 6rem;
  margin-bottom: 0.75rem;
}

.product-grid-card-prices {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.5rem;
}

.product-grid-card-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.25rem;
  padding: 0.5rem 0.75rem;
  border-top: 1px solid #e4e4e7;
  background: #fafafa;
}

#bar-chart-wrap canvas {
  width: 100% !important;
  height: 100% !important;
}

/* Dashboard product showcase */
.dashboard-products-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
}

@media (min-width: 768px) {
  .dashboard-products-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

.dashboard-product-card {
  display: flex;
  flex-direction: column;
  text-align: left;
  border: 1px solid #e4e4e7;
  background: #fff;
  padding: 0;
  cursor: pointer;
  color: inherit;
  font: inherit;
  transition: background 0.15s ease;
}

.dashboard-product-card:hover {
  background: rgba(244, 244, 245, 0.6);
}

.dashboard-product-card-image {
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #fafafa;
  border-bottom: 1px solid #e4e4e7;
  padding: 1rem;
}

.dashboard-product-photo {
  width: 100%;
  height: 100%;
  max-height: 8rem;
  object-fit: contain;
}

.dashboard-product-photo-empty {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: #f4f4f5;
  border: 1px solid #e4e4e7;
}

.dashboard-product-card-body {
  padding: 0.875rem;
}

.dashboard-product-card-price {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.375rem;
}

/* Dashboard top discounts */
.dashboard-discounts-list {
  display: flex;
  flex-direction: column;
}

.dashboard-discount-card {
  display: flex;
  align-items: flex-start;
  gap: 0.875rem;
  width: 100%;
  padding: 1rem;
  border-bottom: 1px solid #e4e4e7;
  text-align: left;
  background: transparent;
  border-left: none;
  border-right: none;
  border-top: none;
  cursor: pointer;
  color: inherit;
  font: inherit;
  transition: background 0.15s ease;
}

.dashboard-discount-card:last-child {
  border-bottom: none;
}

.dashboard-discount-card:hover {
  background: rgba(244, 244, 245, 0.6);
}

.dashboard-discount-photo-wrap {
  flex-shrink: 0;
}

.dashboard-discount-photo {
  width: 4.5rem;
  height: 4.5rem;
  object-fit: contain;
  border: 1px solid #e4e4e7;
  background: #fff;
  padding: 0.25rem;
  display: block;
}

.dashboard-discount-photo-empty {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: #f4f4f5;
}

.dashboard-discount-body {
  flex: 1;
  min-width: 0;
}
