/*
 * VibeCode Bitrix Showcase — web UI on the popizdim-design system.
 * Values come from design/tokens.css (--ds-*). Do not add hex colors here.
 * Rules: DESIGN.md §1–7 (app UI). Neutrals are foreground tints, one accent,
 * the icon tiles are the only colorful element, sentence case, one-line fields.
 */

@font-face {
  font-family: "Inter Variable";
  src: url("assets/fonts/InterVariable.woff2") format("woff2");
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}

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

html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--ds-font);
  font-size: var(--ds-font-size);
  font-feature-settings: var(--ds-font-features);
  line-height: 1.5;
  color: var(--ds-foreground);
  background-color: var(--ds-background);
  -webkit-font-smoothing: antialiased;
}

/* The glows live on a fixed layer: background-attachment: fixed repaints the page on every scroll */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background-image:
    radial-gradient(70vw 60vh at 0% 0%, color-mix(in srgb, var(--ds-accent) var(--ds-page-glow-a), transparent), transparent 70%),
    radial-gradient(60vw 55vh at 100% 100%, color-mix(in srgb, var(--ds-purple) var(--ds-page-glow-b), transparent), transparent 70%);
}

h1, h2, p { margin: 0; }

a { color: inherit; text-decoration: none; }

button { font: inherit; color: inherit; cursor: pointer; }

:focus-visible {
  outline: 2px solid var(--ds-accent);
  outline-offset: 1px;
  border-radius: 6px;
}

code {
  font-family: var(--ds-font-mono);
  font-size: 12px;
  padding: 1px 5px;
  border-radius: 6px;
  background: var(--ds-fg-5);
  color: var(--ds-foreground);
  word-break: break-word;
}

.icon {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex-shrink: 0;
}

/* ---------- Floating frosted sidebar (DESIGN.md §4) ---------- */

.sidebar {
  position: fixed;
  top: 8px;
  bottom: 8px;
  left: 8px;
  z-index: 50;
  width: var(--ds-sidebar-width);
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 12px 10px 10px;
  overflow-y: auto;
  overscroll-behavior: contain;
  border-radius: var(--ds-radius-panel);
  background: var(--ds-glass-panel-bg);
  -webkit-backdrop-filter: var(--ds-glass-blur);
  backdrop-filter: var(--ds-glass-blur);
  box-shadow: var(--ds-shadow-panel), inset 0 0 0 0.5px var(--ds-hairline);
}

.brand-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 6px 2px;
}

.brand-icon {
  width: var(--ds-icon-tile);
  height: var(--ds-icon-tile);
  flex-shrink: 0;
  display: grid;
  place-items: center;
  border-radius: var(--ds-radius-tile);
  background: linear-gradient(180deg, var(--ds-tile-blue-top), var(--ds-tile-blue-bottom));
  box-shadow: inset 0 0 0 0.5px rgba(255, 255, 255, 0.35);
  color: #fff;
  font-size: 12px;
  font-weight: 600;
}

.brand-title {
  font-size: 13px;
  font-weight: 600;
  line-height: 1.3;
}

.brand-subtitle {
  font-size: 12px;
  color: var(--ds-text-secondary);
  line-height: 1.3;
}

/* ---------- Search field: one line, 32 high, radius 12, 1 px ring ---------- */

.search-container {
  position: relative;
  margin: 0 2px;
}

.search-icon {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  width: 14px;
  height: 14px;
  color: var(--ds-text-secondary);
  pointer-events: none;
}

.search-input {
  width: 100%;
  height: var(--ds-control-height);
  padding: 0 36px 0 30px;
  border: 0;
  border-radius: var(--ds-radius-control);
  background: var(--ds-field-fill);
  box-shadow: inset 0 0 0 1px var(--ds-field-ring);
  color: var(--ds-foreground);
  font: inherit;
  font-size: 13px;
  white-space: nowrap;
  text-overflow: ellipsis;
  transition: box-shadow 0.15s;
}

.search-input::placeholder { color: var(--ds-text-secondary); }

.search-input:hover { box-shadow: inset 0 0 0 1px var(--ds-accent); }

