:root {
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  overflow-x: hidden;
}

img,
svg,
video,
canvas {
  max-width: 100%;
}

input,
select,
textarea,
button {
  max-width: 100%;
}

@media (hover: none) and (pointer: coarse) {
  input,
  select,
  textarea {
    font-size: 16px;
  }
}

@media (max-width: 820px) {
  header {
    min-width: 0;
  }

  h1,
  h2,
  h3,
  p,
  label,
  button,
  a,
  td,
  th,
  .muted,
  .message,
  .chunk-text {
    overflow-wrap: anywhere;
  }

  .header-actions,
  .actions,
  .table-tools,
  .settings-actions,
  .feedback-actions,
  .approve-row,
  .modal-footer {
    min-width: 0;
  }

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

  .nav,
  a.button,
  button {
    min-width: 0;
  }

  .table-wrap,
  table {
    max-width: 100%;
  }

  table {
    display: block;
    overflow-x: auto;
    white-space: nowrap;
  }

  td,
  th {
    white-space: normal;
  }

  .modal-backdrop {
    padding: 8px;
  }

  .mcq-modal {
    max-height: calc(100dvh - 16px);
  }
}

@media (max-width: 720px) {
  .admin-shell {
    display: block;
  }

  .admin-sidebar {
    position: sticky;
    top: 0;
    z-index: 6;
    display: flex;
    gap: 6px;
    max-width: 100%;
    margin-bottom: 10px;
    overflow-x: auto;
    padding: 8px;
    scrollbar-width: thin;
  }

  .admin-sidebar-title {
    display: none;
  }

  .admin-sidebar .nav,
  .admin-nav-button {
    flex: 0 0 auto;
    width: auto;
    height: 34px;
    white-space: nowrap;
  }

  .admin-content,
  .admin-section,
  .section {
    min-width: 0;
  }

  .section-header,
  .modal-header,
  .modal-footer {
    align-items: stretch;
    flex-direction: column;
  }

  .table-tools,
  .settings-actions,
  .approve-row,
  .modal-footer {
    display: grid;
    grid-template-columns: 1fr;
    width: 100%;
  }

  .table-tools > *,
  .settings-actions > *,
  .approve-row > *,
  .modal-footer > * {
    width: 100%;
  }

  .compact-form input,
  .compact-form select,
  .compact-form button,
  .query-form input,
  .query-form select,
  .query-form button,
  .upload-form input,
  .upload-form button {
    width: 100% !important;
    grid-column: auto !important;
  }

  .pager {
    display: grid;
    grid-template-columns: 1fr;
    text-align: center;
  }

  .pager button {
    width: 100%;
  }

  .job-title {
    white-space: normal;
  }
}

@media (max-width: 640px) {
  .auth-shell {
    min-height: 100svh;
    padding-bottom: calc(14px + var(--safe-bottom));
  }

  .auth-panel {
    width: 100%;
  }

  .auth-panel button,
  .auth-panel input {
    min-width: 0;
  }

  .shell {
    min-height: 100svh;
  }

  .composer-wrap {
    padding-bottom: calc(8px + var(--safe-bottom));
  }

  .mode-row,
  .tabs,
  .header-actions {
    -webkit-overflow-scrolling: touch;
  }

  .vault-shell,
  .reader,
  .sidebar,
  .panel,
  .profile-required {
    min-width: 0;
  }

  .reader {
    padding: 14px;
  }

  .summary {
    padding: 12px;
    font-size: 15px;
  }

  .section-block p,
  .section-block li {
    font-size: 14px;
  }

  .course-card {
    grid-template-columns: 24px minmax(0, 1fr);
  }

  .profile-required {
    font-size: 14px;
  }
}

@media (max-width: 520px) {
  header {
    gap: 8px;
  }

  .header-actions {
    overflow-x: auto;
    flex-wrap: nowrap;
    padding-bottom: 2px;
  }

  .header-actions a,
  .header-actions button {
    flex: 0 0 auto;
  }

  .toolbar {
    grid-template-columns: 1fr !important;
  }

  .toolbar button,
  .toolbar select {
    width: 100%;
  }

  .practice-actions,
  .review-tools,
  .feedback-actions,
  .actions {
    grid-template-columns: 1fr !important;
  }

  .practice-actions button,
  .review-tools button,
  .review-tools select,
  .feedback-actions button,
  .actions button,
  .actions a {
    width: 100%;
  }

  .progress-strip {
    display: grid;
    grid-template-columns: 1fr;
  }

  .progress-pill {
    justify-content: space-between;
  }

  .message.assistant table,
  .reader table {
    min-width: 480px;
  }
}

