:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --bg: #f8fafc;
  --card: #ffffff;
  --text: #1e293b;
  --muted: #64748b;
  --border: #e2e8f0;
  --success: #16a34a;
  --danger: #dc2626;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Sans", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
}

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

.container { max-width: 960px; margin: 0 auto; padding: 1rem; }
.container-narrow { max-width: 480px; margin: 0 auto; padding: 1rem; }

.navbar {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 0.75rem 1rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem 0.75rem;
}

.navbar-brand {
  font-weight: 700;
  color: var(--text);
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  min-width: 0;
}

.navbar-brand-link {
  display: inline-flex;
  align-items: center;
  cursor: pointer;
}

.brand-mark {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  color: inherit;
  line-height: 1;
  white-space: nowrap;
}

.brand-logo {
  width: 1.75rem;
  height: 1.75rem;
  display: block;
  flex: 0 0 auto;
  border-radius: 0.5rem;
  box-shadow: 0 6px 14px rgba(37, 99, 235, 0.18);
}

.brand-name {
  line-height: 1;
  letter-spacing: 0.01em;
}

.navbar-brand-subtitle {
  font-weight: 400;
  color: var(--muted);
}

.navbar-menus {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-left: auto;
  flex-wrap: wrap;
  justify-content: flex-end;
  min-width: 0;
}

.navbar-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.navbar-user-menu {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}

.navbar-menus .navbar-user-menu {
  border-left: 1px solid var(--border);
  padding-left: 0.5rem;
}

.navbar > .navbar-user-menu,
.navbar > .navbar-menus {
  margin-left: auto;
}

.navbar-user {
  font-size: 0.9rem;
  color: var(--muted);
  white-space: nowrap;
}

.meeting-scope-bar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.meeting-scope-select {
  width: auto;
  min-width: 15rem;
  background: var(--card);
  font-weight: 600;
}

.meeting-scope-bar select.meeting-scope-select {
  height: 2.5rem;
}

.meeting-scope-qr-button,
.meeting-scope-settings-button {
  height: 2.5rem;
  padding-top: 0;
  padding-bottom: 0;
}

.scope-message-dialog {
  width: min(92vw, 28rem);
  max-width: none;
  margin: auto;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--card);
  box-shadow: 0 16px 40px rgba(15, 23, 42, 0.18);
}

.scope-message-dialog::backdrop {
  background: rgba(15, 23, 42, 0.48);
}

.scope-message-dialog-card {
  padding: 1.25rem;
}

.course-scope-row {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.5rem;
  margin: 1rem 0 1.25rem;
}

.course-scope-row--controls-only {
  gap: 0;
}

.page-header-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

.course-scope-controls {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  min-width: 0;
}

.course-scope-ai {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.card-toolbar {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.card-header-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.card-header-row--stacked {
  align-items: flex-start;
}

.card-header-row .card-toolbar {
  margin-left: auto;
}

.page-back-link {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  margin: 0 0 0.75rem;
  padding: 0.4rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card);
  color: var(--text);
  font-size: 0.9rem;
  font-weight: 700;
  text-decoration: none;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.06);
}

.page-back-link:hover {
  color: var(--primary);
  border-color: #bfdbfe;
  background: #eff6ff;
  text-decoration: none;
}

.table th.col-actions,
.table td.col-actions {
  text-align: right;
  white-space: nowrap;
}

.chat-navbar .navbar-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}

.chat-navbar {
  padding: 0.55rem 0.75rem 0.65rem;
}

.chat-navbar .navbar-meta {
  font-size: 0.9rem;
  color: var(--muted);
  white-space: nowrap;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.5rem;
  margin-bottom: 1rem;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  padding: 0.625rem 1rem;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  font-size: 0.95rem;
  text-decoration: none;
  line-height: 1.2;
}

