/* ============================================================
   Layout
   ============================================================ */

/* Span full width and clear the fixed nav bar */
body[data-sidebar-layout] > main {
  grid-column: 1 / -1;
  padding-top: 4rem;
}

.hero h1 {
  text-align: center;
}

.hero p {
  margin-bottom: 2em;
}

hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 1.5rem 0;
}

[hidden] {
  display: none !important;
}


/* ============================================================
   Navigation
   ============================================================ */

.site-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1.5rem;
  border-bottom: 1px solid var(--border);
}

.site-nav-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: 0.75rem;
  padding-bottom: 0.75rem;
}

.site-nav-brand {
  font-weight: bold;
  text-decoration: none;
}

.site-nav small {
  color: var(--color-muted, #888);
  font-size: 0.8rem;
}

/* Public nav (logged-out): always visible inline */
.site-nav-links {
  display: flex;
  gap: 1.5rem;
  list-style: none;
  margin: 0;
  padding: 0;
}

/* Hamburger toggle button — shown only on mobile */
.site-nav-toggle {
  list-style: none;
  cursor: pointer;
  padding: 0.3rem 0.6rem;
  font-size: 1.25rem;
  line-height: 1;
  border: 1px solid var(--border);
  border-radius: var(--radius-small, 4px);
  user-select: none;
  background: none;
}

.site-nav-toggle::-webkit-details-marker,
.site-nav-toggle::marker {
  display: none;
}

/* Mobile: full-width dropdown panel below the nav bar */
.site-nav-mobile ul {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--background);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-medium, 0 4px 8px rgba(0, 0, 0, 0.1));
  list-style: none;
  margin: 0;
  padding: 0;
  z-index: 10;
}

.site-nav-mobile ul li {
  border-bottom: 1px solid var(--border);
}

.site-nav-mobile ul li:last-child {
  border-bottom: none;
}

.site-nav-mobile ul li a,
.site-nav-mobile ul li small {
  display: block;
  padding: 0.75rem 1.5rem;
}

/* Desktop: revert to inline horizontal nav, hide hamburger */
@media (min-width: 640px) {
  .hide-desktop {
    display: none;
  }

  .site-nav-toggle {
    display: none;
  }

  .site-nav-mobile > ul {
    display: flex;
    position: static;
    background: none;
    border: none;
    box-shadow: none;
    gap: 1.5rem;
    flex-direction: row;
    padding: 0;
  }

  .site-nav-mobile ul li {
    border-bottom: none;
  }

  .site-nav-mobile ul li a,
  .site-nav-mobile ul li small {
    display: inline;
    padding: 0;
  }
}


/* ============================================================
   Flash notifications
   ============================================================ */

@keyframes flash-dismiss {
  0%,
  75% {
    opacity: 1;
    max-height: 10em;
  }
  100% {
    opacity: 0;
    max-height: 0;
    overflow: hidden;
  }
}

.flash {
  position: fixed;
  top: 1rem;
  right: 1rem;
  padding: 0.75rem 1rem;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  min-width: 280px;
  max-width: 400px;
  z-index: 50;
  animation: flash-dismiss 3s ease forwards;
}

.flash-info {
  background: #e0f0ff;
  border: 1px solid #90c0f0;
  color: #1a4a7a;
}

.flash-error {
  background: #fde8e8;
  border: 1px solid #f0a0a0;
  color: #7a1a1a;
}

.flash button {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1rem;
  opacity: 0.6;
}

.flash button:hover {
  opacity: 1;
}


/* ============================================================
   Forms
   ============================================================ */

/* Space between the last field and the submit button */
form button[data-variant],
form button[type="submit"] {
  margin-top: 1.5rem;
}

.field-error {
  color: var(--color-error, #c00);
  font-size: 0.875rem;
  margin-top: 0.25rem;
}

.form-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 1.5rem;
}

.btn-secondary {
  display: inline-block;
  padding: 0.5rem 1rem;
  border: 1px solid currentColor;
  border-radius: 4px;
  text-decoration: none;
  color: inherit;
  background: transparent;
  cursor: pointer;
  font-size: inherit;
}

/* Centered, constrained layout for auth pages (login, settings, register) */
.auth-form {
  max-width: 28rem;
  margin: 4rem auto;
  padding-inline: 1rem;
}

.resend-hint {
  margin-top: 2rem;
  font-size: 0.875rem;
}


/* ============================================================
   Tables
   ============================================================ */

/* Unstyled button used as a sortable column header */
.sort-btn {
  background: none;
  border: none;
  cursor: pointer;
  font: inherit;
  color: inherit;
  padding: 0;
}

.row-clickable {
  cursor: pointer;
}

.header-with-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1.5rem;
  margin-bottom: 1rem;
}

