/* ============================================================
   Rany AI — Design System
   Palette: Pink, Purple, Black, White
   Dark mode first, premium chat interface
   ============================================================ */

/* ---- Design Tokens ---- */
:root {
  --rany-pink: #E91E8C;
  --rany-pink-soft: #F472B6;
  --rany-pink-dim: rgba(233, 30, 140, 0.12);
  --rany-purple: #7C3AED;
  --rany-purple-dark: #4C1D95;
  --rany-purple-dim: rgba(124, 58, 237, 0.12);
  --rany-gradient: linear-gradient(135deg, #E91E8C 0%, #7C3AED 100%);

  --bg-primary: #0A0A0A;
  --bg-secondary: #111111;
  --bg-surface: #181818;
  --bg-surface-hover: #222222;
  --bg-surface-active: #2A2A2A;
  --bg-elevated: #1E1E1E;

  --text-primary: #F5F5F5;
  --text-secondary: #A1A1AA;
  --text-tertiary: #71717A;
  --text-inverse: #0A0A0A;

  --border-subtle: rgba(255, 255, 255, 0.06);
  --border-default: rgba(255, 255, 255, 0.1);
  --border-strong: rgba(255, 255, 255, 0.14);

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  --radius-full: 9999px;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.5);

  --sidebar-width: 280px;
  --header-height: 56px;

  --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-normal: 250ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-spring: 350ms cubic-bezier(0.34, 1.56, 0.64, 1);

  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 15px;
  color: var(--text-primary);
  line-height: 1.5;
}

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

html, body {
  height: 100%;
  background: var(--bg-primary);
  overflow: hidden;
}

a { color: var(--rany-pink-soft); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---- Layout ---- */
.app {
  display: flex;
  height: 100vh;
  width: 100%;
}

/* ---- Sidebar ---- */
.sidebar {
  width: var(--sidebar-width);
  background: var(--bg-secondary);
  border-right: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  transition: transform var(--transition-normal);
  z-index: 100;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border-subtle);
}

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

.brand-logo {
  width: 28px;
  height: 28px;
  flex-shrink: 0;
}

.brand-name {
  font-size: 18px;
  font-weight: 700;
  background: var(--rany-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.sidebar-conversations {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}

.sidebar-conversations::-webkit-scrollbar {
  width: 4px;
}

.sidebar-conversations::-webkit-scrollbar-thumb {
  background: var(--border-default);
  border-radius: 4px;
}

.conv-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--text-secondary);
  font-size: 14px;
  transition: all var(--transition-fast);
  position: relative;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.conv-item:hover {
  background: var(--bg-surface-hover);
  color: var(--text-primary);
}

.conv-item.active {
  background: var(--rany-pink-dim);
  color: var(--rany-pink-soft);
}

.conv-item .conv-icon {
  flex-shrink: 0;
  opacity: 0.5;
}

.conv-item .conv-title {
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}

.conv-item .conv-delete {
  position: absolute;
  right: 8px;
  opacity: 0;
  transition: opacity var(--transition-fast);
  background: none;
  border: none;
  color: var(--text-tertiary);
  cursor: pointer;
  padding: 2px;
}

.conv-item:hover .conv-delete {
  opacity: 1;
}

.conv-item .conv-delete:hover {
  color: #ef4444;
}

.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border-subtle);
}

/* ---- Usage bar ---- */
.usage-bar {
  margin-bottom: 12px;
}

.usage-text {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--text-tertiary);
  margin-bottom: 6px;
}

.usage-track {
  height: 4px;
  background: var(--bg-surface);
  border-radius: var(--radius-full);
  overflow: hidden;
}

.usage-fill {
  height: 100%;
  background: var(--rany-gradient);
  border-radius: var(--radius-full);
  transition: width var(--transition-normal);
}

.usage-fill.low {
  background: #ef4444;
}

/* ---- User info ---- */
.user-info {
  display: flex;
  align-items: center;
  gap: 10px;
}

.user-avatar {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-full);
  background: var(--rany-gradient);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 600;
  color: white;
  flex-shrink: 0;
}

.user-details {
  flex: 1;
  min-width: 0;
}

.user-name {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-email {
  display: block;
  font-size: 11px;
  color: var(--text-tertiary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ---- Buttons ---- */
.btn-icon {
  width: 36px;
  height: 36px;
  border: none;
  background: none;
  color: var(--text-secondary);
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-fast);
  flex-shrink: 0;
}

.btn-icon:hover {
  background: var(--bg-surface-hover);
  color: var(--text-primary);
}

/* ---- Chat main ---- */
.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--bg-primary);
}