.icon {
  flex-shrink: 0;
  stroke-width: 2;
}

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); text-decoration: none; color: #fff; }
.btn-secondary { background: #e2e8f0; color: var(--text); }
.btn-success { background: var(--success); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-sm { padding: 0.4rem 0.7rem; font-size: 0.85rem; }
.btn:disabled,
.btn[disabled] {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-text {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.2rem 0.35rem;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.8rem;
  text-decoration: none;
  line-height: 1.2;
}

.btn-text:hover {
  color: var(--danger);
  text-decoration: underline;
  background: transparent;
}

.btn-text-disabled,
.btn-text:disabled {
  color: #cbd5e1;
  cursor: not-allowed;
  opacity: 0.7;
  text-decoration: none;
}

.btn-text-disabled:hover,
.btn-text:disabled:hover {
  color: #cbd5e1;
  text-decoration: none;
}

.form-group { margin-bottom: 1rem; }
.form-subsection-title {
  margin: 1.5rem 0 0.75rem;
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
}
.form-subsection-title:first-of-type {
  margin-top: 1.25rem;
}
.form-group label { display: block; font-weight: 600; margin-bottom: 0.25rem; }
.form-group input:not([type="checkbox"]):not([type="radio"]),
.form-group textarea,
.form-group select,
select.form-control {
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 1rem;
}
.checkbox-row {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
}
.checkbox-row input[type="checkbox"] {
  width: 1rem;
  height: 1rem;
  margin: 0.15rem 0 0;
  flex-shrink: 0;
}
.checkbox-row label {
  display: inline;
  font-weight: normal;
  margin-bottom: 0;
  line-height: 1.5;
}

.form-group--locked,
.form-group--locked label,
.form-group--locked ul {
  color: var(--muted);
}

.form-group--locked input[type="radio"] {
  cursor: not-allowed;
}

.form-group--locked li label {
  font-weight: normal;
  cursor: not-allowed;
}

.form-footer-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  margin-top: 1rem;
}

.form-footer-row form {
  margin: 0;
}

.filters-form {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  align-items: center;
}

.filters-form input,
.filters-form select {
  min-height: 2rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.35rem 0.55rem;
}

.admin-search-form input[type="search"] {
  flex: 1 1 32rem;
  min-width: min(100%, 32rem);
  min-height: 2.5rem;
  font-size: 1rem;
  padding: 0.5rem 0.75rem;
}

select.form-control { width: auto; }
.help-text { color: var(--muted); font-size: 0.85rem; margin-top: 0.25rem; }
.readonly-notice {
  margin: 0.75rem 0 1rem;
  padding: 0.75rem 1rem;
  border-radius: 0.5rem;
  background: #fef3c7;
  color: #92400e;
  font-size: 0.9rem;
}
.form-error { color: var(--danger); font-size: 0.875rem; }

.alert { padding: 0.75rem 1rem; border-radius: 8px; margin-bottom: 1rem; }
.alert-info { background: #eff6ff; border: 1px solid #bfdbfe; }
.alert-warning { background: #fffbeb; border: 1px solid #fde68a; }

.badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  font-size: 0.75rem;
  background: #e2e8f0;
}

.badge-enhanced {
  background: #dbeafe;
  color: #1d4ed8;
  font-weight: 600;
}

.quiz-status-badge {
  background: #dcfce7;
  color: #166534;
  margin-right: 0.35rem;
}

.quiz-status-text {
  color: var(--muted);
  font-size: 0.85rem;
  margin-right: 0.35rem;
}

.quiz-status-empty {
  color: var(--muted);
  font-size: 0.85rem;
}

.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 0.5rem; border-bottom: 1px solid var(--border); text-align: left; }

.operation-log-detail-row td {
  background: #f8fafc;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
}

.operation-log-detail-content {
  font-size: 0.9rem;
  word-break: break-all;
}

.operation-log-detail-block {
  margin-top: 0.35rem;
}

.operation-log-detail-content ul {
  margin: 0.25rem 0 0 1rem;
  padding: 0;
}

.operation-log-detail-toggle {
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.operation-log-detail-chevron {
  transition: transform 0.15s ease;
}

.operation-log-detail-toggle[aria-expanded="true"] .operation-log-detail-chevron {
  transform: rotate(90deg);
}

.table-wrap {
  margin-top: 1rem;
}

.table-scroll-5 {
  --table-scroll-row-height: 3.25rem;
  --table-scroll-header-height: 2.75rem;
  max-height: calc(var(--table-scroll-header-height) + var(--table-scroll-row-height) * 5);
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
}

.table-scroll-5 .table {
  margin: 0;
}

.table-scroll-5 thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #fff;
  box-shadow: 0 1px 0 var(--border);
}

.table-scroll-5 tbody tr:last-child td {
  border-bottom: none;
}

.material-list {
  margin: 0.5rem 0 1rem;
  padding-left: 1.25rem;
}

.material-list li {
  margin: 0.25rem 0;
}

.qr-box { text-align: center; padding: 1rem; }
.qr-box img { max-width: 240px; border: 1px solid var(--border); border-radius: 8px; }

.qr-dialog {
  width: 100vw;
  max-width: none;
  height: 100vh;
  max-height: none;
  margin: 0;
  padding: 0;
  border: none;
  border-radius: 0;
  background: transparent;
}

.qr-dialog::backdrop {
  background: rgba(15, 23, 42, 0.48);
}

.qr-dialog-card {
  background: var(--card);
  min-height: 100vh;
  border-radius: 0;
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  box-shadow: none;
}

.qr-dialog-header {
  position: relative;
}

.qr-dialog-title-block {
  width: 100%;
  text-align: center;
}

.qr-dialog .qr-page-close {
  position: absolute;
  right: 0;
  top: 0;
}

.qr-dialog .qr-box {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.qr-dialog .qr-box-lg img {
  max-width: min(72vmin, 720px);
  max-height: 72vh;
}

.qr-dialog .qr-page-title {
  margin-bottom: 0.25rem;
}

.qr-dialog .qr-page-title + .qr-page-title,
.qr-page > .qr-page-title + .qr-page-title {
  margin-top: 0;
}

.qr-dialog .qr-page-url {
  margin-top: 0.5rem;
  text-align: center;
}

.qr-page {
  max-width: 640px;
  margin-top: 2rem;
  text-align: center;
}

.qr-page-close {
  flex-shrink: 0;
  border-radius: 999px;
}

.qr-page-label {
  margin: 0 0 0.25rem;
  color: var(--muted);
  font-size: 0.95rem;
}

.qr-page-title {
  margin: 0 0 1.5rem;
  font-size: 1.75rem;
}

.qr-box-lg img {
  max-width: min(360px, 80vw);
}

.qr-page-url {
  margin-top: 1.5rem;
  font-size: 0.85rem;
  word-break: break-all;
}

/* Chat UI */
.chat-page {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
}

.chat-page-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  max-width: none;
  width: 100%;
  margin: 0;
  padding: 0;
}

.chat-page-title {
  padding: 0.65rem 1rem;
  border-bottom: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.9rem;
  background: var(--card);
}

.chat-page .chat-card {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  margin-bottom: 0;
  padding: 0;
  overflow: hidden;
  border-radius: 0;
  border-left: none;
  border-right: none;
}

.chat-container {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  height: auto;
  max-height: none;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 0.85rem 1rem 1.1rem 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 1.1rem;
}

.chat-row {
  display: flex;
  align-items: flex-end;
  gap: 0.25rem;
  max-width: 100%;
  overflow: visible;
}

.chat-row.user {
  align-self: flex-end;
  align-items: flex-end;
  gap: 0.35rem;
  padding-right: 0.15rem;
}

.chat-row.user .chat-avatar {
  margin-bottom: 0.9rem;
}

.chat-row.assistant {
  align-self: flex-start;
  align-items: flex-start;
  gap: 0.35rem;
}

.chat-avatar {
  width: 2.25rem;
  height: 2.25rem;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  border: 1px solid var(--border);
}

.chat-avatar.assistant {
  background: #eef2ff;
  color: #4338ca;
}

.chat-avatar.user {
  background: #dbeafe;
  color: var(--primary);
}

.chat-bubble-body {
  max-width: min(88%, calc(100% - 2.5rem));
  min-width: auto;
  width: fit-content;
  flex-shrink: 0;
  overflow: visible;
}

.chat-row.assistant .chat-bubble-body {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.1rem;
}

.chat-row.user .chat-bubble-body {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.25rem;
}

.chat-bubble {
  position: relative;
  display: inline-flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.15rem;
  padding: 0.65rem 0.95rem;
  border-radius: 6px;
  line-height: 1.35;
  word-break: normal;
  overflow-wrap: break-word;
  width: auto;
  max-width: 100%;
  overflow: visible;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.08);
}

.bubble-content {
  margin: 0;
  padding: 0;
  line-height: 1.35;
  white-space: pre-line;
}

.thinking-indicator {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  color: var(--muted);
  white-space: nowrap;
}

.chat-error-message {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  color: var(--text);
}

.chat-error-detail {
  flex-basis: 100%;
  color: var(--muted);
  font-size: 0.8rem;
}

.chat-bubble[data-local-error="true"] {
  padding-right: 3rem;
}

.chat-retry-button {
  position: absolute;
  right: 0.55rem;
  bottom: 0.45rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.65rem;
  height: 1.65rem;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--card);
  color: var(--primary);
  cursor: pointer;
}

