/* app-rail.css — the general (cross-module) left navigation rail.
 *
 * A self-contained, framework-neutral component: pure semantic classes + design tokens.
 * Ported from the design system's left-rail / app-shell (theca-design-system
 * styleguide/components.css, components/left-rail.md). Collapsed state is driven
 * by `html[data-rail-collapsed="1"]` (set pre-paint from localStorage by the
 * inline head snippet, toggled by app-rail.js) so there is no collapse flash.
 */
@import url("./theca-tokens.css");

/* ---- shell: rail + module content side by side, full viewport height ---- */
.theca-app-shell {
	display: flex;
	width: 100%;
	height: 100dvh;
	background: var(--color-background-page);
}

.theca-app-shell-main {
	flex: 1;
	min-width: 0;
	display: flex;
	flex-direction: column;
	overflow: hidden;
}

/* ---- the rail ---- */
.theca-app-rail {
	position: relative;
	z-index: 10; /* lift the rail (and its edge-tab / hover tooltips) above the content */
	width: 248px;
	flex-shrink: 0;
	display: flex;
	flex-direction: column;
	height: 100dvh;
	background: var(--color-background-surface);
	-webkit-font-smoothing: antialiased;
	-moz-osx-font-smoothing: grayscale;
	border-right: 0.5px solid var(--color-border-default);
	padding: var(--space-5) var(--space-4) var(--space-6);
	box-shadow: 4px 0 24px rgba(45, 51, 75, 0.06);
	transition: width var(--duration-medium) var(--easing-standard);
}

html[data-rail-collapsed="1"] .theca-app-rail {
	width: 76px;
	align-items: center;
	padding-left: 0;
	padding-right: 0;
}

/* brand row: toggle + wordmark (wordmark hides when collapsed) */
.theca-app-rail-brand {
	display: flex;
	align-items: center;
	gap: var(--space-3);
	padding: 0 var(--space-4) var(--space-5);
	text-decoration: none;
	transition: opacity var(--duration-fast) var(--easing-standard);
}

.theca-app-rail-brand:hover {
	opacity: 0.7;
}

html[data-rail-collapsed="1"] .theca-app-rail-brand {
	flex-direction: column;
	justify-content: center;
	gap: var(--space-4);
	padding: 0 0 var(--space-4);
}

.theca-app-rail-brand-logo {
	height: 20px;
}

html[data-rail-collapsed="1"] .theca-app-rail-brand-logo {
	display: none;
}

/* the yellow Theca birdy brand mark; in the rail it shows only when collapsed */
.theca-birdy {
	height: 28px;
}

.theca-app-rail-brand .theca-birdy {
	display: none;
}

html[data-rail-collapsed="1"] .theca-app-rail-brand .theca-birdy {
	display: block;
}

/* collapse/expand control on the rail's right border (DS edge-tab) */
.theca-app-rail-edge-tab {
	position: absolute;
	top: 50%;
	right: -13px;
	transform: translateY(-50%);
	z-index: 50;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 26px;
	height: 26px;
	border-radius: var(--radius-full);
	background: var(--color-background-surface);
	border: 0.5px solid var(--color-border-strong);
	box-shadow: var(--shadow-sm);
	color: var(--color-text-secondary);
	cursor: pointer;
	transition: color var(--duration-fast) var(--easing-standard),
		border-color var(--duration-fast) var(--easing-standard);
}

.theca-app-rail-edge-tab:hover {
	color: var(--color-interactive-primary);
	border-color: var(--color-interactive-primary);
}

.theca-app-rail-edge-tab svg {
	width: 14px;
	height: 14px;
}

/* chevron points left to collapse; flips to point right (expand) when collapsed */
html[data-rail-collapsed="1"] .theca-app-rail-edge-tab svg {
	transform: rotate(180deg);
}

/* module identity header (icon + name) at the top of the nav */
.theca-app-rail-module {
	display: flex;
	align-items: center;
	gap: var(--space-3);
	padding: var(--space-3) var(--space-4);
	margin-bottom: var(--space-5);
	border-radius: var(--radius-md);
	color: var(--color-text-primary);
	/* same type treatment as the landing module title (.theca-module-option-title),
	   scaled down for the sidebar */
	font-family: var(--font-display);
	font-size: var(--font-size-lg);
	font-weight: var(--font-weight-semibold);
	line-height: var(--line-height-lg);
}

/* rounded, module-tinted icon tile — same treatment as the landing
   .theca-module-icon, scaled down for the sidebar */
