:root {
  --bg: #f4f6f3;
  --surface: #ffffff;
  --surface-soft: #edf3ee;
  --ink: #202622;
  --muted: #65716a;
  --line: #d9e1dc;
  --brand: #2f6b59;
  --brand-dark: #224d42;
  --accent: #b7793b;
  --warning: #7d5330;
  --shadow: 0 18px 50px rgba(34, 77, 66, 0.12);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  color: var(--ink);
  font-family: "Segoe UI", "Hiragino Kaku Gothic ProN", "Yu Gothic UI", Meiryo, sans-serif;
  background: var(--bg);
}

.merchant-gate {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(244, 246, 243, 0.94);
  backdrop-filter: blur(6px);
}

.merchant-gate.hidden {
  display: none;
}

.merchant-card {
  display: grid;
  gap: 12px;
  width: min(440px, 100%);
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.merchant-card h1 {
  margin: 4px 0 0;
  font-size: 22px;
  letter-spacing: 0;
}

.merchant-card p {
  margin: 0 0 4px;
  color: var(--muted);
  line-height: 1.7;
}

.merchant-card label {
  font-weight: 700;
}

.merchant-card input {
  width: 100%;
  padding: 13px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  outline: none;
}

.merchant-card input:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(47, 107, 89, 0.14);
}

.merchant-card button {
  min-height: 44px;
  border: 0;
  border-radius: 8px;
  color: #fff;
  background: var(--brand);
  cursor: pointer;
  font-weight: 700;
}

button,
input {
  font: inherit;
}

.app-shell {
  display: grid;
  grid-template-columns: 300px minmax(420px, 1fr) 320px;
  gap: 18px;
  min-height: 100vh;
  padding: 18px;
}

.sidebar,
.chat-area,
.result-panel {
  min-width: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 18px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 8px;
  color: #fff;
  background: var(--brand);
  font-weight: 700;
}

.brand h1,
.chat-header h2,
.panel h2 {
  margin: 0;
  letter-spacing: 0;
}

.brand h1 {
  font-size: 18px;
}

.brand p,
.eyebrow,
.panel p {
  margin: 4px 0 0;
  color: var(--muted);
}

.eyebrow {
  font-size: 12px;
  font-weight: 700;
  color: var(--accent);
}

.panel {
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.panel + .panel {
  margin-top: 14px;
}

.panel h2 {
  font-size: 15px;
  margin-bottom: 12px;
}

.panel.compact p {
  font-size: 13px;
  line-height: 1.7;
}

.secondary-button {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--brand-dark);
  background: #fff;
  cursor: pointer;
  font-weight: 700;
}

.secondary-button:hover,
.secondary-button:focus-visible {
  border-color: var(--brand);
  outline: none;
}

.secondary-button.danger {
  color: var(--warning);
}

.secondary-button.full {
  width: 100%;
  margin: 10px 0 8px;
}

.category-list,
.match-list,
.suggestions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.category-button,
.suggestion-button {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: #fff;
  cursor: pointer;
  text-align: left;
}

.category-button {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 12px;
}

.category-button.active {
  border-color: var(--brand);
  background: var(--surface-soft);
  color: var(--brand-dark);
  font-weight: 700;
}

.category-button span:last-child {
  color: var(--muted);
}

.chat-area {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto auto;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--line);
  background: #fbfcfb;
}

.chat-header h2 {
  font-size: 22px;
}

.icon-button {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--brand-dark);
  background: #fff;
  cursor: pointer;
}

.messages {
  overflow: auto;
  padding: 20px;
}

.message {
  display: grid;
  gap: 7px;
  max-width: 82%;
  margin-bottom: 16px;
}

.message.user {
  margin-left: auto;
}

