/* ============================================================
   App Shell — Phase 31 unified BIM shell layer.
   Owns: left nav icons, expanded sidebar tabs, version
   timeline drawer, contextual toolbar morph, properties
   panel tabs, presence bar, responsive breakpoints.
   Does NOT own: viewport canvases, modals, Three.js scene.
   ============================================================ */

/* ── Design tokens (cinematic dark palette) ────────────────
   Sourced from LIBER Creative dark references.             */
:root {
  --shell-bg:           #080d14;
  --shell-surface:      #0d1520;
  --shell-panel:        #111b28;
  --shell-border:       rgba(255,255,255,0.08);
  --shell-border-hover: rgba(52,121,196,0.4);
  --shell-accent:       #3479c4;
  --shell-accent-dim:   rgba(52,121,196,0.15);
  --shell-text:         #c8d4e3;
  --shell-muted:        rgba(200,212,227,0.4);
  --shell-icon-active:  #5b9bd5;
  --shell-warn:         #f59e0b;
  --shell-success:      #4aad6e;
  --shell-badge-beta:   rgba(52,121,196,0.22);
  --shell-focus:        0 0 0 2px #3479c4, 0 0 0 4px rgba(52,121,196,0.15);
}

/* ── Icon-rail (collapsed left nav strip) ─────────────────── */
#nav-rail {
  position: fixed;
  left: 0; top: 40px; bottom: 0;
  width: 44px;
  background: var(--shell-bg);
  border-right: 1px solid var(--shell-border);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 8px 0;
  gap: 2px;
  z-index: 100;
  transition: width 0.2s var(--ease-out, cubic-bezier(0.16,1,0.3,1));
}

.nav-rail-btn {
  position: relative;
  width: 36px; height: 36px;
  border-radius: 8px;
  background: none;
  border: none;
  color: var(--shell-muted);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.12s, color 0.12s;
  flex-shrink: 0;
}
.nav-rail-btn:hover {
  background: rgba(255,255,255,0.05);
  color: var(--shell-text);
}
.nav-rail-btn.active {
  background: var(--shell-accent-dim);
  color: var(--shell-icon-active);
}
.nav-rail-btn:focus-visible { box-shadow: var(--shell-focus); outline: none; }
.nav-rail-btn svg { width: 16px; height: 16px; }

/* Tooltip on hover */
.nav-rail-btn::after {
  content: attr(data-tooltip);
  position: absolute;
  left: calc(100% + 8px);
  top: 50%; transform: translateY(-50%);
  white-space: nowrap;
  background: rgba(13,21,32,0.97);
  border: 1px solid var(--shell-border);
  border-radius: 6px;
  padding: 5px 10px;
  font-size: 11px; font-weight: 600;
  color: var(--shell-text);
  font-family: 'DM Sans', sans-serif;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.1s;
  z-index: 200;
  box-shadow: 0 4px 16px rgba(0,0,0,0.4);
}
.nav-rail-btn:hover::after { opacity: 1; }

/* Divider in nav rail */
.nav-rail-divider {
  width: 24px;
  height: 1px;
  background: var(--shell-border);
  margin: 4px 0;
  flex-shrink: 0;
}

/* ── Expanded sidebar panel ────────────────────────────────── */
#sidebar-expanded {
  position: fixed;
  left: 44px; top: 40px; bottom: 0;
  width: 0;
  overflow: hidden;
  background: var(--shell-surface);
  border-right: 1px solid var(--shell-border);
  z-index: 99;
  transition: width 0.22s cubic-bezier(0.16,1,0.3,1);
  display: flex;
  flex-direction: column;
}
#sidebar-expanded.open {
  width: 240px;
}

.sidebar-pane {
  display: none;
  flex-direction: column;
  flex: 1;
  overflow: hidden;
  width: 240px;
}
.sidebar-pane.active {
  display: flex;
}

.sidebar-pane-header {
  padding: 12px 14px 10px;
  border-bottom: 1px solid var(--shell-border);
  flex-shrink: 0;
}
.sidebar-pane-title {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--shell-muted);
  margin-bottom: 2px;
}
.sidebar-pane-desc {
  font-size: 11px;
  color: var(--shell-muted);
  line-height: 1.4;
}
.sidebar-pane-body {
  flex: 1;
  overflow-y: auto;
  padding: 10px 0;
}
.sidebar-pane-body::-webkit-scrollbar { width: 4px; }
.sidebar-pane-body::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.08); border-radius: 2px; }

/* Beta badge */
.badge-beta {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  background: var(--shell-badge-beta);
  color: var(--shell-accent);
  border: 1px solid rgba(52,121,196,0.25);
  padding: 2px 6px;
  border-radius: 4px;
  flex-shrink: 0;
}

