/* panel.css -- left-rail object browser styling.
   strictly uses travw-design tokens from tokens.css. NOT a port of
   osprey.css's rhino-flavored palette. */

#panel {
  display: flex;
  flex-direction: column;
  background: var(--bg);
  border-left: 1px solid var(--rule);
  min-width: 0;
  overflow: hidden;
}

#panel-toolbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--rule);
  font-size: var(--t-xs);
  font-family: var(--font-mono);
  color: var(--fg-3);
}

/* ---- search row (also hosts the collapse-panel button) ---- */
#panel-search-row {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--rule);
}
#panel-search {
  flex: 1 1 auto;
  min-width: 0;
  background: var(--bg-2);
  color: var(--fg);
  border: 1px solid var(--rule-strong);
  padding: 0.35rem 0.55rem;
  font-family: var(--font-sans);
  font-size: var(--t-sm);
  border-radius: 0;
  outline: none;
}
#panel-search:focus { border-color: var(--accent); }
#panel-search::placeholder { color: var(--fg-3); }

/* ---- filter row: collapsed to a single "Types" dropdown button ---- */
#panel-filter-row {
  flex: 0 0 auto;
  position: relative; /* anchor the absolutely-positioned popover */
  display: flex;
  align-items: center;
  padding: 0.4rem 0.75rem;
  border-bottom: 1px solid var(--rule);
  font-family: var(--font-mono);
}
#panel-types-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.25rem 0.5rem;
  background: transparent;
  border: 1px solid var(--rule-strong);
  color: var(--fg-2);
  font-family: var(--font-mono);
  font-size: var(--t-xs);
  cursor: pointer;
  border-radius: 0;
  user-select: none;
  letter-spacing: 0.02em;
  line-height: 1.4;
}
#panel-types-btn:hover { color: var(--fg); border-color: var(--fg-3); }
#panel-types-btn[aria-expanded="true"],
#panel-types-btn.partial {
  color: var(--accent);
  border-color: var(--accent);
}
#panel-types-btn .types-count { color: var(--fg-3); }
#panel-types-btn.partial .types-count { color: var(--accent); }
#panel-types-btn .types-caret {
  font-size: 0.65rem;
  color: var(--fg-3);
}
#panel-types-btn[aria-expanded="true"] .types-caret { color: var(--accent); }

.filter-link {
  cursor: pointer;
  user-select: none;
  font-size: var(--t-xs);
  color: var(--fg-2);
  margin-left: 0.25rem;
  border-bottom: 1px dotted transparent;
  transition: color 140ms ease, border-color 140ms ease;
}
.filter-link:hover { color: var(--accent); border-bottom-color: var(--accent); }

/* ---- types popover ---- */
#panel-types-popover {
  position: absolute;
  top: 100%;
  left: 0.5rem;
  right: 0.5rem;
  margin-top: 0.1rem;
  background: var(--bg);
  border: 1px solid var(--rule-strong);
  z-index: 14;
  max-height: 70vh;
  overflow-y: auto;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.6);
}
#panel-types-popover[hidden] { display: none; }
.types-popover-header {
  display: flex;
  gap: 0.5rem;
  padding: 0.4rem 0.6rem;
  border-bottom: 1px solid var(--rule);
}
.types-popover-header .filter-link { margin-left: 0; }
#panel-types-list {
  padding: 0.2rem 0;
}
.types-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.25rem 0.7rem;
  cursor: pointer;
  font-family: var(--font-mono);
  font-size: var(--t-xs);
  user-select: none;
}
.types-row:hover { background: var(--bg-2); }
.types-row input[type="checkbox"] {
  flex-shrink: 0;
  width: 0.85rem;
  height: 0.85rem;
  accent-color: var(--accent);
  cursor: pointer;
  margin: 0;
}
.types-row .types-badge {
  flex-shrink: 0;
  font-family: var(--font-mono);
  font-size: 0.625rem;
  padding: 0 0.3rem;
  border: 1px solid var(--rule-strong);
  color: var(--fg-3);
  letter-spacing: 0.05em;
  text-transform: uppercase;
  line-height: 1.4;
}
/* reuse the same per-type accent map as the tree-leaf badges */
.types-row .types-badge.type-brep        { color: var(--accent); border-color: var(--accent); }
.types-row .types-badge.type-extrusion   { color: var(--warn);   border-color: var(--warn); }
.types-row .types-badge.type-curve       { color: var(--fg-2); }
.types-row .types-badge.type-mesh        { color: var(--ok);     border-color: var(--ok); }
.types-row .types-badge.type-subd        { color: var(--ok);     border-color: var(--ok); }
.types-row .types-badge.type-instancereference { color: var(--err); border-color: var(--err); }
.types-row .types-badge.type-annotation  { color: var(--fg-2); }
.types-row .types-badge.type-hatch       { color: var(--fg-2); }
.types-row .types-name {
  flex: 1 1 auto;
  color: var(--fg);
}
.types-row .types-row-count {
  flex-shrink: 0;
  color: var(--fg-3);
  font-size: 0.7rem;
}

