/* ============================================================================
   CSV Source Viewer - Sheet Workspace
   ============================================================================ */

.sources-workspace {
  position: relative;
  height: 100%;
  min-height: 0;
  display: block;
  background: var(--bg);
  overflow: hidden;
}

.sources-file-sidebar {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  z-index: 30;
  width: 300px;
  transform: translateX(-104%);
  min-height: 0;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  background: var(--bg-raised);
  box-shadow: var(--shadow-lg);
  transition: transform 0.18s ease;
}

.sources-workspace.file-panel-open .sources-file-sidebar {
  transform: translateX(0);
}

.sources-drawer-scrim {
  position: absolute;
  inset: 0;
  z-index: 25;
  display: none;
  background: rgba(9, 30, 66, 0.24);
}

.sources-workspace.file-panel-open .sources-drawer-scrim {
  display: block;
}

.sources-file-sidebar-head {
  padding: 16px;
  border-bottom: 1px solid var(--border);
}

.sources-file-title {
  color: var(--text);
  font-size: 18px;
  font-weight: 750;
}

.sources-file-count {
  margin-top: 2px;
  color: var(--text-secondary);
  font-size: 12px;
}

.sources-app-tabs {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
  padding: 12px;
  border-bottom: 1px solid var(--border);
}

.sources-app-tab {
  min-height: 32px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-raised);
  color: var(--text-secondary);
  font: inherit;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}

.sources-app-tab:hover,
.sources-app-tab.active {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent-text);
}

.sources-file-search {
  margin: 12px;
  padding: 9px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-sunken);
  color: var(--text);
  font: inherit;
  outline: none;
}

.sources-file-search:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-soft);
}

.sources-file-list {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 0 8px 12px;
}

.sources-file-item {
  width: 100%;
  display: block;
  margin-bottom: 5px;
  padding: 9px 10px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: transparent;
  color: var(--text);
  text-align: left;
  cursor: pointer;
}

.sources-file-item:hover {
  background: var(--bg-sunken);
}

.sources-file-item.active {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.sources-file-name {
  display: block;
  color: var(--text);
  font-size: 12.5px;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sources-derived-warn {
  display: inline-flex;
  margin-top: 4px;
  padding: 2px 5px;
  border-radius: 4px;
  background: var(--red-soft);
  color: var(--red);
  font-size: 10px;
  font-weight: 850;
  letter-spacing: 0.02em;
}

.sources-file-meta {
  display: block;
  margin-top: 2px;
  color: var(--text-secondary);
  font-size: 11px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sources-empty-mini {
  padding: 16px 8px;
  color: var(--text-secondary);
  text-align: center;
}

.sources-sheet-main {
  height: 100%;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

.sources-catalog,
.sources-sheet {
  position: relative;
  height: 100%;
  width: 100%;
  max-width: 100%;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 18px;
}

.sources-sheet-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  flex-shrink: 0;
  gap: 16px;
  margin-bottom: 12px;
}

.sources-sheet-header h1 {
  margin: 0 0 4px;
  color: var(--text);
  font-size: 24px;
  font-weight: 750;
  overflow-wrap: anywhere;
}

.sources-sheet-header p {
  margin: 0;
  color: var(--text-secondary);
  font-size: 13px;
}

.sources-header-note {
  max-width: 360px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-raised);
  color: var(--text-secondary);
  font-family: var(--font-mono);
  font-size: 11px;
  overflow-wrap: anywhere;
}

.sources-catalog-grid {
  flex: 1;
  min-height: 0;
  overflow: auto;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  grid-auto-rows: minmax(144px, auto);
  gap: 12px;
  padding: 2px 2px 16px;
}

.sources-catalog-card {
  display: flex;
  flex-direction: column;
  min-width: 0;
  padding: 13px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-raised);
  color: var(--text);
  text-align: left;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
}

.sources-catalog-card:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.sources-catalog-card-top {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
  color: var(--text-secondary);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
}

.sources-catalog-name {
  color: var(--text);
  font-size: 15px;
  font-weight: 750;
  overflow-wrap: anywhere;
}

.sources-catalog-stats {
  margin-top: 6px;
  color: var(--text-secondary);
  font-size: 12px;
}

.sources-derived-warning {
  display: inline-flex;
  width: fit-content;
  margin-top: 7px;
  padding: 5px 7px;
  border: 1px solid var(--red);
  border-radius: var(--radius);
  background: var(--red-soft);
  color: var(--red);
  font-size: 11px;
  font-weight: 850;
  letter-spacing: 0.01em;
}

.sources-catalog-headers {
  margin-top: 10px;
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 11px;
  line-height: 1.45;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
}

.sources-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.sources-link-btn {
  min-height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 7px 11px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-raised);
  color: var(--accent-text);
  font: inherit;
  font-size: 12px;
  font-weight: 750;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
}

.sources-link-btn:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.sources-sheet-toolbar {
  flex-shrink: 0;
  display: flex;
  align-items: end;
  gap: 10px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-raised);
  margin-bottom: 12px;
}