.search-input:focus {
  outline: none;
  box-shadow: inset 0 0 0 2px var(--ds-accent);
}

/* ---------- Navigation: 32 high, radius 10, selected = fg 10 % ---------- */

.nav-section-title {
  padding: 4px 8px 0;
  font-size: 12px;
  color: var(--ds-text-secondary);
}

.nav-menu {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-link {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  height: var(--ds-control-height);
  padding: 0 8px;
  border-radius: var(--ds-radius-nav-item);
  color: var(--ds-foreground);
  font-size: 13px;
  font-weight: 400;
  transition: background 0.15s;
}

.nav-link:hover { background: var(--ds-hover); }

.nav-link.active { background: var(--ds-selected); }

.nav-label {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.nav-label .icon { color: var(--ds-text-secondary); }

.nav-label > span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.nav-badge {
  flex-shrink: 0;
  font-size: 12px;
  color: var(--ds-text-secondary);
  font-variant-numeric: tabular-nums;
}

/* ---------- Buttons: secondary fg 15 %, primary accent (DESIGN.md §4) ---------- */

.control-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 6px;
  padding: 0 2px;
}

.btn-primary,
.btn-secondary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: var(--ds-control-height);
  padding: 0 16px;
  border: 0;
  border-radius: var(--ds-radius-control);
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  text-decoration: none;
  transition: background 0.15s, filter 0.15s, transform 0.1s;
}

.btn-primary {
  /* accent darkened 18%: white text on the plain accent is 3.5:1, text needs 4.5:1 */
  background: color-mix(in srgb, var(--ds-accent) 82%, #000);
  color: #fff;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.12), 0 4px 10px color-mix(in srgb, var(--ds-accent) 28%, transparent);
}

.btn-primary:hover { filter: brightness(1.08); color: #fff; }

.btn-secondary {
  background: var(--ds-button-secondary);
  color: var(--ds-foreground);
}

.btn-secondary:hover { background: var(--ds-button-secondary-hover); color: var(--ds-foreground); }

.btn-primary:active,
.btn-secondary:active { transform: scale(0.98); }

.btn-small {
  height: var(--ds-control-height-sm);
  min-width: 0;
  padding: 0 8px;
  font-size: 12px;
}

/* ---------- Sidebar footer ---------- */

.sidebar-footer {
  margin-top: auto;
  padding: 12px 8px 4px;
  font-size: 12px;
  line-height: 1.5;
  color: var(--ds-text-secondary);
}

.sidebar-count {
  margin: 0 0 4px;
  font-size: 12px;
  font-weight: 500;
  color: var(--ds-text-secondary);
}

/* ---------- Mobile top bar (hidden on desktop) ---------- */

.mobile-header { display: none; }

/* ---------- Main column ---------- */

.main-content {
  margin-left: calc(var(--ds-sidebar-width) + 24px);
  padding: 32px 40px 72px;
}

.hero-section,
.category-section {
  max-width: 880px;
}

.hero-section { margin-bottom: 32px; }

.hero-title {
  font-size: 24px;
  font-weight: 600;
  line-height: 1.25;
  color: var(--ds-foreground);
}

.hero-description {
  margin-top: 8px;
  max-width: 64ch;
  font-size: 13px;
  line-height: 1.6;
  color: var(--ds-text-secondary);
}

.hero-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 16px;
}

/* ---------- Category: icon tile, title, count ---------- */

.category-section {
  margin-bottom: 32px;
  scroll-margin-top: 24px;
}

.category-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}

