:root {
  --bg-color: #0B0F14;
  --card-bg: #121821;
  --card-border: #1F2A36;
  --text-main: #FFFFFF;
  --text-muted: #8E9BAE;
  --accent-blue-start: #3B82F6;
  --accent-blue-end: #2563EB;
  --accent-gradient: linear-gradient(135deg, var(--accent-blue-start), var(--accent-blue-end));
  --accent-glow: rgba(59, 130, 246, 0.25);
  --badge-bg: rgba(59, 130, 246, 0.15);
  --badge-color: #93C5FD;
}

body {
  background-color: var(--bg-color);
  background-image: radial-gradient(circle at 50% 0%, rgba(37, 99, 235, 0.1) 0%, transparent 60%);
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  color: var(--text-main);
  padding-bottom: 80px;
  min-height: 100vh;
  margin: 0;
}

/* Nav bar */
.navbar {
  background: rgba(11, 15, 20, 0.8) !important;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--card-border);
}

.navbar-brand {
  font-weight: 700;
  color: var(--text-main) !important;
  letter-spacing: -0.02em;
}

.nav-link {
  color: var(--text-muted) !important;
  font-weight: 500;
  transition: color 0.2s ease;
}

.nav-link:hover,
.nav-link.active {
  color: var(--text-main) !important;
}

/* Header */
.page-header {
  text-align: center;
  padding: 40px 20px;
  margin-top: 20px;
}

.page-header h1 {
  font-weight: 800;
  font-size: 2.5rem;
  letter-spacing: -0.02em;
  background: var(--accent-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  margin-bottom: 8px;
}

.page-header .small-muted {
  color: var(--text-muted);
  font-weight: 500;
  font-size: 1.1rem;
}

/* Premium Exam Cards */
.exam-card {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 20px;
  padding: 32px 24px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
  transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  min-height: 280px;
  position: relative;
  overflow: hidden;
  text-decoration: none;
}

.exam-card.expired {
  opacity: 0.5;
  filter: grayscale(80%);
}

.exam-card.expired:hover {
  transform: none;
  box-shadow: none;
  border-color: var(--card-border);
}

.exam-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 4px;
  background: var(--accent-gradient);
  opacity: 0;
  transition: opacity 0.3s ease;
}

.exam-card:hover:not(.expired) {
  transform: translateY(-6px);
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.4), 0 0 30px var(--accent-glow);
  border-color: rgba(96, 165, 250, 0.3);
}

.exam-card:hover:not(.expired)::before {
  opacity: 1;
}

/* Image Upload & Drag-Drop Styles */
.btn-icon {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--card-border);
  color: var(--text-muted);
  border-radius: 8px;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  cursor: pointer;
}

.btn-icon:hover {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text-main);
  border-color: var(--accent-blue-start);
}

.dragging {
  border-color: var(--accent-blue-start) !important;
  background: rgba(59, 130, 246, 0.05) !important;
}

.drag-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(11, 15, 20, 0.9);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  border-radius: 20px;
  border: 2px dashed var(--accent-blue-start);
  pointer-events: all; /* Important to catch drop */
}

.drag-overlay-content {
  text-align: center;
  color: var(--accent-blue-start);
}

.drag-overlay-content svg {
  margin-bottom: 12px;
  display: block;
  margin-left: auto;
  margin-right: auto;
}

.drag-overlay-content span {
  font-weight: 600;
  font-size: 1.1rem;
}

.chat-image-wrapper {
  margin-top: 8px;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--card-border);
  display: inline-block;
  max-width: 100%;
}

.chat-image {
  max-width: 100%;
  max-height: 300px;
  display: block;
  cursor: zoom-in;
  transition: opacity 0.2s;
}

.chat-image:hover {
  opacity: 0.9;
}

/* Spinner for button */
.spinner-border {
  width: 1.2rem;
  height: 1.2rem;
}

/* Preview Modal Styles */
.preview-modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  padding: 20px;
}

.preview-modal-content {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 24px;
  width: 100%;
  max-width: 500px;
  display: flex;
  flex-direction: column;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
  overflow: hidden;
}

.preview-modal-header {
  padding: 16px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--card-border);
}

.preview-modal-header h5 {
  margin: 0;
  font-weight: 700;
  font-size: 1.1rem;
}

.btn-close-custom {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  padding: 0;
  transition: color 0.2s;
}

.btn-close-custom:hover {
  color: var(--text-main);
}

