:root {
  --bg: #f6f8fb;
  --card: #ffffff;
  --text: #0f172a;
  --muted: #475569;
  --brand: #0d6efd;
  --brand-hover: #0b5ed7;
  --line: #e5e7eb;
  --bubble-user: #e8f1ff;
  --bubble-ai: #ffffff;
  --shadow: 0 6px 24px rgba(0,0,0,0.06);
  --radius: 14px;
  --safe-area: env(safe-area-inset-bottom, 0px);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
  overflow: hidden;
}

/* ===== HEADER ===== */
header {
  background: var(--card);
  box-shadow: var(--shadow);
  padding: 1rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--line);
  height: 60px;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 1000;
}

header h1 {
  margin: 0;
  font-size: 1.2rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

header nav {
  display: flex;
  gap: 0.5rem;
}

/* ===== MAIN LAYOUT ===== */
.layout {
  display: flex;
  flex-direction: column;
  height: 100vh;
  padding-top: 60px;
}

/* ===== SIDEBAR ===== */
#sidebar {
  position: fixed;
  top: 60px;
  left: -100%;
  width: 100%;
  height: calc(100vh - 60px);
  background: var(--card);
  border-right: 1px solid var(--line);
  z-index: 900;
  transition: left 0.3s ease;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

#sidebar.active {
  left: 0;
}

#sidebar h3 {
  padding: 1.5rem 1rem 1rem;
  margin: 0;
  border-bottom: 1px solid var(--line);
  font-size: 1.1rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.sidebar-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--muted);
}

.chat-history {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.chat-item {
  position: relative;
  padding: 0.75rem;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s ease;
  -webkit-user-select: none;
  user-select: none;
}

.chat-item:hover, .chat-item:active {
  background: var(--bubble-user);
  border-color: var(--brand);
}

.chat-item .chat-content {
  padding-right: 2rem;
}

.chat-item strong {
  display: block;
  color: var(--text);
  margin-bottom: 0.25rem;
  font-size: 0.9rem;
  line-height: 1.3;
}

.chat-item small {
  color: var(--muted);
  font-size: 0.75rem;
}

.delete-chat-btn {
  position: absolute;
  right: 0.5rem;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  cursor: pointer;
  padding: 0.5rem;
  border-radius: 6px;
  color: #999;
  transition: all 0.2s ease;
  -webkit-tap-highlight-color: transparent;
}

.chat-item:hover .delete-chat-btn,
.chat-item:active .delete-chat-btn {
  opacity: 1;
}

.delete-chat-btn:hover, .delete-chat-btn:active {
  color: #ff4444;
  background: rgba(255, 68, 68, 0.1);
}

/* ===== MAIN CONTENT ===== */
.container {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

#chat-section {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 0;
  height: 100%;
}

/* ===== PANEL ===== */
.panel {
  background: var(--card);
  border-bottom: 1px solid var(--line);
  padding: 0.5rem 0.75rem;
  flex-shrink: 0;
}

.mobile-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.5rem;
}

.menu-btn {
  background: none;
  border: none;
  font-size: 1.2rem;
  cursor: pointer;
  padding: 0.3rem;
  color: var(--muted);
  min-width: 40px;
  min-height: 40px;
}

