/* ===========================
   Table Containers & Tables
=========================== */
/*!* ================================*/
/*   TABLE STYLES*/
/*   ================================*/
/*   Professional table styling for data inspector, monitoring, analytics*/
/*   Includes DataTables integration, filtering, sorting, and tab support*/
/*   ================================ *!*/

@import url("color_palette.css");

/* Tab Bar styling */
.tab-bar {
  display: flex;
  border-bottom: 2px solid #e1e4e8;
  background: linear-gradient(to bottom, #ffffff, #f8f9fa);
  padding: 0;
  margin: 0;
}

/* Tab buttons: modern flat design */
.tab-button {
  flex: 1;
  padding: 12px 16px;
  border: none;
  background: transparent;
  font-size: var(--font-size-md);
  font-weight: 500;
  color: #586069;
  cursor: pointer;
  transition: all 0.2s ease;
  position: relative;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.tab-button:hover {
  background-color: rgba(204, 102, 0, 0.05);
  color: var(--color-accent-orange);
}

.tab-button.active {
  color: var(--color-accent-orange);
  background-color: transparent;
}

.tab-button.active::after {
  content: "";
  position: absolute;
  bottom: -2px;
  left: 0;
  right: 0;
  height: 2px;
  background: var(--color-accent-orange);
}

/* ===========================
   Table Containers & Tables
=========================== */

/*!* --- Adjust DataTables Header Padding for Sort Icons --- *!*/
/*table.dataTable thead th {*/
/*  padding-right: 25px !important; !* increased from 20px *!*/
/*}*/

/*!* --- Force #data-table to use full width --- *!*/
/*#data-table {*/
/*  width: 100% !important;*/
/*}*/

/*!* Also ensure the DataTables wrapper uses full width *!*/
/*#data-table_wrapper {*/
/*  width: 100% !important;*/
/*}*/

/*!* --- Ensure Data Panel Table Container fills available height --- *!*/
/*#data-panel .table-container {*/
/*  max-height: none !important;*/
/*  height: 100%;*/
/*}*/

/*#data-panel .panel-content > #table-container,*/
/*#data-panel .panel-content > #card-container,*/
/*#data-panel .panel-content > .viewer-container {*/
/*  flex: 0 0 50%; !* do not grow or shrink—it’s always 50% of the parent *!*/
/*  overflow: auto;*/
/*}*/

/*!* 2. Any pane with .active fills its share of space *!*/
/*#data-panel .panel-content > .active {*/
/*  display: flex;*/
/*}*/

/* 1. Allow table cells to wrap/expand vertically */
#results-table td {
  white-space: normal; /* let text wrap onto multiple lines */
  vertical-align: top; /* ensure content aligns at the top */
}

/* 2. snippet‐cell logic (no change here) */
.snippet-cell {
  display: block; /* so that max-height actually pushes the row */
  max-height: 3em; /* show only ~2 lines by default */
  overflow: hidden;
  cursor: pointer;
}
.snippet-cell.expanded {
  max-height: none; /* remove the cap and let it grow */
}

/* 1. Let the table auto‐size and let cells wrap */
#results-table {
  table-layout: auto !important;
}
#results-table td,
#results-table th {
  white-space: normal !important;
  vertical-align: top;
}

/* 2. Wrap every cell’s content in a block that can be clipped */
.row-cell {
  display: block;
  width: 100%;
  overflow: hidden;
  /* we’ll only set max-height on “tr.truncated” */
}

/* 3. If a row is “truncated”, limit its height */
tr.truncated .row-cell {
  max-height: 3em; /* roughly two lines */
}

/* 4. When that same row gets “.expanded”, show full text */
tr.truncated.expanded .row-cell {
  max-height: none;
}

/* Media preview cells: thumbnail + title + secondary metadata.
   Delegated click on .media-cell opens the existing DocumentViewer. */
