* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Sans", "Yu Gothic", sans-serif;
  background: #f5f5f7;
  color: #1d1d1f;
}

/* ログイン画面 */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}
.login-box {
  background: #fff;
  padding: 32px;
  border-radius: 12px;
  box-shadow: 0 2px 12px rgba(0,0,0,0.08);
  width: 100%;
  max-width: 360px;
}
.login-box h1 {
  font-size: 20px;
  margin: 0 0 20px;
  text-align: center;
}
.login-box label {
  display: block;
  margin-bottom: 14px;
  font-size: 13px;
  color: #555;
}
.login-box input {
  display: block;
  width: 100%;
  margin-top: 4px;
  padding: 10px;
  border: 1px solid #ccc;
  border-radius: 6px;
  font-size: 14px;
}
.login-box button {
  width: 100%;
  padding: 10px;
  background: #1a73e8;
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: 14px;
  cursor: pointer;
}
.login-box .error {
  color: #c0392b;
  font-size: 13px;
}
.login-box .notice {
  margin-top: 16px;
  font-size: 11px;
  color: #888;
  text-align: center;
}

/* 共通ヘッダー */
.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 16px;
  background: #fff;
  border-bottom: 1px solid #e0e0e0;
}
.topbar a {
  margin-left: auto;
  color: #1a73e8;
  text-decoration: none;
  font-size: 13px;
}
.notice-small {
  font-size: 11px;
  color: #999;
}

main {
  padding: 24px;
}

/* チャット画面 */
.chat-page, .chat-page .app {
  height: 100vh;
}
.app {
  display: flex;
}
.sidebar {
  width: 260px;
  flex-shrink: 0;
  background: #fff;
  border-right: 1px solid #e0e0e0;
  display: flex;
  flex-direction: column;
}
.sidebar-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px;
}
.new-thread-btn {
  flex: 1;
  padding: 10px;
  background: #1a73e8;
  color: #fff;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
}
.sidebar-toggle {
  display: none;
  border: none;
  background: none;
  font-size: 20px;
  cursor: pointer;
}
.thread-list {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  flex: 1;
}
.thread-item {
  display: flex;
  align-items: center;
  padding: 10px 12px;
  cursor: pointer;
  font-size: 13px;
  border-bottom: 1px solid #f0f0f0;
}
.thread-item:hover {
  background: #f5f5f7;
}
.thread-item.active {
  background: #e8f0fe;
}
.thread-item-title {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.thread-delete-btn {
  border: none;
  background: none;
  color: #999;
  cursor: pointer;
  font-size: 16px;
  padding: 0 4px;
}
.thread-delete-btn:hover {
  color: #c0392b;
}
.sidebar-footer {
  padding: 12px;
  border-top: 1px solid #e0e0e0;
  font-size: 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.sidebar-footer a {
  color: #1a73e8;
  text-decoration: none;
}

.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.chat-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  background: #fff;
  border-bottom: 1px solid #e0e0e0;
}
.menu-btn {
  display: none;
  border: none;
  background: none;
  font-size: 18px;
  cursor: pointer;
}
.thread-title {
  font-size: 14px;
  font-weight: 600;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.model-badge {
  font-size: 11px;
  color: #555;
  background: #eee;
  border-radius: 999px;
  padding: 3px 10px;
}
.notice-bar {
  font-size: 11px;
  color: #b8860b;
  background: #fffbe6;
  padding: 4px 16px;
  border-bottom: 1px solid #f0e6c0;
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.message {
  display: flex;
}
.message-user {
  justify-content: flex-end;
}
.message-assistant {
  justify-content: flex-start;
}
.bubble {
  max-width: 80%;
  padding: 10px 14px;
  border-radius: 10px;
  font-size: 14px;
  line-height: 1.6;
  word-wrap: break-word;
}
.message-user .bubble {
  background: #1a73e8;
  color: #fff;
}
.message-assistant .bubble {
  background: #fff;
  border: 1px solid #e0e0e0;
}
.bubble pre {
  overflow-x: auto;
  padding: 10px;
  border-radius: 6px;
  background: #f6f8fa;
}
.bubble :first-child {
  margin-top: 0;
}
.bubble :last-child {
  margin-bottom: 0;
}
.code-block {
  position: relative;
}
.copy-btn {
  position: absolute;
  top: 4px;
  right: 4px;
  font-size: 11px;
  padding: 2px 8px;
  border: 1px solid #ccc;
  background: #fff;
  border-radius: 4px;
  cursor: pointer;
}
.bubble.loading {
  display: flex;
  gap: 4px;
  align-items: center;
  padding: 14px;
}
.dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #999;
  animation: blink 1.4s infinite both;
}
.dot:nth-child(2) { animation-delay: 0.2s; }
.dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink {
  0%, 80%, 100% { opacity: 0.2; }
  40% { opacity: 1; }
}

.attachment-preview {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 16px;
  background: #fff;
  border-top: 1px solid #e0e0e0;
  font-size: 12px;
  color: #555;
}
.attachment-preview button {
  border: none;
  background: none;
  color: #999;
  cursor: pointer;
  font-size: 14px;
}
.attachment-chip {
  display: inline-block;
  margin-bottom: 6px;
  padding: 4px 10px;
  background: #f0f0f0;
  border-radius: 6px;
  font-size: 12px;
  color: #555;
}
.attach-btn {
  border: none;
  background: none;
  font-size: 20px;
  cursor: pointer;
  padding: 0 4px;
}

.composer {
  display: flex;
  gap: 8px;
  padding: 12px 16px;
  background: #fff;
  border-top: 1px solid #e0e0e0;
}
.composer textarea {
  flex: 1;
  resize: none;
  padding: 10px;
  border: 1px solid #ccc;
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  max-height: 200px;
}
.composer button {
  padding: 0 20px;
  background: #1a73e8;
  color: #fff;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
}
.composer button:disabled {
  background: #aaa;
}

@media (max-width: 768px) {
  .menu-btn { display: block; }
  .sidebar-toggle { display: block; }
  .sidebar {
    position: fixed;
    inset: 0 30% 0 0;
    z-index: 100;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
  }
  .sidebar.open {
    transform: translateX(0);
    box-shadow: 2px 0 8px rgba(0,0,0,0.2);
  }
}