.table-actions {
  white-space: nowrap;
}

.table-actions-inner {
  display: flex;
  gap: 1rem;
}

td.price {
  white-space: nowrap;
}


/* ============================================================
   Cart
   ============================================================ */

/* Cart icon link with floating badge in the nav */
.cart-icon-link {
  position: relative;
  text-decoration: none;
  font-size: 1.5rem;
  line-height: 1;
}

.cart-badge {
  position: absolute;
  top: -0.4rem;
  right: -0.75rem;
  background: #c00;
  color: white;
  font-size: 0.65rem;
  border-radius: 9999px;
  min-width: 1.25em;
  height: 1.25em;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 0.2em;
  z-index: 10;
}

/* "In cart" badge shown on search results */
.in-cart-badge {
  font-size: 0.75rem;
  padding: 0.15rem 0.5rem;
  border-radius: 9999px;
  background: #d4edda;
  color: #155724;
  white-space: nowrap;
}

/* Cart page header row */
.cart-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.cart-totals {
  margin: 0.25rem 0 0;
  color: var(--color-muted, #666);
}

.cart-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  align-items: center;
}

.cart-action {
  display: inline-block;
  padding: 0.4rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--border-radius, 4px);
  background: none;
  cursor: pointer;
  font: inherit;
  font-size: 0.875rem;
  text-decoration: none;
  color: inherit;
  white-space: nowrap;
}

.cart-action:hover {
  background: var(--color-bg-alt, #f5f5f5);
}

/* Cart table column sizing */
.cart-table th:first-child,
.cart-table td:first-child {
  width: 2rem;
  padding-right: 0;
}

.cart-table th:last-child,
.cart-table td:last-child {
  width: 2rem;
  padding-left: 0;
}

.cart-table td:nth-child(2) {
  min-width: 10rem;
}

/* Cart item controls */
.remove-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--color-muted, #999);
  font-size: 1rem;
  padding: 0.25rem 0.5rem;
  line-height: 1;
}

.remove-btn:hover {
  color: var(--color-error, #c00);
}

.qty-input {
  width: 4rem;
}

.subtotal-label {
  text-align: right;
}

.subtotal-amount {
  white-space: nowrap;
}

.import-action {
  margin-top: 1rem;
}


/* ============================================================
   Grocery search
   ============================================================ */

/* Two-column layout: store/item picker on the left, results on the right */
.grocery-layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2rem;
  margin-bottom: 2rem;
  align-items: start;
}

.store-list,
.item-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.store-list li {
  padding: 0.25rem 0;
}

.store-list label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
}

.item-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.4rem 0;
  border-bottom: 1px solid var(--border);
}

.item-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.list-item-checked td {
  opacity: 0.4;
  text-decoration: line-through;
}


/* ============================================================
   Utilities
   ============================================================ */

.icon {
  display: inline-block;
  width: 1rem;
  height: 1rem;
  vertical-align: middle;
}

.spinner {
  display: inline-block;
  width: 0.75rem;
  height: 0.75rem;
  vertical-align: middle;
  margin-left: 0.25rem;
  animation: spin 1s linear infinite;
}

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


/* ============================================================
   Sale detail page
   ============================================================ */

.sale-detail-back {
  margin-bottom: 1.5rem;
}

.sale-detail-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1.5rem;
  color: var(--color-muted, #666);
  margin-bottom: 1.5rem;
  font-size: 0.9rem;
}

.sale-detail-meta span + span::before {
  content: "·";
  margin-right: 1.5rem;
}

.sale-card {
  background: var(--color-bg-alt, #f9f9f9);
  border: 1px solid var(--border);
  border-radius: var(--border-radius, 4px);
  padding: 1.25rem 1.5rem;
  margin-bottom: 2rem;
  display: inline-block;
}

.sale-card-price {
  font-size: 2rem;
  font-weight: bold;
  margin-bottom: 0.4rem;
}

.sale-card-details {
  color: var(--color-muted, #666);
  font-size: 0.9rem;
}

.price-history-chart {
  overflow-x: auto;
  margin-bottom: 1.5rem;
}

.price-history-chart svg {
  display: block;
  max-width: 100%;
  height: auto;
}


/* ============================================================
   Responsive — mobile (max-width: 640px)
   ============================================================ */

@media (max-width: 640px) {
  /* Grocery: switch search layout to single column */
  .grocery-layout {
    grid-template-columns: 1fr;
  }

  /* Hide elements that don't fit on narrow screens */
  .hide-mobile {
    display: none;
  }


  /* Compact table text */
  table {
    font-size: 0.85rem;
  }

  /* Allow header cells to wrap rather than overflow */
  th {
    white-space: normal;
  }
}
