* {
    box-sizing: border-box;
  }
  
  :root {
    /* 柔らかい丸ゴシック（本文・UI）／等幅は診断用に維持 */
    --font-ui:
      "M PLUS Rounded 1c",
      "Hiragino Maru Gothic ProN",
      "Yu Gothic UI",
      "Yu Gothic",
      "Hiragino Sans",
      system-ui,
      sans-serif;
    --font-mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
    /* 薄緑基調（サイトの #99CC99 系に合わせたパレット） */
    --bg: #ecf5ef;
    --card-bg: #ffffff;
    --line: #c8ddcf;
    --border-strong: #7fb396;
    --text: #1a2e22;
    --subtext: #4a5c52;
    --link: #155aad;
    --link-hover: #0d4a8f;
    --primary: #2a7d4f;
    --primary-soft: #e8f5ec;
    --bot-bg: #e8f2eb;
    --user-bg: #d4ebdf;
    --success-bg: #eef8ee;
    --success-text: #1f6b2a;
    --warning-bg: #fff7e8;
    --warning-text: #8a5a00;
    --shadow: 0 8px 28px rgba(42, 125, 79, 0.1);
    --radius-lg: 16px;
    --radius-md: 12px;
    --radius-sm: 10px;
  }
  
  html,
  body {
    margin: 0;
    padding: 0;
    font-family: var(--font-ui);
    background: var(--bg);
    color: var(--text);
  }
  
  body {
    font-size: 17px;
    line-height: 1.65;
    letter-spacing: 0.02em;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
  }

  .lang-row {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
  }

  .lang-row select {
    max-width: 12rem;
    padding: 0.35rem 0.5rem;
    font: inherit;
    border: 2px solid #9bc4aa;
    border-radius: 8px;
    background: #fefffe;
    color: var(--text);
  }
  
  .page-wrap {
    padding: 24px;
  }
  
  .chat-card {
    max-width: 980px;
    margin: 0 auto;
    background: var(--card-bg);
    border: 1px solid rgba(127, 179, 150, 0.45);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    padding: 24px;
  }
  
  h1 {
    margin: 0 0 8px;
    font-size: 32px;
    font-weight: 600;
    line-height: 1.3;
  }
  
  h2 {
    margin: 28px 0 10px;
    font-size: 24px;
    font-weight: 600;
    line-height: 1.4;
  }
  
  .lead,
  .note {
    color: var(--subtext);
    line-height: 1.8;
  }
  
  .note strong {
    color: var(--text);
  }
  
  .notice-box {
    margin-top: 14px;
    padding: 14px 16px;
    border-radius: var(--radius-md);
    background: var(--warning-bg);
    color: var(--warning-text);
    border: 1px solid #f1dfb7;
    font-size: 16px;
    line-height: 1.8;
  }

  .estimate-tesla-note {
    margin-top: 12px;
  }
  
  /* =========================
     チャットウィンドウ
  ========================= */
  .chat-window {
    min-height: 360px;
    max-height: 560px;
    overflow-y: auto;
    border: 2px solid var(--border-strong);
    background: linear-gradient(to bottom, #f8fcf9, #eef6f0);
    border-radius: var(--radius-lg);
    padding: 16px;
    margin: 18px 0 16px;
    scroll-behavior: smooth;
    box-shadow:
      inset 0 1px 0 rgba(255, 255, 255, 0.75),
      0 2px 12px rgba(42, 125, 79, 0.12);
  }
  
  .message-row {
    display: flex;
    margin-bottom: 14px;
  }
  
  .message-row.user-row {
    justify-content: flex-end;
  }
  
  .message-row.bot-row {
    justify-content: flex-start;
  }
  
  .message-wrap {
    max-width: min(78%, 680px);
  }
  
  .message {
    padding: 12px 14px;
    border-radius: 16px;
    white-space: pre-wrap;
    word-break: break-word;
    line-height: 1.8;
    font-size: 17px;
    font-weight: 500;
    box-shadow: 0 2px 8px rgba(42, 125, 79, 0.08);
  }
  
  .message.user {
    background: var(--user-bg);
    border: 1px solid rgba(127, 179, 150, 0.55);
    border-bottom-right-radius: 6px;
  }
  
  .message.bot {
    background: var(--bot-bg);
    border: 1px solid rgba(127, 179, 150, 0.4);
    border-bottom-left-radius: 6px;
  }

  .message a {
    color: var(--link);
    text-decoration: underline;
    text-underline-offset: 2px;
    word-break: break-all;
  }

  .message a:hover {
    color: var(--link-hover);
  }

  .message-embeds {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 10px;
    max-width: 100%;
  }

  .message-embed-link {
    display: inline-flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
    max-width: min(100%, 320px);
    border-radius: var(--radius-sm);
    overflow: hidden;
    border: 1px solid var(--line);
    background: var(--card-bg);
    text-decoration: none;
    color: inherit;
    box-shadow: 0 1px 4px rgba(42, 125, 79, 0.08);
  }

  .message-embed-link:hover {
    border-color: var(--border-strong);
    box-shadow: 0 2px 8px rgba(42, 125, 79, 0.12);
  }

  .message-embed-thumb {
    display: block;
    width: 100%;
    max-height: 180px;
    object-fit: cover;
  }

  .message-embed-label {
    display: block;
    padding: 2px 8px 6px;
    font-size: 14px;
    color: var(--subtext);
    line-height: 1.3;
  }

  .message-embed-vimeo {
    min-height: 48px;
    min-width: 120px;
    border-radius: var(--radius-sm);
    border: 1px dashed var(--line);
    background: var(--primary-soft);
  }

  .message-embed-vimeo:empty {
    display: none;
  }

  /** 概算見積APIの diagnostics（実行結果・診断） */
  .message-detail {
    margin-top: 10px;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    background: var(--card-bg);
    border: 1px solid var(--line);
    font-size: 14px;
    line-height: 1.55;
    color: var(--subtext);
    white-space: pre-wrap;
    word-break: break-word;
    font-family: var(--font-mono);
  }

  .message-detail a {
    color: var(--link);
    text-decoration: underline;
    word-break: break-all;
  }

  .message-detail a:hover {
    color: var(--link-hover);
  }
  
  .message-meta {
    font-size: 14px;
    color: #7b8592;
    margin-top: 4px;
    padding: 0 4px;
  }
  
  .user-row .message-meta {
    text-align: right;
  }
  
  .bot-row .message-meta {
    text-align: left;
  }
  
  .message.system {
    background: var(--success-bg);
    color: var(--success-text);
  }
  
  /* 旧クラス互換 */
  .message.user,
  .message.bot {
    display: block;
  }
  
  /* =========================
     送信中インジケータ
  ========================= */
  .typing-indicator {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 10px 12px;
    border-radius: 14px;
    background: var(--bot-bg);
    color: var(--subtext);
    font-size: 16px;
    font-weight: 500;
  }
  
  .typing-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #6a9f82;
    animation: blink 1.2s infinite ease-in-out;
  }
  
  .typing-dot:nth-child(2) {
    animation-delay: 0.15s;
  }
  
  .typing-dot:nth-child(3) {
    animation-delay: 0.3s;
  }
  
  @keyframes blink {
    0%, 80%, 100% {
      opacity: 0.25;
      transform: translateY(0);
    }
    40% {
      opacity: 1;
      transform: translateY(-2px);
    }
  }
  
  /* =========================
     クイックボタン
  ========================= */
  .quick-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 14px;
  }
  
  .quick-buttons button,
  .primary-btn,
  .chat-input-row button,
  .upload-group button,
  .image-upload-box button {
    border: none;
    border-radius: var(--radius-sm);
    padding: 10px 14px;
    cursor: pointer;
    background: var(--primary);
    color: #fff;
    font-size: 16px;
    font-weight: 500;
    line-height: 1.4;
    transition: opacity 0.15s ease, transform 0.05s ease;
  }
  
  .quick-buttons button:hover,
  .primary-btn:hover,
  .chat-input-row button:hover,
  .upload-group button:hover,
  .image-upload-box button:hover {
    opacity: 0.93;
  }
  
  .quick-buttons button:active,
  .primary-btn:active,
  .chat-input-row button:active,
  .upload-group button:active,
  .image-upload-box button:active {
    transform: translateY(1px);
  }
  
  /* =========================
     入力欄
  ========================= */
  .chat-input-row {
    display: flex;
    gap: 10px;
    align-items: flex-end;
    margin-top: 4px;
    padding: 12px 14px;
    background: linear-gradient(to bottom, #f5fbf7, #eef6f0);
    border: 2px solid var(--border-strong);
    border-radius: var(--radius-lg);
    box-shadow:
      inset 0 1px 0 rgba(255, 255, 255, 0.85),
      0 2px 10px rgba(42, 125, 79, 0.1);
  }
  
  .chat-input-row textarea {
    flex: 1;
    min-width: 0;
    min-height: 54px;
    max-height: 220px;
    padding: 12px 14px;
    border: 2px solid #9bc4aa;
    border-radius: 12px;
    font-size: 17px;
    line-height: 1.7;
    resize: vertical;
    overflow-y: auto;
    font-family: inherit;
    background: #fefffe;
    color: var(--text);
    transition: border 0.15s ease, box-shadow 0.15s ease;
  }
  
  .chat-input-row textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(42, 125, 79, 0.22);
  }
  
  .chat-input-row button {
    min-width: 96px;
    height: 44px;
  }
  
  .input-help {
    margin-top: 10px;
    margin-bottom: 0;
    font-size: 14px;
    color: #4d6a58;
  }
  
  /* =========================
     区切り線
  ========================= */
  hr {
    border: none;
    border-top: 1px solid #c5ddcc;
    margin: 30px 0;
  }
  
  /* =========================
     折りたたみ（現地調査 / 概算見積）
  ========================= */
  .chat-accordion {
    margin: 0;
    border: 1px solid #c5ddcc;
    border-radius: var(--radius-md);
    background: #fafbfc;
    overflow: hidden;
  }
  
  .chat-accordion-summary {
    list-style: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 14px 16px;
    margin: 0;
    font-size: 24px;
    font-weight: 600;
    line-height: 1.4;
    color: var(--text);
    user-select: none;
  }
  
  .chat-accordion-summary::-webkit-details-marker {
    display: none;
  }
  
  .chat-accordion-summary::after {
    content: "";
    flex-shrink: 0;
    width: 0.55em;
    height: 0.55em;
    border-right: 2px solid #6a7a8a;
    border-bottom: 2px solid #6a7a8a;
    transform: rotate(45deg);
    transition: transform 0.2s ease;
    margin-top: -0.15em;
  }
  
  details[open] > .chat-accordion-summary::after {
    transform: rotate(225deg);
    margin-top: 0.12em;
  }
  
  .chat-accordion-title {
    flex: 1;
    min-width: 0;
  }
  
  .chat-accordion-panel {
    padding: 0 16px 16px;
    border-top: 1px solid #e0ebe8;
    background: #fff;
  }
  
  .chat-accordion-panel > .note:first-of-type {
    margin-top: 12px;
  }
  
  /* =========================
     概算見積フォーム
  ========================= */
  .estimate-form {
    margin-top: 10px;
  }
  
  .estimate-form .grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
  }
  
  .estimate-form label {
    display: flex;
    flex-direction: column;
    gap: 6px;
  }
  
  .estimate-form label span {
    font-size: 16px;
    color: #415063;
  }
  
  .estimate-form input,
  .estimate-form select {
    width: 100%;
    padding: 12px 14px;
    border: 1px solid #cfd8e5;
    border-radius: 12px;
    font-size: 16px;
    background: #fff;
    transition: border 0.15s ease, box-shadow 0.15s ease;
  }
  
  .estimate-form input:focus,
  .estimate-form select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(42, 125, 79, 0.18);
  }

  /* 訪問候補日フォーム（連絡先グリッド・テキストエリアは概算と同系統） */
  .visit-request-form {
    margin-top: 10px;
  }

  .visit-request-form .grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
  }

  .visit-request-form label {
    display: flex;
    flex-direction: column;
    gap: 6px;
  }

  .visit-request-form label span {
    font-size: 16px;
    color: #415063;
  }

  .visit-request-form input,
  .visit-request-form textarea {
    width: 100%;
    padding: 12px 14px;
    border: 1px solid #cfd8e5;
    border-radius: 12px;
    font-size: 16px;
    background: #fff;
    transition: border 0.15s ease, box-shadow 0.15s ease;
    box-sizing: border-box;
  }

  .visit-request-form input:focus,
  .visit-request-form textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(42, 125, 79, 0.18);
  }

  .visit-request-form .visit-candidate-block {
    margin-top: 14px;
  }
  
  .checkbox-row {
    display: flex !important;
    flex-direction: row !important;
    align-items: flex-start;
    gap: 10px;
    margin: 18px 0 20px;
    padding: 12px 14px;
    border: 1px solid #e1e6ef;
    border-radius: 12px;
    background: #fafbfd;
  }
  
  .checkbox-row input {
    width: auto;
    margin-top: 3px;
  }
  
  /* =========================
     画像アップロード
  ========================= */
  .image-upload-box,
  .upload-group {
    margin-top: 18px;
    padding: 14px;
    border: 1px solid #dfe5ee;
    border-radius: 14px;
    background: #fafbfd;
  }
  
  .image-upload-box h2 {
    margin-top: 0;
  }
  
  .upload-group .file-field,
  .image-upload-box .file-field {
    display: flex;
    flex-direction: column;
    gap: 8px;
  }
  
  .file-field-caption {
    font-size: 16px;
    color: #415063;
  }
  
  .file-field-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
  }

  /* 概算見積フォーム: 写真アップロード横の参考例（折りたたみ） */
  .upload-example-ref {
    flex: 0 0 auto;
    align-self: center;
    max-width: 100%;
    min-width: 0;
  }

  .upload-example-ref__summary {
    cursor: pointer;
    list-style: none;
    font-size: clamp(14px, 3.8vw, 15px);
    font-weight: 600;
    padding: 7px 10px;
    border: 1px dashed #9bc4aa;
    border-radius: var(--radius-sm);
    color: var(--primary);
    background: #f3faf5;
    line-height: 1.35;
    user-select: none;
  }

  .upload-example-ref__summary::-webkit-details-marker {
    display: none;
  }

  .upload-example-ref__summary::after {
    content: " ▼";
    font-size: 0.75em;
    opacity: 0.75;
  }

  .upload-example-ref[open] .upload-example-ref__summary::after {
    content: " ▲";
  }

  .upload-example-ref__body {
    margin-top: 10px;
    padding: clamp(6px, 2vw, 10px);
    border: 1px solid #dfe5ee;
    border-radius: 12px;
    background: #fff;
    /* 横は画面幅に追従しつつ、大画面では上限 */
    width: min(100%, 92vw, 420px);
    max-width: 100%;
    margin-left: auto;
    margin-right: auto;
    box-sizing: border-box;
    box-shadow: 0 2px 10px rgba(42, 125, 79, 0.06);
    overflow: hidden;
  }

  .upload-example-ref__img {
    display: block;
    width: 100%;
    max-width: 100%;
    height: auto;
    /* 縦長でも画面の約半分を上限に（スマホの縦画面で過大表示しない） */
    max-height: min(52vh, 380px);
    object-fit: contain;
    object-position: center center;
    border-radius: 8px;
  }

  @supports (height: 1dvh) {
    .upload-example-ref__img {
      max-height: min(48dvh, 52vh, 380px);
    }
  }

  @media (max-width: 520px) {
    .file-field-row .upload-example-ref {
      flex-basis: 100%;
    }

    .file-field-row .upload-example-ref__body {
      width: 100%;
      max-width: 100%;
    }

    .upload-example-ref__img {
      max-height: min(46vh, 300px);
    }
  }

  @supports (height: 1dvh) {
    @media (max-width: 520px) {
      .upload-example-ref__img {
        max-height: min(44dvh, 46vh, 300px);
      }
    }
  }

  /* 極狭幅・横向き: 縦を抑えてフォーム全体が見えるように */
  @media (max-height: 500px) and (orientation: landscape) {
    .upload-example-ref__img {
      max-height: min(40vh, 220px);
    }
  }
  
  .file-input-native {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
  }
  
  .file-input-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 8px 14px;
    font-size: 16px;
    line-height: 1.4;
    cursor: pointer;
    border-radius: var(--radius-sm);
    border: 2px solid #9bc4aa;
    background: #fefffe;
    color: var(--text);
    font-family: inherit;
    transition: border 0.15s ease, box-shadow 0.15s ease;
  }
  
  .file-input-btn:hover {
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(42, 125, 79, 0.12);
  }
  
  .file-input-btn:focus-visible {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(42, 125, 79, 0.22);
  }
  
  .file-input-status {
    flex: 1;
    min-width: min(100%, 12rem);
    font-size: 14px;
    color: #4d6a58;
    line-height: 1.5;
    word-break: break-all;
  }
  
  .upload-status {
    margin-top: 8px;
    color: #485568;
    font-size: 16px;
    line-height: 1.6;
  }
  
  /* =========================
     フッター系文言
  ========================= */
  .small-text {
    font-size: 14px;
    color: #7a8492;
    line-height: 1.7;
  }
  
  .company-site-line {
    margin-top: 0.35em;
  }
  
  .company-site-line a {
    color: #5c6a7a;
    text-decoration: underline;
  }
  
  .company-site-line a:hover {
    color: #3d4a5c;
  }
  
  /* =========================
     スマホ対応
  ========================= */
  @media (max-width: 768px) {
    .page-wrap {
      padding: 12px;
    }
  
    .chat-card {
      padding: 16px;
      border-radius: 14px;
    }
  
    h1 {
      font-size: 26px;
    }
  
    h2 {
      font-size: 21px;
    }
  
    .chat-accordion-summary {
      font-size: 21px;
      padding: 12px 14px;
    }
  
    /* 会話・クイック・入力を 1 画面内に収める（svh でアドレスバー変動に追従） */
    .chat-main-block {
      display: flex;
      flex-direction: column;
      min-height: 0;
      height: min(
        calc(100svh - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px)),
        640px
      );
    }
  
    .chat-main-block .chat-window {
      flex: 1 1 auto;
      min-height: 0;
      max-height: none;
      padding: 12px;
      margin: 12px 0 8px;
      overflow-y: auto;
      -webkit-overflow-scrolling: touch;
    }
  
    .chat-main-block .quick-buttons {
      display: grid;
      grid-template-columns: 1fr 1fr;
      gap: 8px;
      margin-bottom: 8px;
      flex-shrink: 0;
    }
  
    .chat-main-block .quick-buttons button {
      width: auto;
      min-width: 0;
      padding: 9px 10px;
      font-size: 14px;
    }
  
    .chat-main-block .chat-input-row {
      flex-direction: column;
      align-items: stretch;
      flex-shrink: 0;
      margin-top: 0;
      padding: 10px 12px;
    }
  
    .chat-main-block .chat-input-row textarea {
      width: 100%;
      min-height: 44px;
      max-height: 100px;
      padding: 10px 12px;
    }
  
    .chat-main-block .chat-input-row button {
      width: 100%;
      min-width: 0;
    }
  
    .chat-main-block .input-help {
      flex-shrink: 0;
      margin: 4px 0 0;
      font-size: 14px;
      line-height: 1.45;
    }
  
    .message-wrap {
      max-width: 92%;
    }
  
    .estimate-form .grid,
    .visit-request-form .grid {
      grid-template-columns: 1fr;
    }
  }

  .consultation-ended-banner {
    margin: 12px 0;
    padding: 12px 14px;
    border-radius: var(--radius-md);
    background: var(--success-bg);
    color: var(--success-text);
    border: 1px solid #b8d4b8;
    font-size: 16px;
  }

  /* 訪問候補日のみ送信済み（チャット・概算は操作可） */
  body.visit-request-submitted .visit-request-form {
    opacity: 0.52;
    pointer-events: none;
    user-select: none;
  }

  body.consultation-ended .chat-input-row,
  body.consultation-ended .quick-buttons,
  body.consultation-ended .image-upload-box,
  body.consultation-ended .estimate-form,
  body.consultation-ended .visit-request-form,
  body.consultation-ended .input-help {
    opacity: 0.52;
    pointer-events: none;
    user-select: none;
  }

  .estimate-section-title {
    margin: 20px 0 8px;
    font-size: 18px;
    font-weight: 600;
    color: var(--text);
  }