/* Ported from tldraw's apps/dotcom/client TlaSidebar (light theme, LTR only).
   Source: packages/editor/editor.css (.tl-theme__light) and
   apps/dotcom/client/src/tla/styles/tla.css (.tla-theme__light), plus
   TlaSidebar/sidebar.module.css, TlaSidebarLayout/sidebar-layout.module.css
   and TlaIcon/icon.module.css, with class names kept verbatim. */

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

.layout button,
.layout input,
.layout select,
.layout textarea {
  font: inherit;
  color: inherit;
}

:root {
  --tl-color-low: hsl(204, 16%, 94%);
  --tl-color-muted-0: hsl(0, 0%, 0%, 2%);
  --tl-color-muted-2: hsl(0, 0%, 0%, 4.3%);
  --tl-color-overlay: hsl(0, 0%, 0%, 20%);
  --tl-color-divider: hsl(0, 0%, 91%);
  --tl-color-focus: hsl(219, 65%, 50%);
  --tl-color-text-0: hsl(0, 0%, 11%);
  --tl-color-text-3: hsl(204, 4%, 45%);
  --tl-color-primary: hsl(214, 84%, 56%);
  --tl-color-background: hsl(210, 20%, 98%);
  --tla-color-sidebar: hsl(0, 0%, 99%);
  --tl-layer-menus: 300;
  --tla-sidebar-width: 260px;
}

/* ----------------------------- TlaIcon ----------------------------- */

.icon {
  display: flex;
  position: relative;
  flex-shrink: 0;
  background-color: currentColor;
  height: 15px;
  width: 15px;
  z-index: 1;
  pointer-events: none;
  color: inherit;
}

.inline {
  display: inline-flex;
}

/* --------------------------- Sidebar layout --------------------------- */

.layout {
  --tla-sidebar-width: 260px;
  position: absolute;
  top: 0px;
  left: 0px;
  width: 100%;
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 11px;
  transition: padding-left 0.16s ease-in-out;
  background-color: var(--tl-color-background);
}

.layout[data-sidebar="true"] {
  padding-left: var(--tla-sidebar-width);
  transition: padding-left 0.22s ease-out;
}

.layout[data-resizing="true"] {
  pointer-events: none;
  transition: none !important;
  user-select: none;
  -webkit-user-select: none;
}

.resizeHandle {
  --indicator-width: 2px;
  --hoverable-width: 6px;
  --active-width: 40px;
  height: 100%;
  position: absolute;
  top: 0;
  left: calc(var(--tla-sidebar-width) - var(--hoverable-width) + 1px);
  width: var(--hoverable-width);
  cursor: col-resize;
  z-index: 250;
  justify-content: center;
  display: flex;
}

.resizeHandle:active {
  left: calc(var(--tla-sidebar-width) - (var(--active-width) / 2) - (var(--hoverable-width) / 2) + 1px);
  width: var(--active-width);
}

.resizeHandleIndicator {
  background-color: var(--tl-color-primary);
  height: 100%;
  width: var(--indicator-width);
  opacity: 0;
  transition: opacity 100ms;
  pointer-events: none;
}

.resizeHandle:hover .resizeHandleIndicator,
.resizeHandle:active .resizeHandleIndicator {
  transition: opacity 150ms 80ms;
  opacity: 1;
}

.toggleContainer {
  position: absolute;
  top: 4px;
  margin-left: 4px;
  z-index: 1;
}

/* ------------------------------- Sidebar ------------------------------- */

.sidebar {
  position: absolute;
  display: flex;
  top: 0px;
  left: calc(var(--tla-sidebar-width) * -1);
  height: 100%;
  width: var(--tla-sidebar-width);
  z-index: 100;
  transform: translate(0px, 0px);
  flex-direction: column;
  flex: 0 0 auto;
  padding: 0 0 4px 0;
  background: var(--tla-color-sidebar);
  border-right: 1px solid var(--tl-color-low);
  transition: transform 0.16s ease-in-out;
}

.sidebar[data-visible="true"] {
  transform: translate(100%, 0px);
  transition: transform 0.22s ease-out;
}

.sidebarOverlayMobile {
  display: none;
}

.sidebarContent {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  margin: 0;
  padding: 0 12px 40px 12px;
  overflow-y: scroll;
  overflow-x: visible;
  -ms-overflow-style: none;
  scrollbar-width: none;
}