/* ---- Chat header ---- */
.chat-header {
  height: var(--header-height);
  display: flex;
  align-items: center;
  padding: 0 16px;
  border-bottom: 1px solid var(--border-subtle);
  gap: 12px;
  flex-shrink: 0;
}

.chat-header-title {
  flex: 1;
  min-width: 0;
}

.chat-header-title h1 {
  font-size: 15px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

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

.coming-soon-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-tertiary);
  padding: 4px 10px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-full);
  white-space: nowrap;
}

/* ---- Messages ---- */
.messages-container {
  flex: 1;
  overflow-y: auto;
  padding: 0;
  scroll-behavior: smooth;
}

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

.messages-container::-webkit-scrollbar-thumb {
  background: var(--border-default);
  border-radius: 6px;
}

/* Welcome screen */
.welcome-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 24px;
  text-align: center;
  min-height: 100%;
}

.welcome-logo {
  margin-bottom: 20px;
  animation: welcome-pulse 3s ease-in-out infinite;
}

@keyframes welcome-pulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.05); opacity: 0.9; }
}

.welcome-screen h2 {
  font-size: 28px;
  font-weight: 700;
  margin-bottom: 8px;
  background: var(--rany-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.welcome-screen p {
  font-size: 15px;
  color: var(--text-secondary);
  max-width: 420px;
  margin-bottom: 32px;
}

.suggestion-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  max-width: 520px;
}

.suggestion-chip {
  padding: 10px 16px;
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-full);
  color: var(--text-secondary);
  font-size: 13px;
  cursor: pointer;
  transition: all var(--transition-fast);
  font-family: inherit;
}

.suggestion-chip:hover {
  background: var(--rany-pink-dim);
  border-color: var(--rany-pink);
  color: var(--rany-pink-soft);
  transform: translateY(-1px);
}

/* Message bubble */
.messages {
  padding: 16px 0;
}

.message {
  padding: 12px 24px;
  display: flex;
  gap: 14px;
  max-width: 840px;
  margin: 0 auto;
  width: 100%;
  animation: msg-in 300ms ease-out;
}

@keyframes msg-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.message-avatar {
  width: 30px;
  height: 30px;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 600;
  flex-shrink: 0;
  margin-top: 2px;
}

.message.user .message-avatar {
  background: var(--bg-surface);
  color: var(--text-secondary);
}

.message.assistant .message-avatar {
  background: var(--rany-gradient);
  color: white;
}

.message-body {
  flex: 1;
  min-width: 0;
}

.message-role {
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 4px;
}

.message.user .message-role {
  color: var(--text-primary);
}

.message.assistant .message-role {
  background: var(--rany-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.message-content {
  font-size: 15px;
  line-height: 1.65;
  color: var(--text-primary);
  word-break: break-word;
}

.message-content p {
  margin-bottom: 10px;
}

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

.message-content code {
  background: var(--bg-surface);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 14px;
  font-family: 'Fira Code', 'Consolas', monospace;
  color: var(--rany-pink-soft);
}

.message-content pre {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  margin: 10px 0;
  overflow-x: auto;
  position: relative;
}

.message-content pre code {
  background: none;
  padding: 0;
  font-size: 13px;
  color: var(--text-primary);
  line-height: 1.5;
}

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

.message-content li {
  margin-bottom: 4px;
}

.message-content strong {
  color: var(--text-primary);
  font-weight: 600;
}

.message-content em {
  color: var(--text-secondary);
}

.message-content blockquote {
  border-left: 3px solid var(--rany-purple);
  padding: 8px 16px;
  margin: 10px 0;
  color: var(--text-secondary);
  background: var(--rany-purple-dim);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

/* Streaming dots */
.typing-indicator {
  display: inline-flex;
  gap: 4px;
  padding: 4px 0;
}

.typing-indicator span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--rany-pink);
  animation: typing-bounce 1.4s ease-in-out infinite;
}

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

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

/* ---- Input area ---- */
.input-area {
  padding: 12px 16px 16px;
  flex-shrink: 0;
}

.input-container {
  max-width: 840px;
  margin: 0 auto;
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  transition: border-color var(--transition-fast);
  overflow: hidden;
}

.input-container:focus-within {
  border-color: var(--rany-pink);
  box-shadow: 0 0 0 1px var(--rany-pink-dim);
}

.input-row {
  display: flex;
  align-items: flex-end;
  gap: 4px;
  padding: 6px 8px;
}

.btn-attach {
  width: 36px;
  height: 36px;
  color: var(--text-tertiary);
}

.btn-attach:hover {
  color: var(--rany-pink-soft);
  background: var(--rany-pink-dim);
}

textarea#message-input {
  flex: 1;
  background: none;
  border: none;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 15px;
  padding: 8px 4px;
  resize: none;
  max-height: 200px;
  outline: none;
  line-height: 1.5;
}

