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

:root {
  /* ── Sixsentix Primary ── */
  --orange:     #E05535;
  --teal:       #3A8C7E;
  --navy:       #2B3990;
  --gold:       #CCA030;
  --charcoal:   #525252;

  /* ── Sixsentix Secondary ── */
  --orange-dk:  #8B3828;
  --teal-dk:    #1F5C50;
  --navy-dk:    #1A2460;
  --gold-dk:    #7A6018;
  --gray-lt:    #D8D8D8;

  /* ── Sixsentix Lighter ── */
  --orange-lt:  #E8907A;
  --teal-lt:    #7ABBB0;
  --blue-lt:    #6B78C8;
  --gold-lt:    #D4C060;

  /* ── Layout ── */
  --sidebar-w:  272px;
  --topbar-h:   50px;
  --infobar-h:  54px;
  --white:      #FFFFFF;
  --bg:         #F4F5F8;
  --text:       #2B2B2B;
  --text-muted: #6B7280;
}

html, body { height: 100%; overflow: hidden; }
body {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
}

/* ── Layout ─────────────────────────────────────────────── */
#app { display: flex; height: 100vh; overflow: hidden; }

/* ── Sidebar ─────────────────────────────────────────────── */
#sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--navy);
  border-right: 1px solid rgba(255,255,255,0.08);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#brand {
  padding: 18px 16px 14px;
  border-bottom: 1px solid rgba(255,255,255,0.1);
  flex-shrink: 0;
}
.brand-row { display: flex; align-items: center; gap: 8px; margin-bottom: 3px; }
.brand-diamond {
  display: inline-block;
  width: 10px; height: 10px;
  background: var(--orange);
  transform: rotate(45deg);
  flex-shrink: 0;
}
.brand-name { font-size: 15px; font-weight: 800; letter-spacing: 2.5px; color: var(--white); }
.brand-tag  { font-size: 11px; color: rgba(255,255,255,0.55); padding-left: 18px; }

#search-wrap { padding: 10px 10px 6px; flex-shrink: 0; }
#search {
  width: 100%;
  background: rgba(255,255,255,0.1);
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 6px;
  color: var(--white);
  padding: 7px 10px;
  font-size: 12.5px;
  outline: none;
  transition: border-color 0.15s;
}
#search::placeholder { color: rgba(255,255,255,0.4); }
#search:focus { border-color: var(--teal-lt); }

#tree { flex: 1; overflow-y: auto; overflow-x: hidden; padding: 4px 0 20px; }
#tree::-webkit-scrollbar { width: 3px; }
#tree::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.15); border-radius: 2px; }

.tree-empty { padding: 14px 16px; font-size: 12.5px; color: rgba(255,255,255,0.4); }
.tree-node  { position: relative; }

.tree-row {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  padding: 5px 10px 5px 12px;
  font-size: 12.5px;
  color: rgba(255,255,255,0.65);
  border-left: 2px solid transparent;
  cursor: pointer;
  user-select: none;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
  line-height: 1.35;
}
.tree-row:hover { background: rgba(255,255,255,0.07); color: var(--white); }
.tree-row.active {
  background: rgba(58,140,126,0.25);
  border-left-color: var(--teal-lt);
  color: var(--white);
}
.tree-row.active .tree-label { font-weight: 600; }

.tree-toggle {
  flex-shrink: 0; width: 13px; margin-top: 1px;
  font-size: 10px; color: rgba(255,255,255,0.4);
  transition: transform 0.15s; cursor: pointer;
}
.tree-toggle.collapsed { transform: rotate(-90deg); }
.tree-toggle:hover { color: rgba(255,255,255,0.8); }

.tree-dot { flex-shrink: 0; width: 13px; text-align: center; color: rgba(255,255,255,0.3); font-size: 14px; margin-top: -1px; }
.tree-dot::before { content: "·"; }
.tree-label { flex: 1; }

/* ── Main ────────────────────────────────────────────────── */
#main { flex: 1; display: flex; flex-direction: column; overflow: hidden; min-width: 0; }

#topbar {
  height: var(--topbar-h);
  background: var(--white);
  border-bottom: 1px solid var(--gray-lt);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  flex-shrink: 0;
  gap: 12px;
}

