/* =========================================================================
   MARKET INTELLIGENCE module (Y26 9月 onwards)
   Everything is prefixed .mi- so it cannot leak into the page shell.
   Colours, radii and shadows come from the tokens in page.css.
   ========================================================================= */

/* Brands outside Key Focus (KEY_FOCUS in mi.js) share one neutral accent, so the
   focus brands stand out in the list at a glance. On :root because the drawer
   and dialog are mounted on <body>, outside the page. */
:root {
  --mi-brand-other: #8a94a8;
}

#market-intelligence {
  max-width: calc(1900px * var(--ui));
  margin: 0 auto;
}

/* ---- Monthly observations ------------------------------------------- */
/* Magazine layout: two columns of numbered items, read down the left column
   first (mi.js sets --obs-rows to half the items, rounded up). A large pale
   number anchors each item, a blue rule runs beside its text, thin rules sit
   between items. One column on narrow screens. */
.mi-obs-card {
  border-radius: var(--r-lg);
  background: var(--white);
  box-shadow: var(--sh-card);
  padding: calc(8px * var(--ui)) calc(22px * var(--ui));
}

.mi-obs-list {
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: repeat(var(--obs-rows, 3), auto);
  grid-auto-flow: column;
  column-gap: calc(32px * var(--ui));
}

.mi-obs-list li {
  display: grid;
  grid-template-columns: calc(52px * var(--ui)) 1fr;
  column-gap: calc(12px * var(--ui));
  padding: calc(11px * var(--ui)) 0;
  border-bottom: 1px solid var(--rule);
}

/* no rule under the last item of each column */
.mi-obs-list li:last-child,
.mi-obs-list li.is-col-end { border-bottom: 0; }

.mi-obs-num {
  font: 900 calc(34px * var(--ui))/1 Inter, sans-serif;
  letter-spacing: -.02em;
  color: color-mix(in oklab, var(--accent) 22%, white);
  font-variant-numeric: tabular-nums;
}

.mi-obs-text {
  position: relative;
  display: block;
  min-width: 0;
  padding-left: calc(14px * var(--ui));
}

/* Rule beside the text: blue at the title, fading out downwards, like the
   short underline under the topbar title. */
.mi-obs-text::before {
  content: '';
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: calc(3px * var(--ui));
  border-radius: 2px;
  background: linear-gradient(180deg, var(--accent), transparent);
}

/* The lead-in phrase matches the card title size (.mi-card-title). */
.mi-obs-title {
  display: block;
  margin-bottom: calc(6px * var(--ui));
  font-size: calc(15px * var(--ui));
  font-weight: 800;
  line-height: 1.45;
  color: var(--ink);
}

.mi-obs-body {
  display: block;
  font-size: calc(14px * var(--ui));
  line-height: 1.65;
  color: var(--ink-2);
}

@media (max-width: 1100px) {
  .mi-obs-list { grid-template-columns: 1fr; grid-template-rows: none; grid-auto-flow: row; }
  .mi-obs-list li.is-col-end:not(:last-child) { border-bottom: 1px solid var(--rule); }
}

/* Entrance (mi.js): the items come out one at a time. A waiting item is
   only transparent, so it keeps its space and nothing below moves. */
.mi-obs-list.is-playing { cursor: pointer; }

.mi-obs-list li { transition: opacity .18s ease; }

.mi-obs-list li.is-waiting { opacity: 0; }

.mi-caret {
  display: inline-block;
  width: 2px;
  height: 1.05em;
  margin-left: 2px;
  vertical-align: -0.15em;
  border-radius: 1px;
  background: var(--accent);
  animation: mi-caret-blink 1s steps(1) infinite;
}

@keyframes mi-caret-blink {
  50% { opacity: 0; }
}

/* ---- Filter bar ------------------------------------------------------ */
/* The wrapper sticks under the topbar (--bar-h) so the filters stay reachable
   while the list scrolls. Its 12px top padding is page-coloured, so cards
   scrolling underneath do not show between the topbar and the bar - and
   because it is the wrapper's own box, it never paints over the section
   title above it. */
.mi-filter-sticky {
  position: sticky;
  top: var(--bar-h);
  z-index: 20;
  margin-top: -12px;
  padding-top: 12px;
  background: var(--bg);
}

