:root {
  --primary: #0f60af;
  --primary-light: #e8f0fe;
  --primary-hover: #0d4f8f;
  --success: #28a745;
  --danger: #dc3545;
  --gray: #6c757d;
  --gray-light: #f8f9fa;
  --gray-200: #e9ecef;
  --gray-300: #dee2e6;
  --border: #dee2e6;
  --text: #212529;
  --text-muted: #6c757d;
  --radius: 6px;
  --shadow: 0 1px 3px rgba(0,0,0,.1);
  --shadow-lg: 0 4px 12px rgba(0,0,0,.12);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  font-family: 'Nunito', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background: var(--gray-light);
  line-height: 1.5;
  display: flex;
  flex-direction: column;
}

/* Header - matches INDICATE Shiny app */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #ffffff;
  padding: 10px 20px;
  border-bottom: 2px solid var(--primary);
  box-shadow: 0 2px 10px rgba(0,0,0,.05);
  position: sticky;
  top: 0;
  z-index: 100;
  gap: 20px;
}
.header-left {
  display: flex;
  align-items: center;
  flex-shrink: 0;
  gap: 15px;
  cursor: pointer;
  text-decoration: none;
}
.header-logo {
  height: 40px;
}
.header-title {
  font-size: 20px;
  font-weight: 700;
  color: var(--primary);
  white-space: nowrap;
}
.header-nav {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  justify-content: center;
}
.nav-tab {
  background: transparent;
  border: none;
  color: var(--gray);
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  padding: 8px 16px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: all .2s ease;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
  text-decoration: none;
}
.nav-tab:hover { background: #f2f7fd; color: var(--primary); }
.nav-tab.active {
  background: var(--primary) !important;
  color: #ffffff !important;
  font-weight: 600;
}
.nav-tab.active:hover { background: #0d4d8f !important; }
.nav-tab i { font-size: 14px; }

/* Header icon button (cog) */
.header-icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--gray);
  font-size: 16px;
  cursor: pointer;
  transition: all .2s;
}
.header-icon-btn:hover {
  background: var(--gray-200);
  color: var(--primary);
}
.header-icon-btn.active {
  background: var(--primary);
  color: #fff;
}
.header-icon-btn.active:hover {
  background: var(--primary-hover);
}

/* Nav dropdown (Settings) */
.nav-dropdown {
  position: relative;
  display: inline-flex;
}
.nav-dropdown-menu {
  position: absolute;
  top: 100%;
  left: 0;
  margin-top: 4px;
  min-width: 240px;
  white-space: nowrap;
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  z-index: 200;
  padding: 4px 0;
}
.nav-dropdown-menu-right {
  left: auto;
  right: 0;
}
.nav-dropdown-menu a {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  color: var(--text);
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
  transition: background .15s;
}
.nav-dropdown-menu a:hover {
  background: var(--primary-light);
  color: var(--primary);
}
.nav-dropdown-menu a i {
  width: 16px;
  text-align: center;
  color: var(--gray);
}
.nav-dropdown-menu a:hover i {
  color: var(--primary);
}
.nav-dropdown-divider {
  height: 1px;
  background: var(--border);
  margin: 4px 0;
}
.nav-dropdown-menu a.nav-dropdown-danger {
  color: #dc3545;
}
.nav-dropdown-menu a.nav-dropdown-danger i {
  color: #dc3545;
}
.nav-dropdown-menu a.nav-dropdown-danger:hover {
  background: #fdf0f0;
  color: #b02a37;
}
.nav-dropdown-menu a.nav-dropdown-danger:hover i {
  color: #b02a37;
}