/* Feature item row in sidebar panes */
.sidebar-feature-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  cursor: pointer;
  transition: background 0.1s;
  border-radius: 0;
  color: var(--shell-text);
  font-size: 12px;
  font-weight: 500;
  text-decoration: none;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
}
.sidebar-feature-row:hover {
  background: rgba(255,255,255,0.04);
}
.sidebar-feature-row:focus-visible { box-shadow: var(--shell-focus); outline: none; }
.sidebar-feature-row svg {
  width: 14px; height: 14px;
  color: var(--shell-muted);
  flex-shrink: 0;
}
.sidebar-feature-row .row-label { flex: 1; }
.sidebar-feature-row .row-meta {
  font-size: 10px;
  color: var(--shell-muted);
}

/* Section headers within pane body */
.sidebar-section-head {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--shell-muted);
  padding: 10px 14px 4px;
}

/* ── Properties Panel — tabbed ────────────────────────────── */
#props-tabs {
  display: flex;
  border-bottom: 1px solid var(--shell-border);
  background: var(--shell-surface);
  flex-shrink: 0;
  overflow-x: auto;
}
#props-tabs::-webkit-scrollbar { display: none; }

.props-tab-btn {
  flex-shrink: 0;
  padding: 7px 10px;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--shell-muted);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  cursor: pointer;
  white-space: nowrap;
  transition: color 0.12s, border-color 0.12s;
}
.props-tab-btn:hover { color: var(--shell-text); }
.props-tab-btn.active {
  color: var(--shell-accent);
  border-bottom-color: var(--shell-accent);
}
.props-tab-btn:focus-visible { box-shadow: var(--shell-focus); outline: none; }

.props-tab-pane { display: none; flex: 1; overflow-y: auto; }
.props-tab-pane.active { display: block; }
.props-tab-pane::-webkit-scrollbar { width: 4px; }
.props-tab-pane::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.08); border-radius: 2px; }

/* Materials tab */
.material-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 14px;
  font-size: 11px;
  color: var(--shell-text);
  border-bottom: 1px solid rgba(255,255,255,0.04);
}
.material-swatch {
  width: 16px; height: 16px;
  border-radius: 3px;
  flex-shrink: 0;
  border: 1px solid rgba(255,255,255,0.12);
}

/* Violations tab */
.violation-item {
  padding: 8px 14px;
  border-bottom: 1px solid rgba(255,255,255,0.04);
  font-size: 11px;
}
.violation-item .viol-code {
  font-family: 'DM Mono', monospace;
  font-size: 10px;
  color: var(--shell-warn);
  margin-bottom: 2px;
}
.violation-item .viol-msg { color: var(--shell-text); }

/* History tab */
.history-event {
  display: flex;
  gap: 8px;
  padding: 7px 14px;
  border-bottom: 1px solid rgba(255,255,255,0.04);
  font-size: 11px;
  color: var(--shell-muted);
}
.history-event .hev-time {
  font-family: 'DM Mono', monospace;
  font-size: 10px;
  color: var(--shell-muted);
  flex-shrink: 0;
  width: 56px;
}
.history-event .hev-text { flex: 1; color: var(--shell-text); }

/* ── Version Timeline Drawer ──────────────────────────────── */
#version-timeline-drawer {
  position: fixed;
  bottom: 0; left: 44px; right: 0;
  height: 0;
  background: var(--shell-surface);
  border-top: 1px solid var(--shell-border);
  z-index: 90;
  overflow: hidden;
  transition: height 0.22s cubic-bezier(0.16,1,0.3,1);
  display: flex;
  flex-direction: column;
}
#version-timeline-drawer.open {
  height: 160px;
}

#version-timeline-handle {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 16px;
  background: var(--shell-panel);
  border-bottom: 1px solid var(--shell-border);
  cursor: pointer;
  user-select: none;
  flex-shrink: 0;
}
#version-timeline-handle:hover { background: rgba(255,255,255,0.03); }
.vtl-title {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--shell-muted);
}
#version-timeline-handle .vtl-spacer { flex: 1; }
#btn-vtl-close {
  background: none;
  border: none;
  color: var(--shell-muted);
  cursor: pointer;
  font-size: 14px;
  padding: 2px 6px;
  border-radius: 4px;
  transition: color 0.1s;
}
#btn-vtl-close:hover { color: var(--shell-text); }

#version-timeline-track {
  flex: 1;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 0;
}
#version-timeline-track::-webkit-scrollbar { height: 4px; }
#version-timeline-track::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.08); border-radius: 2px; }

.vtl-commit {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  flex-shrink: 0;
  cursor: pointer;
}
.vtl-commit::before {
  content: '';
  position: absolute;
  top: 10px;
  right: calc(100%);
  width: 32px;
  height: 1px;
  background: var(--shell-border);
}
.vtl-commit:first-child::before { display: none; }
.vtl-commit + .vtl-commit { margin-left: 32px; }

