/* GSM Structural Assistant — presentation layer only */
body.gsm-ai-open { overflow: hidden; }

#gsm-ai-root { position: fixed; inset: 0; z-index: 100000; pointer-events: none; }
#gsm-ai-root.is-open { pointer-events: auto; }

.gsm-ai-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.58);
  backdrop-filter: blur(8px);
  opacity: 0;
  animation: gsm-ai-fade-in 180ms ease forwards;
}

.gsm-ai-dialog {
  position: absolute;
  top: 50%;
  left: 50%;
  width: min(920px, calc(100vw - 32px));
  max-height: min(860px, calc(100vh - 32px));
  transform: translate(-50%, -48%);
  display: grid;
  grid-template-rows: auto auto auto auto minmax(220px, 1fr) auto auto;
  overflow: hidden;
  border: 1px solid color-mix(in srgb, var(--gsm-teal, #087f8c) 20%, transparent);
  border-radius: 28px;
  background: #ffffff;
  color: var(--gsm-navy, #0f3142);
  box-shadow: 0 32px 100px rgba(15, 23, 42, 0.30);
  opacity: 0;
  animation: gsm-ai-dialog-in 220ms ease forwards;
}

.gsm-ai-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 24px 28px 18px;
  border-bottom: 1px solid #e3edf0;
  background: linear-gradient(135deg, #fbfeff 0%, #f1fbfb 52%, #eef8f6 100%);
}

.gsm-ai-brand { display: flex; align-items: center; gap: 14px; min-width: 0; }
.gsm-ai-brand-icon {
  display: grid;
  place-items: center;
  width: 52px;
  height: 52px;
  flex: 0 0 52px;
  padding: 2px;
  overflow: hidden;
  border: 1px solid rgba(8, 127, 140, 0.18);
  border-radius: 16px;
  background: #ffffff;
  box-shadow: 0 10px 24px rgba(15, 49, 66, 0.12);
}
.gsm-ai-brand-icon img { display: block; width: 100%; height: 100%; object-fit: contain; }
.gsm-ai-kicker { margin: 0 0 2px; color: #61717e; font-size: 12px; font-weight: 750; letter-spacing: .08em; text-transform: uppercase; }
.gsm-ai-model-line { margin: 3px 0 0; color: #6d7f8a; font-size: 11px; line-height: 1.35; font-weight: 700; }
.gsm-ai-header h2 { margin: 0; color: var(--gsm-navy, #0f3142); font-size: clamp(21px, 2.5vw, 29px); line-height: 1.2; }
.gsm-ai-close {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  flex: 0 0 44px;
  padding: 0;
  line-height: 0;
  border: 1px solid #d7e5e9;
  border-radius: 14px;
  background: #fff;
  color: #344451;
  cursor: pointer;
  transition: border-color 160ms ease, color 160ms ease, background 160ms ease, transform 160ms ease;
}
.gsm-ai-close:hover { border-color: var(--gsm-teal, #087f8c); background: #f2fbfb; color: var(--gsm-teal-dark, #045e69); transform: translateY(-1px); }
.gsm-ai-close svg { display: block; width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }

.gsm-ai-country { display: flex; align-items: center; gap: 13px; margin: 18px 28px 0; padding: 13px 16px; border: 1px solid #dde9ec; border-radius: 18px; background: #f7fcfc; }
.gsm-ai-flag { font-size: 30px; line-height: 1; }
.gsm-ai-country-copy { display: grid; gap: 2px; min-width: 0; }
.gsm-ai-country-copy strong { color: #1e2b36; font-size: 16px; }
.gsm-ai-country-copy span { overflow: hidden; color: #60717e; font-size: 13px; text-overflow: ellipsis; white-space: nowrap; }
.gsm-ai-description { margin: 12px 28px 0; color: #667681; font-size: 14px; line-height: 1.55; }

.gsm-ai-quick-wrap { padding: 14px 28px 12px; }
.gsm-ai-section-label { margin: 0 0 9px; color: #44545f; font-size: 12px; font-weight: 800; letter-spacing: .05em; text-transform: uppercase; }
.gsm-ai-quick-list { display: flex; gap: 8px; overflow-x: auto; padding: 2px 2px 5px; scrollbar-width: thin; }
.gsm-ai-chip { flex: 0 0 auto; border: 1px solid #d9e6e9; border-radius: 999px; padding: 9px 13px; background: #fff; color: #40505c; font: inherit; font-size: 13px; font-weight: 700; cursor: pointer; transition: border-color 160ms ease, background 160ms ease, color 160ms ease, transform 160ms ease; }
.gsm-ai-chip:hover { border-color: var(--gsm-teal, #087f8c); background: var(--gsm-teal-soft, #dff6f6); color: var(--gsm-teal-dark, #045e69); transform: translateY(-1px); }
.gsm-ai-chip:disabled { cursor: wait; opacity: .55; transform: none; }

.gsm-ai-conversation { overflow-y: auto; margin: 0 16px; padding: 18px 12px 22px; border-top: 1px solid #edf2f4; background: linear-gradient(#fff, #fbfdfd); scroll-behavior: smooth; }
.gsm-ai-message { display: flex; align-items: flex-start; gap: 10px; margin: 0 0 16px; }
.gsm-ai-message-user { flex-direction: row-reverse; }
.gsm-ai-message-content { display: grid; gap: 7px; min-width: 0; max-width: min(74ch, 82%); }
.gsm-ai-message-user .gsm-ai-message-content { justify-items: end; }
.gsm-ai-avatar { display: grid; place-items: center; width: 34px; height: 34px; flex: 0 0 34px; border-radius: 11px; background: #e5f6f3; color: #287f72; font-size: 10px; font-weight: 850; }
.gsm-ai-message-user .gsm-ai-avatar { background: #fff1b8; color: #8a5b00; }
.gsm-ai-bubble { width: fit-content; max-width: 100%; padding: 13px 15px; border: 1px solid #dce8eb; border-radius: 6px 18px 18px 18px; background: #fff; color: #33434f; box-shadow: 0 7px 20px rgba(31, 51, 65, .055); font-size: 14px; line-height: 1.65; overflow-wrap: anywhere; }
.gsm-ai-message-user .gsm-ai-bubble { border-color: #f0d36a; border-radius: 18px 6px 18px 18px; background: #fff8dc; color: #24333d; box-shadow: 0 7px 20px rgba(163, 111, 0, .08); }
.gsm-ai-bubble p { margin: 0 0 11px; }
.gsm-ai-bubble p:last-child { margin-bottom: 0; }
.gsm-ai-bubble h3,
.gsm-ai-bubble h4,
.gsm-ai-bubble h5 { margin: 15px 0 7px; color: var(--gsm-navy, #0f3142); line-height: 1.35; }
.gsm-ai-bubble h3:first-child,
.gsm-ai-bubble h4:first-child,
.gsm-ai-bubble h5:first-child { margin-top: 0; }
.gsm-ai-bubble h3 { font-size: 17px; }
.gsm-ai-bubble h4 { font-size: 15px; }
.gsm-ai-bubble h5 { font-size: 14px; }
.gsm-ai-bubble strong { color: #1c3743; font-weight: 800; }
.gsm-ai-bubble code { padding: 2px 5px; border-radius: 6px; background: #edf7f7; color: var(--gsm-teal-dark, #045e69); font: 600 .92em/1.4 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.gsm-ai-bubble ul,
.gsm-ai-bubble ol { margin: 4px 0 12px; padding-inline-start: 22px; }
.gsm-ai-bubble li + li { margin-top: 6px; }
.gsm-ai-bubble li::marker { color: var(--gsm-teal, #087f8c); font-weight: 800; }
.gsm-ai-typing { display: inline-flex; align-items: center; gap: 5px; min-height: 20px; }
.gsm-ai-typing i { width: 7px; height: 7px; border-radius: 50%; background: var(--gsm-teal, #087f8c); animation: gsm-ai-dot 1s ease-in-out infinite; }
.gsm-ai-typing i:nth-child(2) { animation-delay: .15s; }
.gsm-ai-typing i:nth-child(3) { animation-delay: .3s; }

.gsm-ai-message-actions { display: flex; align-items: center; gap: 4px; padding-inline: 4px; opacity: .78; transition: opacity 160ms ease; }
.gsm-ai-message:hover .gsm-ai-message-actions,
.gsm-ai-message:focus-within .gsm-ai-message-actions { opacity: 1; }
.gsm-ai-message-action { display: inline-flex; align-items: center; gap: 5px; padding: 5px 7px; border: 0; border-radius: 8px; background: transparent; color: #6a7b85; font: inherit; font-size: 11px; font-weight: 750; cursor: pointer; }
.gsm-ai-message-action:hover { background: #eef8f8; color: var(--gsm-teal-dark, #045e69); }
.gsm-ai-message-action svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.gsm-ai-composer { margin: 0 28px; padding: 12px; border: 1px solid #d8e6e9; border-radius: 19px; background: #fff; box-shadow: 0 10px 28px rgba(39, 58, 70, .08); }
.gsm-ai-composer:focus-within { border-color: var(--gsm-teal, #087f8c); box-shadow: 0 10px 30px rgba(8, 127, 140, .12); }
.gsm-ai-composer textarea { width: 100%; min-height: 54px; max-height: 150px; resize: vertical; border: 0; outline: 0; background: transparent; color: #263641; font: inherit; font-size: 15px; line-height: 1.5; }
.gsm-ai-composer textarea::placeholder { color: #8897a1; }
.gsm-ai-composer-footer { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 7px; }
.gsm-ai-limit { color: #85939c; font-size: 11px; }
.gsm-ai-send { display: inline-flex; align-items: center; gap: 8px; border: 0; border-radius: 12px; padding: 10px 15px; background: linear-gradient(135deg, var(--gsm-teal-dark, #045e69), var(--gsm-teal, #087f8c)); color: #fff; font: inherit; font-size: 13px; font-weight: 800; cursor: pointer; box-shadow: 0 7px 18px rgba(8, 127, 140, .23); transition: transform 160ms ease, box-shadow 160ms ease, filter 160ms ease; }
.gsm-ai-send:hover { filter: brightness(1.05); transform: translateY(-1px); box-shadow: 0 10px 22px rgba(8, 127, 140, .27); }
.gsm-ai-send:disabled { cursor: wait; opacity: .62; transform: none; }
.gsm-ai-send svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linejoin: round; }
.gsm-ai-note { margin: 11px 28px 18px; color: #7b8992; font-size: 11px; line-height: 1.45; text-align: center; }

.gsm-ai-dialog :focus-visible { outline: 3px solid rgba(8, 127, 140, .30); outline-offset: 3px; }

@keyframes gsm-ai-fade-in { to { opacity: 1; } }
@keyframes gsm-ai-dialog-in { to { opacity: 1; transform: translate(-50%, -50%); } }
@keyframes gsm-ai-dot { 0%, 60%, 100% { transform: translateY(0); opacity: .45; } 30% { transform: translateY(-4px); opacity: 1; } }

@media (max-width: 680px) {
  .gsm-ai-dialog { inset: 10px; top: auto; left: auto; width: auto; max-height: none; transform: translateY(12px); border-radius: 22px; grid-template-rows: auto auto auto auto minmax(170px, 1fr) auto auto; }
  .gsm-ai-header { padding: 18px 18px 14px; }
  .gsm-ai-brand-icon { width: 46px; height: 46px; flex-basis: 46px; border-radius: 14px; }
  .gsm-ai-kicker { font-size: 10px; }
  .gsm-ai-country { margin: 13px 18px 0; }
  .gsm-ai-description { margin: 10px 18px 0; }
  .gsm-ai-quick-wrap { padding: 12px 18px 10px; }
  .gsm-ai-conversation { margin: 0 8px; padding-inline: 10px; }
  .gsm-ai-message-content { max-width: 88%; }
  .gsm-ai-composer { margin: 0 18px; }
  .gsm-ai-note { margin: 9px 18px 13px; }
  .gsm-ai-message-action span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  @keyframes gsm-ai-dialog-in { to { opacity: 1; transform: translateY(0); } }
}

@media (prefers-reduced-motion: reduce) {
  .gsm-ai-backdrop, .gsm-ai-dialog, .gsm-ai-typing i { animation: none !important; }
  .gsm-ai-backdrop, .gsm-ai-dialog { opacity: 1; }
  .gsm-ai-dialog { transform: translate(-50%, -50%); }
  .gsm-ai-conversation { scroll-behavior: auto; }
  .gsm-ai-close, .gsm-ai-chip, .gsm-ai-send { transition: none; }
}

/* GSM Structural Assistant v1.2 — controlled two-country comparison */
.gsm-ai-country-stack {
  display: grid;
  gap: 10px;
  margin: 18px 28px 0;
}

.gsm-ai-country-stack .gsm-ai-country {
  margin: 0;
}

.gsm-ai-country {
  position: relative;
}

.gsm-ai-compare-trigger {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  margin-inline-start: auto;
  padding: 8px 11px;
  border: 1px solid #cfe1e5;
  border-radius: 999px;
  background: #ffffff;
  color: var(--gsm-teal-dark, #045e69);
  font: inherit;
  font-size: 12px;
  font-weight: 800;
  cursor: pointer;
  white-space: nowrap;
  transition: border-color 160ms ease, background 160ms ease, transform 160ms ease;
}

.gsm-ai-compare-trigger:hover,
.gsm-ai-compare-trigger:focus-visible {
  border-color: var(--gsm-teal, #087f8c);
  background: var(--gsm-teal-soft, #dff6f6);
  color: var(--gsm-teal-dark, #045e69);
  transform: translateY(-1px);
}

.gsm-ai-compare-trigger:active {
  border-color: var(--gsm-teal, #087f8c);
  background: color-mix(in srgb, var(--gsm-teal-soft, #dff6f6) 78%, #ffffff);
  color: var(--gsm-teal-dark, #045e69);
  transform: translateY(0) scale(.98);
}

.gsm-ai-compare-trigger:focus:not(:focus-visible) {
  outline: none;
  box-shadow: none;
}

.gsm-ai-compare-trigger svg,
.gsm-ai-compare-remove svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.gsm-ai-compare-picker {
  padding: 13px 14px;
  border: 1px solid #d9e7ea;
  border-radius: 16px;
  background: #fbfefe;
  box-shadow: 0 10px 28px rgba(15, 49, 66, .07);
}

.gsm-ai-compare-picker[hidden],
.gsm-ai-country-comparison[hidden] {
  display: none !important;
}

.gsm-ai-compare-picker > label {
  display: block;
  margin-bottom: 8px;
  color: #40525e;
  font-size: 12px;
  font-weight: 800;
}

.gsm-ai-compare-controls {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 8px;
}

.gsm-ai-compare-controls input {
  min-width: 0;
  height: 42px;
  padding: 0 12px;
  border: 1px solid #ccdce1;
  border-radius: 12px;
  background: #ffffff;
  color: #243742;
  font: inherit;
  font-size: 14px;
}

.gsm-ai-compare-controls input:focus {
  border-color: var(--gsm-teal, #087f8c);
  outline: 3px solid rgba(8, 127, 140, .16);
  outline-offset: 1px;
}

.gsm-ai-compare-apply,
.gsm-ai-compare-cancel {
  min-height: 42px;
  padding: 0 13px;
  border-radius: 12px;
  font: inherit;
  font-size: 12px;
  font-weight: 800;
  cursor: pointer;
}

.gsm-ai-compare-apply {
  border: 0;
  background: var(--gsm-teal, #087f8c);
  color: #ffffff;
}

.gsm-ai-compare-apply:hover,
.gsm-ai-compare-apply:focus-visible {
  background: var(--gsm-teal-dark, #045e69);
  color: #ffffff;
}
.gsm-ai-compare-apply:active {
  background: var(--gsm-teal, #087f8c);
  color: #ffffff;
  transform: scale(.98);
}

.gsm-ai-compare-cancel {
  border: 1px solid #d5e2e6;
  background: #ffffff;
  color: #53656f;
}

.gsm-ai-compare-cancel:hover,
.gsm-ai-compare-cancel:focus-visible {
  border-color: var(--gsm-teal, #087f8c);
  background: var(--gsm-teal-soft, #dff6f6);
  color: var(--gsm-teal-dark, #045e69);
}
.gsm-ai-compare-cancel:active {
  background: color-mix(in srgb, var(--gsm-teal-soft, #dff6f6) 78%, #ffffff);
  color: var(--gsm-teal-dark, #045e69);
  transform: scale(.98);
}

.gsm-ai-compare-status {
  min-height: 18px;
  margin: 7px 2px 0;
  color: #6f7f89;
  font-size: 11px;
  line-height: 1.45;
}

.gsm-ai-country-comparison {
  border-color: rgba(8, 127, 140, .30);
  background: linear-gradient(135deg, #f3fbfb, #edf8f6);
}

.gsm-ai-compare-symbol {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  flex: 0 0 30px;
  border-radius: 10px;
  background: var(--gsm-teal-soft, #dff6f6);
  color: var(--gsm-teal-dark, #045e69);
  font-size: 16px;
  font-weight: 900;
}

.gsm-ai-compare-remove {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  flex: 0 0 34px;
  margin-inline-start: auto;
  padding: 0;
  border: 1px solid #cfdee2;
  border-radius: 11px;
  background: #ffffff;
  color: #687983;
  cursor: pointer;
}

.gsm-ai-compare-remove:hover {
  border-color: var(--gsm-teal, #087f8c);
  color: var(--gsm-teal-dark, #045e69);
}

@media (max-width: 680px) {
  .gsm-ai-country-stack {
    margin: 13px 18px 0;
  }

  .gsm-ai-country {
    align-items: flex-start;
    flex-wrap: wrap;
  }

  .gsm-ai-compare-trigger {
    width: 100%;
    justify-content: center;
    margin-inline-start: 0;
  }

  .gsm-ai-compare-controls {
    grid-template-columns: 1fr 1fr;
  }

  .gsm-ai-compare-controls input {
    grid-column: 1 / -1;
  }

  .gsm-ai-compare-apply,
  .gsm-ai-compare-cancel {
    width: 100%;
  }
}

@media (prefers-reduced-motion: reduce) {
  .gsm-ai-compare-trigger {
    transition: none;
  }
}


/* ======================================================
   GSM Structural Assistant — mobile viewport/keyboard lock
====================================================== */
@media (max-width: 680px) {
  #gsm-ai-root.is-open {
    top: var(--gsm-ai-viewport-top, 0px);
    height: var(--gsm-ai-viewport-height, 100dvh);
    bottom: auto;
    overflow: hidden;
  }
  .gsm-ai-dialog {
    inset: 8px;
    width: auto;
    height: calc(var(--gsm-ai-viewport-height, 100dvh) - 16px);
    max-height: none;
    min-height: 0;
    grid-template-rows: auto auto auto auto minmax(110px, 1fr) auto auto;
    border-radius: 20px;
  }
  .gsm-ai-header {
    gap: 10px;
    padding: 13px 13px 11px;
  }
  .gsm-ai-brand { gap: 10px; min-width: 0; }
  .gsm-ai-brand > div { min-width: 0; }
  .gsm-ai-brand-icon {
    width: 42px;
    height: 42px;
    flex-basis: 42px;
    border-radius: 12px;
  }
  .gsm-ai-header h2 {
    overflow: hidden;
    font-size: clamp(18px, 5.4vw, 22px);
    line-height: 1.15;
    text-overflow: ellipsis;
  }
  .gsm-ai-model-line { font-size: 10px; }
  .gsm-ai-close {
    width: 42px;
    height: 42px;
    flex-basis: 42px;
  }
  .gsm-ai-country-stack { margin: 10px 12px 0; gap: 8px; min-width: 0; }
  .gsm-ai-country { padding: 11px 12px; gap: 10px; min-width: 0; }
  .gsm-ai-country-copy { flex: 1 1 180px; }
  .gsm-ai-country-copy span { white-space: normal; line-height: 1.35; }
  .gsm-ai-description { margin: 8px 12px 0; font-size: 13px; line-height: 1.42; }
  .gsm-ai-quick-wrap { min-width: 0; padding: 9px 12px 8px; }
  .gsm-ai-quick-list {
    gap: 7px;
    overscroll-behavior-x: contain;
    scroll-snap-type: x proximity;
  }
  .gsm-ai-chip { scroll-snap-align: start; padding: 8px 11px; font-size: 12px; }
  .gsm-ai-conversation {
    min-height: 0;
    margin: 0 6px;
    padding: 12px 7px 14px;
    overscroll-behavior: contain;
  }
  .gsm-ai-message { gap: 7px; margin-bottom: 12px; }
  .gsm-ai-avatar { width: 30px; height: 30px; flex-basis: 30px; border-radius: 9px; }
  .gsm-ai-message-content { max-width: calc(100% - 38px); }
  .gsm-ai-bubble { padding: 11px 12px; font-size: 13.5px; line-height: 1.55; }
  .gsm-ai-composer {
    margin: 0 10px;
    padding: 9px 10px;
    border-radius: 16px;
  }
  .gsm-ai-composer textarea {
    min-height: 42px;
    max-height: 90px;
    resize: none;
    font-size: 16px;
  }
  .gsm-ai-send { min-height: 40px; padding: 9px 13px; }
  .gsm-ai-note { margin: 7px 12px 9px; font-size: 10px; }
}

@media (max-width: 390px) {
  .gsm-ai-kicker { display: none; }
  .gsm-ai-brand-icon { width: 38px; height: 38px; flex-basis: 38px; }
  .gsm-ai-header h2 { font-size: 18px; }
  .gsm-ai-model-line { font-size: 9px; }
}

/* ======================================================
   GSM Assistant — keyboard-safe composer lock
====================================================== */
@media (max-width: 680px) {
  .gsm-ai-dialog {
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }

  .gsm-ai-composer {
    position: relative;
    z-index: 5;
    background: #ffffff;
  }
}

@media (max-width: 680px) and (max-height: 620px) {
  .gsm-ai-header { padding: 8px 10px !important; }
  .gsm-ai-brand-icon { width: 34px !important; height: 34px !important; flex-basis: 34px !important; }
  .gsm-ai-kicker,
  .gsm-ai-model-line,
  .gsm-ai-description,
  .gsm-ai-quick-wrap,
  .gsm-ai-note { display: none !important; }
  .gsm-ai-country-stack { margin: 6px 9px 0 !important; }
  .gsm-ai-country { padding: 7px 9px !important; }
  .gsm-ai-flag { font-size: 23px !important; }
  .gsm-ai-country-copy strong { font-size: 14px !important; }
  .gsm-ai-country-copy span { font-size: 11px !important; }
  .gsm-ai-compare-trigger { min-height: 36px !important; padding: 6px 9px !important; }
  .gsm-ai-dialog { grid-template-rows: auto auto minmax(72px, 1fr) auto !important; }
  .gsm-ai-conversation { padding-top: 8px !important; padding-bottom: 8px !important; }
  .gsm-ai-composer { margin: 0 8px 6px !important; }
}
