/* Design System Base — Reset, Typography, Layout & State Utilities */

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

  html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
  }

  html.is-clipped {
    overflow: hidden;
  }

  body {
    margin: 0;
    font-family: var(--font-sans);
    font-size: 1rem;
    line-height: 1.5;
    color: var(--text-primary);
    background-color: var(--bg-page);
    min-height: 100vh;
  }

  a {
    color: var(--accent);
    text-decoration: none;
    transition: color 0.15s ease;

    &:hover {
      color: var(--accent-hover);
    }
  }

  h1, h2, h3, h4, h5, h6, p, ul, ol, dl, figure, blockquote {
    margin: 0;
    padding: 0;
  }

  button, input, select, textarea {
    font-family: inherit;
    margin: 0;
  }

  /* Inline SVG Icon Normalization */
  svg.fa-icon, .fa-icon {
    width: 1em;
    height: 1em;
    display: inline-block;
    vertical-align: -0.125em;
    fill: currentColor;
    flex-shrink: 0;
  }

  /* Layout Containers & Grids */
  .ui-container {
    width: 100%;
    margin-inline: auto;
    padding-inline: 0.75rem;
  }
  @media (min-width: 1024px) {
    .ui-container {
      max-width: 960px;
    }
  }
  @media (min-width: 1216px) {
    .ui-container {
      max-width: 1152px;
    }
  }
  @media (min-width: 1408px) {
    .ui-container {
      max-width: 1344px;
    }
  }

  .ui-stack {
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
  }

  .ui-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-3);
  }

  .ui-between {
    justify-content: space-between;
  }

  .ui-py-4 {
    padding-block: 1.5rem; /* 24px, matches Bulma my-4 */
  }

  /* Micro Flex & Spacing Utilities */
  .ui-gap-xs { gap: 2px; }
  .ui-gap-sm { gap: 4px; }
  .ui-gap-md { gap: 6px; }
  .ui-gap-lg { gap: 8px; }
  .ui-gap-10 { gap: 10px; }
  .ui-nowrap { flex-wrap: nowrap; }
  .ui-flex-1 { flex: 1; min-width: 0; }
  .ui-items-start { align-items: flex-start; }

  .ui-grid-auto {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 1rem;
  }

  .ui-divider {
    border: none;
    border-top: 1px solid var(--border-subtle);
    margin-block: 0.75rem;
  }

  .ui-list-bullet {
    list-style: disc;
    padding-left: 1.25rem;
    font-size: 0.92rem;
    line-height: 1.65;
  }

  .ui-grid {
    display: grid;
    gap: var(--space-4);
    grid-template-columns: 1fr;

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

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

  .ui-grid-2 {
    display: grid;
    gap: var(--space-4);
    grid-template-columns: 1fr;

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

  /* Typography Helpers */
  .ui-h1 {
    font-size: 1.75rem;
    font-weight: 800;
    line-height: 1.2;
    letter-spacing: -0.02em;
    color: var(--text-primary);
    margin-bottom: var(--space-2);
  }

  .ui-h2 {
    font-size: 1.25rem;
    font-weight: 700;
    line-height: 1.3;
    color: var(--text-primary);
    margin-bottom: var(--space-3);
  }

  .ui-h3 {
    font-size: 1rem;
    font-weight: 700;
    line-height: 1.35;
    color: var(--text-primary);
    margin-bottom: var(--space-2);
  }

  :is(.ui-text-primary, .text-primary) {
    color: var(--text-primary);
  }

  :is(.ui-text-secondary, .text-secondary) {
    color: var(--text-secondary);
  }

  :is(.ui-text-muted, .text-muted) {
    color: var(--text-muted);
    font-size: 0.875rem;
  }

  :is(.ui-text-subtle, .text-subtle) {
    color: var(--text-subtle);
  }

  :is(.ui-price, .price) {
    font-weight: 800;
    color: var(--accent);
  }

  /* Universal JS State Helpers */
  .is-hidden {
    display: none !important;
  }

  /* Global Navbar, Main & Footer Shell */
  .nav-brand-row {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-inline: 0;
  }

  .nav-brand-link {
    color: #2563eb;
    gap: 0.35rem;
  }

  .nav-search-slot {
    flex: 1;
    max-width: 440px;
    margin: 0 1rem;
  }

  .nav-search-form {
    width: 100%;
  }

  .nav-search-input {
    background-color: #f1f5f9;
    border-color: #cbd5e1;
    width: 100%;
  }

  .nav-icon-btn {
    position: relative;
  }

  /* Intentionally non-!important so Stimulus style.display = "inline-flex" overrides it */
  .nav-fav-hidden {
    display: none;
  }

  .nav-heart-icon {
    color: #ef4444;
  }

  .nav-count-badge {
    position: absolute;
    top: -6px;
    right: -6px;
    font-size: 0.65rem;
    height: 1.25rem;
    min-width: 1.25rem;
    padding: 0 4px;
    border: 2px solid var(--bg-surface);
    font-weight: bold;
  }

  .nav-avatar-sm {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    object-fit: cover;
  }

  .nav-logout-btn {
    border: none;
    background: transparent;
    width: 100%;
    text-align: left;
    cursor: pointer;
  }

  .nav-signin-btn {
    color: var(--text-primary) !important;
    border-color: var(--border-strong) !important;
    background-color: transparent !important;
    font-weight: 600;
  }

  .site-main {
    flex: 1;
  }

  .site-flash {
    border-radius: 8px;
  }

  .site-footer {
    border-top: 1px solid var(--border-default);
    padding: 0.6rem 0;
    margin-top: auto;
  }

  .site-footer-row {
    gap: 0.5rem;
    font-size: 0.75rem;
    line-height: 1.4;
  }

  .site-footer-group {
    gap: 0.6rem;
  }

  .site-footer-link {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
  }

  /* ========================================================================
     Bulma-Free Utility & Grid Layer (Spacing, Flex, Typography, Columns)
     ======================================================================== */

  /* Spacing: m*-0..6 and p*-0..6 */
  .m-0 { margin: 0 !important; }
  .mt-0, .my-0 { margin-top: 0 !important; }
  .mb-0, .my-0 { margin-bottom: 0 !important; }
  .ml-0, .mx-0 { margin-left: 0 !important; }
  .mr-0, .mx-0 { margin-right: 0 !important; }

  .m-1 { margin: 0.25rem !important; }
  .mt-1, .my-1 { margin-top: 0.25rem !important; }
  .mb-1, .my-1 { margin-bottom: 0.25rem !important; }
  .ml-1, .mx-1 { margin-left: 0.25rem !important; }
  .mr-1, .mx-1 { margin-right: 0.25rem !important; }

  .m-2 { margin: 0.5rem !important; }
  .mt-2, .my-2 { margin-top: 0.5rem !important; }
  .mb-2, .my-2 { margin-bottom: 0.5rem !important; }
  .ml-2, .mx-2 { margin-left: 0.5rem !important; }
  .mr-2, .mx-2 { margin-right: 0.5rem !important; }

  .m-3 { margin: 0.75rem !important; }
  .mt-3, .my-3 { margin-top: 0.75rem !important; }
  .mb-3, .my-3 { margin-bottom: 0.75rem !important; }
  .ml-3, .mx-3 { margin-left: 0.75rem !important; }
  .mr-3, .mx-3 { margin-right: 0.75rem !important; }

  .m-4 { margin: 1rem !important; }
  .mt-4, .my-4 { margin-top: 1rem !important; }
  .mb-4, .my-4 { margin-bottom: 1rem !important; }
  .ml-4, .mx-4 { margin-left: 1rem !important; }
  .mr-4, .mx-4 { margin-right: 1rem !important; }

  .m-5 { margin: 1.5rem !important; }
  .mt-5, .my-5 { margin-top: 1.5rem !important; }
  .mb-5, .my-5 { margin-bottom: 1.5rem !important; }
  .ml-5, .mx-5 { margin-left: 1.5rem !important; }
  .mr-5, .mx-5 { margin-right: 1.5rem !important; }

  .m-6 { margin: 3rem !important; }
  .mt-6, .my-6 { margin-top: 3rem !important; }
  .mb-6, .my-6 { margin-bottom: 3rem !important; }

  .p-0 { padding: 0 !important; }
  .pt-0, .py-0 { padding-top: 0 !important; }
  .pb-0, .py-0 { padding-bottom: 0 !important; }
  .pl-0, .px-0 { padding-left: 0 !important; }
  .pr-0, .px-0 { padding-right: 0 !important; }

  .p-1 { padding: 0.25rem !important; }
  .pt-1, .py-1 { padding-top: 0.25rem !important; }
  .pb-1, .py-1 { padding-bottom: 0.25rem !important; }
  .pl-1, .px-1 { padding-left: 0.25rem !important; }
  .pr-1, .px-1 { padding-right: 0.25rem !important; }

  .p-2 { padding: 0.5rem !important; }
  .pt-2, .py-2 { padding-top: 0.5rem !important; }
  .pb-2, .py-2 { padding-bottom: 0.5rem !important; }
  .pl-2, .px-2 { padding-left: 0.5rem !important; }
  .pr-2, .px-2 { padding-right: 0.5rem !important; }

  .p-3 { padding: 0.75rem !important; }
  .pt-3, .py-3 { padding-top: 0.75rem !important; }
  .pb-3, .py-3 { padding-bottom: 0.75rem !important; }
  .pl-3, .px-3 { padding-left: 0.75rem !important; }
  .pr-3, .px-3 { padding-right: 0.75rem !important; }

  .p-4 { padding: 1rem !important; }
  .pt-4, .py-4 { padding-top: 1rem !important; }
  .pb-4, .py-4 { padding-bottom: 1rem !important; }
  .pl-4, .px-4 { padding-left: 1rem !important; }
  .pr-4, .px-4 { padding-right: 1rem !important; }

  .p-5 { padding: 1.5rem !important; }
  .pt-5, .py-5 { padding-top: 1.5rem !important; }
  .pb-5, .py-5 { padding-bottom: 1.5rem !important; }
  .pl-5, .px-5 { padding-left: 1.5rem !important; }
  .pr-5, .px-5 { padding-right: 1.5rem !important; }

  .p-6 { padding: 3rem !important; }

  @media (min-width: 769px) {
    .mr-2-tablet { margin-right: 0.5rem !important; }
  }

  /* Flex, Display & Visibility */
  .is-flex { display: flex !important; }
  .is-inline-flex { display: inline-flex !important; }
  .is-block { display: block !important; }
  .is-hidden { display: none !important; }
  .is-flex-direction-column { flex-direction: column !important; }
  .is-flex-wrap-wrap { flex-wrap: wrap !important; }
  .is-flex-grow-1 { flex-grow: 1 !important; }
  .is-align-items-center { align-items: center !important; }
  .is-align-items-start { align-items: flex-start !important; }
  .is-justify-content-between,
  .is-justify-content-space-between { justify-content: space-between !important; }
  .is-justify-content-center { justify-content: center !important; }
  .is-justify-content-flex-end { justify-content: flex-end !important; }
  .is-clickable { cursor: pointer !important; }

  @media (max-width: 768px) {
    .is-hidden-mobile { display: none !important; }
    .is-size-5-mobile { font-size: 1.25rem !important; }
    .has-text-centered-mobile { text-align: center !important; }
  }

  @media (min-width: 769px) {
    .is-hidden-tablet { display: none !important; }
    .is-size-4-tablet { font-size: 1.5rem !important; }
  }

  /* Typography & Semantic Colors */
  .title {
    color: var(--text-primary);
    font-size: 2rem;
    font-weight: 700;
    line-height: 1.125;
    margin-bottom: 1.5rem;
  }
  .is-size-3, .title.is-3 { font-size: 2rem !important; }
  .is-size-4, .title.is-4 { font-size: 1.5rem !important; }
  .is-size-5, .title.is-5 { font-size: 1.25rem !important; }
  .is-size-6 { font-size: 1rem !important; }
  .is-size-7 { font-size: 0.75rem !important; }

  .has-text-weight-bold { font-weight: 700 !important; }
  .has-text-weight-semibold { font-weight: 600 !important; }
  .has-text-weight-medium { font-weight: 500 !important; }
  .is-family-monospace { font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace !important; }
  .has-text-centered { text-align: center !important; }
  .has-text-right { text-align: right !important; }
  .has-text-danger { color: var(--danger) !important; }
  .has-text-warning { color: var(--warning) !important; }
  .has-text-white { color: #ffffff !important; }
  .has-background-white { background-color: var(--bg-surface); }

  /* Container & Columns Grid */
  .container {
    flex-grow: 1;
    margin: 0 auto;
    position: relative;
    width: 100%;
  }
  @media (min-width: 1024px) {
    .container { max-width: 960px; }
    .container.is-max-desktop { max-width: 960px !important; }
  }
  @media (min-width: 1216px) {
    .container:not(.is-max-desktop) { max-width: 1152px; }
  }
  @media (min-width: 1408px) {
    .container:not(.is-max-desktop) { max-width: 1344px; }
  }
  .container.is-fluid {
    max-width: none !important;
    width: 100%;
  }

  .columns {
    display: flex;
    flex-wrap: wrap;
    margin-left: -0.75rem;
    margin-right: -0.75rem;
    margin-top: -0.75rem;

    &:last-child { margin-bottom: -0.75rem; }
    &:not(:last-child) { margin-bottom: 0.75rem; }
    &.is-multiline { flex-wrap: wrap; }
    &.is-centered { justify-content: center; }
    &.is-gapless {
      margin: 0 !important;
      & > .column { margin: 0; padding: 0 !important; }
    }
  }

  .column {
    display: block;
    flex-basis: 0;
    flex-grow: 1;
    flex-shrink: 1;
    padding: 0.75rem;
  }

  @media (max-width: 768px) {
    .column { flex: none; width: 100%; }
  }

  @media (min-width: 769px) {
    .column.is-narrow { flex: none; width: unset; }
    .column.is-3 { flex: none; width: 25%; }
    .column.is-4 { flex: none; width: 33.3333%; }
    .column.is-5-tablet { flex: none; width: 41.6667%; }
    .column.is-6, .column.is-6-tablet { flex: none; width: 50%; }
    .column.is-7-tablet { flex: none; width: 58.3333%; }
    .column.is-8-tablet { flex: none; width: 66.6667%; }
    .column.is-12 { flex: none; width: 100%; }
  }

  @media (min-width: 1024px) {
    .column.is-3-desktop { flex: none; width: 25%; }
    .column.is-4-desktop { flex: none; width: 33.3333%; }
    .column.is-6-desktop { flex: none; width: 50%; }
    .column.is-7-desktop { flex: none; width: 58.3333%; }
  }