.tree-action {
  cursor: pointer;
  user-select: none;
  color: var(--fg-2);
  border-bottom: 1px dotted transparent;
  transition: color 140ms ease, border-color 140ms ease;
}
.tree-action:hover {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

#panel-object-count {
  margin-left: auto;
  color: var(--fg-3);
}

#panel-selected-count {
  margin-left: auto;
  color: var(--accent);
}
#panel-selected-count[hidden] { display: none; }
/* when both are visible, selected pushes to the right and object-count
   loses its auto-margin so they sit beside one another with a gap. */
#panel-selected-count:not([hidden]) + #panel-object-count {
  margin-left: 0.75rem;
}

#panel-tree {
  flex: 1 1 auto;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 0.25rem 0;
  font-size: var(--t-sm);
  line-height: 1.5;
}

#panel-empty {
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 1.5rem 1rem;
  color: var(--fg-3);
  font-size: var(--t-sm);
  line-height: 1.5;
}
#panel-empty[hidden] { display: none; }

/* ---- tree rows ---- */

.tree-node { user-select: none; }

.tree-group {
  display: flex;
  align-items: center;
  cursor: pointer;
  padding: 0.15rem 0.6rem 0.15rem 0;
  white-space: nowrap;
  color: var(--fg-2);
  font-family: var(--font-mono);
  font-size: var(--t-xs);
}
.tree-group:hover { background: var(--bg-2); color: var(--fg); }
.tree-group.selected {
  background: rgba(21, 167, 159, 0.15);
  color: var(--accent);
}
.tree-group.selected .tree-group-count { color: var(--accent); }

.tree-toggle {
  width: 1rem;
  flex-shrink: 0;
  text-align: center;
  color: var(--fg-3);
  font-size: 0.65rem;
  line-height: 1;
}
.tree-toggle:hover { color: var(--fg); }

.tree-group-label {
  overflow: hidden;
  text-overflow: ellipsis;
  letter-spacing: 0.01em;
  flex: 1 1 auto;
  min-width: 0;
}

.tree-group-count {
  color: var(--fg-3);
  font-size: var(--t-xs);
  margin-left: 0.4rem;
  flex-shrink: 0;
}

/* lightbulb visibility toggle -- pinned to the far right of the row.
   lit = visible (warn yellow), dark = hidden (fg-3 outline only).
   matches rhino's layer-panel metaphor. */