.bubble {
  padding: 13px 15px;
  border-radius: 8px;
  line-height: 1.75;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.bubble a {
  color: var(--brand-dark);
  font-weight: 700;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.bot .bubble {
  border: 1px solid var(--line);
  background: var(--surface-soft);
}

.user .bubble {
  color: #fff;
  background: var(--brand);
}

.meta {
  color: var(--muted);
  font-size: 12px;
}

.user .meta {
  text-align: right;
}

.error-report {
  max-width: 82%;
  margin: -6px 0 16px;
  padding: 12px;
  border: 1px solid #e2c8b0;
  border-radius: 8px;
  background: #fffaf4;
}

.error-report p {
  margin: 0 0 10px;
  color: var(--warning);
  font-size: 13px;
  line-height: 1.6;
}

.error-report button {
  min-height: 38px;
  padding: 0 14px;
  border: 1px solid var(--warning);
  border-radius: 8px;
  color: #fff;
  background: var(--warning);
  cursor: pointer;
  font-weight: 700;
}

.error-report button:disabled {
  cursor: default;
  opacity: 0.65;
}

.suggestions {
  display: grid;
  gap: 8px;
  padding: 0 20px 14px;
  max-height: 280px;
  overflow: auto;
}

.suggestion-button {
  display: grid;
  gap: 7px;
  padding: 13px 14px;
  line-height: 1.55;
  color: var(--brand-dark);
  background: #fffaf4;
}

.suggestion-button small {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.selection-panel {
  border-top: 1px solid var(--line);
  background: #fff;
}

.selection-heading {
  padding: 16px 20px 10px;
}

.selection-heading h3 {
  margin: 0;
  font-size: 17px;
  letter-spacing: 0;
}

.selection-heading p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.direct-input {
  border-top: 1px solid var(--line);
  background: #fbfcfb;
}

.direct-input summary {
  padding: 14px 20px;
  color: var(--brand-dark);
  cursor: pointer;
  font-weight: 700;
}

.composer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 88px;
  gap: 10px;
  padding: 0 20px 20px;
  border-top: 0;
  background: #fbfcfb;
}

.composer input {
  width: 100%;
  min-width: 0;
  padding: 13px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  outline: none;
  background: #fff;
}

.composer input:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(47, 107, 89, 0.14);
}

.composer button {
  border: 0;
  border-radius: 8px;
  color: #fff;
  background: var(--brand);
  cursor: pointer;
  font-weight: 700;
}

.composer button:disabled,
.composer input:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.match-card {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  cursor: pointer;
  transition:
    border-color 0.15s ease,
    box-shadow 0.15s ease,
    transform 0.15s ease;
}

.match-card:hover,
.match-card:focus-visible {
  border-color: var(--brand);
  box-shadow: 0 10px 24px rgba(47, 107, 89, 0.12);
  outline: none;
  transform: translateY(-1px);
}

.match-card h3 {
  margin: 0 0 8px;
  font-size: 14px;
  line-height: 1.5;
}

.match-card p {
  margin: 0;
  font-size: 12px;
  line-height: 1.6;
}

.match-card .score {
  margin-top: 6px;
  color: var(--accent);
  font-weight: 700;
}

.badge {
  display: inline-flex;
  margin-bottom: 8px;
  padding: 3px 7px;
  border-radius: 6px;
  color: var(--brand-dark);
  background: var(--surface-soft);
  font-size: 12px;
  font-weight: 700;
}

.empty {
  color: var(--muted);
  line-height: 1.7;
}

@media (max-width: 1120px) {
  .app-shell {
    grid-template-columns: 260px minmax(0, 1fr);
  }

  .result-panel {
    grid-column: 1 / -1;
  }
}

@media (max-width: 760px) {
  body {
    background: var(--surface);
  }

  .app-shell {
    grid-template-columns: 1fr;
    gap: 10px;
    padding: 8px;
  }

  .brand {
    margin-bottom: 10px;
  }

  .brand-mark {
    width: 38px;
    height: 38px;
  }

  .brand h1 {
    font-size: 16px;
  }

  .panel {
    padding: 12px;
    box-shadow: none;
  }

  .category-list {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .category-button {
    align-items: flex-start;
    min-height: 44px;
    padding: 11px 10px;
    line-height: 1.45;
  }

  .category-button span:first-child {
    overflow-wrap: anywhere;
  }

  .category-button span:last-child {
    flex: 0 0 auto;
    line-height: 1.45;
  }

  .chat-area {
    min-height: 72vh;
    box-shadow: none;
  }

  .chat-header {
    padding: 14px;
  }

  .chat-header h2 {
    font-size: 18px;
  }

  .messages {
    padding: 14px;
  }

  .message {
    max-width: 100%;
    margin-bottom: 12px;
  }

  .error-report {
    max-width: 100%;
  }

  .error-report button {
    width: 100%;
  }

  .bubble {
    padding: 12px;
    line-height: 1.65;
  }

  .selection-heading {
    padding: 14px 14px 8px;
  }

  .selection-heading h3 {
    font-size: 16px;
  }

  .suggestions {
    gap: 10px;
    max-height: 360px;
    padding: 0 12px 16px;
  }

  .suggestion-button {
    min-height: 56px;
    padding: 14px 12px;
    line-height: 1.6;
  }

  .suggestion-button span {
    display: block;
    overflow-wrap: anywhere;
  }

  .direct-input summary {
    padding: 14px;
  }

  .composer {
    grid-template-columns: 1fr;
    padding: 0 14px 14px;
  }

  .composer button {
    min-height: 44px;
  }

  .result-panel {
    display: none;
  }
}