.mi-filter-bar {
  display: flex;
  align-items: center;
  gap: 10px 14px;
  flex-wrap: wrap;
  padding: calc(14px * var(--ui)) calc(18px * var(--ui));
  border-radius: var(--r-md);
  background: var(--white);
  box-shadow: var(--sh-card);
}

.mi-filter {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: calc(12px * var(--ui));
  font-weight: 700;
  color: var(--ink-3);
}

/* ---- Filter dropdown (custom, so the brand list can show logos) ------- */
/* Closed: the same pill as the topbar month picker, on a light surface. */
.mi-dd {
  position: relative;
}

.mi-dd-btn {
  display: inline-flex;
  align-items: center;
  min-width: 120px;
  max-width: 220px;
  box-sizing: border-box;
  border: 1px solid #d8d8e4;
  background: #fff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%237B7B96' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") no-repeat right 12px center;
  color: var(--ink);
  border-radius: 999px;
  padding: 6px 32px 6px 13px;
  min-height: 32px;
  font-size: calc(12px * var(--ui));
  font-weight: 700;
  font-family: inherit;
  text-align: left;
  cursor: pointer;
  outline: none;
  transition: border-color .16s ease, box-shadow .16s ease;
}

.mi-dd-btn:hover { border-color: rgba(59, 91, 219, 0.34); }

.mi-dd-btn:focus-visible,
.mi-dd-btn[aria-expanded="true"],
.mi-search input:focus-visible {
  border-color: color-mix(in oklab, var(--accent) 56%, white);
  box-shadow: 0 0 0 3px color-mix(in oklab, var(--accent) 14%, transparent);
}

/* A filter that is narrowing the list is tinted like the active brand tab. */
.mi-dd-btn.is-set {
  background-color: rgba(86, 163, 255, 0.11);
  border-color: rgba(59, 91, 219, 0.42);
  color: var(--accent);
}

.mi-dd-value {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
}

.mi-dd-value .mi-dd-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Open: a white panel under the pill. */
.mi-dd-menu {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  z-index: 30;
  min-width: 100%;
  width: max-content;
  max-height: min(380px, 60vh);
  overflow-y: auto;
  overscroll-behavior: contain;
  box-sizing: border-box;
  padding: 6px;
  border: 1px solid var(--rule);
  border-radius: 12px;
  background: #fff;
  box-shadow: var(--sh-hover);
}

.mi-dd-menu[hidden] { display: none; }

.mi-dd-group {
  padding: 9px 10px 4px;
  font-size: 10.5px;
  font-weight: 800;
  letter-spacing: 0.06em;
  color: var(--ink-4);
  white-space: nowrap;
}

.mi-dd-opt {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 6px 10px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--ink);
  font-size: 11.5px;
  font-weight: 650;
  font-family: inherit;
  text-align: left;
  white-space: nowrap;
  cursor: pointer;
  outline: none;
}

.mi-dd-opt:hover,
.mi-dd-opt:focus-visible {
  background: var(--surf);
}

.mi-dd-opt[aria-selected="true"] {
  background: color-mix(in oklab, var(--accent) 10%, white);
  color: var(--accent-strong);
}

