/* =========================================
   JM Celulares — Catálogo Styles
   Mobile-first, dark theme
   ========================================= */

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

:root {
  --bg:          #0b0b12;
  --bg-2:        #111118;
  --bg-card:     #16161f;
  --bg-card-h:   #1c1c28;
  --primary:     #3b82f6;
  --primary-d:   #2563eb;
  --accent:      #8b5cf6;
  --wa:          #25d366;
  --wa-d:        #1ebe5d;
  --ig:          #e1306c;
  --text:        #f1f5f9;
  --text-muted:  #94a3b8;
  --text-dim:    #64748b;
  --border:      rgba(255,255,255,.07);
  --border-b:    rgba(255,255,255,.13);
  --green-bg:    rgba(16,185,129,.1);
  --green-text:  #34d399;
  --green-border:rgba(16,185,129,.25);
  --amber-bg:    rgba(245,158,11,.1);
  --amber-text:  #fbbf24;
  --amber-border:rgba(245,158,11,.25);
  --red-bg:      rgba(239,68,68,.1);
  --red-text:    #f87171;
  --red-border:  rgba(239,68,68,.25);
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
}

html { -webkit-text-size-adjust: 100%; }
[hidden] { display: none !important; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: contain;
}

/* ============ APP SHELL ============ */
.app {
  max-width: 520px;
  margin-inline: auto;
  min-height: 100svh;
  position: relative;
  padding-bottom: 88px;
}

/* ============ TOPBAR ============ */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  background: rgba(11,11,18,.9);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border);
  padding: 0;
}

.topbar__inner {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px 10px;
}

.topbar__back {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px; height: 36px;
  border-radius: 10px;
  background: var(--bg-card);
  border: 1px solid var(--border-b);
  color: var(--text-muted);
  flex-shrink: 0;
  transition: color .15s, border-color .15s;
}
.topbar__back:hover { color: var(--text); border-color: var(--primary); }

.topbar__brand {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  min-width: 0;
}

.topbar__logo-img {
  width: 32px; height: 32px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}

.topbar__title {
  font-size: .92rem;
  font-weight: 700;
  line-height: 1.2;
}
.topbar__subtitle {
  font-size: .72rem;
  color: var(--text-dim);
  line-height: 1.2;
}

.topbar__wa {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px; height: 36px;
  border-radius: 10px;
  background: rgba(37,211,102,.12);
  border: 1px solid rgba(37,211,102,.25);
  color: var(--wa);
  flex-shrink: 0;
  transition: background .15s;
}
.topbar__wa:hover { background: rgba(37,211,102,.2); }

/* ---- Search ---- */
.search-wrap {
  padding: 8px 12px 12px;
}

.search-box {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg-card);
  border: 1px solid var(--border-b);
  border-radius: 12px;
  padding: 10px 14px;
  transition: border-color .2s;
}
.search-box:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(59,130,246,.1);
}

.search-icon { color: var(--text-dim); flex-shrink: 0; }

.search-box input {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  font-family: var(--font);
  font-size: .9rem;
  color: var(--text);
  min-width: 0;
}
.search-box input::placeholder { color: var(--text-dim); }

.search-clear {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-dim);
  display: flex;
  align-items: center;
  padding: 2px;
  border-radius: 4px;
}
.search-clear:hover { color: var(--text); }

/* ============ BRAND TABS ============ */
.brand-tabs-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  border-bottom: 1px solid var(--border);
  background: var(--bg-2);
}
.brand-tabs-wrap::-webkit-scrollbar { display: none; }

.brand-tabs {
  display: flex;
  gap: 4px;
  padding: 10px 12px;
  min-width: max-content;
}

.brand-tab {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border-radius: 50px;
  border: 1px solid var(--border-b);
  background: none;
  color: var(--text-muted);
  font-size: .8rem;
  font-weight: 500;
  font-family: var(--font);
  cursor: pointer;
  white-space: nowrap;
  transition: all .15s;
  position: relative;
}
.brand-tab:hover {
  color: var(--text);
  border-color: var(--border-b);
  background: var(--bg-card);
}
.brand-tab--active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
  font-weight: 600;
}