@media (max-width: 380px) {
  main {
    padding-left: 8px;
    padding-right: 8px;
  }

  .auth-panel,
  .panel,
  .reader,
  .section,
  .metric,
  .summary {
    border-radius: 7px;
  }

  .message {
    font-size: 13px;
  }

  .header-actions {
    gap: 4px;
  }
}

/* ==========================================
   Vercel / Cloudflare Inspired Modern Design Overrides
   ========================================== */

:root {
  --font-sans: 'Inter', ui-sans-serif, system-ui, -apple-system, sans-serif;
  --border-color: #eaeaea;
  --bg-new: #fafafa;
  --text-primary: #171717;
  --text-muted: #666666;
  --panel-new: #ffffff;
}

/* Global Font and Body Adjustments */
body {
  font-family: var(--font-sans) !important;
  background-color: var(--bg-new) !important;
  color: var(--text-primary) !important;
}

/* Modern Header Layout */
header {
  display: flex !important;
  align-items: center !important;
  justify-content: space-between !important;
  padding: 0 12px !important;
  height: 40px !important;
  border-bottom: 1px solid var(--border-color) !important;
  background: #ffffff !important;
  position: sticky !important;
  top: 0 !important;
  z-index: 100 !important;
}

.header-brand {
  display: flex !important;
  align-items: center !important;
  gap: 8px !important;
  flex-shrink: 0 !important;
}

@media (min-width: 641px) {
  .header-brand {
    gap: 12px !important;
  }
}

.brand-title {
  font-size: 15px !important;
  font-weight: 800 !important;
  color: #000000 !important;
  letter-spacing: -0.04em !important;
}

header h1 {
  font-size: 15px !important;
  font-weight: 700 !important;
  color: #000000 !important;
  letter-spacing: -0.03em !important;
  margin: 0 !important;
  line-height: 1.1 !important;
}

header .header-subtitle, header .muted {
  font-size: 11px !important;
  color: var(--text-muted) !important;
  margin-top: 0px !important;
  line-height: 1.1 !important;
  white-space: nowrap !important;
  overflow: hidden !important;
  text-overflow: ellipsis !important;
  max-width: 180px !important;
}

@media (min-width: 641px) {
  header .header-subtitle, header .muted {
    max-width: 400px !important;
  }
}

@media (min-width: 900px) {
  header .header-subtitle, header .muted {
    max-width: 600px !important;
  }
}

header .menu-toggle {
  padding: 4px !important;
  height: 28px !important;
  width: 28px !important;
}

header .menu-toggle svg {
  width: 20px !important;
  height: 20px !important;
}

/* Header actions list & buttons styling on Desktop */
@media (min-width: 641px) {
  .header-actions, header .actions {
    display: flex !important;
    grid-template-columns: none !important;
    align-items: center !important;
    justify-content: flex-end !important;
    gap: 12px !important;
    width: auto !important;
    overflow: visible !important;
  }

  .history-select {
    height: 28px !important;
    border: 1px solid #e5e7eb !important;
    border-radius: 6px !important;
    background: #f9fafb !important;
    padding: 0 8px !important;
    font-size: 12px !important;
    color: #1f2937 !important;
    outline: none !important;
    min-width: 160px !important;
    max-width: 240px !important;
    transition: all 0.2s !important;
  }

  .history-select:focus {
    border-color: #000000 !important;
    background: #ffffff !important;
    box-shadow: 0 0 0 1px #000000 !important;
  }

  /* Text-based Vercel-style links */
  .ghost-button, a.ghost-button, header a.button.ghost, header button.ghost, header a.nav, header a.button {
    background: transparent !important;
    border: none !important;
    color: #666666 !important;
    font-size: 12px !important;
    font-weight: 500 !important;
    padding: 4px 8px !important;
    border-radius: 6px !important;
    height: 26px !important;
    width: auto !important;
    min-width: 0 !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    text-decoration: none !important;
    transition: all 0.15s ease !important;
    cursor: pointer !important;
    line-height: 1 !important;
  }

  .ghost-button:hover, a.ghost-button:hover, header a.button.ghost:hover, header button.ghost:hover, header a.nav:hover, header a.button:hover {
    color: #000000 !important;
    background-color: #f4f4f5 !important;
  }

  .desktop-label {
    display: inline-block !important;
  }

  .mobile-label {
    display: none !important;
  }

  .status {
    display: inline-flex !important;
    align-items: center !important;
    gap: 8px !important;
    font-size: 11px !important;
    color: var(--text-muted) !important;
    margin-left: 8px !important;
  }
}

