/* Tab 1: Fuentes */

/* -- Buscador del corpus -------------------------------------------------- */
.corpus-search {
  padding: var(--space-xs) var(--space-sm);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: var(--space-xs);
}

.corpus-search input {
  flex: 1;
  padding: var(--space-xs) var(--space-sm);
  font-size: var(--font-size-sm);
}

.search-results {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-xs) var(--space-sm);
}

.search-results[hidden] {
  display: none;
}

.search-summary {
  font-size: var(--font-size-sm);
  color: var(--muted);
  padding: var(--space-xs) 0 var(--space-sm);
  border-bottom: 1px solid var(--border);
  margin-bottom: var(--space-sm);
}

.search-result {
  padding: var(--space-sm);
  margin-bottom: var(--space-xs);
  background: var(--surface-alt);
  border-radius: var(--radius);
  cursor: pointer;
  border-left: 3px solid var(--accent);
  transition: background 0.15s;
}

.search-result:hover {
  background: var(--mark-bg-hover);
}

.search-result-text {
  font-family: var(--font-reading);
  font-size: var(--font-size-sm);
  line-height: 1.5;
  color: var(--ink);
}

.search-result-text mark {
  background: var(--mark-bg-hover);
  color: var(--ink);
  border-radius: 2px;
  padding: 0 1px;
  font-weight: 600;
}

.search-result-source {
  font-size: 0.6875rem;
  color: var(--muted);
  margin-top: 2px;
}

/* -- Grilla Mondrian de fuentes ------------------------------------------- */
.sources-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  grid-auto-rows: 40px;
  grid-auto-flow: dense;
  gap: var(--space-xs);
  padding: var(--space-sm);
}

.source-cell {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-sm);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  overflow: hidden;
  transition: border-color var(--duration) var(--ease),
              box-shadow var(--duration) var(--ease);
}

.source-cell:hover {
  border-color: var(--accent);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
}

.source-cell.selected {
  background: color-mix(in srgb, var(--accent) 8%, var(--surface));
  border-color: var(--accent);
}

.source-cell-title {
  font-size: var(--font-size-sm);
  font-weight: 600;
  line-height: 1.3;
  color: var(--ink);
  /* Clamp to available space */
  overflow: hidden;
  display: -webkit-box;
  -webkit-box-orient: vertical;
}

.source-cell-author {
  font-size: 0.6875rem;
  color: var(--muted);
  margin-top: var(--space-xs);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.source-cell-footer {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-top: auto;
  padding-top: var(--space-xs);
}

.source-cell-year {
  font-size: 0.6875rem;
  color: var(--muted);
  font-family: var(--mono);
}

.source-cell-words {
  font-size: 0.625rem;
  color: var(--muted);
  font-family: var(--mono);
}

/* -- Ficha de fuente (columna derecha) ------------------------------------ */
.source-detail-view {
  display: flex;
  flex-direction: column;
  height: 100%;
  position: relative;
}

.source-detail-clickable {
  cursor: pointer;
  transition: background var(--duration) var(--ease);
  border-radius: var(--radius);
  padding: var(--space-lg);
  margin: calc(-1 * var(--space-md));
}

.source-detail-clickable:hover {
  background: color-mix(in srgb, var(--accent) 4%, transparent);
}

.source-detail-title {
  font-family: var(--font-reading);
  font-size: 1.25rem;
  font-weight: 600;
  line-height: 1.3;
  margin-bottom: var(--space-md);
}

.source-edit-overlay {
  position: absolute;
  top: var(--space-sm);
  right: var(--space-sm);
  opacity: 0;
  transition: opacity var(--duration) var(--ease);
  z-index: 2;
}

.source-detail-clickable:hover .source-edit-overlay {
  opacity: 0.5;
}

.source-edit-overlay:hover {
  opacity: 1 !important;
}

.source-detail-meta {
  font-size: var(--font-size-sm);
  color: var(--muted);
  margin-bottom: var(--space-lg);
  line-height: 1.6;
}

.source-detail-meta strong {
  color: var(--ink);
  font-weight: 500;
}

.source-detail-divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 0 0 var(--space-md);
}

.source-detail-section {
  margin-bottom: var(--space-lg);
}

.btn-refresh {
  opacity: 0.4;
  vertical-align: middle;
  margin-left: var(--space-xs);
  font-size: 0.875rem;
  transition: opacity 0.15s;
}

