/* Ra'no AI Chat styles - Modern ChatGPT-like design */
:root {
  --bg-light: #ffffff;
  --bg-dark: #212121;
  --surface-light: #f7f7f8;
  --surface-dark: #2f2f2f;
  --border-light: #d1d5db;
  --border-dark: #444654;
  --text-light: #374151;
  --text-dark: #ececf1;
  --text-muted-light: #6b7280;
  --text-muted-dark: #9ca3af;
  --accent: #10a37f;
  --user-bg-light: #f7f7f8;
  --user-bg-dark: #444654;
  --bot-bg-light: #ffffff;
  --bot-bg-dark: #444654;
  --shadow-light: rgba(0, 0, 0, 0.1);
  --shadow-dark: rgba(0, 0, 0, 0.25);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: var(--bg-dark);
    --surface: var(--surface-dark);
    --border: var(--border-dark);
    --text: var(--text-dark);
    --text-muted: var(--text-muted-dark);
    --user-bg: var(--user-bg-dark);
    --bot-bg: var(--bot-bg-dark);
    --shadow: var(--shadow-dark);
  }
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: var(--bg-light);
    --surface: var(--surface-light);
    --border: var(--border-light);
    --text: var(--text-light);
    --text-muted: var(--text-muted-light);
    --user-bg: var(--user-bg-light);
    --bot-bg: var(--bot-bg-light);
    --shadow: var(--shadow-light);
  }
}
* {
  box-sizing: border-box;
}
html,
body {
  height: 100%;
}
body {
  margin: 0;
  font-family: "Söhne", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    Oxygen, Ubuntu, Cantarell, "Fira Sans", "Droid Sans", "Helvetica Neue",
    sans-serif;
  background: var(--bg);
  color: var(--text);
  transition: background-color 0.3s ease, color 0.3s ease;
}

.app {
  max-width: 768px;
  margin: 0 auto;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  position: relative;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 16px 20px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
}
.logo {
  font-weight: 600;
  font-size: 18px;
  color: var(--text);
}
.status {
  display: none; /* Hide status for cleaner look */
}

.chat {
  flex: 1;
  overflow-y: auto;
  padding: 0;
  padding-bottom: 180px; /* Space for composer */
  scroll-behavior: smooth;
}

.chat::-webkit-scrollbar {
  width: 6px;
}
.chat::-webkit-scrollbar-track {
  background: transparent;
}
.chat::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}
.chat::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}
.message {
  width: 100%;
  padding: 16px 20px;
  position: relative;
  transition: all 0.2s ease;
}
.message:hover {
  background: rgba(0, 0, 0, 0.01);
}
.message.user {
  display: flex;
  justify-content: flex-end;
}
.message.bot {
  display: flex;
  justify-content: flex-start;
}