.row {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.row-item {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.action-buttons {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.3rem;
}

/* ===== CHAT MESSAGES ===== */
.chat-box {
  flex: 1;
  overflow-y: auto;
  padding: 0.75rem;
  background: var(--bg);
  min-height: 0;
  -webkit-overflow-scrolling: touch;
  height: auto;
}

.bubble {
  max-width: 90%;
  border-radius: 18px;
  padding: 0.75rem 1rem;
  margin-bottom: 0.6rem;
  line-height: 1.4;
  word-wrap: break-word;
  white-space: pre-wrap;
  border: 1px solid var(--line);
  font-size: 0.95rem;
  -webkit-user-select: text;
  user-select: text;
}

.bubble-user {
  background: var(--bubble-user);
  margin-left: auto;
  margin-right: 0;
}

.bubble-assistant {
  background: var(--bubble-ai);
  margin-right: auto;
  margin-left: 0;
}

/* ===== COMPOSER ===== */
.composer {
  background: var(--card);
  border-top: 1px solid var(--line);
  padding: 0.75rem;
  padding-bottom: calc(0.75rem + var(--safe-area));
  flex-shrink: 0;
}

.composer-form {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.composer-actions {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
}

/* ===== FORM ELEMENTS ===== */
.label {
  display: block;
  font-size: 0.9rem;
  color: var(--muted);
  margin-bottom: 0.4rem;
  font-weight: 500;
}

.select, .textarea, .input {
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: 12px;
  padding: 1rem;
  font-size: 1rem;
  outline: none;
  color: var(--text);
  font-family: inherit;
  width: 100%;
  -webkit-appearance: none;
  appearance: none;
}

.select:focus, .textarea:focus, .input:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(13,110,253,0.12);
}

.textarea {
  min-height: 80px;
  resize: none;
  line-height: 1.4;
}

/* ===== BUTTONS ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  border-radius: 12px;
  border: 1px solid transparent;
  padding: 1rem;
  cursor: pointer;
  font-weight: 600;
  font-size: 1rem;
  transition: all 0.2s ease;
  text-decoration: none;
  font-family: inherit;
  -webkit-tap-highlight-color: transparent;
  min-height: 44px;
}

.btn-primary {
  background: var(--brand);
  color: white;
  border: none;
}

.btn-primary:hover, .btn-primary:active {
  background: var(--brand-hover);
  transform: translateY(-1px);
}

.btn-ghost {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--muted);
}

.btn-ghost:hover, .btn-ghost:active {
  background: rgba(0,0,0,0.04);
  color: var(--text);
}

/* ===== MOBILE OPTIMIZATIONS ===== */
/* ===== MOBILE OPTIMIZATIONS ===== */
@media (max-width: 767px) {
  .mobile-header {
    display: flex;
  }

  .menu-btn, .sidebar-close {
    display: block;
  }

  .row-item:first-child .label,
  .row-item:first-child .select {
    display: none;
  }

  /* RESET alles naar simpel */
  .layout {
    height: 100vh;
    padding-top: 60px;
  }

  .container {
    height: 100%;
    display: flex;
    flex-direction: column;
  }

  #chat-section {
    display: flex;
    flex-direction: column;
    height: 100%;
  }

  .panel {
    padding: 0.5rem;
  }

  /* CHAT BOX - SIMPELE GROTE HOOGTE */
/* CHAT BOX */
.chat-box {
  height: 500px;
  overflow-y: auto;
  padding: 1rem;
  background: var(--bg);
  border: 1px solid var(--line);
}

/* COMPOSER */
.composer {
  background: var(--card);
  border-top: 1px solid var(--line);
  padding: 1rem;
}
  .action-buttons .btn {
    padding: 0.5rem;
    font-size: 0.8rem;
  }

  .bubble {
    max-width: 85%;
    padding: 0.75rem 1rem;
  }
}
/* ===== DESKTOP STYLES ===== */
@media (min-width: 768px) {
  header {
    padding: 1rem 2rem;
    height: 70px;
  }

  .layout {
    flex-direction: row;
    padding-top: 70px;
  }

  #sidebar {
    position: static;
    width: 320px;
    min-width: 320px;
    height: auto;
    left: auto;
  }

  .mobile-header, .menu-btn, .sidebar-close {
    display: none;
  }

  .panel {
    padding: 1rem 2rem;
  }

  .row {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
  }

  .row-item {
    flex-direction: row;
    align-items: center;
    flex: 1;
  }

  .row-item:first-child {
    flex: 0 0 auto;
    min-width: 250px;
  }

  .row-item:last-child {
    justify-content: flex-end;
  }

  .action-buttons {
    display: flex;
    grid-template-columns: none;
    gap: 0.5rem;
  }

  .chat-box {
    padding: 2rem;
    height: auto;
    padding-bottom: 1rem;
  }

  .bubble {
    max-width: 70%;
    padding: 1rem 1.25rem;
  }

  .composer {
    padding: 1.5rem 2rem;
    position: static;
  }
}

/* ===== LARGE DESKTOP ===== */
@media (min-width: 1024px) {
  #sidebar {
    width: 360px;
    min-width: 360px;
  }

  .chat-box {
    padding: 2rem 3rem;
  }
}

/* ===== DARK THEME ===== */
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1220;
    --card: #0f172a;
    --text: #e5e7eb;
    --muted: #9aa5b1;
    --brand: #76a9fa;
    --brand-hover: #5b8be0;
    --line: #1f2937;
    --bubble-user: #0d2547;
    --bubble-ai: #101829;
    --shadow: 0 8px 28px rgba(0,0,0,0.45);
  }
}

/* ===== UTILITIES ===== */
.loading {
  opacity: 0.6;
  pointer-events: none;
}

.no-chats {
  text-align: center;
  padding: 2rem;
  color: var(--muted);
  font-style: italic;
}

/* Scrollbars */
.chat-box::-webkit-scrollbar,
.chat-history::-webkit-scrollbar {
  width: 6px;
}

.chat-box::-webkit-scrollbar-track,
.chat-history::-webkit-scrollbar-track {
  background: transparent;
}

.chat-box::-webkit-scrollbar-thumb,
.chat-history::-webkit-scrollbar-thumb {
  background: var(--line);
  border-radius: 3px;
}

.chat-box::-webkit-scrollbar-thumb:hover,
.chat-history::-webkit-scrollbar-thumb:hover {
  background: var(--muted);
}

/* Extra mobiele optimalisaties */
@media (max-width: 767px) {
  .chat-box {
    overscroll-behavior: contain;
    scroll-behavior: smooth;
  }
}
/* Fix voor toetsenbord op mobiel */
@media (max-width: 767px) {
  html {
    height: 100%;
    overflow: auto;
  }

  body {
    height: 100%;
    overflow: auto;
    position: relative;
  }

  .composer {
    position: sticky;
    bottom: 0;
    background: var(--card);
    padding: 1rem;
    padding-bottom: calc(1rem + env(safe-area-inset-bottom, 1rem));
    z-index: 1000;
    border-top: 1px solid var(--line);
  }

  .chat-box {
    padding-bottom: 100px;
  }
}
/* ===== TOOLS SIDEBAR ===== */
#toolsSidebar {
  position: fixed;
  top: 60px;
  right: -100%;
  width: 100%;
  height: calc(100vh - 60px);
  background: var(--card);
  border-left: 1px solid var(--line);
  z-index: 900;
  transition: right 0.3s ease;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

#toolsSidebar.active {
  right: 0;
}

#toolsSidebar h3 {
  padding: 1.5rem 1rem 1rem;
  margin: 0;
  border-bottom: 1px solid var(--line);
  font-size: 1.1rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.tools-menu {
  flex: 1;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.tools-menu .btn {
  justify-content: flex-start;
  text-align: left;
  padding: 1rem;
}

@media (max-width: 767px) {
  .action-buttons {
    display: none;
  }
}

/* Desktop styles */
@media (min-width: 768px) {
  #toolsSidebar {
    width: 280px;
    min-width: 280px;
  }
}