.layer-bulb {
  flex-shrink: 0;
  margin-left: 0.5rem;
  margin-right: 0.15rem;
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.layer-bulb .bulb-glass {
  fill: var(--warn);
  stroke: var(--warn);
  stroke-width: 0.5;
  opacity: 0.9;
}
.layer-bulb .bulb-base {
  stroke: var(--fg-2);
  stroke-width: 1;
  stroke-linecap: round;
  fill: none;
}
.layer-bulb:hover .bulb-glass { opacity: 1; }
.layer-bulb:hover .bulb-base { stroke: var(--fg); }
.layer-bulb.off .bulb-glass {
  fill: none;
  stroke: var(--fg-3);
  stroke-width: 1;
  opacity: 1;
}
.layer-bulb.off .bulb-base { stroke: var(--fg-3); }
.layer-bulb.off:hover .bulb-glass { stroke: var(--fg-2); }
.layer-bulb.off:hover .bulb-base { stroke: var(--fg-2); }

.tree-children { display: none; }
.tree-node.expanded > .tree-children { display: block; }

/* layer-hidden: the bulb has been clicked off. dim the row + leaves so
   it's obvious the layer's objects aren't currently being rendered.
   the row stays clickable so the user can toggle the bulb back on. */
.tree-node.layer-hidden > .tree-group .tree-group-label,
.tree-node.layer-hidden > .tree-group .tree-group-count {
  color: var(--fg-3);
  text-decoration: line-through;
  text-decoration-color: var(--fg-3);
}
.tree-leaf.layer-hidden { opacity: 0.45; }
.tree-leaf.layer-hidden .tree-leaf-name {
  color: var(--fg-3);
  text-decoration: line-through;
}

.tree-leaf {
  display: flex;
  align-items: center;
  cursor: pointer;
  padding: 0.1rem 0.6rem 0.1rem 0;
  white-space: nowrap;
  overflow: hidden;
}
.tree-leaf:hover { background: var(--bg-2); }
.tree-leaf.selected {
  background: rgba(21, 167, 159, 0.22);
  outline: 1px solid var(--accent);
  outline-offset: -1px;
}
.tree-leaf.selected .tree-leaf-name { color: var(--fg); }
.tree-leaf.selected .tree-leaf-badge { border-color: var(--accent); }

.tree-leaf-badge {
  flex-shrink: 0;
  font-family: var(--font-mono);
  font-size: 0.625rem;
  padding: 0 0.3rem;
  margin-right: 0.4rem;
  border: 1px solid var(--rule-strong);
  color: var(--fg-3);
  letter-spacing: 0.05em;
  text-transform: uppercase;
  line-height: 1.4;
}

/* per-type accents -- pulled from travw-design semantic palette where it
   fits, else neutral. keep these subtle; the panel is mostly text. */
.tree-leaf-badge.type-brep        { color: var(--accent); border-color: var(--accent); }
.tree-leaf-badge.type-extrusion   { color: var(--warn);   border-color: var(--warn); }
.tree-leaf-badge.type-curve       { color: var(--fg-2); }
.tree-leaf-badge.type-mesh        { color: var(--ok);     border-color: var(--ok); }
.tree-leaf-badge.type-subd        { color: var(--ok);     border-color: var(--ok); }
.tree-leaf-badge.type-instancereference { color: var(--err); border-color: var(--err); }
.tree-leaf-badge.type-annotation  { color: var(--fg-2); }
.tree-leaf-badge.type-hatch       { color: var(--fg-2); }

.tree-leaf-name {
  color: var(--fg);
  overflow: hidden;
  text-overflow: ellipsis;
}
.tree-leaf-name.unnamed {
  color: var(--fg-3);
  font-style: italic;
  font-family: var(--font-mono);
}

/* ---- collapsible sections (layers, details) ---- */
.panel-section {
  flex: 0 0 auto;
  border-top: 1px solid var(--rule);
  display: flex;
  flex-direction: column;
  min-height: 0;
  max-height: 40%;
}
.panel-section-header {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.35rem 0.75rem;
  background: var(--bg);
  font-family: var(--font-mono);
  font-size: var(--t-xs);
  color: var(--fg-2);
  cursor: pointer;
  user-select: none;
}
.panel-section-header:hover { color: var(--fg); }
.section-chevron {
  font-size: 0.65rem;
  width: 0.75rem;
  text-align: center;
  color: var(--fg-3);
}
.section-title { letter-spacing: 0.05em; text-transform: uppercase; }
.section-meta { margin-left: auto; color: var(--fg-3); }
.panel-section.collapsed .section-chevron { transform: rotate(-90deg); }
.panel-section.collapsed .panel-section-body { display: none; }
.panel-section-body {
  overflow-y: auto;
  padding: 0.25rem 0;
  font-size: var(--t-xs);
}

/* ---- layers panel ---- */
.layer-row {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.15rem 0.75rem;
  cursor: pointer;
  white-space: nowrap;
  font-family: var(--font-mono);
}
.layer-row:hover { background: var(--bg-2); }
.layer-row.hidden-state .layer-name { color: var(--fg-3); text-decoration: line-through; }
.layer-swatch {
  flex-shrink: 0;
  width: 0.75rem;
  height: 0.75rem;
  border: 1px solid var(--rule-strong);
  background: var(--fg-3);
}
.layer-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--fg);
}
.layer-toggle {
  flex-shrink: 0;
  color: var(--fg-3);
  font-size: 0.7rem;
  padding: 0 0.25rem;
  user-select: none;
}
.layer-toggle:hover { color: var(--fg); }
.layer-toggle.off { color: var(--fg-3); text-decoration: line-through; }
.layer-badge {
  flex-shrink: 0;
  color: var(--warn);
  font-size: 0.55rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  border: 1px solid var(--warn);
  padding: 0 0.25rem;
  line-height: 1.4;
}

/* ---- detail panel ---- */
.detail-empty {
  color: var(--fg-3);
  font-style: italic;
  padding: 0.5rem 0.75rem;
}
.detail-name {
  padding: 0.4rem 0.75rem 0.1rem;
  font-size: var(--t-sm);
  color: var(--fg);
  font-weight: 500;
  word-break: break-all;
}
.detail-layer-path {
  padding: 0 0.75rem 0.1rem;
  color: var(--fg-2);
  font-family: var(--font-mono);
  font-size: var(--t-xs);
}
.detail-row {
  display: flex;
  gap: 0.5rem;
  padding: 0.1rem 0.75rem;
  font-family: var(--font-mono);
  font-size: var(--t-xs);
}
.detail-row .detail-key {
  flex: 0 0 5.5rem;
  color: var(--fg-3);
  text-transform: lowercase;
}
.detail-row .detail-val {
  flex: 1;
  color: var(--fg);
  word-break: break-all;
}
.detail-section-rule {
  border-top: 1px solid var(--rule);
  margin: 0.3rem 0;
}
.detail-userstrings-header,
.detail-common-header {
  padding: 0.25rem 0.75rem 0.15rem;
  color: var(--fg-3);
  font-family: var(--font-mono);
  font-size: 0.65rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}
