:root {
  color-scheme: light;
  --bg: #f7f7f8;
  --panel: #ffffff;
  --text: #202123;
  --muted: #6b6c70;
  --border: #dedfe2;
  --accent: #10a37f;
  --accent-dark: #0d876a;
  --user: #ececf1;
  --danger: #b42318;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans JP", sans-serif;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  line-height: 1.65;
}

button, input, textarea { font: inherit; }

button { cursor: pointer; }
button:disabled { cursor: wait; opacity: .55; }

.app-shell {
  height: 100%;
  display: grid;
  grid-template-columns: 250px minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr) auto;
}

.history-sidebar {
  grid-column: 1;
  grid-row: 1 / -1;
  min-height: 0;
  padding: 18px 12px;
  display: flex;
  flex-direction: column;
  background: #f0f0f2;
  border-right: 1px solid var(--border);
}
.history-heading {
  padding: 0 9px 10px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}
.history-list {
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
  overflow-y: auto;
}
.history-item {
  width: 100%;
  padding: 9px 10px;
  border: 1px solid transparent;
  border-radius: 9px;
  background: transparent;
  color: var(--text);
  overflow: hidden;
  text-align: left;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.history-item:hover:not(:disabled) { background: rgba(255,255,255,.72); }
.history-item.is-active {
  background: var(--panel);
  border-color: var(--border);
  font-weight: 650;
}
.history-empty { padding: 8px 9px; color: var(--muted); font-size: 12px; }

.app-header { grid-column: 2; grid-row: 1; }
.chat-main { grid-column: 2; grid-row: 2; }
footer.composer-wrap { grid-column: 2; grid-row: 3; }

.app-header {
  min-height: 68px;
  padding: 10px 22px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  z-index: 2;
}

.app-title { font-weight: 700; font-size: 18px; }
.participant-name { color: var(--muted); font-size: 12px; }

.header-actions { display: flex; align-items: center; gap: 10px; }
.header-actions form { margin: 0; }

.secondary-button,
.text-button {
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--panel);
  color: var(--text);
  padding: 8px 13px;
}

