/*
 * The sidebar's deck of two cards (single chats, group chats), its
 * workspaces and rows; the account badge in the top-right corner; and the
 * dialogs the sidebar opens.
 */

/* ---- card 1: the three ways to start something ---- */

.sb-actions {
	display: flex;
	flex-direction: column;
}

button.sb-new {
	width: 100%;
	border: 0;
	background: none;
	font: inherit;
	text-align: left;
	cursor: pointer;
}

.sb-new svg {
	flex: none;
	color: var(--muted);
}

/* ---- card 2: the deck ---- */

/* the card behind shows its right and bottom edge */
.sb-deck {
	--sb-peek: 7px;
	position: relative;
	flex: 1;
	min-height: 0;
	margin: 0 var(--sb-peek) var(--sb-peek) 0;
}

.sb-face {
	position: absolute;
	inset: 0;
	display: flex;
	flex-direction: column;
	overflow: hidden;
	transition: transform 0.35s var(--ease), filter 0.35s;
}

.sb-face.is-front {
	z-index: 2;
}

.sb-face.is-back {
	z-index: 1;
	filter: brightness(0.97);
	transform: translate(var(--sb-peek), var(--sb-peek));
}

.sb-face > * {
	transition: opacity 0.25s;
}

.sb-face.is-back > * {
	opacity: 0;
}

/* swapping: the front card steps aside and sinks behind; the back one swings out and comes forward */
.sb-deck.is-swapping .sb-face {
	transition: none;
}

.sb-deck.is-swapping .sb-face.is-leaving {
	animation: sb-to-back 0.5s var(--ease) both;
}

.sb-deck.is-swapping .sb-face.is-coming {
	animation: sb-to-front 0.5s var(--ease) both;
}

.sb-deck.is-swapping .sb-face.is-coming > * {
	transition-delay: 0.2s;
}

@keyframes sb-to-back {
	0% {
		z-index: 2;
		transform: none;
	}
	45% {
		z-index: 2;
		transform: translate(-3%, -4px) scale(0.97) rotate(-1.5deg);
	}
	55% {
		z-index: 1;
	}
	100% {
		z-index: 1;
		transform: translate(var(--sb-peek), var(--sb-peek));
	}
}

@keyframes sb-to-front {
	0% {
		z-index: 1;
		transform: translate(var(--sb-peek), var(--sb-peek));
	}
	45% {
		z-index: 1;
		transform: translate(12%, 6px) rotate(2deg);
	}
	55% {
		z-index: 3;
	}
	100% {
		z-index: 3;
		transform: none;
	}
}

.sb-face-head {
	display: flex;
	flex: none;
	align-items: center;
	justify-content: space-between;
	gap: 8px;
	padding: 10px 8px 2px 16px;
}

.sb-face-tools {
	display: flex;
	flex: 0 1 auto;
	align-items: center;
	gap: 6px;
	min-width: 0;
	max-width: 70%;
}

/* the collapse button: a round outline, like the swap pill beside it */
.sb-face-tools .sb-collapse {
	width: 26px;
	height: 26px;
	border: 1px solid var(--border);
	border-radius: 999px;
}

.sb-face-tools .sb-flip {
	flex: 0 1 auto;
	min-width: 0;
	max-width: none;
}

.sb-face-title {
	overflow: hidden;
	font-size: calc(13px * var(--ui-scale));
	font-weight: 600;
	color: var(--text-strong);
	text-overflow: ellipsis;
	white-space: nowrap;
}

.sb-flip {
	position: relative;
	display: inline-flex;
	flex: none;
	align-items: center;
	gap: 5px;
	max-width: 60%;
	padding: 3px 10px;
	border: 1px solid var(--border);
	border-radius: 999px;
	background: none;
	color: var(--muted);
	font: inherit;
	font-size: calc(12px * var(--ui-scale));
	cursor: pointer;
	transition: background-color 0.15s, color 0.15s;
}