.sidebarContent::-webkit-scrollbar {
  display: none;
}

/* -------------------- Hoverable ------------------- */

.hoverable {
  position: relative;
}

.hoverable::after {
  display: block;
  content: "";
  position: absolute;
  top: 2px;
  left: 0px;
  right: 0px;
  bottom: 2px;
  border-radius: 4px;
  background-color: var(--tl-color-muted-0);
  z-index: 0;
  pointer-events: none;
  visibility: hidden;
}

.hoverable:has(*[data-state="open"])::after,
.hoverable[data-active="true"]::after {
  background-color: var(--tl-color-muted-2);
  visibility: visible;
}

.hoverable:hover::after {
  visibility: visible;
}

.hoverable {
  color: var(--tl-color-text-0);
}

.hoverable[data-active="true"],
.hoverable:hover {
  color: var(--tl-color-text-0);
}

/* ----------------- Sidebar toggle ----------------- */

.sidebarToggle {
  position: relative;
  /* Self-contained translucent "glass" chip so the toggle stays legible over any Document background
     (dark or light) once the sidebar is collapsed and it floats over the content iframe. The icon
     contrasts the chip, not the page behind it. */
  background: hsla(0, 0%, 100%, 0.6);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid hsla(0, 0%, 0%, 0.1);
  border-radius: 8px;
  box-shadow: 0 1px 3px hsla(0, 0%, 0%, 0.18);
  cursor: pointer;
  width: 36px;
  height: 36px;
  color: var(--tl-color-text-0);
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: all;
  flex-shrink: 0;
  padding: 0px;
}

.sidebarToggle::after {
  display: block;
  content: "";
  position: absolute;
  top: 4px;
  left: 4px;
  right: 4px;
  bottom: 4px;
  border-radius: 4px;
  pointer-events: none;
  z-index: 0;
  visibility: hidden;
  background-color: var(--tl-color-muted-0);
}

.sidebarToggle:focus-visible {
  border-radius: 8px;
  outline-offset: -4px;
  outline: 2px solid var(--tl-color-focus);
}

.sidebarToggle:hover {
  z-index: 100;
}

.sidebarToggle:hover::after {
  visibility: visible;
}

/* --------------------- Top area -------------------- */

.sidebarTopRow {
  display: flex;
  flex-direction: row;
  align-items: center;
  flex: 0 0 auto;
  height: 44px;
  padding: 3px 8px 0px 4px;
  gap: 8px;
}

.sidebarWorkspaceButton {
  background: none;
  border: none;
  position: relative;
  height: 40px;
  flex-grow: 2;
  display: flex;
  align-items: center;
  padding-right: 6px;
  padding-left: 15.3px;
  background-color: var(--tla-color-sidebar);
  overflow: hidden;
  padding-bottom: 1px;
  cursor: pointer;
  color: inherit;
  text-decoration: none;
  font-weight: 700;
  font-size: 16px;
  gap: 8px;
}

.sidebarWorkspaceButton span[role="img"] {
  width: 16px;
  height: 16px;
}

.sidebarCreateFileButton {
  background: none;
  border: none;
  cursor: pointer;
  position: relative;
  top: 0px;
  right: -4px;
  height: 40px;
  width: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: inherit;
  flex-shrink: 0;
  padding: 0px;
  z-index: 10;
}

.sidebarCreateFileButton::after {
  display: block;
  content: "";
  position: absolute;
  top: 4px;
  left: 4px;
  right: 4px;
  bottom: 4px;
  border-radius: 4px;
  pointer-events: none;
  z-index: 0;
  visibility: hidden;
  background-color: var(--tl-color-muted-0);
}

.sidebarCreateFileButton:focus-visible {
  border-radius: 8px;
  outline-offset: -4px;
}

.sidebar:hover .sidebarCreateFileButton:hover::after {
  visibility: visible;
}

/* ------------------- Bottom area ------------------ */

.sidebarBottomArea {
  display: flex;
  flex-direction: column;
  flex: 0 0 auto;
  margin-top: 0px;
  padding: 0 12px;
}

.sidebarDivider {
  margin: 0 12px;
  height: 8px;
  display: flex;
  align-items: center;
  flex: 0 0 auto;
}