.secondary-button:hover { background: #f2f2f3; }
.text-button { color: var(--muted); border-color: transparent; }
.text-button:hover { color: var(--text); background: #f2f2f3; }

.chat-main {
  min-height: 0;
  overflow-y: auto;
  padding: 28px 0 110px;
}

.topic-card,
.empty-state,
.message-inner,
.composer-wrap {
  width: min(820px, calc(100% - 32px));
  margin-left: auto;
  margin-right: auto;
}

.topic-card {
  padding: 17px 20px;
  margin-bottom: 26px;
  border: 1px solid #cfe8e1;
  border-radius: 14px;
  background: #f2fbf8;
}

.topic-card[hidden], .empty-state[hidden] { display: none; }
.topic-label { color: var(--accent-dark); font-size: 12px; font-weight: 700; }
.topic-card h1 { margin: 2px 0 3px; font-size: 17px; }
.topic-card p { margin: 0; color: #4c625c; }

.empty-state {
  margin-top: 10vh;
  text-align: center;
  color: var(--muted);
}

.empty-icon,
.brand-mark {
  width: 48px;
  height: 48px;
  margin: 0 auto 14px;
  display: grid;
  place-items: center;
  border-radius: 14px;
  background: var(--accent);
  color: white;
  font-weight: 800;
}

.empty-state h1 { margin: 0 0 6px; color: var(--text); font-size: 24px; }
.empty-state p { margin: 0; }

.messages { display: flex; flex-direction: column; gap: 4px; }
.message { padding: 22px 0; }
.message-user { background: var(--user); }
.message-label { margin-bottom: 5px; font-size: 13px; font-weight: 700; }
.message-body { overflow-wrap: anywhere; line-height: 1.7; }
.message-body > :first-child { margin-top: 0; }
.message-body > :last-child { margin-bottom: 0; }
.message-assistant.is-new-answer .message-inner {
  animation: answer-reveal .36s cubic-bezier(.22, .75, .3, 1) both;
}
.message-assistant.is-new-answer .message-files {
  animation: answer-assets-reveal .3s ease-out .14s both;
}
@keyframes answer-reveal {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes answer-assets-reveal {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}
.message-body p { margin: 0 0 12px; }
.message-body h2,
.message-body h3,
.message-body h4 { margin: 20px 0 8px; line-height: 1.35; }
.message-body h2 { font-size: 20px; }
.message-body h3 { font-size: 17px; }
.message-body h4 { font-size: 15px; }
.message-body ul,
.message-body ol { margin: 8px 0 14px; padding-left: 1.6em; }
.message-body li { margin: 4px 0; }
.message-body blockquote {
  margin: 12px 0;
  padding: 8px 14px;
  border-left: 4px solid var(--accent);
  background: #f2fbf8;
  color: #46534f;
  white-space: pre-wrap;
}
.message-body a { color: #087f68; text-decoration: underline; }
.message-body .inline-code {
  padding: 2px 5px;
  border-radius: 5px;
  background: #ececf1;
  font-family: Consolas, Monaco, monospace;
  font-size: .92em;
}
.ai-working {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  color: var(--muted);
  font-size: 14px;
}
.image-job-error { color: #b42318; }
.ai-working::before {
  content: '';
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--accent);
  animation: ai-working-pulse 1.5s ease-in-out infinite;
}
.ai-working-dots { display: inline-flex; align-items: center; gap: 4px; }
.ai-working-dots span {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: currentColor;
  animation: ai-working-dot 1.2s ease-in-out infinite;
}
.ai-working-dots span:nth-child(2) { animation-delay: .15s; }
.ai-working-dots span:nth-child(3) { animation-delay: .3s; }
@keyframes ai-working-pulse {
  0%, 100% { opacity: .35; transform: scale(.8); }
  50% { opacity: 1; transform: scale(1.15); }
}
@keyframes ai-working-dot {
  0%, 60%, 100% { opacity: .3; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-3px); }
}
@media (prefers-reduced-motion: reduce) {
  .ai-working::before,
  .ai-working-dots span,
  .message-assistant.is-new-answer .message-inner,
  .message-assistant.is-new-answer .message-files { animation: none; opacity: 1; transform: none; }
}
.message-body pre {
  margin: 14px 0;
  padding: 16px;
  overflow-x: auto;
  border-radius: 10px;
  background: #202123;
  color: #f7f7f8;
  white-space: pre;
}
.message-files {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 14px;
}
.message-actions { margin-top: 10px; }
.message-actions button {
  padding: 4px 8px;
  border: 1px solid transparent;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
}
.message-actions button:hover { border-color: var(--border); background: var(--panel); color: var(--text); }
.copy-helper { position: fixed; left: -9999px; top: 0; }

.file-card {
  width: min(360px, 100%);
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 11px 13px;
  border: 1px solid var(--border);
  border-radius: 11px;
  background: var(--panel);
  color: var(--text);
  text-decoration: none;
}
.file-card:hover { border-color: #aeb0b5; }
.file-icon {
  min-width: 48px;
  padding: 7px 5px;
  border-radius: 7px;
  background: #e7f6f1;
  color: var(--accent-dark);
  font-size: 10px;
  font-weight: 800;
  text-align: center;
}
.file-details { min-width: 0; display: flex; flex-direction: column; }
.file-details strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-details small { color: var(--muted); }

.message-image { margin: 0; max-width: 320px; }
.message-image.generated-image { max-width: min(640px, 100%); }
.message-image img {
  display: block;
  max-width: 100%;
  max-height: 640px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: white;
}
.message-image figcaption {
  margin-top: 6px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 6px 10px;
  color: var(--muted);
  font-size: 11px;
}
.image-edit-button {
  padding: 5px 9px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--panel);
  color: var(--accent-dark);
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}
.image-edit-button:hover { border-color: var(--accent); background: #f0faf7; }
.image-edit-button:disabled { cursor: not-allowed; opacity: .55; }
.is-temporary { opacity: .68; }

.composer-wrap {
  position: relative;
  padding: 0 0 12px;
}

footer.composer-wrap {
  width: 100%;
  max-width: none;
  padding: 12px max(16px, calc((100% - 820px) / 2));
  background: linear-gradient(to bottom, rgba(247,247,248,0), var(--bg) 18%);
}

.pending-files {
  width: min(820px, 100%);
  min-height: 0;
  margin: 0 auto 7px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.pending-file {
  max-width: 260px;
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 6px 8px 6px 11px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--panel);
  font-size: 12px;
}
.pending-file span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pending-file button {
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 0 3px;
  font-size: 17px;
  line-height: 1;
}
.edit-source-file {
  border-color: var(--accent);
  background: #f0faf7;
  color: var(--accent-dark);
  font-weight: 700;
}

.composer {
  width: min(820px, 100%);
  min-height: 58px;
  margin: 0 auto;
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 10px 10px 10px 17px;
  border: 1px solid #c9cacf;
  border-radius: 16px;
  background: var(--panel);
  box-shadow: 0 3px 14px rgba(0,0,0,.08);
}

.composer:focus-within { border-color: #8f9298; }
.composer.is-dragging {
  border-color: var(--accent);
  background: #f0faf7;
  box-shadow: 0 0 0 3px rgba(23, 129, 103, .14), 0 3px 14px rgba(0,0,0,.08);
}

.composer textarea {
  flex: 1;
  min-height: 36px;
  max-height: 180px;
  resize: none;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  line-height: 1.5;
  padding: 6px 0;
}

.attach-button {
  width: 38px;
  height: 38px;
  flex: 0 0 38px;
  border: 0;
  border-radius: 10px;
  background: #ececf1;
  color: var(--text);
  font-size: 24px;
  line-height: 1;
}
.attach-button:hover:not(:disabled) { background: #dedfe5; }

.send-button {
  width: 38px;
  height: 38px;
  flex: 0 0 38px;
  border: 0;
  border-radius: 10px;
  background: var(--text);
  color: white;
  font-size: 21px;
  line-height: 1;
}

.send-button:hover:not(:disabled) { background: #37383b; }

.status-message,
.input-hint {
  width: min(820px, 100%);
  min-height: 19px;
  margin: 3px auto 0;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}
.status-message.is-error { color: var(--danger); }
.input-hint { min-height: auto; margin-top: 0; }

.login-page {
  display: grid;
  place-items: center;
  padding: 24px;
  background: linear-gradient(145deg, #f4fbf9, #f7f7f8 55%);
}

.login-card {
  width: min(430px, 100%);
  padding: 38px;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: var(--panel);
  box-shadow: 0 18px 55px rgba(0,0,0,.08);
}

.login-card h1 { margin: 0; text-align: center; font-size: 26px; }
.login-lead { margin: 6px 0 24px; text-align: center; color: var(--muted); }
.login-error {
  padding: 10px 12px;
  border-radius: 8px;
  background: #fff1f0;
  color: var(--danger);
}

.login-form { display: grid; gap: 9px; }
.login-form label { margin-top: 5px; font-size: 13px; font-weight: 700; }
.login-form input {
  width: 100%;
  padding: 11px 12px;
  border: 1px solid #c9cacf;
  border-radius: 9px;
  outline: none;
}
.login-form input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(16,163,127,.13); }
.login-form button {
  margin-top: 12px;
  padding: 11px;
  border: 0;
  border-radius: 9px;
  background: var(--accent);
  color: white;
  font-weight: 700;
}
.login-form button:hover { background: var(--accent-dark); }

@media (max-width: 640px) {
  .app-shell {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto auto minmax(0, 1fr) auto;
  }
  .history-sidebar {
    grid-column: 1;
    grid-row: 2;
    padding: 7px 10px;
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }
  .history-heading { display: none; }
  .history-list { flex-direction: row; overflow-x: auto; overflow-y: hidden; }
  .history-item { width: auto; min-width: 150px; max-width: 220px; padding: 7px 9px; }
  .app-header { grid-column: 1; grid-row: 1; }
  .chat-main { grid-column: 1; grid-row: 3; }
  footer.composer-wrap { grid-column: 1; grid-row: 4; }
  .app-header { padding: 9px 12px; }
  .participant-name { display: none; }
  .secondary-button, .text-button { padding: 7px 9px; font-size: 13px; }
  .chat-main { padding-top: 16px; }
  .topic-card, .empty-state, .message-inner { width: calc(100% - 24px); }
  .message { padding: 17px 0; }
  footer.composer-wrap { padding-left: 10px; padding-right: 10px; }
  .input-hint { display: none; }
  .login-card { padding: 28px 22px; }
}