.detail-id {
  display: flex;
  gap: 0.5rem;
  align-items: baseline;
  padding: 0.25rem 0.75rem;
  font-family: var(--font-mono);
  font-size: var(--t-xs);
  cursor: pointer;
  color: var(--fg-2);
}
.detail-id:hover { color: var(--accent); }
.detail-id .id-label { color: var(--fg-3); flex: 0 0 5.5rem; }
.detail-id .id-value { word-break: break-all; }
.detail-id.copied .id-value { color: var(--ok); }
.detail-id-note {
  padding: 0 0.75rem 0.4rem;
  font-family: var(--font-mono);
  font-size: 0.65rem;
  color: var(--fg-3);
  font-style: italic;
}
.detail-multi-summary {
  padding: 0.4rem 0.75rem;
  color: var(--fg);
  font-family: var(--font-mono);
  font-size: var(--t-sm);
}

/* ---- narrow viewport sheet (<= 700px) ---- */

/* desktop hides the mobile sheet header entirely */
#panel-sheet-header { display: none; }

@media (max-width: 700px) {
  /* mobile: panel becomes a bottom sheet with three snap states.
     peek (default) keeps the view-tabs + viewport-controls always
     accessible; pull up to half or full to reveal search / tree /
     details. canvas stays full-screen behind the sheet. */
  #panel {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    top: auto;
    width: 100%;
    height: var(--sheet-peek-h, 138px);
    max-height: 100vh;
    transform: none;
    transition: height 220ms cubic-bezier(0.2, 0.8, 0.2, 1);
    z-index: 12;
    border-left: none;
    border-top: 1px solid var(--rule-strong);
    box-shadow: 0 -8px 24px rgba(0, 0, 0, 0.6);
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }
  #panel.dragging { transition: none; }
  #panel.sheet-peek { height: var(--sheet-peek-h, 138px); }
  #panel.sheet-half { height: 50vh; }
  #panel.sheet-full { height: 92vh; }

  /* sheet header is always visible -- contains the grab handle + the
     view-tabs + viewport-controls that JS reflows into it on mobile. */
  #panel-sheet-header {
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    background: var(--bg);
  }
  #panel-sheet-grabber {
    height: 22px;
    cursor: grab;
    touch-action: none;
    position: relative;
    user-select: none;
  }
  #panel-sheet-grabber::before {
    content: "";
    position: absolute;
    top: 8px;
    left: 50%;
    transform: translateX(-50%);
    width: 38px;
    height: 4px;
    background: var(--fg-3);
    border-radius: 2px;
    transition: background 140ms ease;
  }
  #panel-sheet-grabber:active::before,
  #panel.dragging #panel-sheet-grabber::before { background: var(--fg-2); }
  #panel.dragging #panel-sheet-grabber { cursor: grabbing; }
  #panel-sheet-stage-row {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    padding-bottom: 0.35rem;
    border-bottom: 1px solid var(--rule);
  }

  /* view-tabs + viewport-controls when reflowed into the sheet header.
     stretch full-width with evenly distributed buttons. */
  #panel-sheet-stage-row #view-tabs,
  #panel-sheet-stage-row #viewport-controls {
    position: static;
    inset: auto;
    z-index: auto;
    display: flex;
    width: 100%;
    padding: 0;
  }
  #panel-sheet-stage-row .view-tab {
    flex: 1 1 0;
    justify-content: center;
    padding: 0.45rem 0.3rem;
    font-size: var(--t-xs);
  }
  /* hotkey indicators are mouse/keyboard affordances; drop on touch */
  #panel-sheet-stage-row .view-tab-key { display: none; }
  /* ortho toggle keeps its slight separation */
  #panel-sheet-stage-row .ortho-tab { margin-left: 0.25rem; }
  /* display dropdown popover should expand UPWARD inside the sheet so
     it doesn't render off-screen above the sheet header */
  #panel-sheet-stage-row .vp-group { position: relative; flex: 1 1 0; }
  #panel-sheet-stage-row #display-popover { bottom: 100%; right: 0; }

  /* on mobile, hide the desktop-only collapse / resize / expand handles. */
  #panel-collapse,
  #panel-resizer,
  #panel-expand { display: none !important; }

  /* sections inside the sheet body shouldn't gobble vertical space */
  .panel-section { max-height: 35vh; }

  /* chrome at top stays minimal on mobile: brand + title + download.
     no flex-wrap needed since Objects toggle is gone. */
  .viewer-chrome {
    padding: 0.45rem 0.65rem;
  }
  .viewer-chrome .left { flex: 1 1 auto; min-width: 0; }
  .viewer-chrome .title { max-width: none; flex: 1 1 auto; }
}