.sidebarBottomArea .sidebarDivider {
  margin: 0px 0px 6px 0px;
}

.sidebarDivider::after {
  content: "";
  width: 100%;
  height: 1px;
  background-color: var(--tl-color-divider);
}

.sidebarBottomRow {
  display: flex;
  flex-direction: row;
  align-items: center;
  flex: 0 0 auto;
}

/* ----------------- Link button ---------------- */

.sidebarLinkButton {
  position: relative;
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 6px;
  height: 36px;
  flex: 0 0 auto;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--tl-color-text-0);
  padding: 0px 8px;
  text-align: left;
  text-decoration: none;
  width: 100%;
}

.sidebarLinkButton > span[role="img"] {
  flex-shrink: 0;
}

.sidebarLinkButtonLabel {
  flex: 0 1 auto;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebarLinkButton:focus-visible {
  outline-offset: -2px;
}

/* ---------------- File link section --------------- */

.sidebarFileSectionWrapper {
  margin-top: 8px;
}

.sidebarFileSection {
  position: relative;
  background: var(--tla-color-sidebar);
}

.sidebarFileSectionTitle {
  position: relative;
  width: 100%;
  height: 36px;
  padding: 0px 8px;
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 4px;
  color: var(--tl-color-text-3);
  font-weight: 500;
  background: none;
  border: none;
  cursor: pointer;
}

.sidebarFileSectionTitleText {
  flex: 1 1 auto;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-align: left;
}

.sidebarFileSectionTitlePadding span[role="img"] {
  margin-bottom: 1px;
}

/* "CSS" badge marking a Folder/Document that carries its own stylesheet, so the user can see at a
 * glance where custom styling lives. Always visible (it's an awareness cue, not a hover affordance). */
.sidebarCssIndicator {
  flex: 0 0 auto;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.04em;
  line-height: 1;
  padding: 2px 4px;
  border-radius: 4px;
  color: var(--tl-color-primary);
  background-color: hsl(214, 84%, 56%, 12%);
}

/* ----------------------------- Shared section ----------------------------- */

.sidebarSection {
  display: flex;
  flex-direction: column;
  flex: 0 0 auto;
  justify-content: center;
  padding: 6px 12px;
}

/* --------------- Workspace switcher --------------- */

.sidebarWorkspaceSwitcher {
  display: flex;
  flex-direction: column;
  flex: 0 0 auto;
  justify-content: center;
  padding: 0px 12px;
  height: 48px;
}

.sidebarWorkspaceSwitcherTrigger {
  position: relative;
  display: flex;
  flex-direction: row;
  align-items: center;
  height: 36px;
  width: 100%;
  gap: 6px;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--tl-color-text-0);
  padding: 0px 8px;
  text-align: left;
  min-width: 0;
}

.sidebarWorkspaceSwitcherTrigger:focus-visible {
  outline-offset: -2px;
}

.sidebarWorkspaceSwitcherTrigger[data-state="open"]::after {
  background-color: var(--tl-color-muted-2);
  visibility: visible;
}

.sidebarWorkspaceSwitcherLabel {
  flex: 0 1 auto;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  position: relative;
  z-index: 1;
  font-weight: 800;
}

.sidebarWorkspaceSwitcherChevrons {
  flex-shrink: 0;
  position: relative;
  z-index: 1;
}

.sidebarWorkspaceSwitcherMenu {
  min-width: max(260px, calc(var(--tla-sidebar-width) - 4px));
  max-width: calc(var(--tla-sidebar-width) - 4px);
  max-height: 70vh;
  overflow-y: auto;
  padding: 2px 0px;
  background: white;
  border-radius: 8px;
  box-shadow: var(--tl-shadow-3, 0 4px 14px rgba(0, 0, 0, 0.12));
  border: 1px solid var(--tl-color-divider);
}

.sidebarWorkspaceSwitcherOverlay {
  position: fixed;
  inset: 0;
  z-index: calc(var(--tl-layer-menus) - 1);
  pointer-events: all;
}

.sidebarWorkspaceSwitcherRoot {
  position: relative;
  z-index: var(--tl-layer-menus);
}

.sidebarWorkspaceSwitcherItem {
  position: relative;
  display: flex;
  align-items: center;
  height: 40px;
  padding: 0px 12px;
  color: var(--tl-color-text-0);
  cursor: pointer;
  outline: none;
  min-width: 0;
  z-index: 1;
  background: none;
  border: none;
  text-align: left;
  width: 100%;
}

