/* ==========================================================================
   Common Strangers — Window system
   Desktop metaphor: backdrop + stacked, draggable, closable windows.
   Signature chrome: raised bevel, active pink / idle grey title bar.
   ========================================================================== */

/* --- Desktop: full-bleed backdrop layer ---
   Base is a tiled dark weave (retro desktop feel, no asset needed). When the
   backdrop library returns a photo, it covers on top (dimmed for legibility). */
.cs-desktop {
	position: fixed;
	inset: 0;
	overflow: hidden;
	background-color: var(--ink);
	background-image:
		repeating-linear-gradient(45deg,  rgba(255,255,255,0.02) 0 2px, transparent 2px 6px),
		repeating-linear-gradient(-45deg, rgba(0,0,0,0.35) 0 2px, transparent 2px 6px);
	background-size: 12px 12px, 12px 12px;
}

.cs-backdrop {
	position: absolute;
	inset: 0;
	background-size: cover;
	background-position: center;
	background-repeat: no-repeat;
	z-index: 0;
}
/* Only dim once a real photo is loaded — otherwise the tiled desktop shows through. */
.cs-backdrop.has-image {
	box-shadow: inset 0 0 0 100vmax rgba(13, 13, 15, 0.55);
}

/* --- Window --- */
.cs-window {
	position: absolute;
	display: flex;
	flex-direction: column;
	min-width: 280px;
	min-height: 160px;
	max-width: 96vw;
	max-height: 92vh;
	background: var(--frame);
	box-shadow: var(--bevel-raised), var(--window-shadow);
	z-index: var(--z-window-base);
}

.cs-window__titlebar {
	display: flex;
	align-items: center;
	gap: var(--sp-2);
	height: var(--titlebar-h);
	padding: 0 var(--sp-1) 0 var(--sp-3);
	background: var(--faint);           /* idle grey */
	cursor: grab;
	user-select: none;
	flex: 0 0 auto;
}
.cs-window__titlebar:active { cursor: grabbing; }

.cs-window.is-active {
	z-index: calc(var(--z-window-base) + 50);
	box-shadow: var(--bevel-raised), var(--window-shadow-active);
}
.cs-window.is-active .cs-window__titlebar { background: var(--pink); }

/* Rolled-up (minimized in place): only the title bar shows. */
.cs-window.is-collapsed { height: auto !important; min-height: 0; }
.cs-window.is-collapsed .cs-window__body,
.cs-window.is-collapsed .cs-subtopics,
.cs-window.is-collapsed .cs-rz { display: none; }

/* Invisible resize zones on every edge + corner (desktop). Corners sit above
   edges so diagonal cursors win at the overlap. */
.cs-rz { position: absolute; z-index: 3; }
.cs-rz--n { top: 0; left: 0; right: 0; height: 6px; cursor: ns-resize; }
.cs-rz--s { bottom: 0; left: 0; right: 0; height: 6px; cursor: ns-resize; }
.cs-rz--e { top: 0; right: 0; bottom: 0; width: 6px; cursor: ew-resize; }
.cs-rz--w { top: 0; left: 0; bottom: 0; width: 6px; cursor: ew-resize; }
.cs-rz--ne, .cs-rz--nw, .cs-rz--se, .cs-rz--sw { width: 12px; height: 12px; z-index: 4; }
.cs-rz--nw { top: 0; left: 0; cursor: nwse-resize; }
.cs-rz--se { bottom: 0; right: 0; cursor: nwse-resize; }
.cs-rz--ne { top: 0; right: 0; cursor: nesw-resize; }
.cs-rz--sw { bottom: 0; left: 0; cursor: nesw-resize; }

.cs-window__title {
	font-size: var(--fs-wintitle);
	font-weight: 700;
	text-transform: uppercase;
	letter-spacing: var(--tr-wintitle);
	line-height: var(--lh-wintitle);
	color: var(--muted);               /* idle title reads as "behind" */
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
	flex: 1 1 auto;
}
.cs-window.is-active .cs-window__title { color: var(--ink); }

/* Window controls — minimize (_) then close (✕), top-right. */
.cs-window__controls { flex: 0 0 auto; display: flex; align-items: center; gap: var(--sp-1); }

.cs-window__min,
.cs-window__max,
.cs-window__close {
	width: 22px; height: 22px;
	display: grid; place-items: center;
	color: var(--paper);
	box-shadow: var(--bevel-raised);
	border: 0;
	font-family: var(--font);
	font-size: var(--fs-label);
	font-weight: 700;
	cursor: pointer;
	line-height: 1;
}
.cs-window__min:active,
.cs-window__max:active,
.cs-window__close:active { box-shadow: var(--bevel-pressed); }

