/* ================================
   LAYOUT - APP STRUCTURE
   ================================
   Core layout styles for app container,
   sidebars, main content, map, and panels
   ================================ */

@import url("color_palette.css");

/* ===========================
   CSS Variables for Layout
=========================== */
:root {
  --sidebar-width: 48px;
  --expanded-width: 120px;

  /* Panel width hierarchy */
  --panel-width-default: clamp(300px, 25vw, 450px);
  --panel-width-expanded: clamp(400px, 40vw, 800px);
  --panel-width-fifty: clamp(500px, 50vw, 1000px);
  --panel-width-sixty: clamp(550px, 60vw, 1200px);
  --panel-width-very-expanded: clamp(600px, 70vw, 1400px);
  --panel-width-small: 250px;

  --panel-gap: 0.5rem;
  --menu-bar-height: 40px;
  --panel-header-height: 50px;
}

/* Responsive variables for smaller screens */
@media (max-width: 1024px) {
  :root {
    --sidebar-width: clamp(50px, 6vw, 70px);
    --expanded-width: clamp(140px, 20vw, 180px);
  }
}

/* ===========================
   Body and App Container
=========================== */
body {
  overflow: hidden;
  margin: 0;
  padding: 0;
}

#app {
  display: flex;
  flex-direction: row;
  height: 100vh;
  overflow: hidden;
}

.hidden {
  display: none !important;
}

/* ===========================
   Left Sidebar
=========================== */
#sidebar {
  width: var(--sidebar-width);
  background-color: rgba(0, 0, 0, 0.8);
  display: flex;
  flex-direction: column;
  padding: 10px 0;
  box-sizing: border-box;
  overflow-y: auto;
  transition: width 0.3s;
  flex-shrink: 0;
  z-index: 1001;
}

#sidebar:hover {
  width: var(--expanded-width);
}

.sidebar-btn.icon-btn {
  position: relative;
  display: flex;
  align-items: center;
  margin: 3px 4px;
  padding: 5px;
  width: calc(100% - 8px);
  overflow: hidden;
  white-space: nowrap;
  transition:
    background-color 0.2s ease,
    color 0.2s ease;
}

.sidebar-icon {
  font-size: var(--font-size-sm);
  margin: 0 auto;
  transform: translateY(5px);
  color: #fff;
}

.sidebar-text {
  flex: 1;
  opacity: 0;
  transform: translateY(5px);
  transition: opacity 0.2s ease;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: var(--font-size-xs);
}

#sidebar:hover .sidebar-text {
  opacity: 1;
}

.sidebar-divider {
  width: 80%;
  margin: 10px auto;
  border: none;
  border-top: 1px solid #555;
}

.sidebar-btn:hover {
  background-color: #555;
  cursor: pointer;
}

/* Sidebar always retracted by default, expands on hover */

/* ===========================
   Right Sidebar
=========================== */
#right-sidebar {
  position: fixed;
  top: 0;
  right: 0;
  width: var(--sidebar-width);
  height: 100%;
  background-color: #222;
  border-left: 1px solid rgba(255, 255, 255, 0.8);
  box-sizing: border-box;
  overflow: hidden;
  transition: width 0.3s ease;
  z-index: 1000;
  color: #fff;
  font-family: "Arial", sans-serif;
}

#right-sidebar:hover {
  width: var(--expanded-width);
}

#right-sidebar .sidebar-header {
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: rgba(0, 0, 0, 0.9);
  transition: transform 0.3s ease;
  overflow: hidden;
}

#right-sidebar .sidebar-header i {
  font-size: var(--font-size-3xl);
  transform: rotate(90deg);
  transition:
    transform 0.3s ease,
    font-size 0.3s ease;
}

#right-sidebar:hover .sidebar-header i {
  transform: rotate(0deg);
  font-size: var(--font-size-lg);
}

#right-sidebar .sidebar-content {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease;
  padding: 0 5px;
}

#right-sidebar:hover .sidebar-content {
  max-height: 1000px;
  margin-top: 2px;
}

#right-sidebar .section h4 {
  font-size: var(--font-size-lg);
  margin-bottom: 2px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.2);
  padding-bottom: 2px;
  color: #fff;
}

#right-sidebar button.sidebar-btn {
  display: block;
  width: calc(100% - 8px);
  padding: 4px 6px;
  margin: 2px auto;
  line-height: 2.5;
  min-height: 0;
  height: auto;
  font-size: var(--font-size-base);
  cursor: pointer;
  background-color: #444;
  color: #fff;
  border: none;
  border-radius: 2px;
  transition:
    transform 0.2s ease,
    background-color 0.3s ease;
}

#right-sidebar button.sidebar-btn:hover {
  transform: scale(1);
  background-color: #555;
}

/* ===========================
   Main Content & Map
=========================== */
#main-content {
  position: relative;
  flex: 1;
  overflow: hidden;
}

#map {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 0;
}