/* Mobile Side Drawer Menu Styling */
@media (max-width: 640px) {
  .header-actions {
    background: #ffffff !important;
    border-left: 1px solid var(--border-color) !important;
    box-shadow: -4px 0 30px rgba(0, 0, 0, 0.05) !important;
    padding: 24px 16px !important;
  }
  .header-actions .desktop-label {
    display: none !important;
  }
  .header-actions .mobile-label {
    display: inline !important;
  }
  .header-actions .ghost-button, .header-actions a.ghost-button {
    width: 100% !important;
    height: 40px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: flex-start !important;
    padding: 0 12px !important;
    border-radius: 6px !important;
    border: 1px solid #e5e7eb !important;
    background: #f9fafb !important;
    color: #171717 !important;
    font-size: 14px !important;
    font-weight: 500 !important;
    text-decoration: none !important;
  }
  .header-actions .ghost-button:hover, .header-actions a.ghost-button:hover {
    background: #f3f4f6 !important;
    border-color: #d1d5db !important;
    color: #000000 !important;
  }
}

/* Chat Composer UI (Vercel Playground Style) */
.composer-wrap {
  background: transparent !important;
  border-top: none !important;
  padding: 8px 16px 12px !important;
  width: 100% !important;
  display: flex !important;
  justify-content: center !important;
}

.composer {
  width: min(960px, 100%) !important;
  border: 1px solid #e5e7eb !important;
  border-radius: 10px !important;
  background: #ffffff !important;
  padding: 10px 12px !important;
  box-shadow: 0 10px 30px -5px rgba(0, 0, 0, 0.02), 0 4px 12px -2px rgba(0, 0, 0, 0.01) !important;
  transition: border-color 0.2s, box-shadow 0.2s !important;
  display: grid !important;
  grid-template-columns: minmax(0, 1fr) auto !important;
  gap: 8px !important;
  align-items: end !important;
}

.composer:focus-within {
  border-color: #000000 !important;
  box-shadow: 0 0 0 1px #000000 !important;
}

.mode-row {
  grid-column: 1 / -1 !important;
  display: flex !important;
  flex-wrap: wrap !important;
  align-items: center !important;
  gap: 4px 8px !important;
  padding-bottom: 4px !important;
  border-bottom: 1px solid #f3f4f6 !important;
  margin-bottom: 0px !important;
  overflow-x: visible !important;
}

.mode-row label {
  font-size: 10px !important;
  font-weight: 600 !important;
  text-transform: uppercase !important;
  letter-spacing: 0.05em !important;
  color: #888888 !important;
  margin-right: -4px !important;
}

.mode-row select, .mode-row .source-select {
  height: 25px !important;
  border: 1px solid #e5e7eb !important;
  border-radius: 6px !important;
  background: #f9fafb !important;
  color: #171717 !important;
  font-size: 11px !important;
  padding: 0 6px !important;
  outline: none !important;
  transition: all 0.15s !important;
  min-width: 0 !important;
  max-width: none !important;
  width: auto !important;
}

.mode-row select:focus, .mode-row .source-select:focus {
  border-color: #000000 !important;
  background: #ffffff !important;
}

#modeSelect { width: 110px !important; }
#answerLengthSelect { width: 95px !important; }
#specialtySelect { max-width: 200px !important; }
#sourceSelect { max-width: 220px !important; }

textarea#question {
  grid-column: 1 !important;
  border: none !important;
  background: transparent !important;
  box-shadow: none !important;
  padding: 6px 0 !important;
  font-size: 14px !important;
  min-height: 72px !important;
  max-height: 200px !important;
  line-height: 1.5 !important;
  color: #171717 !important;
  outline: none !important;
  resize: none !important;
}

textarea#question::placeholder {
  color: #9ca3af !important;
}

#sendButton {
  grid-column: 2 !important;
  height: 32px !important;
  width: 32px !important;
  min-width: 32px !important;
  border-radius: 6px !important;
  background: #000000 !important;
  color: #ffffff !important;
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  padding: 0 !important;
  border: none !important;
  cursor: pointer !important;
  transition: background-color 0.15s !important;
}

