@layer base, layout, components, utilities, pages;

@layer components {
  /* Button variants and adjustments */
  .filters__actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.85rem;
    align-items: center;
  }

  .filters__actions .btn {
    --btn-radius: var(--radius-md);
    --btn-padding-y: 0.65rem;
    --btn-padding-x: 1.4rem;
    min-width: 130px;
    font-size: 0.95rem;
    justify-content: center;
  }

  .filters__actions .btn:not(.btn--primary) {
    --btn-bg: var(--color-surface-muted);
    --btn-border: rgba(59, 130, 246, 0.28);
    --btn-color: #1d4ed8;
  }

  .filters__actions .btn:not(.btn--primary):hover,
  .filters__actions .btn:not(.btn--primary):focus-visible {
    --btn-border: rgba(59, 130, 246, 0.45);
    --btn-bg: rgba(59, 130, 246, 0.18);
  }

  .btn.qa-toggle-all {
    --btn-radius: var(--radius-md);
    --btn-padding-y: 0.55rem;
    --btn-padding-x: 1.1rem;
    --btn-bg: var(--color-surface-muted);
    --btn-border: var(--color-border);
    --btn-color: var(--color-text);
    font-size: 0.9rem;
  }

  .btn.qa-toggle-all:hover,
  .btn.qa-toggle-all:focus-visible {
    --btn-border: rgba(37, 99, 235, 0.42);
    --btn-bg: rgba(59, 130, 246, 0.12);
    --btn-color: #1d4ed8;
  }

  /* Search form */
  .im-search {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 8px;
    margin: 12px 0 16px;
  }

  .im-search__label {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    border: 0;
  }

  .im-search__input {
    border: 1px solid rgba(15, 23, 42, 0.18);
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    font-size: 0.95rem;
  }

  .im-search__input:focus-visible {
    border-color: rgba(59, 130, 246, 0.6);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.18);
    outline: none;
  }

  .im-search__submit {
    --btn-radius: var(--radius-sm);
    padding-inline: 1.25rem;
  }

  /* Card deck */
  /* Chip tokens */
  .chips {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin: 0.5rem 0 0;
  }

  .chip {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    border-radius: var(--radius-pill);
    border: 1px solid #d9e6ff;
    background: #f4f8ff;
    color: #0b1a3a;
    padding: 0.4rem 0.85rem;
    font-size: 0.8rem;
    font-weight: 600;
    transition: border-color 0.2s ease, background 0.2s ease, color 0.2s ease;
  }

  .chip:focus-visible {
    outline: 2px solid var(--color-primary);
    outline-offset: 2px;
  }

  .chip--material {
    border-color: #cfe0ff;
  }

  .chip--defect {
    border-color: #ffd5d5;
    background: #fff6f6;
  }

  .chip--guide_type {
    border-color: #e0d5ff;
    background: #f8f6ff;
  }

  .chip--qa_topic {
    border-color: #d5f0ff;
    background: #f6fbff;
  }

  .chip--industry {
    border-color: #d5ffd9;
    background: #f4fff6;
  }

  /* Filter form */
  .filters {
    display: grid;
    gap: clamp(16px, 3vw, 28px);
    padding: clamp(20px, 3vw, 34px);
    margin: clamp(16px, 3vw, 36px) 0;
    border-radius: 20px;
    border: 1px solid var(--color-border);
    background: linear-gradient(135deg, rgba(236, 246, 255, 0.95) 0%, #ffffff 60%);
    box-shadow: var(--shadow-sm);
  }

  .filters__group {
    display: flex;
    flex-direction: column;
    gap: 0.65rem;
    margin: 0;
  }

  .filters__label {
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: rgba(15, 23, 42, 0.58);
  }

  .filters__field-row {
    display: grid;
    gap: 0.75rem;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  }

  .filters select,
  .filters input[type="search"] {
    width: 100%;
    min-height: 48px;
    padding: 0.7rem 1rem;
    border-radius: 14px;
    border: 1px solid rgba(59, 130, 246, 0.18);
    background: #ffffff;
    font-size: 0.95rem;
    line-height: 1.5;
    color: var(--color-text);
    box-shadow: inset 0 1px 2px rgba(15, 23, 42, 0.05);
    transition: border-color 0.2s ease, box-shadow 0.2s ease, transform 0.2s ease;
  }

  .filters select:hover,
  .filters input[type="search"]:hover {
    border-color: rgba(14, 165, 233, 0.45);
  }

  .filters select:focus-visible,
  .filters input[type="search"]:focus-visible {
    border-color: rgba(59, 130, 246, 0.7);
    box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.12);
    outline: none;
  }

  .filters select {
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath fill='%232563eb' d='M4.998 5.75a.74.74 0 0 1-.53-.22L.22 1.282A.75.75 0 0 1 1.28.22L5 3.94 8.72.22a.75.75 0 0 1 1.06 1.06L5.53 5.53a.74.74 0 0 1-.532.22Z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 1rem center;
    background-size: 10px 6px;
    padding-right: 2.75rem;
  }

  .filters select::-ms-expand {
    display: none;
  }

  .filters .chips {
    margin: 0;
    display: flex;
    flex-wrap: wrap;
    gap: 0.6rem;
  }

  .filters .chip {
    border-radius: 999px;
    border: 1px solid rgba(59, 130, 246, 0.28);
    background: rgba(59, 130, 246, 0.08);
    color: #1d4ed8;
  }

  .filters .chip input[type="checkbox"] {
    accent-color: #2563eb;
  }

  .filters .chip input[type="checkbox"]:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.25);
    border-radius: 50%;
  }

  @media (max-width: 900px) {
    .filters {
      padding: 20px;
      border-radius: 18px;
    }
  }

  @media (max-width: 640px) {
    .filters__field-row {
      grid-template-columns: 1fr;
    }

    .filters__actions .btn {
      flex: 1 1 45%;
    }
  }

  /* Table of contents and anchor offset */
  .toc {
    border: 1px solid #e6e6e6;
    padding: 12px;
    background: #fff;
    margin: 12px 0 16px;
  }

  .toc__list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: grid;
    gap: 8px;
  }

  .toc__item {
    font-size: 14px;
  }

  .toc__item a {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    color: inherit;
    text-decoration: none;
    font-weight: 600;
  }

  .toc__index {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 2.2ch;
    padding: 2px 8px;
    border-radius: var(--radius-pill);
    background: rgba(37, 99, 235, 0.12);
    color: #1d4ed8;
    font-size: 0.78rem;
    font-weight: 700;
    letter-spacing: 0.05em;
  }

  .toc__item--child a {
    color: rgba(15, 23, 42, 0.72);
  }

  .toc__item--child {
    padding-left: 8px;
  }

  .toc__item--child .toc__index {
    background: rgba(148, 163, 184, 0.16);
    color: #475569;
  }

  .toc__text {
    flex: 1 1 auto;
  }

  .entry-content h2[id],
  .entry-content h3[id] {
    scroll-margin-top: 80px;
  }

  /* Skip link */
  .skip-link {
    position: absolute;
    left: -9999px;
    top: auto;
    width: 1px;
    height: 1px;
    overflow: hidden;
  }

  .skip-link:focus {
    position: fixed;
    left: 12px;
    top: 12px;
    width: auto;
    height: auto;
    background: #000;
    color: #fff;
    padding: 8px 12px;
    z-index: 2000;
  }

  /* Content defaults */

  /* Breadcrumbs handled in style.css to avoid duplicate definitions */
  .entry-content h2 {
    font-size: 24px;
    margin: 24px 0 12px;
    border-left: 6px solid var(--color-primary);
    padding-left: 12px;
    line-height: 1.3;
  }

  .entry-content h3 {
    font-size: 18px;
    margin: 18px 0 8px;
    border-left: 4px solid var(--color-primary);
    padding-left: 10px;
  }

  .entry-content h4 {
    font-size: 16px;
    margin: 14px 0 6px;
  }

  .entry-content p {
    line-height: 1.9;
    margin: 0 0 1em;
  }

  .entry-content ul,
  .entry-content ol {
    padding-left: 1.25em;
    margin: 0 0 1em;
  }

  .entry-content table {
    border-collapse: collapse;
    width: 100%;
    margin: 16px 0;
  }

  .entry-content th,
  .entry-content td {
    border: 1px solid #e0e0e0;
    padding: 10px 12px;
    text-align: left;
  }

  .entry-content th {
    background: #f6f8fb;
  }

  /* Company page components */
  .company__head h1 {
    margin: 0 0 6px;
  }

  .company__lead {
    color: #444;
    margin: 0 0 16px;
  }

  .timeline {
    list-style: none;
    margin: 0;
    padding: 0;
    border-left: 2px solid #e6e6e6;
  }

  .timeline li {
    display: grid;
    grid-template-columns: 120px 1fr;
    gap: 12px;
    padding: 10px 0 10px 12px;
    position: relative;
  }

  .timeline li::before {
    content: "";
    position: absolute;
    left: -5px;
    top: 18px;
    width: 8px;
    height: 8px;
    background: var(--color-primary);
  }

  .timeline__date {
    color: #666;
  }

  .offices .office {
    padding: 12px;
    border: 1px solid #e6e6e6;
  }

  .executives {
    list-style: none;
    margin: 0;
    padding: 0;
    display: grid;
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .executive {
    display: grid;
    grid-template-columns: 120px 1fr;
    gap: 16px;
    padding: 12px;
    border: 1px solid #e6e6e6;
  }

  .executive__media img {
    width: 100%;
    height: auto;
    display: block;
  }

  .executive__name {
    font-size: 18px;
  }

  @media (min-width: 900px) {
    .executives {
      grid-template-columns: 1fr 1fr;
    }
  }

  /* Strengths */
  .feature-list {
    list-style: none;
    margin: 0;
    padding: 0;
  }

  .feature {
    border: 1px solid #e6e6e6;
    background: #fff;
    padding: 16px;
  }

  .feature__title {
    font-size: 16px;
    font-weight: 800;
    margin: 0 0 6px;
  }

  .feature__text {
    margin: 0;
    color: #444;
    line-height: 1.7;
  }

  /* QA accordion */
  .qa-group {
    margin: 16px 0 24px;
  }

  .qa-group__head {
    font-size: 18px;
    margin: 0 0 8px;
    border-left: 4px solid var(--color-primary);
    padding-left: 10px;
  }

  .qa-list {
    list-style: none;
    padding-left: 0;
    margin: 0;
    display: grid;
    gap: 8px;
  }

  .qa-item {
    list-style: none;
  }

  .qa-accordion {
    border: 1px solid #e6e6e6;
    background: #fff;
  }

  .qa-q {
    display: flex;
    gap: 8px;
    align-items: center;
    padding: 10px 12px;
    cursor: pointer;
    list-style: none;
    position: relative;
  }

  .qa-q::-webkit-details-marker {
    display: none;
  }

  .qa-q__label {
    font-weight: 900;
    color: var(--color-primary);
  }

  .qa-accordion > .qa-q::after {
    content: "+";
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    font-weight: 900;
    color: #0a1a33;
  }

  .qa-accordion[open] > .qa-q::after {
    content: "−";
  }

  .qa-a {
    border-top: 1px solid #eee;
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 8px;
    padding: 10px 12px;
  }

  .qa-a__label {
    font-weight: 900;
    color: #0a1a33;
  }

  .qa-more {
    font-size: 13px;
    text-decoration: underline;
    text-underline-offset: 2px;
  }
}
