:root {
  --bg: #f6f7f6;
  --panel: #ffffff;
  --text: #1b2520;
  --muted: #5b665f;
  --line: #d7dfd5;
  --green: #1d7550;
  --deep-green: #244536;
  --mint: #e7f2ec;
  --amber: #a76500;
  --red: #b3261e;
  --blue: #1f5f99;
  --user: #d9eefc;
  --bot: #ffffff;
  --shadow: 0 12px 28px rgba(22, 32, 27, 0.12);
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Yu Gothic", "Hiragino Kaku Gothic ProN", Meiryo, sans-serif;
  font-size: 19px;
  line-height: 1.65;
}

button,
textarea,
input {
  font: inherit;
}

button {
  border: 0;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 800;
  min-height: 48px;
  padding: 10px 16px;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

button:focus-visible,
textarea:focus-visible {
  outline: 4px solid rgba(31, 95, 153, 0.25);
  outline-offset: 2px;
}

input {
  width: 100%;
  min-height: 54px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  background: #fff;
  color: var(--text);
}

body.auth-locked .chat-app,
body.auth-locked .deep-dive-drawer,
body.auth-locked .print-panel {
  display: none;
}

body:not(.auth-locked) .login-gate {
  display: none;
}

.login-gate {
  width: min(520px, calc(100% - 24px));
  margin: 18px auto;
}

.login-card {
  display: grid;
  gap: 12px;
  padding: 20px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.login-card .eyebrow {
  color: var(--green);
}

.login-card label {
  color: var(--deep-green);
  font-weight: 900;
}

.login-note {
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 0.95rem;
  font-weight: 700;
}

.login-mascot {
  width: 76px;
  height: 76px;
  overflow: hidden;
  border: 3px solid #bee2d0;
  border-radius: 50%;
  background: #e9f8f0;
}

.login-mascot img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.app-header {
  background: var(--deep-green);
  color: #fff;
  padding: 10px 16px;
}

.header-inner,
.chat-app {
  width: min(980px, 100%);
  margin: 0 auto;
}

.header-inner {
  display: grid;
  grid-template-columns: 76px 1fr;
  gap: 14px;
  align-items: center;
}

.mascot-frame,
.avatar {
  display: grid;
  place-items: center;
  overflow: hidden;
  background: #e9f8f0;
  border: 3px solid #bee2d0;
  border-radius: 50%;
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.16);
}

.mascot-frame {
  width: 74px;
  height: 74px;
}

.mascot-frame img,
.avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.fallback-mascot {
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  color: var(--deep-green);
  font-weight: 900;
  font-size: 2rem;
}

.fallback-mascot.small {
  font-size: 1.35rem;
}

.eyebrow {
  margin: 0 0 4px;
  color: #cfe0d6;
  font-size: 0.9rem;
  font-weight: 800;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 4px;
  font-size: clamp(1.35rem, 5vw, 2rem);
  line-height: 1.25;
}

h2 {
  margin-bottom: 2px;
  font-size: 1.35rem;
  line-height: 1.3;
}

h3 {
  margin-bottom: 8px;
  font-size: 1.12rem;
}

.lead {
  margin-bottom: 0;
  font-size: 0.96rem;
}

.chat-app {
  padding: 16px 64px 16px 16px;
}

.chat-card {
  display: grid;
  grid-template-rows: auto auto minmax(380px, 1fr) auto auto auto;
  min-height: calc(100vh - 130px);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

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

.assistant-profile {
  display: flex;
  gap: 12px;
  align-items: center;
  min-width: 0;
}

.assistant-profile .eyebrow {
  color: var(--green);
}

.avatar {
  width: 62px;
  height: 62px;
  flex: 0 0 auto;
}

.step-status {
  margin: 0;
  color: var(--muted);
  font-size: 0.95rem;
  font-weight: 700;
}

.top-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.top-actions button {
  min-height: 44px;
  padding: 8px 12px;
  font-size: 0.95rem;
}

.secondary-button {
  background: #e8efe9;
  color: #173a2b;
  border: 1px solid #c9d5cc;
}

.ghost-button {
  background: #fff;
  color: #315343;
  border: 1px solid #cfd8d1;
}

.compact-status {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  background: #fbfdfb;
}

.risk-summary {
  color: var(--muted);
  font-size: 0.92rem;
  font-weight: 800;
}

.mode-badge {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  border-radius: 999px;
  padding: 3px 10px;
  background: #eef3f0;
  color: #244536;
  border: 1px solid #cbd8d0;
  font-size: 0.92rem;
  font-weight: 900;
}

.mode-badge.ai {
  background: #e8f2ff;
  color: #174777;
  border-color: #bfd5ef;
}

.mode-badge.fallback {
  background: #fff4d8;
  color: #6d4300;
  border-color: #e7c878;
}

.mode-badge.error {
  background: #ffe1de;
  color: #7d1711;
  border-color: #efbbb7;
}

.mode-text {
  color: var(--muted);
  font-size: 0.92rem;
  font-weight: 800;
}

.demo-panel {
  margin: 10px 14px 0;
  padding: 12px;
  border: 1px solid #d7dfd5;
  border-radius: 8px;
  background: #ffffff;
}

.demo-panel p {
  margin-bottom: 10px;
  color: var(--muted);
  font-weight: 800;
}

.sample-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 10px;
}

.sample-grid button {
  display: grid;
  gap: 2px;
  min-height: 58px;
  background: #f5f8f5;
  color: #173a2b;
  border: 1px solid #cbd8d0;
  text-align: left;
}

.sample-grid button small {
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 700;
}

.demo-script {
  margin-top: 12px;
  padding: 12px;
  border-radius: 8px;
  background: #f7faf8;
  border: 1px solid #d7dfd5;
}

.demo-script strong {
  display: block;
  margin-bottom: 6px;
  color: #244536;
}

.demo-script ol {
  margin: 0;
  padding-left: 1.25em;
}

.demo-script li {
  margin: 3px 0;
}

.chat-log {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 14px 14px 130px;
  overflow-y: auto;
  scroll-behavior: smooth;
}

.message {
  display: grid;
  gap: 8px;
  max-width: min(760px, 100%);
}

.message.bot {
  grid-template-columns: 42px minmax(0, 1fr);
  align-self: start;
}

.message.user {
  align-self: end;
}

.message-avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  overflow: hidden;
  background: var(--mint);
  border: 2px solid #c4e4d2;
}

