:root {
  color-scheme: light;
  --bg: #eef2f6;
  --surface: #ffffff;
  --surface-soft: #f7f9fb;
  --surface-strong: #eff3f7;
  --border: #d6dde6;
  --border-strong: #c8d1dc;
  --text: #1d2733;
  --muted: #5c6877;
  --accent: #2558d8;
  --success: #1f7a4d;
  --warning: #996a08;
  --danger: #b33c42;
  --success-soft: #e8f6ee;
  --warning-soft: #fff4da;
  --danger-soft: #fcecee;
  --radius: 8px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.05);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", Arial, sans-serif;
  font-size: 14px;
}

a {
  color: var(--accent);
  text-decoration: none;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

.workspace {
  max-width: 100%;
  padding: 10px 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.compact-workspace {
  padding-top: 8px;
}

.topbar {
  min-height: 42px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.topbar-left,
.topbar-right,
.topbar-nav,
.header-actions,
.toolbar-left,
.toolbar-right,
.filter-group,
.quick-links,
.tag-row,
.inline-tags,
.row-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.topbar-title {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
}

.topbar-link {
  display: inline-flex;
  align-items: center;
  height: 28px;
  padding: 0 10px;
  border-radius: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.topbar-link.active {
  background: var(--accent);
  color: #fff;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 10px 12px;
}

.dense-panel {
  padding: 9px 10px;
}

.panel h3,
.panel h4 {
  margin: 0;
  font-size: 14px;
}

.panel p,
.card-content,
.table-secondary,
.table-empty,
.detail-header-line,
.school-meta {
  color: var(--muted);
  line-height: 1.45;
  white-space: pre-wrap;
}

.field-label,
.section-kicker,
.eyebrow {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.section-kicker,
.eyebrow {
  margin: 0 0 4px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}

.compact-head {
  margin-bottom: 6px;
}

.toolbar {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}

.compact-toolbar {
  margin-bottom: 6px;
}

.toolbar-input,
input[type="url"] {
  height: 34px;
  padding: 0 10px;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
}

.toolbar-input {
  min-width: 260px;
}

.toolbar-input:focus,
input[type="url"]:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37, 88, 216, 0.12);
}

.analyze-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.form-row {
  display: flex;
  gap: 8px;
}

.form-row input[type="url"] {
  flex: 1;
  min-width: 0;
}

.filter-chip,
.quick-link,
.secondary-btn,
.primary-link-btn,
.danger-btn,
#submitBtn,
.table-action-button,
.table-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 30px;
  padding: 0 10px;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  font-size: 12px;
  font-weight: 700;
}

.filter-chip.active,
.primary-link-btn,
#submitBtn {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.secondary-btn {
  background: var(--surface-strong);
}

.danger-btn {
  background: var(--danger-soft);
  border-color: #f1c4c8;
  color: var(--danger);
}

.ghost-link {
  font-size: 12px;
  font-weight: 700;
  color: var(--accent);
}

.status-chip,
.result-status,
.missing-tag {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
}

.status-chip,
.result-status {
  background: var(--surface-strong);
  color: var(--muted);
}

.status-chip.success,
.result-status.success {
  background: var(--success-soft);
  color: var(--success);
}

.status-chip.warning,
.status-chip.pending,
.result-status.loading {
  background: var(--warning-soft);
  color: var(--warning);
}

.status-chip.error,
.result-status.error {
  background: var(--danger-soft);
  color: var(--danger);
}

.compact-chip {
  min-height: 22px;
}

.missing-tag {
  background: #fff3da;
  color: var(--warning);
}

.detail-header-line {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  background: var(--surface);
}

.data-table thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  padding: 8px 9px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-strong);
  color: var(--muted);
  text-align: left;
  font-size: 12px;
  font-weight: 700;
}

.data-table tbody td {
  padding: 8px 9px;
  border-bottom: 1px solid #edf1f4;
  vertical-align: top;
  word-break: break-word;
}

.data-table tbody tr:hover {
  background: #fafbfd;
}

.table-primary {
  font-weight: 700;
}

.table-secondary {
  margin-top: 3px;
  font-size: 12px;
}

.table-link {
  color: var(--accent);
}

.table-empty {
  padding: 20px 12px !important;
  text-align: center;
}

.compact-empty-row {
  padding: 6px 0;
}