.chat-retry-button:hover {
  border-color: var(--primary);
  background: #eff6ff;
  color: var(--primary-dark);
}

.thinking-dots {
  display: inline-flex;
  align-items: center;
  gap: 0.18rem;
  padding-left: 0.05rem;
}

.thinking-dots span {
  width: 0.28rem;
  height: 0.28rem;
  border-radius: 999px;
  background: currentColor;
  opacity: 0.35;
  animation: thinking-dot 1s ease-in-out infinite;
}

.thinking-dots span:nth-child(2) {
  animation-delay: 0.15s;
}

.thinking-dots span:nth-child(3) {
  animation-delay: 0.3s;
}

.generating-dots {
  margin-left: 0.25rem;
  color: var(--muted);
  vertical-align: middle;
}

@keyframes thinking-dot {
  0%,
  80%,
  100% {
    transform: translateY(0);
    opacity: 0.35;
  }
  40% {
    transform: translateY(-0.18rem);
    opacity: 0.9;
  }
}

.chat-row.user .chat-bubble {
  display: inline-flex;
  flex-direction: column;
  align-items: flex-start;
  width: auto;
  background: var(--primary);
  color: #fff;
  padding: 0.65rem 0.95rem;
  border-bottom-right-radius: 6px;
}

.chat-row.user .chat-bubble.has-image {
  width: fit-content;
  max-width: fit-content;
}

.chat-row.user .bubble-content {
  white-space: normal;
  word-break: normal;
  overflow-wrap: break-word;
}

.chat-bubble .rich-markdown,
.chat-bubble .chat-markdown {
  word-break: break-word;
  overflow-wrap: anywhere;
}

.chat-bubble .citations {
  margin-top: 0.35rem;
}

.chat-message-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  width: 100%;
  margin-top: 0.25rem;
  flex-wrap: nowrap;
}

.chat-row.assistant .chat-message-footer {
  width: 100%;
  min-width: 7rem;
  max-width: 100%;
  justify-content: space-between;
}

.chat-message-footer .feedback-btns {
  flex-shrink: 0;
  flex-wrap: nowrap;
  justify-content: flex-start;
}

.chat-message-time {
  width: auto;
  color: var(--muted);
  font-size: 0.72rem;
  line-height: 1.1;
  white-space: nowrap;
}

.chat-message-meta {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.45rem;
  margin-left: auto;
  white-space: nowrap;
  min-width: 0;
}

.chat-row.assistant .chat-message-meta {
  margin-left: auto;
  justify-content: flex-end;
}

.chat-row.user .chat-message-time {
  width: 100%;
  min-width: 7rem;
  text-align: left;
  padding-left: 0.15rem;
}

.chat-row.assistant .chat-message-time {
  text-align: right;
}

.chat-message-footer .verify-badge {
  margin: 0;
}

.chat-bubble .chat-image {
  margin-bottom: 0.15rem;
}

.chat-row.user .chat-bubble::before {
  content: "";
  position: absolute;
  right: -4px;
  bottom: 0.8rem;
  width: 8px;
  height: 8px;
  background: var(--primary);
  transform: rotate(45deg);
  border-radius: 0 0 2px 0;
  z-index: 1;
}

.chat-row.assistant .chat-bubble {
  background: #f1f5f9;
}

.chat-row.assistant .chat-bubble.is-processing {
  opacity: 0.62;
}

