:root {
  color-scheme: light;
  font-family: "Inter", "Segoe UI", system-ui, sans-serif;
  --primary: #1d4ed8;
  --secondary: #0f172a;
  --accent: #e0f2fe;
  --muted: #64748b;
  --border: #e2e8f0;
  --background: #f8fafc;
  --card: #ffffff;
  --success: #16a34a;
  --danger: #ef4444;
  --warning: #f59e0b;
  --shadow: 0 15px 30px rgba(15, 23, 42, 0.08);
}

body[data-theme="dark"] {
  color-scheme: dark;
  --primary: #60a5fa;
  --secondary: #e2e8f0;
  --accent: #1e293b;
  --muted: #94a3b8;
  --border: #1f2937;
  --background: #0f172a;
  --card: #111827;
  --success: #4ade80;
  --danger: #f87171;
  --warning: #fbbf24;
  --shadow: 0 20px 40px rgba(2, 6, 23, 0.4);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  background: var(--background);
  color: var(--secondary);
  line-height: 1.5;
  min-height: 100vh;
}

.app {
  max-width: 1200px;
  margin: 0 auto;
  padding: 2.5rem 1.5rem 4rem;
}

/* ============================================
   HEADER
   ============================================ */
.site-header {
  display: flex;
  flex-wrap: wrap;
  gap: 2rem;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 2.5rem;
}

.site-header h1 {
  font-size: 2.4rem;
  font-weight: 700;
  line-height: 1.2;
  margin-bottom: 0.75rem;
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.2em;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
}

.subtitle {
  max-width: 550px;
  color: var(--muted);
  line-height: 1.6;
  font-size: 1.1rem;
}

.header-actions {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  align-items: flex-end;
}

.header-card {
  background: linear-gradient(120deg, var(--accent), var(--card));
  border-radius: 16px;
  padding: 1.5rem;
  max-width: 280px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}

.header-card span {
  font-weight: 700;
  color: var(--success);
  font-size: 1.1rem;
  display: block;
  margin-bottom: 0.5rem;
}

.header-card p {
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.5;
}

.theme-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--card);
  color: var(--secondary);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  padding: 0.5rem 1rem;
  border-radius: 999px;
  font-size: 0.9rem;
  cursor: pointer;
  transition: all 0.2s ease;
}

.theme-toggle:hover {
  transform: translateY(-2px);
  border-color: var(--primary);
}

/* ============================================
   MAIN
   ============================================ */
main {
  display: flex;
  flex-direction: column;
  gap: 2rem;
}

/* ============================================
   CARDS
   ============================================ */
.card {
  background: var(--card);
  border-radius: 20px;
  padding: 1.75rem;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.card:hover {
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.12);
}

/* ============================================
   LOGIN SECTION
   ============================================ */
.login {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 1.5rem;
  align-items: start;
}

.login .card:first-child {
  grid-column: span 1;
}

.login form {
  display: grid;
  gap: 1.25rem;
  margin-top: 1.5rem;
}

/* ============================================
   FORM ELEMENTS
   ============================================ */
label {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--secondary);
}

input,
select,
textarea {
  padding: 0.75rem 1rem;
  border: 2px solid var(--border);
  border-radius: 12px;
  font-size: 1rem;
  background: var(--card);
  color: var(--secondary);
  transition: all 0.2s ease;
  width: 100%;
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(29, 78, 216, 0.1);
}

input:hover,
select:hover,
textarea:hover {
  border-color: var(--primary);
}

/* ============================================
   BUTTONS
   ============================================ */
button {
  padding: 0.75rem 1.5rem;
  border-radius: 999px;
  border: none;
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
  transition: all 0.2s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
}

button.primary {
  background: var(--primary);
  color: white;
  box-shadow: 0 4px 6px -1px rgba(29, 78, 216, 0.3);
}

button.primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 10px -1px rgba(29, 78, 216, 0.4);
}

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

button.secondary {
  background: var(--accent);
  color: var(--secondary);
  border: 1px solid var(--border);
}

button.secondary:hover {
  background: var(--card);
  border-color: var(--primary);
  transform: translateY(-2px);
}

button.delete {
  background: var(--danger);
  color: white;
  border: none;
}

button.delete:hover {
  background: #dc2626;
}

button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none !important;
}

/* Logout Button */
#logout-button,
#logout-button-dashboard {
  background: var(--accent);
  color: var(--secondary);
  border: 1px solid var(--border);
}

#logout-button:hover,
#logout-button-dashboard:hover {
  background: var(--danger);
  color: white;
  border-color: var(--danger);
}