.brand-tab__count {
  background: rgba(255,255,255,.18);
  border-radius: 50px;
  padding: 1px 7px;
  font-size: .7rem;
}
.brand-tab--active .brand-tab__count { background: rgba(255,255,255,.25); }

/* ============ CONTENT ============ */
.content {
  padding: 12px;
}

/* ---- Loading ---- */
.loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 60px 20px;
  color: var(--text-muted);
  font-size: .9rem;
}
.loading__spinner {
  width: 32px; height: 32px;
  border: 2.5px solid var(--border-b);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- Error / Empty ---- */
.error-state,
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 60px 20px;
  color: var(--text-muted);
  text-align: center;
  font-size: .9rem;
}
.error-state svg, .empty-state svg { color: var(--text-dim); }
.error-state strong, .empty-state strong { color: var(--text); }

.btn-retry {
  margin-top: 4px;
  padding: 9px 20px;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 50px;
  font-size: .85rem;
  font-weight: 600;
  font-family: var(--font);
  cursor: pointer;
  transition: background .15s;
}
.btn-retry:hover { background: var(--primary-d); }

/* ============ BRAND CARD ============ */
.brand-card {
  border: 1px solid var(--border);
  border-radius: 14px;
  margin-bottom: 10px;
  overflow: hidden;
  background: var(--bg-card);
  transition: border-color .2s;
}
.brand-card--active { border-color: var(--border-b); }

.brand-card__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  gap: 10px;
}
.brand-card__header:active { background: var(--bg-card-h); }

.brand-card__left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand-card__icon {
  width: 36px; height: 36px;
  border-radius: 9px;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .85rem;
  font-weight: 800;
  color: #fff;
  flex-shrink: 0;
  letter-spacing: -.02em;
}

.brand-card__name {
  font-size: .95rem;
  font-weight: 700;
  truncate: ellipsis;
  overflow: hidden;
  white-space: nowrap;
}
.brand-card__count {
  font-size: .72rem;
  color: var(--text-dim);
  margin-top: 1px;
}

.brand-card__chevron {
  color: var(--text-dim);
  transition: transform .25s ease;
  flex-shrink: 0;
}
.brand-card--active .brand-card__chevron { transform: rotate(180deg); }

/* ---- Products panel ---- */
.brand-card__products {
  display: grid;
  grid-template-rows: 0fr;
  transition: grid-template-rows .28s ease;
}
.brand-card--active .brand-card__products {
  grid-template-rows: 1fr;
}

.brand-card__products-inner {
  overflow: hidden;
}

.products-list {
  border-top: 1px solid var(--border);
  padding: 6px 0;
}

/* ============ PRODUCT ROW ============ */
.product-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  transition: background .12s;
  animation: fadeIn .2s ease both;
}
.product-row:last-child { border-bottom: none; }
.product-row:active { background: var(--bg-card-h); }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: none; }
}

.product-row__info { flex: 1; min-width: 0; }

.product-row__model {
  font-size: .88rem;
  font-weight: 600;
  color: var(--text);
  line-height: 1.3;
  margin-bottom: 3px;
}

.product-row__quality {
  font-size: .75rem;
  color: var(--text-dim);
  line-height: 1.3;
}

.product-row__right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 5px;
  flex-shrink: 0;
}

.product-row__price {
  font-size: .95rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -.01em;
}

.stock-badge {
  font-size: .68rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 50px;
  border: 1px solid;
  white-space: nowrap;
}
.stock-badge--ok {
  background: var(--green-bg);
  color: var(--green-text);
  border-color: var(--green-border);
}
.stock-badge--low {
  background: var(--amber-bg);
  color: var(--amber-text);
  border-color: var(--amber-border);
}
.stock-badge--out {
  background: var(--red-bg);
  color: var(--red-text);
  border-color: var(--red-border);
}

