/* Design System Components — 1:1 Unified Scale */

/* ========================================================================
   1. Cards & Containers (6, 10, 12, 14, 16px)
   ======================================================================== */

  /* General Box (matches Bulma .box: 6px radius, 1.25rem padding) */
  .ui-box {
    background-color: var(--bg-surface);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-sm); /* 6px */
    padding: 1.25rem;
    box-shadow: var(--shadow-sm);
    color: var(--text-primary);
  }

  /* Compact Box (matches show page side boxes: 12px radius, 1rem padding) */
  .ui-box--compact {
    border-radius: var(--radius-lg); /* 12px */
    padding: 1rem;
  }

  /* Bento Shelf Container (matches .bento-box: 14px radius, 12px 14px padding) */
  .ui-bento-container {
    background-color: var(--bg-surface);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-xl); /* 14px */
    padding: 12px 14px;
    box-shadow: var(--shadow-sm);
  }

  /* Listing Card (matches .re-card and .item-card: 12px radius, tight padding) */
  .ui-listing-card {
    background-color: var(--bg-surface);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-lg); /* 12px */
    overflow: hidden;
    box-shadow: var(--shadow-sm);
    display: flex;
    flex-direction: column;
    transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;

    &:hover {
      transform: translateY(-2px);
      box-shadow: var(--shadow-md);
      border-color: var(--border-strong);
    }

    &.is-highlighted {
      border-color: var(--accent);
      box-shadow: 0 0 0 2px var(--accent);
    }

    &.is-viewed {
      opacity: 0.78;
    }
  }

  /* Listing Media Box (matches .re-card-media: 145px height) */
  .ui-listing-media {
    position: relative;
    height: 145px;
    background-color: var(--bg-media);
    overflow: hidden;

    & img {
      width: 100%;
      height: 100%;
      object-fit: cover;
      display: block;
    }
  }

  /* Media Placeholder (matches .re-card-placeholder / .deal-card-placeholder) */
  .ui-placeholder {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    background-color: var(--bg-media);
    color: var(--text-muted);
    user-select: none;

    & i, & svg {
      font-size: 1.8rem;
      margin-bottom: 2px;
      color: var(--text-subtle);
      opacity: 0.65;
    }

    & span {
      font-size: 0.78rem;
      font-weight: 600;
      color: var(--text-muted);
      opacity: 0.75;
    }
  }

  /* Listing Body (matches .re-card-body: padding: 0.5rem 0.65rem) */
  .ui-listing-body {
    padding: 0.5rem 0.65rem;
    display: flex;
    flex-direction: column;
    flex: 1;
  }

  .ui-listing-price-row {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    margin-bottom: 0.25rem;
  }

  .ui-listing-price {
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--text-primary);
  }

  html[data-theme="dark"] .ui-listing-price {
    color: var(--accent);
  }

  .ui-listing-title {
    font-size: 0.85rem;
    line-height: 1.25;
    font-weight: 600;
    margin-bottom: 0.25rem;
    color: var(--text-primary);
    display: -webkit-box;
    -webkit-line-clamp: 1;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }

  .ui-listing-specs {
    font-size: 0.75rem;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.35rem;
    margin-bottom: 0.35rem;
  }

  .ui-listing-footer {
    border-top: 1px solid var(--border-subtle);
    font-size: 0.78rem;
    color: var(--text-muted);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 6px;
    margin-top: auto;
    padding-top: 0.25rem;
  }

  /* ========================================================================
     2. Buttons (Zero-BEM Compound Inheritance)
     ======================================================================== */

  :is(.btn, .ui-btn, .btn-primary, .ui-btn--primary, .btn-telegram, .ui-btn--telegram, .btn-channel, .ui-btn--channel, .btn-soft, .ui-btn--soft, .btn-ghost, .ui-btn--ghost, .btn-danger, .ui-btn--danger) {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: calc(0.5em - 1px) 1em;
    min-height: 2.25em;
    border-radius: var(--radius-sm); /* 6px */
    border: 1px solid var(--border-default);
    background-color: var(--bg-surface);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.875rem;
    font-weight: 500;
    line-height: 1.5;
    cursor: pointer;
    text-decoration: none;
    white-space: nowrap;
    transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
    -webkit-tap-highlight-color: transparent;

    &:hover {
      background-color: var(--bg-subtle);
      border-color: var(--border-strong);
      color: var(--text-primary);
      text-decoration: none;
    }
  }

  /* Primary Action */
  :is(.btn-primary, .ui-btn--primary) {
    background-color: var(--accent);
    border-color: var(--accent);
    color: #ffffff !important;

    & svg {
      fill: currentColor;
    }

    &:hover {
      background-color: var(--accent-hover);
      border-color: var(--accent-hover);
      color: #ffffff !important;
    }
  }

  /* Telegram CTA: Pre-configured rounded pill with official brand blue */
  :is(.btn-telegram, .ui-btn--telegram) {
    background-color: var(--brand-telegram);
    border-color: var(--brand-telegram);
    color: #ffffff !important;
    border-radius: var(--radius-full);
    font-size: 0.78rem;
    height: 2.1em;
    padding: 0 0.9em;

    &:hover {
      background-color: var(--brand-telegram-hover);
      border-color: var(--brand-telegram-hover);
      color: #ffffff !important;
    }
  }

  /* Channel List CTA: Pre-configured ice-blue pill */
  :is(.btn-channel, .ui-btn--channel) {
    background-color: var(--brand-telegram-soft);
    color: var(--brand-telegram-text) !important;
    border: 1px solid transparent;
    font-weight: 600;
    font-size: 0.78rem;
    height: 2.1em;
    padding: 0 0.9em;
    flex-shrink: 0;
    border-radius: var(--radius-full);

    &:hover {
      background-color: var(--accent);
      color: #ffffff !important;
      border-color: var(--accent);
    }
  }

  /* Soft Accent */
  :is(.btn-soft, .ui-btn--soft) {
    background-color: var(--accent-soft);
    border-color: transparent;
    color: var(--accent-pill-text) !important;

    &:hover {
      background-color: var(--accent);
      border-color: var(--accent);
      color: #ffffff !important;
    }
  }

  /* Ghost */
  :is(.btn-ghost, .ui-btn--ghost) {
    background-color: transparent;
    border-color: transparent;
    color: var(--text-secondary);

    &:hover {
      background-color: var(--bg-subtle);
      color: var(--text-primary);
    }
  }

  /* Danger */
  :is(.btn-danger, .ui-btn--danger) {
    background-color: var(--danger-soft);
    border-color: var(--danger-border);
    color: var(--danger-text);

    &:hover {
      background-color: var(--danger);
      border-color: var(--danger);
      color: #ffffff !important;
    }
  }

  /* Optional Modifiers */
  :is(.btn-sm, .ui-btn--sm) {
    border-radius: var(--radius-sm);
    padding: 2px 8px;
    height: 24px;
    min-height: 24px;
    font-size: 0.72rem;
    font-weight: 600;
  }

  :is(.btn-pill, .ui-btn--rounded) {
    border-radius: var(--radius-full);
  }

  :is(.btn-full, .ui-btn--full) {
    width: 100%;
  }

  :is(.btn-cta, .ui-btn--cta) {
    border-radius: var(--radius-md);
    min-height: 2.85rem;
    padding: 0.5rem 1.25rem;
    font-size: 1rem;
    font-weight: 700;
  }

  /* ========================================================================
     3. Tags & Badges (Zero-BEM Compound Inheritance)
     ======================================================================== */

  :is(.tag, .ui-tag, .tag-accent, .ui-tag--accent, .tag-success, .ui-tag--success, .tag-warning, .ui-tag--warning, .tag-danger, .ui-tag--danger, .tag-discount, .ui-tag--discount, .tag-rank, .ui-badge-rank, .tag-micro, .ui-badge-micro, .tag-pill, .ui-tag--rounded) {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    height: 2em;
    padding: 0 0.75em;
    border-radius: var(--radius-sm); /* 6px */
    font-size: 0.75rem;
    font-weight: 600;
    line-height: 1.5;
    border: 1px solid var(--border-default);
    background-color: var(--bg-subtle);
    color: var(--text-secondary);
    white-space: nowrap;
    text-decoration: none;

    &:hover {
      color: var(--text-primary);
      background-color: var(--border-default);
      text-decoration: none;
    }
  }

  :is(.tag-accent, .ui-tag--accent) {
    background-color: var(--accent-soft);
    border-color: transparent;
    color: var(--accent-pill-text) !important;
  }

  :is(.tag-success, .ui-tag--success) {
    background-color: var(--success-soft);
    border-color: var(--success-border);
    color: var(--success-text);
  }

  :is(.tag-warning, .ui-tag--warning) {
    background-color: var(--warning-soft);
    border-color: var(--warning-border);
    color: var(--warning-text);
  }

  :is(.tag-danger, .ui-tag--danger) {
    background-color: var(--danger-soft);
    border-color: var(--danger-border);
    color: var(--danger-text);
  }

  :is(.tag-pill, .ui-tag--rounded) {
    border-radius: var(--radius-full);
    padding: 0 0.85em;
  }

  :is(.tag-discount, .ui-tag--discount) {
    font-size: 0.65rem;
    height: 1.5em;
    padding: 0 5px;
    border-radius: var(--radius-full);
  }

  :is(.tag-rank, .ui-badge-rank) {
    font-weight: 700;
    width: 20px;
    height: 20px;
    padding: 0;
    justify-content: center;
    font-size: 0.7rem;
    border-radius: var(--radius-full);
  }

  :is(.tag-micro, .ui-badge-micro) {
    font-size: 0.65rem;
    height: 1.25rem;
    padding: 0 6px;
    border-radius: var(--radius-full);
  }

  /* ========================================================================
     4. Form Inputs (6px radius)
     ======================================================================== */

  .ui-field {
    display: flex;
    flex-direction: column;
    gap: 4px;
  }

  .ui-label {
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
  }

  .ui-input,
  .ui-select {
    width: 100%;
    padding: calc(0.5em - 1px) 0.75em;
    border-radius: var(--radius-sm); /* 6px */
    border: 1px solid var(--border-default);
    background-color: var(--bg-surface);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.875rem;
    line-height: 1.5;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;

    &::placeholder {
      color: var(--text-subtle);
    }

    &:focus {
      outline: none;
      border-color: var(--accent);
      box-shadow: 0 0 0 3px var(--accent-soft);
    }
  }

  /* ========================================================================
     5. Notices (Zero-BEM Compound Inheritance: 6px standard, 10px compact)
     ======================================================================== */

  :is(.notice, .ui-notice, .notice-info, .ui-notice--info, .notice-warning, .ui-notice--warning, .notice-success, .ui-notice--success, .notice-danger, .ui-notice--danger) {
    padding: 1.25rem 2.5rem 1.25rem 1.5rem;
    border-radius: var(--radius-sm); /* 6px */
    border: 1px solid var(--border-default);
    background-color: var(--bg-subtle);
    color: var(--text-secondary);
    font-size: 0.875rem;
  }

  :is(.notice-compact, .ui-notice--compact) {
    border-radius: var(--radius-md); /* 10px */
    padding: 0.5rem 0.75rem;
  }

  :is(.notice-info, .ui-notice--info) {
    background-color: var(--accent-soft);
    border-color: var(--accent);
    color: var(--text-primary);
  }

  :is(.notice-warning, .ui-notice--warning) {
    background-color: var(--warning-soft);
    border-color: var(--warning-border);
    color: var(--warning-text);
  }

  :is(.notice-success, .ui-notice--success) {
    background-color: var(--success-soft);
    border-color: var(--success-border);
    color: var(--success-text);
  }

  /* ========================================================================
     6. Foldables & Details (10px radius)
     ======================================================================== */

  :is(.foldable, .ui-foldable) {
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md); /* 10px */
    background-color: var(--bg-surface);
    overflow: hidden;

    & summary {
      padding: 0.65rem 0.85rem;
      cursor: pointer;
      font-weight: 600;
      font-size: 0.875rem;
      color: var(--text-primary);
      list-style: none;
      display: flex;
      align-items: center;
      justify-content: space-between;

      &:hover {
        background-color: var(--bg-subtle);
      }
    }

    & :is(.foldable-body, .ui-foldable-body) {
      padding: 0.75rem 0.85rem;
      border-top: 1px solid var(--border-subtle);
      background-color: var(--bg-subtle);
      color: var(--text-secondary);
      font-size: 0.875rem;
    }
  }

  /* ========================================================================
     7. Sticky Bottom Action Bar (8px padding, glassmorphism)
     ======================================================================== */

  :is(.sticky-bar, .ui-sticky-bar) {
    position: sticky;
    bottom: 0;
    z-index: 40;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 8px 16px;
    padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px));
    background-color: var(--bg-glass);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border-top: 1px solid var(--border-default);
    box-shadow: var(--shadow-lg);
  }

  /* ========================================================================
     8. Tables
     ======================================================================== */

  .ui-table-wrap {
    width: 100%;
    overflow-x: auto;
  }

  :is(.table, .ui-table) {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;

    & th {
      text-align: left;
      padding: 0.5rem 0.75rem;
      font-size: 0.75rem;
      font-weight: 700;
      text-transform: uppercase;
      letter-spacing: 0.03em;
      color: var(--text-muted);
      border-bottom: 1px solid var(--border-default);
    }

    & td {
      padding: 0.5rem 0.75rem;
      color: var(--text-secondary);
      border-bottom: 1px solid var(--border-subtle);
      vertical-align: middle;
    }

    & tbody tr:hover td {
      background-color: var(--bg-subtle);
    }

    & tbody tr.is-active td {
      background-color: var(--bg-subtle);
      color: var(--text-primary);
      font-weight: 600;
    }
  }

  /* ========================================================================
     9. Tabs
     ======================================================================== */

  .ui-tabs {
    display: flex;
    align-items: center;
    gap: 4px;
    border-bottom: 1px solid var(--border-default);
    margin-bottom: 1rem;
  }

  .ui-tab {
    padding: 0.5rem 0.85rem;
    border: none;
    border-bottom: 2px solid transparent;
    background: transparent;
    color: var(--text-muted);
    font-family: inherit;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: color 0.15s ease, border-color 0.15s ease;

    &:hover {
      color: var(--text-primary);
    }

    &.is-active {
      color: var(--accent);
      border-bottom-color: var(--accent);
    }
  }

  /* ========================================================================
     10. Breadcrumbs, Directory Links & Channel Rows (Pages)
     ======================================================================== */

  :is(.breadcrumb, .ui-breadcrumb) {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 6px;
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-bottom: 1.5rem; /* 24px, matches Bulma mb-4 */

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

    & .is-active a {
      color: var(--text-primary);
      font-weight: 600;
    }

    & .ui-sep {
      color: var(--text-subtle);
    }
  }

  :is(.hero-banner, .ui-hero-banner) {
    border-radius: var(--radius-xl); /* 14px */
    border: 1px solid var(--border-default);
    background: linear-gradient(135deg, #f8fafc 0%, #eff6ff 100%);
    padding: 1.25rem 1.5rem;
    box-shadow: 0 4px 14px -1px rgba(15, 23, 42, 0.07), 0 2px 4px -1px rgba(15, 23, 42, 0.04);
    display: flex;
    align-items: center;
    gap: 1.25rem;
    margin-bottom: var(--space-5);

    @media (max-width: 640px) {
      flex-direction: column;
      text-align: center;
    }
  }

  html[data-theme="dark"] :is(.hero-banner, .ui-hero-banner) {
    background: #1e293b;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.35);
  }

  :is(.dir-link, .ui-dir-link) {
    display: flex;
    align-items: center;
    padding: 4px 8px;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: 0.875rem;
    text-decoration: none;
    transition: background-color 0.15s ease, color 0.15s ease;

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

  /* Card Header & Contact Cards */
  :is(.card-header, .ui-card-header) {
    padding: 0.75rem;
    border-bottom: 1px solid var(--border-default);
    background-color: var(--bg-subtle);
  }

  :is(.contact-card, .ui-contact-card) {
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    background-color: var(--bg-surface);
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: 1.25rem;

    & .contact-header, & .ui-contact-header {
      display: flex;
      align-items: center;
      gap: 8px;
      margin-bottom: 0.75rem;

      & .contact-icon, & .ui-contact-icon {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        width: 22px;
        height: 22px;
        flex-shrink: 0;

        & svg, & .fa-icon {
          width: 18px;
          height: 18px;
        }
      }

      & h3, & .ui-h3 {
        margin: 0;
        font-size: 1rem;
        font-weight: 700;
        line-height: 1.3;
      }
    }
  }

  :is(.channel-title, .ui-channel-title) {
    font-weight: 600;
    font-size: 0.85rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: var(--text-primary);
  }

  :is(.channel-handle, .ui-channel-handle) {
    font-size: 0.75rem;
    color: var(--accent);
    font-weight: 600;
  }

  :is(.card-highlight-dashed, .ui-card--highlight-dashed) {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem;
    margin-top: 0.5rem;
    border-radius: var(--radius-md);
    background-color: var(--accent-soft);
    border: 1px dashed var(--accent);
  }

  :is(.channel-row, .ui-channel-row) {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 10px;
    border-radius: var(--radius-md); /* 10px */
    background-color: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    margin-bottom: 6px;
    transition: background-color 0.15s ease, border-color 0.15s ease;

    &:hover {
      background-color: var(--bg-subtle);
      border-color: var(--border-default);
    }
  }

  :is(.tip-box, .ui-tip-box) {
    padding: 10px 14px;
    border-radius: var(--radius-md); /* 10px */
    background-color: var(--accent-soft);
    border-left: 3px solid var(--accent);
    color: var(--text-secondary);
    font-size: 0.875rem;
    line-height: 1.5;
  }

