.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

.header {
  height: var(--header-h);
  flex-shrink: 0;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--space-7);
  z-index: 300;
  position: relative;
}

.header::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: var(--esp-red);
}

.header__brand {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.header__brand--link {
  color: inherit;
  text-decoration: none;
  transition: opacity var(--ease-out);
}

.header__brand--link:hover {
  text-decoration: none;
  opacity: 0.92;
}

.header__brand--link:hover .header__title span {
  color: var(--esp-red-hover);
}

.header__logo-img {
  width: 40px;
  height: 40px;
  object-fit: contain;
  flex-shrink: 0;
}

.header__title { font-size: 1.2rem; font-weight: 600; }
.header__title span { color: var(--esp-red); transition: color var(--ease-out); }

.type-tabs {
  display: flex;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
  background: var(--bg-input);
}

.type-tabs__btn {
  height: 36px;
  padding: 0 18px;
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--text-secondary);
  border-right: 1px solid var(--border);
  transition: background var(--ease-out), color var(--ease-out);
}

.type-tabs__btn:last-child { border-right: none; }
.type-tabs__btn:hover:not(.is-active) { color: var(--text-primary); background: var(--bg-elevated); }
.type-tabs__btn.is-active { background: var(--esp-red); color: #fff; }

.filter-bar {
  flex-shrink: 0;
  position: relative;
  z-index: 200;
  background: var(--bg-filter);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-soft);
}

.filter-bar__inner {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-6);
  max-width: 1800px;
  margin: 0 auto;
  min-height: 52px;
}

.filter-bar__search {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex: 0 0 220px;
  height: 36px;
  padding: 0 var(--space-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-input);
  color: var(--text-muted);
  transition: border-color var(--ease-out), box-shadow var(--ease-out);
}

.filter-bar__search:focus-within {
  border-color: var(--esp-red);
  box-shadow: 0 0 0 3px var(--border-focus);
}

.filter-bar__search input {
  flex: 1;
  min-width: 0;
  border: none;
  outline: none;
  background: transparent;
  color: var(--text-primary);
  font-size: var(--text-sm);
}

.filter-bar__menus {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex: 1;
  min-width: 0;
  overflow-x: auto;
  padding: 2px 0;
  scrollbar-width: none;
}

.filter-bar__menus::-webkit-scrollbar { display: none; }

.filter-bar__meta {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  flex-shrink: 0;
  margin-left: auto;
}

.filter-bar__quick {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-sm);
  color: var(--text-secondary);
  cursor: pointer;
  white-space: nowrap;
}

.filter-bar__quick input { accent-color: var(--esp-red); }

.filter-bar__count {
  font-size: var(--text-sm);
  color: var(--text-secondary);
  white-space: nowrap;
}

.filter-bar__count strong { color: var(--esp-red); }

.filter-bar__btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 36px;
  padding: 0 14px;
  font-size: var(--text-sm);
  font-weight: 500;
  border-radius: var(--radius-md);
  white-space: nowrap;
  transition: background var(--ease-out), border-color var(--ease-out), color var(--ease-out);
}

.filter-bar__btn--ghost {
  color: var(--text-secondary);
  border: 1px solid var(--border);
  background: transparent;
}

.filter-bar__btn--ghost:hover { color: var(--esp-red); border-color: var(--esp-red); }

.filter-bar__btn--primary {
  background: var(--esp-red);
  color: #fff;
  font-weight: 600;
}

.filter-bar__btn--primary:hover { background: var(--esp-red-hover); }

.filter-popover {
  position: absolute;
  top: calc(100% + 4px);
  z-index: 250;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  max-height: min(360px, 50vh);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.filter-popover[hidden] { display: none; }

.main {
  flex: 1;
  width: 100%;
  max-width: 1800px;
  margin: 0 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.content {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: var(--space-5) var(--space-7) var(--space-6);
  overflow: hidden;
}

.content__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-3);
  flex-shrink: 0;
  flex-wrap: wrap;
  gap: var(--space-3);
}

.content__head-left {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  flex: 1;
  min-width: 0;
}

.results-chips {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
}

.results-chips:empty { display: none; }

.results-chip {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: 4px 10px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  color: var(--text-primary);
}

.results-chip button {
  color: var(--text-muted);
  font-size: 1rem;
  line-height: 1;
  padding: 0 2px;
  transition: color var(--ease-out);
}

.results-chip button:hover { color: var(--esp-red); }

.results-chips__clear {
  font-size: var(--text-sm);
  color: var(--esp-red);
  font-weight: 500;
  padding: 4px 8px;
}

.results-shell {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-surface);
  box-shadow: var(--shadow-soft);
  overflow: hidden;
  position: relative;
}

.results-shell::before,
.results-shell::after {
  content: '';
  position: absolute;
  top: 0;
  bottom: 0;
  width: 24px;
  pointer-events: none;
  z-index: 2;
  opacity: 0;
  transition: opacity var(--ease-out);
}

.results-shell::before {
  left: 0;
  background: linear-gradient(to right, var(--bg-surface), transparent);
}

.results-shell::after {
  right: 0;
  background: linear-gradient(to left, var(--bg-surface), transparent);
}

.results-shell.is-scrollable::after {
  opacity: 1;
}