/* Message actions */
.message-actions {
  position: absolute;
  top: 8px;
  display: flex;
  gap: 4px;
  opacity: 0;
  transition: all 0.2s ease;
  z-index: 10;
}
.message.user .message-actions {
  left: 8px;
}
.message.bot .message-actions {
  right: 8px;
}
.message:hover .message-actions {
  opacity: 1;
}
.message-action {
  width: 28px;
  height: 28px;
  border: none;
  background: rgba(255, 255, 255, 0.9);
  color: var(--text-muted);
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  font-size: 14px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  border: 1px solid rgba(0, 0, 0, 0.1);
  backdrop-filter: blur(10px);
}
.message-action:hover {
  background: var(--accent);
  color: white;
  transform: scale(1.1);
  box-shadow: 0 4px 16px rgba(16, 163, 127, 0.25);
}
.message-action:active {
  transform: scale(0.95);
}
.message-content {
  max-width: 70%;
  display: flex;
  gap: 12px;
  align-items: flex-start;
  position: relative;
}
.message.user .message-content {
  flex-direction: row-reverse;
}
.message .avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  position: relative;
  font-size: 18px;
  transition: transform 0.2s ease;
  border: 2px solid white;
  box-shadow: 0 3px 12px rgba(0, 0, 0, 0.15);
}
.message .avatar:hover {
  transform: scale(1.08);
}
.message.user .avatar {
  background: linear-gradient(135deg, #6b7280 0%, #9ca3af 50%, #d1d5db 100%);
}
.message.bot .avatar {
  background: linear-gradient(135deg, #10b981 0%, #059669 50%, #047857 100%);
}

/* Typing indicator for bot avatar */
.message.bot.typing .avatar::after {
  content: "";
  position: absolute;
  width: 8px;
  height: 8px;
  background: #22c55e;
  border-radius: 50%;
  bottom: -2px;
  right: -2px;
  border: 2px solid white;
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0%,
  100% {
    opacity: 1;
    transform: scale(1);
  }
  50% {
    opacity: 0.7;
    transform: scale(0.9);
  }
}
.message .bubble {
  max-width: 100%;
  padding: 18px 22px;
  border-radius: 20px;
  line-height: 1.7;
  font-size: 17px;
  white-space: pre-wrap;
  word-wrap: break-word;
  position: relative;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  transition: all 0.2s ease;
}
.message.user .bubble {
  background: var(--surface);

  color: var(--text);
  border: 1px solid var(--border);
  border-bottom-right-radius: 6px;
}
.message.bot .bubble {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-bottom-left-radius: 6px;
}
.message .bubble:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
}

/* Message timestamp */
.message-time {
  font-size: 11px;
  margin-top: 6px;
  opacity: 1;
  transition: opacity 0.2s ease;
}
.message.user .message-time {
  color: var(--text-muted);
  text-align: right;
}
.message.bot .message-time {
  color: var(--text-muted);
}
.message:hover .message-time {
  opacity: 1;
}

/* Message status indicators */
.message-status {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-top: 4px;
  font-size: 12px;
  color: var(--text-muted);
}
.message.user .message-status {
  justify-content: flex-end;
}

.status-icon {
  width: 12px;
  height: 12px;
  border-radius: 50%;
}
.status-sending {
  background: #f59e0b;
}
.status-sent {
  background: #10b981;
}
.status-error {
  background: #ef4444;
}

.bubble .small {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-top: 8px;
}

/* Markdown formatting styles */
.bubble h1,
.bubble h2,
.bubble h3,
.bubble h4,
.bubble h5,
.bubble h6 {
  margin: 20px 0 12px 0;
  font-weight: 600;
  line-height: 1.4;
}
.bubble h1 {
  font-size: 2em;
}
.bubble h2 {
  font-size: 1.7em;
}
.bubble h3 {
  font-size: 1.4em;
}
.bubble h4 {
  font-size: 1.2em;
}

.bubble p {
  margin: 12px 0;
  line-height: 1.7;
  font-size: 17px;
}
.bubble p:first-child {
  margin-top: 0;
}
.bubble p:last-child {
  margin-bottom: 0;
}

.bubble ul,
.bubble ol {
  margin: 16px 0;
  padding-left: 24px;
}
.bubble li {
  margin: 8px 0;
  line-height: 1.7;
  font-size: 17px;
}

.bubble blockquote {
  margin: 20px 0;
  padding: 16px 20px;
  border-left: 4px solid var(--accent);
  background: rgba(16, 163, 127, 0.05);
  border-radius: 0 8px 8px 0;
  font-style: italic;
}

.bubble code {
  background: rgba(142, 150, 170, 0.15);
  padding: 4px 8px;
  border-radius: 6px;
  font-family: "SF Mono", "Monaco", "Inconsolata", "Roboto Mono",
    "Source Code Pro", monospace;
  font-size: 0.95em;
  color: #eb5757;
}

.bubble pre {
  background: rgba(0, 0, 0, 0.05);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px 20px;
  overflow-x: auto;
  margin: 20px 0;
  position: relative;
}
.bubble pre code {
  background: none;
  padding: 0;
  color: var(--text);
  font-size: 0.875em;
  line-height: 1.6;
}

.bubble strong,
.bubble b {
  font-weight: 600;
}

.bubble em,
.bubble i {
  font-style: italic;
}

.bubble a {
  color: var(--accent);
  text-decoration: underline;
  text-decoration-color: rgba(16, 163, 127, 0.4);
  text-underline-offset: 2px;
}
.bubble a:hover {
  text-decoration-color: var(--accent);
}

.bubble table {
  border-collapse: collapse;
  margin: 20px 0;
  width: 100%;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--border);
}
.bubble th,
.bubble td {
  border-bottom: 1px solid var(--border);
  padding: 12px 16px;
  text-align: left;
}
.bubble th {
  background: var(--surface);
  font-weight: 600;
  border-bottom: 2px solid var(--border);
}
.bubble tr:last-child td {
  border-bottom: none;
}