.theca-app-rail-module-icon {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 2.25rem;
	height: 2.25rem;
	flex-shrink: 0;
	border-radius: var(--radius-lg);
}

.theca-app-rail-module-icon svg {
	width: 1.25rem;
	height: 1.25rem;
}

.theca-app-rail-module--economy .theca-app-rail-module-icon {
	background: var(--color-green-100);
	color: var(--color-green-700);
}

.theca-app-rail-module--maintenance .theca-app-rail-module-icon {
	background: var(--color-yellow-100);
	color: var(--color-yellow-700);
}

.theca-app-rail-module-label {
	flex: 1;
	min-width: 0;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

/* collapsed: the header (plain module OR switcher summary) shrinks to an icon. */
html[data-rail-collapsed="1"] .theca-app-rail-header {
	justify-content: center;
	padding: var(--space-3);
}

html[data-rail-collapsed="1"] .theca-app-rail-header .theca-app-rail-module-label {
	display: none;
}

/* ---- module switcher: header opens a dropdown of other available modules ---- */
.theca-app-rail-switcher {
	position: relative;
	margin-bottom: var(--space-5);
}

.theca-app-rail-switcher > summary,
.theca-app-rail-language > summary {
	margin-bottom: 0;
	cursor: pointer;
	list-style: none;
	user-select: none;
}

.theca-app-rail-switcher > summary::-webkit-details-marker,
.theca-app-rail-language > summary::-webkit-details-marker {
	display: none;
}

.theca-app-rail-switcher > summary:hover,
.theca-app-rail-language > summary:hover {
	background: var(--color-background-subtle);
}

.theca-app-rail-switcher-icon {
	display: inline-flex;
	flex-shrink: 0;
	color: var(--color-text-tertiary);
}

.theca-app-rail-switcher-icon svg {
	width: 16px;
	height: 16px;
}

/* dropdown panel: floats over the content below, items flush-left (no indent) */
.theca-app-rail-switcher-body {
	position: absolute;
	top: calc(100% + var(--space-1));
	left: 0;
	right: 0;
	z-index: 40;
	padding: var(--space-2);
	background: var(--color-background-surface);
	border: 0.5px solid var(--color-border-default);
	border-radius: var(--radius-lg);
	box-shadow: var(--shadow-lg);
}

.theca-app-rail-switcher-option {
	margin-bottom: 0;
	text-decoration: none;
	padding-left: var(--space-3);
}

.theca-app-rail-switcher-option:hover {
	background: var(--color-background-subtle);
}

/* collapsed: hide the swap icon; the dropdown flies out to the right with a
   comfortable width and full labels (the rail's icon-only rules don't apply here) */
html[data-rail-collapsed="1"] .theca-app-rail-switcher-icon {
	display: none;
}

html[data-rail-collapsed="1"] .theca-app-rail-switcher-body {
	top: 0;
	left: calc(100% + var(--space-2));
	right: auto;
	min-width: 200px;
}

/* nav */
.theca-app-rail-nav {
	display: flex;
	flex: 1;
	flex-direction: column;
	min-height: 0;
	width: 100%;
	overflow-x: hidden;
	overflow-y: auto;
	scrollbar-width: thin;
	scrollbar-color: var(--color-neutral-300) transparent;
}
.theca-app-rail-nav::-webkit-scrollbar {
	width: 6px;
}
.theca-app-rail-nav::-webkit-scrollbar-track {
	background: transparent;
}
.theca-app-rail-nav::-webkit-scrollbar-thumb {
	background: var(--color-neutral-300);
	border: 1px solid transparent;
	border-radius: var(--radius-full);
	background-clip: content-box;
}
.theca-app-rail-nav::-webkit-scrollbar-thumb:hover {
	background: var(--color-neutral-400);
	border: 1px solid transparent;
	background-clip: content-box;
}

/* collapsed: don't clip horizontally, so hover flyout tooltips can escape the rail */
html[data-rail-collapsed="1"] .theca-app-rail-nav {
	overflow: visible;
}

.theca-app-rail-section {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: var(--space-2);
	font-size: 11px;
	font-weight: 600;
	text-transform: uppercase;
	letter-spacing: 0.08em;
	color: var(--color-text-tertiary);
	padding: var(--space-3) var(--space-4);
	margin-top: var(--space-5);
}

.theca-app-rail-section:first-child {
	margin-top: 0;
}

html[data-rail-collapsed="1"] .theca-app-rail-section {
	display: none;
}

/* ---- expandable section (native <details>): title + chevron ---- */
.theca-app-rail-group {
	margin-top: var(--space-5);
}

.theca-app-rail-group-summary {
	display: flex;
	align-items: center;
	gap: var(--space-2);
	padding: var(--space-3) var(--space-4);
	font-size: 11px;
	font-weight: 600;
	text-transform: uppercase;
	letter-spacing: 0.08em;
	color: var(--color-text-tertiary);
	cursor: pointer;
	user-select: none;
	list-style: none;
}

.theca-app-rail-group-summary::-webkit-details-marker {
	display: none;
}

.theca-app-rail-group-summary:hover {
	color: var(--color-text-secondary);
}

.theca-app-rail-group-aux {
	display: inline-flex;
	align-items: center;
	gap: var(--space-2);
	flex-shrink: 0;
}

/* A control parked in a section's summary (e.g. the dashboards "+"). Sized to match
   the chevron beside it; app-rail.js stops its click from toggling the section. */
.theca-app-rail-group-action {
	display: inline-flex;
	align-items: center;
	flex-shrink: 0;
	border: 0;
	background: none;
	padding: 0;
	color: var(--color-text-tertiary);
	cursor: pointer;
}

.theca-app-rail-group-action:hover {
	color: var(--color-text-primary);
}

.theca-app-rail-group-action svg {
	width: 14px;
	height: 14px;
}

.theca-app-rail-group-chevron {
	display: inline-flex;
	flex-shrink: 0;
	color: var(--color-text-tertiary);
	transition: transform var(--duration-fast) var(--easing-standard);
}

.theca-app-rail-group-chevron svg {
	width: 14px;
	height: 14px;
}

.theca-app-rail-group[open] .theca-app-rail-group-chevron {
	transform: rotate(180deg);
}

/* muted placeholder for an empty expandable list */
.theca-app-rail-empty {
	padding: var(--space-2) var(--space-4);
	font-size: var(--font-size-xs);
	color: var(--color-text-tertiary);
}

/* iconless sections can't shrink to a rail icon, so they hide when collapsed;
   the icon links/buttons around them stay visible */
html[data-rail-collapsed="1"] .theca-app-rail-group {
	display: none;
}

.theca-app-rail-link {
	display: flex;
	align-items: center;
	gap: var(--space-4);
	padding: var(--space-3) var(--space-4);
	margin-bottom: 1px;
	border-radius: var(--radius-md);
	font-family: var(--font-body);
	font-size: var(--font-size-base);
	font-weight: 400;
	color: var(--color-text-secondary);
	background: transparent;
	border: none;
	width: 100%;
	text-align: left;
	text-decoration: none;
	cursor: pointer;
	position: relative;
	transition: background-color var(--duration-instant) var(--easing-standard),
		color var(--duration-instant) var(--easing-standard);
}

.theca-app-rail-link svg {
	width: 18px;
	height: 18px;
	flex-shrink: 0;
}

.theca-app-rail-link-label {
	flex: 1;
	min-width: 0;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

.theca-app-rail-link-badge {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	min-width: 18px;
	height: 18px;
	margin-left: auto;
	padding: 0 var(--space-2);
	border-radius: var(--radius-full);
	background: var(--color-background-subtle);
	color: var(--color-text-tertiary);
	font-size: 11px;
	font-weight: var(--font-weight-semibold);
	line-height: 1;
}

.theca-app-rail-link:hover {
	background: var(--color-background-subtle);
	color: var(--color-text-primary);
}

.theca-app-rail-link.is-active {
	background: var(--color-green-50);
	color: var(--color-interactive-primary-active);
	font-weight: 500;
}

.theca-app-rail-link.is-active::before {
	content: "";
	position: absolute;
	left: -4px;
	top: 50%;
	transform: translateY(-50%);
	width: 3px;
	height: 22px;
	border-radius: var(--radius-full);
	background: var(--color-brand-accent);
}

/* collapsed: icon-only links, labels hidden, centered, hover flyout tooltip */
html[data-rail-collapsed="1"] .theca-app-rail-link {
	justify-content: center;
	gap: 0;
	padding: var(--space-3);
}

html[data-rail-collapsed="1"] .theca-app-rail-link-label,
html[data-rail-collapsed="1"] .theca-app-rail-link-badge {
	display: none;
}

html[data-rail-collapsed="1"]
	.theca-app-rail-section:not(:first-child)
	+ .theca-app-rail-link {
	margin-top: var(--space-4);
}

html[data-rail-collapsed="1"] .theca-app-rail-link.is-active::before {
	left: 0;
}

/* per-icon flyout label shown only when collapsed */
html[data-rail-collapsed="1"] .theca-app-rail-link[data-tooltip]:hover::after,
html[data-rail-collapsed="1"] .theca-app-rail-icon-btn[data-tooltip]:hover::after,
html[data-rail-collapsed="1"] .theca-app-rail-profile-avatar[data-tooltip]:hover::after {
	content: attr(data-tooltip);
	position: absolute;
	left: calc(100% + var(--space-3));
	top: 50%;
	transform: translateY(-50%);
	white-space: nowrap;
	padding: var(--space-2) var(--space-3);
	border-radius: var(--radius-md);
	background: var(--color-background-inverse);
	color: var(--color-text-inverse);
	font-size: var(--font-size-xs);
	box-shadow: var(--shadow-md);
	z-index: 60;
	pointer-events: none;
}

/* ---- profile: pinned to the bottom, stays put while the nav scrolls ---- */
.theca-app-rail-profile {
	display: flex;
	align-items: center;
	gap: var(--space-3);
	flex-shrink: 0;
	margin-top: auto;
	padding-top: var(--space-4);
	border-top: 0.5px solid var(--color-border-default);
}

html[data-rail-collapsed="1"] .theca-app-rail-profile {
	flex-direction: column;
	gap: var(--space-3);
}

.theca-app-rail-profile-avatar {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	position: relative;
	width: 32px;
	height: 32px;
	flex-shrink: 0;
	border-radius: var(--radius-full);
	background: var(--color-green-100);
	color: var(--color-text-primary);
	font-size: var(--font-size-sm);
	font-weight: 600;
}

.theca-app-rail-profile-id {
	flex: 1;
	min-width: 0;
	line-height: 1.2;
}

html[data-rail-collapsed="1"] .theca-app-rail-profile-id {
	display: none;
}

.theca-app-rail-profile-name {
	font-size: var(--font-size-sm);
	font-weight: 600;
	color: var(--color-text-primary);
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

.theca-app-rail-profile-email {
	font-size: var(--font-size-xs);
	color: var(--color-text-secondary);
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

.theca-app-rail-profile-logout {
	flex-shrink: 0;
}

/* UI-language picker. Hand-written here rather than Tailwind because the inspection app
   loads app-rail.css but not output.css. The trigger and the panel reuse the module
   switcher's rules (the shared selectors above, plus `theca-app-rail-switcher-body` and
   `-switcher-option` in the markup); only the deltas live here, since this one opens
   upward. */
.theca-app-rail-language {
	position: relative;
	flex-shrink: 0;
}

/* Bottom cluster: the picker takes over the profile's auto margin so the two stay
   adjacent above the divider instead of drifting apart. */
.theca-app-rail > .theca-app-rail-language {
	margin-top: auto;
}

.theca-app-rail-language + .theca-app-rail-profile {
	margin-top: 0;
}

/* Chevron follows the rail's expander convention: down closed, up when open. */
.theca-app-rail-language[open] .theca-app-rail-switcher-icon {
	transform: rotate(180deg);
}

/* Opens upward: the trigger is the last thing above the profile. */
.theca-app-rail-language-body {
	top: auto;
	bottom: calc(100% + var(--space-1));
	min-width: 160px;
}

/* The selected language: a grey fill, deliberately not the rail's `is-active` treatment —
   that one means "you are here" in the nav and pairs a green tint with the yellow accent
   bar. A step darker than the hover grey so the two stay distinguishable. Ordered after
   the shared link rules so it also holds while hovered. */
.theca-app-rail-language-body [aria-current="true"] {
	background: var(--color-neutral-200);
	color: var(--color-text-primary);
	font-weight: 500;
}

/* Collapsed, the switcher rules fly the panel out to the right from `top: 0`, so the
   upward anchor has to yield. Scoped to the rail so the login card can't inherit it. */
html[data-rail-collapsed="1"] .theca-app-rail .theca-app-rail-language-body {
	bottom: auto;
}

.theca-app-rail-icon-btn {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	position: relative;
	width: 32px;
	height: 32px;
	border-radius: var(--radius-md);
	background: transparent;
	border: none;
	color: var(--color-text-secondary);
	cursor: pointer;
	transition: background-color var(--duration-instant) var(--easing-standard),
		color var(--duration-instant) var(--easing-standard);
}

.theca-app-rail-icon-btn svg {
	width: 18px;
	height: 18px;
}

.theca-app-rail-icon-btn:hover {
	background: var(--color-background-subtle);
	color: var(--color-text-primary);
}