#breadcrumb {
  display: flex; align-items: center; gap: 4px;
  font-size: 12.5px; overflow: hidden; flex: 1; min-width: 0;
}
.bc-link {
  color: var(--text-muted); cursor: pointer;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 160px;
  transition: color 0.12s;
}
.bc-link:hover { color: var(--navy); }
.bc-sep   { color: var(--gray-lt); font-size: 11px; flex-shrink: 0; }
.bc-curr  { color: var(--navy); font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ── View tabs ───────────────────────────────────────────── */
#view-tabs { display: flex; gap: 4px; flex-shrink: 0; }
.vtab {
  background: none;
  border: 1.5px solid var(--gray-lt);
  border-radius: 6px;
  color: var(--text-muted);
  padding: 5px 14px;
  font-size: 12.5px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
}
.vtab:hover { border-color: var(--navy); color: var(--navy); }
.vtab.active {
  background: var(--navy);
  border-color: var(--navy);
  color: var(--white);
  font-weight: 600;
}

/* ── Viewport (Model view) ───────────────────────────────── */
#viewport {
  flex: 1;
  position: relative;
  overflow: hidden;
  cursor: grab;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
}
#viewport.grabbing { cursor: grabbing; }

#canvas {
  position: relative;
  flex-shrink: 0;
  will-change: transform;
}
#canvas.html-mode {
  width: 100%;
  height: 100%;
  align-self: stretch;
  flex: 1;
  transform: none !important;
}
#canvas.html-mode iframe {
  width: 100%;
  height: 100%;
  border: none;
  display: block;
}

#canvas img {
  display: block;
  max-width: none;
  user-select: none;
  pointer-events: none;
  -webkit-user-drag: none;
  box-shadow: 0 8px 32px rgba(0,0,0,0.18);
  border-radius: 4px;
  opacity: 0;
  transition: opacity 0.25s;
}
#canvas img.loaded { opacity: 1; }

/* ── Child grid ──────────────────────────────────────────── */
.child-grid { display: grid; gap: 14px; transform: translate(-50%, -50%); }
.child-card {
  background: var(--white);
  border: 1.5px solid var(--gray-lt);
  border-radius: 12px;
  padding: 22px 18px 18px;
  cursor: pointer;
  transition: border-color 0.18s, transform 0.18s, box-shadow 0.18s;
  text-align: center;
  min-width: 180px; max-width: 220px;
}
.child-card:hover {
  border-color: var(--navy);
  transform: translateY(-3px);
  box-shadow: 0 8px 24px rgba(43,57,144,0.12);
}
.card-icon  { font-size: 34px; margin-bottom: 10px; }
.card-title { font-size: 13px; font-weight: 600; margin-bottom: 5px; line-height: 1.3; color: var(--navy); }
.card-sub   { font-size: 11.5px; color: var(--text-muted); line-height: 1.4; }
.card-count {
  margin-top: 8px; font-size: 11px; color: var(--teal);
  background: rgba(58,140,126,0.1); border-radius: 10px;
  padding: 2px 8px; display: inline-block;
}

/* ── Loader ──────────────────────────────────────────────── */
#loader {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: rgba(244,245,248,0.7); pointer-events: none;
}
.spinner {
  width: 32px; height: 32px;
  border: 3px solid var(--gray-lt);
  border-top-color: var(--navy);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Empty state ─────────────────────────────────────────── */
#empty-state {
  position: absolute; inset: 0;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 10px; pointer-events: none; text-align: center; padding: 32px;
}
.empty-icon  { font-size: 44px; opacity: 0.3; }
.empty-title { font-size: 16px; font-weight: 600; color: var(--charcoal); }
.empty-hint  { font-size: 12.5px; color: var(--text-muted); line-height: 1.6; }
.empty-hint code {
  background: rgba(43,57,144,0.08); padding: 1px 5px;
  border-radius: 4px; font-size: 11.5px;
}

/* ── Hotspots ────────────────────────────────────────────── */
.hotspot {
  position: absolute;
  cursor: pointer;
  border-radius: 4px;
  border: 2px solid transparent;
  transition: background 0.18s, border-color 0.18s;
  z-index: 10;
}
.hotspot:hover {
  background: rgba(224,85,53,0.12);
  border-color: rgba(224,85,53,0.5);
}
.hotspot-tip {
  position: absolute;
  top: 8px; left: 50%;
  transform: translateX(-50%);
  background: var(--navy);
  color: var(--white);
  padding: 5px 12px;
  border-radius: 6px;
  font-size: 12px; font-weight: 600;
  white-space: nowrap; pointer-events: none;
  opacity: 0; transition: opacity 0.15s;
  box-shadow: 0 4px 16px rgba(0,0,0,0.2);
}
.hotspot:hover .hotspot-tip { opacity: 1; }