.preview-modal-body {
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.preview-image-container {
  width: 100%;
  background: #000;
  border-radius: 12px;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  max-height: 350px;
  border: 1px solid var(--card-border);
}

.preview-image-container img {
  max-width: 100%;
  max-height: 350px;
  object-fit: contain;
}

#captionInput {
  width: 100%;
  background: rgba(0, 0, 0, 0.2);
  border: 1px solid var(--card-border);
  border-radius: 12px;
  padding: 12px;
  color: var(--text-main);
  font-size: 1rem;
  resize: none;
  height: 80px;
  outline: none;
  transition: border-color 0.2s;
}

#captionInput:focus {
  border-color: var(--accent-blue-start);
}

.preview-modal-footer {
  padding: 16px 20px;
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  background: rgba(255, 255, 255, 0.02);
  border-top: 1px solid var(--card-border);
}

.btn-secondary-custom {
  background: transparent;
  border: 1px solid var(--card-border);
  color: var(--text-main);
  font-weight: 600;
  padding: 10px 20px;
  border-radius: 12px;
  transition: all 0.2s;
}

/* Chat Header & Fullscreen */
.chat-header {
  padding: 12px 20px;
  background: rgba(255, 255, 255, 0.03);
  border-bottom: 1px solid var(--card-border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.status-indicator {
  width: 8px;
  height: 8px;
  background: #10B981;
  border-radius: 50%;
  box-shadow: 0 0 8px rgba(16, 185, 129, 0.6);
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0% { opacity: 1; }
  50% { opacity: 0.5; }
  100% { opacity: 1; }
}

.btn-fullscreen {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
  border-radius: 6px;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-fullscreen:hover {
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-main);
}

/* Fullscreen State (Reliable on Mobile & Desktop) */
.chat-container.is-app-fullscreen {
  position: fixed !important;
  top: 0 !important;
  left: 0 !important;
  width: 100vw !important;
  height: 100vh !important;
  height: 100dvh !important; /* Dynamic Viewport Height for mobile */
  z-index: 9999 !important;
  border-radius: 0 !important;
  border: none !important;
  max-width: none !important;
  margin: 0 !important;
}

.chat-container.is-app-fullscreen .chat-messages {
  max-height: none !important;
  flex: 1;
}

.chat-container.is-app-fullscreen .chat-header {
  border-radius: 0;
}

/* Segmented Message Layout */
.message-body {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.message-text {
  font-size: 0.95rem;
  line-height: 1.5;
  word-break: break-word;
}

.chat-image-box {
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--card-border);
  background: #000;
  display: flex;
  align-items: center;
  justify-content: center;
  max-width: 100%;
}

.chat-image {
  max-width: 100%;
  max-height: 450px; /* Reduced from 50vh for better scaling */
  display: block;
  cursor: zoom-in;
  transition: opacity 0.2s;
}

.chat-image:hover {
  opacity: 0.9;
}

/* Adjust bubble for images */
.message-bubble:has(.chat-image-box) {
  width: fit-content;
  max-width: 85%;
}

/* --- Mobile Responsiveness --- */
@media (max-width: 768px) {
  body {
    padding-bottom: 20px;
  }

  .container {
    padding-left: 10px;
    padding-right: 10px;
  }

  /* Chat Container Mobile */
  .chat-container {
    height: 85vh; /* Taller on mobile for better keyboard experience */
    border-radius: 12px;
  }

  .chat-messages {
    padding: 12px;
    gap: 12px;
  }

  .message-bubble {
    max-width: 95%; /* More width on narrow screens */
    padding: 10px 12px;
  }

  .message-nickname {
    font-size: 0.8rem;
  }

  .message-time {
    font-size: 0.65rem;
  }

  .chat-image {
    max-height: 300px;
  }

  /* Input Area adjustments */
  .chat-input-area {
    padding: 15px;
  }

  .chat-message-row {
    gap: 8px;
  }

  .btn-icon, .btn-send {
    width: 40px;
    height: 40px;
  }

  .chat-message-row textarea {
    font-size: 1rem; /* Prevent zoom on iOS */
    height: 40px;
  }

  /* Preview Modal Mobile */
  .preview-modal-content {
    max-width: 100%;
    height: 90vh;
    border-radius: 16px;
  }

  .preview-image-container {
    max-height: 250px;
  }

  .preview-image-container img {
    max-height: 250px;
  }

  /* Fullscreen on mobile */
  .chat-container.is-fullscreen {
    height: 100vh !important;
    position: fixed;
    top: 0;
    left: 0;
    z-index: 3000;
  }
}

@media (max-width: 480px) {
  .page-header h1 {
    font-size: 1.8rem;
  }

  .top-tab {
    padding: 10px 4px;
    font-size: 0.85rem;
  }

  .navbar-brand {
    font-size: 1rem;
  }
}

.exam-card h5 {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--text-main);
  margin: 0;
  line-height: 1.4;
}

.badge {
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  padding: 0.5em 0.7em;
  background: var(--badge-bg) !important;
  color: var(--badge-color) !important;
  border: 1px solid rgba(147, 197, 253, 0.2);
  border-radius: 8px;
}

.badge-passed {
  background: rgba(255, 255, 255, 0.05) !important;
  color: #64748B !important;
  border: 1px solid rgba(255, 255, 255, 0.1);
}

/* Countdown layout */
.countdown-box-container {
  display: flex;
  justify-content: center;
  gap: 16px;
  margin: 20px 0;
}

.countdown-box {
  text-align: center;
}

.countdown-box .number {
  font-weight: 800;
  font-size: 2.2rem;
  line-height: 1;
  background: #FFFFFF;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.countdown-box .label {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-top: 4px;
}

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

/* Progress Bar */
.progress {
  height: 6px;
  border-radius: 6px;
  margin-top: 16px;
  background: rgba(255, 255, 255, 0.05);
  overflow: visible;
}

.progress .progress-bar {
  border-radius: 6px;
  background: var(--accent-gradient);
  box-shadow: 0 0 10px var(--accent-glow);
  transition: width 1.2s cubic-bezier(0.22, 1, 0.36, 1);
  position: relative;
}

.progress .progress-bar::after {
  content: '';
  position: absolute;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 10px;
  height: 10px;
  background: #FFF;
  border-radius: 50%;
  box-shadow: 0 0 8px rgba(255, 255, 255, 0.8);
}

footer {
  margin-top: 48px;
  color: #475569;
  text-align: center;
  font-size: 0.85rem;
}

/* App Button */
.btn-primary-gradient {
  background: var(--accent-gradient);
  border: none;
  color: #fff;
  font-weight: 600;
  border-radius: 12px;
  transition: all 0.2s ease;
}

.btn-primary-gradient:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 20px var(--accent-glow);
}

