@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+JP:wght@400;500;600;700;800&family=Shippori+Mincho:wght@400;500;600&display=swap');

:root {
  /* 家づくり向け — 信頼・落ち着き・読みやすさ */
  --brand: #4a6fa5;
  --brand-deep: #2c4568;
  --brand-soft: #e8eef6;
  --green: #0f766e;
  --green-soft: #ccfbf1;
  --cta: #0d9488;
  --bg: #f4f7fb;
  --bg-warm: #faf8f5;
  --paper: #fff;
  --ink: #1a2332;
  --muted: #5c6b7e;
  --line: #dde3ec;
  --orange: #ea580c;
  --danger: #dc2626;
  --success: #059669;
  --radius-sm: 10px;
  --radius: 16px;
  --radius-lg: 20px;
  --radius-full: 999px;
  --shadow-sm: 0 2px 8px rgba(44, 69, 104, 0.06);
  --shadow: 0 8px 28px rgba(44, 69, 104, 0.08);
  --shadow-lg: 0 16px 40px rgba(44, 69, 104, 0.12);
  --ease: cubic-bezier(0.4, 0, 0.2, 1);
  --focus-ring: 0 0 0 3px rgba(15, 118, 110, 0.28);
  --touch-min: 44px;
  --content-max: 1180px;
  --chat-max: 480px;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: "Noto Sans JP", -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.65;
  min-height: 100vh;
  overflow-x: clip;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

a { color: var(--brand-deep); }
a:hover { color: var(--green); }

.skip-link {
  position: absolute; left: -9999px; top: 8px; z-index: 10000;
  padding: 10px 16px; background: var(--brand-deep); color: #fff;
  border-radius: var(--radius-sm); font-weight: 700; text-decoration: none;
}
.skip-link:focus { left: 8px; outline: none; box-shadow: var(--focus-ring); }

.wrap { max-width: var(--content-max); margin: 0 auto; padding: 20px 16px 72px; }

.page-intro {
  margin-bottom: 20px; padding: 16px 18px;
  background: linear-gradient(135deg, var(--paper) 0%, var(--brand-soft) 100%);
  border: 1px solid var(--line); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}
.page-intro p { color: var(--muted); font-size: 14px; margin: 0; max-width: 62ch; }

.header {
  display: flex; justify-content: space-between; align-items: center;
  gap: 16px; flex-wrap: wrap; margin-bottom: 20px;
  padding-bottom: 16px; border-bottom: 1px solid var(--line);
}

.header h1 { font-size: clamp(1.125rem, 2.5vw, 1.375rem); color: var(--brand-deep); font-weight: 800; letter-spacing: -0.02em; }
.header small { display: block; color: var(--muted); font-size: 11px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; }

.demo-banner {
  background: rgba(26, 35, 50, 0.94); color: #fff; text-align: center;
  font-size: 13px; padding: 10px 14px; line-height: 1.5;
}
.demo-banner strong { color: #fde68a; }
.demo-banner a { color: #a7f3d0; text-decoration: underline; text-underline-offset: 2px; }
.demo-banner.is-hidden { display: none; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: var(--touch-min); padding: 0 18px; border-radius: var(--radius);
  font-size: 14px; font-weight: 700; cursor: pointer;
  border: 1px solid var(--line); background: var(--paper); color: var(--brand-deep);
  text-decoration: none; transition: background 0.2s var(--ease), border-color 0.2s var(--ease), box-shadow 0.2s var(--ease), transform 0.15s var(--ease);
  white-space: nowrap; flex-shrink: 0;
}
.btn:hover { background: var(--brand-soft); border-color: rgba(74, 111, 165, 0.25); }
.btn:active { transform: scale(0.98); }
.btn:focus-visible { outline: none; box-shadow: var(--focus-ring); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; transform: none; }
.btn-solid { background: var(--green); color: #fff; border-color: transparent; }
.btn-solid:hover { background: #0d6b64; }
.btn-orange { background: var(--orange); color: #fff; border-color: transparent; }
.btn-orange:hover { background: #c2410c; }
.btn-ghost { background: transparent; }
.btn-sm { min-height: 38px; padding: 0 14px; font-size: 13px; border-radius: var(--radius-sm); }
.btn-danger { color: var(--danger); border-color: #fecaca; background: #fff; }

.card {
  background: var(--paper); border: 1px solid var(--line);
  border-radius: var(--radius-lg); padding: 20px; box-shadow: var(--shadow-sm);
  transition: box-shadow 0.2s var(--ease);
}
.card:hover { box-shadow: var(--shadow); }

.tabs {
  display: flex; gap: 6px; flex-wrap: nowrap; margin-bottom: 16px;
  overflow-x: auto; padding-bottom: 4px; -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
}
.tab {
  flex-shrink: 0;
  padding: 10px 16px; border-radius: var(--radius-full); border: 1px solid var(--line);
  background: var(--paper); cursor: pointer; font-weight: 700; font-size: 13px;
  color: var(--muted); transition: all 0.2s var(--ease);
}
.tab:hover { color: var(--brand-deep); background: var(--brand-soft); }
.tab:focus-visible { outline: none; box-shadow: var(--focus-ring); }
.tab.on { background: var(--brand-deep); color: #fff; border-color: transparent; }
.tab-panel { display: none; animation: fadeIn 0.25s var(--ease); }
.tab-panel.on { display: block; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }

.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.data { width: 100%; min-width: 960px; border-collapse: collapse; font-size: 14px; table-layout: auto; }
table.data th, table.data td { padding: 14px 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
table.data th { font-size: 11px; color: var(--muted); font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; background: #f8fafc; position: sticky; top: 0; z-index: 1; }
table.data tbody tr { transition: background 0.15s var(--ease); }
table.data tbody tr:hover { background: #f8fafc; }
table.data th.col-url,
table.data td.col-url { min-width: 196px; }
table.data th.col-embed,
table.data td.col-embed { min-width: 220px; }
table.data th.col-actions,
table.data td.col-actions { min-width: 96px; width: 1%; white-space: nowrap; }

.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 4px 10px; border-radius: var(--radius-full);
  font-size: 12px; font-weight: 700; line-height: 1.3;
}
.badge-ok { background: #d1fae5; color: #065f46; }
.badge-muted { background: #f1f5f9; color: var(--muted); }
.badge-warn { background: #fef3c7; color: #92400e; }
.badge-danger { background: #fee2e2; color: #991b1b; }
.badge-progress { background: #dbeafe; color: #1d4ed8; }

.drive-fields-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 8px; }
.session-toolbar { flex-wrap: wrap; gap: 8px; align-items: center; }
.session-show-deleted { margin: 0; }
.row-deleted { opacity: 0.65; }

.toast {
  position: fixed; bottom: 24px; right: 24px; z-index: 9999;
  background: var(--brand-deep); color: #fff; padding: 12px 18px;
  border-radius: 12px; font-size: 14px; font-weight: 600;
  opacity: 0; transform: translateY(8px); transition: all 0.2s;
  pointer-events: none; max-width: 360px;
}
.toast.show { opacity: 1; transform: translateY(0); }

.modal-overlay {
  position: fixed; inset: 0; background: rgba(15, 23, 42, 0.45);
  display: none; align-items: center; justify-content: center;
  z-index: 1000; padding: 16px;
}
.modal {
  background: #fff; border-radius: var(--radius); padding: 24px;
  max-width: 520px; width: 100%; max-height: 90vh; overflow-y: auto;
}
.modal h2 { font-size: 18px; margin-bottom: 12px; color: var(--brand-deep); }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }

.form-row { margin-bottom: 16px; }
.form-row > label { display: block; font-size: 13px; font-weight: 700; margin-bottom: 6px; color: var(--brand-deep); }
.form-row .checkbox-row { display: flex; align-items: center; gap: 8px; font-weight: 400; margin-bottom: 8px; }
.form-row input, .form-row select, .form-row textarea {
  width: 100%; padding: 12px 14px; border: 1px solid var(--line);
  border-radius: var(--radius-sm); font-size: 16px; font-family: inherit;
  background: var(--paper); color: var(--ink);
  transition: border-color 0.2s var(--ease), box-shadow 0.2s var(--ease);
}
.form-row input:focus, .form-row select:focus, .form-row textarea:focus {
  outline: none; border-color: var(--green); box-shadow: var(--focus-ring);
}
.form-row textarea { min-height: 88px; resize: vertical; font-size: 14px; }

/* Editor */
.editor-layout {
  display: grid; grid-template-columns: 220px 1fr; gap: 16px;
}
@media (max-width: 900px) { .editor-layout { grid-template-columns: 1fr; } }

.step-list-item {
  display: flex; align-items: center; gap: 8px; padding: 12px 14px;
  border-radius: var(--radius-sm); cursor: pointer; margin-bottom: 4px;
  border: 1px solid transparent; transition: background 0.2s var(--ease), border-color 0.2s var(--ease);
}
.step-list-item:hover { background: #f8fafc; border-color: var(--line); }
.step-list-item.on { background: var(--brand-soft); border-color: rgba(74, 111, 165, 0.35); font-weight: 700; color: var(--brand-deep); }
.step-list-item:focus-visible { outline: none; box-shadow: var(--focus-ring); }

.eq-card {
  border: 1px solid var(--line); border-radius: 14px; padding: 16px;
  margin-bottom: 12px; background: #fff;
}
.eq-card--cond { border-left: 4px solid var(--orange); }
.eq-header { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; flex-wrap: wrap; }
.eq-question-input { flex: 1; min-width: 200px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 10px; font-size: 14px; }
.eq-req-badge { font-size: 11px; font-weight: 800; padding: 3px 8px; border-radius: 999px; background: #f1f5f9; }
.eq-req-on { background: var(--brand-soft); color: var(--brand-deep); }
.eq-cat-opt { background: #fef3c7; color: #92400e; }
.eq-toolbar { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; align-items: center; }
.eq-opt-row { display: flex; gap: 8px; align-items: center; margin-bottom: 6px; }
.eq-panel {
  border: 1px dashed var(--line); border-radius: 12px; padding: 12px;
  margin-top: 10px; background: #fafbfc; font-size: 13px;
}
.eq-panel-title { font-weight: 800; color: var(--brand-deep); margin-bottom: 8px; }

.pref-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 6px; max-height: 200px; overflow-y: auto;
}
.pref-grid label { font-size: 12px; font-weight: 500; display: flex; gap: 6px; align-items: center; }

.img-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  gap: 8px;
}
.img-thumb {
  border: 2px solid var(--line); border-radius: 10px; overflow: hidden;
  cursor: pointer; position: relative; aspect-ratio: 4/3;
}
.img-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.img-thumb.selected { border-color: var(--green); box-shadow: 0 0 0 2px var(--brand-soft); }
.img-thumb .check {
  position: absolute; top: 4px; right: 4px; width: 22px; height: 22px;
  border-radius: 999px; background: var(--green); color: #fff;
  display: none; place-items: center; font-size: 12px; font-weight: 800;
}
.img-thumb.selected .check { display: grid; }

/* Chat */
.chat-app {
  max-width: var(--chat-max); margin: 0 auto; min-height: 0; height: 100%;
  display: flex; flex-direction: column; background: var(--paper);
  box-shadow: var(--shadow-lg);
}
.chat-top {
  padding: 14px 16px; border-bottom: 1px solid var(--line);
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  background: var(--paper); position: sticky; top: 0; z-index: 10;
}
.chat-top-brand {
  display: flex; align-items: center; gap: 12px; min-width: 0;
}
.chat-top-titles { min-width: 0; }
.chat-top-progress {
  display: none; align-items: center; gap: 12px; flex-shrink: 0;
}
.progress-step-label {
  font-size: 12px; color: var(--muted); white-space: nowrap;
}
.progress-segments {
  display: flex; align-items: center; gap: 6px;
}
.progress-segment {
  display: block; height: 6px; width: 6px; border-radius: 999px;
  background: #E8E0C8;
  transition: width 0.3s ease, background 0.3s ease;
}
.progress-segment.is-active {
  width: 16px;
  background: #F5C440;
}
.chat-choice-hint {
  display: none;
  flex-shrink: 0;
  border-top: 1px solid rgba(0, 0, 0, 0.08);
  padding: 12px 16px;
}
.chat-choice-hint.is-visible { display: block; }
.chat-choice-hint p {
  margin: 0;
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  text-align: center;
  color: rgba(122, 112, 96, 0.45);
}
.chat-top .avatar {
  width: 44px; height: 44px; border-radius: var(--radius-full); background: linear-gradient(135deg, var(--green), var(--brand));
  color: #fff; display: grid; place-items: center; font-weight: 800; font-size: 13px;
  flex-shrink: 0; box-shadow: var(--shadow-sm);
}
.progress-wrap {
  background: #f1f5f9; border-bottom: 1px solid var(--line);
  padding: 6px 16px 8px;
}
.progress-meta {
  display: flex; justify-content: space-between; align-items: center;
  font-size: 11px; font-weight: 700; color: var(--muted); margin-bottom: 4px;
}
.progress { height: 6px; background: #e2e8f0; border-radius: var(--radius-full); overflow: hidden; }
.progress > span {
  display: block;
  height: 100%;
  width: var(--progress-pct, 0%);
  background: linear-gradient(90deg, var(--green), var(--cta));
  transition: width 0.35s var(--ease);
  border-radius: var(--radius-full);
}

.chat-scroll {
  flex: 1; min-height: 0; overflow-y: auto; overflow-x: hidden;
  scroll-behavior: smooth; -webkit-overflow-scrolling: touch;
}
.chat-body {
  flex: none; overflow: visible; padding: 16px 16px 8px;
  display: flex; flex-direction: column; gap: 14px;
}
.chat-scroll-anchor { height: 12px; flex-shrink: 0; }
.bubble {
  max-width: 90%; padding: 12px 16px; border-radius: 18px; font-size: 15px; line-height: 1.55;
  word-break: break-word; overflow-wrap: anywhere;
  animation: rise 0.25s var(--ease);
}
.bubble.ai { background: var(--brand-soft); align-self: flex-start; border-bottom-left-radius: 6px; color: var(--ink); }
.bubble.user { background: linear-gradient(135deg, var(--brand-deep), var(--brand)); color: #fff; align-self: flex-end; border-bottom-right-radius: 6px; }
.bubble.note { align-self: center; background: #fff7ed; color: #9a3412; font-size: 12px; border-radius: var(--radius-full); padding: 8px 14px; border: 1px solid #fed7aa; }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

.chat-widget {
  border: 1px solid var(--line); border-radius: var(--radius-lg); padding: 16px;
  background: var(--paper); align-self: stretch; box-shadow: var(--shadow-sm);
}
.chat-widget-header {
  position: sticky;
  top: 0;
  z-index: 2;
  margin: -16px -16px 12px;
  padding: 16px 16px 10px;
  background: var(--paper);
  border-bottom: 1px solid var(--line);
  box-shadow: 0 4px 12px rgba(15, 23, 42, 0.06);
}
.chat-widget h4 {
  font-size: 15px; margin: 0 0 6px; color: var(--brand-deep); font-weight: 800;
  line-height: 1.55; word-break: break-word; overflow-wrap: anywhere;
}
.chat-widget .desc {
  font-size: 13px; color: var(--muted); margin: 0; line-height: 1.55;
  word-break: break-word; overflow-wrap: anywhere;
}
.chat-widget .img-grid {
  max-height: min(52vh, 440px);
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}
.chat-widget .img-grid--pick {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-top: 4px;
}
.chat-widget .img-thumb {
  display: flex;
  flex-direction: column;
  aspect-ratio: auto;
  border: 1px solid #e8e4df;
  border-radius: 16px;
  background: #fff;
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.06);
  transition: border-color 0.2s var(--ease), box-shadow 0.2s var(--ease), transform 0.15s var(--ease);
}
.chat-widget .img-thumb:hover {
  border-color: #d6d0c8;
  box-shadow: 0 4px 14px rgba(15, 23, 42, 0.1);
}
.chat-widget .img-thumb:active { transform: scale(0.98); }
.chat-widget .img-thumb-media {
  position: relative;
  aspect-ratio: 4 / 3;
  overflow: hidden;
  border-radius: 15px 15px 0 0;
}
.chat-widget .img-thumb-media img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.chat-widget .img-thumb-label {
  padding: 10px 8px 12px;
  text-align: center;
  font-size: 13px;
  font-weight: 700;
  line-height: 1.4;
  color: var(--ink);
  background: #fff;
  border-radius: 0 0 15px 15px;
}
.chat-widget .img-thumb.selected {
  border-color: var(--green);
  box-shadow: 0 0 0 2px var(--brand-soft), 0 4px 14px rgba(15, 118, 110, 0.12);
}
.chat-widget .img-thumb .check {
  top: 8px;
  right: 8px;
  width: 24px;
  height: 24px;
  font-size: 13px;
}

.goal-form .form-step-indicator {
  display: flex; align-items: center; gap: 6px; margin-bottom: 14px; flex-wrap: wrap;
}
.goal-form .form-step {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 11px; font-weight: 700; color: var(--muted);
}
.goal-form .form-step-num {
  width: 22px; height: 22px; border-radius: 999px; border: 1px solid var(--line);
  display: inline-flex; align-items: center; justify-content: center; background: #fff;
}
.goal-form .form-step--active { color: var(--brand-deep); }
.goal-form .form-step--active .form-step-num {
  background: var(--green); color: #fff; border-color: transparent;
}
.goal-form .form-step--done { color: var(--green); }
.goal-form .form-step--done .form-step-num {
  background: var(--green-soft); border-color: var(--green); color: var(--green);
}
.goal-form .form-step-line { flex: 1; min-width: 12px; height: 1px; background: var(--line); }

.goal-form .form-field { margin-bottom: 12px; }
.goal-form .form-field label { display: block; font-size: 13px; font-weight: 700; margin-bottom: 6px; }
.goal-form .form-field .req { color: #b91c1c; font-size: 11px; font-weight: 700; margin-left: 4px; }
.goal-form .form-field .opt { color: var(--muted); font-size: 11px; font-weight: 700; margin-left: 4px; }
.goal-form .form-input {
  width: 100%; padding: 10px; border: 1px solid var(--line); border-radius: 10px; font-size: 14px;
}
.goal-form .form-field .hint { font-size: 11px; color: var(--muted); margin-top: 4px; }
.goal-form .form-field .field-error { font-size: 12px; color: #b91c1c; margin-top: 4px; display: none; }
.goal-form .form-field.has-error .field-error { display: block; }
.goal-form .form-field.has-error .form-input { border-color: #fca5a5; }
.goal-form .consent-label { display: flex; gap: 8px; align-items: flex-start; font-size: 13px; font-weight: 400; }
.goal-form .consent-label a { color: var(--brand-deep); }

.goal-form .form-confirm-dl { margin: 12px 0; font-size: 13px; }
.goal-form .form-confirm-dl dt { color: var(--muted); font-size: 11px; font-weight: 700; margin-top: 8px; }
.goal-form .form-confirm-dl dd { font-weight: 600; margin-top: 2px; word-break: break-all; }

.goal-form .form-actions { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.goal-form .form-submit-error {
  margin-top: 10px; padding: 10px 12px; border-radius: 10px;
  background: #fef2f2; color: #b91c1c; font-size: 13px;
  display: none;
}
.goal-form .form-submit-error.is-visible { display: block; }
.goal-form.form-complete { text-align: center; }
.goal-form.form-complete .desc { margin-top: 8px; }

.chip-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.chip {
  border: 1.5px solid var(--green); color: var(--green); background: var(--paper);
  border-radius: var(--radius-full); padding: 10px 16px; font-size: 14px; font-weight: 700;
  cursor: pointer; font-family: inherit; min-height: var(--touch-min);
  transition: background 0.2s var(--ease), transform 0.15s var(--ease);
}
.chip:hover { background: var(--green-soft); }
.chip:active { transform: scale(0.98); }
.chip:focus-visible { outline: none; box-shadow: var(--focus-ring); }

.chat-input-area {
  border-top: 1px solid var(--line); padding: 12px 14px calc(12px + env(safe-area-inset-bottom, 0px));
  gap: 8px; background: var(--paper);
  position: sticky; bottom: 0; z-index: 10;
}
#chat-form:not(.is-visible) { display: none; }
#chat-form.is-visible { display: flex; flex-wrap: wrap; }
.chat-input-assist {
  flex: 1 1 100%; display: flex; flex-wrap: wrap; gap: 6px;
}
.chat-assist-chip {
  border: 1px solid var(--line); background: #f8fafc; color: var(--brand-deep);
  border-radius: var(--radius-full); padding: 8px 14px; font-size: 13px; font-weight: 600;
  cursor: pointer; font-family: inherit; min-height: 36px;
  transition: background 0.2s var(--ease), border-color 0.2s var(--ease);
}
.chat-assist-chip:hover:not(:disabled) { background: var(--brand-soft); border-color: var(--brand); }
.chat-assist-chip:disabled { opacity: 0.5; cursor: not-allowed; }
.chat-assist-chip:focus-visible { outline: none; box-shadow: var(--focus-ring); }
.chat-input-area input {
  flex: 1; min-width: 0; padding: 12px 16px; border: 1px solid var(--line);
  border-radius: var(--radius-full); font-size: 16px; min-height: var(--touch-min);
  transition: border-color 0.2s var(--ease), box-shadow 0.2s var(--ease);
}
.chat-input-area input:focus { outline: none; border-color: var(--green); box-shadow: var(--focus-ring); }
.chat-input-area button {
  min-width: 76px; min-height: var(--touch-min); padding: 0 18px; border: none; border-radius: var(--radius-full);
  background: var(--green); color: #fff; font-weight: 700; font-size: 14px; cursor: pointer;
  transition: background 0.2s var(--ease), transform 0.15s var(--ease);
}
.chat-input-area button:hover { background: #0d6b64; }
.chat-input-area button:active { transform: scale(0.98); }
.chat-input-area button:focus-visible { outline: none; box-shadow: var(--focus-ring); }
.chat-input-area button:disabled { opacity: 0.55; cursor: not-allowed; }

.result-card {
  background: linear-gradient(135deg, var(--brand-deep) 0%, var(--brand) 100%);
  color: #fff; border-radius: var(--radius-lg); padding: 24px; margin-bottom: 16px;
  box-shadow: var(--shadow);
}
.result-card .result-lead {
  margin: 10px 0 0;
  font-size: 14px;
  line-height: 1.6;
  opacity: 0.95;
}
.result-card h2 { font-size: clamp(1.125rem, 3vw, 1.375rem); margin-top: 8px; line-height: 1.35; }

.auth-gate-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.92);
  padding: 24px;
}
.auth-gate-overlay[hidden] {
  display: none !important;
  visibility: hidden;
  pointer-events: none;
}
.auth-gate-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: stretch;
}
.auth-gate-box { text-align: center; padding: 48px 24px; max-width: 420px; width: 100%; }
.auth-gate-box h2 { margin: 0 0 8px; }
.auth-gate-box p { color: var(--muted); font-size: 14px; margin-bottom: 16px; }
.auth-gate-error { color: #c0392b; font-size: 13px; margin-top: 12px; min-height: 1.2em; }
body.auth-gate-active .main-content { filter: blur(4px); pointer-events: none; }

.img-pick-controls {
  display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 12px;
}
.img-asset-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 12px;
}
.img-asset-card {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 8px;
  background: #fafbfd;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.img-asset-thumb {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  border-radius: 8px;
  background: #e8edf5;
}
.img-asset-missing {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 12px;
}
.img-asset-card input[type="text"] {
  width: 100%;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 12px;
}

/* Layout utilities (CSP: no inline styles) */
.is-hidden { display: none !important; }
.flex-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.flex-row-between { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; }
.flex-row-end { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }
.flex-col-actions {
  display: flex; gap: 6px; flex-wrap: wrap; align-items: center;
  width: max-content; max-width: 100%;
}
.flex-col-actions .btn { flex-shrink: 0; }
.mb-sm { margin-bottom: 8px; }
.mb-md { margin-bottom: 12px; }
.mb-lg { margin-bottom: 16px; }
.mt-sm { margin-top: 8px; }
.mt-md { margin-top: 12px; }
.mt-lg { margin-top: 20px; }
.card-compact { padding: 10px; }
.card-spaced { margin-bottom: 10px; }
.card-section { margin-bottom: 16px; }
.text-muted { color: var(--muted); }
.text-muted-sm { color: var(--muted); font-size: 13px; }
.text-muted-xs { color: var(--muted); font-size: 12px; }
.text-error { color: #b91c1c; }
.section-title { margin: 16px 0 8px; font-size: 15px; color: var(--brand-deep); font-weight: 800; }
.section-title-lg { margin: 20px 0 8px; font-size: 15px; color: var(--brand-deep); font-weight: 800; }
.metric-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; }
.metric-card {
  padding: 16px; border-radius: var(--radius);
  background: var(--paper); border: 1px solid var(--line);
  border-left: 4px solid var(--brand);
}
.metric-card--accent { border-left-color: var(--green); }
.metric-card--info { border-left-color: #4a6fa5; }
.metric-card--warn { border-left-color: var(--orange); }
.metric-value { font-size: clamp(1.25rem, 3vw, 1.625rem); font-weight: 800; color: var(--brand-deep); line-height: 1.2; }
.metric-label { color: var(--muted); font-size: 12px; display: block; font-weight: 600; margin-bottom: 4px; }
.login-wrap { max-width: 440px; padding-top: clamp(32px, 8vh, 72px); }
.login-brand { color: var(--green); font-weight: 700; letter-spacing: 0.08em; font-size: 11px; text-transform: uppercase; }
.login-title { margin: 10px 0 12px; font-size: clamp(1.25rem, 4vw, 1.5rem); color: var(--brand-deep); font-weight: 800; line-height: 1.35; }
.login-desc { color: var(--muted); margin-bottom: 20px; font-size: 14px; line-height: 1.65; }
.login-state-box { padding: 12px 14px; background: var(--brand-soft); border: 1px solid var(--line); border-radius: var(--radius-sm); margin-bottom: 16px; font-size: 14px; }
.login-actions { display: flex; flex-wrap: wrap; gap: 10px; }
.login-trust { margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--line); font-size: 12px; color: var(--muted); }
.demo-banner a { color: #a7f3d0; }
.checkbox-row { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; font-size: 14px; }
.checkbox-row-start { display: flex; gap: 8px; align-items: flex-start; }
.checkbox-row-start small { display: block; color: var(--muted); margin-top: 4px; }
.field-hint { display: block; color: var(--muted); margin-top: 4px; font-size: 12px; }
.input-mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }
.input-narrow { width: 70px; padding: 6px 8px; border: 1px solid var(--line); border-radius: 8px; font-size: 13px; font-family: inherit; }
.input-narrow-md { width: 80px; padding: 6px 8px; border: 1px solid var(--line); border-radius: 8px; font-size: 13px; font-family: inherit; }
.input-flex { flex: 1; padding: 8px; border: 1px solid var(--line); border-radius: 8px; font-size: 14px; font-family: inherit; }
.cond-label { display: block; margin: 4px 0; font-size: 13px; }
.empty-hint { grid-column: 1 / -1; color: var(--muted); font-size: 13px; }
.empty-state { color: var(--muted); font-size: 14px; }
.editor-embed-note { color: var(--muted); font-size: 13px; margin-bottom: 12px; }
.pref-grid.is-hidden { display: none; }
.pref-grid.mt-sm { margin-top: 8px; }

.modal-overlay.is-open { display: flex; }

/* Form controls — editor toolbar / admin selects */
.eq-toolbar select,
.field-select,
.js-q-type,
.js-q-cat,
.js-cond-qid,
#setting-prompt-version,
#setting-embed-initial,
#ua-role,
#setting-goal-type,
#setting-goal-rule-pref {
  min-height: 36px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  font-size: 13px;
  font-family: inherit;
  background: #fff;
  color: var(--ink);
  max-width: 100%;
}
.eq-toolbar select { min-width: 120px; }
.js-cond-qid { width: 100%; margin-bottom: 8px; }
.field-select-full { width: 100%; }

.admin-action-group {
  display: flex; flex-wrap: wrap; gap: 6px; align-items: center;
  width: max-content; max-width: 100%;
}
.admin-action-group .btn { flex-shrink: 0; }

.goal-rule-panel { border: 1px dashed var(--line); border-radius: 12px; padding: 12px; margin-top: 10px; background: #fafbfc; }

/* ===== レスポンシブ ===== */

@media (max-width: 768px) {
  .wrap { padding: 16px 12px 56px; }

  .page-intro { padding: 14px 16px; }

  .header { gap: 12px; }

  .card { padding: 16px; border-radius: var(--radius); }

  .card > .flex-row-between,
  .ai-card-header {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
  }

  .card > .flex-row-between .btn,
  .card > .flex-row-between .flex-row {
    width: 100%;
    justify-content: stretch;
  }

  .card > .flex-row-between .btn-orange,
  .card > .flex-row-between .btn-solid {
    width: 100%;
  }

  .session-toolbar {
    width: 100%;
    flex-direction: column;
    align-items: stretch;
  }

  .session-toolbar .field-select,
  .session-toolbar .btn {
    width: 100%;
  }

  .metric-grid { grid-template-columns: 1fr 1fr; }

  .table-wrap {
    margin: 0 -4px;
    padding-bottom: 2px;
  }

  .table-wrap::after {
    content: "表は左右にスワイプできます";
    display: block;
    text-align: center;
    font-size: 11px;
    color: var(--muted);
    padding: 8px 4px 0;
  }

  table.data { min-width: 720px; font-size: 13px; }
  table.data th, table.data td { padding: 10px 8px; }

  .admin-action-group,
  .flex-col-actions {
    width: 100%;
    max-width: none;
  }

  .modal { padding: 20px 16px; margin: 0; border-radius: var(--radius-lg); }

  .auth-gate-overlay { padding: 12px; }
  .auth-gate-box { padding: 32px 20px; }

  .toast {
    left: 12px;
    right: 12px;
    bottom: max(12px, env(safe-area-inset-bottom, 0px));
    max-width: none;
  }

  .login-actions { flex-direction: column; }
  .login-actions .btn { width: 100%; }

  .eq-toolbar { flex-direction: column; align-items: stretch; }
  .eq-toolbar select { width: 100%; min-width: 0; }

  .chip-row { gap: 8px; }
  .chip { flex: 1 1 calc(50% - 4px); min-width: 0; justify-content: center; text-align: center; }

  .chat-input-area {
    padding-left: 12px;
    padding-right: 12px;
    padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  }

  .chat-input-area button {
    flex: 0 0 auto;
    min-width: 64px;
  }

  .chat-input-area input { min-width: 0; flex: 1 1 120px; }
}

@media (max-width: 480px) {
  .wrap { padding: 12px 10px 48px; }

  .header h1 { font-size: 1.0625rem; }

  .demo-banner { font-size: 12px; padding: 8px 10px; }

  .tabs { gap: 4px; margin-bottom: 12px; }
  .tab { padding: 9px 14px; font-size: 12px; }

  .metric-grid { grid-template-columns: 1fr; }

  table.data { min-width: 640px; }

  .flex-row { gap: 6px; }

  .bubble { max-width: 94%; font-size: 14px; }

  .goal-form .form-actions { flex-direction: column; }
  .goal-form .form-actions .btn { width: 100%; }

  .chip { flex: 1 1 100%; }

  .ai-model-grid { grid-template-columns: 1fr; }

  .chat-app {
    max-width: 100%;
    margin: 0;
    box-shadow: none;
  }
}

.admin-muted-note { color: var(--muted); font-size: 13px; }
.detail-section-title { margin: 16px 0 8px; font-size: 15px; font-weight: 800; color: var(--brand-deep); }
.detail-list { font-size: 13px; }
.progress-muted { color: var(--muted); font-size: 12px; }

.ai-card-header { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.ai-model-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 10px; }