/* ============================================
   FORM ERROR
   ============================================ */
.form-error {
  color: var(--danger);
  font-size: 0.9rem;
  min-height: 1.5rem;
  margin-top: 0.5rem;
  font-weight: 500;
}

/* ============================================
   INFO CARD
   ============================================ */
.info ul {
  margin-top: 1rem;
  display: grid;
  gap: 0.8rem;
  color: var(--muted);
  list-style: none;
}

.info li {
  padding-left: 1.5rem;
  position: relative;
}

.info li::before {
  content: "✓";
  color: var(--success);
  position: absolute;
  left: 0;
  font-weight: bold;
}

/* ============================================
   DASHBOARD
   ============================================ */
.dashboard {
  display: flex;
  flex-direction: column;
  gap: 2rem;
}

.welcome {
  display: grid;
  gap: 1rem;
}

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

.welcome h2 {
  font-size: 1.8rem;
  font-weight: 700;
}

#welcome-text {
  color: var(--muted);
  font-size: 1.1rem;
}

/* ============================================
   PROFILE
   ============================================ */
.profile {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1.5rem;
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

.label {
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.25rem;
}

.value {
  font-weight: 700;
  font-size: 1.2rem;
}

#status-label {
  color: var(--success);
}

/* ============================================
   INTRO CARDS
   ============================================ */
.intro {
  background: linear-gradient(135deg, var(--accent) 0%, var(--card) 100%);
  border-left: 4px solid var(--primary);
  position: relative;
  overflow: hidden;
}

.intro::after {
  content: "";
  position: absolute;
  top: 0;
  right: 0;
  width: 100px;
  height: 100px;
  background: linear-gradient(135deg, transparent 50%, rgba(29, 78, 216, 0.1) 50%);
  border-radius: 0 0 0 100px;
}

.intro h3 {
  font-size: 1.4rem;
  margin-bottom: 0.75rem;
  color: var(--secondary);
}

.intro-steps {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 1rem;
  margin-top: 1.5rem;
}

.intro-steps div {
  background: var(--card);
  border-radius: 16px;
  padding: 1rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  font-weight: 600;
  border: 1px solid var(--border);
  transition: all 0.2s ease;
}

.intro-steps div:hover {
  transform: translateY(-2px);
  border-color: var(--primary);
}

.intro-steps span {
  width: 36px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--primary);
  color: white;
  border-radius: 50%;
  font-weight: 700;
  font-size: 1.1rem;
  box-shadow: 0 4px 6px -1px rgba(29, 78, 216, 0.3);
}

/* ============================================
   COLUMNS LAYOUT
   ============================================ */
.columns {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 1.5rem;
}

/* ============================================
   SUBJECTS (Fächerauswahl)
   ============================================ */
.subjects {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 0.75rem;
  margin: 1.25rem 0 1.5rem;
}

.subject {
  border: 2px solid var(--border);
  border-radius: 14px;
  padding: 0.8rem 1rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  cursor: pointer;
  transition: all 0.2s ease;
  background: var(--card);
  font-weight: 500;
}

.subject:hover {
  border-color: var(--primary);
  background: var(--accent);
  transform: translateY(-2px);
}

.subject input[type="checkbox"] {
  width: 20px;
  height: 20px;
  accent-color: var(--primary);
  cursor: pointer;
  margin: 0;
}

.subject input[type="checkbox"]:checked + span {
  color: var(--primary);
  font-weight: 600;
}

/* ============================================
   MENTOR LIST
   ============================================ */
.mentor-list {
  display: grid;
  gap: 1rem;
  margin-top: 1rem;
  max-height: 400px;
  overflow-y: auto;
  padding-right: 0.5rem;
}

.mentor-list::-webkit-scrollbar {
  width: 6px;
}

.mentor-list::-webkit-scrollbar-track {
  background: var(--border);
  border-radius: 10px;
}

.mentor-list::-webkit-scrollbar-thumb {
  background: var(--primary);
  border-radius: 10px;
}

.mentor {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.25rem;
  border-radius: 16px;
  border: 2px solid var(--border);
  transition: all 0.2s ease;
  background: var(--card);
}

.mentor:hover {
  border-color: var(--primary);
  transform: translateY(-2px);
  box-shadow: var(--shadow);
}

.mentor.unavailable {
  opacity: 0.6;
  background: var(--accent);
}

.mentor.unavailable button {
  background: var(--muted);
  color: white;
  cursor: not-allowed;
}

.mentor div:first-child {
  flex: 1;
}

