/* ============================================================
   RV4 Assistent — Stylesheet
   Professional, clean design. No external dependencies.
   ============================================================ */

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

:root {
  --primary: #1a1a2e;
  --accent: #0066cc;
  --bg: #f5f5f5;
  --white: #ffffff;
  --gray-100: #f0f0f0;
  --gray-200: #e0e0e0;
  --gray-300: #ccc;
  --gray-500: #888;
  --gray-700: #555;
  --user-bubble: #e3f2fd;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.08);
  --shadow-md: 0 2px 8px rgba(0,0,0,0.12);
  --radius: 12px;
  --radius-sm: 8px;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen,
          Ubuntu, Cantarell, 'Helvetica Neue', sans-serif;
}

html, body {
  height: 100%;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  color: #222;
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- Top bar ---------- */
.topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 54px;
  background: var(--primary);
  color: var(--white);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  z-index: 100;
  box-shadow: 0 2px 6px rgba(0,0,0,0.15);
}

.topbar h1 {
  font-size: 17px;
  font-weight: 600;
  letter-spacing: 0.3px;
}

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

.topbar .btn-new-chat {
  background: transparent;
  border: 1px solid rgba(255,255,255,0.2);
  color: rgba(255,255,255,0.7);
  padding: 5px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s, color 0.2s;
}

.topbar .btn-new-chat:hover {
  background: rgba(255,255,255,0.08);
  border-color: rgba(255,255,255,0.45);
  color: var(--white);
}

.topbar .btn-logout {
  background: transparent;
  border: 1px solid rgba(255,255,255,0.35);
  color: var(--white);
  padding: 5px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s;
}

.topbar .btn-logout:hover {
  background: rgba(255,255,255,0.12);
  border-color: rgba(255,255,255,0.6);
}

/* ---------- Login page ---------- */
.login-wrapper {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 20px;
}

.login-card {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  padding: 40px 36px 36px;
  width: 100%;
  max-width: 380px;
}

.login-card .login-header {
  background: var(--primary);
  color: var(--white);
  margin: -40px -36px 28px;
  padding: 28px 36px 22px;
  border-radius: var(--radius) var(--radius) 0 0;
  text-align: center;
}

.login-card .login-header h1 {
  font-size: 22px;
  font-weight: 600;
  margin-bottom: 4px;
}

.login-card .login-header p {
  font-size: 13px;
  opacity: 0.7;
}

.login-card label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--gray-700);
  margin-bottom: 5px;
}

.login-card input[type="text"],
.login-card input[type="password"] {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--gray-300);
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-family: var(--font);
  margin-bottom: 18px;
  transition: border-color 0.2s;
}

.login-card input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(0,102,204,0.12);
}

.login-card .btn-login {
  width: 100%;
  padding: 11px;
  background: var(--primary);
  color: var(--white);
  border: none;
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-weight: 500;
  font-family: var(--font);
  cursor: pointer;
  transition: background 0.2s;
}

.login-card .btn-login:hover {
  background: #16213e;
}

.login-card .btn-login:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.login-error {
  background: #fdecea;
  color: #b71c1c;
  font-size: 13px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  margin-bottom: 16px;
  display: none;
}

.login-error.visible {
  display: block;
}

/* ---------- Main layout (sidebar + chat) ---------- */
.main-layout {
  display: flex;
  max-width: 1100px;
  margin: 0 auto;
  height: 100vh;
}

/* ---------- Sidebar ---------- */
.sidebar {
  width: 240px;
  flex-shrink: 0;
  background: #fafafa;
  border-right: 1px solid var(--gray-200);
  padding: 20px;
  padding-top: 74px; /* clear topbar */
  overflow-y: auto;
}

.sidebar::-webkit-scrollbar { width: 4px; }
.sidebar::-webkit-scrollbar-track { background: transparent; }
.sidebar::-webkit-scrollbar-thumb {
  background: var(--gray-300);
  border-radius: 2px;
}

.sidebar-heading {
  font-size: 1rem;
  font-weight: 700;
  color: #222;
  margin-bottom: 18px;
}

.sidebar-section-label {
  font-size: 0.7rem;
  font-weight: 700;
  color: #666;
  letter-spacing: 1px;
  text-transform: uppercase;
  margin-top: 18px;
  margin-bottom: 8px;
}

.sidebar-heading + .sidebar-section-label {
  margin-top: 0;
}

.sidebar-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.sidebar-item {
  padding: 8px 12px;
  font-size: 0.85rem;
  color: #333;
  cursor: pointer;
  border-radius: 6px;
  transition: background 0.15s;
  line-height: 1.4;
}

.sidebar-item:hover {
  background: var(--gray-100);
}

/* ---------- Chat layout ---------- */
.chat-container {
  display: flex;
  flex-direction: column;
  height: 100vh;
  flex: 1;
  min-width: 0;
  max-width: 800px;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 70px 16px 160px;
  scroll-behavior: smooth;
}

/* Thin scrollbar */
.chat-messages::-webkit-scrollbar { width: 6px; }
.chat-messages::-webkit-scrollbar-track { background: transparent; }
.chat-messages::-webkit-scrollbar-thumb {
  background: var(--gray-300);
  border-radius: 3px;
}

/* ---------- Conversation starters ---------- */
.starters {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 1;
  padding: 20px;
}

.starters-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  max-width: 520px;
  width: 100%;
}