/* Minimize — grey tile with a bottom bar (the classic "_"). */
.cs-window__min { background: var(--frame); position: relative; }
.cs-window__min::before {
	content: ""; position: absolute; left: 50%; bottom: 5px;
	transform: translateX(-50%); width: 10px; height: 2px; background: var(--paper);
}

/* Maximize — grey tile with a hollow square (the classic "▢"). */
.cs-window__max { background: var(--frame); position: relative; }
.cs-window__max::before {
	content: ""; position: absolute; left: 50%; top: 50%;
	transform: translate(-50%, -50%); width: 9px; height: 8px;
	border: 1.5px solid var(--paper);
}
/* When maximized, the glyph reads as "restore" (two offset squares). */
.cs-window.is-maximized .cs-window__max::before { top: 55%; left: 45%; }
.cs-window.is-maximized .cs-window__max::after {
	content: ""; position: absolute; left: 55%; top: 45%;
	transform: translate(-50%, -50%); width: 9px; height: 8px;
	border: 1.5px solid var(--paper); background: var(--frame);
}

/* Close — red, the primary control. */
.cs-window__close { background: var(--red); }

/* Maximized: fill the working area — right of the left menu, below the top bar.
   Never cover the menus. */
.cs-window.is-maximized {
	left: var(--leftcol-w) !important;
	top: var(--topbar-h) !important;
	width: calc(100vw - var(--leftcol-w)) !important;
	height: calc(100vh - var(--topbar-h)) !important;
	max-width: none !important;
	max-height: none !important;
	z-index: 470 !important;
}
/* Left menu collapsed → the maximized window takes the full width. */
html.cs-sidebar-off .cs-window.is-maximized {
	left: 0 !important;
	width: 100vw !important;
}
/* Agenda ticker shown → the top bar is taller, so start below it. */
html.cs-ticker-on .cs-window.is-maximized {
	top: calc(var(--topbar-h) + var(--agenda-bar-h)) !important;
	height: calc(100vh - var(--topbar-h) - var(--agenda-bar-h)) !important;
}
.cs-window.is-maximized .cs-rz { display: none; } /* no resize while maximized */
.cs-window.is-maximized .cs-window__titlebar { cursor: default; }

/* --- Subtopic strip (slash-named) --- */
.cs-subtopics {
	display: flex;
	flex-wrap: wrap;
	gap: var(--sp-3);
	padding: var(--sp-2) var(--sp-3);
	background: var(--body);
	border-bottom: 1px solid var(--frame);
	flex: 0 0 auto;
}
.cs-subtopic {
	font-size: var(--fs-label);
	font-weight: 500;
	color: var(--muted);
	cursor: pointer;
	background: none; border: 0; padding: 0;
	font-family: var(--font);
}
.cs-subtopic.is-active { color: var(--orange); }
.cs-subtopic:hover { color: var(--paper); }

/* --- Window body — dark surface, its own scroll --- */
.cs-window__body {
	flex: 1 1 auto;
	min-height: 0;
	background: var(--body);
	padding: var(--sp-3);
	overflow: auto;
	/* No standard scrollbar-color — it would disable our ::-webkit-scrollbar in Chrome. */
}
.cs-window__body::-webkit-scrollbar { width: var(--scrollbar-size); height: var(--scrollbar-size); }
.cs-window__body::-webkit-scrollbar-track { background: var(--sb-track); }
.cs-window__body::-webkit-scrollbar-thumb { background: var(--sb-face); box-shadow: var(--sb-bevel-raised); }
.cs-window__body::-webkit-scrollbar-thumb:active { box-shadow: var(--sb-bevel-pressed); }

/* Monospace data rows inside windows. */
.cs-row {
	display: flex;
	gap: var(--sp-3);
	padding: var(--sp-2) 0;
	border-bottom: 1px solid var(--frame);
	font-size: var(--fs-data);
}
.cs-row:last-child { border-bottom: 0; }
.cs-row__meta { color: var(--faint); flex: 0 0 auto; }

/* --- Mobile: windows off → vertical feed --- */
@media (max-width: 1023.98px) {
	.cs-desktop { position: static; overflow: visible; height: auto; }
	/* No desktop metaphor on mobile: the absolute backdrop would otherwise
	   stretch over the feed and swallow every tap. */
	.cs-backdrop { display: none; }
	.cs-window {
		position: static !important;
		width: 100% !important;
		max-width: 100%;
		max-height: none;
		height: auto !important;
		margin: 0 0 var(--sp-4);
		transform: none !important;
	}
	.cs-window__titlebar { cursor: default; }
	.cs-window__body { overflow: visible; max-height: none; }
	.cs-rz { display: none; } /* no resize on mobile */
}
