/* Philentia application shell
 * Copyright (c) 2026, IT Business Dominicana (ITBD)
 *
 * The navigation frame the brand manual describes: a 260px navy sidebar
 * collapsing to 72px, a 64px top bar carrying the legal entity and its
 * jurisdictions, and a workspace capped at 1440px.
 *
 * Server-rendered on purpose. The manual's shell is not reachable by theming
 * the Frappe desk — v16 has no desktop top bar at all — and the alternative to
 * this is a second build system (Vite, a bundler, an npm install inside the
 * image) for a frame that is fundamentally static. Pages here are Jinja and
 * plain CSS, so they ship in the same image with no toolchain, and any single
 * screen can later be replaced by a Vue island without touching the frame.
 *
 * Built only on `philentia-tokens.css`. No hex values below this line.
 */

/* ===========================================================================
 * Frame
 * =========================================================================== */

.pa {
	--pa-sidebar: var(--sidebar-width);
	min-height: 100vh;
	background: var(--surface-secondary);
	color: var(--text-primary);
	font-family: var(--font-ui);
	font-size: var(--text-body);
}

.pa[data-sidebar="collapsed"] {
	--pa-sidebar: var(--sidebar-collapsed);
}

.pa__main {
	margin-left: var(--pa-sidebar);
	transition: margin-left var(--duration-base) var(--ease-out);
	min-height: 100vh;
	display: flex;
	flex-direction: column;
}

.pa__workspace {
	flex: 1;
	width: 100%;
	max-width: var(--content-max);
	margin: 0 auto;
	padding: var(--space-6);
}

/* ===========================================================================
 * Sidebar
 * =========================================================================== */

/* The sidebar wears a muted blue — softer than the brand navy, chosen by
 * the owner from a swatch (#4b63b3). White text reads at ~5.5:1 on it; the
 * active item is a white tint with the lime rail of the mark. */
.pa__sidebar {
	--sb-bg: #4b63b3;
	--sb-bg-deep: #4058a6;
	--sb-text: rgba(255, 255, 255, 0.86);
	--sb-text-strong: #ffffff;
	--sb-muted: rgba(255, 255, 255, 0.58);
	--sb-hover: rgba(255, 255, 255, 0.12);
	--sb-active: rgba(255, 255, 255, 0.2);
	--sb-line: rgba(255, 255, 255, 0.16);
	position: fixed;
	inset: 0 auto 0 0;
	width: var(--pa-sidebar);
	background: linear-gradient(180deg, var(--sb-bg) 0%, var(--sb-bg-deep) 100%);
	display: flex;
	flex-direction: column;
	z-index: 40;
	transition: width var(--duration-base) var(--ease-out);
	overflow: hidden;
}

.pa__brand {
	display: flex;
	align-items: center;
	gap: var(--space-3);
	height: var(--topbar-height);
	padding: 0 var(--space-4);
	flex: none;
	text-decoration: none;
}

.pa__brand img {
	height: 30px;
	width: auto;
	flex: none;
}

.pa__brand-word {
	font-family: var(--font-brand);
	font-weight: var(--weight-bold);
	font-size: 1.05rem;
	letter-spacing: 0.01em;
	color: var(--sb-text-strong);
	white-space: nowrap;
}

.pa[data-sidebar="collapsed"] .pa__brand {
	justify-content: center;
	padding: 0;
}
.pa[data-sidebar="collapsed"] .pa__brand-word,
.pa[data-sidebar="collapsed"] .pa__nav-label,
.pa[data-sidebar="collapsed"] .pa__group-title {
	display: none;
}

.pa__nav {
	flex: 1;
	overflow-y: auto;
	overflow-x: hidden;
	padding: var(--space-2) 0 var(--space-6);
	scrollbar-width: thin;
	scrollbar-color: rgba(255, 255, 255, 0.3) transparent;
}

