/* Reset and base styles */
* {
  box-sizing: border-box;
}

body {
  background-color: #f5f5f5;
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen,
    Ubuntu, Cantarell, sans-serif;
  height: 100vh; /* Fallback for older browsers */
  height: 100dvh; /* Dynamic viewport height for modern browsers */
  height: calc(var(--vh, 1vh) * 100); /* iOS Safari viewport height */
  overflow: hidden;
}

/* Header styling */
#header {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: #fff;
  font-size: 24px;
  padding: 15px 20px;
  text-align: center;
  width: 100%;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  position: relative;
  z-index: 10;
}

#header > div:first-child {
  font-weight: 600;
  letter-spacing: 0.5px;
}

#header > div:nth-child(2) {
  position: absolute;
  right: 20px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 16px;
}

#header a {
  color: #fff;
  text-decoration: none;
  opacity: 0.9;
  transition: opacity 0.2s;
}

#header a:hover {
  opacity: 1;
}

/* Main content area */
#content {
  height: calc(100vh - 80px); /* Fallback for older browsers */
  height: calc(100dvh - 80px); /* Dynamic viewport height for modern browsers */
  height: calc((var(--vh, 1vh) * 100) - 80px); /* iOS Safari viewport height */
  display: flex;
  flex-direction: column;
  padding: 0;
}

/* Login page styling */
.login-container {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  padding: 20px;
}

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

.login-card h2 {
  margin: 0 0 10px 0;
  color: #333;
  font-size: 28px;
  font-weight: 600;
}

.login-subtitle {
  color: #666;
  margin: 0 0 30px 0;
  font-size: 16px;
  line-height: 1.4;
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.form-group {
  display: flex;
  flex-direction: column;
}

.login-input {
  padding: 12px 16px;
  border: 2px solid #e0e0e0;
  border-radius: 8px;
  font-size: 16px;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
  background: #fafafa;
}

.login-input:focus {
  border-color: #667eea;
  box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
  background: #fff;
}

.login-input::placeholder {
  color: #999;
}

.login-button {
  padding: 12px 24px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
}

.login-button:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
}

.login-button:active {
  transform: translateY(0);
}

/* Chat container */
.chat-container {
  display: flex;
  flex-direction: column;
  height: 100%;
  background: #fff;
  border-radius: 8px;
  margin: 12px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
  overflow: hidden;
}

/* Messages area */
.messages-area {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  background: #fafafa;
  scroll-behavior: smooth;
}

.messages-area::-webkit-scrollbar {
  width: 6px;
}

.messages-area::-webkit-scrollbar-track {
  background: #f1f1f1;
  border-radius: 3px;
}

.messages-area::-webkit-scrollbar-thumb {
  background: #c1c1c1;
  border-radius: 3px;
}

.messages-area::-webkit-scrollbar-thumb:hover {
  background: #a8a8a8;
}

/* Message styling */
.message {
  margin-bottom: 12px;
  padding: 8px 12px;
  border-radius: 8px;
  max-width: 85%;
  word-wrap: break-word;
  line-height: 1.4;
  animation: fadeIn 0.3s ease-in;
  border-left: 4px solid transparent;
}

.system-message {
  background: #e3f2fd;
  color: #1565c0;
  border-left-color: #2196f3;
  margin-left: 0;
  margin-right: auto;
}

.user-message {
  background: #e8f5e8;
  color: #2e7d32;
  border-left-color: #4caf50;
  margin-left: auto;
  margin-right: 0;
  text-align: right;
}

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

/* Input area */
.input-area {
  padding: 20px;
  padding-bottom: calc(20px + env(safe-area-inset-bottom, 0px));
  background: #fff;
  border-top: 1px solid #e0e0e0;
  display: flex;
  align-items: center;
  position: relative;
  z-index: 10;
}

.input-area input {
  width: 100%;
  padding: 12px 16px;
  border: 2px solid #e0e0e0;
  border-radius: 24px;
  font-size: 16px;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
  background: #fafafa;
}

.input-area input:focus {
  border-color: #667eea;
  box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
  background: #fff;
}

.input-area input::placeholder {
  color: #999;
}

/* Animations */
@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Responsive design */
@media (max-width: 768px) {
  #header {
    font-size: 20px;
    padding: 12px 15px;
  }

  #header > div:nth-child(2) {
    font-size: 14px;
    right: 15px;
  }

  .chat-container {
    margin: 8px;
    border-radius: 6px;
  }

  .messages-area {
    padding: 15px;
  }

  .input-area {
    padding: 15px;
    padding-bottom: calc(15px + env(safe-area-inset-bottom, 0px));
  }

  .input-area input {
    padding: 10px 14px;
    font-size: 16px; /* Prevent zoom on iOS */
    min-height: 44px; /* Better touch target for iOS */
  }

  .message {
    max-width: 90%;
  }

  .login-card {
    padding: 30px 20px;
  }

  .login-card h2 {
    font-size: 24px;
  }
}

@media (max-width: 480px) {
  #header {
    font-size: 18px;
    padding: 10px 12px;
  }

  .chat-container {
    margin: 4px;
  }

  .messages-area {
    padding: 12px;
  }

  .input-area {
    padding: 12px;
    padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  }

  .login-container {
    padding: 15px;
  }

  .login-card {
    padding: 25px 15px;
  }
}

/* iOS Safari specific styles */
@supports (-webkit-touch-callout: none) {
  /* iOS Safari specific adjustments */
  .input-area {
    padding-bottom: calc(20px + env(safe-area-inset-bottom, 0px));
    position: sticky;
    bottom: 0;
    background: #fff;
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1);
  }

  .input-area input {
    -webkit-appearance: none;
    border-radius: 24px;
    min-height: 44px; /* Better touch target for iOS */
  }

  /* Prevent zoom on input focus */
  .input-area input[type="text"] {
    font-size: 16px;
  }

  /* Ensure input is always visible */
  .chat-container {
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }
}

/* Footer styling (if needed) */
#footer {
  display: none; /* Hide footer for chat interface */
}