.btn-refresh:hover {
  opacity: 1;
}

.source-detail-section h3 {
  font-size: var(--font-size-sm);
  color: var(--muted);
  font-weight: 400;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: var(--space-sm);
}

.source-detail-excerpts {
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
}

.source-excerpt-item {
  font-size: var(--font-size-sm);
  padding: var(--space-xs) var(--space-sm);
  background: var(--surface-alt);
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 0.15s;
  line-height: 1.4;
}

.source-excerpt-item:hover {
  background: var(--mark-bg-hover);
}

.source-excerpt-concepts {
  font-size: 0.6875rem;
  color: var(--accent);
  margin-top: 2px;
}

.source-detail-concepts {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-xs);
}

.source-concept-tag {
  font-size: 0.75rem;
  padding: 2px var(--space-sm);
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--ink);
}

/* -- Editor inline (reemplaza ficha) -------------------------------------- */
.source-editor-view {
  display: flex;
  flex-direction: column;
  height: 100%;
  gap: var(--space-md);
}

.source-editor-fields {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
  flex-shrink: 0;
}

.source-editor-fields label {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.source-editor-fields label span {
  font-size: var(--font-size-sm);
  color: var(--muted);
  font-weight: 500;
}

.source-editor-content {
  flex: 1;
  min-height: 200px;
  font-family: var(--mono);
  font-size: 0.8125rem;
  line-height: 1.6;
  white-space: pre-wrap;
  resize: none;
  padding: var(--space-md);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
}

.source-editor-content:focus {
  outline: none;
  border-color: var(--accent);
}

.source-editor-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  padding-top: var(--space-sm);
  padding-bottom: var(--space-md);
  border-top: 1px solid var(--border);
}

.source-editor-actions-right {
  display: flex;
  gap: var(--space-sm);
}

.source-editor-wordcount {
  font-size: var(--font-size-sm);
  color: var(--muted);
  font-family: var(--mono);
}

/* -- Modal de importacion (se mantiene) ----------------------------------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.35);
  backdrop-filter: blur(2px);
}

.modal-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 90%;
  max-width: 440px;
  max-height: 90vh;
  overflow-y: auto;
  padding: var(--space-lg);
  transition: max-width 0.25s ease, max-height 0.25s ease;
}

.modal-box.modal-box-lg {
  max-width: 80vw;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
}

.modal-box.modal-box-lg .modal-form {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding-bottom: var(--space-md);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-md);
  flex-shrink: 0;
}

.modal-header h3 {
  font-size: var(--font-size-base);
  font-weight: 600;
}

.modal-form {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
}

.modal-form label {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.modal-form label span {
  font-size: var(--font-size-sm);
  color: var(--muted);
  font-weight: 500;
}

.modal-form hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: var(--space-xs) 0;
}

.modal-form-row {
  display: flex;
  gap: var(--space-sm);
  align-items: flex-end;
}

.modal-field-grow {
  flex: 1;
}

.modal-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: var(--space-md);
  padding-top: var(--space-md);
  padding-bottom: var(--space-sm);
  flex-shrink: 0;
}

.modal-box-lg .modal-actions {
  position: sticky;
  bottom: 0;
  margin: 0;
  padding: var(--space-md) 0;
  background: var(--surface);
  border-top: 1px solid var(--border);
  z-index: 1;
}

.modal-actions-right {
  display: flex;
  gap: var(--space-sm);
}

.content-editor {
  flex: 1;
  min-height: 300px;
  max-height: 60vh;
  font-family: var(--mono);
  font-size: 0.8125rem;
  line-height: 1.6;
  white-space: pre-wrap;
  resize: vertical;
  padding: var(--space-md);
}

.modal-box-lg .content-editor {
  min-height: 50vh;
}

.content-editor-toolbar {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  margin-bottom: var(--space-xs);
}

.content-word-count {
  font-size: var(--font-size-sm);
  color: var(--muted);
  margin-left: auto;
}

/* -- Boton agregar fuente ------------------------------------------------- */
.btn-add-source {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  font-size: 1.2rem;
  font-weight: 600;
  color: var(--accent);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.15s ease;
  background: transparent;
}

/* hidden attribute must win over display */
.btn-add-source[hidden] {
  display: none !important;
}

.btn-add-source:not([hidden]) {
  display: flex;
}

.btn-add-source:hover {
  background: var(--accent);
  color: white;
}