.sb-flip span:not(.sb-flip-dot) {
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

.sb-flip:hover {
	background: var(--surface-2);
	color: var(--text-strong);
}

.sb-flip svg {
	flex: none;
}

.sb-flip-dot {
	position: absolute;
	top: -2px;
	right: -2px;
	width: 8px;
	height: 8px;
	border: 2px solid var(--sb-card-bg);
	border-radius: 50%;
	background: #3c78d8;
	box-sizing: content-box;
}

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

.sb-item-pin {
	display: inline-flex;
	flex: none;
	color: var(--faint);
}

.sb-unread {
	flex: none;
	min-width: 18px;
	height: 18px;
	padding: 0 5px;
	border-radius: 9px;
	background: #3c78d8;
	color: #fff;
	font-size: calc(11px * var(--ui-scale));
	font-weight: 600;
	line-height: 18px;
	text-align: center;
}

.sb-item.is-unread .sb-item-title {
	font-weight: 600;
	color: var(--text-strong);
}

/* ---- workspaces ---- */

.sb-spaces {
	position: relative;
	display: flex;
	flex-direction: column;
	gap: 4px;
	margin: 8px 0 4px;
}

.sb-spaces.is-dragging {
	cursor: grabbing;
	user-select: none;
}

.sb-ws {
	position: relative;
	border-radius: 10px;
}

.sb-spaces.is-dragging .sb-ws:not(.is-dragged) {
	transition: transform 0.15s ease-out;
}

.sb-ws.is-dragged {
	z-index: 10;
}

/* lifted: only the header floats (the body folds away meanwhile, so a shadow
   round the whole workspace would flash at its old full height), and the
   shadow grows in rather than appearing at once */
.sb-ws.is-dragged .sb-ws-head {
	background: var(--surface);
	box-shadow: var(--menu-shadow);
}

.sb-ws-head {
	display: flex;
	align-items: center;
	height: 32px;
	padding: 0 2px 0 4px;
	border-radius: 10px;
	background: color-mix(in srgb, var(--surface-2) 55%, transparent);
	color: var(--muted);
	transition: box-shadow 0.2s ease-out, background-color 0.15s;
}

.sb-ws-head:hover,
.sb-ws-head.is-hot {
	background: var(--surface-2);
}

/* the grip hides to a sliver until the row is hovered */
.sb-ws-grip {
	display: flex;
	flex: none;
	align-items: center;
	justify-content: center;
	width: 22px;
	height: 100%;
	padding: 0;
	border: 0;
	background: none;
	color: var(--faint);
	cursor: grab;
	touch-action: none;
	transition: width 0.15s ease-out;
}

.sb-ws-grip svg {
	transition: transform 0.2s, opacity 0.2s;
}

@media (hover: hover) {
	.sb-ws-grip {
		width: 5px;
	}

	.sb-ws-grip svg {
		opacity: 0;
		transform: scale(0.3);
	}

	.sb-ws-head:hover .sb-ws-grip,
	.sb-ws-head.is-hot .sb-ws-grip,
	.sb-ws-grip:focus-visible,
	.sb-ws.is-dragged .sb-ws-grip {
		width: 22px;
	}

	.sb-ws-head:hover .sb-ws-grip svg,
	.sb-ws-head.is-hot .sb-ws-grip svg,
	.sb-ws-grip:focus-visible svg,
	.sb-ws.is-dragged .sb-ws-grip svg {
		opacity: 1;
		transform: none;
	}
}

.sb-ws-toggle {
	display: flex;
	flex: 1;
	align-items: center;
	gap: 4px;
	min-width: 0;
	height: 100%;
	padding: 0 2px;
	border: 0;
	background: none;
	color: inherit;
	font: inherit;
	font-size: calc(13px * var(--ui-scale));
	font-weight: 500;
	text-align: left;
	cursor: pointer;
}

.sb-ws-chevron {
	display: inline-flex;
	flex: none;
}

.sb-ws-chevron svg {
	transition: transform 0.2s;
}

.sb-ws.is-open .sb-ws-chevron svg {
	transform: rotate(90deg);
}

.sb-ws-name {
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

.sb-ws-count {
	flex: none;
	font-size: calc(11px * var(--ui-scale));
	font-weight: 400;
	color: var(--faint);
}

.sb-ws-head .sb-item-more {
	width: 26px;
	height: 26px;
}

.sb-ws-head:hover .sb-item-more,
.sb-ws-head.is-hot .sb-item-more {
	opacity: 1;
}

/* 0fr ↔ 1fr animates the height without measuring it */
.sb-ws-body {
	display: grid;
	grid-template-rows: 0fr;
	transition: grid-template-rows 0.2s ease-out;
}

.sb-ws.is-open .sb-ws-body {
	grid-template-rows: 1fr;
}

.sb-spaces.is-dragging .sb-ws-body {
	grid-template-rows: 0fr;
}

.sb-ws-inner {
	min-height: 0;
	overflow: hidden;
}

/* branch lines from the workspace down to its chats */
.sb-ws-tree {
	display: flex;
	flex-direction: column;
	gap: 1px;
	padding: 2px 0 4px 24px;
}

.sb-ws-tree > .sb-item,
.sb-ws-tree > .sb-ws-day,
.sb-ws-tree > .sb-ws-empty {
	position: relative;
}

.sb-ws-tree > *::before {
	content: "";
	position: absolute;
	top: -1px;
	bottom: 0;
	left: -11px;
	border-left: 1px solid var(--border-strong);
}

.sb-ws-tree > :last-child::before {
	bottom: 50%;
}

.sb-ws-tree > .sb-item::after {
	content: "";
	position: absolute;
	top: 50%;
	left: -11px;
	width: 7px;
	border-top: 1px solid var(--border-strong);
}

.sb-ws-day {
	padding: 8px 10px 2px;
	font-size: calc(11px * var(--ui-scale));
	color: var(--faint);
}

.sb-ws-empty {
	margin: 0;
	padding: 6px 10px;
	font-size: calc(12px * var(--ui-scale));
	color: var(--faint);
}

/* ---- the account, top right ---- */

.acct {
	position: fixed;
	top: 10px;
	right: 14px;
	z-index: 20;
}

.acct-btn {
	display: flex;
	align-items: center;
	padding: 3px;
	border: 1px solid var(--border);
	border-radius: 999px;
	background: var(--sb-card-bg);
	box-shadow: var(--sb-card-shadow);
	color: var(--text);
	font: inherit;
	cursor: pointer;
}

.acct-name {
	display: grid;
	grid-template-columns: 0fr;
	transition: grid-template-columns 0.28s var(--ease);
}

.acct-name > span {
	min-width: 0;
	overflow: hidden;
	padding: 0;
	font-weight: 500;
	white-space: nowrap;
}

.acct-name > span::before,
.acct-name > span::after {
	content: "";
	display: inline-block;
	width: 8px;
}

.acct-name > span::after {
	width: 10px;
}

@media (hover: hover) {
	.acct-btn:hover .acct-name {
		grid-template-columns: 1fr;
	}
}

.acct-btn:focus-visible .acct-name,
.acct-btn[aria-expanded="true"] .acct-name,
html[data-account-badge="pill"] .acct-name {
	grid-template-columns: 1fr;
}

@media (max-width: 767px) {
	.acct {
		top: 8px;
		right: 8px;
	}

	/* phones: only the avatar, beside the top bar */
	html[data-account-badge="pill"] .acct-name {
		grid-template-columns: 0fr;
	}

	/* in a chat with messages the avatar has moved onto your messages (chat.js); it comes back with a pop */
	.acct {
		transition: opacity 0.25s ease, scale 0.36s cubic-bezier(0.34, 1.56, 0.64, 1);
	}

	html.acct-in-thread:not([data-user-identity="off"]) .acct {
		opacity: 0;
		scale: 0.5;
		visibility: hidden;
		transition: none;
	}
}

/* computers, set to accountPlace "thread": the same as on phones */
@media (min-width: 768px) {
	html[data-account-place="thread"] .acct {
		transition: opacity 0.25s ease, scale 0.36s cubic-bezier(0.34, 1.56, 0.64, 1);
	}

	html[data-account-place="thread"].acct-in-thread:not([data-user-identity="off"]) .acct {
		opacity: 0;
		scale: 0.5;
		visibility: hidden;
		transition: none;
	}
}

@media (prefers-reduced-motion: reduce) {
	.acct,
	html[data-account-place="thread"] .acct {
		transition: none;
	}
}

/* ---- dialogs ---- */

.modal-wide {
	width: min(520px, 100%);
}

.modal-hint {
	margin: 0;
	font-size: calc(13px * var(--ui-scale));
	color: var(--faint);
}

.modal-options {
	display: flex;
	flex-direction: column;
	gap: 8px;
}

.modal-option {
	display: flex;
	align-items: flex-start;
	gap: 8px;
	cursor: pointer;
}

.modal-option input {
	margin-top: 3px;
}

.pick-list {
	max-height: min(50vh, 360px);
	overflow-y: auto;
	padding: 4px;
	border: 1px solid var(--border);
	border-radius: 10px;
}

.pick-head {
	padding: 8px 6px 4px;
	font-size: calc(12px * var(--ui-scale));
	color: var(--faint);
}

.pick-item {
	display: flex;
	align-items: center;
	gap: 8px;
	padding: 6px;
	border-radius: 8px;
	cursor: pointer;
}

.pick-item:hover {
	background: var(--surface-2);
}

.pick-item span {
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

.people-field {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 6px;
	min-height: 40px;
	padding: 5px 8px;
	border: 1px solid var(--border-strong);
	border-radius: var(--radius);
	background: var(--surface);
	cursor: text;
}

.people-field:focus-within {
	border-color: var(--muted);
	box-shadow: 0 0 0 3px var(--focus-ring);
}

.people-chips {
	display: contents;
}

.people-chip {
	display: inline-flex;
	align-items: center;
	gap: 2px;
	padding: 2px 3px 2px 10px;
	border-radius: 999px;
	background: var(--surface-2);
	font-size: calc(13px * var(--ui-scale));
}

.people-chip button {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 20px;
	height: 20px;
	padding: 0;
	border: 0;
	border-radius: 50%;
	background: none;
	color: var(--muted);
	cursor: pointer;
}

.people-chip button:hover {
	background: var(--border);
}

.people-input {
	flex: 1;
	min-width: 120px;
	padding: 3px 2px;
	border: 0;
	outline: none;
	background: none;
	color: var(--text);
	font: inherit;
}

.people-history-head {
	display: flex;
	align-items: center;
	justify-content: space-between;
	margin: 4px 0 6px;
	font-size: calc(12px * var(--ui-scale));
	color: var(--faint);
}

.people-history-list {
	display: flex;
	flex-wrap: wrap;
	gap: 6px;
}

.people-suggest {
	display: inline-flex;
	align-items: center;
	overflow: hidden;
	border: 1px dashed var(--border-strong);
	border-radius: 999px;
}

.people-suggest button {
	display: inline-flex;
	align-items: center;
	gap: 4px;
	padding: 3px 8px;
	border: 0;
	background: none;
	color: var(--text);
	font: inherit;
	font-size: calc(13px * var(--ui-scale));
	cursor: pointer;
}

.people-suggest button:hover {
	background: var(--surface-2);
}

.people-suggest .people-suggest-x {
	padding: 3px 7px 3px 4px;
	color: var(--faint);
}

.link-btn {
	padding: 0;
	border: 0;
	background: none;
	color: var(--muted);
	font: inherit;
	text-decoration: underline;
	cursor: pointer;
}

@media (prefers-reduced-motion: reduce) {
	.sb-face,
	.sb-face > *,
	.acct-name,
	.sb-ws-body {
		transition: none;
	}
}

/* ---- the settings cards: in the deck's place while a settings page is open (wide screens) ---- */

.sb-stage {
	position: relative;
	display: flex;
	flex: 1;
	flex-direction: column;
	min-height: 0;
}

/* the deck steps out to the left (animated by sidebar.js slideCard) */
.sb-stage.has-panel .sb-deck {
	opacity: 0;
	pointer-events: none;
	transform: translateX(calc(-100% - 24px));
}

.sb-panel {
	position: absolute;
	inset: 0; /* the whole deck's room, its peeking back card included */
	z-index: 1;
	display: flex;
	flex-direction: column;
	overflow: hidden;
	visibility: hidden;
}

.sb-panel.is-open {
	visibility: visible;
}

.sb-set-nav {
	flex: 1;
	min-height: 0;
	padding: 4px 8px 12px;
	overflow-y: auto;
}

.sb-set-nav .set-nav-arrow {
	display: none;
}

.sb-model-name {
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

/* card 3: the button whose card is open stays pressed */
.sb-page.is-pressed {
	background: var(--surface-2);
	color: var(--text-strong);
	font-weight: 500;
}

.sb-page.is-pressed svg {
	color: var(--text-strong);
}

@media (prefers-reduced-motion: reduce) {
	.sb-deck {
		transition: none;
	}

	/* base.css shortens every transition instead of removing it, and even a tiny one keeps
	   an opening card (and everything in it, as visibility is inherited) "hidden" for a frame,
	   too long to take the focus */
	.sb-panel,
	.sb-panel * {
		transition-property: none !important;
	}
}

/* the rising card comes out from behind card 3, not over it */
.sb-pages {
	position: relative;
	z-index: 2;
}

/* a new chat's row on its way from the "New chat" button to the list (sidebar.js flyNew) */
.sb-item-ghost {
	background: var(--sb-card-bg);
	box-shadow: var(--sb-card-shadow);
}

.sb-list.is-landing .sb-item.is-current {
	visibility: hidden;
}

.is-landing-row {
	visibility: hidden;
}

/* ---- new group / new workspace: a form card in the chats card's place (sidebar.js showForm) ---- */

/* it comes down out of its button in card 1 */
.sb-form {
	transform-origin: 50% 0;
}

.sb-form-body {
	flex: 1;
	min-height: 0;
	padding: 4px 14px 14px;
	overflow-y: auto;
}

.sb-form-body .modal-actions {
	flex-wrap: wrap;
	align-items: center;
}

/* card 1: the button whose form is open stays pressed */
.sb-new.is-pressed {
	background: var(--surface-2);
	color: var(--text-strong);
	font-weight: 500;
}

.sb-new.is-pressed svg {
	color: var(--text-strong);
}

/* the "New chat" bar on its way into the round corner button and back (sidebar.js morphNew) */
.sb-new-ghost {
	position: fixed;
	z-index: 40;
	box-sizing: border-box;
	margin: 0;
	overflow: hidden;
	white-space: nowrap;
	pointer-events: none;
}

/* the models card: each model with its avatar (it replaced the models page) */
.sb-model {
	display: flex;
	align-items: center;
	gap: 10px;
}

.sb-set-nav .sb-model {
	justify-content: flex-start;
}

/* the models card: a search box above the list */
.sb-model-search {
	width: 100%;
	margin: 0 0 6px;
}