.mentor strong {
  font-size: 1.1rem;
  display: block;
  margin-bottom: 0.25rem;
  color: var(--secondary);
}

.mentor p {
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.4;
}

.mentor p small {
  font-size: 0.8rem;
}

.mentor button {
  background: var(--accent);
  color: var(--primary);
  padding: 0.6rem 1.2rem;
  font-size: 0.9rem;
  white-space: nowrap;
  margin-left: 1rem;
}

.mentor button:hover:not(:disabled) {
  background: var(--primary);
  color: white;
  transform: translateY(-2px);
}

/* Status Badges */
.status-badge {
  display: inline-block;
  font-size: 0.75rem;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  margin-left: 0.5rem;
}

.status-badge.available {
  background: #10b981;
  color: white;
}

.status-badge.unavailable {
  background: #6b7280;
  color: white;
}

/* ============================================
   SENIOR STATUS CARD
   ============================================ */
.senior-status-card {
  background: var(--card);
  border-radius: 16px;
  padding: 1.5rem;
  margin: 1rem 0;
  border: 2px solid var(--border);
}

.status-toggle {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.status-toggle h4 {
  margin: 0;
  color: var(--secondary);
}

.toggle-wrapper {
  display: flex;
  gap: 1rem;
}

.toggle-wrapper button {
  flex: 1;
}

.status-info {
  color: var(--muted);
  font-size: 0.9rem;
  margin: 0;
}

/* ============================================
   CHAT SECTION - VERBESSERT
   ============================================ */
.chat {
  display: grid;
  gap: 1.5rem;
  margin-top: 1rem;
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding-bottom: 1rem;
  border-bottom: 2px solid var(--border);
}

.chat-header h3 {
  font-size: 1.5rem;
  color: var(--primary);
}

#chat-subtitle {
  font-size: 0.95rem;
  margin-top: 0.25rem;
}

.chat-subtitle-content {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.status-text {
  color: var(--muted);
  font-size: 0.95rem;
}

/* Chat Delete Button mit Abstand */
.chat-delete-btn {
  margin-top: 0.5rem;
  align-self: flex-start;
  background: var(--danger);
  color: white;
  border: none;
}

.chat-delete-btn:hover {
  background: #dc2626;
}

/* Chat Actions für Anfragen */
.chat-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.chat-actions button {
  flex: 1;
}

.chat-layout {
  display: grid;
  grid-template-columns: 260px 1fr;
  gap: 1.5rem;
  min-height: 450px;
}

/* Chat Sidebar */
.chat-sidebar {
  background: var(--accent);
  border-radius: 16px;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  border: 1px solid var(--border);
}

.chat-sidebar h4 {
  font-size: 1.1rem;
  color: var(--secondary);
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border);
}

.chat-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  overflow-y: auto;
  max-height: 350px;
  padding-right: 0.25rem;
}

.chat-list::-webkit-scrollbar {
  width: 4px;
}

.chat-list::-webkit-scrollbar-track {
  background: var(--border);
  border-radius: 10px;
}

.chat-list::-webkit-scrollbar-thumb {
  background: var(--primary);
  border-radius: 10px;
}

.chat-item {
  border: 1px solid var(--border);
  padding: 0.75rem 1rem;
  border-radius: 12px;
  cursor: pointer;
  background: var(--card);
  text-align: left;
  transition: all 0.2s ease;
  width: 100%;
}

.chat-item:hover {
  transform: translateX(4px);
  border-color: var(--primary);
}

.chat-item.selected {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
  transform: translateX(4px);
}

.chat-item.selected .muted {
  color: rgba(255, 255, 255, 0.9);
}

.chat-item.pending {
  border-left: 4px solid var(--warning);
}

.chat-item.active {
  border-left: 4px solid var(--success);
}

.chat-item.closed {
  border-left: 4px solid var(--muted);
  opacity: 0.7;
}

.chat-item-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.25rem;
}

.chat-item strong {
  display: block;
  font-size: 1rem;
}