.detail-top-grid,
.cards-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.info-card {
  background: var(--surface-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px;
}

.span-2 {
  grid-column: span 2;
}

.kv-list {
  display: grid;
  grid-template-columns: 92px 1fr;
  gap: 6px 10px;
  margin: 0;
}

.detail-kv {
  grid-template-columns: 80px 1fr;
}

.kv-list dt {
  color: var(--muted);
  font-weight: 700;
}

.kv-list dd {
  margin: 0;
}

.pill-list,
.source-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.pill-list {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.pill-list li {
  padding: 5px 9px;
  border-radius: 999px;
  background: #edf3ff;
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
}

.result-view {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.result-hero {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-soft);
}

.result-hero-actions,
.result-links {
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: flex-end;
}

.empty-state,
.loading-state {
  min-height: 120px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 14px;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  background: var(--surface-soft);
  text-align: center;
}

.compact-empty {
  min-height: 96px;
}

.loading-state {
  gap: 12px;
  text-align: left;
}

.spinner {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 3px solid #dbe6ff;
  border-top-color: var(--accent);
  animation: spin 0.85s linear infinite;
}

.debug-panel {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 10px;
  background: #fafbfd;
}

.debug-panel summary {
  cursor: pointer;
  font-weight: 700;
}

#debugOutput {
  margin: 8px 0 0;
  padding: 8px;
  border-radius: 6px;
  background: #122033;
  color: #dbe5f7;
  overflow: auto;
  white-space: pre-wrap;
}

.error-banner {
  padding: 8px 10px;
  border: 1px solid #f0c3c8;
  border-radius: var(--radius);
  background: #fff5f6;
  color: #8e2730;
}

.hidden {
  display: none !important;
}

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

@media (max-width: 900px) {
  .detail-top-grid,
  .cards-grid {
    grid-template-columns: 1fr;
  }

  .span-2 {
    grid-column: span 1;
  }
}

@media (max-width: 720px) {
  .workspace {
    padding: 8px;
  }

  .topbar,
  .toolbar,
  .form-row,
  .result-hero {
    flex-direction: column;
    align-items: stretch;
  }

  .toolbar-input {
    width: 100%;
    min-width: 0;
  }

  .kv-list,
  .detail-kv {
    grid-template-columns: 1fr;
  }
}

/* Chat UI Styles */
.chat-container {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 180px);
  min-height: 500px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.chat-history {
  flex: 1;
  padding: 16px;
  overflow-y: auto;
  background: var(--surface-soft);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.chat-message {
  max-width: 80%;
  display: flex;
}

.ai-message {
  align-self: flex-start;
}

.ai-message .message-content {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0 var(--radius) var(--radius) var(--radius);
}

.user-message {
  align-self: flex-end;
}

.user-message .message-content {
  background: var(--accent);
  color: white;
  border-radius: var(--radius) 0 var(--radius) var(--radius);
}

.message-content {
  padding: 10px 14px;
  line-height: 1.5;
  white-space: pre-wrap;
}

.chat-form {
  display: flex;
  padding: 12px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  gap: 8px;
}

.chat-input {
  flex: 1;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  outline: none;
}

.chat-input:focus {
  border-color: var(--accent);
}

/* Modal Styles */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal.hidden {
  display: none !important;
}

.modal-content {
  background: var(--surface);
  border-radius: var(--radius);
  width: 90%;
  max-width: 500px;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

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

.modal-header h2 {
  margin: 0;
  font-size: 16px;
}

.close-modal-btn {
  background: none;
  border: none;
  font-size: 20px;
  cursor: pointer;
  color: var(--muted);
}

.modal-body {
  padding: 16px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.notes-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.note-item {
  background: var(--surface-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px;
}

.note-item-header {
  display: flex;
  justify-content: space-between;
  margin-bottom: 6px;
  font-size: 12px;
  color: var(--muted);
}

.note-item-content {
  white-space: pre-wrap;
  word-break: break-word;
}

.note-item-content.edit-mode {
  display: none;
}

.note-edit-textarea {
  width: 100%;
  border: 1px solid var(--border-strong);
  border-radius: 4px;
  padding: 6px;
  margin-bottom: 6px;
  resize: vertical;
}

.note-actions {
  display: flex;
  gap: 6px;
  margin-top: 8px;
  justify-content: flex-end;
}

.note-action-btn {
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
  font-size: 12px;
  padding: 0;
}

.note-action-btn.delete {
  color: var(--danger);
}

.add-note-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
  border-top: 1px solid var(--border);
  padding-top: 16px;
}

.input-field {
  width: 100%;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  padding: 8px;
  resize: vertical;
}

.primary-btn {
  background: var(--accent);
  color: white;
  border: none;
  padding: 8px 16px;
  border-radius: var(--radius);
  font-weight: 700;
  cursor: pointer;
}