/* Fixed-width logo slot so names line up, logos or not. */
.mi-dd-logo {
  width: 20px;
  height: 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.mi-dd-logo img {
  max-width: 20px;
  max-height: 12px;
  object-fit: contain;
  display: block;
}

.mi-dd-count {
  margin-left: auto;
  padding-left: 16px;
  font-size: 11px;
  font-weight: 700;
  color: var(--ink-4);
  font-variant-numeric: tabular-nums;
}

.mi-dd-opt[aria-selected="true"] .mi-dd-count { color: inherit; opacity: .7; }

.mi-search {
  position: relative;
  flex: 1 1 220px;
  max-width: 340px;
}

.mi-search svg {
  position: absolute;
  left: 13px;
  top: 50%;
  transform: translateY(-50%);
  width: 14px;
  height: 14px;
  color: var(--ink-4);
  pointer-events: none;
}

.mi-search input {
  width: 100%;
  box-sizing: border-box;
  border: 1px solid #d8d8e4;
  border-radius: 999px;
  padding: 7px 13px 7px 34px;
  font-size: calc(12px * var(--ui));
  font-weight: 600;
  font-family: inherit;
  color: var(--ink);
  background: #fff;
  outline: none;
}

.mi-search input::placeholder { color: var(--ink-4); font-weight: 500; }

.mi-filter-result {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: 12px;
  font-size: calc(12px * var(--ui));
  font-weight: 700;
  color: var(--ink-3);
  white-space: nowrap;
}

.mi-filter-result b { color: var(--ink); font-variant-numeric: tabular-nums; }

.mi-reset {
  border: 0;
  background: none;
  padding: 0;
  color: var(--accent);
  font: inherit;
  cursor: pointer;
}

.mi-reset:hover { text-decoration: underline; }

/* ---- Event list: card grid ------------------------------------------- */
.mi-list {
  display: grid;
  grid-template-columns: repeat(var(--cols), minmax(0, 1fr));
  gap: calc(16px * var(--ui));
  margin-top: 14px;
}

/* Card columns by page width: 5 on wide screens, 4 on laptops (even at
   150% Windows scaling, ~1280px), then 3 / 2 / 1. */
#market-intelligence { --cols: 4; }
@media (min-width: 1760px) { #market-intelligence { --cols: 5; } }
@media (max-width: 1199px) { #market-intelligence { --cols: 3; } }
@media (max-width: 959px)  { #market-intelligence { --cols: 2; } }
@media (max-width: 639px)  { #market-intelligence { --cols: 1; } }

/* White card with a soft shadow, a 3px brand-colour rule along the top and
   the cover image across the top half. */
.mi-card {
  --insight-accent: var(--mi-brand-other);
  position: relative;
  overflow: hidden;
  border: 1px solid #e3e8f0;
  border-top: 3px solid var(--insight-accent);
  border-radius: var(--r-md);
  background: #fff;
  box-shadow: 0 5px 18px rgba(40, 61, 95, .07);
  transition: box-shadow .18s ease, border-color .18s ease;
}

.mi-card-face {
  display: flex;
  flex-direction: column-reverse;
  justify-content: flex-end;
  height: 100%;
  box-sizing: border-box;
  cursor: pointer;
  outline: none;
}

.mi-card:hover {
  box-shadow: var(--sh-hover);
  border-color: color-mix(in oklab, var(--insight-accent) 30%, #e3e8f0);
  border-top-color: var(--insight-accent);
}

.mi-card-face:focus-visible {
  box-shadow: inset 0 0 0 2px color-mix(in oklab, var(--accent) 56%, white);
}

/* The card whose details are open in the drawer. */
.mi-card.is-current {
  border-color: color-mix(in oklab, var(--insight-accent) 55%, #e3e8f0);
  border-top-color: var(--insight-accent);
  box-shadow: var(--sh-lift);
}

.mi-card-main {
  display: grid;
  gap: calc(7px * var(--ui));
  min-width: 0;
  padding: calc(14px * var(--ui)) calc(16px * var(--ui)) calc(16px * var(--ui));
}

.mi-brand {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: calc(11.5px * var(--ui));
  font-weight: 800;
  letter-spacing: 0.02em;
  /* Mixing bright accents with the text colour keeps brand labels legible. */
  color: color-mix(in oklab, var(--insight-accent) 70%, var(--text));
}

.mi-brand img {
  height: 14px;
  width: auto;
  max-width: 26px;
  object-fit: contain;
  display: block;
}

.mi-brand-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--insight-accent);
}

.mi-card-title {
  margin: 0;
  font-size: calc(15px * var(--ui));
  font-weight: 800;
  line-height: 1.45;
  letter-spacing: -0.005em;
  color: var(--ink);
}

/* Card text: two lines on every card, always reading as "there is more".
   Structured events show their summary sentence followed by "…";
   single-paragraph events show the paragraph, cut with "…" at line two.
   The fixed two-line height keeps titles and tags lined up across a row. */
.mi-card-lead {
  margin: 0;
  min-height: calc(2 * 1.65em);
  font-size: calc(12.5px * var(--ui));
  line-height: 1.65;
  color: var(--ink-2);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.mi-card-lead.has-more::after {
  content: '…';
  margin-left: 1px;
}

.mi-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 2px;
}

.mi-tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 7px;
  border-radius: 999px;
  background: var(--surf);
  color: var(--ink-2);
  font-size: calc(11px * var(--ui));
  font-weight: 700;
  line-height: 1.5;
  white-space: nowrap;
}

/* Region reads as a different kind of tag: outlined, with a pin glyph. */
.mi-tag.is-region {
  background: transparent;
  border: 1px solid var(--rule);
  color: var(--ink-3);
  padding: 2px 5px;
}


/* A tag that matches the active filter is tinted. */
.mi-tag.is-match {
  background: color-mix(in oklab, var(--accent) 12%, white);
  color: var(--accent-strong);
}

.mi-tag.is-region.is-match {
  border-color: color-mix(in oklab, var(--accent) 40%, white);
}

mark.mi-hit {
  background: #fff1b8;
  color: inherit;
  border-radius: 3px;
  padding: 0 1px;
}

/* ---- Cover image ----------------------------------------------------- */
/* The event's first image at 16:9 across the top of the card, with an
   image-count badge. */
.mi-thumb {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  background: var(--rule-soft);
}

.mi-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center 30%;
  display: block;
  transition: transform .35s ease;
}

.mi-card:hover .mi-thumb:not(.is-empty) img { transform: scale(1.04); }

.mi-thumb-count {
  position: absolute;
  right: 8px;
  bottom: 8px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 7px;
  border-radius: 999px;
  background: rgba(17, 19, 24, .62);
  color: #fff;
  font-size: 10.5px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1.5;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

.mi-thumb-count svg { width: 11px; height: 11px; }

/* No pictures: a brand-tinted tile with the logo or name. */
.mi-thumb.is-empty {
  display: grid;
  place-items: center;
  background: color-mix(in oklab, var(--insight-accent) 9%, #fff);
}

.mi-thumb.is-empty img {
  width: auto;
  height: auto;
  max-width: 34%;
  max-height: 30%;
  object-fit: contain;
  opacity: .85;
}

.mi-thumb.is-empty span {
  padding: 0 10px;
  font-size: 15px;
  font-weight: 800;
  letter-spacing: .02em;
  text-align: center;
  color: color-mix(in oklab, var(--insight-accent) 70%, var(--text));
}

.mi-empty {
  padding: 48px 24px;
  border-radius: var(--r-lg);
  background: var(--white);
  box-shadow: var(--sh-card);
  text-align: center;
  color: var(--ink-3);
  font-size: 13px;
  line-height: 1.8;
}

.mi-empty strong {
  display: block;
  margin-bottom: 4px;
  color: var(--ink);
  font-size: 15px;
}

.mi-empty .mi-reset { font-weight: 700; }

/* ---- Detail content (inside the drawer) ------------------------------ */
.mi-detail {
  --insight-accent: var(--mi-brand-other);
  display: grid;
  gap: calc(16px * var(--ui));
}

.mi-detail-title {
  margin: 0;
  font-size: calc(19px * var(--ui));
  font-weight: 800;
  line-height: 1.4;
  letter-spacing: -0.01em;
  color: var(--ink);
}

.mi-detail-lead {
  margin: 0;
  padding-left: calc(14px * var(--ui));
  border-left: 3px solid var(--insight-accent);
  font-size: calc(14px * var(--ui));
  font-weight: 600;
  line-height: 1.75;
  color: var(--ink);
}

.mi-detail-body {
  font-size: calc(13px * var(--ui));
  line-height: 1.8;
  color: var(--ink-2);
}

.mi-detail-body p { margin: 0 0 8px; }

.mi-detail-body strong { color: var(--ink); font-weight: 800; }

.mi-body-list,
.mi-body-list ul {
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 8px;
}

.mi-body-list ul { margin-top: 6px; gap: 5px; }

.mi-body-list li {
  position: relative;
  padding-left: 16px;
}

.mi-body-list li::before {
  content: '';
  position: absolute;
  top: calc(10px * var(--ui));
  left: 4px;
  width: 5px;
  height: 5px;
  border-radius: 999px;
  background: var(--insight-accent);
}

.mi-body-list ul li::before {
  width: 5px;
  height: 1.5px;
  border-radius: 1px;
  top: calc(12px * var(--ui));
  background: var(--ink-4);
}

.mi-section-label {
  margin: 4px 0 -4px;
  font-size: calc(11px * var(--ui));
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-4);
}

.mi-gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(calc(120px * var(--ui)), 1fr));
  gap: calc(8px * var(--ui));
}

.mi-gallery button {
  padding: 0;
  border: 0;
  border-radius: var(--r-xs);
  overflow: hidden;
  background: var(--rule-soft);
  aspect-ratio: 3 / 4;
  cursor: zoom-in;
}

.mi-gallery img,
.mi-gallery-preview {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: top center;
  display: block;
  transition: transform .25s ease;
}

.mi-gallery button:hover img,
.mi-gallery button:hover .mi-gallery-preview { transform: scale(1.04); }

.mi-gallery button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---- Detail drawer: slides over the page, the list is not resized ---- */
.mi-overlay {
  position: fixed;
  inset: 0;
  z-index: 1100;
  background: rgba(12, 18, 28, 0.38);
  opacity: 0;
  transition: opacity .22s ease;
}

.mi-overlay.is-open { opacity: 1; }

.mi-drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 1101;
  width: min(calc(720px * var(--ui)), 100vw);
  display: flex;
  flex-direction: column;
  background: var(--white);
  box-shadow: -18px 0 48px rgba(8, 14, 24, 0.22);
  transform: translateX(100%);
  transition: transform .26s cubic-bezier(.2, .8, .2, 1);
}

.mi-drawer.is-open { transform: none; }

/* Drawer header / scroll body / footer. */
.mi-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: calc(12px * var(--ui));
  padding: calc(16px * var(--ui)) calc(22px * var(--ui));
  border-bottom: 1px solid var(--rule);
}