.sidebarWorkspaceSwitcherMenu > * {
  margin-top: -4px;
  margin-bottom: -4px;
}

.sidebarWorkspaceSwitcherMenu > *:hover {
  z-index: 2;
}

.sidebarWorkspaceSwitcherMenu > *:nth-of-type(1) {
  margin-top: 0px;
}

.sidebarWorkspaceSwitcherMenu > *:nth-last-of-type(1) {
  margin-bottom: 0px;
}

.sidebarWorkspaceSwitcherItem::after {
  content: "";
  position: absolute;
  inset: 4px 6px;
  opacity: 0;
  pointer-events: none;
  border-radius: 4px;
}

.sidebarWorkspaceSwitcherItem[data-highlighted]::after {
  opacity: 1;
  background-color: var(--tl-color-muted-2);
}

.sidebarWorkspaceSwitcherItemLabel {
  flex: 0 1 auto;
  display: flex;
  width: 100%;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.sidebarTruncatedText {
  flex: 0 1 auto;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebarWorkspaceSwitcherMenu > .sidebarWorkspaceSwitcherSeparator {
  height: 1px;
  margin: 6px 0px;
  background-color: var(--tl-color-divider);
}

.sidebarCreateWorkspaceButton {
  position: relative;
  display: flex;
  align-items: center;
  gap: 6px;
  height: 32px;
  min-width: 0;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--tl-color-text-0);
  padding: 0px 8px;
  text-align: left;
  width: 100%;
}

.sidebarCreateWorkspaceButton > span[role="img"] {
  flex-shrink: 0;
}

.sidebarCreateWorkspaceButton:focus-visible {
  outline-offset: -2px;
}

.sidebarActionButton {
  position: relative;
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 6px;
  height: 36px;
  flex: 0 0 auto;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0px 8px;
  text-align: left;
  color: var(--tl-color-text-0);
  width: 100%;
}

.sidebarActionButton span[role="img"] {
  width: 15px;
  height: 15px;
  position: relative;
  color: var(--tl-color-text-0);
}

.sidebarActionButtonLabel {
  flex: 0 1 auto;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebarActionButton:focus-visible {
  outline-offset: -2px;
}

.sidebarActionButton:disabled {
  color: var(--tl-color-text-3);
  cursor: not-allowed;
}

/* ------------------- Sidebar search ------------------ */

.sidebarSearch {
  position: relative;
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 6px;
  height: 36px;
  flex: 0 0 auto;
  padding: 0px 4px 0px 8px;
  color: var(--tl-color-text-0);
}

.sidebarSearch::before {
  content: "";
  position: absolute;
  inset: 2px 0px;
  border-radius: 4px;
  border: 1px solid transparent;
  pointer-events: none;
}

.sidebarSearch:focus-within::before {
  border-color: var(--tl-color-primary);
}

.sidebarSearchIcon {
  flex-shrink: 0;
  z-index: 1;
  height: 15px;
  width: 15px;
  color: var(--tl-color-text-0);
}

.sidebarSearchInput {
  flex: 1 1 auto;
  min-width: 0;
  height: auto;
  background: none;
  border: none;
  padding: 0px;
  color: var(--tl-color-text-0);
  position: relative;
  z-index: 1;
  font: inherit;
}

.sidebarSearchInput:focus {
  outline: none;
}

.sidebarSearchClear {
  padding: 0px;
  background: none;
  border: none;
  position: relative;
  outline: none;
  margin-inline-end: -10px;
  width: 36px;
  height: 36px;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  z-index: 3;
  cursor: pointer;
  color: var(--tl-color-text-0);
}

.sidebarSearchClear:focus-visible {
  border-radius: 8px;
  outline-offset: -4px;
}

.sidebarSearchEmpty {
  padding: 8px;
  color: var(--tl-color-text-3);
}

/* ------------------- File links ------------------- */

.sidebarFileListItem {
  background-color: transparent;
  position: relative;
  width: 100%;
  display: flex;
  flex-direction: row;
  align-items: center;
  height: 36px;
  padding: 0px 4px 0px 8px;
  color: var(--tl-color-text-0);
}

.sidebarFileListItem[data-active="true"] {
  border-radius: 4px;
}

.sidebarFileListItemContent {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: flex-start;
  gap: 8px;
  position: relative;
  pointer-events: none;
  z-index: 2;
}

.sidebarFileListItemLabel {
  flex: 0 1 auto;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  position: relative;
  z-index: 1;
  color: var(--tl-color-text-0);
}

.sidebarFileListItem[data-active="true"] .sidebarFileListItemLabel {
  font-weight: 600;
}

.sidebarFileListItemLabelMatch {
  font-weight: 700;
  color: var(--tl-color-text-0);
}

.sidebarFileListItemRenameInputWrapper {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  padding: 0px 8px 0px 8px;
  outline-offset: -2px;
  gap: 8px;
  position: relative;
  width: 100%;
}

.sidebarFileListItemRenameInputWrapper::before {
  content: "";
  position: absolute;
  bottom: 0px;
  inset: 2px 0px;
  border-radius: 4px;
  border: 1px solid var(--tl-color-primary);
}

.sidebarFileListItemRenameInput {
  height: 36px;
  flex: 1 1 auto;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  position: relative;
  z-index: 1;
  background: none;
  border: none;
  font: inherit;
  color: var(--tl-color-text-0);
  padding: 0;
}

.sidebarFileListItemRenameInput:focus {
  outline: none;
}

.sidebarFileListItemButton {
  padding: 0px;
  background: none;
  border: none;
  position: absolute;
  top: 0px;
  left: 3px;
  width: calc(100% - 42px);
  height: 100%;
  cursor: pointer;
  z-index: 2;
  pointer-events: all;
}

.sidebarFileListItemButton:focus-visible {
  border-radius: 4px;
  outline-offset: 0px;
}

.sidebarFileListItemMenuTrigger {
  padding: 0px;
  background: none;
  border: none;
  position: relative;
  outline: none;
  margin-inline-end: -6px;
  width: 36px;
  height: 36px;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--tl-color-text-3);
  flex: 0 0 auto;
  z-index: 3;
  cursor: pointer;
  visibility: hidden;
}

.sidebarFileListItem:hover .sidebarFileListItemMenuTrigger,
.sidebarFileSectionTitle:hover .sidebarFileListItemMenuTrigger,
.sidebarFileListItemMenuTrigger[data-state="open"] {
  visibility: visible;
}

.sidebarFileListItemMenuTrigger:focus-visible {
  border-radius: 8px;
  outline-offset: -4px;
  visibility: visible;
}

.sidebarFileListItemMenuTrigger:hover {
  color: var(--tl-color-text-0);
}

.sidebarFileListItemMenu {
  min-width: 180px;
  background: white;
  border-radius: 8px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.12);
  border: 1px solid var(--tl-color-divider);
  padding: 2px 0px;
  z-index: var(--tl-layer-menus);
}