.chat-row.assistant .chat-bubble::before {
  content: "";
  position: absolute;
  left: -4px;
  top: 0.85rem;
  width: 8px;
  height: 8px;
  background: #f1f5f9;
  transform: rotate(45deg);
  border-radius: 0 0 0 2px;
  z-index: 1;
}

.chat-input-area {
  border-top: 1px solid var(--border);
  padding: 0.6rem 1rem 0.55rem 0.75rem;
  background: var(--card);
  display: flex;
  gap: 0.5rem;
  align-items: flex-start;
}

.chat-input-tools {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  align-self: flex-end;
  flex-shrink: 0;
  height: 5.4rem;
}

.chat-input-tools .btn-icon-only {
  flex: 1 1 0;
  min-height: 0;
  height: auto;
  padding: 0;
}

.chat-input-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  min-width: 0;
  min-height: 0;
}

.question-suggestions {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  flex-wrap: wrap;
  padding: 0.75rem 1rem 0.55rem;
  border-top: 1px solid var(--border);
  background: var(--card);
}

.question-suggestions[hidden] {
  display: none;
}

.question-suggestions button {
  border: 1px solid var(--border);
  border-radius: 999px;
  background: #f8fafc;
  color: var(--text);
  padding: 0.28rem 0.65rem;
  font-size: 0.8rem;
  line-height: 1.2;
  cursor: pointer;
}

.question-suggestions button:hover {
  border-color: var(--primary);
  background: #eff6ff;
  color: var(--primary-dark);
}

.chat-input-actions {
  display: flex;
  align-items: stretch;
  align-self: flex-end;
  flex-shrink: 0;
}

.btn-icon-only {
  padding: 0.6rem;
  min-width: 2.6rem;
}

.btn-icon-only.is-recording {
  border-color: #ef4444;
  background: #fef2f2;
  color: #dc2626;
}

.image-preview {
  position: relative;
  display: inline-block;
  max-width: 160px;
}

.image-preview[hidden] {
  display: none !important;
}

.image-preview img {
  display: block;
  max-width: 160px;
  max-height: 120px;
  border-radius: 8px;
  border: 1px solid var(--border);
}

.image-preview img:not([src]),
.image-preview img[src=""] {
  display: none;
}

.image-preview-clear {
  position: absolute;
  top: -0.35rem;
  right: -0.35rem;
  width: 1.25rem;
  height: 1.25rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--card);
  cursor: pointer;
  line-height: 1;
  font-size: 0.85rem;
}

.chat-image {
  display: block;
  max-width: min(280px, 78vw);
  max-height: 220px;
  border-radius: 6px;
  margin-bottom: 0.35rem;
}

.chat-input-area textarea {
  flex: 1 1 auto;
  width: 100%;
  min-height: 5.4rem;
  height: 100%;
  resize: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.5rem;
  font-size: 1rem;
  line-height: 1.4;
  box-sizing: border-box;
}

.chat-input-actions .btn {
  height: 5.4rem;
  min-height: 5.4rem;
}

.feedback-btns {
  display: flex;
  gap: 0.25rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}
