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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: #f5f5f5;
  color: #1a1a1a;
  height: 100dvh;
  display: flex;
  align-items: stretch;
}

.container {
  width: 100%;
  max-width: 800px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  background: #fff;
  box-shadow: 0 0 40px rgba(0,0,0,0.08);
}

header {
  padding: 24px;
  border-bottom: 1px solid #eee;
}

.header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

header h1 { font-size: 1.4rem; font-weight: 700; }
.subtitle { font-size: 0.85rem; color: #888; margin-top: 4px; }

.log-btn {
  padding: 6px 14px;
  font-size: 0.8rem;
  font-weight: 500;
  background: #f0f0f0;
  color: #555;
  border: 1px solid #ddd;
  border-radius: 8px;
  white-space: nowrap;
  flex-shrink: 0;
}
button.log-btn:hover { background: #e4e4e4; color: #555; }

main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.message {
  max-width: 85%;
  padding: 12px 16px;
  border-radius: 12px;
  line-height: 1.55;
  font-size: 0.95rem;
}

.message.user {
  align-self: flex-end;
  background: #2563eb;
  color: #fff;
  border-bottom-right-radius: 4px;
}

.message.assistant {
  align-self: flex-start;
  background: #f0f0f0;
  color: #1a1a1a;
  border-bottom-left-radius: 4px;
}

.message.error {
  align-self: flex-start;
  background: #fee2e2;
  color: #991b1b;
}

.message.assistant p { margin: 0 0 8px; }
.message.assistant p:last-child { margin-bottom: 0; }
.message.assistant strong { font-weight: 700; }
.message.assistant ol,
.message.assistant ul { padding-left: 20px; margin: 4px 0 8px; }
.message.assistant li { margin-bottom: 4px; }

.thinking {
  align-self: flex-start;
  display: flex;
  gap: 5px;
  padding: 14px 18px;
  background: #f0f0f0;
  border-radius: 12px;
  border-bottom-left-radius: 4px;
}

.thinking span {
  width: 8px;
  height: 8px;
  background: #888;
  border-radius: 50%;
  animation: bounce 1.2s infinite;
}
.thinking span:nth-child(2) { animation-delay: 0.2s; }
.thinking span:nth-child(3) { animation-delay: 0.4s; }

@keyframes bounce {
  0%, 80%, 100% { transform: translateY(0); }
  40% { transform: translateY(-6px); }
}

.input-area {
  display: flex;
  gap: 12px;
  padding: 16px 24px;
  border-top: 1px solid #eee;
  align-items: flex-end;
}

textarea {
  flex: 1;
  resize: none;
  border: 1px solid #ddd;
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 0.95rem;
  font-family: inherit;
  line-height: 1.4;
  outline: none;
  transition: border-color 0.2s;
}

textarea:focus { border-color: #2563eb; }

button {
  padding: 10px 22px;
  background: #2563eb;
  color: #fff;
  border: none;
  border-radius: 10px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.2s, opacity 0.2s;
}

button:hover { background: #1d4ed8; }
button:disabled { opacity: 0.5; cursor: not-allowed; }

.log-modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.log-modal.hidden { display: none; }

.log-modal-box {
  background: #fff;
  border-radius: 12px;
  width: 90%;
  max-width: 700px;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 8px 40px rgba(0,0,0,0.2);
}

.log-modal-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 14px 16px;
  border-bottom: 1px solid #eee;
  font-weight: 600;
  font-size: 0.95rem;
}

.log-modal-header span { flex: 1; }

.log-modal-header button {
  padding: 6px 14px;
  font-size: 0.8rem;
  font-weight: 500;
  border-radius: 8px;
}

#log-modal-copy {
  background: #2563eb;
  color: #fff;
  border: none;
}
#log-modal-copy:hover { background: #1d4ed8; }

#log-modal-close {
  background: #f0f0f0;
  color: #555;
  border: 1px solid #ddd;
}
#log-modal-close:hover { background: #e4e4e4; }

.log-modal-box textarea {
  flex: 1;
  border: none;
  outline: none;
  resize: none;
  padding: 16px;
  font-family: monospace;
  font-size: 0.8rem;
  line-height: 1.5;
  color: #1a1a1a;
  min-height: 300px;
}