.sidebarFileListItemMenuItem {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
  height: 36px;
  padding: 0px 12px;
  color: var(--tl-color-text-0);
  cursor: pointer;
  outline: none;
}

.sidebarFileListItemMenuItem[data-highlighted] {
  background-color: var(--tl-color-muted-2);
}

.sidebarFileListItemMenuItem[data-danger="true"] {
  color: hsl(0, 90%, 43%);
}

/* ---------------- Project switcher: remove-from-list (hover ✕) ---------------- */

.sidebarWorkspaceSwitcherItemRemove {
  margin-left: auto;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  padding: 0;
  border: none;
  border-radius: 4px;
  background: none;
  color: var(--tl-color-text-3);
  cursor: pointer;
  opacity: 0;
  z-index: 2;
}

.sidebarWorkspaceSwitcherItem:hover .sidebarWorkspaceSwitcherItemRemove,
.sidebarWorkspaceSwitcherItemRemove:focus-visible {
  opacity: 1;
}

.sidebarWorkspaceSwitcherItemRemove:hover {
  background-color: var(--tl-color-muted-2);
  color: var(--tl-color-text-0);
}

/* ---------------- Sidebar Selection highlight (data-selected) ---------------- */

.sidebarFileListItem[data-selected="true"],
.sidebarFileSectionTitle[data-selected="true"] {
  box-shadow: inset 2px 0 0 var(--tl-color-primary);
}