/* ===========================
   Panels Container
=========================== */
#panels-container {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: 100%;
  display: flex;
  flex-wrap: nowrap;
  gap: var(--panel-gap);
  z-index: 1000;
  margin: 0;
  padding: 0;
  pointer-events: none;
  overflow-x: hidden;
  overflow-y: hidden;
}

#panels-container > .panel {
  pointer-events: auto;
  flex: 0 1 auto; /* don't grow, but allow shrink to fit viewport */
  min-width: 250px;
  max-width: 95vw; /* always leave some map visible */
}

/* Every panel declares its own width. Without this a panel is `width: auto`
   inside a flex row, which resolves to max-content — so the widest thing
   rendered inside it (a results table, a pre-formatted AI answer, a long
   source key) silently became the panel width, and the panel jumped whenever
   that content changed. Inner scroll containers handle the overflow instead.
   Low specificity on purpose: .panel.expanded / .very-expanded / per-panel id
   rules / inline widths set by JS all still win. */
.panel {
  width: clamp(360px, 30vw, 680px);
}

/* Two-column layout (inputs + method), so it needs more than the base. */
#querying-panel {
  width: clamp(600px, 46vw, 900px);
}

/* Holds wide result tables; sized so it and the querying panel fit side by
   side without adjustPanels() having to scale either one down. */
#search-results-panel {
  width: clamp(520px, 44vw, 1000px);
}

/* ===========================
   Map retracted
   body.map-retracted (map_retract.js) hides the map and lets the panels fill
   the screen as one surface. Panels take their part from data-retract-role;
   the underlay rules above are untouched.
=========================== */

/* Minimum widths while retracted. map_retract.js reads these to decide how
   many panels fit side by side. The anchor's is the least its two columns
   need (querying_panel.css), so nothing in it is cut off; with the stage's
   it fits a 1280px laptop screen. */
.panel {
  --retract-floor: 520px;
}
.panel[data-retract-role="anchor"] {
  --retract-floor: 648px;
}
.panel[data-retract-role="side"] {
  --retract-floor: 420px;
}

/* Hidden, not removed: the map keeps its size, so layers and camera moves
   made while it is hidden are right when it comes back. Descendants are named
   because the map library marks its controls visible itself. */
body.map-retracted #map,
body.map-retracted #map *,
body.map-retracted #map-layer-toggles,
body.map-retracted #floating-quick-controls,
body.map-retracted .map-status-display,
body.map-retracted #universal-back-button,
body.map-retracted #top-toggle-bar {
  visibility: hidden !important;
}

body.map-retracted #main-content {
  background: var(--gd-base);
}

/* The panels stop short of the far edge, leaving a strip for the drawer
   tabs, which stack there instead of sitting over a panel header. */
body.map-retracted #panels-container {
  gap: 0;
  width: calc(100% - 48px);
  pointer-events: auto;
}
body.map-retracted .drawer-tab {
  right: 8px;
}
body.map-retracted .drawer-tab[data-drawer="watch"] {
  top: calc(var(--menu-bar-height, 50px) + 48px);
}
body.map-retracted .drawer {
  z-index: 1001; /* over the panels, which now reach the drawer's side */
}

/* Grow weights three orders apart act as a priority: the spare width goes to
   the stage if one is open, else to the anchor, else to the side panel. */
body.map-retracted #panels-container > .panel {
  flex: 1000000 1 0;
  /* Never wider than the row: on a narrow screen the last panel fills it. */
  min-width: min(var(--retract-floor), 100%);
  max-width: none;
  margin: 0;
  border-width: 0 !important;
  border-inline-end-width: 1px !important;
  border-radius: 0 !important;
  box-shadow: none !important;
}
body.map-retracted #panels-container > .panel[data-retract-role="anchor"] {
  flex: 1000 1 auto;
}
body.map-retracted #panels-container > .panel[data-retract-role="side"] {
  flex: 1 1 auto;
  order: 1;
}

/* A subordinate panel floats beside its parent. With the parent filling the
   row that is off screen, so it sits inside the far edge instead. */
body.map-retracted .panel.subordinate {
  left: auto !important;
  right: 56px !important;
}

/* Only the anchor has a width of its own to drag. */
body.map-retracted
  #panels-container
  > .panel:not([data-retract-role="anchor"])
  > .panel-resize-edge {
  display: none;
}

/* A stray header click would close a full-screen panel, so only the close
   button closes it; the last panel standing has none. */
body.map-retracted #panels-container > .panel > .panel-header {
  pointer-events: none;
}
body.map-retracted #panels-container > .panel > .panel-header button {
  pointer-events: auto;
}
body.map-retract-lone [data-retract-role="anchor"] > .panel-header .close-btn {
  display: none !important;
}

/* Reading text keeps a readable measure in a wide Workspace; tables, graphs
   and lists use the full width. */
body.map-retracted .querying-method-column > * {
  box-sizing: border-box;
  width: 100%;
  max-width: 760px;
  margin-inline: auto;
}

/* ===========================
   Utility Classes
=========================== */
.table-container {
  max-height: 300px;
  overflow-x: auto;
  overflow-y: auto;
  border: 1px solid #ddd;
  margin-top: 10px;
}