/* Access Form */
.access-container {
  max-width: 400px;
  margin: 80px auto;
  padding: 32px;
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 20px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
}

.access-container .form-control {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--card-border);
  color: var(--text-main);
  border-radius: 12px;
  padding: 12px 16px;
  text-align: center;
  font-size: 1.2rem;
  letter-spacing: 0.2em;
}

.access-container .form-control:focus {
  background: rgba(255, 255, 255, 0.05);
  border-color: var(--accent-blue-start);
  box-shadow: 0 0 0 3px var(--accent-glow);
  outline: none;
}

.error-text {
  color: #F87171;
  font-size: 0.9rem;
  margin-top: 12px;
  display: none;
  text-align: center;
}

/* --- Past Papers UI --- */

.paper-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 24px;
  border-bottom: 1px solid var(--card-border);
  padding-bottom: 12px;
  overflow-x: auto;
  scrollbar-width: none;
}
.paper-tabs::-webkit-scrollbar {
  display: none;
}

.paper-tab {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-muted);
  font-weight: 600;
  padding: 8px 16px;
  border-radius: 8px;
  transition: all 0.2s ease;
  white-space: nowrap;
  outline: none;
}

.paper-tab:hover {
  color: var(--text-main);
  background: rgba(255, 255, 255, 0.03);
}

.paper-tab.active {
  color: var(--text-main);
  background: var(--badge-bg);
  border: 1px solid rgba(59, 130, 246, 0.3);
  box-shadow: 0 0 15px var(--accent-glow);
}

.paper-accordion {
  border: 1px solid var(--card-border);
  border-radius: 12px;
  overflow: hidden;
  margin-bottom: 12px;
  background: rgba(255, 255, 255, 0.01);
  transition: all 0.3s ease;
}

.paper-accordion:hover {
  border-color: rgba(255, 255, 255, 0.1);
}

.paper-accordion-header {
  padding: 16px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
  background: transparent;
  font-weight: 600;
  color: var(--text-main);
  transition: background 0.2s;
  user-select: none;
}

.paper-accordion-header:hover {
  background: rgba(255, 255, 255, 0.02);
}

.paper-accordion-header::after {
  content: '+';
  font-size: 1.2rem;
  font-weight: 400;
  transition: transform 0.3s;
}