/* ============ FLOATING BUTTONS ============ */
.floating-btns {
  position: fixed;
  bottom: 20px;
  right: 16px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.floating-btn {
  width: 48px; height: 48px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  box-shadow: 0 4px 16px rgba(0,0,0,.4);
  transition: transform .2s, box-shadow .2s;
}
.floating-btn:hover {
  transform: scale(1.08) translateY(-2px);
  box-shadow: 0 8px 24px rgba(0,0,0,.45);
}
.floating-btn--wa {
  background: linear-gradient(135deg, var(--wa), var(--wa-d));
  position: relative;
}
.floating-btn--wa::after {
  content: '';
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  border: 2px solid var(--wa);
  animation: pulse 2.5s ease-out infinite;
  opacity: 0;
}
.floating-btn--ig {
  background: linear-gradient(135deg, #f09433, #e6683c, #dc2743, #cc2366, #bc1888);
}

@keyframes pulse {
  0%   { transform: scale(.9); opacity: .5; }
  80%  { transform: scale(1.4); opacity: 0; }
  100% { opacity: 0; }
}

/* ============ RESPONSIVE ============ */

/* Tablet: wider app shell */
@media (min-width: 560px) {
  .app {
    border-inline: 1px solid var(--border);
    max-width: 600px;
  }
}

/* Desktop: two-column layout */
@media (min-width: 960px) {
  body { background: var(--bg-2); }

  .app {
    max-width: 1100px;
    border-inline: none;
    display: grid;
    grid-template-rows: auto auto 1fr;
    grid-template-columns: 260px 1fr;
    grid-template-areas:
      "topbar  topbar"
      "sidebar catalog"
      "sidebar catalog";
    min-height: 100svh;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 16px;
    margin: 24px auto;
    overflow: hidden;
  }

  .topbar {
    grid-area: topbar;
    position: sticky;
    top: 0;
    border-bottom: 1px solid var(--border);
  }

  /* Brand tabs become a vertical sidebar */
  .brand-tabs-wrap {
    grid-area: sidebar;
    overflow-y: auto;
    overflow-x: hidden;
    border-bottom: none;
    border-right: 1px solid var(--border);
    background: var(--bg-2);
    scrollbar-width: thin;
    scrollbar-color: var(--border-b) transparent;
    position: sticky;
    top: 120px; /* topbar height */
    max-height: calc(100svh - 120px);
    align-self: start;
  }

  .brand-tabs {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 12px 10px;
    min-width: unset;
  }

  .brand-tab {
    justify-content: space-between;
    border-radius: 10px;
    padding: 9px 14px;
    font-size: .85rem;
    width: 100%;
  }

  /* Catalog takes remaining space */
  .content {
    grid-area: catalog;
    padding: 16px;
  }

  /* Product cards in 2-col grid on large screens */
  .brand-card {
    margin-bottom: 12px;
  }

  .products-list {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
  }

  .product-row {
    border-bottom: 1px solid var(--border);
    border-right: 1px solid var(--border);
  }
  /* Remove right border on last column */
  .product-row:nth-child(2n) { border-right: none; }
  /* Remove bottom border on last 2 rows */
  .product-row:nth-last-child(-n+2) { border-bottom: none; }
  /* Edge case: odd total */
  .product-row:last-child:nth-child(odd) {
    grid-column: 1 / -1;
    border-right: none;
  }

  /* Floating buttons shift left so they don't overlap catalog cards */
  .floating-btns {
    right: calc((100vw - 1100px) / 2 + 16px);
  }
}

/* Large desktop: 3-col products */
@media (min-width: 1280px) {
  .app { max-width: 1280px; }

  .products-list {
    grid-template-columns: repeat(3, 1fr);
  }
  .product-row:nth-child(2n) { border-right: 1px solid var(--border); }
  .product-row:nth-child(3n) { border-right: none; }
  .product-row:nth-last-child(-n+3) { border-bottom: none; }
  .product-row:last-child:nth-child(odd) { grid-column: unset; }
}