.pa__group-title {
	display: flex;
	align-items: center;
	justify-content: space-between;
	width: 100%;
	padding: var(--space-5) var(--space-4) var(--space-2);
	border: 0;
	background: transparent;
	font: inherit;
	font-size: var(--text-caption);
	font-weight: var(--weight-semibold);
	letter-spacing: 0.08em;
	text-transform: uppercase;
	color: var(--sb-muted);
	cursor: pointer;
	text-align: left;
}
.pa__group-title:hover { color: var(--sb-text-strong); }
.pa__group-chevron { transition: transform var(--duration-base) var(--ease-out); }
.pa__group[data-collapsed] .pa__group-chevron { transform: rotate(-90deg); }
.pa__group[data-collapsed] .pa__group-items { display: none; }
/* Folding is a thing the wide sidebar does; the narrow one shows every icon. */
.pa[data-sidebar="collapsed"] .pa__group[data-collapsed] .pa__group-items { display: block; }

.pa__nav-item {
	display: flex;
	align-items: center;
	gap: var(--space-3);
	min-height: 40px;
	padding: 0 var(--space-4);
	/* The 3px sits in a transparent border so the label never shifts by 3px
	 * when an item becomes active. */
	border-left: 3px solid transparent;
	color: var(--sb-text);
	text-decoration: none;
	font-size: var(--text-body);
	transition: background-color var(--duration-hover) var(--ease-out),
		color var(--duration-hover) var(--ease-out);
}

.pa__nav-item:hover {
	background: var(--sb-hover);
	color: var(--sb-text-strong);
}

.pa__nav-item[aria-current="page"] {
	background: var(--sb-active);
	border-left-color: var(--growth-lime-500);
	color: var(--sb-text-strong);
	font-weight: var(--weight-medium);
}

.pa__nav-icon {
	width: 18px;
	height: 18px;
	flex: none;
	stroke-width: 1.85;
}

.pa[data-sidebar="collapsed"] .pa__nav-item {
	justify-content: center;
	padding: 0;
	border-left-width: 0;
}
.pa[data-sidebar="collapsed"] .pa__nav-item[aria-current="page"] {
	box-shadow: inset 3px 0 0 0 var(--growth-lime-500);
}

.pa__sidebar-foot {
	flex: none;
	border-top: 1px solid var(--sb-line);
	padding: var(--space-2);
}

.pa__collapse {
	display: flex;
	align-items: center;
	justify-content: center;
	gap: var(--space-2);
	width: 100%;
	min-height: 40px;
	background: transparent;
	border: 0;
	border-radius: var(--radius-md);
	color: var(--sb-text);
	font-family: inherit;
	font-size: var(--text-body-sm);
	cursor: pointer;
}
.pa__collapse:hover {
	background: var(--sb-hover);
	color: var(--sb-text-strong);
}

/* ===========================================================================
 * Top bar
 * =========================================================================== */

.pa__topbar {
	position: sticky;
	top: 0;
	z-index: 30;
	display: flex;
	align-items: center;
	gap: var(--space-4);
	height: var(--topbar-height);
	padding: 0 var(--space-6);
	background: var(--surface);
	border-bottom: 1px solid var(--border);
}

.pa__crumbs {
	display: flex;
	align-items: center;
	gap: var(--space-2);
	font-size: var(--text-body-sm);
	color: var(--text-muted);
	min-width: 0;
}
.pa__crumbs a {
	color: var(--text-muted);
	text-decoration: none;
}
.pa__crumbs a:hover {
	color: var(--text-link);
}
.pa__crumbs [aria-current="page"] {
	color: var(--text-primary);
	font-weight: var(--weight-medium);
}
/* A record's title can be a sentence ("Declaración Jurada Anual Informativa
   para Instituciones sin Fines de Lucro"). The crumb shows what fits and the
   page heading shows the rest; a crumb that wraps four lines pushes the
   search box off the bar. */