.mi-panel-body {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: calc(20px * var(--ui)) calc(22px * var(--ui)) calc(26px * var(--ui));
}

.mi-panel-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: calc(12px * var(--ui));
  padding: calc(12px * var(--ui)) calc(22px * var(--ui));
  border-top: 1px solid var(--rule);
  font-size: calc(12px * var(--ui));
  font-weight: 700;
  color: var(--ink-3);
}

.mi-icon-btn {
  width: calc(32px * var(--ui));
  height: calc(32px * var(--ui));
  border: 0;
  border-radius: 10px;
  background: var(--surf);
  color: var(--ink-2);
  font-size: calc(16px * var(--ui));
  line-height: 1;
  cursor: pointer;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.mi-icon-btn:hover { background: var(--rule); color: var(--ink); }

.mi-step-btn {
  border: 1px solid #d8d8e4;
  background: #fff;
  color: var(--ink);
  border-radius: 999px;
  padding: calc(7px * var(--ui)) calc(14px * var(--ui));
  font-size: calc(12px * var(--ui));
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
}

.mi-step-btn:hover:not(:disabled) { border-color: rgba(59, 91, 219, 0.42); color: var(--accent); }
.mi-step-btn:disabled { opacity: .4; cursor: default; }

/* ---- Image lightbox (same look as the dashboard's insight lightbox) --- */
.mi-lightbox {
  position: fixed;
  inset: 0;
  z-index: 1200;
  display: grid;
  place-items: center;
  padding: 32px;
  background: rgba(12, 18, 28, 0.72);
}

.mi-lightbox[hidden] { display: none; }

.mi-lightbox-dialog {
  position: relative;
  display: grid;
  gap: 10px;
  justify-items: center;
  max-width: min(92vw, 1100px);
  padding: 14px;
  border-radius: 14px;
  background: var(--surface);
  box-shadow: 0 24px 60px rgba(8, 14, 24, 0.42);
}

.mi-lightbox-dialog img {
  display: block;
  max-width: 100%;
  max-height: calc(86vh - 70px);
  object-fit: contain;
  border-radius: 8px;
}

.mi-lightbox-caption {
  font-size: calc(12px * var(--ui));
  font-weight: 600;
  color: var(--ink-2);
  text-align: center;
}

.mi-lightbox .mi-icon-btn.is-close { position: absolute; top: -14px; right: -14px; background: #fff; box-shadow: var(--sh-lift); }

.mi-lightbox-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: calc(40px * var(--ui));
  height: calc(40px * var(--ui));
  border: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, .92);
  box-shadow: var(--sh-lift);
  font-size: calc(18px * var(--ui));
  cursor: pointer;
}

.mi-lightbox-nav.is-prev { left: -20px; }
.mi-lightbox-nav.is-next { right: -20px; }

body.mi-lock { overflow: hidden; }

@media (max-width: 900px) {
  .mi-filter-sticky { position: static; }
  .mi-filter-result { margin-left: 0; }
}