/* ── Details pane ────────────────────────────────────────── */
#details-pane {
  flex: 1;
  overflow-y: auto;
  background: var(--bg);
  padding: 24px;
}
#details-pane::-webkit-scrollbar { width: 5px; }
#details-pane::-webkit-scrollbar-thumb { background: var(--gray-lt); border-radius: 3px; }

#details-inner {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 20px;
  max-width: 1100px;
  margin: 0 auto;
}

.details-section {
  background: var(--white);
  border-radius: 12px;
  padding: 0;
  box-shadow: 0 2px 8px rgba(0,0,0,0.07);
  overflow: hidden;
}

.section-head {
  padding: 14px 18px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--white);
  display: flex;
  align-items: center;
  gap: 8px;
}
.section-head.resp  { background: var(--navy); }
.section-head.roles { background: var(--teal); }
.section-head.deliv { background: var(--orange); }

.section-body { padding: 12px 0; }

.detail-card {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 18px;
  cursor: pointer;
  border-left: 3px solid transparent;
  transition: background 0.12s, border-color 0.12s;
}
.detail-card:hover { background: var(--bg); }
.detail-card:hover.resp-card  { border-left-color: var(--navy); }
.detail-card:hover.roles-card { border-left-color: var(--teal); }
.detail-card:hover.deliv-card { border-left-color: var(--orange); }
.detail-card-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
  margin-top: 5px;
}
.resp-dot  { background: var(--navy); }
.roles-dot { background: var(--teal); }
.deliv-dot { background: var(--orange); }

.detail-card-title { font-size: 13px; font-weight: 600; color: var(--text); line-height: 1.35; }
.detail-card-sub   { font-size: 11.5px; color: var(--text-muted); margin-top: 2px; line-height: 1.4; }

.section-empty {
  padding: 16px 18px;
  font-size: 12.5px;
  color: var(--text-muted);
  font-style: italic;
}

/* ── Item drawer ─────────────────────────────────────────── */
#item-drawer {
  position: fixed;
  right: -520px;
  top: 0;
  height: 100vh;
  width: 460px;
  background: var(--white);
  box-shadow: -4px 0 24px rgba(0,0,0,0.12);
  z-index: 200;
  display: flex;
  flex-direction: column;
  transition: right 0.28s cubic-bezier(0.4, 0, 0.2, 1);
}
#item-drawer.open { right: 0; }

#drawer-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 199;
  background: rgba(0,0,0,0.18);
  cursor: pointer;
}
#drawer-overlay.visible { display: block; }

#drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--gray-lt);
  flex-shrink: 0;
}
#drawer-section-tag {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
  padding: 4px 10px;
  border-radius: 20px;
  color: var(--white);
}
#drawer-close {
  background: none;
  border: 1.5px solid var(--gray-lt);
  border-radius: 6px;
  width: 30px; height: 30px;
  font-size: 18px;
  cursor: pointer;
  color: var(--text-muted);
  display: flex; align-items: center; justify-content: center;
  transition: all 0.12s;
  line-height: 1;
}
#drawer-close:hover { border-color: var(--charcoal); color: var(--text); }

#drawer-body {
  flex: 1;
  overflow-y: auto;
  padding: 24px 24px 32px;
}
#drawer-title {
  font-size: 20px;
  font-weight: 700;
  color: var(--navy);
  margin-bottom: 16px;
  line-height: 1.3;
}
#drawer-description {
  font-size: 14px;
  color: var(--charcoal);
  line-height: 1.75;
}
#drawer-description p + p { margin-top: 12px; }

/* ── Info bar ────────────────────────────────────────────── */
#infobar {
  height: var(--infobar-h);
  background: var(--white);
  border-top: 1px solid var(--gray-lt);
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 14px;
  flex-shrink: 0;
  overflow: hidden;
}
#node-info   { min-width: 0; flex-shrink: 0; max-width: 340px; }
#node-title  { font-size: 13px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--navy); }
#node-subtitle { font-size: 11.5px; color: var(--text-muted); margin-top: 1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

#children-pills { display: flex; gap: 6px; overflow-x: auto; flex: 1; }
#children-pills::-webkit-scrollbar { height: 0; }

.pill {
  background: rgba(43,57,144,0.08);
  border: 1.5px solid rgba(43,57,144,0.2);
  color: var(--navy);
  border-radius: 20px;
  padding: 4px 12px;
  font-size: 11.5px;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.12s, color 0.12s;
  flex-shrink: 0;
}
.pill:hover { background: var(--navy); color: var(--white); }

/* ── Utility ─────────────────────────────────────────────── */
.hidden { display: none !important; }
