:root {
  --navy: #123a5c;
  --navy-dark: #0d2b45;
  --navy-soft: #e8eef4;
  --amber: #f4b942;
  --amber-dark: #d99b1f;
  --bg: #f4f6f8;
  --card: #ffffff;
  --text: #1b2733;
  --muted: #64748b;
  --line: #dde5ec;
  --ok: #1f9d63;
  --warn: #b45309;
  --radius: 16px;
  --header-h: 62px;
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Noto Sans JP", "Yu Gothic", Meiryo, sans-serif;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.75;
  -webkit-text-size-adjust: 100%;
  display: flex;
  flex-direction: column;
  height: 100dvh;
}

.app-header {
  flex: 0 0 auto;
  height: var(--header-h);
  padding: 0 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: linear-gradient(135deg, var(--navy) 0%, var(--navy-dark) 100%);
  color: #fff;
  box-shadow: 0 2px 10px rgba(13, 43, 69, .18);
  z-index: 10;
}

.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }

.brand-mark {
  width: 36px; height: 36px;
  border-radius: 10px;
  background: var(--amber);
  color: var(--navy-dark);
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 15px; letter-spacing: .5px;
  flex: 0 0 auto;
}

.brand-text h1 {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: .02em;
  line-height: 1.3;
  white-space: nowrap;
}

.brand-text p {
  margin: 1px 0 0;
  font-size: 11px;
  color: rgba(255, 255, 255, .72);
  line-height: 1.2;
}

.header-actions { display: flex; gap: 6px; }

.icon-btn {
  width: 38px; height: 38px;
  border: 0;
  border-radius: 10px;
  background: rgba(255, 255, 255, .1);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  transition: background .15s ease;
}
.icon-btn:hover { background: rgba(255, 255, 255, .2); }
.icon-btn svg { width: 20px; height: 20px; }

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

.msg { display: flex; gap: 9px; max-width: 100%; animation: rise .22s ease both; }

@keyframes rise {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

.msg.user { flex-direction: row-reverse; }

.avatar {
  flex: 0 0 auto;
  width: 32px; height: 32px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700;
  margin-top: 2px;
}
.msg.ai .avatar { background: var(--amber); color: var(--navy-dark); }
.msg.user .avatar { background: var(--navy-soft); color: var(--navy); }

.bubble-col { min-width: 0; max-width: 86%; }
.msg.user .bubble-col { display: flex; flex-direction: column; align-items: flex-end; }

.bubble {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  border-top-left-radius: 6px;
  padding: 12px 14px;
  white-space: pre-wrap;
  word-break: break-word;
  box-shadow: 0 1px 2px rgba(15, 37, 56, .05);
}

.msg.user .bubble {
  background: var(--navy);
  border-color: var(--navy);
  color: #fff;
  border-radius: var(--radius);
  border-top-right-radius: 6px;
}

.msg.ai .bubble { font-size: 15px; }

.bubble .lead { color: var(--navy); font-weight: 700; }

.msg-meta {
  margin-top: 5px;
  font-size: 11px;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 8px;
}

.msg.user .msg-meta { justify-content: flex-end; }

.copy-btn {
  border: 0;
  background: none;
  color: var(--muted);
  font-size: 11px;
  padding: 2px 0;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
}
.copy-btn:hover { color: var(--navy); }

.welcome { max-width: 100%; }
.welcome .bubble { background: #fffdf6; border-color: #f0dfae; }
.welcome .bubble .lead { color: var(--navy); }
.welcome .bubble p { margin: 0 0 8px; }
.welcome .bubble p:last-child { margin-bottom: 0; }
.welcome .note { font-size: 12px; color: var(--muted); margin-top: 8px; }

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 4px 0 0 41px;
}

.chip {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--navy);
  border-radius: 999px;
  padding: 7px 13px;
  font-size: 12.5px;
  font-family: inherit;
  cursor: pointer;
  transition: all .15s ease;
}
.chip:hover { border-color: var(--navy); background: var(--navy-soft); }

.typing { display: inline-flex; gap: 5px; padding: 4px 0; }
.typing span {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--navy);
  opacity: .35;
  animation: pulse 1.1s infinite ease-in-out;
}
.typing span:nth-child(2) { animation-delay: .18s; }
.typing span:nth-child(3) { animation-delay: .36s; }

@keyframes pulse {
  0%, 70%, 100% { opacity: .25; transform: translateY(0); }
  35% { opacity: 1; transform: translateY(-3px); }
}

.status-line {
  font-size: 12px;
  color: var(--muted);
  margin: 0 0 0 41px;
}

.err-bubble {
  background: #fff5f5;
  border-color: #f3c2c2;
  color: #8f2323;
  font-size: 13.5px;
}

.composer-wrap {
  flex: 0 0 auto;
  padding: 8px 12px calc(10px + env(safe-area-inset-bottom));
  background: linear-gradient(to top, var(--bg) 78%, rgba(244, 246, 248, 0));
}

.hint {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: #fff8e6;
  border: 1px solid #f0dca8;
  border-radius: 12px;
  padding: 9px 12px;
  font-size: 12.5px;
  color: #7a5a10;
  margin-bottom: 8px;
}

.link-btn {
  border: 0;
  background: none;
  color: var(--navy);
  font-weight: 700;
  font-size: 12.5px;
  cursor: pointer;
  text-decoration: underline;
  white-space: nowrap;
}

.composer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 7px 7px 7px 15px;
  box-shadow: 0 3px 14px rgba(15, 37, 56, .07);
}