.category-title-group {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

/* One tile color per category; blue is the default. */
.category-icon {
  --tile-top: var(--ds-tile-blue-top);
  --tile-bottom: var(--ds-tile-blue-bottom);
  width: var(--ds-icon-tile);
  height: var(--ds-icon-tile);
  flex-shrink: 0;
  display: grid;
  place-items: center;
  border-radius: var(--ds-radius-tile);
  background: linear-gradient(180deg, var(--tile-top), var(--tile-bottom));
  box-shadow: inset 0 0 0 0.5px rgba(255, 255, 255, 0.35);
  color: #fff;
}

.category-icon .icon {
  width: 13px;
  height: 13px;
  stroke-width: 2;
}

#analytics .category-icon { --tile-top: var(--ds-tile-blue-top); --tile-bottom: var(--ds-tile-blue-bottom); }
#calculators .category-icon { --tile-top: var(--ds-tile-orange-top); --tile-bottom: var(--ds-tile-orange-bottom); }
#ai-voice .category-icon { --tile-top: var(--ds-tile-purple-top); --tile-bottom: var(--ds-tile-purple-bottom); }
#bots .category-icon { --tile-top: var(--ds-tile-sky-top); --tile-bottom: var(--ds-tile-sky-bottom); }
#devtools .category-icon { --tile-top: var(--ds-tile-green-top); --tile-bottom: var(--ds-tile-green-bottom); }
#crm-internal .category-icon { --tile-top: var(--ds-tile-yellow-top); --tile-bottom: var(--ds-tile-yellow-bottom); }
#client-services .category-icon { --tile-top: var(--ds-tile-pink-top); --tile-bottom: var(--ds-tile-pink-bottom); }
#docs-accounting .category-icon { --tile-top: var(--ds-tile-orange-top); --tile-bottom: var(--ds-tile-orange-bottom); }
#integrations-access .category-icon { --tile-top: var(--ds-tile-red-top); --tile-bottom: var(--ds-tile-red-bottom); }
#ai-infra .category-icon { --tile-top: var(--ds-tile-gray-top); --tile-bottom: var(--ds-tile-gray-bottom); }

.category-title {
  font-size: 16px;
  font-weight: 500;
  line-height: 1.3;
  color: var(--ds-foreground);
}

.category-count {
  flex-shrink: 0;
  font-size: 12px;
  color: var(--ds-text-secondary);
  white-space: nowrap;
}

/* ---------- Settings group: one card per category, rows inside ---------- */

.accordion-group {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border-radius: var(--ds-radius-card);
  background: var(--ds-card-fill);
  box-shadow: inset 0 0 0 0.5px var(--ds-hairline);
}

.accordion-item + .accordion-item {
  border-top: 1px solid var(--ds-divider);
}

.accordion-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 20px;
  cursor: pointer;
  user-select: none;
  transition: background 0.15s;
}

.accordion-header:hover { background: var(--ds-hover); }

.accordion-header:focus-visible {
  outline-offset: -2px;
  border-radius: 0;
}