.bubble hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 24px 0;
  opacity: 0.6;
}

.composer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--bg);
  border-top: 1px solid var(--border);
  padding: 20px;
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
}
.composer-inner {
  max-width: 768px;
  margin: 0 auto;
  position: relative;
}
textarea {
  width: 100%;
  resize: none;
  min-height: 52px;
  max-height: 200px;
  border: 1px solid var(--border);
  outline: none;
  color: var(--text);
  background: var(--surface);
  border-radius: 26px;
  padding: 14px 50px 14px 16px;
  font-size: 16px;
  line-height: 1.5;
  box-shadow: 0 2px 8px var(--shadow);
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 2px 12px var(--shadow), 0 0 0 3px rgba(16, 163, 127, 0.1);
}
textarea::placeholder {
  color: var(--text-muted);
}
button#send {
  position: absolute;
  right: 8px;
  bottom: 8px;
  width: 36px;
  height: 36px;
  padding: 0;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background-color 0.2s ease, transform 0.1s ease;
}
button#send:hover:not(:disabled) {
  background: #0d8f6f;
  transform: scale(1.05);
}
button#send:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
}
button#send::before {
  content: "↑";
  font-size: 18px;
  font-weight: 600;
}

/* Enhanced typing indicator */
.loader {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 12px 0;
}

.typing-dots {
  display: flex;
  gap: 4px;
}
.typing-dots span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: typing 1.4s infinite ease-in-out;
}
.typing-dots span:nth-child(1) {
  animation-delay: 0s;
}
.typing-dots span:nth-child(2) {
  animation-delay: 0.2s;
}
.typing-dots span:nth-child(3) {
  animation-delay: 0.4s;
}

.typing-text {
  font-size: 14px;
  color: var(--text-muted);
  margin-left: 8px;
  font-style: italic;
}

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

/* Message animations */
.message {
  animation: messageSlideIn 0.3s ease-out;
}
.message.user {
  animation: messageSlideInRight 0.3s ease-out;
}

@keyframes messageSlideIn {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes messageSlideInRight {
  from {
    opacity: 0;
    transform: translateX(20px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

/* Notification animations */
@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateX(100%);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes slideOut {
  to {
    opacity: 0;
    transform: translateX(100%);
  }
}

/* Empty state */
.chat-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 400px;
  text-align: center;
  color: var(--text-muted);
  font-size: 16px;
}
.chat-empty .icon {
  font-size: 48px;
  margin-bottom: 16px;
  opacity: 0.6;
}
.chat-empty .title {
  font-weight: 600;
  margin-bottom: 8px;
  color: var(--text);
}
.chat-empty .subtitle {
  font-size: 14px;
  max-width: 300px;
  line-height: 1.5;
}

/* Mobile responsiveness */
@media (max-width: 768px) {
  .app {
    max-width: 100%;
  }
  .app-header {
    padding: 12px 16px;
  }
  .message {
    padding: 12px 16px;
  }
  .message-content {
    max-width: 85%;
    gap: 10px;
  }
  .message .avatar {
    width: 32px;
    height: 32px;
    font-size: 16px;
  }
  .message .bubble {
    font-size: 17px;
    padding: 16px 20px;
  }
  .message-actions {
    display: none; /* Hide actions on mobile */
  }
  .composer {
    padding: 16px;
  }
  .chat {
    padding-bottom: 140px;
  }
  textarea {
    font-size: 16px; /* Prevent zoom on iOS */
    padding: 12px 44px 12px 14px;
  }
  button#send {
    width: 32px;
    height: 32px;
    border-radius: 16px;
    right: 6px;
    bottom: 6px;
  }
}

@media (max-width: 480px) {
  .app-header {
    padding: 10px 12px;
  }
  .logo {
    font-size: 16px;
  }
  .message {
    padding: 16px 12px;
  }
  .composer {
    padding: 12px;
  }
  .chat {
    padding-bottom: 120px;
  }
}