.chat-preview {
  font-size: 0.85rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.unread-badge {
  background: var(--primary);
  color: white;
  border-radius: 999px;
  padding: 0.15rem 0.5rem;
  font-size: 0.75rem;
  font-weight: bold;
  min-width: 1.5rem;
  text-align: center;
}

/* Chat Panel */
.chat-panel {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  background: var(--card);
  border-radius: 16px;
  padding: 1rem;
  border: 1px solid var(--border);
}

.chat-body {
  background: var(--background);
  border-radius: 16px;
  padding: 1.25rem;
  min-height: 300px;
  max-height: 350px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  border: 1px solid var(--border);
}

.chat-body::-webkit-scrollbar {
  width: 6px;
}

.chat-body::-webkit-scrollbar-track {
  background: var(--border);
  border-radius: 10px;
}

.chat-body::-webkit-scrollbar-thumb {
  background: var(--primary);
  border-radius: 10px;
}

/* Message Styles - Verbessert */
.message-container {
  display: flex;
  flex-direction: column;
  max-width: 70%;
  margin-bottom: 1rem;
}

.message-container.me {
  align-self: flex-end;
  margin-left: auto;
}

.message-time {
  font-size: 0.7rem;
  color: var(--muted);
  margin-bottom: 0.25rem;
  margin-left: 0.5rem;
  margin-right: 0.5rem;
}

.message-container.me .message-time {
  text-align: right;
}

.message-container:not(.me) .message-time {
  text-align: left;
}

.chat-message {
  background: var(--card);
  padding: 0.75rem 1.25rem;
  border-radius: 18px;
  border: 1px solid var(--border);
  word-wrap: break-word;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05);
}

.message-container.me .chat-message {
  background: var(--primary);
  color: white;
  border-bottom-right-radius: 4px;
  border-color: var(--primary);
}

.message-container:not(.me) .chat-message {
  background: var(--card);
  border-bottom-left-radius: 4px;
}

.chat-input {
  display: flex;
  gap: 0.75rem;
  margin-top: auto;
}

.chat-input input {
  flex: 1;
  padding: 0.75rem 1rem;
  border-radius: 999px;
  background: var(--accent);
}

.chat-placeholder {
  color: var(--muted);
  text-align: center;
  align-self: center;
  justify-self: center;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-style: italic;
}

/* ============================================
   MUTED TEXT
   ============================================ */
.muted {
  color: var(--muted);
  font-size: 0.95rem;
}

/* ============================================
   RESPONSIVE DESIGN
   ============================================ */
@media (max-width: 1024px) {
  .app {
    padding: 2rem 1rem 3rem;
  }
  
  .site-header h1 {
    font-size: 2rem;
  }
}

@media (max-width: 768px) {
  .site-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 1.5rem;
  }

  .header-actions {
    align-items: flex-start;
    width: 100%;
  }

  .header-card {
    max-width: 100%;
  }

  .chat-layout {
    grid-template-columns: 1fr;
  }

  .chat-sidebar {
    max-height: 200px;
  }

  .chat-input {
    flex-direction: column;
  }

  button {
    width: 100%;
  }

  .welcome-header {
    flex-direction: column;
    gap: 1rem;
    align-items: flex-start;
  }

  .mentor {
    flex-direction: column;
    align-items: flex-start;
    gap: 1rem;
  }

  .mentor button {
    width: 100%;
    margin-left: 0;
  }

  .profile {
    grid-template-columns: 1fr;
    gap: 1rem;
  }

  .intro-steps {
    grid-template-columns: 1fr;
  }

  .subjects {
    grid-template-columns: repeat(2, 1fr);
  }

  .message-container {
    max-width: 85%;
  }
  
  .toggle-wrapper {
    flex-direction: column;
  }
}

@media (max-width: 480px) {
  .app {
    padding: 1.5rem 0.75rem 2rem;
  }

  .site-header h1 {
    font-size: 1.6rem;
  }

  .subtitle {
    font-size: 1rem;
  }

  .card {
    padding: 1.25rem;
  }

  .subjects {
    grid-template-columns: 1fr;
  }

  .chat-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .chat-header button {
    width: 100%;
  }

  .intro-steps div {
    padding: 0.75rem;
  }
}

/* ============================================
   ANIMATIONS
   ============================================ */
@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateX(-20px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

.dashboard {
  animation: slideIn 0.4s ease;
}

.card {
  animation: fadeIn 0.3s ease;
}

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

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ============================================
   UTILITY CLASSES
   ============================================ */
.text-center {
  text-align: center;
}

.mt-2 {
  margin-top: 0.5rem;
}

.mt-4 {
  margin-top: 1rem;
}

.mb-2 {
  margin-bottom: 0.5rem;
}

.mb-4 {
  margin-bottom: 1rem;
}

.hidden {
  display: none !important;
}

/* ============================================
   LOADING STATES
   ============================================ */
.loading {
  position: relative;
  pointer-events: none;
  opacity: 0.7;
}

.loading::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 20px;
  height: 20px;
  margin: -10px 0 0 -10px;
  border: 2px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}