.accordion-meta-main {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.case-header-content {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.case-title {
  font-size: 13px;
  font-weight: 500;
  line-height: 1.35;
  color: var(--ds-foreground);
}

.case-author {
  font-size: 12px;
  line-height: 1.4;
  color: var(--ds-text-secondary);
}

.case-author-icon { display: none; }

/* Badges are neutral: color is reserved for tiles, the accent and the logo. */
.case-badge {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 92px;
  height: 20px;
  padding: 0 8px;
  border-radius: 6px;
  /* solid white chip: it must stay distinct from the grey hover row and the card */
  background: var(--ds-background);
  box-shadow: inset 0 0 0 1px var(--ds-divider);
  color: var(--ds-text-secondary);
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
}

.badge-cyan,
.badge-green,
.badge-orange,
.badge-pink,
.badge-purple {
  background: var(--ds-background);
  box-shadow: inset 0 0 0 1px var(--ds-divider);
  color: var(--ds-text-secondary);
}

.accordion-chevron {
  flex-shrink: 0;
  display: grid;
  place-items: center;
  width: 16px;
  height: 16px;
  color: var(--ds-text-secondary);
  transition: transform 0.22s var(--ds-ease-out-expo), color 0.15s;
}

.accordion-chevron svg {
  width: 16px;
  height: 16px;
}

.accordion-item.active .accordion-chevron {
  transform: rotate(180deg);
  color: var(--ds-foreground);
}

.accordion-content { display: none; }

.accordion-item.active .accordion-content { display: block; }

.accordion-body-inner { padding: 0 20px 16px; }

.case-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(260px, 40%);
  gap: 20px;
  align-items: start;
}

.case-section-subtitle {
  margin: 10px 0 4px;
  font-size: 12px;
  font-weight: 500;
  color: var(--ds-text-secondary);
}

.case-description {
  margin-bottom: 4px;
  font-size: 13px;
  line-height: 1.6;
  color: var(--ds-foreground);
  text-wrap: pretty;
}

.feature-list {
  list-style: none;
  margin: 0 0 4px;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

/* Block flow, not flex: the text can mix plain words and <code> inline. */
.feature-item {
  position: relative;
  padding-left: 12px;
  font-size: 13px;
  line-height: 1.55;
  color: var(--ds-text-secondary);
}

/* The dot is a plain 4 px tint, not a colored check. */
.feature-bullet {
  position: absolute;
  left: 0;
  top: 0.72em;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--ds-text-tertiary);
  font-size: 0;
}

.feature-item code { white-space: nowrap; }

.tech-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.tech-tag {
  display: inline-flex;
  align-items: center;
  height: 20px;
  padding: 0 8px;
  border-radius: 6px;
  background: var(--ds-background);
  box-shadow: inset 0 0 0 1px var(--ds-divider);
  color: var(--ds-text-secondary);
  font-size: 12px;
  font-weight: 500;
}

/* Metadata sits on a 5 % field fill, radius 12, no borders. */
.meta-box {
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-self: stretch;
  margin-top: 20px;
  padding: 12px 14px;
  border-radius: var(--ds-radius-control);
  /* white panel, same as the case badges: a grey fill merged with the hovered header above */
  background: var(--ds-background);
  box-shadow: inset 0 0 0 1px var(--ds-divider);
}

.meta-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.meta-label {
  font-size: 12px;
  color: var(--ds-text-secondary);
}

.meta-value {
  font-size: 13px;
  font-weight: 500;
  line-height: 1.4;
  color: var(--ds-foreground);
}

.telegram-quote {
  margin: 0 0 12px;
  padding: 10px 12px;
  border-radius: var(--ds-radius-control);
  background: var(--ds-field-fill);
  color: var(--ds-text-secondary);
  font-style: italic;
  line-height: 1.6;
}

/* ---------- Empty state and footer ---------- */

.empty-state {
  padding: 24px 20px;
  text-align: center;
  font-size: 13px;
  color: var(--ds-text-secondary);
  border-radius: var(--ds-radius-card);
  background: var(--ds-card-fill);
  box-shadow: inset 0 0 0 0.5px var(--ds-hairline);
}

.empty-state[hidden] { display: none; }

.site-footer {
  margin-top: 40px;
  font-size: 12px;
  color: var(--ds-text-secondary);
  text-align: center;
}

/* ---------- Narrow screens: sidebar becomes a sliding panel ---------- */

@media (max-width: 1024px) {
  /* the phone menu slides in from the right edge */
  .sidebar {
    left: auto;
    right: 8px;
    transform: translateX(calc(100% + 16px));
    transition: transform 0.28s var(--ds-ease-out-expo);
  }

  .sidebar.mobile-open { transform: none; }

  .mobile-header {
    position: sticky;
    top: 0;
    z-index: 40;
    display: flex;
    align-items: center;
    height: 48px;
    padding: 0 16px;
    gap: 12px;
    justify-content: flex-start;
    background: var(--ds-glass-panel-bg);
    -webkit-backdrop-filter: var(--ds-glass-blur);
    backdrop-filter: var(--ds-glass-blur);
    box-shadow: inset 0 -0.5px 0 var(--ds-hairline);
  }

  .mobile-logo {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    font-weight: 600;
  }

  .mobile-logo .brand-icon {
    width: var(--ds-icon-tile);
    height: var(--ds-icon-tile);
  }

  .mobile-menu-btn {
    order: -1; /* menu sits at the left edge, the title follows it */
    display: inline-flex;
    align-items: center;
    gap: 6px;
    height: var(--ds-control-height);
    padding: 0 12px;
    border: 0;
    border-radius: var(--ds-radius-control);
    background: var(--ds-button-secondary);
    color: var(--ds-foreground);
    font-size: 13px;
    font-weight: 500;
  }

  .mobile-menu-btn .icon { width: 14px; height: 14px; }

  .main-content {
    margin-left: 0;
    padding: 16px 16px 56px;
  }

  .hero-title { font-size: 20px; }
}

@media (max-width: 760px) {
  .case-grid {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .accordion-header { padding: 12px 16px; }
  .accordion-body-inner { padding: 0 16px 14px; }

  .case-badge { min-width: 0; }

  .accordion-meta-main { flex-wrap: wrap; gap: 8px; }
  .case-header-content { flex-basis: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ---- Accessibility and touch (ux-designer: 03, 06, 08, 19) ---- */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  left: 16px;
  top: -64px;
  z-index: 100;
  padding: 8px 12px;
  border-radius: 8px;
  background: var(--ds-background);
  color: var(--ds-foreground);
  box-shadow: inset 0 0 0 1px var(--ds-hairline);
}
.skip-link:focus { top: 8px; }

.accordion-heading { margin: 0; font: inherit; }

button.accordion-header {
  width: 100%;
  margin: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: inherit;
  text-align: left;
}

.search-input::-webkit-search-cancel-button { -webkit-appearance: none; appearance: none; }
.search-clear {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  width: 24px;
  height: 24px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--ds-text-secondary);
  font-size: 12px;
  line-height: 1;
}
.search-clear:hover { background: var(--ds-hover); }
.search-clear[hidden] { display: none; }

.link-btn {
  padding: 0;
  border: 0;
  background: none;
  color: var(--ds-foreground);
  text-decoration: underline;
  font: inherit;
}

@media (max-width: 1024px) {
  /* 44px touch targets on phones (08-mobile-ux); WCAG 2.2 floor is 24px */
  .nav-link,
  .mobile-menu-btn,
  .search-input,
  .btn-small { min-height: 44px; }
}

/* Narrow screens: the count wraps instead of squeezing the title */
.category-header { flex-wrap: wrap; }
.category-title-group { flex-wrap: wrap; min-width: 0; }
.category-title-group .category-count { white-space: nowrap; }

/* Phone menu: the brand block is already in the top bar, so the panel starts with search */
@media (max-width: 1024px) {
  .brand-header { display: none; }
}

/* Phone menu: no expand/collapse-all row; the buttons stay on desktop */
@media (max-width: 1024px) {
  .control-row { display: none; }
}

/* Phone: icon-only menu button, 44px square (touch target), no text label */
@media (max-width: 1024px) {
  .mobile-menu-btn {
    width: 44px;
    padding: 0;
    justify-content: center;
    touch-action: manipulation;
  }
}

/* Case header: the title sits in a shrink-to-fit button, the icon follows it, and the whole row is the click target */
.accordion-heading { position: relative; display: flex; align-items: flex-start; gap: 8px; }
.accordion-heading:hover { background: var(--ds-hover); }
.accordion-heading > .accordion-header {
  flex: 0 1 auto;
  width: auto;
  min-width: 0;
  max-width: calc(100% - 96px); /* leaves room for the icon and the chevron */
  padding-right: 0;
  background: transparent;
}
.accordion-heading > .accordion-header:hover { background: transparent; }
.accordion-heading > .accordion-header::after { content: ""; position: absolute; inset: 0; }
.accordion-heading > .accordion-header .accordion-chevron {
  position: absolute;
  right: 20px;
  top: 50%;
  margin-top: -8px;
}
.source-icon {
  position: relative;
  z-index: 1;
  flex: none;
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  margin-top: 9px; /* centres the 24px icon on the first (title) line: 12px padding + (17.5px line - 24px) / 2 */
  border-radius: 6px;
  color: var(--ds-text-secondary);
}
.source-icon:hover { color: var(--ds-foreground); background: var(--ds-hover); }

@media (max-width: 760px) {
  .accordion-heading > .accordion-header .accordion-chevron { right: 16px; }
}

/* Promo banner 300x600 on the right: only where the main column leaves room (1536px and wider) */
.side-banner { display: none; }
@media (min-width: 1536px) {
  .side-banner {
    display: block;
    position: fixed;
    top: 32px;
    right: 24px;
    width: 300px;
    height: 600px;
    z-index: 5;
  }
}
.side-banner iframe {
  display: block;
  width: 300px;
  height: 600px;
  border: 0;
  border-radius: 16px;
}