textarea#message-input::placeholder {
  color: var(--text-tertiary);
}

.btn-send {
  width: 36px;
  height: 36px;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--rany-gradient);
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-fast);
  flex-shrink: 0;
  opacity: 0.4;
}

.btn-send:not(:disabled) {
  opacity: 1;
}

.btn-send:not(:disabled):hover {
  transform: scale(1.05);
  box-shadow: 0 2px 12px rgba(233, 30, 140, 0.3);
}

.btn-send:disabled {
  cursor: default;
}

.input-disclaimer {
  text-align: center;
  font-size: 12px;
  color: var(--text-tertiary);
  margin-top: 8px;
}

/* Image previews */
.image-previews {
  display: flex;
  gap: 8px;
  padding: 10px 12px 0;
  flex-wrap: wrap;
}

.image-preview {
  position: relative;
  width: 64px;
  height: 64px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--border-default);
}

.image-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.image-preview .remove-image {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: rgba(0,0,0,0.7);
  color: white;
  border: none;
  font-size: 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

/* ---- Login screen ---- */
.login-screen {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: var(--bg-primary);
  display: flex;
  align-items: center;
  justify-content: center;
}

.login-container {
  text-align: center;
  padding: 40px;
  max-width: 420px;
}

.login-logo {
  margin-bottom: 24px;
  animation: welcome-pulse 3s ease-in-out infinite;
}

.login-container h1 {
  font-size: 36px;
  font-weight: 700;
  margin-bottom: 8px;
  background: var(--rany-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.login-subtitle {
  font-size: 16px;
  color: var(--text-secondary);
  margin-bottom: 16px;
}

.login-desc {
  font-size: 14px;
  color: var(--text-tertiary);
  margin-bottom: 32px;
  line-height: 1.6;
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin-bottom: 24px;
}

.input-group input {
  width: 100%;
  padding: 14px 16px;
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 14px;
  transition: all var(--transition-fast);
}

.input-group input:focus {
  outline: none;
  border-color: var(--rany-pink);
  box-shadow: 0 0 0 1px var(--rany-pink-dim);
}

.input-group input::placeholder {
  color: var(--text-tertiary);
}

.auth-error {
  color: #ef4444;
  font-size: 13px;
  margin-top: -4px;
}

.btn-login {
  display: flex;
  width: 100%;
  align-items: center;
  justify-content: center;
  padding: 14px 28px;
  background: var(--rany-gradient);
  color: white;
  font-size: 15px;
  font-weight: 600;
  border: none;
  border-radius: var(--radius-full);
  text-decoration: none;
  transition: all var(--transition-fast);
  font-family: inherit;
  box-shadow: 0 4px 20px rgba(233, 30, 140, 0.25);
  cursor: pointer;
}

.btn-login:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none !important;
  box-shadow: none !important;
}

.btn-login:not(:disabled):hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 28px rgba(233, 30, 140, 0.35);
}

.login-help {
  font-size: 13px;
  color: var(--text-tertiary);
  margin-top: 16px;
}

/* ---- Modal ---- */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 300;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  animation: modal-fade-in 200ms ease;
}

@keyframes modal-fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal {
  background: var(--bg-elevated);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  padding: 32px;
  max-width: 380px;
  width: 90%;
  text-align: center;
}

.modal-icon {
  font-size: 40px;
  margin-bottom: 16px;
}

.modal h3 {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 8px;
}

.modal p {
  font-size: 14px;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.modal-timer {
  font-size: 20px;
  font-weight: 700;
  color: var(--rany-pink);
  margin-bottom: 20px;
}

.btn-primary {
  display: inline-block;
  padding: 10px 24px;
  background: var(--rany-gradient);
  color: white;
  font-size: 14px;
  font-weight: 600;
  border: none;
  border-radius: var(--radius-full);
  cursor: pointer;
  font-family: inherit;
  transition: all var(--transition-fast);
}

.btn-primary:hover {
  transform: scale(1.03);
  box-shadow: 0 4px 16px rgba(233, 30, 140, 0.3);
}

/* ---- Mobile ---- */
.mobile-only { display: none; }
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 99;
}

@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    transform: translateX(-100%);
    z-index: 100;
    box-shadow: var(--shadow-lg);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .sidebar.open + .sidebar-overlay {
    display: block;
  }

  .mobile-only {
    display: flex;
  }

  .message {
    padding: 10px 16px;
  }

  .suggestion-chips {
    flex-direction: column;
    align-items: stretch;
  }

  .coming-soon-badge {
    display: none;
  }
}