.message-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.bubble {
  min-width: 0;
  padding: 12px 14px;
  border-radius: 8px;
  word-break: break-word;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.bubble p {
  white-space: pre-wrap;
}

.bot .bubble {
  background: var(--bot);
  border: 1px solid var(--line);
  border-top-left-radius: 2px;
}

.user .bubble {
  background: var(--user);
  border: 1px solid #b9daf0;
  border-top-right-radius: 2px;
}

.bubble p:last-child,
.answer-section p:last-child {
  margin-bottom: 0;
}

.answer-section {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}

.answer-section ul,
.answer-section ol {
  margin: 8px 0 0;
  padding-left: 1.25em;
}

.answer-section li {
  margin: 6px 0;
}

.risk-badge {
  display: inline-flex;
  align-items: center;
  min-height: 42px;
  border-radius: 8px;
  padding: 6px 14px;
  font-size: 1.15rem;
  font-weight: 900;
}

.risk-low {
  color: #0d4d2f;
  background: #dff3e8;
}

.risk-medium {
  color: #6d4300;
  background: #ffedc2;
}

.risk-high {
  color: #7d1711;
  background: #ffd7d4;
}

.note {
  color: var(--muted);
  font-weight: 800;
}

.choice-area {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

.choice-area:empty {
  display: none;
}

.deep-dive-drawer {
  position: fixed;
  top: 190px;
  right: -360px;
  z-index: 20;
  width: min(360px, calc(100vw - 42px));
  transform: translateX(0);
  transition: transform 180ms ease;
}

.deep-dive-drawer.open {
  transform: translateX(-360px);
}

.deep-dive-tab {
  position: absolute;
  top: 18px;
  left: -54px;
  width: 42px;
  min-height: 112px;
  padding: 8px 4px;
  border-radius: 8px 0 0 8px;
  background: var(--deep-green);
  color: #fff;
  border: 1px solid #173a2b;
  writing-mode: vertical-rl;
  letter-spacing: 0;
  box-shadow: 0 8px 18px rgba(22, 32, 27, 0.18);
}

.deep-dive-panel {
  max-height: min(70vh, 560px);
  overflow-y: auto;
  padding: 12px;
  background: #fff;
  border: 1px solid var(--line);
  border-right: 0;
  border-radius: 8px 0 0 8px;
  box-shadow: -10px 12px 28px rgba(22, 32, 27, 0.16);
}

.deep-dive-head {
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
  color: var(--deep-green);
}

.deep-dive-head button {
  min-height: 42px;
  padding: 6px 10px;
}

.export-panel {
  padding: 12px 14px;
  border-top: 1px solid var(--line);
  background: #fff;
}

.export-panel p {
  margin-bottom: 10px;
  color: var(--muted);
  font-weight: 800;
}

.export-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 10px;
}

.export-grid button {
  min-height: 56px;
  background: #eef3f0;
  color: #173a2b;
  border: 1px solid #cbd8d0;
}

.print-panel {
  width: min(980px, calc(100% - 32px));
  margin: 0 auto 24px;
  background: #f7faf8;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.print-toolbar {
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  background: #fff;
}

.print-toolbar > div {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.print-sheet {
  margin: 16px;
  padding: 24px;
  background: #fff;
  border: 1px solid #d8e0da;
  border-radius: 8px;
}

.print-sheet h2 {
  margin-bottom: 16px;
  color: var(--deep-green);
}

.print-sheet pre {
  margin: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-family: "Yu Gothic", "Hiragino Kaku Gothic ProN", Meiryo, sans-serif;
  font-size: 1rem;
  line-height: 1.75;
}

.choice-button {
  min-height: 58px;
  background: #eef3f0;
  color: #173a2b;
  border: 1px solid #cbd8d0;
  text-align: left;
}

.choice-button.subtle {
  background: #eef3f7;
  color: #183b58;
  border-color: #c8d6e0;
}

.composer {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto auto;
  gap: 8px;
  padding: 14px 14px 6px;
  border-top: 1px solid var(--line);
  background: #fbfcfb;
  position: sticky;
  bottom: 0;
  z-index: 10;
}

textarea {
  width: 100%;
  min-height: 76px;
  max-height: 150px;
  resize: vertical;
  border: 2px solid #b9c2ba;
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  padding: 10px 12px;
  font-size: 1.05rem;
}

.primary-button {
  background: var(--deep-green);
  color: #fff;
}

.icon-button {
  background: #e7f0fb;
  color: #1f4f7d;
  border: 1px solid #c7d9eb;
}

.status-text {
  min-height: 28px;
  margin: 0;
  padding: 0 14px 12px;
  color: var(--muted);
  font-size: 0.95rem;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}

@media (max-width: 640px) {
  body {
    font-size: 18px;
  }

  .app-header {
    padding: 14px 12px;
  }

  .header-inner {
    grid-template-columns: 64px 1fr;
  }

  .mascot-frame {
    width: 62px;
    height: 62px;
  }

  h1 {
    font-size: 1.35rem;
  }

  .lead {
    display: none;
  }

  .chat-app {
    padding: 10px 54px 10px 8px;
  }

  .chat-card {
    min-height: calc(100vh - 96px);
  }

  .chat-topbar {
    align-items: flex-start;
    display: grid;
    gap: 10px;
  }

  .top-actions {
    display: flex;
    flex-wrap: wrap;
    width: 100%;
  }

  .top-actions button {
    flex: 1 1 46%;
    min-height: 44px;
  }

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

  .choice-area {
    grid-template-columns: 1fr;
  }

  .deep-dive-drawer {
    top: 150px;
    right: -330px;
    width: min(330px, calc(100vw - 48px));
  }

  .deep-dive-drawer.open {
    transform: translateX(-330px);
  }

  .deep-dive-tab {
    left: -50px;
    width: 42px;
    min-height: 42px;
    border-radius: 999px 0 0 999px;
    writing-mode: horizontal-tb;
    font-size: 0.95rem;
  }

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

  .print-panel {
    width: calc(100% - 16px);
    margin-bottom: 16px;
  }

  .print-toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .print-toolbar > div,
  .print-toolbar button {
    width: 100%;
  }

  .print-sheet {
    margin: 8px;
    padding: 16px;
  }

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

  .composer textarea {
    grid-column: 1 / -1;
  }

  .composer button {
    width: 100%;
    min-height: 48px;
  }
}

@media print {
  body {
    background: #fff;
  }

  .app-header,
  .chat-app,
  .print-toolbar {
    display: none !important;
  }

  .print-panel {
    display: block !important;
    width: 100%;
    margin: 0;
    border: 0;
    box-shadow: none;
  }

  .print-sheet {
    margin: 0;
    padding: 0;
    border: 0;
  }

  .print-sheet pre {
    font-size: 12pt;
    line-height: 1.65;
  }
}