.starter-card {
  background: var(--white);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  padding: 18px 16px;
  font-size: 14px;
  color: #333;
  cursor: pointer;
  transition: box-shadow 0.2s, border-color 0.2s, transform 0.15s;
  line-height: 1.4;
}

.starter-card:hover {
  border-color: var(--accent);
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

/* ---------- Chat bubbles ---------- */
.message {
  margin-bottom: 14px;
  display: flex;
  flex-direction: column;
}

.message.user {
  align-items: flex-end;
}

.message.assistant {
  align-items: flex-start;
}

.message.system {
  align-items: center;
}

.bubble {
  max-width: 80%;
  padding: 10px 15px;
  border-radius: var(--radius);
  font-size: 14px;
  line-height: 1.55;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.message.user .bubble {
  background: var(--user-bubble);
  border-bottom-right-radius: 4px;
  box-shadow: var(--shadow-sm);
}

.message.assistant .bubble {
  background: var(--white);
  border: 1px solid var(--gray-200);
  border-bottom-left-radius: 4px;
  box-shadow: var(--shadow-sm);
}

.message.system .bubble {
  background: transparent;
  color: var(--gray-500);
  font-style: italic;
  font-size: 13px;
  padding: 6px 12px;
}

/* Markdown inside bubbles */
.bubble p { margin-bottom: 8px; }
.bubble p:last-child { margin-bottom: 0; }
.bubble strong { font-weight: 600; }
.bubble em { font-style: italic; }
.bubble ul, .bubble ol { margin: 6px 0 6px 20px; }
.bubble li { margin-bottom: 3px; }
.bubble code {
  background: var(--gray-100);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 13px;
  font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
}
.bubble pre {
  background: #1e1e1e;
  color: #d4d4d4;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  overflow-x: auto;
  margin: 8px 0;
  font-size: 13px;
  line-height: 1.45;
}
.bubble pre code {
  background: transparent;
  padding: 0;
  color: inherit;
}
.bubble a {
  color: var(--accent);
  text-decoration: underline;
}

/* Images inside bubbles */
.bubble img {
  max-width: 100%;
  max-height: 300px;
  border-radius: var(--radius-sm);
  margin: 6px 0;
  cursor: pointer;
  transition: opacity 0.2s;
}

.bubble img:hover {
  opacity: 0.9;
}

/* ---------- Thinking / loading indicator ---------- */
.thinking-indicator .bubble {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 12px 18px;
}

.thinking-indicator .dot {
  width: 7px;
  height: 7px;
  background: var(--gray-500);
  border-radius: 50%;
  animation: pulse-dot 1.4s ease-in-out infinite;
}

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

@keyframes pulse-dot {
  0%, 80%, 100% { opacity: 0.3; transform: scale(0.8); }
  40% { opacity: 1; transform: scale(1); }
}

.thinking-text {
  font-size: 13px;
  color: var(--gray-500);
  margin-left: 6px;
  font-style: italic;
}

/* ---------- Input area ---------- */
.input-area {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--white);
  border-top: 1px solid var(--gray-200);
  padding: 12px 16px;
  z-index: 50;
}

.input-inner {
  max-width: 800px;
  margin: 0 auto;
}

/* Image preview above input */
.image-preview {
  display: none;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  padding: 6px 8px;
  background: var(--gray-100);
  border-radius: var(--radius-sm);
}

.image-preview.visible {
  display: flex;
}

.image-preview img {
  height: 48px;
  width: 48px;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid var(--gray-200);
}

.image-preview .remove-image {
  background: none;
  border: none;
  color: var(--gray-500);
  cursor: pointer;
  font-size: 18px;
  padding: 2px 6px;
  line-height: 1;
  transition: color 0.2s;
}

.image-preview .remove-image:hover {
  color: #b71c1c;
}

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

.input-row textarea {
  flex: 1;
  resize: none;
  border: 1px solid var(--gray-300);
  border-radius: var(--radius);
  padding: 10px 14px;
  font-size: 14px;
  font-family: var(--font);
  line-height: 1.45;
  max-height: 120px; /* ~4 lines */
  overflow-y: auto;
  transition: border-color 0.2s;
}

.input-row textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(0,102,204,0.1);
}

.input-row textarea::placeholder {
  color: var(--gray-500);
}

.btn-icon {
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s, opacity 0.2s;
  flex-shrink: 0;
}

.btn-send {
  background: var(--primary);
  color: var(--white);
}

.btn-send:hover { background: #16213e; }
.btn-send:disabled { opacity: 0.4; cursor: not-allowed; }

.btn-image {
  background: var(--gray-100);
  color: var(--gray-700);
}

.btn-image:hover { background: var(--gray-200); }

/* SVG icons inside buttons */
.btn-icon svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
}

/* ---------- Responsive ---------- */

/* Hide sidebar on mobile / tablet */
@media (max-width: 768px) {
  .sidebar { display: none; }
}

@media (max-width: 600px) {
  .topbar { padding: 0 14px; }
  .topbar h1 { font-size: 15px; }

  .chat-messages { padding: 62px 10px 150px; }

  .starters-grid {
    grid-template-columns: 1fr;
    max-width: 100%;
  }

  .starter-card { font-size: 13px; padding: 14px; }

  .bubble { max-width: 90%; font-size: 13.5px; }

  .input-area { padding: 10px 10px; }
  .input-row textarea { font-size: 15px; /* prevent iOS zoom */ }

  .login-card { padding: 32px 24px 28px; }
  .login-card .login-header { margin: -32px -24px 24px; padding: 24px 24px 18px; }
}