.feedback-btns button {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: #fff;
  cursor: pointer;
  font-size: 0.75rem;
  color: var(--muted);
}
.feedback-btns button.active-satisfied { background: #dcfce7; border-color: var(--success); }
.feedback-btns button.active-unsatisfied { background: #fee2e2; border-color: var(--danger); }

.terms-box {
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem;
  max-height: 200px;
  overflow-y: auto;
  font-size: 0.9rem;
  white-space: pre-wrap;
}

.analysis-result {
  white-space: normal;
  background: #f8fafc;
  padding: 1rem;
  border-radius: 8px;
  border: 1px solid var(--border);
}

.analysis-result.rich-markdown h2,
.analysis-result.chat-markdown h2 {
  font-size: 1.15rem;
  font-weight: 600;
  margin: 1.1rem 0 0.4rem;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0.25rem;
}

.analysis-result.rich-markdown h3,
.analysis-result.chat-markdown h3 {
  font-size: 1.05rem;
  font-weight: 600;
  margin: 1rem 0 0.35rem;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0.25rem;
}

.analysis-result.rich-markdown h4 {
  font-size: 0.95rem;
  font-weight: 600;
  margin: 0.75rem 0 0.25rem;
}

.analysis-result.rich-markdown > :first-child {
  margin-top: 0;
}

.analysis-result.rich-markdown > ul,
.analysis-result.rich-markdown > ol,
.analysis-result.chat-markdown > ul,
.analysis-result.chat-markdown > ol {
  padding-left: 1.1rem;
  margin: 0.5rem 0 0.85rem;
}

.analysis-result.rich-markdown > ul > li,
.analysis-result.chat-markdown > ul > li {
  margin-bottom: 0.85rem;
}

.analysis-result.rich-markdown ul ul,
.analysis-result.chat-markdown ul ul {
  margin: 0.35rem 0 0;
  padding-left: 1.25rem;
}

.analysis-result.rich-markdown ul ul > li,
.analysis-result.chat-markdown ul ul > li {
  margin-bottom: 0.3rem;
  list-style-type: circle;
}

.analysis-result.rich-markdown li > p {
  margin: 0.15rem 0;
}

.analysis-result.rich-markdown li > strong {
  font-weight: 600;
}

.analysis-empty {
  color: var(--muted);
  font-size: 0.95rem;
  margin: 0;
  padding: 1rem 0;
  text-align: center;
}

.analysis-running-banner {
  margin: 0.75rem 0 0;
  padding: 0.75rem 1rem;
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  border-radius: 8px;
}

.analysis-running-banner-body {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  color: #1e40af;
  font-size: 0.9rem;
}

.overall-analysis-stale-alert {
  margin-top: 0.75rem;
  margin-bottom: 0;
}

.analysis-meta-note {
  color: var(--muted);
  font-size: 0.9em;
}

.analysis-pending-card .analysis-running-banner-body {
  margin-top: 0.75rem;
}

.analysis-status-badge {
  margin-left: 0.35rem;
  background: #fef3c7;
  color: #92400e;
}

.analysis-status-badge--failed {
  background: #fee2e2;
  color: #991b1b;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 1rem;
  margin-bottom: 1rem;
}

.stat-box {
  text-align: center;
  padding: 1rem;
  background: #f8fafc;
  border-radius: 8px;
  border: 1px solid var(--border);
}

.stat-box-button {
  width: 100%;
  cursor: pointer;
  font: inherit;
  color: inherit;
}

.stat-box-button:hover,
.stat-box-button[aria-expanded="true"] {
  border-color: var(--primary);
  background: #eff6ff;
}

.stat-value { font-size: 1.5rem; font-weight: 700; }
.stat-label { font-size: 0.85rem; color: var(--muted); }

.follow-up-panel {
  margin-top: 1rem;
  padding: 1rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #f8fafc;
}

.follow-up-panel[hidden] {
  display: none;
}

.follow-up-panel h3 {
  margin: 0 0 0.25rem;
  font-size: 1rem;
}

.follow-up-help,
.follow-up-empty {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.follow-up-list {
  margin: 0.75rem 0 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.follow-up-list li {
  padding: 0;
  border: none;
  border-radius: 0;
  background: transparent;
}

.follow-up-meta {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  flex-wrap: wrap;
  color: var(--muted);
  font-size: 0.85rem;
}

.follow-up-reason {
  background: #fef3c7;
  color: #92400e;
}

.follow-up-question {
  margin: 0.35rem 0 0.25rem;
  font-weight: 600;
}

.charts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 1.25rem;
  margin-top: 1rem;
}

.chart-card {
  padding: 1rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fafbfc;
}

.chart-card h3 {
  margin: 0 0 0.75rem;
  font-size: 0.95rem;
  font-weight: 600;
}

.chart-card canvas {
  width: 100% !important;
  max-height: 280px;
}

.chart-empty {
  color: var(--muted);
  font-size: 0.9rem;
  margin: 0;
  padding: 2rem 0;
  text-align: center;
}

.citations {
  margin-top: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
}

.citation-tag {
  display: inline-block;
  font-size: 0.75rem;
  padding: 0.15rem 0.5rem;
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  border-radius: 999px;
  color: #1e40af;
}

.chat-bubble.assistant .citations .citation-tag {
  background: #e2e8f0;
  border-color: #cbd5e1;
  color: #334155;
}

.quiz-question { margin-bottom: 1rem; }
.quiz-correct { border-left: 4px solid var(--success); }
.quiz-wrong { border-left: 4px solid var(--danger); }
.quiz-choices { list-style: none; padding: 0; margin: 0; }
.quiz-choices li { padding: 0.5rem 0.75rem; margin-bottom: 0.25rem; border-radius: 6px; }
.choice-correct { background: #dcfce7; }
.choice-selected-wrong { background: #fee2e2; }
.quiz-choices-form { display: flex; flex-direction: column; gap: 0.5rem; }
.quiz-choice-label {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  padding: 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
}
.quiz-choice-label:has(input:checked) { border-color: var(--primary); }
.quiz-choice-label-readonly {
  display: grid;
  grid-template-columns: auto 1fr;
  column-gap: 0.625rem;
  align-items: start;
  cursor: default;
  pointer-events: none;
}
.quiz-choice-label-readonly:has(input:checked) {
  border-color: var(--border);
}
.quiz-choice-label-readonly.choice-correct {
  border-color: #86efac;
  background: #dcfce7;
}
.quiz-choice-label-readonly.choice-correct:has(input:checked) {
  border-color: #86efac;
  background: #dcfce7;
}
.quiz-choice-body {
  display: inline;
  min-width: 0;
  line-height: 1.5;
}
.quiz-choice-text {
  display: inline;
}
.quiz-choice-result {
  display: inline;
  font-weight: 700;
  margin-left: 0.35rem;
  line-height: inherit;
  vertical-align: baseline;
}
.quiz-choice-result-correct {
  color: var(--success);
}
.quiz-choice-result-wrong {
  color: var(--danger);
}
.quiz-choice-label-readonly input[type="radio"] {
  accent-color: #64748b;
  width: 1rem;
  height: 1rem;
  margin: 0.1875rem 0 0;
}
.verify-badge {
  font-size: 0.75rem;
  margin-top: 0;
  color: var(--muted);
}
.verify-badge.verify-checking,
.verify-badge.verify-correcting {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}
.verify-badge.verify-checking {
  color: #6366f1;
}

.verify-badge .generating-dots {
  margin-left: 0;
  color: currentColor;
}

.verify-badge.verify-correcting { color: #d97706; }

.page-loader {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(248, 250, 252, 0.85);
  backdrop-filter: blur(2px);
}
.page-loader[hidden] {
  display: none;
}
.page-loader-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 1.25rem;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.08);
}
.page-loader-spinner {
  width: 2rem;
  height: 2rem;
  border: 3px solid #dbeafe;
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: page-loader-spin 0.8s linear infinite;
}

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

.overall-analysis-loading-body {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 1.5rem 0 0.5rem;
  text-align: center;
}

.overall-analysis-panel .analysis-section {
  margin-top: 1.5rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
}

.analysis-meta {
  margin: 0.35rem 0 0;
  color: var(--muted);
}

.card-header-row .analysis-meta {
  margin-bottom: 0;
}

.verify-badge.verify-ok { color: var(--success); }
.verify-badge.verify-error { color: var(--muted); }
.verify-badge.verify-failed { color: var(--danger); }

.verification-audit-panel {
  margin-top: 0.55rem;
  padding: 0.65rem 0.8rem;
  border: 1px solid #fde68a;
  border-radius: 10px;
  background: #fffbeb;
  color: var(--text);
  font-size: 0.88rem;
}

.verification-audit-panel summary {
  cursor: pointer;
  font-weight: 600;
  color: #92400e;
}

.verification-audit-section {
  margin-top: 0.6rem;
}

.verification-audit-label {
  margin-bottom: 0.2rem;
  font-weight: 600;
  color: #92400e;
}

.trace-duration {
  margin-left: 0.35rem;
  font-weight: 500;
  font-size: 0.85em;
  color: #6b7280;
}

.trace-step-badge {
  margin-left: 0.45rem;
  padding: 0.08rem 0.45rem;
  border-radius: 999px;
  font-size: 0.78em;
  font-weight: 600;
  vertical-align: middle;
}

.trace-step-badge-error {
  color: #991b1b;
  background: #fee2e2;
  border: 1px solid #fecaca;
}

.trace-step-badge-warning {
  color: #92400e;
  background: #fef3c7;
  border: 1px solid #fde68a;
}

.trace-step-badge-fallback {
  color: #9a3412;
  background: #ffedd5;
  border: 1px solid #fed7aa;
}

.trace-step-badge-failed {
  color: #991b1b;
  background: #fee2e2;
  border: 1px solid #fecaca;
}

.verification-audit-content {
  white-space: pre-wrap;
  color: var(--text);
}

.chat-meta-panel .verification-audit-section .verification-audit-section {
  padding: 0.45rem 0.6rem;
  border-left: 3px solid #e5e7eb;
  background: rgba(255, 255, 255, 0.55);
}

.chat-meta-inline {
  margin-left: 0.35rem;
  color: var(--muted);
  font-weight: 500;
}

.chat-ai-inline {
  display: inline-flex;
  align-items: center;
  gap: 0.15rem;
  margin-left: 0.35rem;
  color: #9ca3af;
  font-size: 0.78rem;
  font-weight: 400;
}

.verification-audit-list {
  margin: 0.25rem 0 0;
  padding-left: 1.2rem;
}

.chat-prompt-panel {
  border-color: #e5e7eb;
  background: #f9fafb;
}

.chat-prompt-panel summary {
  color: #374151;
}

.chat-prompt-panel .verification-audit-label {
  color: #374151;
}

.trace-prompt-panel {
  margin-top: 0.45rem;
  margin-left: 0.35rem;
  padding: 0.45rem 0.55rem;
  border: 1px dashed #e5e7eb;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.6);
}

.trace-prompt-panel > summary {
  cursor: pointer;
  font-weight: 600;
  font-size: 0.82rem;
  color: #6b7280;
}

.prompt-log-blocks {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  margin-top: 0.35rem;
}

.prompt-log-block {
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  overflow: hidden;
  background: #f9fafb;
}

.prompt-log-block-label {
  padding: 0.3rem 0.6rem;
  background: #f3f4f6;
  border-bottom: 1px solid #e5e7eb;
  font-size: 0.78rem;
  font-weight: 600;
  color: #6b7280;
}

.prompt-log-block-content {
  margin: 0;
  padding: 0.55rem 0.65rem;
  background: #f9fafb;
  color: var(--text);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.78rem;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 20rem;
  overflow: auto;
}

.chat-meta-panel .trace-prompt-panel .prompt-log-section summary {
  color: #6b7280;
}

.prompt-log-entry + .prompt-log-entry {
  margin-top: 0.75rem;
  padding-top: 0.75rem;
  border-top: 1px dashed #e5e7eb;
}

.prompt-log-section {
  margin-top: 0.35rem;
  margin-left: 0.35rem;
}

.prompt-log-section summary {
  cursor: pointer;
  font-weight: 500;
  font-size: 0.85rem;
  color: #4b5563;
}

.prompt-log-content {
  margin: 0.35rem 0 0;
  padding: 0.55rem 0.65rem;
  border-radius: 8px;
  border: 1px solid #e5e7eb;
  background: #fff;
  color: var(--text);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.78rem;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 24rem;
  overflow: auto;
}

.chat-meta-panel {
  padding: 0.35rem 0.8rem;
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 0.82rem;
}

.chat-meta-panel summary {
  color: var(--muted);
  font-weight: 500;
}

.chat-meta-panel .verification-audit-label {
  color: var(--muted);
}

.chat-meta-panel .verification-audit-content {
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.5;
}

.chat-meta-panel .verification-audit-content.chat-markdown h1,
.chat-meta-panel .verification-audit-content.chat-markdown h2,
.chat-meta-panel .verification-audit-content.chat-markdown h3,
.chat-meta-panel .verification-audit-content.chat-markdown h4,
.chat-meta-panel .verification-audit-content.chat-markdown p,
.chat-meta-panel .verification-audit-content.chat-markdown li,
.chat-meta-panel .verification-audit-content.chat-markdown th,
.chat-meta-panel .verification-audit-content.chat-markdown td,
.chat-meta-panel .verification-audit-content.chat-markdown pre,
.chat-meta-panel .verification-audit-content.chat-markdown code {
  font-size: inherit;
}

.chat-meta-panel .verification-audit-content.chat-markdown h1,
.chat-meta-panel .verification-audit-content.chat-markdown h2,
.chat-meta-panel .verification-audit-content.chat-markdown h3,
.chat-meta-panel .verification-audit-content.chat-markdown h4 {
  font-weight: 600;
  margin: 0.35rem 0 0.2rem;
}

.chat-meta-panel .verification-audit-content.chat-markdown table {
  font-size: inherit;
}

.verification-audit-content-indented {
  margin-left: 1.2rem;
}

.chat-meta-subtitle {
  margin-top: 0.4rem;
  color: var(--muted);
  font-weight: 600;
}

.chat-log-heading {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  flex-wrap: wrap;
}

.chat-log-heading span {
  color: var(--muted);
  font-size: 0.85rem;
}

.chat-log-heading .chat-context-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
  padding: 0.12rem 0.45rem;
  border-radius: 999px;
  background: #f3f4f6;
  color: #4b5563;
  font-size: 0.75rem;
  font-weight: 600;
  line-height: 1.3;
}

.chat-log-heading .chat-log-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
  padding: 0.12rem 0.45rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  line-height: 1.3;
}

.chat-log-badge-error {
  background: #fee2e2;
  color: #b91c1c;
}

.chat-log-badge-system {
  background: #e5e7eb;
  color: #4b5563;
}

.chat-log-badge-outside {
  background: #ffedd5;
  color: #c2410c;
}

.chat-log-badge-review {
  background: #fee2e2;
  color: #b91c1c;
}

.chat-log-badge-reason {
  background: #f8fafc;
  color: #64748b;
  font-weight: 500;
}

.chat-log-badge-verify-error {
  background: #f3f4f6;
  color: #4b5563;
}

.chat-log-badge-corrected {
  background: #fef3c7;
  color: #b45309;
}

.chat-log-badge-pending {
  background: #e0e7ff;
  color: #4338ca;
}

.chat-log-card {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.chat-log-card .chat-bubble {
  box-shadow: none;
}

.chat-log-pair {
  border: 1px solid #e5e7eb;
  border-radius: 0.75rem;
  background: #fafafa;
  overflow: hidden;
  scroll-margin-top: 5rem;
}

.chat-log-pair-pending {
  border-color: #c7d2fe;
  background: #f8faff;
}

.chat-log-pair-header {
  display: flex;
  align-items: baseline;
  gap: 0.65rem;
  padding: 0.55rem 0.9rem;
  border-bottom: 1px solid #e5e7eb;
  background: rgba(255, 255, 255, 0.72);
}

.chat-log-pair-number {
  flex: 0 0 auto;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: #6b7280;
}

.chat-log-pair-preview {
  font-size: 0.88rem;
  color: #374151;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-log-pair-body {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.chat-log-pair-body .chat-log-entry {
  margin-bottom: 0;
  padding: 0.85rem 0.9rem 0.75rem;
}

.chat-log-pair-body .chat-log-entry-user {
  border-bottom: 1px dashed #e5e7eb;
  background: rgba(239, 246, 255, 0.45);
}

.chat-log-pair-body .chat-log-entry-assistant {
  background: rgba(255, 255, 255, 0.55);
}

.chat-log-question-text {
  white-space: pre-wrap;
}

.chat-log-feedback {
  font-size: 0.85rem;
  color: var(--muted);
}

.chat-log-pair-waiting {
  padding: 0.85rem 0.9rem;
  font-size: 0.9rem;
  color: var(--muted);
  font-style: italic;
}

.chat-log-entry {
  scroll-margin-top: 5rem;
}

.chat-log-entry-deleted {
  opacity: 0.72;
}

.chat-log-badge-deleted {
  background: #f3f4f6;
  color: #6b7280;
}

.chat-log-deleted-note {
  margin: 0.35rem 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.chat-log-entry-highlight {
  --chat-log-jump-ring: #fb923c;
  --chat-log-jump-ring-muted: #fdba74;
  border-radius: 0.375rem;
  outline: 2px solid var(--chat-log-jump-ring-muted);
  outline-offset: 3px;
  animation: chat-log-jump-pulse 2s ease-out forwards;
}

.chat-log-pair.chat-log-entry-highlight {
  --chat-log-jump-ring: #fb923c;
  --chat-log-jump-ring-muted: #fdba74;
  outline: 2px solid var(--chat-log-jump-ring-muted);
  outline-offset: 3px;
  animation: chat-log-jump-pulse 2s ease-out forwards;
}

.chat-log-pair.chat-log-entry-highlight.is-settled {
  outline-color: var(--chat-log-jump-ring-muted);
}

.chat-log-entry-highlight.is-settled {
  animation: none;
  outline-color: var(--chat-log-jump-ring-muted);
}

.chat-log-pair-highlight-overlay {
  --chat-log-jump-ring: #fb923c;
  --chat-log-jump-ring-muted: #fdba74;
  position: fixed;
  pointer-events: none;
  z-index: 20;
  border-radius: 0.5rem;
  background: transparent;
  box-shadow: 0 0 0 2px var(--chat-log-jump-ring-muted);
  animation: chat-log-pair-jump-pulse 2s ease-out forwards;
}

.chat-log-pair-highlight-overlay.is-settled {
  animation: none;
  box-shadow: 0 0 0 2px var(--chat-log-jump-ring-muted);
}

@keyframes chat-log-jump-pulse {
  0% {
    outline-color: var(--chat-log-jump-ring-muted);
    outline-width: 2px;
  }
  18% {
    outline-color: var(--chat-log-jump-ring);
    outline-width: 3px;
  }
  55% {
    outline-color: var(--chat-log-jump-ring);
    outline-width: 3px;
  }
  100% {
    outline-color: var(--chat-log-jump-ring-muted);
    outline-width: 2px;
  }
}

@keyframes chat-log-pair-jump-pulse {
  0% {
    box-shadow: 0 0 0 2px var(--chat-log-jump-ring-muted);
  }
  18% {
    box-shadow: 0 0 0 3px var(--chat-log-jump-ring);
  }
  55% {
    box-shadow: 0 0 0 3px var(--chat-log-jump-ring);
  }
  100% {
    box-shadow: 0 0 0 2px var(--chat-log-jump-ring-muted);
  }
}

.material-status-failed {
  background: #fee2e2;
  color: #b91c1c;
}

.material-status-processed {
  background: #dcfce7;
  color: #166534;
}

.material-status-pending {
  background: #fef3c7;
  color: #92400e;
}

.material-failed-summary {
  margin-bottom: 1rem;
}

.material-error-detail {
  color: var(--danger);
  font-size: 0.85rem;
  padding-top: 0;
  padding-bottom: 0.75rem;
}

.material-error-row .material-error-detail {
  padding-top: 0;
  padding-bottom: 0.75rem;
}

.material-failed-summary .material-error-detail {
  margin-top: 0.35rem;
  padding-bottom: 0;
}

.bubble-content.rich-markdown,
.chat-markdown {
  white-space: normal;
}

.chat-bubble .rich-markdown strong,
.chat-markdown strong {
  font-weight: 700;
}

.chat-bubble .rich-markdown > :first-child,
.chat-bubble .chat-markdown > :first-child {
  margin-top: 0;
}

.chat-bubble .rich-markdown > :last-child,
.chat-bubble .chat-markdown > :last-child {
  margin-bottom: 0;
}

.chat-bubble .rich-markdown p,
.chat-markdown p {
  margin: 0.35rem 0;
}

.chat-bubble .rich-markdown h2,
.chat-bubble .rich-markdown h3,
.chat-markdown h2,
.chat-markdown h3 {
  margin: 0.5rem 0 0.25rem;
  font-size: 0.95rem;
}

.chat-bubble .rich-markdown ul,
.chat-bubble .rich-markdown ol,
.chat-markdown ul,
.chat-markdown ol {
  margin: 0.25rem 0;
  padding-left: 1.1rem;
}

.chat-bubble .rich-markdown li,
.chat-markdown li {
  margin-bottom: 0.15rem;
}

.chat-bubble .rich-markdown table,
.chat-markdown table {
  width: 100%;
  border-collapse: collapse;
  margin: 0.35rem 0;
  font-size: 0.85rem;
}

.chat-bubble .rich-markdown th,
.chat-bubble .rich-markdown td,
.chat-markdown th,
.chat-markdown td {
  border: 1px solid var(--border);
  padding: 0.25rem 0.4rem;
}

.chat-bubble .rich-markdown pre,
.chat-markdown pre {
  margin: 0.35rem 0;
  padding: 0.35rem 0.5rem;
  border-radius: 6px;
  background: #e2e8f0;
  overflow-x: auto;
  font-size: 0.8rem;
}

.chat-bubble .mermaid,
.chat-markdown .mermaid {
  margin: 0.35rem 0;
  max-width: 100%;
  overflow-x: auto;
}

.chat-markdown .mermaid-fallback pre {
  margin: 0.35rem 0;
  padding: 0.75rem;
  border-radius: 6px;
  background: #f8fafc;
  border: 1px solid var(--border);
  overflow-x: auto;
  font-size: 0.8rem;
  white-space: pre-wrap;
}

.chat-markdown .katex {
  font-size: 1em;
}

.chat-markdown .katex-display {
  max-width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 0.1rem 0;
}

.rich-markdown h2 { font-size: 1.25rem; margin: 1.25rem 0 0.5rem; border-bottom: 1px solid var(--border); padding-bottom: 0.25rem; }
.rich-markdown h3 { font-size: 1.05rem; margin: 1rem 0 0.35rem; }
.rich-markdown ul, .rich-markdown ol { padding-left: 1.25rem; }
.rich-markdown li { margin-bottom: 0.35rem; }
.rich-markdown p { margin: 0.5rem 0; }
.rich-markdown table { width: 100%; border-collapse: collapse; margin: 0.75rem 0; font-size: 0.9rem; }
.rich-markdown th, .rich-markdown td { border: 1px solid var(--border); padding: 0.35rem 0.5rem; }

@media (max-width: 600px) {
  .container { padding: 0.5rem; }
  .chat-bubble-body { max-width: 90%; }
  .chat-navbar {
    flex-wrap: wrap;
    gap: 0.35rem;
  }
  .chat-navbar .navbar-actions {
    gap: 0.35rem;
  }
  .chat-navbar .navbar-meta {
    font-size: 0.75rem;
  }
}

/* Moodle 等 iframe 埋め込み（?embed=1） */
body.embed-mode {
  background: var(--card);
}
body.embed-mode .chat-page {
  min-height: 100vh;
}
body.embed-mode .chat-page-main {
  padding: 0.5rem;
}
body.embed-mode .chat-card {
  box-shadow: none;
  border: none;
  margin: 0;
}
body.embed-mode .page-loader {
  border-radius: 0;
}