.vtl-dot {
  width: 20px; height: 20px;
  border-radius: 50%;
  background: var(--shell-panel);
  border: 2px solid var(--shell-border);
  transition: border-color 0.12s, transform 0.1s;
  margin-bottom: 6px;
}
.vtl-commit:hover .vtl-dot {
  border-color: var(--shell-accent);
  transform: scale(1.15);
}
.vtl-commit.current .vtl-dot {
  background: var(--shell-accent);
  border-color: var(--shell-accent);
  box-shadow: 0 0 0 4px rgba(52,121,196,0.18);
}
.vtl-label {
  font-size: 9px;
  color: var(--shell-muted);
  text-align: center;
  max-width: 60px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.vtl-commit.current .vtl-label { color: var(--shell-accent); }

/* Action buttons in timeline */
#vtl-actions {
  display: flex;
  gap: 6px;
  padding: 0 16px 0 0;
  align-items: center;
  flex-shrink: 0;
  margin-left: auto;
}
.vtl-action-btn {
  background: none;
  border: 1px solid var(--shell-border);
  color: var(--shell-muted);
  font-size: 10px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 5px;
  cursor: pointer;
  white-space: nowrap;
  transition: border-color 0.12s, color 0.12s;
}
.vtl-action-btn:hover {
  border-color: var(--shell-accent);
  color: var(--shell-text);
}
.vtl-action-btn:focus-visible { box-shadow: var(--shell-focus); outline: none; }

/* ── Presence bar polish ────────────────────────────────────── */
/* #topbar-presence-bar is the logical name; actual DOM element is #presence-cluster */
#topbar-presence-bar,
#presence-cluster {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 8px;
}

.presence-avatar {
  width: 26px; height: 26px;
  border-radius: 50%;
  background: var(--shell-accent-dim);
  border: 2px solid var(--shell-bg);
  display: flex; align-items: center; justify-content: center;
  font-size: 10px; font-weight: 700;
  color: var(--shell-text);
  cursor: pointer;
  transition: border-color 0.1s, transform 0.1s;
  margin-left: -8px;
  position: relative;
}
.presence-avatar:first-child { margin-left: 0; }
.presence-avatar:hover { border-color: var(--shell-accent); transform: translateY(-1px); z-index: 1; }
.presence-avatar.online::after {
  content: '';
  position: absolute;
  bottom: 1px; right: 1px;
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--shell-success);
  border: 1px solid var(--shell-bg);
}

#btn-share-presence {
  background: rgba(52,121,196,0.12);
  border: 1px solid rgba(52,121,196,0.25);
  color: var(--shell-accent);
  font-size: 11px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 20px;
  cursor: pointer;
  transition: background 0.12s;
  display: flex;
  align-items: center;
  gap: 5px;
}
#btn-share-presence:hover { background: rgba(52,121,196,0.22); }
#btn-share-presence:focus-visible { box-shadow: var(--shell-focus); outline: none; }

/* ── Contextual toolbar morph ───────────────────────────────── */
/* Context groups — visible only when their data-context matches */
.toolbar-context-group {
  display: none !important;
}
.toolbar-context-group.context-visible {
  display: flex !important;
}
/* Smooth show/hide */
.toolbar-context-group {
  transition: opacity 0.15s;
  opacity: 0;
}
.toolbar-context-group.context-visible {
  opacity: 1;
}

/* ── Mobile responsive ─────────────────────────────────────── */
@media (max-width: 768px) {
  #nav-rail {
    top: auto; bottom: 0; left: 0; right: 0;
    width: 100%; height: 56px;
    flex-direction: row;
    justify-content: space-around;
    padding: 0 8px;
    border-right: none;
    border-top: 1px solid var(--shell-border);
  }
  .nav-rail-divider {
    width: 1px; height: 24px;
    margin: 0 4px;
  }
  #sidebar-expanded {
    left: 0; top: auto; bottom: 56px;
    height: 0; width: 100%;
    border-right: none;
    border-top: 1px solid var(--shell-border);
    transition: height 0.22s cubic-bezier(0.16,1,0.3,1);
  }
  #sidebar-expanded.open {
    height: 60vh;
    width: 100%;
  }
  #version-timeline-drawer {
    left: 0;
    bottom: 56px;
  }
  /* Hide tooltips on mobile */
  .nav-rail-btn::after { display: none; }
}
@media (max-width: 375px) {
  #nav-rail { gap: 0; }
  .nav-rail-btn { width: 32px; height: 32px; }
}

/* ── High-contrast / WCAG AA focus ring ────────────────────── */
@media (forced-colors: active) {
  .nav-rail-btn, .props-tab-btn, .vtl-action-btn, .sidebar-feature-row,
  #btn-share-presence, #btn-vtl-close {
    outline: 2px solid ButtonText;
    outline-offset: 2px;
  }
}