.sources-search-wrap {
  flex: 1;
  min-width: 260px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.sources-search-wrap span {
  color: var(--text-muted);
  font-size: 10px;
  font-weight: 800;
  text-transform: uppercase;
}

.sources-search-wrap input {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-sunken);
  color: var(--text);
  font: inherit;
  outline: none;
}

.sources-search-wrap input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-soft);
}

.sources-load-state {
  min-width: 190px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-sunken);
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 700;
}

.sources-load-state.warning {
  border-color: var(--yellow);
  background: var(--yellow-soft);
  color: var(--text);
}

.sources-load-state.error {
  border-color: var(--red);
  background: var(--red-soft);
  color: var(--red);
}

.sources-sheet-layout {
  position: relative;
  flex: 1;
  width: 100%;
  max-width: 100%;
  min-height: 0;
  display: flex;
  overflow: hidden;
}

.sources-grid-pane {
  flex: 1;
  height: 100%;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-raised);
}

.sources-tabulator,
.sources-tabulator.tabulator {
  height: 100%;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  border: 0;
  background: var(--bg-raised);
  color: var(--text);
  font-family: var(--font);
  font-size: 12px;
}

.sources-tabulator .tabulator-tableholder {
  height: calc(100% - 42px) !important;
  overflow-x: auto !important;
  overflow-y: auto !important;
  scrollbar-gutter: stable both-edges;
}

.sources-tabulator .tabulator-table,
.sources-tabulator .tabulator-calcs-holder {
  min-width: max-content;
}

.sources-tabulator .tabulator-header {
  overflow-x: hidden !important;
}

.sources-tabulator .tabulator-header,
.sources-tabulator .tabulator-col {
  background: var(--bg-sunken);
  color: var(--text);
}

.sources-tabulator .tabulator-col-title {
  font-weight: 750;
}

.sources-filter-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  margin-left: 5px;
  border: 1px solid var(--border-strong);
  border-radius: 4px;
  background: var(--bg-raised);
  color: var(--accent-text);
  font-size: 12px;
  font-weight: 900;
}

.sources-tabulator .tabulator-header-filter input,
.sources-tabulator .tabulator-header-filter select {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg-raised);
  color: var(--text);
  font-size: 11px;
  padding: 3px 5px;
}

.sources-filter-popup {
  width: 260px;
  max-height: 340px;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-raised);
  box-shadow: var(--shadow-lg);
}

.sources-filter-popup-clear,
.sources-filter-popup-item {
  width: 100%;
  min-height: 28px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 12px;
  text-align: left;
  cursor: pointer;
}

.sources-filter-popup-clear {
  margin-bottom: 6px;
  padding: 5px 7px;
  color: var(--accent-text);
  font-weight: 800;
}

.sources-filter-popup-list {
  max-height: 280px;
  overflow: auto;
}

.sources-filter-popup-item {
  display: block;
  padding: 5px 7px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sources-filter-popup-clear:hover,
.sources-filter-popup-item:hover {
  background: var(--accent-soft);
}

.sources-tabulator .tabulator-row {
  background: var(--bg-raised);
  color: var(--text);
}

.sources-tabulator .tabulator-row.tabulator-row-even {
  background: var(--bg);
}

.sources-tabulator .tabulator-row:hover,
.sources-tabulator .tabulator-row.tabulator-selected {
  background: var(--accent-soft);
}

.sources-detail-pane {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 20;
  width: min(420px, 38vw);
  min-height: 0;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-raised);
  box-shadow: var(--shadow-lg);
  transform: translateX(calc(100% + 18px));
  transition: transform 0.18s ease;
}

.sources-workspace.detail-panel-open .sources-detail-pane {
  transform: translateX(0);
}

.sources-detail-empty {
  padding: 28px 20px;
  color: var(--text-secondary);
  text-align: center;
}

.sources-detail-header {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 13px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-sunken);
}

.sources-detail-close {
  flex: 0 0 auto;
  min-height: 28px;
  padding: 5px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-raised);
  color: var(--accent-text);
  font: inherit;
  font-size: 11px;
  font-weight: 800;
  cursor: pointer;
}

.sources-detail-close:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.sources-detail-title {
  color: var(--text);
  font-size: 15px;
  font-weight: 750;
}

.sources-detail-subtitle {
  margin-top: 2px;
  color: var(--text-secondary);
  font-size: 12px;
}

.sources-detail-fields {
  padding: 10px 14px 14px;
}

.sources-detail-field {
  padding: 9px 0;
  border-bottom: 1px solid var(--border);
}

.sources-detail-field:last-child {
  border-bottom: 0;
}

.sources-detail-label {
  margin-bottom: 3px;
  color: var(--text-muted);
  font-size: 10px;
  font-weight: 800;
  text-transform: uppercase;
}

.sources-detail-value {
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 12px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

@media (max-width: 1100px) {
  .sources-sheet-layout {
    display: block;
  }

  .sources-detail-pane {
    width: min(440px, 76vw);
  }
}

@media (max-width: 760px) {
  .sources-file-sidebar {
    width: min(86vw, 320px);
  }

  .sources-sheet-header,
  .sources-sheet-toolbar {
    flex-direction: column;
    align-items: stretch;
  }
}