.results-table-view {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

.results-table-head {
  flex-shrink: 0;
  overflow-x: hidden;
  border-bottom: 1px solid var(--border);
  background: var(--bg-elevated);
}

.results-table-wrap {
  flex: 1;
  min-height: 0;
  overflow: auto;
  border: none;
  border-radius: 0;
  box-shadow: none;
  background: transparent;
  scrollbar-gutter: stable;
}

.results-card-view {
  display: none;
  flex: 1;
  min-height: 0;
  flex-direction: column;
  gap: var(--space-3);
  padding: var(--space-4);
  overflow-y: auto;
}

@media (max-width: 900px) {
  .results-table-view { display: none; }
  .results-card-view { display: flex; }
  .results-shell::before,
  .results-shell::after { display: none; }
}

.filter-open-btn {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  height: 36px;
  padding: 0 var(--space-4);
  font-size: var(--text-sm);
  font-weight: 600;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  transition: border-color var(--ease-out), background var(--ease-out);
}

.filter-open-btn:hover,
.filter-open-btn.is-active {
  border-color: var(--esp-red);
  background: var(--esp-red-muted);
}

.filter-open-btn__badge {
  display: none;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  font-size: var(--text-xs);
  font-weight: 700;
  background: var(--esp-red);
  color: #fff;
  border-radius: 9px;
  align-items: center;
  justify-content: center;
}

.filter-open-btn__badge.is-visible,
.filter-open-btn.is-active .filter-open-btn__badge:not(:empty) {
  display: inline-flex;
}

.filter-modal {
  position: fixed;
  inset: 0;
  z-index: 400;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-6);
}

.filter-modal[hidden] { display: none; }

.filter-modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(2px);
}

.filter-modal__panel {
  position: relative;
  width: min(920px, 100%);
  max-height: min(85vh, 800px);
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.filter-modal__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--border);
}

.filter-modal__header h2 {
  font-size: var(--text-lg);
  font-weight: 600;
}

.filter-modal__close {
  font-size: 1.5rem;
  line-height: 1;
  color: var(--text-muted);
  padding: 4px 8px;
  transition: color var(--ease-out);
}

.filter-modal__close:hover { color: var(--esp-red); }

.fm-quicknav {
  display: flex;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-5);
  border-bottom: 1px solid var(--border);
  background: var(--bg-elevated);
  overflow-x: auto;
  flex-shrink: 0;
}

.fm-navlink {
  flex-shrink: 0;
  padding: 6px 12px;
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--text-secondary);
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 999px;
  white-space: nowrap;
  transition: color var(--ease-out), border-color var(--ease-out), background var(--ease-out);
}

.fm-navlink:hover {
  color: var(--text-primary);
  border-color: var(--border-focus);
}

.fm-navlink.is-active {
  color: var(--esp-red);
  border-color: var(--esp-red);
  background: var(--esp-red-muted);
}

.filter-modal__body {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-5);
  display: flex;
  flex-direction: column;
  gap: var(--space-7);
  scroll-behavior: smooth;
}

.fm-category {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: var(--space-4);
}

.filter-modal__footer {
  display: flex;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-5);
  border-top: 1px solid var(--border);
  box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.15);
}

@media (max-width: 640px) {
  .filter-modal__footer .filter-bar__btn {
    flex: 1 1 auto;
  }
}

body.filter-modal-open { overflow: hidden; }

.app--product {
  height: 100vh;
  height: 100dvh;
}

.main.main--product {
  overflow-y: auto;
  max-width: none;
}

.content.content--product {
  overflow: visible;
  padding: 0;
}

.content__count { font-size: var(--text-base); color: var(--text-secondary); }
.content__count strong { color: var(--esp-red); }

.content__sort {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  font-size: var(--text-sm);
  color: var(--text-secondary);
  flex-shrink: 0;
}

.content__sort select {
  height: 36px;
  padding: 0 var(--space-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-elevated);
  color: var(--text-primary);
  transition: border-color var(--ease-out);
}

.content__sort select:focus {
  border-color: var(--esp-red);
  outline: none;
}

@media (max-width: 1100px) {
  .filter-bar__inner { flex-wrap: wrap; }
  .filter-bar__search { flex: 1 1 180px; }
  .filter-bar__meta { width: 100%; justify-content: flex-end; }
}

@media (max-width: 768px) {
  .filter-bar__inner { padding-left: var(--space-4); padding-right: var(--space-4); }
  .header { padding: 0 var(--space-4); }
  .content { padding: var(--space-4); }
}

@media (max-width: 640px) {
  .app {
    height: 100dvh;
  }

  .header {
    height: auto;
    min-height: 56px;
    flex-wrap: wrap;
    padding: var(--space-3) var(--space-4);
    gap: var(--space-2);
    justify-content: center;
  }

  .header__title { font-size: var(--text-lg); }
  .header__logo-img { width: 32px; height: 32px; }

  .header__nav { width: 100%; display: flex; justify-content: center; }

  .type-tabs { width: 100%; }
  .type-tabs__btn { flex: 1; padding: 0 var(--space-2); }

  .filter-bar__inner {
    flex-wrap: wrap;
    padding: var(--space-3) var(--space-4);
    gap: var(--space-2);
  }

  .filter-bar__search { flex: 1 1 100%; order: 1; }
  .filter-open-btn { order: 2; flex: 1; justify-content: center; }
  .filter-bar__meta {
    order: 3;
    width: 100%;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: var(--space-2);
  }
  .filter-bar__count { order: 1; }
  .filter-bar__quick { order: 2; }
  .filter-bar__btn--ghost { order: 3; }
  .filter-bar__btn--primary { order: 4; flex: 1 1 100%; justify-content: center; }

  .content { padding: var(--space-3); }

  .content__head {
    flex-direction: column;
    align-items: stretch;
  }

  .content__sort { justify-content: space-between; }
  .content__sort select { flex: 1; }

  .filter-modal { padding: 0; }

  .filter-modal__panel {
    width: 100%;
    height: 100%;
    max-height: 100%;
    border-radius: 0;
  }

  .fm-category { grid-template-columns: 1fr; }
  .fm-ranges { grid-template-columns: 1fr; }
}