.header-right {
  display: flex;
  align-items: center;
  flex-shrink: 0;
  gap: 8px;
}
.lang-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  background: var(--primary);
  border: none;
  border-radius: 20px;
  color: white;
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background .2s;
}
.lang-toggle:hover { background: #0d4d8f; }
.lang-toggle.reset { background: #6c757d; }
.lang-toggle.reset:hover { background: #545b62; }

.current-user-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  background: var(--primary);
  border: none;
  border-radius: 20px;
  color: white;
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background .2s;
}
.current-user-badge:hover { background: #0d4d8f; }
.current-user-badge i { font-size: 16px; }

/* Loading */
.loading-overlay {
  position: fixed; inset: 0;
  background: white;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  gap: 16px;
}
.loading-overlay.hidden { display: none; }
.spinner {
  width: 40px; height: 40px;
  border: 3px solid var(--gray-200);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-text { color: var(--text-muted); font-size: 14px; }

/* Toast notifications */
.toast-container {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 10000;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  font-size: 13px;
  font-family: inherit;
  color: white;
  animation: toast-in .25s ease;
  max-width: 380px;
}
.toast.toast-error { background: #dc3545; }
.toast.toast-success { background: #28a745; }
.toast.toast-warning { background: #e67700; }
.toast.toast-info { background: var(--primary); }
.toast i { font-size: 14px; flex-shrink: 0; }
.toast-fade-out { animation: toast-out .3s ease forwards; }
@keyframes toast-in { from { opacity: 0; transform: translateX(40px); } to { opacity: 1; transform: translateX(0); } }
@keyframes toast-out { from { opacity: 1; } to { opacity: 0; transform: translateX(40px); } }

/* Main layout */
.main { padding: 10px; flex: 1; overflow: hidden; display: flex; flex-direction: column; }
.page-container { display: none; }

.list-view { display: flex; flex-direction: column; flex: 1; min-height: 0; overflow: hidden; }

/* Search & filters */
.toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.search-input {
  flex: 1;
  min-width: 250px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  outline: none;
  transition: border-color .15s;
}
.search-input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(15,96,175,.1); }

/* Concept Sets toolbar */
.cs-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  flex-wrap: wrap;
}
.cs-toolbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
  flex-shrink: 0;
}
.cs-toolbar-right > button,
.cs-toolbar-right > span {
  padding: 4px 10px;
  font-size: 12px;
  line-height: 1.3;
  height: 28px;
  box-sizing: border-box;
}
.btn-secondary-custom {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 6px 10px;
  background: #6c757d;
  color: #fff;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  transition: background .15s;
}
.btn-secondary-custom:hover { background: #5a6268; }
.btn-secondary-custom.active { background: var(--primary); }
.btn-secondary-custom.active:hover { background: var(--primary-hover); }
.btn-sm { padding: 6px 10px; font-size: 12px; }
.btn-danger-custom {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 6px 10px;
  background: var(--danger);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  transition: background .15s;
}
.btn-danger-custom:hover { background: #c82333; }
.cs-selection-count {
  font-size: 12px;
  font-weight: 600;
  color: var(--primary);
  padding: 0 4px;
}

/* Selection mode: checkbox column + row highlight */
#cs-table .cs-select-col { display: none; width: 36px; text-align: center; }
#cs-table .cs-edit-col { display: none; width: 40px; text-align: center; }
#cs-table.selection-mode .cs-select-col { display: table-cell; }
#cs-table.selection-mode .cs-edit-col { display: table-cell; }
#cs-table tbody tr.selected { background: #e8f0fe; }
#cs-table tbody tr.selected:hover { background: #d4e4fa; }
.cs-row-checkbox { width: 16px; height: 16px; cursor: pointer; accent-color: var(--primary); }
.cs-row-edit-btn { background: none; border: none; cursor: pointer; color: var(--gray-400); font-size: 14px; padding: 4px 8px; border-radius: var(--radius); transition: color .15s, background .15s; }
.cs-row-edit-btn:hover { background: var(--primary-light, #e8e5ff); color: var(--primary); }

.category-badges {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.category-badge {
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid var(--border);
  background: white;
  color: var(--text);
  transition: all .15s;
  white-space: nowrap;
}
.category-badge:hover { border-color: var(--primary); color: var(--primary); }
.category-badge.active {
  background: #ff8c00;
  color: white;
  border-color: #ff8c00;
}
.category-badge .count {
  display: inline-block;
  background: rgba(0,0,0,.1);
  padding: 0 6px;
  border-radius: 10px;
  font-size: 11px;
  margin-left: 4px;
}
.category-badge.active .count { background: rgba(255,255,255,.2); }

/* Tables */
.table-container {
  background: white;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}
.table-container thead { position: sticky; top: 0; z-index: 2; }
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
table.col-resizable {
  table-layout: fixed;
}
thead th {
  background: var(--gray-light);
  padding: 6px 10px;
  text-align: left;
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: var(--text-muted);
  border-bottom: 2px solid var(--border);
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
  position: relative;
}
/* Column resize handle */
.col-resize-handle {
  position: absolute;
  top: 0;
  right: -2px;
  width: 5px;
  height: 100%;
  cursor: col-resize;
  z-index: 3;
}
.col-resize-handle:hover,
.col-resize-handle.dragging {
  background: var(--primary);
  opacity: 0.5;
}
thead th:hover { color: var(--primary); }
thead th .sort-icon { margin-left: 4px; font-size: 10px; opacity: .4; }
thead th.sorted .sort-icon { opacity: 1; color: var(--primary); }
tbody tr {
  border-bottom: 1px solid var(--gray-200);
  cursor: pointer;
  transition: background .1s;
}
tbody tr:hover { background: var(--primary-light); }
tbody td {
  padding: 5px 10px;
  vertical-align: middle;
  overflow: hidden;
  text-overflow: ellipsis;
}

.td-center { text-align: center; }
.td-right { text-align: right; }

/* Badges & chips */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
}
.badge-standard { background: #d4edda; color: #155724; }
.badge-classification { background: #e2e3e5; color: #383d41; }
.badge-non-standard { background: #f8d7da; color: #721c24; }
.badge-valid { background: #d4edda; color: #155724; }
.badge-invalid { background: #f8d7da; color: #721c24; }
.badge-category {
  background: #fff3e0;
  color: #e65100;
  font-weight: 500;
}
.badge-subcategory {
  background: var(--primary-light);
  color: var(--primary);
  font-weight: 500;
}
.badge-count {
  background: var(--gray-200);
  color: var(--text-muted);
  font-weight: 500;
  min-width: 28px;
  text-align: center;
}

/* Detail view */
.detail-view { display: none; }
.detail-view.active { display: flex; flex-direction: column; flex: 1; min-height: 0; overflow: hidden; }
.list-view.hidden { display: none; }

.detail-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 8px;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
  gap: 8px;
}
.detail-header-left {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.detail-header-tabs {
  display: flex;
  gap: 6px;
}
.tab-btn-blue {
  background: #d0e4f7;
  border: none;
  color: #0f60af;
  font-size: 12px;
  font-weight: 500;
  padding: 4px 10px;
  border-radius: 4px;
  cursor: pointer;
  transition: all .2s ease;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.tab-btn-blue:hover { background: #b8d4f0; color: #0d4d8f; }
.tab-btn-blue.active { background: #0f60af; color: #fff; font-weight: 600; }
.tab-btn-blue.active:hover { background: #0d4d8f; }
.tab-btn-blue i { font-size: 12px; }
.tab-btn-green {
  background: #d4edda;
  border: none;
  color: #155724;
  font-size: 12px;
  font-weight: 500;
  padding: 4px 10px;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.2s ease;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  white-space: nowrap;
  font-family: inherit;
}
.tab-btn-green:hover { background: #c3e6cb; color: #0f4c18; }
.tab-btn-green i { font-size: 12px; }
.btn-back {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  background: white;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  transition: all .15s;
}
.btn-back:hover { border-color: var(--primary); color: var(--primary); }

.detail-title {
  font-size: 20px;
  font-weight: 600;
}
.detail-meta {
  margin-left: auto;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

/* Panels */
.panels {
  display: grid;
  gap: 20px;
}
.panels-2 { grid-template-columns: 1fr 1fr; }
.panels-1 { grid-template-columns: 1fr; }

.panel {
  background: white;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.panel-header {
  padding: 12px 5px;
  border-bottom: 1px solid var(--gray-200);
  display: flex;
  align-items: center;
  background: var(--gray-light);
}
.panel-header h3 {
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: var(--text-muted);
}
.panel-body { padding: 16px; }

/* Concept detail grid (matches Shiny app) */
.concept-details-container {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 13px;
}
.concept-details-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 5px 12px;
}
.detail-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  background: #f8f9fa;
  border-left: 3px solid #0f60af;
  border-radius: 3px;
  line-height: 1.4;
}
.detail-item strong {
  flex-shrink: 0;
  color: #0f60af;
  font-weight: 600;
  font-size: 12px;
  display: inline-block;
  min-width: 120px;
}
.detail-item > span {
  display: flex;
  align-items: center;
  color: #333;
  font-size: 13px;
}
.detail-item a {
  color: var(--primary);
  text-decoration: underline;
}
.detail-item a:hover { color: var(--primary-hover); }

/* Vocab tabs (Related / Hierarchy / Synonyms) */
.concept-vocab-tab-bar { display: flex; gap: 4px; margin: 16px 0 8px; border-bottom: 2px solid var(--border); padding: 0 4px; }
.concept-vocab-tab { padding: 6px 14px; border: none; background: none; cursor: pointer; font-size: 12px; font-weight: 600; color: var(--text-muted); border-bottom: 2px solid transparent; margin-bottom: -2px; transition: color 0.15s, border-color 0.15s; }
.concept-vocab-tab:hover { color: var(--text); }
.concept-vocab-tab.active { color: var(--primary); border-bottom-color: var(--primary); }
.concept-vocab-content { padding: 8px 0; flex: 1; display: flex; flex-direction: column; min-height: 0; overflow-y: auto; }
.concept-vocab-content .loading-inline { padding: 20px; text-align: center; color: var(--text-muted); font-size: 13px; }
.concept-related-table { width: 100%; font-size: 12px; border-collapse: collapse; }
.concept-related-table th { text-align: left; padding: 6px 8px; border-bottom: 2px solid var(--border); color: var(--primary); font-weight: 600; font-size: 11px; }
.concept-related-table td { padding: 5px 8px; border-bottom: 1px solid #eee; font-size: 12px; }
.concept-related-table tbody tr:hover { background: var(--primary-light); cursor: pointer; }
.concept-synonyms-list { list-style: none; padding: 0; margin: 0; }
.concept-synonyms-list li { padding: 6px 8px; border-bottom: 1px solid #eee; font-size: 13px; }
.related-pager { display: flex; align-items: center; justify-content: center; gap: 10px; padding: 8px 0; }

/* Hierarchy graph header + controls */
.hierarchy-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  background: var(--gray-light);
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.hierarchy-header-title {
  font-weight: 600;
  color: var(--text);
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.hierarchy-header-title .hierarchy-id { color: var(--text-muted); font-weight: 400; margin-left: 6px; }
.hierarchy-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  background: white;
  border: 1px solid var(--border);
  border-radius: 4px;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 13px;
  transition: all .15s;
  flex-shrink: 0;
}
.hierarchy-btn:hover { border-color: var(--primary); color: var(--primary); }
.hierarchy-btn:disabled { opacity: .3; cursor: default; }
.hierarchy-btn:disabled:hover { border-color: var(--border); color: var(--text-muted); }
.hierarchy-controls { display: flex; gap: 4px; flex-shrink: 0; }
.hierarchy-graph-container {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 300px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  position: relative;
  overflow: hidden;
}
.hierarchy-graph-container.fullscreen {
  position: fixed;
  inset: 0;
  z-index: 9999;
  height: 100vh;
  min-height: unset;
  border-radius: 0;
  border: none;
  background: white;
}
/* Custom hierarchy tooltip */
.hierarchy-tooltip {
  position: absolute;
  z-index: 100;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.12);
  padding: 8px 10px;
  pointer-events: auto;
  max-width: 360px;
}
.hierarchy-tooltip-table { border-collapse: collapse; width: 100%; font-size: 12px; }
.hierarchy-tooltip-table td { padding: 2px 6px; vertical-align: top; white-space: nowrap; }
.hierarchy-tooltip-table .ht-label { color: var(--text-muted); font-weight: 500; width: 70px; }
.hierarchy-tooltip-table .ht-value { color: var(--text); white-space: normal; word-break: break-word; }
.hierarchy-tooltip-table .ht-action { padding: 2px 0 2px 4px; vertical-align: middle; width: 24px; }
.ht-copy {
  display: inline-flex; align-items: center; justify-content: center;
  background: none; border: 1px solid var(--gray-300); border-radius: 3px;
  cursor: pointer; padding: 2px 4px; font-size: 10px;
  color: var(--text-muted);
}
.ht-copy:hover { background: var(--gray-100); color: var(--text); }

/* Hierarchy warning overlay (for large graphs, shown inside wrapper to preserve fullscreen) */
.hierarchy-warn-overlay {
  position: absolute;
  inset: 0;
  z-index: 10;
  background: rgba(255,255,255,0.92);
  display: flex;
  align-items: center;
  justify-content: center;
}
.hierarchy-warn-box {
  text-align: center;
  padding: 24px 32px;
  background: white;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 4px 16px rgba(0,0,0,0.1);
  max-width: 400px;
  font-size: 13px;
  line-height: 1.5;
}
/* Previous concept color in hierarchy */

/* Pagination */
.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-top: 1px solid var(--gray-200);
  background: var(--gray-light);
  position: sticky;
  bottom: 0;
  z-index: 2;
  margin-top: auto;
  font-size: 13px;
  color: var(--text-muted);
}
.pagination-buttons {
  display: flex;
  gap: 4px;
}
.pagination button {
  padding: 4px 10px;
  border: 1px solid var(--border);
  background: white;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 13px;
  transition: all .15s;
}
.pagination button:hover { border-color: var(--primary); color: var(--primary); }
.pagination button:disabled { opacity: .4; cursor: default; }
.pagination button.active { background: var(--primary); color: white; border-color: var(--primary); }

/* Project cards */
.project-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(400px, 1fr));
  gap: 16px;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  align-content: start;
}
.project-card {
  background: white;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  cursor: pointer;
  transition: all .15s;
  border: 2px solid transparent;
  display: flex;
  flex-direction: column;
  height: 180px;
}
.project-card:hover {
  box-shadow: var(--shadow-lg);
  border-color: var(--primary);
}
.project-card h3 {
  font-size: 16px;
  margin-bottom: 8px;
  color: var(--primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.project-card p {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 12px;
  display: -webkit-box;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.project-card-footer {
  display: flex;
  gap: 12px;
  font-size: 12px;
  color: var(--text-muted);
  margin-top: auto;
}
.project-card-footer span { display: flex; align-items: center; gap: 4px; }

/* Project detail */
.project-detail-section {
  margin-bottom: 20px;
}
.project-detail-section h4 {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 8px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .5px;
}
.project-detail-section p {
  font-size: 13.5px;
  line-height: 1.7;
}
.project-detail-section h1 { font-size: 18px; font-weight: 700; margin: 0 0 10px; padding-bottom: 6px; border-bottom: 1px solid var(--gray-200); }
.project-detail-section h2 { font-size: 16px; font-weight: 700; margin: 16px 0 8px; padding-bottom: 4px; border-bottom: 1px solid var(--gray-200); }
.project-detail-section h3 { font-size: 14.5px; font-weight: 700; margin: 14px 0 6px; }
.project-detail-section h1:first-child, .project-detail-section h2:first-child, .project-detail-section h3:first-child { margin-top: 0; }
.project-detail-section ul, .project-detail-section ol { margin: 0 0 10px; padding-left: 22px; font-size: 13.5px; line-height: 1.7; }
.project-detail-section li { margin-bottom: 3px; }
.project-detail-section blockquote {
  margin: 0 0 10px; padding: 8px 14px;
  border-left: 3px solid var(--primary); background: var(--primary-light);
  border-radius: 0 var(--radius) var(--radius) 0; color: #3a5a7a; font-size: 13px;
}
.project-detail-section code {
  font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
  font-size: 12px; background: var(--gray-light); border: 1px solid var(--gray-200);
  border-radius: 3px; padding: 1px 5px;
}
.project-detail-section pre {
  margin: 0 0 10px; padding: 10px 14px;
  background: #1e293b; color: #e2e8f0; border-radius: var(--radius);
  overflow-x: auto; font-size: 12px; line-height: 1.6;
}
.project-detail-section pre code { background: none; border: none; padding: 0; color: inherit; }
.project-detail-section a { color: var(--primary); text-decoration: none; }
.project-detail-section a:hover { text-decoration: underline; }
.project-detail-section strong { font-weight: 700; }

/* Tabs inside panels */
.panel-tabs {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--gray-200);
}
.panel-tab {
  padding: 10px 16px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  color: var(--text-muted);
  transition: all .15s;
  background: none;
  border-top: none;
  border-left: none;
  border-right: none;
}
.panel-tab:hover { color: var(--text); }
.panel-tab.active { color: var(--primary); border-bottom-color: var(--primary); }

/* Empty state */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted);
}
.empty-state svg { margin-bottom: 12px; opacity: .4; }
.empty-state p { font-size: 14px; }

/* Responsive */
@media (max-width: 1200px) {
  .nav-tab span { display: none; }
  .nav-tab { padding: 8px 12px; }
  .header-nav { gap: 5px; }
}
@media (max-width: 900px) {
  .panels-2 { grid-template-columns: 1fr; }
  .project-cards { grid-template-columns: 1fr; }
  .concept-detail-grid { grid-template-columns: 1fr; }
  .header-title { font-size: 16px; }
  .main { padding: 12px; }
}

/* Tab content fills available height */
.cs-tab-content { display: flex; flex-direction: column; flex: 1; min-height: 0; }
#cs-resolved-view, #cs-expression-view { display: flex; flex-direction: column; flex: 1; min-height: 0; overflow: hidden; }
#cs-resolved-view .panels { flex: 1; min-height: 0; overflow: hidden; }
#cs-resolved-view .panel, #cs-expression-view .panel { display: flex; flex-direction: column; min-height: 0; flex: 1; }

/* Project detail: tabs fill available space */
#proj-tab-variables { display: flex; flex-direction: column; flex: 1; min-height: 0; margin-top: 16px; }
#proj-tab-context { overflow-y: auto; flex: 1; min-height: 0; margin-top: 16px; }
#proj-tab-context-edit { display: flex; flex-direction: column; flex: 1; min-height: 0; margin-top: 16px; }
#proj-tab-context-edit > .panel-body { display: flex; flex-direction: column; flex: 1; min-height: 0; gap: 10px; overflow: hidden; }
#proj-tab-context-edit .project-detail-section { display: flex; flex-direction: column; min-height: 0; margin-bottom: 0; }
#proj-tab-context-edit .project-detail-section:first-child { flex: 1; }
#proj-tab-context-edit .project-detail-section:nth-child(2) { flex: 3; }
#proj-tab-context-edit .project-detail-section h4 { flex-shrink: 0; }
#proj-tab-context-edit .md-editor-wrap { flex: 1; min-height: 0; }
#proj-tab-context-edit .md-editor-pane { display: flex; flex-direction: column; overflow-y: auto; }
#proj-tab-context-edit .md-editor-textarea { flex: 1; min-height: 0; }
/* Scrollable table in panel */
.panel-table-wrap {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
}
.panel-table-wrap > table { flex-shrink: 0; }
.panel-table-wrap table thead { position: sticky; top: 0; z-index: 2; }
.panel-table-wrap > .pagination { position: sticky; bottom: 0; z-index: 2; flex-shrink: 0; }

/* Description truncation */
.desc-truncated {
  max-width: 300px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.export-btn {
  padding: 6px 14px;
  background: white;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  transition: all .15s;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.export-btn:hover { border-color: var(--primary); color: var(--primary); }

/* Status badges matching Shiny app */
.status-badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 600;
  vertical-align: middle;
  cursor: pointer;
  transition: filter .2s, transform .2s;
}
.status-badge.draft { background: #6c757d; color: white; }
.status-badge.pending_review { background: #ffc107; color: #000; }
.status-badge.approved { background: #28a745; color: white; }
.status-badge.needs_revision { background: #dc3545; color: white; }
.status-badge.deprecated { background: #495057; color: white; }

/* Column filter dropdowns */
.column-filter {
  padding: 5px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 12px;
  font-family: inherit;
  outline: none;
  background: white;
  color: var(--text);
  max-width: 100%;
  width: 100%;
}
.column-filter:focus { border-color: var(--primary); box-shadow: 0 0 0 2px rgba(15,96,175,.1); }
.ms-container { position: relative; }
.ms-toggle {
  padding: 5px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 12px;
  font-family: inherit;
  background: white;
  color: var(--text);
  width: 100%;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 4px;
}
.ms-toggle:hover { border-color: var(--primary); }
.ms-dropdown {
  position: absolute;
  left: 0;
  top: 100%;
  background: white;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  z-index: 60;
  min-width: 180px;
  max-height: 250px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  padding: 0;
}
.ms-option {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  font-size: 12px;
  cursor: pointer;
  white-space: nowrap;
}
.ms-option:hover { background: var(--gray-light); }
.ms-search-wrap { padding: 4px 6px; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: white; z-index: 1; }
.ms-search { width: 100%; padding: 4px 6px; border: 1px solid var(--border); border-radius: var(--radius); font-size: 12px; font-family: inherit; outline: none; box-sizing: border-box; }
.ms-search:focus { border-color: var(--primary); }
.ms-options { max-height: 220px; overflow-y: auto; padding: 4px 0; }
.filter-row th {
  padding: 4px 12px 8px !important;
  background: var(--gray-light) !important;
  border-bottom: none !important;
  box-shadow: 0 2px 0 0 var(--border) !important;
  cursor: default !important;
}
.filter-row th:hover { color: var(--text-muted) !important; }

/* Project detail header - matches Shiny app */
.project-name-badge {
  display: inline-block;
  max-width: 400px;
  padding: 4px 12px;
  font-size: 13px;
  font-weight: 600;
  color: #fff;
  background: #f97316;
  border-radius: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: default;
}
.project-name-badge.has-title-tooltip {
  overflow: visible;
  text-overflow: clip;
}
.project-name-badge:hover { background: #ea580c; }
.has-title-tooltip { position: relative; overflow: visible; }
.has-title-tooltip > .title-tooltip-text {
  display: inline-block;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  vertical-align: bottom;
}
.has-title-tooltip > .title-tooltip-bubble {
  visibility: hidden;
  opacity: 0;
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  background: #1a1a1a;
  color: #fff;
  font-size: 12px;
  font-weight: 400;
  line-height: 1.5;
  padding: 8px 12px;
  border-radius: 8px;
  white-space: normal;
  width: max-content;
  max-width: 500px;
  z-index: 200;
  pointer-events: none;
  transition: opacity .2s ease, visibility .2s ease;
  box-shadow: 0 4px 12px rgba(0,0,0,.25);
}
.has-title-tooltip:hover > .title-tooltip-bubble {
  visibility: visible;
  opacity: 1;
}

.concept-set-badges {
  display: inline-flex;
  gap: 6px;
  align-items: center;
  flex-wrap: wrap;
}
.version-badge {
  display: inline-block;
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 600;
  color: #fff;
  background: #6c757d;
  border-radius: 12px;
  vertical-align: middle;
  cursor: pointer;
  transition: filter .2s, transform .2s;
}
.version-badge:hover, .status-badge:hover {
  filter: brightness(1.15);
  transform: scale(1.05);
}
.org-badge {
  display: inline-block;
  padding: 4px 10px;
  font-size: 11px;
  font-weight: 500;
  color: var(--text-muted);
  background: var(--gray-100);
  border: 1px solid var(--gray-200);
  border-radius: 12px;
  vertical-align: middle;
}
.uuid-badge {
  display: inline-block;
  padding: 4px 10px;
  font-size: 11px;
  font-weight: 500;
  font-family: 'SF Mono', 'Fira Code', monospace;
  color: var(--text-muted);
  background: var(--gray-100);
  border: 1px solid var(--gray-200);
  border-radius: 12px;
  vertical-align: middle;
  cursor: pointer;
  transition: border-color .2s;
}
.uuid-badge:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.btn-primary-custom {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  transition: background .15s;
  line-height: 1.4;
}
.btn-primary-custom:hover { background: var(--primary-hover); }
.btn-primary-custom.btn-gray { background: #6c757d; }
.btn-primary-custom.btn-gray:hover { background: #5a6268; }
.btn-primary-custom.btn-purple { background: #6f42c1; }
.btn-primary-custom.btn-purple:hover { background: #5a32a3; }
.btn-primary-custom.btn-danger { background: #dc3545; }
.btn-primary-custom.btn-danger:hover { background: #c82333; }


.btn-back-discrete {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  background: white;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  color: var(--text-muted);
  transition: all .15s;
  flex-shrink: 0;
}
.btn-back-discrete:hover { border-color: var(--primary); color: var(--primary); }

/* Custom tooltip */
.custom-tooltip {
  position: relative;
  display: inline-flex;
  align-items: center;
  cursor: help;
}
.custom-tooltip .tooltip-text {
  visibility: hidden;
  opacity: 0;
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  background: #1a1a1a;
  color: #fff;
  font-size: 12px;
  font-weight: 400;
  line-height: 1.5;
  padding: 8px 12px;
  border-radius: 8px;
  white-space: normal;
  width: 300px;
  z-index: 200;
  pointer-events: none;
  transition: opacity .2s ease, visibility .2s ease;
  box-shadow: 0 4px 12px rgba(0,0,0,.25);
}
.custom-tooltip .tooltip-text::after {
  content: '';
  position: absolute;
  bottom: 100%;
  left: 12px;
  border: 6px solid transparent;
  border-bottom-color: #1a1a1a;
}
.custom-tooltip:hover .tooltip-text {
  visibility: visible;
  opacity: 1;
}

/* Toggle bar for Expression/Resolved */
.toggle-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}
.toggle-bar-right {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
}
.toggle-group {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.toggle-btn {
  padding: 6px 16px;
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  border: none;
  background: white;
  color: var(--text-muted);
  cursor: pointer;
  transition: all .15s;
}
.toggle-btn:not(:last-child) { border-right: 1px solid var(--border); }
.toggle-btn:hover { background: var(--gray-light); color: var(--text); }
.toggle-btn.active { background: var(--primary); color: white; font-weight: 600; }

/* Column visibility dropdown */
.btn-outline-sm {
  background: white;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 4px 12px;
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  color: var(--text-muted);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  line-height: 1.4;
  transition: background .15s;
}
.btn-outline-sm:hover { border-color: var(--primary); color: var(--primary); }
.col-vis-dropdown {
  position: absolute;
  right: 0;
  top: 100%;
  margin-top: 4px;
  background: white;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 8px 0;
  z-index: 50;
  min-width: 180px;
}
.col-vis-dropdown label {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 14px;
  font-size: 12px;
  cursor: pointer;
  white-space: nowrap;
}
.col-vis-dropdown label:hover { background: var(--gray-light); }

/* Flag badges for expression table */
.flag-yes { display: inline-block; padding: 2px 8px; border-radius: 4px; font-size: 11px; font-weight: 600; background: #d4edda; color: #155724; }
.flag-no { display: inline-block; padding: 2px 8px; border-radius: 4px; font-size: 11px; font-weight: 600; background: var(--gray-200); color: var(--text-muted); }
.flag-yes-danger { display: inline-block; padding: 2px 8px; border-radius: 4px; font-size: 11px; font-weight: 600; background: #f8d7da; color: #721c24; }

/* Modal */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex; align-items: center; justify-content: center;
  z-index: 500;
}
.modal {
  background: white;
  border-radius: 8px;
  box-shadow: var(--shadow-lg);
  width: 600px;
  max-width: 90vw;
  max-height: 85vh;
  overflow-y: auto;
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--gray-200);
}
.modal-header h3 { font-size: 16px; font-weight: 600; }

/* Profile modal tabs (author / organization) */
.profile-modal-tabs {
  display: flex;
  justify-content: center;
  gap: 0;
  border-bottom: 1px solid var(--gray-200);
}
.profile-modal-tab {
  background: none;
  border: none;
  padding: 10px 24px;
  font-size: 13px;
  font-weight: 600;
  color: var(--gray);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: color .2s, border-color .2s;
}
.profile-modal-tab:hover {
  color: var(--primary);
}
.profile-modal-tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}
.modal-close {
  background: none; border: none;
  font-size: 24px; color: var(--text-muted);
  cursor: pointer; padding: 0; line-height: 1;
}
.modal-close:hover { color: var(--text); }
.modal-body { padding: 20px; }
.modal-footer {
  display: flex; justify-content: flex-end; gap: 10px;
  padding: 16px 20px;
  border-top: 1px solid var(--gray-200);
}

/* Form elements */
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 12px; }
.form-group { margin-bottom: 12px; }
.form-group label {
  display: block; font-size: 12px; font-weight: 600;
  text-transform: uppercase; letter-spacing: .5px;
  color: var(--text-muted); margin-bottom: 4px;
}
.form-input {
  width: 100%; padding: 8px 12px;
  border: 1px solid var(--border); border-radius: var(--radius);
  font-size: 14px; font-family: inherit; outline: none;
  transition: border-color .15s;
}
.form-input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(15,96,175,.1); }
textarea.form-input { resize: vertical; min-height: 100px; }
select.form-input { appearance: auto; }
.input-with-add { display: flex; gap: 6px; align-items: center; }
.input-with-add select { flex: 1; }
.input-with-add .btn-outline-sm {
  flex-shrink: 0; width: 34px; height: 34px; padding: 0;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--primary); color: white; border-color: var(--primary);
  border-radius: 50%; font-size: 13px;
}
.input-with-add .btn-outline-sm:hover { background: #0a4a8a; border-color: #0a4a8a; color: white; }

/* Markdown preview */
.markdown-preview {
  border: 1px solid var(--gray-200); border-radius: var(--radius);
  padding: 12px; min-height: 60px;
  font-size: 14px; line-height: 1.6;
  background: var(--gray-light);
}
.markdown-preview p { margin-bottom: 8px; }
.markdown-preview p:last-child { margin-bottom: 0; }

/* Fullscreen modal */
.modal-fs {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: white;
  z-index: 9999;
  flex-direction: column;
}
.modal-fs.visible { display: flex; }
.modal-fs-header {
  padding: 6px 15px;
  border-bottom: 1px solid #ddd;
  background: #f8f9fa;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}
.modal-fs-header h3 { font-size: 15px; font-weight: 600; margin: 0; }
.modal-fs-header select {
  min-width: 200px;
  height: 28px;
  font-size: 12px;
  font-family: inherit;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0 8px;
}
.modal-fs-close {
  width: 28px; height: 28px;
  font-size: 20px;
  background: none;
  border: none;
  color: #666;
  border-radius: 4px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-left: auto;
}
.modal-fs-close:hover { background: #e9ecef; color: #333; }
.modal-fs-body {
  flex: 1;
  display: flex;
  padding: 5px 10px 10px 10px;
  min-height: 0;
  gap: 0;
}
.modal-fs-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  margin: 5px;
}
.modal-fs-col-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  padding: 4px 0 6px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.modal-fs-col-title i { font-size: 11px; }
.modal-fs-col:first-child { border-right: 1px solid #dee2e6; padding-right: 10px; }
#review-ace-editor {
  flex: 1;
  min-height: 0;
  border: 1px solid #dee2e6;
  border-radius: 4px;
  font-size: 12px;
}
.markdown-body {
  flex: 1;
  min-height: 0;
  overflow: auto;
  border: 1px solid #dee2e6;
  border-radius: 4px;
  padding: 12px 16px;
  background: white;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 12px;
  line-height: 1.6;
  color: #2d3748;
}
.markdown-body h1 { font-size: 18px; font-weight: 700; color: #1a202c; margin: 16px 0 8px; }
.markdown-body h2 { font-size: 16px; font-weight: 600; color: #2d3748; margin: 14px 0 6px; border-bottom: 1px solid #eee; padding-bottom: 4px; }
.markdown-body h3 { font-size: 14px; font-weight: 600; color: #4a5568; margin: 12px 0 4px; }
.markdown-body p { margin: 0 0 8px; }
.markdown-body ul, .markdown-body ol { margin: 0 0 8px; padding-left: 20px; }
.markdown-body li { margin-bottom: 2px; }
.markdown-body code { background: #f7f7f7; border: 1px solid #ddd; padding: 2px 6px; border-radius: 3px; font-size: 11px; }
.markdown-body pre { background: #f7f7f7; border-radius: 4px; padding: 12px; overflow: auto; margin: 0 0 8px; }
.markdown-body pre code { border: none; padding: 0; background: none; }
.markdown-body blockquote { border-left: 3px solid var(--primary); margin: 0 0 8px; padding: 4px 12px; color: #4a5568; }
.markdown-body table { border-collapse: collapse; margin: 0 0 8px; width: 100%; }
.markdown-body th, .markdown-body td { border: 1px solid #ddd; padding: 6px 10px; font-size: 12px; }
.markdown-body th { background: #f8f9fa; font-weight: 600; }
.markdown-preview-placeholder { color: #aaa; font-style: italic; padding: 20px; text-align: center; }

/* Mapping Recommendations page */
.mapping-page-toolbar {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 0 0 10px;
}
.mapping-view-container {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 16px 24px;
}
.mapping-view-container .markdown-body {
  max-width: 960px;
  margin: 0 auto;
}
.mapping-edit-container {
  flex: 1;
  min-height: 0;
  width: 100%;
  display: none;
}
.mapping-edit-container .mapping-editor-layout {
  height: 100%;
  width: 100%;
}

/* Comments split handle (resizable editor/preview) */
.comments-split-handle {
  width: 5px;
  background: var(--gray-200);
  cursor: col-resize;
  flex-shrink: 0;
  transition: background .15s;
  position: relative;
}
.comments-split-handle:hover,
.comments-split-handle.dragging {
  background: var(--primary);
}

.btn-success-custom {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 12px; background: #28a745; color: #fff; border: none;
  border-radius: var(--radius); cursor: pointer; font-size: 13px;
  font-weight: 500; font-family: inherit; transition: background .15s; line-height: 1.4;
}
.btn-success-custom:hover { background: #218838; }

/* Modal buttons */
.btn-cancel {
  padding: 8px 16px; background: white;
  border: 1px solid var(--border); border-radius: var(--radius);
  cursor: pointer; font-size: 13px; font-weight: 500;
  font-family: inherit; color: var(--text); transition: all .15s;
}
.btn-cancel:hover { border-color: var(--primary); color: var(--primary); }
.btn-submit {
  padding: 8px 16px; background: var(--primary);
  border: 1px solid var(--primary); border-radius: var(--radius);
  cursor: pointer; font-size: 13px; font-weight: 600;
  font-family: inherit; color: white; transition: all .15s;
  display: inline-flex; align-items: center; gap: 6px;
}
.btn-submit:hover { background: var(--primary-hover); }

/* Export modal options */
.export-options-container {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 10px 0;
}
.export-option {
  display: flex;
  align-items: center;
  gap: 15px;
  padding: 12px 15px;
  border: 2px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  transition: all .2s ease;
  background: #fff;
}
.export-option:hover {
  border-color: var(--primary);
  background: #f2f7fd;
  box-shadow: 0 2px 8px rgba(15,96,175,.1);
  transform: translateY(-1px);
}
.export-option-icon {
  font-size: 24px;
  min-width: 40px;
  text-align: center;
}
.export-option-content { flex: 1; }
.export-option-title {
  margin: 0 0 4px 0;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}
.export-option-subtitle {
  margin: 0;
  font-size: 12px;
  color: var(--text-muted);
}

/* ==================== SETTINGS PAGE ==================== */
.settings-tabs {
  display: flex;
  gap: 0;
  border-bottom: 2px solid var(--border);
  margin-bottom: 0;
  background: #fff;
  border-radius: var(--radius) var(--radius) 0 0;
}
.settings-tab {
  padding: 12px 20px;
  border: none;
  background: transparent;
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: all .2s;
  display: flex;
  align-items: center;
  gap: 6px;
}
.settings-tab:hover { color: var(--primary); }
.settings-tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}
.settings-content {
  background: #fff;
  border-radius: 0 0 var(--radius) var(--radius);
  min-height: 400px;
}

/* Mapping editor layout */
.mapping-editor-layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0;
  height: calc(100vh - 220px);
  min-height: 400px;
}
.mapping-editor-pane {
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  overflow: hidden;
}
.mapping-editor-pane:last-child { border-right: none; }
.mapping-pane-header {
  padding: 8px 16px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .5px;
  border-bottom: 1px solid var(--border);
  background: var(--gray-light);
  display: flex;
  align-items: center;
  gap: 6px;
}
.mapping-pane-body {
  flex: 1;
  overflow: auto;
  min-height: 0;
}
.mapping-pane-body .markdown-body {
  padding: 16px;
}
#mapping-ace-editor, #mapping-page-ace-editor {
  width: 100%;
  height: 100%;
  font-size: 13px;
}

/* Comments & Statistics edit mode */
.form-textarea {
  width: 100%; box-sizing: border-box;
  padding: 8px 12px; border: 1px solid var(--border); border-radius: var(--radius);
  font-family: inherit; font-size: 13px; line-height: 1.5; resize: vertical;
  color: var(--text); background: white;
}
.form-textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 2px rgba(79,70,229,.15); }
.form-select-sm {
  padding: 4px 8px; border: 1px solid var(--border); border-radius: var(--radius);
  font-size: 12px; background: white; color: var(--text); cursor: pointer;
}
#cs-comments-ace-editor, #cs-stats-ace-editor {
  width: 100%; font-size: 12px;
  border: 1px solid #dee2e6; border-radius: 0;
}
#cs-tab-comments { display: flex; flex-direction: column; }
#cs-comments-view { flex: 1; min-height: 0; }
#cs-comments-edit { display: flex; flex-direction: column; flex: 1; min-height: 0; }
#cs-tab-statistics { display: flex; flex-direction: column; }
#cs-statistics-edit { display: flex; flex-direction: column; flex: 1; min-height: 0; }

/* Statistics view */
.stats-summary-table { border-collapse: collapse; }
.stats-summary-table td { border: none; }
.stats-histogram { display: flex; flex-direction: column; gap: 4px; }
.stats-hist-row { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.stats-hist-label { width: 60px; text-align: right; flex-shrink: 0; color: var(--text-muted); font-size: 12px; }
.stats-hist-bar-wrap { flex: 1; height: 18px; background: var(--gray-100); border-radius: 3px; overflow: hidden; }
.stats-hist-bar { height: 100%; background: var(--primary); border-radius: 3px; min-width: 1px; transition: width .2s; }
.stats-hist-bar-cat { background: #38a169; }
.stats-hist-count { width: 80px; flex-shrink: 0; font-size: 12px; color: var(--text-muted); }

/* Settings toolbar */
.settings-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--gray-light);
}
.settings-toolbar .search-input {
  max-width: 300px;
}

/* Editable cell */
.editable-cell {
  cursor: pointer;
  position: relative;
}
.editable-cell:hover {
  background: var(--primary-light);
}
.editable-cell input {
  width: 80px;
  padding: 2px 6px;
  font-size: 13px;
  font-family: inherit;
  border: 1px solid var(--primary);
  border-radius: 3px;
  outline: none;
}

/* Action buttons in tables */
.btn-action {
  padding: 4px 8px;
  border: none;
  border-radius: 4px;
  font-family: inherit;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  transition: all .15s;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.btn-action-test { background: #fff3cd; color: #856404; }
.btn-action-test:hover { background: #ffc107; color: #fff; }
.btn-action-delete { background: #f8d7da; color: #721c24; }
.btn-action-delete:hover { background: var(--danger); color: #fff; }

/* Test conversion modal */
.test-conv-info {
  text-align: center;
  padding: 12px;
  background: var(--gray-light);
  border-radius: var(--radius);
  margin-bottom: 16px;
  font-size: 13px;
  color: var(--text-muted);
}
.test-conv-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}
.test-conv-row input {
  flex: 1;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  font-family: inherit;
}
.test-conv-row .unit-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  min-width: 60px;
}
.test-conv-arrow {
  text-align: center;
  padding: 8px;
  color: var(--primary);
  font-size: 13px;
}
.test-conv-result {
  background: var(--primary-light);
  border-radius: var(--radius);
  padding: 12px 16px;
  text-align: center;
  font-size: 16px;
  font-weight: 600;
  color: var(--primary);
}

/* ── General Settings / Vocabulary DB ─────────────────── */

.vocab-page {
  max-width: 800px;
  margin: 0 auto;
  padding: 24px 20px;
}

.vocab-status-panel {
  display: flex;
  align-items: center;
  gap: 16px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 24px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}
.vocab-status-panel .vocab-status-icon {
  font-size: 28px;
  color: var(--gray);
  flex-shrink: 0;
}
.vocab-status-panel .vocab-status-title {
  font-size: 16px;
  font-weight: 700;
}
.vocab-status-panel .vocab-status-msg {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 2px;
}

.vocab-status-loading .vocab-status-icon { color: var(--primary); }
.vocab-status-ready .vocab-status-icon { color: var(--success); }
.vocab-status-error .vocab-status-icon { color: var(--danger); }
.vocab-status-empty .vocab-status-icon { color: var(--gray); }

.vocab-info-box {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  background: var(--primary-light);
  border: 1px solid #b6d4fe;
  border-radius: var(--radius);
  padding: 14px 18px;
  font-size: 13px;
  color: #084298;
  margin-bottom: 20px;
  line-height: 1.5;
}
.vocab-info-box i {
  margin-top: 2px;
  flex-shrink: 0;
}
.vocab-info-box a {
  color: #084298;
  font-weight: 600;
  text-decoration: underline;
}
.vocab-info-warning {
  background: #fff3cd;
  border-color: #ffecb5;
  color: #664d03;
}
.vocab-info-warning a {
  color: #664d03;
}
.vocab-info-parquet {
  background: #f0f7ff;
  border-color: #b6d4fe;
  color: #084298;
}
.vocab-info-parquet .btn-link {
  background: none;
  border: none;
  color: #084298;
  font-weight: 600;
  text-decoration: underline;
  cursor: pointer;
  padding: 0;
  font-size: 13px;
}

/* Parquet code block */
.vocab-code-tabs {
  display: flex;
  gap: 0;
  margin-bottom: -1px;
  position: relative;
  z-index: 1;
}
.vocab-code-tab {
  background: var(--gray-100);
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-bottom: none;
  border-radius: 6px 6px 0 0;
  padding: 5px 14px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}
.vocab-code-tab.active {
  background: #f5f5f5;
  color: var(--text);
}
.vocab-code-block {
  position: relative;
}
.vocab-code-block pre {
  background: #f5f5f5;
  color: #333;
  border-radius: 0 6px 6px 6px;
  padding: 12px 14px;
  margin: 0;
  font-size: 12.5px;
  font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
  overflow-x: auto;
  white-space: pre-wrap;
  line-height: 1.5;
  border: 1px solid var(--border);
}
.vocab-code-block pre code {
  font-family: inherit;
}
.vocab-code-copy {
  position: absolute;
  top: 6px;
  right: 6px;
  background: rgba(0,0,0,0.06);
  border: none;
  color: #888;
  border-radius: 4px;
  padding: 4px 7px;
  cursor: pointer;
  font-size: 12px;
  z-index: 2;
  transition: color .15s, background .15s;
}
.vocab-code-copy:hover {
  background: rgba(0,0,0,0.12);
  color: #333;
}
.vocab-code-note {
  margin: 6px 0 0 0;
  font-size: 12px;
  color: var(--text-muted);
}

/* Full hierarchy badge */
.vocab-badge {
  display: inline-block;
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 4px;
  font-weight: 600;
  vertical-align: middle;
  margin-left: 6px;
}
.vocab-badge-parquet {
  background: var(--primary);
  color: white;
}

#page-general-settings { overflow: hidden auto; }

.vocab-actions {
  display: flex;
  gap: 10px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

/* Progress */
.vocab-progress-section {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 24px;
  margin-bottom: 20px;
  box-shadow: var(--shadow);
}
.vocab-progress-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
  font-size: 13px;
  font-weight: 600;
}
.vocab-progress-bar {
  height: 8px;
  background: var(--gray-200);
  border-radius: 4px;
  overflow: hidden;
  margin-bottom: 16px;
}
.vocab-progress-fill {
  height: 100%;
  background: var(--primary);
  border-radius: 4px;
  transition: width 0.3s ease;
}

.vocab-file-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.vocab-file-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-muted);
  padding: 4px 0;
}
.vocab-file-icon {
  width: 16px;
  text-align: center;
  flex-shrink: 0;
}
.vocab-file-importing { color: var(--primary); font-weight: 600; }
.vocab-file-importing .vocab-file-icon { color: var(--primary); }
.vocab-file-done { color: var(--success); }
.vocab-file-done .vocab-file-icon { color: var(--success); }
.vocab-file-error { color: var(--danger); }
.vocab-file-error .vocab-file-icon { color: var(--danger); }

/* Stats grid */
.vocab-stats-section {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 24px;
  box-shadow: var(--shadow);
}
.vocab-section-title {
  font-size: 15px;
  font-weight: 700;
  margin-bottom: 16px;
}
.vocab-stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 12px;
}
.vocab-stat-card {
  background: var(--gray-light);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  padding: 14px 16px;
}
.vocab-stat-name {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 4px;
}
.vocab-stat-count {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
}

/* ── Dev Tools ────────────────────────────────────────── */

.devtools-db-status {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  font-size: 13px;
  border-bottom: 1px solid var(--border);
  background: var(--gray-light);
}
.devtools-db-status i:first-child { font-size: 16px; flex-shrink: 0; }
.devtools-db-loading { color: var(--primary); }
.devtools-db-ready { color: var(--success); }
.devtools-db-error { color: var(--danger); }
.devtools-db-empty { color: var(--text-muted); }
.devtools-db-warning { color: #664d03; background: #fff3cd; border-color: #ffecb5; }
.devtools-db-link {
  margin-left: auto;
  font-size: 12px;
  font-weight: 600;
  color: var(--primary);
  text-decoration: underline;
}

.devtools-sql-layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  height: calc(100vh - 195px);
  min-height: 400px;
}
.devtools-sql-left {
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
}
.devtools-sql-right {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.devtools-sql-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--gray-light);
  flex-shrink: 0;
}
.devtools-sql-toolbar .form-input {
  padding: 5px 10px;
  font-size: 13px;
}
.devtools-sql-toolbar .btn-submit {
  padding: 5px 14px;
  font-size: 13px;
}
.devtools-sql-toolbar .toggle-btn {
  padding: 5px 14px;
}
.devtools-sql-toolbar .btn-outline-sm {
  padding: 5px 10px;
}
.devtools-shortcut-hint {
  font-size: 11px;
  color: var(--text-muted);
  background: var(--gray-200);
  padding: 2px 6px;
  border-radius: 3px;
  font-family: monospace;
}
.devtools-sql-ace {
  flex: 1;
  width: 100%;
  min-height: 120px;
  font-size: 13px;
}
.devtools-sql-results {
  flex: 1;
  overflow: hidden;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
.devtools-sql-pager {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 6px 12px;
  border-top: 1px solid var(--border);
  background: var(--gray-light);
  flex-shrink: 0;
}
.devtools-pager-info {
  font-size: 12px;
  color: var(--text-muted);
  min-width: 100px;
  text-align: center;
}
.devtools-sql-results .data-table { font-size: 12px; }
.devtools-sql-results .data-table thead th {
  position: sticky;
  top: 0;
  z-index: 2;
}
.devtools-sql-error {
  padding: 16px;
  color: var(--danger);
  font-size: 13px;
  background: #fff5f5;
  border-left: 3px solid var(--danger);
  margin: 12px;
  border-radius: var(--radius);
}
.devtools-sql-error i { margin-right: 6px; }
.devtools-row-count {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 500;
}

/* ERD */
.devtools-erd-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--gray-light);
}
.devtools-erd-hint {
  font-size: 11px;
  color: var(--text-muted);
  margin-left: auto;
}
.devtools-erd-viewport {
  overflow: hidden;
  position: relative;
  cursor: grab;
  background: #fafbfc;
  height: calc(100vh - 195px);
  min-height: 400px;
}
.devtools-erd-canvas {
  position: relative;
  transform-origin: 0 0;
}
.devtools-erd-svg {
  position: absolute;
  top: 0;
  left: 0;
  pointer-events: none;
}
.erd-card {
  position: absolute;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  font-size: 12px;
  z-index: 1;
  border: 2px solid var(--border);
}
.erd-card-header {
  padding: 6px 12px;
  font-weight: 700;
  font-size: 13px;
  border-bottom: 1px solid rgba(0,0,0,.1);
}
.erd-card-body {
  padding: 4px 0;
  background: #fff;
}
.erd-card-row {
  padding: 2px 12px;
  font-size: 11px;
  font-family: 'SFMono-Regular', Consolas, monospace;
  color: #333;
  white-space: nowrap;
}
.erd-card-row:hover { background: var(--gray-light); }

.erd-card-yellow { border-color: #f0c040; }
.erd-card-yellow .erd-card-header { background: #fef3cd; color: #856404; }
.erd-card-green { border-color: #82c982; }
.erd-card-green .erd-card-header { background: #d4edda; color: #155724; }
.erd-card-red { border-color: #e0a0a0; }
.erd-card-red .erd-card-header { background: #f8d7da; color: #721c24; }

.erd-badge-pk {
  display: inline-block;
  padding: 0 4px;
  font-size: 9px;
  font-weight: 700;
  border-radius: 2px;
  background: #fef3cd;
  color: #856404;
  margin-right: 3px;
  vertical-align: middle;
}
.erd-badge-fk {
  display: inline-block;
  padding: 0 4px;
  font-size: 9px;
  font-weight: 700;
  border-radius: 2px;
  background: var(--primary-light);
  color: var(--primary);
  margin-right: 3px;
  vertical-align: middle;
}
.erd-line {
  fill: none;
  stroke-width: 1.5;
  stroke-dasharray: 6 3;
}
.erd-line-green { stroke: #82c982; }
.erd-line-red { stroke: #e0a0a0; }
.erd-line-yellow { stroke: #f0c040; }

/* Toggle switch component */
.toggle-switch { position: relative; display: inline-block; width: 34px; height: 18px; vertical-align: middle; }
.toggle-switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.toggle-slider { position: absolute; cursor: pointer; inset: 0; background: var(--gray-300); border-radius: 18px; transition: .2s; }
.toggle-slider::before { content: ''; position: absolute; height: 14px; width: 14px; left: 2px; bottom: 2px; background: white; border-radius: 50%; transition: .2s; }
.toggle-switch input:checked + .toggle-slider { background: var(--primary); }
.toggle-switch input:checked + .toggle-slider::before { transform: translateX(16px); }
.toggle-sm { width: 30px; height: 16px; }
.toggle-sm .toggle-slider::before { height: 12px; width: 12px; }
.toggle-sm input:checked + .toggle-slider::before { transform: translateX(14px); }
.toggle-exclude input:checked + .toggle-slider { background: var(--danger); }

/* Expression edit actions (in toggle bar) */
#expr-edit-actions { display: flex; align-items: center; gap: 6px; }

/* Expression table edit/select mode */
#expression-table .expr-select-col, #expression-table .expr-action-col { display: none; }
#expression-table.expr-edit-mode .expr-select-col { display: table-cell; }
#expression-table.expr-edit-mode .expr-action-col { display: table-cell; }
.expr-row-checkbox { width: 16px; height: 16px; cursor: pointer; accent-color: var(--primary); }
.expr-edit-custom-icon { cursor: pointer; color: var(--primary); opacity: 0.6; font-size: 13px; margin-right: 6px; }
.expr-edit-custom-icon:hover { opacity: 1; }
#data-update-modal .modal { display: flex; flex-direction: column; max-height: 80vh; }
#data-update-modal .modal-body { overflow-y: auto; flex: 1 1 auto; max-height: calc(80vh - 130px); }
#edit-custom-concept-modal .modal { overflow: visible; }
#edit-custom-concept-modal .modal-body { overflow: visible; }
#edit-custom-concept-modal .ms-dropdown { z-index: 510; }
.expr-delete-icon { cursor: pointer; color: var(--danger); opacity: 0.6; font-size: 13px; }
.expr-delete-icon:hover { opacity: 1; }
#expression-table tbody tr.expr-selected { background: #e8f0fe; }
#expression-table tbody tr.expr-selected:hover { background: #d4e4fa; }

/* Add concepts modal: tabs */
.expr-add-tabs { display: flex; gap: 0; flex: 1; justify-content: center; }
.expr-add-tab {
  padding: 5px 16px; font-size: 13px; font-weight: 500; cursor: pointer;
  border: 1px solid var(--border); background: var(--gray-light); color: var(--text-muted);
  transition: all .15s;
}
.expr-add-tab:first-child { border-radius: var(--radius) 0 0 var(--radius); }
.expr-add-tab:last-child { border-radius: 0 var(--radius) var(--radius) 0; border-left: none; }
.expr-add-tab.active { background: var(--primary); color: #fff; border-color: var(--primary); font-weight: 600; }
.expr-add-tab:not(.active):hover { background: #e9ecef; }

/* Custom concept form */
.custom-concept-form { max-width: 600px; margin: 0 auto; padding: 20px 0; }
.custom-concept-row { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.custom-concept-row > label { min-width: 130px; font-size: 13px; font-weight: 600; color: var(--text); text-align: right; }
.custom-concept-row > .form-input, .custom-concept-row > select.form-input, .custom-concept-row > .custom-concept-ms, .custom-concept-row > .custom-concept-input-wrap { width: 300px; min-width: 300px; flex: 0 0 300px; }
.custom-concept-input-wrap { display: flex; flex-direction: column; gap: 4px; }
.custom-concept-input-wrap > .form-input { width: 100%; }
.custom-concept-ms .ms-toggle { padding: 8px 12px; font-size: 14px; }
.custom-concept-hint { font-size: 11px; color: var(--text-muted); font-style: italic; }
.ms-option-single { padding: 5px 10px; font-size: 12px; cursor: pointer; }
.ms-option-single:hover { background: var(--gray-light); }
.ms-option-single.ms-option-selected { background: var(--primary); color: #fff; }
.ms-option-single.ms-option-selected:hover { background: #0d4d8f; }

/* Add concepts modal */
.modal-fs-footer { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; border-top: 1px solid var(--gray-200); background: var(--gray-light); flex-shrink: 0; }
.expr-add-toggles { display: flex; align-items: center; gap: 12px; font-size: 13px; }

/* Add concepts: layout */
#expr-add-panel-ohdsi { display: flex; flex-direction: column; flex: 1; min-height: 0; gap: 8px; }
#expr-add-search-row { display: flex; gap: 8px; align-items: center; position: relative; flex-shrink: 0; }

/* Add concepts: top half (results table + pagination) */
#expr-add-results-wrap { flex: 1; min-height: 0; display: flex; flex-direction: column; overflow-y: auto; }
#expr-add-table-scroll { flex: 1; min-height: 0; overflow-y: auto; }
#expr-add-results-wrap > .pagination { flex-shrink: 0; }

/* Add concepts: bottom half (details + hierarchy) */
.expr-add-bottom { flex: 1; min-height: 0; display: flex; gap: 12px; overflow: hidden; }
.expr-add-detail-panel { flex: 1; min-height: 0; border: 1px solid var(--border); border-radius: var(--radius); display: flex; flex-direction: column; overflow: hidden; }
.expr-add-panel-title { padding: 8px 12px; font-size: 13px; font-weight: 600; background: var(--gray-light); border-bottom: 1px solid var(--border); flex-shrink: 0; }
.expr-add-detail-body { flex: 1; min-height: 0; overflow-y: auto; padding: 10px 12px; font-size: 13px; }
.expr-add-detail-body .empty-state { padding: 20px 12px; }
.expr-add-detail-body .empty-state p { font-size: 13px; }
.expr-add-hierarchy-panel { flex: 1; min-height: 0; border: 1px solid var(--border); border-radius: var(--radius); display: flex; flex-direction: column; overflow: hidden; }
.expr-add-hierarchy-body { flex: 1; min-height: 0; overflow: hidden; position: relative; }
.expr-add-hierarchy-body .hierarchy-graph-container { position: absolute; inset: 0; min-height: 0; border: none; border-radius: 0; }
.expr-add-hierarchy-body .hierarchy-graph-container.fullscreen { position: fixed; inset: 0; z-index: 9999; height: 100vh; min-height: unset; background: white; }
.expr-add-hierarchy-body .amh-canvas { position: relative; flex: 1; min-height: 0; }
.expr-add-hierarchy-body .amh-canvas > .vis-network { position: absolute !important; inset: 0; }
.expr-add-hierarchy-body .loading-inline { padding: 20px; text-align: center; color: var(--text-muted); font-size: 13px; }
.expr-add-hierarchy-body .empty-state { padding: 20px 12px; }
.expr-add-hierarchy-body .empty-state p { font-size: 13px; }

.expr-add-already-badge { background: #28a745; color: white; border-radius: 4px; text-align: center; padding: 4px 8px; font-size: 12px; font-weight: 500; margin-bottom: 8px; }

/* Add concepts: filters popup */
#expr-add-search-row { display: flex; flex-wrap: nowrap; }
.expr-add-filters-popup { position: absolute; top: 100%; right: 0; z-index: 200; background: white; border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; box-shadow: 0 4px 16px rgba(0,0,0,.12); width: 280px; margin-top: 6px; }
.expr-add-filters-popup .ms-dropdown { z-index: 210; }
.expr-add-filters-row { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.expr-add-filters-row label { font-size: 12px; font-weight: 600; color: var(--text-muted); min-width: 70px; }
.expr-add-filters-row .form-input-sm { padding: 3px 8px; font-size: 12px; }
.expr-add-filters-row select.form-input-sm { padding: 3px 6px; font-size: 12px; }

/* Add concepts: column filter row */
#expr-add-col-filter-row { display: none; }
#expr-add-results-table.add-show-col-filters #expr-add-col-filter-row { display: table-row; }
#expr-add-col-filter-row .column-filter { font-size: 11px; padding: 2px 6px; }

/* Add concepts: checkbox column in multi-select */
.expr-add-check-col { display: none; }
#expr-add-results-table.add-multi-select .expr-add-check-col { display: table-cell; }

/* Add concepts: active row (single-select focus) */
#expr-add-results-tbody tr.add-active-row { background: #e8f0fe; }
#expr-add-results-tbody tr.add-active-row:hover { background: #d4e4fa; }
#expr-add-results-tbody tr { cursor: pointer; }

@media (max-width: 900px) {
  .mapping-editor-layout { grid-template-columns: 1fr; height: auto; }
  .mapping-editor-pane { min-height: 300px; border-right: none; border-bottom: 1px solid var(--border); }
  .devtools-sql-layout { grid-template-columns: 1fr; height: auto; }
  .devtools-sql-left { border-right: none; border-bottom: 1px solid var(--border); min-height: 200px; }
  .devtools-sql-right { min-height: 300px; }
}

@media (max-width: 600px) {
  .form-row { grid-template-columns: 1fr; }
  .modal { width: 95vw; }
  .vocab-stats-grid { grid-template-columns: 1fr 1fr; }
}

/* Modal-box (alias for .modal) */
.modal-box {
  background: white;
  border-radius: 8px;
  box-shadow: var(--shadow-lg);
  max-width: 90vw;
  max-height: 85vh;
  overflow-y: auto;
}

/* Form label */
.form-label {
  display: block; font-size: 12px; font-weight: 600;
  text-transform: uppercase; letter-spacing: .5px;
  color: var(--text-muted); margin-bottom: 4px;
}

/* Project card actions menu */
.project-card { position: relative; }
.project-card-menu-btn {
  position: absolute; top: 10px; right: 10px;
  background: none; border: none; color: var(--text-muted);
  cursor: pointer; font-size: 16px; padding: 4px 8px;
  border-radius: var(--radius); opacity: 0; transition: opacity .15s;
}
.project-card:hover .project-card-menu-btn { opacity: 1; }
.project-card-menu-btn:hover { background: var(--gray-200); color: var(--text); }
.project-card-menu {
  position: absolute; top: 36px; right: 10px;
  background: white; border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow-lg);
  z-index: 50; min-width: 140px; padding: 4px 0;
  display: none;
}
.project-card-menu.visible { display: block; }
.project-card-menu-item {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 14px; font-size: 13px; cursor: pointer;
  color: var(--text); background: none; border: none;
  width: 100%; text-align: left; font-family: inherit;
}
.project-card-menu-item:hover { background: var(--gray-light); }
.project-card-menu-item.danger { color: var(--danger); }
.project-card-menu-item.danger:hover { background: #fff5f5; }

/* Markdown editor (side-by-side) */
.md-editor-wrap {
  display: flex; gap: 0; border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden; min-height: 200px;
}
.md-editor-pane {
  flex: 1; min-width: 0;
}
.md-editor-textarea {
  width: 100%; height: 100%; min-height: 200px;
  padding: 12px; border: none; outline: none; resize: none;
  font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
  font-size: 13px; line-height: 1.6; background: #fafbfc;
}
.md-editor-textarea:focus { background: #fff; }
.md-preview {
  padding: 16px 18px; overflow-y: auto;
  font-size: 13.5px; line-height: 1.7; color: var(--text);
  border-left: 1px solid var(--border); background: white;
}
.md-preview h1 { font-size: 18px; font-weight: 700; margin: 0 0 10px; padding-bottom: 6px; border-bottom: 1px solid var(--gray-200); }
.md-preview h2 { font-size: 16px; font-weight: 700; margin: 16px 0 8px; padding-bottom: 4px; border-bottom: 1px solid var(--gray-200); }
.md-preview h3 { font-size: 14.5px; font-weight: 700; margin: 14px 0 6px; }
.md-preview h4 { font-size: 13.5px; font-weight: 700; margin: 12px 0 4px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .3px; }
.md-preview h5, .md-preview h6 { font-size: 13px; font-weight: 600; margin: 10px 0 4px; color: var(--text-muted); }
.md-preview h1:first-child, .md-preview h2:first-child, .md-preview h3:first-child, .md-preview h4:first-child { margin-top: 0; }
.md-preview p { margin: 0 0 10px; }
.md-preview p:last-child { margin-bottom: 0; }
.md-preview ul, .md-preview ol { margin: 0 0 10px; padding-left: 22px; }
.md-preview li { margin-bottom: 3px; }
.md-preview li:last-child { margin-bottom: 0; }
.md-preview blockquote {
  margin: 0 0 10px; padding: 8px 14px;
  border-left: 3px solid var(--primary); background: var(--primary-light);
  border-radius: 0 var(--radius) var(--radius) 0; color: #3a5a7a; font-size: 13px;
}
.md-preview blockquote p { margin-bottom: 4px; }
.md-preview blockquote p:last-child { margin-bottom: 0; }
.md-preview code {
  font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
  font-size: 12px; background: var(--gray-light); border: 1px solid var(--gray-200);
  border-radius: 3px; padding: 1px 5px;
}
.md-preview pre {
  margin: 0 0 10px; padding: 10px 14px;
  background: #1e293b; color: #e2e8f0; border-radius: var(--radius);
  overflow-x: auto; font-size: 12px; line-height: 1.6;
}
.md-preview pre code { background: none; border: none; padding: 0; color: inherit; font-size: inherit; }
.md-preview table { border-collapse: collapse; width: 100%; margin: 0 0 10px; font-size: 13px; }
.md-preview table th, .md-preview table td { border: 1px solid var(--gray-200); padding: 6px 10px; text-align: left; }
.md-preview table th { background: var(--gray-light); font-weight: 600; }
.md-preview table tr:nth-child(even) td { background: #fafbfc; }
.md-preview hr { border: none; border-top: 1px solid var(--gray-200); margin: 14px 0; }
.md-preview a { color: var(--primary); text-decoration: none; }
.md-preview a:hover { text-decoration: underline; }
.md-preview strong { font-weight: 700; }
.md-preview-empty { color: #aaa; font-style: italic; font-size: 13px; }

/* Project CS edit tables */
#proj-tab-variables-edit { flex: 1; min-height: 0; margin-top: 16px; }
#proj-tab-variables-edit .panel-table-wrap { overflow-y: auto; }
#proj-tab-variables-edit table tbody tr { cursor: default; }
.proj-cs-remove-btn, .proj-cs-add-btn {
  background: none; border: none; cursor: pointer;
  font-size: 14px; padding: 4px 8px; border-radius: var(--radius);
}
.proj-cs-remove-btn { color: var(--danger); }
.proj-cs-remove-btn:hover { background: #fff5f5; }
.proj-cs-add-btn { color: var(--success); }
.proj-cs-add-btn:hover { background: #f0fff4; }

/* Footer */
.app-footer {
  text-align: center;
  padding: 12px 0;
  font-size: 12px;
  color: var(--text-muted);
  border-top: 1px solid var(--gray-200);
  margin-top: auto;
}