#sendButton:hover {
  background-color: #171717 !important;
}

#sendButton:disabled {
  background-color: #f3f4f6 !important;
  color: #9ca3af !important;
  cursor: not-allowed !important;
}

/* Chat Messages Overhaul */
.messages {
  width: min(920px, 100%) !important;
  gap: 16px !important;
}

.message {
  max-width: min(760px, 90%) !important;
  border-radius: 12px !important;
  padding: 16px 20px !important;
  font-size: 14px !important;
  line-height: 1.6 !important;
  box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.02) !important;
}

.message.user {
  background-color: #f4f4f5 !important;
  border: 1px solid #e4e4e7 !important;
  color: #18181b !important;
}

.message.assistant {
  background-color: #ffffff !important;
  border: 1px solid #e4e4e7 !important;
  color: #18181b !important;
}

/* Initial Screen Empty State */
.empty {
  margin-top: 10vh !important;
  text-align: center !important;
}

.empty h2 {
  font-size: 24px !important;
  font-weight: 700 !important;
  letter-spacing: -0.03em !important;
  color: #000000 !important;
  margin-bottom: 8px !important;
}

.empty p {
  font-size: 14px !important;
  color: #666666 !important;
  max-width: 420px !important;
  margin: 0 auto !important;
  line-height: 1.5 !important;
}

/* Knowledge Vault Redesign */
.sidebar, .reader {
  background: #ffffff !important;
  border: 1px solid var(--border-color) !important;
  border-radius: 12px !important;
}

.topic-button {
  border-radius: 6px !important;
  transition: all 0.15s !important;
}

.topic-button.active {
  background: #f4f4f5 !important;
  border-color: #e4e4e7 !important;
  color: #000000 !important;
}

/* General Input styling overrides on other pages */
.panel {
  border-radius: 12px !important;
  border-color: var(--border-color) !important;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.01) !important;
}

input[type="text"], input[type="tel"], select {
  border-color: #e5e7eb !important;
  border-radius: 6px !important;
  transition: all 0.15s !important;
}

input[type="text"]:focus, input[type="tel"]:focus, select:focus {
  border-color: #000000 !important;
  box-shadow: 0 0 0 1px #000000 !important;
}

/* MCQ Zone Styling Overrides */
.tabs {
  border-bottom: 1px solid var(--border-color) !important;
  display: flex !important;
  gap: 24px !important;
  padding: 0 !important;
  margin-bottom: 20px !important;
}

.tab {
  background: transparent !important;
  border: none !important;
  border-bottom: 2px solid transparent !important;
  color: #666666 !important;
  font-size: 14px !important;
  font-weight: 500 !important;
  padding: 10px 0 !important;
  border-radius: 0 !important;
  cursor: pointer !important;
  transition: all 0.15s ease !important;
}

.tab:hover {
  color: #000000 !important;
}

.tab.active {
  color: #000000 !important;
  border-bottom-color: #000000 !important;
}

.option-button {
  border: 1px solid #e5e7eb !important;
  border-radius: 8px !important;
  background: #ffffff !important;
  color: #171717 !important;
  font-size: 14px !important;
  transition: all 0.15s !important;
  cursor: pointer !important;
}

.option-button:hover {
  background: #f9fafb !important;
  border-color: #d1d5db !important;
}

.option-button.selected {
  border-color: #000000 !important;
  background: #f9fafb !important;
  color: #000000 !important;
}

.option-button.correct {
  border-color: #10b981 !important;
  background: #ecfdf5 !important;
  color: #065f46 !important;
}

.option-button.incorrect {
  border-color: #ef4444 !important;
  background: #fef2f2 !important;
  color: #991b1b !important;
}

/* Practice Buttons styling */
.practice-actions button, a.button {
  height: 38px !important;
  border-radius: 8px !important;
  font-size: 13px !important;
  font-weight: 500 !important;
  transition: all 0.15s !important;
}

.practice-actions button:not(.ghost), a.button:not(.ghost) {
  background: #000000 !important;
  color: #ffffff !important;
  border: none !important;
}

.practice-actions button:not(.ghost):hover, a.button:not(.ghost):hover {
  background: #171717 !important;
}

.practice-actions button.ghost, a.button.ghost {
  background: #ffffff !important;
  color: #171717 !important;
  border: 1px solid #e5e7eb !important;
}

.practice-actions button.ghost:hover, a.button.ghost:hover {
  background: #f9fafb !important;
  border-color: #d1d5db !important;
}