.row-cell--media {
  overflow: visible;
  max-height: none !important;
}
.media-cell {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 0;
  cursor: pointer;
  border-radius: 3px;
  transition: background 0.15s ease;
}
.media-cell:hover {
  background: var(--color-gray-50, rgba(255, 255, 255, 0.04));
}
.media-cell-thumb {
  flex: 0 0 auto;
  object-fit: cover;
  border: 1px solid var(--color-gray-300, #212d3f);
  border-radius: 3px;
  background: var(--color-gray-100, #0e1624);
}
.media-cell-thumb--fallback {
  object-fit: contain;
  padding: 10px;
  opacity: 0.7;
}
.media-cell-info {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.media-cell-title {
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.media-cell-secondary {
  font-size: var(--font-size-sm, 11px);
  opacity: 0.65;
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}
.media-cell-sep {
  opacity: 0.5;
}
tr:has(.media-cell) td {
  vertical-align: middle;
}

/* "Open all" button in the filter row when a media column is present.
   Skin comes from .table-action-btn (geodesy_panel_redesign.css) so it
   matches "Plot on map"; only the placement offset is local. */
.media-open-all {
  margin-right: 8px;
  vertical-align: middle;
}

/* Documents view — master/detail layout. Left: scrolling rich cards.
   Right (~75%): live DocumentViewer preview of the selected card.
   flex:1 + min-height:0 + overflow:hidden is required so the list's
   overflow-y:auto has a bounded height to scroll against (same pattern
   as .results-table-view). */
.results-documents-view {
  flex: 1;
  flex-direction: row;
  gap: 0;
  min-height: 0;
  overflow: hidden;
}
.doc-view-empty {
  padding: 24px;
  opacity: 0.6;
  text-align: center;
  width: 100%;
}
.doc-view-list {
  flex: 0 0 320px;
  min-width: 260px;
  max-width: 420px;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--gd-rim, #212d3f);
}
.doc-view-preview {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
  position: relative;
  background: var(--color-gray-100, #0b1220);
  overflow: hidden;
}
.doc-view-preview > * {
  width: 100%;
  height: 100%;
}
.doc-view-preview iframe {
  width: 100%;
  height: 100%;
  border: none;
}
.doc-view-preview-placeholder {
  padding: 40px;
  opacity: 0.5;
  text-align: center;
}
.doc-view-preview.has-doc .doc-view-preview-placeholder {
  display: none;
}

/* A document's card: a flat row like an entity list's (a quiet divider, the elevated
   surface on hover, dim amber when selected), its title in regular weight. */
.doc-card {
  border-bottom: 1px solid var(--gd-rim, #212d3f);
  padding: 8px 10px;
  cursor: pointer;
  transition: background var(--gd-t, 0.1s ease);
}
.doc-card:hover {
  background: var(--gd-elevated, #1a2333);
}
.doc-card.selected {
  background: var(--gd-amber-dim, rgba(224, 123, 0, 0.15));
}
.doc-card-header {
  display: flex;
  align-items: center;
  gap: 10px;
}
.doc-card-header .media-cell {
  padding: 0;
  flex: 0 0 auto;
  cursor: pointer;
}
.doc-card-header .media-cell .media-cell-info {
  display: none; /* title rendered by .doc-card-main */
}
.doc-card-main {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.doc-card-title {
  font-weight: 400;
  font-size: var(--gd-sz-lg, 13px);
  color: var(--gd-text-hi, #e8edf5);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.doc-card-meta {
  font-size: var(--gd-sz-sm, 11px);
  color: var(--gd-text-low, #8195ae);
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}
.doc-card-sep {
  opacity: 0.45;
}
.doc-card-snippet {
  margin-top: 6px;
  font-size: var(--gd-sz-sm, 12px);
  line-height: 1.4;
  color: var(--gd-text-mid, #8fa3bd);
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.doc-card-entities,
.doc-card-coords {
  margin-top: 6px;
}

/* A document's entity and coordinate pills (its card, the document search table, its map
   popup): the run bar's quiet outlined style, amber on hover; coordinates in mono. The
   panel's broad `.panel-content span` colour (geodesy_panel_redesign.css) would win over a
   single class, so each colour is also named under .panel-content. */
.entity-pill,
.coord-pill,
.panel-content .entity-pill,
.panel-content .coord-pill {
  display: inline-block;
  margin: 2px 4px 2px 0;
  padding: 1px 6px;
  border: 1px solid var(--gd-rim, #212d3f);
  border-radius: var(--gd-r, 2px);
  background: transparent;
  color: var(--gd-text-mid, #8fa3bd);
  font: 400 var(--gd-sz-sm, 12px) var(--gd-font-sans, sans-serif);
  cursor: pointer;
  white-space: nowrap;
  transition:
    border-color var(--gd-t, 0.1s ease),
    color var(--gd-t, 0.1s ease);
}
.coord-pill,
.panel-content .coord-pill {
  font-family: var(--gd-font-mono, monospace);
  font-size: var(--gd-sz-xs, 11px);
}
.entity-pill-type,
.panel-content .entity-pill-type {
  margin-inline-start: 4px;
  color: var(--gd-text-low, #8195ae);
}
.entity-pill:hover,
.coord-pill:hover,
.entity-pill:hover .entity-pill-type {
  border-color: var(--gd-amber, #e07b00);
  color: var(--gd-amber, #e07b00);
}

/* All tables: contained within container, scrollable with consistent scrollbars */
.panel .table-container,
.panel .dataTables_wrapper,
.panel .dataTables_scrollBody {
  max-height: calc(
    100vh - var(--menu-bar-height) - var(--panel-header-height) - 12rem
  ) !important; /* Leave room for horizontal scrollbar */
  overflow: auto !important;
  width: 100% !important;
}

/* Consistent scrollbar styling for all tables */
.panel .table-container::-webkit-scrollbar,
.panel .dataTables_wrapper::-webkit-scrollbar,
.panel .dataTables_scrollBody::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

.panel .table-container::-webkit-scrollbar-track,
.panel .dataTables_wrapper::-webkit-scrollbar-track,
.panel .dataTables_scrollBody::-webkit-scrollbar-track {
  background: var(--bg-secondary);
  border-radius: 4px;
}

.panel .table-container::-webkit-scrollbar-thumb,
.panel .dataTables_wrapper::-webkit-scrollbar-thumb,
.panel .dataTables_scrollBody::-webkit-scrollbar-thumb {
  background: var(--border-medium);
  border-radius: 4px;
}

.panel .table-container::-webkit-scrollbar-thumb:hover,
.panel .dataTables_wrapper::-webkit-scrollbar-thumb:hover,
.panel .dataTables_scrollBody::-webkit-scrollbar-thumb:hover {
  background: var(--border-dark);
}

/* ================================
   VIEW TOGGLE BUTTONS (TABLE/CARDS)
   ================================ */

.view-toggle {
  display: flex;
  gap: 0;
  margin-bottom: 12px;
  flex-shrink: 0;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  overflow: hidden;
  width: fit-content;
  background: var(--bg-secondary);
}

.view-btn {
  padding: 6px 16px;
  border: none;
  background: transparent;
  cursor: pointer;
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-medium);
  color: var(--text-secondary);
  transition: all var(--transition-fast);
  position: relative;
  border-right: 1px solid var(--border-light);
}

.view-btn:last-child {
  border-right: none;
}

.view-btn:hover:not(.active) {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

.view-btn.active {
  background: var(--color-accent-orange);
  color: var(--text-on-dark);
  font-weight: var(--font-weight-semibold);
}

/* ================================
   DATATABLE BASE STYLING
   Clean, professional table appearance
   ================================ */

/* Base table styling */
.table-container table.dataTable {
  border-collapse: collapse;
  width: 100%;
  font-size: var(--font-size-sm) !important;
  background: var(--bg-primary);
}

/* Header styling - uppercase, subtle, clean */
.table-container table.dataTable thead th {
  background: var(--color-gray-50);
  border-bottom: 1px solid var(--border-light);
  color: var(--color-gray-500);
  font-size: var(--font-size-sm) !important;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 8px 10px;
  text-align: left;
  white-space: nowrap;
}

.table-container table.dataTable thead th:hover {
  color: var(--color-gray-700);
}

/* A column's original source column(s), in italics under its name, as written. */
table.dataTable thead th .col-source {
  display: block;
  font-style: italic;
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
}

/* Sorted column header - accent color */
.table-container table.dataTable thead th.sorting_asc,
.table-container table.dataTable thead th.sorting_desc {
  color: var(--color-accent-orange);
}

/* Body cell styling */
.table-container table.dataTable tbody td {
  padding: 6px 10px;
  border-bottom: 1px solid var(--color-gray-100);
  color: var(--color-gray-700);
  vertical-align: middle;
  font-size: var(--font-size-sm) !important;
  line-height: 1.4;
}

/* Row hover - subtle highlight */
.table-container table.dataTable tbody tr:hover {
  background: var(--color-gray-50);
}

/* Alternating row colors - very subtle */
.table-container table.dataTable tbody tr.odd {
  background: var(--bg-primary);
}

.table-container table.dataTable tbody tr.even {
  background: rgba(0, 0, 0, 0.015);
}

/* Selected row */
.table-container table.dataTable tbody tr.selected {
  background: var(--orange-overlay-10);
}

/* Row an AI answer cites: highlighted until another citation is opened */
.table-container table.dataTable tbody tr.row-cited {
  background: var(--orange-overlay-10);
  box-shadow: inset 2px 0 0 var(--gd-amber, #e07b00);
}

/* ================================
   DATATABLES CONTROLS STYLING
   ================================ */

/* Filter bar layout */
.table-container .dataTables_wrapper .dataTables_filter {
  display: flex;
  align-items: center;
  justify-content: flex-end;
}

/* Filter/search input */
.table-container .dataTables_wrapper .dataTables_filter input {
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  padding: 5px 10px;
  font-size: var(--font-size-sm);
  color: var(--text-primary);
  background: var(--bg-primary);
  margin-left: 6px;
  transition: border-color var(--transition-fast);
}

.table-container .dataTables_wrapper .dataTables_filter input:focus {
  outline: none;
  border-color: var(--color-accent-orange);
}

.table-container .dataTables_wrapper .dataTables_filter label {
  font-size: var(--font-size-sm);
  color: var(--color-gray-500);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

/* Info text */
.table-container .dataTables_wrapper .dataTables_info {
  font-size: var(--font-size-sm);
  color: var(--color-gray-500);
  padding: 6px 0;
}

/* Pagination */
.table-container .dataTables_wrapper .dataTables_paginate {
  padding: 6px 0;
}

.table-container .dataTables_wrapper .dataTables_paginate .paginate_button {
  padding: 4px 10px;
  margin: 0 2px;
  border-radius: var(--radius-sm);
  font-size: var(--font-size-sm);
  color: var(--color-gray-600);
  background: transparent;
  border: 1px solid transparent;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.table-container
  .dataTables_wrapper
  .dataTables_paginate
  .paginate_button:hover:not(.disabled):not(.current) {
  background: var(--color-gray-100);
  color: var(--color-gray-800);
}

.table-container
  .dataTables_wrapper
  .dataTables_paginate
  .paginate_button.current {
  background: var(--color-accent-orange);
  color: var(--text-on-dark);
  border-color: var(--color-accent-orange);
  font-weight: 600;
}

.table-container
  .dataTables_wrapper
  .dataTables_paginate
  .paginate_button.disabled {
  color: var(--color-gray-300);
  cursor: not-allowed;
}

/* Export buttons */
.table-container .dataTables_wrapper .dt-buttons {
  margin-bottom: 6px;
}

.table-container .dataTables_wrapper .dt-buttons .dt-button {
  background: var(--bg-secondary);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  padding: 4px 10px;
  font-size: var(--font-size-sm);
  font-weight: 500;
  color: var(--color-gray-600);
  cursor: pointer;
  margin-right: 4px;
  transition: all var(--transition-fast);
}

.table-container .dataTables_wrapper .dt-buttons .dt-button:hover {
  background: var(--color-gray-100);
  color: var(--color-gray-800);
  border-color: var(--border-medium);
}

/* Length selector */
.table-container .dataTables_wrapper .dataTables_length select {
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  padding: 3px 6px;
  font-size: var(--font-size-sm);
  color: var(--text-primary);
  background: var(--bg-primary);
  margin: 0 4px;
}

.table-container .dataTables_wrapper .dataTables_length label {
  font-size: var(--font-size-sm);
  color: var(--color-gray-500);
}

/* A results table's controls: one bar that stays at the top of its scrolling body while
   the rows scroll. The filter leads; the count and pages follow; the table's sideways
   scroller sits under them (data_inspector.js _syncTopScroller), so it is always in view. */
.dataTables_wrapper .dt-top {
  position: sticky;
  top: 0;
  z-index: 3;
  background: var(--gd-base);
}
.dataTables_wrapper .dt-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 0;
}
.dataTables_wrapper .dt-controls .dataTables_info {
  margin-inline-start: auto;
}
.dataTables_wrapper .dt-controls .dataTables_info,
.dataTables_wrapper .dt-controls .dataTables_paginate {
  padding: 0 !important;
}
/* Drawn whenever the table is wider than its space, not only on hover (the app's
   scrollbars otherwise show on hover only) */
.dataTables_wrapper .dt-xbar {
  display: none;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: thin;
  scrollbar-color: var(--gd-stroke) var(--gd-void);
}
.dataTables_wrapper .dt-xbar.is-needed {
  display: block;
}
.dataTables_wrapper .dt-xbar > div {
  height: 1px;
}
/* The table scrolls sideways here; its own scrollbar is the bar's */
.dataTables_wrapper .dt-x {
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
}

/* ================================
   EMPTY/NULL VALUE STYLING
   ================================ */

.cell-empty {
  color: var(--color-gray-300);
  font-size: var(--font-size-sm);
  font-style: italic;
  user-select: none;
}

.cell-empty::before {
  content: "empty";
}

/* ================================
   ROW MENU (three-dot action button)
   ================================ */
.row-menu-col {
  width: 24px !important;
  padding: 4px 2px !important;
  text-align: center;
  cursor: default;
}
.row-menu-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  font-size: 18px;
  font-weight: 700;
  line-height: 1;
  color: var(--color-gray-600);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition-fast);
  user-select: none;
}
.row-menu-btn:hover {
  background: var(--color-gray-200);
  color: var(--color-gray-900);
}
/* Hide header background tint on menu column */
.table-container table.dataTable thead th.row-menu-col {
  background: var(--color-gray-50);
  border-bottom-color: var(--border-light);
}

/* ================================
   COLUMN MENU (header click)
   ================================ */
.col-menu {
  position: fixed;
  background: var(--bg-primary, #fff);
  border: 1px solid var(--border-light, #d1d5db);
  border-radius: var(--radius-sm, 4px);
  box-shadow: var(--shadow-md, 0 4px 6px rgba(0, 0, 0, 0.1));
  z-index: 10000;
  min-width: 100px;
  padding: 2px 0;
}
.col-menu-item {
  padding: 4px 10px;
  cursor: pointer;
  font-size: var(--font-size-xs);
  color: var(--text-secondary, #4b5563);
  transition: all 0.15s ease;
}
.col-menu-item:hover {
  background: var(--bg-tertiary, #f3f4f6);
  color: var(--text-primary, #1a1d23);
}