.paper-accordion.open .paper-accordion-header::after {
  content: '−';
}

.paper-accordion-body {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.4s cubic-bezier(0.25, 0.8, 0.25, 1);
  padding: 0 20px;
}
.paper-accordion.open .paper-accordion-body {
  max-height: 8000px;
  padding: 0 20px 20px 20px;
}

.paper-row-label {
  color: var(--text-muted);
  font-size: 0.85rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-top: 16px;
  margin-bottom: 12px;
  border-bottom: 1px solid var(--card-border);
  padding-bottom: 8px;
}
/* Top Navigation Tabs */
.top-tabs {
  display: flex;
  justify-content: center;
  gap: 12px;
  margin-bottom: 32px;
  background: rgba(255, 255, 255, 0.03);
  padding: 8px;
  border-radius: 16px;
  border: 1px solid var(--card-border);
}

.top-tab {
  flex: 1;
  max-width: 200px;
  padding: 12px;
  text-align: center;
  border-radius: 12px;
  cursor: pointer;
  font-weight: 600;
  color: var(--text-muted);
  transition: all 0.2s ease;
  user-select: none;
}

.top-tab:hover {
  color: var(--text-main);
  background: rgba(255, 255, 255, 0.05);
}

.top-tab.active {
  background: var(--accent-gradient);
  color: #FFFFFF;
  box-shadow: 0 4px 15px var(--accent-glow);
}

/* Chatboard Styles */
.chat-container {
  display: flex;
  flex-direction: column;
  height: 600px;
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: 20px;
  overflow: hidden;
}

.chat-messages {
  flex: 1;
  padding: 20px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
  scrollbar-width: thin;
  scrollbar-color: var(--card-border) transparent;
}

.chat-messages::-webkit-scrollbar {
  width: 6px;
}
.chat-messages::-webkit-scrollbar-thumb {
  background: var(--card-border);
  border-radius: 10px;
}

.message-bubble {
  max-width: 85%;
  background: rgba(255, 255, 255, 0.05);
  padding: 12px 16px;
  border-radius: 16px;
  border: 1px solid var(--card-border);
  align-self: flex-start;
}

.message-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 4px;
  gap: 12px;
}

.message-nickname {
  font-weight: 700;
  font-size: 0.85rem;
  color: var(--badge-color);
}

.message-time {
  font-size: 0.7rem;
  color: var(--text-muted);
}

.message-content {
  font-size: 0.95rem;
  line-height: 1.5;
  word-break: break-word;
}

.chat-input-area {
  padding: 20px;
  background: rgba(255, 255, 255, 0.02);
  border-top: 1px solid var(--card-border);
}

.chat-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.chat-meta-inputs {
  display: flex;
  gap: 12px;
}

.chat-meta-inputs input {
  flex: 1;
  background: rgba(0, 0, 0, 0.2);
  border: 1px solid var(--card-border);
  border-radius: 8px;
  padding: 8px 12px;
  color: var(--text-main);
  font-size: 0.9rem;
}

.chat-message-row {
  display: flex;
  gap: 12px;
}

.chat-message-row textarea {
  flex: 1;
  background: rgba(0, 0, 0, 0.2);
  border: 1px solid var(--card-border);
  border-radius: 8px;
  padding: 10px 12px;
  color: var(--text-main);
  resize: none;
  height: 44px;
  font-size: 0.95rem;
}

.btn-send {
  background: var(--accent-gradient);
  border: none;
  border-radius: 8px;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s;
}

.btn-send:hover {
  transform: scale(1.05);
}

.btn-send svg {
  fill: #FFF;
}

.paper-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 12px;
  margin-top: 16px;
}

.btn-paper {
  background: rgba(147, 197, 253, 0.05);
  border: 1px solid rgba(147, 197, 253, 0.1);
  color: var(--text-main);
  padding: 12px 16px;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 500;
  text-decoration: none;
  display: flex;
  justify-content: space-between;
  align-items: center;
  transition: all 0.2s ease;
  cursor: pointer;
}

.btn-paper:hover {
  transform: translateY(-2px);
  background: rgba(147, 197, 253, 0.15);
  border-color: rgba(147, 197, 253, 0.4);
  box-shadow: 0 4px 12px rgba(59, 130, 246, 0.15);
  color: var(--text-main);
}

.btn-paper svg {
  fill: currentColor;
  opacity: 0.7;
}

.btn-paper:hover svg {
  opacity: 1;
}