.pa__crumbs a,
.pa__crumbs [aria-current="page"] {
	max-width: 28ch;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

.pa__notice {
	padding: var(--space-3) var(--space-6);
	font-size: var(--text-body-sm);
	border-bottom: 1px solid var(--border);
	background: var(--surface-secondary);
	color: var(--text-primary);
}
.pa__notice--warning { background: #fff7e0; border-color: #f2d27a; }
.pa__notice--danger { background: #fdecec; border-color: #f0b4b4; }

.pa__bell-wrap { position: relative; }
.pa__bell-count {
	position: absolute; top: 2px; right: 2px; min-width: 16px; height: 16px; padding: 0 4px;
	border-radius: 8px; background: var(--danger, #c0392b); color: #fff; font-size: 10px; line-height: 16px;
	text-align: center; font-weight: 600;
}
.pa__bell-menu { right: 0; left: auto; min-width: 340px; max-width: 90vw; }
.pa__bell-item { display: block; padding: var(--space-3) var(--space-4); border-bottom: 1px solid var(--border); text-decoration: none; color: var(--text-primary); }
.pa__bell-item--unread { background: var(--surface-secondary); }
.pa__bell-item small { display: block; color: var(--text-muted); margin-top: 2px; }

.pa__topbar-spacer {
	margin-left: auto;
}

.pa__search {
	display: flex;
	align-items: center;
	gap: var(--space-2);
	min-width: 220px;
	height: 36px;
	padding: 0 var(--space-3);
	background: var(--surface-secondary);
	border: 1px solid var(--border-control);
	border-radius: var(--radius-md);
	color: var(--text-muted);
	font-size: var(--text-body-sm);
	cursor: pointer;
	font-family: inherit;
}
.pa__search:hover {
	background: var(--surface-tertiary);
}
.pa__search kbd {
	margin-left: auto;
	font-family: var(--font-mono);
	font-size: var(--text-caption);
	background: var(--surface);
	border: 1px solid var(--border);
	border-radius: var(--radius-xs);
	padding: 1px 5px;
}

/* --- Entity and jurisdiction ---------------------------------------------
 * These two stay visible because they change every figure, obligation and
 * permission on the page. A user who misreads which entity they are looking at
 * has misread everything else too.
 * ------------------------------------------------------------------------- */

.pa__entity {
	display: flex;
	align-items: center;
	gap: var(--space-3);
	height: 44px;
	padding: 0 var(--space-3);
	background: transparent;
	border: 1px solid var(--border-control);
	border-radius: var(--radius-md);
	cursor: pointer;
	font-family: inherit;
	text-align: left;
	max-width: 300px;
}
.pa__entity:hover {
	background: var(--surface-secondary);
}

.pa__entity-name {
	font-size: var(--text-body);
	font-weight: var(--weight-semibold);
	color: var(--text-primary);
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}
.pa__entity-where {
	font-size: var(--text-caption);
	color: var(--text-muted);
	white-space: nowrap;
}

/* A jurisdiction is a code and a name, never a flag alone: US-FL and US-NY
 * share a flag and do not share obligations. */
.pa__juris {
	display: inline-flex;
	align-items: center;
	gap: var(--space-2);
	height: 44px;
	padding: 0 var(--space-3);
	background: transparent;
	border: 1px solid var(--border-control);
	border-radius: var(--radius-md);
	font-family: var(--font-mono);
	font-size: var(--text-body-sm);
	color: var(--text-secondary);
	cursor: pointer;
}
.pa__juris:hover {
	background: var(--surface-secondary);
}
.pa__juris-dot {
	width: 8px;
	height: 8px;
	border-radius: var(--radius-full);
	flex: none;
}
.pa__juris-dot--ok { background: var(--success-fill-strong); }
.pa__juris-dot--review { background: var(--warning-fill-strong); }
.pa__juris-dot--none { background: var(--muted-fill); }

.pa__icon-btn {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 40px;
	height: 40px;
	background: transparent;
	border: 0;
	border-radius: var(--radius-md);
	color: var(--text-secondary);
	cursor: pointer;
}
.pa__icon-btn:hover {
	background: var(--surface-secondary);
	color: var(--text-primary);
}

.pa__avatar {
	width: 36px;
	height: 36px;
	border-radius: var(--radius-full);
	background: var(--philentia-blue-600);
	color: var(--white);
	display: inline-flex;
	align-items: center;
	justify-content: center;
	font-size: var(--text-body-sm);
	font-weight: var(--weight-semibold);
	flex: none;
	border: none;
	cursor: pointer;
}

.pa__avatar:focus-visible {
	outline: var(--focus-ring);
	outline-offset: 2px;
}

/* ---------------------------------------------------------------------------
 * The account menu
 * ---------------------------------------------------------------------------
 * Anchored to the avatar rather than fixed: the top bar scrolls with nothing,
 * so absolute positioning here cannot drift. `hidden` does the showing and
 * hiding — never `display` in a style attribute — so the state lives in one
 * place and assistive technology is told about it.
 */
.pa__account {
	position: relative;
	flex: none;
}

.pa__menu {
	position: absolute;
	top: calc(100% + var(--space-2));
	right: 0;
	z-index: 60;
	min-width: 272px;
	padding: var(--space-2);
	background: var(--surface);
	border: 1px solid var(--border);
	border-radius: var(--radius-lg);
	box-shadow: var(--shadow-lg);
	animation: pa-menu-in var(--duration-fast) var(--ease-out) both;
}

@keyframes pa-menu-in {
	from { opacity: 0; transform: translateY(-4px); }
	to   { opacity: 1; transform: translateY(0); }
}

.pa__menu-head {
	display: flex;
	flex-direction: column;
	gap: 2px;
	padding: var(--space-3);
	border-bottom: 1px solid var(--border);
	margin-bottom: var(--space-2);
}

.pa__menu-head strong {
	font-size: var(--text-body);
	color: var(--text-primary);
}

.pa__menu-head span {
	font-size: var(--text-caption);
	color: var(--text-muted);
	word-break: break-all;
}

.pa__menu-roles {
	display: flex;
	flex-wrap: wrap;
	gap: var(--space-2);
	padding: 0 var(--space-3) var(--space-3);
	border-bottom: 1px solid var(--border);
	margin-bottom: var(--space-2);
}

.pa__menu-form {
	margin: 0;
}

.pa__menu-item {
	display: flex;
	align-items: center;
	gap: var(--space-3);
	width: 100%;
	padding: var(--space-3);
	border: none;
	background: none;
	border-radius: var(--radius-md);
	font: inherit;
	font-size: var(--text-body-sm);
	color: var(--text-secondary);
	text-align: left;
	text-decoration: none;
	cursor: pointer;
	transition: background var(--duration-hover) var(--ease-out);
}

.pa__menu-item:hover,
.pa__menu-item:focus-visible {
	background: var(--surface-secondary);
	color: var(--text-primary);
}

.pa__menu-item--danger {
	color: var(--danger-text);
}

.pa__menu-item--danger:hover,
.pa__menu-item--danger:focus-visible {
	background: var(--danger-bg);
	color: var(--danger-text);
}

/* ===========================================================================
 * Page header
 * =========================================================================== */

.pa__page-head {
	display: flex;
	align-items: flex-start;
	gap: var(--space-4);
	flex-wrap: wrap;
	margin-bottom: var(--space-6);
}

.pa__title {
	font-size: var(--text-h1);
	font-weight: var(--weight-bold);
	line-height: var(--leading-tight);
	margin: 0;
	color: var(--text-primary);
}

.pa__lede {
	margin: var(--space-2) 0 0;
	color: var(--text-muted);
	max-width: 70ch;
	line-height: var(--leading-relaxed);
}

.pa__page-actions {
	margin-left: auto;
	display: flex;
	gap: var(--space-2);
	flex-wrap: wrap;
}

.pa__section {
	margin-bottom: var(--space-8);
}
.pa__section-title {
	font-size: var(--text-h4);
	font-weight: var(--weight-semibold);
	margin: 0 0 var(--space-4);
	color: var(--text-primary);
}

.pa__meta {
	display: flex;
	gap: var(--space-4);
	flex-wrap: wrap;
	font-size: var(--text-body-sm);
	color: var(--text-muted);
}

/* ===========================================================================
 * Tabs — the detail page pattern, identical across every object
 * =========================================================================== */

.pa__tabs {
	display: flex;
	gap: var(--space-1);
	border-bottom: 1px solid var(--border);
	margin-bottom: var(--space-6);
	overflow-x: auto;
	scrollbar-width: none;
}
.pa__tabs::-webkit-scrollbar { display: none; }

.pa__tab {
	padding: var(--space-3) var(--space-4);
	border: 0;
	border-bottom: 2px solid transparent;
	background: transparent;
	color: var(--text-muted);
	font-family: inherit;
	font-size: var(--text-body);
	font-weight: var(--weight-medium);
	white-space: nowrap;
	cursor: pointer;
	text-decoration: none;
}
.pa__tab:hover { color: var(--text-primary); }
.pa__tab[aria-selected="true"] {
	color: var(--text-link);
	border-bottom-color: var(--brand-primary);
}

/* ===========================================================================
 * Command palette
 * =========================================================================== */

.pa__overlay {
	position: fixed;
	inset: 0;
	background: rgba(16, 24, 40, 0.45);
	z-index: 60;
	display: flex;
	align-items: flex-start;
	justify-content: center;
	padding: 10vh var(--space-4) var(--space-4);
}

.pa__palette {
	width: min(640px, 100%);
	background: var(--surface);
	border-radius: var(--radius-xl);
	box-shadow: var(--shadow-lg);
	overflow: hidden;
}

.pa__palette input {
	width: 100%;
	height: 56px;
	padding: 0 var(--space-5);
	border: 0;
	border-bottom: 1px solid var(--border);
	font-family: inherit;
	font-size: var(--text-body-lg);
	color: var(--text-primary);
	background: var(--surface);
}
.pa__palette input:focus { outline: none; }

.pa__palette-list {
	max-height: 50vh;
	overflow-y: auto;
	padding: var(--space-2);
	margin: 0;
	list-style: none;
}

.pa__palette-item {
	display: flex;
	align-items: center;
	gap: var(--space-3);
	padding: var(--space-3);
	border-radius: var(--radius-md);
	color: var(--text-primary);
	text-decoration: none;
	cursor: pointer;
}
.pa__palette-item:hover,
.pa__palette-item[data-active="true"] {
	background: var(--philentia-blue-50);
}
.pa__palette-group {
	padding: var(--space-3) var(--space-3) var(--space-1);
	font-size: var(--text-caption);
	text-transform: uppercase;
	letter-spacing: 0.05em;
	color: var(--text-muted);
}

/* ===========================================================================
 * Drawer — quick read and edit, never a multi-step process
 * =========================================================================== */

.pa__drawer {
	position: fixed;
	inset: 0 0 0 auto;
	width: min(var(--rail-width), 100%);
	background: var(--surface);
	box-shadow: var(--shadow-lg);
	z-index: 61;
	display: flex;
	flex-direction: column;
	animation: pa-slide var(--duration-drawer) var(--ease-out);
}

@keyframes pa-slide {
	from { transform: translateX(100%); }
	to { transform: translateX(0); }
}

@media (prefers-reduced-motion: reduce) {
	.pa__drawer { animation: none; }
}

.pa__drawer-head {
	display: flex;
	align-items: center;
	gap: var(--space-3);
	padding: var(--space-5);
	border-bottom: 1px solid var(--border);
}
.pa__drawer-body {
	flex: 1;
	overflow-y: auto;
	padding: var(--space-5);
}

/* ===========================================================================
 * Mobile
 * =========================================================================== */

.pa__bottom-nav { display: none; }

@media (max-width: 1023px) {
	.pa__sidebar {
		transform: translateX(-100%);
		transition: transform var(--duration-base) var(--ease-out);
		width: var(--sidebar-width);
	}
	.pa[data-drawer-open="true"] .pa__sidebar { transform: translateX(0); }
	.pa__main { margin-left: 0; }
}

@media (max-width: 767px) {
	.pa__workspace { padding: var(--space-4); }
	.pa__topbar { padding: 0 var(--space-4); gap: var(--space-2); }
	.pa__search { min-width: 0; width: 40px; padding: 0; justify-content: center; }
	.pa__search span, .pa__search kbd { display: none; }
	.pa__entity-where { display: none; }
	.pa__title { font-size: var(--text-h2); }
}

@media (max-width: 639px) {
	.pa__main { padding-bottom: 72px; }
	/* A table narrower than its columns crushes them into one word per line;
	   it keeps its shape and the wrapper scrolls sideways instead. */
	.ph-table-wrap .ph-table { min-width: 560px; }
	.pa__entity { max-width: 160px; }
	.pa__juris { display: none; }

	.pa__bottom-nav {
		position: fixed;
		inset: auto 0 0 0;
		z-index: 50;
		display: grid;
		grid-template-columns: repeat(5, 1fr);
		background: var(--surface);
		border-top: 1px solid var(--border);
		padding-bottom: env(safe-area-inset-bottom, 0);
	}
	.pa__bottom-item {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		gap: 2px;
		min-height: 60px;
		color: var(--text-muted);
		text-decoration: none;
		font-size: 0.6875rem;
	}
	.pa__bottom-item[aria-current="page"] { color: var(--text-link); }
}


/* ===========================================================================
   Print: any screen is a report
   =========================================================================== */
.pa__print-head { display: none; }
@media print {
	@page { margin: 14mm 12mm; }
	html, body { background: #fff !important; }
	.pa__sidebar, .pa__topbar, .pa__bottom-nav, .pa__notice, .pa__page-actions, .ph-btn, button,
	form.ph-row, .pa__tabs, .ph-source--unverified.pa__print-hide, [data-print-hide] { display: none !important; }
	.pa__main { margin-left: 0 !important; width: 100% !important; }
	.pa__workspace { padding: 0 !important; max-width: none !important; }
	.pa__print-head {
		display: flex; align-items: center; gap: 14px; border-bottom: 2px solid #1a1a1a;
		padding-bottom: 8px; margin-bottom: 16px; font-size: 10pt; color: #444;
	}
	.pa__print-head img { height: 48px; width: auto; }
	.pa__print-head strong { font-size: 13pt; color: #111; }
	.pa__print-meta { margin-left: auto; text-align: right; font-size: 9pt; color: #666; }
	.ph-card, .ph-table-wrap { box-shadow: none !important; border-color: #ccc !important; break-inside: avoid; }
	.ph-table { font-size: 9.5pt; }
	.ph-table th, .ph-table td { padding: 4pt 6pt !important; }
	a { color: inherit !important; text-decoration: none !important; }
	.ph-badge { border: 1px solid #999 !important; background: #fff !important; color: #111 !important; }
	.ph-grid--kpi { grid-template-columns: repeat(4, 1fr) !important; }
}

/* Skip link: invisible until a keyboard user tabs into the page, then the first thing they reach. */
.pa__skip {
	position: absolute;
	left: -9999px;
	top: 8px;
	z-index: 1000;
	padding: 10px 14px;
	border-radius: 8px;
	background: var(--brand-primary, #4b63b3);
	color: #fff;
	font-weight: 600;
	text-decoration: none;
}
.pa__skip:focus {
	left: 12px;
	outline: 3px solid #f2a93b;
	outline-offset: 2px;
}