.composer:focus-within { border-color: var(--navy); }

.composer textarea {
  flex: 1 1 auto;
  border: 0;
  outline: 0;
  resize: none;
  font-family: inherit;
  font-size: 15px;
  line-height: 1.6;
  max-height: 132px;
  padding: 6px 0;
  background: transparent;
  color: var(--text);
}

.send-btn {
  flex: 0 0 auto;
  width: 40px; height: 40px;
  border: 0;
  border-radius: 14px;
  background: var(--navy);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  transition: background .15s ease, transform .1s ease;
}
.send-btn:hover { background: var(--navy-dark); }
.send-btn:active { transform: scale(.95); }
.send-btn:disabled { background: #b9c6d2; cursor: default; }
.send-btn svg { width: 20px; height: 20px; }

.disclaimer {
  margin: 7px 4px 0;
  font-size: 10.5px;
  color: var(--muted);
  text-align: center;
  line-height: 1.5;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(10, 26, 40, .55);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 50;
  padding: 0;
}

.modal[hidden] { display: none; }

.modal-panel {
  width: 100%;
  max-width: 560px;
  max-height: 92dvh;
  overflow-y: auto;
  background: #fff;
  border-radius: 20px 20px 0 0;
  padding: 18px 18px calc(18px + env(safe-area-inset-bottom));
  animation: slideUp .22s ease both;
}

@keyframes slideUp {
  from { transform: translateY(24px); opacity: .6; }
  to { transform: none; opacity: 1; }
}

.modal-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.modal-head h2 { margin: 0; font-size: 18px; }
.modal-sub { margin: 2px 0 0; font-size: 12px; color: var(--muted); }
.modal-head .icon-btn { background: var(--navy-soft); color: var(--navy); width: 34px; height: 34px; }

.field { display: block; margin-bottom: 16px; }
.field > span { display: block; font-size: 13px; font-weight: 700; margin-bottom: 6px; }
.field small { display: block; margin-top: 6px; font-size: 11.5px; color: var(--muted); line-height: 1.6; }
.field a { color: var(--navy); }

.input-row { display: flex; gap: 8px; }

.input, .select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 14px;
  font-family: inherit;
  background: #fff;
  color: var(--text);
  outline: 0;
}
.input:focus, .select:focus { border-color: var(--navy); }

.btn {
  border: 0;
  border-radius: 10px;
  background: var(--navy);
  color: #fff;
  font-family: inherit;
  font-size: 14px;
  font-weight: 700;
  padding: 11px 18px;
  cursor: pointer;
}
.btn:hover { background: var(--navy-dark); }
.btn.ghost { background: #fff; color: var(--navy); border: 1px solid var(--line); }
.btn.ghost:hover { background: var(--navy-soft); }
.btn.small { padding: 10px 12px; font-size: 12.5px; white-space: nowrap; }

.notice {
  background: #fff8e6;
  border: 1px solid #f0dca8;
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 12px;
  color: #7a5a10;
  line-height: 1.6;
  margin-bottom: 14px;
}

.actions { display: flex; gap: 8px; flex-wrap: wrap; }

.danger-link {
  display: block;
  margin: 18px auto 0;
  border: 0;
  background: none;
  color: #a13b3b;
  font-size: 12.5px;
  font-family: inherit;
  text-decoration: underline;
  text-underline-offset: 2px;
  cursor: pointer;
}

.about {
  margin-top: 18px;
  border-top: 1px solid var(--line);
  padding-top: 12px;
  font-size: 12.5px;
  color: var(--muted);
}
.about summary { cursor: pointer; color: var(--navy); font-weight: 700; }
.about p { margin: 8px 0 0; line-height: 1.7; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(92px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: rgba(18, 58, 92, .95);
  color: #fff;
  font-size: 12.5px;
  padding: 9px 16px;
  border-radius: 999px;
  z-index: 80;
  box-shadow: 0 4px 14px rgba(10, 26, 40, .25);
  max-width: 90vw;
  text-align: center;
}
.toast[hidden] { display: none; }

@media (min-width: 720px) {
  body { max-width: 780px; margin: 0 auto; box-shadow: 0 0 30px rgba(10, 26, 40, .08); }
  .chat { padding: 24px 22px 8px; }
  .bubble-col { max-width: 78%; }
  .modal { align-items: center; padding: 20px; }
  .modal-panel { border-radius: 20px; max-height: 86dvh; }
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1922;
    --card: #17242f;
    --text: #e6edf3;
    --muted: #93a4b4;
    --line: #2a3b4a;
    --navy-soft: #203647;
  }
  .bubble { box-shadow: none; }
  .welcome .bubble { background: #232a1f; border-color: #4a4526; }
  .chip { background: #17242f; color: #cfe0ee; }
  .composer { background: #17242f; }
  .composer textarea { color: var(--text); }
  .modal-panel { background: #131f29; }
  .input, .select { background: #17242f; color: var(--text); }
  .btn.ghost { background: #17242f; color: #cfe0ee; }
  .err-bubble { background: #3a1f1f; border-color: #6b3535; color: #ffc9c9; }
  .hint, .notice { background: #2c2717; border-color: #524824; color: #e8cf94; }
  .msg.user .bubble { background: #1d4e78; border-color: #1d4e78; }
  .msg.user .avatar { background: #203647; color: #cfe0ee; }
  .welcome .bubble .lead { color: #f4b942; }
  .bubble .lead { color: #9dc4e6; }
}
