/* Layer order is declared in src/app.html. Component <style> (incl. :global) stays unlayered and wins. */
@layer components {
  .annotation-content, .annotation-contents {
    font-family: 'Inter', sans-serif;
    font-size: 1.5em;

    & > * > .title {
      display: flex;
      box-sizing: border-box;
      inline-size: 100%;
      block-size: auto;
      background-color: #000100;
      color: white;
      border: 5px solid #000000;

      flex-direction: row;
      justify-content: flex-start;
      align-items: flex-start;
      padding: 15px;

      .icon {
        flex: 0;
        block-size: 32px;
        margin-inline-end: 5px;
      }
    }

    & > * > .content {
      display: block;
      box-sizing: border-box;
      inline-size: 100%;
      block-size: auto;
      min-block-size: 300px;
      background-color: transparent;
      color: white;
      border: 5px solid #000000;

      padding: 0 15px 15px 15px;

      /* Tag defaults: `:where(&)` keeps this whole ancestor chain at zero specificity, so any
         utility class below (.text-lg, .text-sm, .text-center, ...) reliably overrides it. */
      :where(&) {
        h1, h2, h3 {
          font-size: 1.5em;
          padding: 0;
          margin: 0;
        }

        h4 {
          font-size: 1em;
          padding: 0;
          margin: 0;
        }

        p {
          font-size: 0.8em;
          line-height: 1.5em;
          padding: 0;
          margin: 0;
        }

        blockquote {
          font-size: 0.85em;
          line-height: 1.4em;
          margin: 10px 0;
          padding: 8px 12px;
          border-inline-start: 3px solid rgba(255, 255, 255, 0.3);
        }
      }

      .separator-1 {
        block-size: 1px;
        background: rgba(255, 255, 255, 0.2);
        margin: 10px 0;
      }

      .separator-2 {
        block-size: 1px;
        background: rgba(255, 255, 255, 0.8);
        margin: 10px 0;
      }
    }

    .warning, .caution, .note {
      background-color: #000000;
      border-color: #000000;
      border-radius: 0;
      border-width: 5px;
      font-size: clamp(0.72rem, 0.48rem + 0.4vw, 1.44rem);

      & > .title {
        font-weight: bold;
        font-size: 3em;
        line-height: 1em;

        & > * {
          margin: 0;
          padding: 0;
          font-size: 1em;
        }

        .icon {
          flex: 0;
          inline-size: auto;
          block-size: 1em;
          margin-inline-end: 5px;
        }
      }

      & > .content {
        font-size: 1.2em;
      }

      .bordered-table {
        border: 2px solid black;
        border-collapse: collapse;
        inline-size: 100%;
        background-color: #eee;
        color: black;

        :where(&) {
          th, td {
            border: 1px solid black;
            padding: 5px;
            text-align: start;
            font-size: clamp(0.72rem, 0.48rem + 0.4vw, 1.44rem);
          }
        }

        &.text-center {
          text-align: center;

          :where(&) {
            th, td {
              text-align: center;
            }
          }
        }
      }

      .separator-1 {
        block-size: 1px;
        background: rgba(255, 255, 255, 0.2);
        margin: 10px 0;
      }

      .separator-2 {
        block-size: 1px;
        background: rgba(255, 255, 255, 0.8);
        margin: 10px 0;
      }
    }

    /* Utilities usable anywhere inside annotation popup content. Plain classes, so they always
       outrank the :where()-wrapped tag defaults above regardless of nesting depth. */
    .text-lg {
      font-size: 1em;
      line-height: 1.5em;
    }

    .text-sm {
      font-size: 0.7em;
      line-height: 1.5em;
    }

    .text-center {
      text-align: center;
    }

    .cell-label {
      font-weight: bold;
      text-align: center;
    }

    .col-50 {
      inline-size: 50%;
    }

    .align-top {
      vertical-align: top;
    }

    .reference {
      color: var(--kia-ev6-color-danger);
    }
  }

  /*
   * Shared OverlayPopup content helpers, used inside `.popup-content` across every
   * annotation-video-player layout (default / PRPO / kia-ev6). Single source instead of the
   * identical `:global(...)` blocks that used to be duplicated in each layout's OverlayPopup.svelte.
   */
  .popup-content > div {
    flex: 1 1 auto;
    inline-size: auto;
    position: relative;
  }

  .popup-content .link-url {
    flex: 1 1 auto;
    display: block;
    inline-size: 100%;
    text-align: center;
    font-size: 1.5625rem;
    font-weight: bold;
    color: black;
    background-color: #eee;
  }

  .popup-content .fit-container {
    inline-size: 100%;
    max-inline-size: 100%;
    block-size: auto;
    margin: auto;
    vertical-align: bottom;
    object-fit: contain;
  }

  .popup-content .info {
    white-space: break-spaces;
    padding: 20px 5px;
  }

  .popup-content .zoomable {
    inline-size: 100%;
    block-size: auto;
    vertical-align: bottom;
    object-fit: contain;
    transform-origin: 0 0;
  }

  .popup-content .note {
    display: block;
    object-fit: contain;
    max-inline-size: 100%;
    max-block-size: 100%;
  }

  .popup-content iframe {
    inline-size: 100%;
    block-size: 100%;
    overflow: visible;
  }

  /*
   * Tab view (image/video switcher) for named-part popups.
   * This markup does NOT sit inside .annotation-content/.annotation-contents — these files are a bare
   * `<div class="tabview-container">` fragment. `nav.tab-nav`/`button.tab-button` are synthesized at
   * runtime by OverlayPopup.svelte's generateTabNav() from the `.tab`/`.tabview-container` structure
   * that originates in the annotation HTML, so they live here rather than as component :global CSS.
   */
  .tabview-container {
    display: flex;
    flex-direction: column;
    inline-size: 100%;
    block-size: 100%;
    position: relative;

    nav.tab-nav {
      position: absolute;
      inset-block-start: 0;
      inset-inline-start: 0;
      inline-size: 100%;
      block-size: 40px;
      display: flex;
      flex-direction: row;
      border-block-end: 1px solid #ccc;
      background-color: #f9f9f9;

      button.tab-button {
        flex: 1 1 auto;
        padding: 8px 12px;
        border: none;
        background: none;
        cursor: pointer;
        font-size: 0.875rem;

        &.active {
          border-block-end: 2px solid #333;
          font-weight: bold;
        }

        &:hover {
          background-color: #eee;
        }

        img {
          inline-size: 16px;
          block-size: 16px;
        }
      }
    }

    .tabview-contents {
      margin-block-start: 40px;
      inline-size: 100%;
      block-size: calc(100% - 40px);
      overflow-y: auto;
    }
  }

  /* Highlight dots that ammWithHighlight() (layouts/default/ammUtils.ts) adds inside popup content.
     This file is global, so the keyframes get a prefixed name instead of a bare `blink`. */
  @keyframes annotation-highlight-blink {
    0%, 100% { opacity: 0.3; }
    50% { opacity: 0.7; }
  }

  .popup-content .highlight-dot.blinking {
    @media (prefers-reduced-motion: no-preference) {
      animation: annotation-highlight-blink 1s infinite;
    }
  }
}
