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

/* Login screen */
#login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
  height: 100dvh;
  background: #f5f5f5;
}

.login-card {
  background: #fff;
  border-radius: 16px;
  padding: 40px;
  text-align: center;
  box-shadow: 0 2px 16px rgba(0, 0, 0, 0.1);
  max-width: 360px;
  width: 100%;
}

.login-logo {
  width: 64px;
  height: 64px;
  margin-bottom: 16px;
}

.login-card h1 {
  font-size: 1.5rem;
  color: #202124;
  margin-bottom: 8px;
}

.login-card p {
  color: #5f6368;
  font-size: 14px;
  margin-bottom: 24px;
}

.login-btn {
  padding: 10px 24px;
  background: #1a73e8;
  color: #fff;
  border: none;
  border-radius: 20px;
  cursor: pointer;
  font-size: 14px;
  width: 100%;
}

.login-btn:hover {
  background: #1557b0;
}

.login-btn:disabled {
  background: #ccc;
  cursor: not-allowed;
}

.login-error {
  color: #c5221f;
  font-size: 13px;
  margin-top: 12px;
  min-height: 18px;
}

/* App container */
#app-container {
  height: 100vh;
  height: 100dvh;
}

/* Header actions */
.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.user-name {
  font-size: 12px;
  opacity: 0.85;
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.logout-btn {
  padding: 6px 12px;
  background: transparent;
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.6);
  border-radius: 16px;
  cursor: pointer;
  font-size: 12px;
}

.logout-btn:hover {
  background: rgba(255, 255, 255, 0.15);
  border-color: #fff;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  background: #f5f5f5;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  max-width: 800px;
  margin: 0 auto;
  width: 100%;
  background: #fff;
  box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}

header {
  padding: 12px 16px;
  background: #1a73e8;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.header-logo {
  width: 36px;
  height: 36px;
  filter: brightness(0) invert(1);
}

header h1 {
  font-size: 1.2rem;
}

#new-chat-btn {
  padding: 6px 12px;
  background: transparent;
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.6);
  border-radius: 16px;
  cursor: pointer;
  font-size: 12px;
}

#new-chat-btn:hover {
  background: rgba(255, 255, 255, 0.15);
  border-color: #fff;
}

main {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
}

footer {
  padding: 12px 16px;
  border-top: 1px solid #e0e0e0;
  background: #fff;
}

#chat-form {
  display: flex;
  gap: 8px;
  align-items: flex-end;
}

#chat-input {
  flex: 1;
  padding: 10px 14px;
  border: 1px solid #ddd;
  border-radius: 20px;
  font-size: 16px;
  line-height: 1.4;
  resize: none;
  outline: none;
  font-family: inherit;
  overflow-y: hidden;
}

#chat-input:focus {
  border-color: #1a73e8;
}

#send-btn {
  padding: 10px 20px;
  background: #1a73e8;
  color: #fff;
  border: none;
  border-radius: 20px;
  cursor: pointer;
  font-size: 14px;
}

#send-btn:hover {
  background: #1557b0;
}

#send-btn:disabled {
  background: #ccc;
  cursor: not-allowed;
}

.message {
  max-width: 80%;
  padding: 10px 14px;
  margin-bottom: 12px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.5;
  word-wrap: break-word;
  overflow-wrap: break-word;
  word-break: break-word;
}

.message-user {
  align-self: flex-end;
  margin-left: auto;
  background: #1a73e8;
  color: #fff;
  border-bottom-right-radius: 4px;
}

.message-assistant {
  align-self: flex-start;
  margin-right: auto;
  background: #e8eaed;
  color: #202124;
  border-bottom-left-radius: 4px;
}

/* Markdown inside assistant messages */
.message-assistant p {
  margin-bottom: 8px;
}

.message-assistant p:last-child {
  margin-bottom: 0;
}

.message-assistant code {
  background: rgba(0, 0, 0, 0.07);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 13px;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
}

.message-assistant pre {
  background: #1e1e1e;
  color: #d4d4d4;
  padding: 10px 12px;
  border-radius: 8px;
  overflow-x: auto;
  margin: 8px 0;
}

.message-assistant pre code {
  background: none;
  padding: 0;
  color: inherit;
  font-size: 13px;
}

.message-assistant ul,
.message-assistant ol {
  margin: 6px 0;
  padding-left: 20px;
}

.message-assistant li {
  margin-bottom: 2px;
}

.message-assistant a {
  color: #1a73e8;
  text-decoration: underline;
}

.message-assistant strong {
  font-weight: 600;
}

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

.message-error {
  align-self: center;
  margin: 0 auto;
  background: #fce8e6;
  color: #c5221f;
  border-radius: 8px;
  text-align: center;
  font-size: 13px;
}

.message-error::before {
  content: "\26A0  ";
}

/* Retry button in error messages */
.retry-btn {
  display: inline-block;
  margin-left: 10px;
  padding: 4px 12px;
  background: #c5221f;
  color: #fff;
  border: none;
  border-radius: 12px;
  cursor: pointer;
  font-size: 12px;
}

.retry-btn:hover {
  background: #a31b19;
}

/* Typing indicator */
.message-typing {
  align-self: flex-start;
  margin-right: auto;
  background: #e8eaed;
  border-bottom-left-radius: 4px;
  display: flex;
  align-items: center;
  gap: 4px;
  min-height: 40px;
}

.typing-dots {
  display: flex;
  align-items: center;
  gap: 4px;
}

.typing-dots span {
  width: 8px;
  height: 8px;
  background: #80868b;
  border-radius: 50%;
  animation: typingBounce 1.4s ease-in-out infinite;
}

.typing-dots span:nth-child(2) {
  animation-delay: 0.2s;
}

.typing-dots span:nth-child(3) {
  animation-delay: 0.4s;
}

.typing-text {
  font-size: 13px;
  color: #5f6368;
  margin-left: 4px;
}

@keyframes typingBounce {
  0%, 60%, 100% {
    transform: translateY(0);
    opacity: 0.4;
  }
  30% {
    transform: translateY(-6px);
    opacity: 1;
  }
}

/* Mobile: < 768px */
@media (max-width: 767px) {
  #app {
    max-width: 100%;
    box-shadow: none;
  }

  main {
    padding: 12px;
  }

  .message {
    max-width: 90%;
  }

  footer {
    padding: 10px 12px;
  }

  #chat-form {
    gap: 6px;
  }

  #send-btn {
    min-height: 44px;
    min-width: 44px;
    padding: 10px 16px;
  }

  .user-name {
    display: none;
  }

  .login-card {
    margin: 0 16px;
    padding: 32px 24px;
  }
}

/* Small phones: < 360px (iPhone SE) */
@media (max-width: 359px) {
  header h1 {
    font-size: 1rem;
  }

  .header-logo {
    width: 28px;
    height: 28px;
  }

  .message {
    font-size: 13px;
    padding: 8px 10px;
  }

  #chat-input {
    padding: 8px 12px;
    font-size: 16px;
  }

  #send-btn {
    padding: 8px 12px;
    font-size: 13px;
  }
}

