/**
 * Household Expense Tracker - frontend application styles.
 * Scoped under .het-app so themes are never affected.
 */

.het-app {
	--het-bg: #f4f6f8;
	--het-surface: #ffffff;
	--het-surface-alt: #fafbfc;
	--het-border: #e2e6ea;
	--het-border-strong: #cdd4da;
	--het-text: #1d2429;
	--het-text-muted: #667180;
	--het-primary: #1f6feb;
	--het-primary-dark: #1857b8;
	--het-primary-soft: #e8f0fe;
	--het-success: #1f8f5f;
	--het-success-soft: #e6f4ee;
	--het-warning: #b7791f;
	--het-warning-soft: #fdf3e2;
	--het-danger: #c0392b;
	--het-danger-soft: #fbeceb;
	--het-radius: 12px;
	--het-radius-sm: 8px;
	--het-gap: 20px;
	--het-shadow: 0 1px 2px rgba(16, 24, 40, 0.04);

	position: relative;
	display: grid;
	/*
	 * minmax(0, 1fr) is required: a bare 1fr keeps an automatic min-content
	 * floor, so a wide table would push the whole app past the viewport
	 * instead of scrolling inside its own card.
	 */
	grid-template-columns: minmax(0, 248px) minmax(0, 1fr);
	grid-template-areas: "sidebar main";
	max-width: 100%;
	gap: var(--het-gap);
	box-sizing: border-box;
	padding: var(--het-gap);
	background: var(--het-bg);
	color: var(--het-text);
	font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
	font-size: 15px;
	line-height: 1.5;
	min-height: 60vh;
}

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

/*
 * Several components set an explicit display, which outranks the user agent's
 * [hidden] rule on specificity. Without this the empty and error states render
 * permanently on every screen.
 */
.het-app [hidden] {
	display: none !important;
}

/*
 * Nothing inside the app may establish a min-content floor wider than its
 * parent. Without this an embedded table or long word makes the page scroll
 * sideways instead of the element scrolling internally.
 */
.het-app :is(.het-main, .het-screen, .het-card, .het-kpi, .het-field, .het-form__row > *, .het-grid > *, .het-cards > *, .het-list__row, .het-txcard, [data-het-content]) {
	min-width: 0;
	max-width: 100%;
}

.het-app--standalone,
.het-app--gate {
	grid-template-columns: minmax(0, 1fr);
	grid-template-areas: "main";
}

/* A single-screen shortcode has no bottom navigation to clear. */
.het-app--standalone.is-narrow,
.het-app--gate.is-narrow {
	padding-bottom: 12px;
}

.het-app .screen-reader-text {
	position: absolute !important;
	width: 1px;
	height: 1px;
	overflow: hidden;
	clip: rect(1px, 1px, 1px, 1px);
	white-space: nowrap;
}

/* Topbar ------------------------------------------------------------- */

.het-topbar {
	display: none;
	align-items: center;
	gap: 12px;
	grid-column: 1 / -1;
}

.het-topbar__title {
	display: flex;
	flex-direction: column;
	line-height: 1.2;
	flex: 1;
	min-width: 0;
}

.het-topbar__household {
	font-weight: 600;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

.het-topbar__role {
	font-size: 12px;
	color: var(--het-text-muted);
}

.het-topbar__actions {
	position: relative;
}

.het-badge {
	position: absolute;
	top: -2px;
	right: -2px;
	min-width: 18px;
	padding: 0 5px;
	border-radius: 9px;
	background: var(--het-danger);
	color: #fff;
	font-size: 11px;
	line-height: 18px;
	text-align: center;
}

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

.het-sidebar {
	grid-area: sidebar;
	background: var(--het-surface);
	border: 1px solid var(--het-border);
	border-radius: var(--het-radius);
	padding: 12px;
	align-self: start;
	position: sticky;
	top: 20px;
}

.het-sidebar__list {
	list-style: none;
	margin: 0;
	padding: 0;
	display: flex;
	flex-direction: column;
	gap: 2px;
}

.het-navlink {
	display: flex;
	align-items: center;
	gap: 10px;
	width: 100%;
	padding: 10px 12px;
	border: 0;
	border-radius: var(--het-radius-sm);
	background: transparent;
	color: var(--het-text);
	font: inherit;
	text-align: left;
	cursor: pointer;
	min-height: 44px;
}

.het-navlink:hover {
	background: var(--het-surface-alt);
}

.het-navlink.is-active {
	background: var(--het-primary-soft);
	color: var(--het-primary-dark);
	font-weight: 600;
}

.het-icon {
	display: inline-flex;
	flex: 0 0 auto;
	width: 18px;
	height: 18px;
	color: currentColor;
}

.het-icon svg {
	width: 100%;
	height: 100%;
	display: block;
	stroke: currentColor;
	fill: none;
	stroke-width: 1.75;
	stroke-linecap: round;
	stroke-linejoin: round;
}

.het-navlink .het-icon {
	opacity: 0.55;
}

.het-navlink.is-active .het-icon,
.het-navlink:hover .het-icon {
	opacity: 1;
}

/* Main --------------------------------------------------------------- */

.het-main {
	grid-area: main;
	min-width: 0;
	display: flex;
	flex-direction: column;
	gap: var(--het-gap);
}

.het-screen {
	display: flex;
	flex-direction: column;
	gap: var(--het-gap);
}

.het-screen[hidden] {
	display: none;
}

.het-screen__head {
	display: flex;
	flex-wrap: wrap;
	align-items: flex-end;
	justify-content: space-between;
	gap: 12px;
}

.het-screen__title {
	margin: 0;
	font-size: 24px;
	line-height: 1.25;
	font-weight: 650;
}

.het-screen__sub {
	margin: 4px 0 0;
	color: var(--het-text-muted);
	font-size: 14px;
}

.het-screen__actions {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 8px;
}

/* Cards -------------------------------------------------------------- */

.het-card {
	background: var(--het-surface);
	border: 1px solid var(--het-border);
	border-radius: var(--het-radius);
	padding: 18px;
	box-shadow: var(--het-shadow);
}

.het-card--flush {
	padding: 0;
	overflow: hidden;
}

.het-card__head {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 12px;
	margin-bottom: 12px;
}

.het-card__title {
	margin: 0 0 12px;
	font-size: 15px;
	font-weight: 650;
	letter-spacing: 0.01em;
}

.het-card__head .het-card__title {
	margin: 0;
}

.het-grid {
	display: grid;
	gap: var(--het-gap);
}

.het-grid--2 {
	grid-template-columns: repeat(2, minmax(0, 1fr));
}

.het-grid--3 {
	grid-template-columns: repeat(3, minmax(0, 1fr));
}

/* KPIs --------------------------------------------------------------- */

.het-kpis {
	display: grid;
	grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
	gap: 12px;
}

.het-kpi {
	background: var(--het-surface);
	border: 1px solid var(--het-border);
	border-radius: var(--het-radius);
	padding: 16px;
}

.het-kpi__label {
	margin: 0;
	font-size: 12px;
	text-transform: uppercase;
	letter-spacing: 0.06em;
	color: var(--het-text-muted);
}

.het-kpi__value {
	margin: 6px 0 0;
	font-size: 22px;
	font-weight: 650;
	overflow-wrap: anywhere;
}

.het-kpi__meta {
	margin: 4px 0 0;
	font-size: 12px;
	color: var(--het-text-muted);
}

.het-kpi__meta.is-up {
	color: var(--het-danger);
}

.het-kpi__meta.is-down {
	color: var(--het-success);
}

/* Buttons ------------------------------------------------------------ */

.het-btn {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: 6px;
	min-height: 42px;
	padding: 0 16px;
	border: 1px solid transparent;
	border-radius: var(--het-radius-sm);
	font: inherit;
	font-weight: 550;
	line-height: 1;
	cursor: pointer;
	text-decoration: none;
	transition: background-color 0.15s ease, border-color 0.15s ease;
}

.het-btn--primary {
	background: var(--het-primary);
	color: #fff;
}

.het-btn--primary:hover {
	background: var(--het-primary-dark);
}

.het-btn--secondary {
	background: var(--het-surface);
	border-color: var(--het-border-strong);
	color: var(--het-text);
}

.het-btn--secondary:hover {
	background: var(--het-surface-alt);
}

.het-btn--danger {
	background: var(--het-danger);
	color: #fff;
}

.het-btn--text {
	background: transparent;
	color: var(--het-primary-dark);
	padding: 0 8px;
}

.het-btn[disabled],
.het-btn.is-busy {
	opacity: 0.6;
	cursor: not-allowed;
}

.het-btn--sm {
	min-height: 34px;
	padding: 0 10px;
	font-size: 13px;
}

.het-icon-btn {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 44px;
	height: 44px;
	border: 1px solid var(--het-border);
	border-radius: var(--het-radius-sm);
	background: var(--het-surface);
	color: var(--het-text);
	font-size: 18px;
	cursor: pointer;
	position: relative;
}

.het-app :is(button, a, input, select, textarea, summary):focus-visible {
	outline: 2px solid var(--het-primary);
	outline-offset: 2px;
}

.het-burger,
.het-burger::before,
.het-burger::after {
	display: block;
	width: 18px;
	height: 2px;
	background: currentColor;
	border-radius: 2px;
	position: relative;
}

.het-burger::before,
.het-burger::after {
	content: "";
	position: absolute;
	left: 0;
}

.het-burger::before {
	top: -6px;
}

.het-burger::after {
	top: 6px;
}

/* Forms -------------------------------------------------------------- */

.het-form {
	display: flex;
	flex-direction: column;
	gap: 18px;
}

.het-fieldset {
	border: 0;
	margin: 0;
	padding: 0;
	display: flex;
	flex-direction: column;
	gap: 14px;
}

.het-fieldset__legend {
	padding: 0;
	font-size: 13px;
	font-weight: 650;
	text-transform: uppercase;
	letter-spacing: 0.06em;
	color: var(--het-text-muted);
}

.het-form__row {
	display: grid;
	grid-template-columns: repeat(2, minmax(0, 1fr));
	gap: 14px;
}

.het-field {
	display: flex;
	flex-direction: column;
	gap: 6px;
	min-width: 0;
}

.het-field--inline {
	flex-direction: row;
	align-items: center;
}

.het-label {
	font-size: 13px;
	font-weight: 550;
}

.het-required {
	color: var(--het-danger);
}

.het-input {
	width: 100%;
	min-height: 44px;
	padding: 10px 12px;
	border: 1px solid var(--het-border-strong);
	border-radius: var(--het-radius-sm);
	background: var(--het-surface);
	color: var(--het-text);
	font: inherit;
}

textarea.het-input {
	min-height: 88px;
	resize: vertical;
}

.het-input--amount {
	font-size: 20px;
	font-weight: 600;
}

.het-input[aria-invalid="true"] {
	border-color: var(--het-danger);
	background: var(--het-danger-soft);
}

.het-hint {
	margin: 0;
	font-size: 12px;
	color: var(--het-text-muted);
}

.het-error {
	margin: 0;
	font-size: 13px;
	color: var(--het-danger);
}

.het-checkbox {
	display: flex;
	align-items: center;
	gap: 8px;
	font-size: 14px;
	min-height: 44px;
}

.het-checkbox input {
	width: 18px;
	height: 18px;
}

.het-form__actions {
	display: flex;
	flex-wrap: wrap;
	gap: 8px;
	padding-top: 4px;
	border-top: 1px solid var(--het-border);
}

.het-form__alert {
	border-radius: var(--het-radius-sm);
	padding: 12px 14px;
}

.het-quickadd {
	display: flex;
	flex-wrap: wrap;
	gap: 8px;
}

.het-chip {
	min-height: 38px;
	padding: 0 14px;
	border: 1px solid var(--het-border-strong);
	border-radius: 999px;
	background: var(--het-surface-alt);
	font: inherit;
	font-size: 13px;
	cursor: pointer;
}

.het-chip:hover,
.het-chip.is-active {
	background: var(--het-primary-soft);
	border-color: var(--het-primary);
	color: var(--het-primary-dark);
}

.het-receipt__row {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 8px;
}

.het-receipt__name {
	font-size: 13px;
	color: var(--het-text-muted);
	overflow-wrap: anywhere;
}

/* Filters ------------------------------------------------------------ */

.het-filters {
	background: var(--het-surface);
	border: 1px solid var(--het-border);
	border-radius: var(--het-radius);
	padding: 12px 18px;
}

.het-filters__summary {
	cursor: pointer;
	font-weight: 600;
	min-height: 32px;
	display: flex;
	align-items: center;
}

.het-filters__form,
.het-report-filters {
	display: grid;
	grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
	gap: 12px;
	padding-top: 14px;
}

.het-report-filters {
	padding-top: 0;
	align-items: end;
}

.het-filters__actions {
	display: flex;
	align-items: flex-end;
	gap: 8px;
	grid-column: 1 / -1;
}

/* Tables and lists --------------------------------------------------- */

.het-tablewrap {
	width: 100%;
	max-width: 100%;
	overflow-x: auto;
	-webkit-overflow-scrolling: touch;
	overscroll-behavior-x: contain;
}

.het-table {
	width: 100%;
	/* Keeps columns readable and moves the overflow into the wrapper's own scroll. */
	min-width: 680px;
	border-collapse: collapse;
	font-size: 14px;
}

.het-table th,
.het-table td {
	padding: 12px 16px;
	text-align: left;
	border-bottom: 1px solid var(--het-border);
	vertical-align: middle;
}

.het-table th {
	background: var(--het-surface-alt);
	font-size: 12px;
	text-transform: uppercase;
	letter-spacing: 0.05em;
	color: var(--het-text-muted);
	font-weight: 600;
	white-space: nowrap;
}

.het-table tbody tr:last-child td {
	border-bottom: 0;
}

.het-amount {
	font-variant-numeric: tabular-nums;
	font-weight: 600;
	white-space: nowrap;
	text-align: right;
}

.het-amount--expense {
	color: var(--het-danger);
}

.het-amount--income {
	color: var(--het-success);
}

.het-amount--transfer {
	color: var(--het-text-muted);
}

.het-rowactions {
	display: flex;
	gap: 4px;
	justify-content: flex-end;
}

.het-cards {
	display: grid;
	grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
	gap: 12px;
}

.het-txcards {
	display: none;
	flex-direction: column;
	gap: 10px;
	padding: 12px;
}

.het-txcard {
	border: 1px solid var(--het-border);
	border-radius: var(--het-radius-sm);
	padding: 12px;
	display: flex;
	flex-direction: column;
	gap: 6px;
}

.het-txcard__top {
	display: flex;
	justify-content: space-between;
	gap: 10px;
	align-items: baseline;
}

.het-txcard__meta {
	font-size: 12px;
	color: var(--het-text-muted);
	display: flex;
	flex-wrap: wrap;
	gap: 8px;
}

.het-list {
	list-style: none;
	margin: 0;
	padding: 0;
	display: flex;
	flex-direction: column;
	gap: 10px;
}

.het-list__row {
	display: flex;
	justify-content: space-between;
	gap: 10px;
	align-items: center;
	font-size: 14px;
}

.het-list__label {
	min-width: 0;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

/* Progress ----------------------------------------------------------- */

.het-progress {
	display: flex;
	flex-direction: column;
	gap: 6px;
	margin-bottom: 14px;
}

.het-progress__head {
	display: flex;
	justify-content: space-between;
	gap: 10px;
	font-size: 14px;
}

.het-progress__bar {
	height: 8px;
	border-radius: 999px;
	background: var(--het-border);
	overflow: hidden;
}

.het-progress__fill {
	display: block;
	height: 100%;
	border-radius: 999px;
	background: var(--het-success);
	transition: width 0.3s ease;
}

.het-progress--warning .het-progress__fill {
	background: #d9a441;
}

.het-progress--high .het-progress__fill {
	background: #e07b39;
}

.het-progress--exceeded .het-progress__fill {
	background: var(--het-danger);
}

.het-progress__meta {
	font-size: 12px;
	color: var(--het-text-muted);
	display: flex;
	justify-content: space-between;
	gap: 8px;
}

/* Pills -------------------------------------------------------------- */

.het-pill {
	display: inline-flex;
	align-items: center;
	padding: 3px 10px;
	border-radius: 999px;
	font-size: 12px;
	font-weight: 600;
	background: var(--het-surface-alt);
	color: var(--het-text-muted);
	white-space: nowrap;
}

.het-pill--upcoming { background: var(--het-primary-soft); color: var(--het-primary-dark); }
.het-pill--due_soon { background: var(--het-warning-soft); color: var(--het-warning); }
.het-pill--overdue { background: var(--het-danger-soft); color: var(--het-danger); }
.het-pill--paid { background: var(--het-success-soft); color: var(--het-success); }
.het-pill--cancelled { background: #eef0f2; color: var(--het-text-muted); }
.het-pill--archived { background: #eef0f2; color: var(--het-text-muted); }

/* Charts ------------------------------------------------------------- */

.het-chart {
	position: relative;
	width: 100%;
	height: 260px;
}

.het-chart--tall {
	height: 340px;
}

/*
 * Pinning the canvas stops Chart.js from feeding its own rendered size back
 * into the layout, which otherwise grows the card on every resize.
 */
.het-chart canvas {
	position: absolute;
	inset: 0;
	width: 100% !important;
	height: 100% !important;
	max-width: 100%;
}

/* States ------------------------------------------------------------- */

.het-state {
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	gap: 10px;
	padding: 32px 18px;
	border-radius: var(--het-radius);
	text-align: center;
	color: var(--het-text-muted);
	background: var(--het-surface);
	border: 1px dashed var(--het-border-strong);
}

.het-state--error {
	border-style: solid;
	border-color: var(--het-danger);
	background: var(--het-danger-soft);
	color: var(--het-danger);
	text-align: left;
	align-items: flex-start;
	padding: 14px 16px;
}

.het-spinner {
	width: 18px;
	height: 18px;
	border: 2px solid var(--het-border-strong);
	border-top-color: var(--het-primary);
	border-radius: 50%;
	animation: het-spin 0.8s linear infinite;
}

@keyframes het-spin {
	to { transform: rotate(360deg); }
}

@media (prefers-reduced-motion: reduce) {
	.het-spinner { animation-duration: 3s; }
	.het-app * { transition: none !important; }
}

/* Pagination --------------------------------------------------------- */

.het-pagination {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	justify-content: center;
	gap: 6px;
	padding: 14px;
	border-top: 1px solid var(--het-border);
}

.het-pagination button {
	min-width: 40px;
	min-height: 40px;
	border: 1px solid var(--het-border-strong);
	border-radius: var(--het-radius-sm);
	background: var(--het-surface);
	font: inherit;
	cursor: pointer;
}

.het-pagination button.is-active {
	background: var(--het-primary);
	border-color: var(--het-primary);
	color: #fff;
}

/* Modal -------------------------------------------------------------- */

.het-modal {
	position: fixed;
	inset: 0;
	z-index: 100000;
	display: flex;
	align-items: center;
	justify-content: center;
	padding: 16px;
}

.het-modal[hidden] {
	display: none;
}

.het-modal__backdrop {
	position: absolute;
	inset: 0;
	background: rgba(16, 24, 40, 0.45);
}

.het-modal__panel {
	position: relative;
	width: min(640px, 100%);
	max-height: min(88vh, 900px);
	display: flex;
	flex-direction: column;
	background: var(--het-surface);
	border-radius: var(--het-radius);
	box-shadow: 0 20px 45px rgba(16, 24, 40, 0.2);
}

.het-modal__header {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 12px;
	padding: 16px 18px;
	border-bottom: 1px solid var(--het-border);
}

.het-modal__title {
	margin: 0;
	font-size: 17px;
	font-weight: 650;
}

.het-modal__body {
	padding: 18px;
	overflow-y: auto;
}

/* Drawer ------------------------------------------------------------- */

.het-drawer {
	position: fixed;
	top: 0;
	right: 0;
	bottom: 0;
	width: min(380px, 92vw);
	z-index: 100001;
	background: var(--het-surface);
	border-left: 1px solid var(--het-border);
	box-shadow: -8px 0 24px rgba(16, 24, 40, 0.12);
	display: flex;
	flex-direction: column;
}

.het-drawer[hidden] {
	display: none;
}

.het-drawer__header {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 8px;
	padding: 14px 16px;
	border-bottom: 1px solid var(--het-border);
}

.het-drawer__header h2 {
	margin: 0;
	font-size: 16px;
}

.het-drawer__body {
	padding: 12px 16px;
	overflow-y: auto;
	display: flex;
	flex-direction: column;
	gap: 10px;
}

.het-notification {
	border: 1px solid var(--het-border);
	border-left-width: 3px;
	border-radius: var(--het-radius-sm);
	padding: 10px 12px;
	font-size: 14px;
}

.het-notification--warning { border-left-color: #d9a441; }
.het-notification--danger { border-left-color: var(--het-danger); }
.het-notification--success { border-left-color: var(--het-success); }
.het-notification--info { border-left-color: var(--het-primary); }

.het-notification.is-read {
	opacity: 0.6;
}

.het-notification__meta {
	font-size: 12px;
	color: var(--het-text-muted);
	display: flex;
	justify-content: space-between;
	gap: 8px;
	margin-top: 4px;
}

/* Toasts ------------------------------------------------------------- */

.het-toasts {
	position: fixed;
	right: 16px;
	bottom: 16px;
	z-index: 100002;
	display: flex;
	flex-direction: column;
	gap: 8px;
	max-width: min(360px, calc(100vw - 32px));
}

.het-toast {
	padding: 12px 14px;
	border-radius: var(--het-radius-sm);
	background: #12181f;
	color: #fff;
	font-size: 14px;
	box-shadow: 0 8px 24px rgba(16, 24, 40, 0.24);
}

.het-toast--success { background: #14603f; }
.het-toast--error { background: #8f2c22; }

/* Scrim and mobile nav ----------------------------------------------- */

.het-scrim {
	position: fixed;
	inset: 0;
	background: rgba(16, 24, 40, 0.4);
	z-index: 99998;
}

.het-scrim[hidden] {
	display: none;
}

.het-bottomnav {
	display: none;
}

.het-gate {
	max-width: 520px;
	margin: 0 auto;
	text-align: center;
}

.het-gate__title {
	margin: 0 0 8px;
	font-size: 20px;
}

.het-gate__text {
	color: var(--het-text-muted);
	margin: 0 0 16px;
}

/* Responsive ---------------------------------------------------------
 *
 * The app is a shortcode: its container can be far narrower than the
 * viewport, so viewport media queries alone give the wrong answer. A
 * ResizeObserver measures the app's own width and sets .is-narrow /
 * .is-tiny, and every layout switch below keys off those classes. The
 * media block at the end is a no-JS fallback and stands down as soon as
 * JavaScript has measured (.is-measured).
 */

.het-app.is-medium .het-grid--3 {
	grid-template-columns: repeat(2, minmax(0, 1fr));
}

.het-app.is-narrow {
	grid-template-columns: minmax(0, 1fr);
	grid-template-areas:
		"topbar"
		"main";
	padding: 12px;
	padding-bottom: 84px;
	gap: 14px;
}

.het-app.is-narrow .het-topbar {
	display: flex;
	grid-area: topbar;
}

.het-app.is-narrow .het-sidebar {
	position: fixed;
	top: 0;
	left: 0;
	bottom: 0;
	width: min(280px, 84vw);
	z-index: 99999;
	border-radius: 0;
	border-width: 0 1px 0 0;
	transform: translateX(-102%);
	transition: transform 0.22s ease;
	overflow-y: auto;
}

.het-app.is-narrow .het-sidebar.is-open {
	transform: translateX(0);
}

.het-app.is-narrow .het-grid--2,
.het-app.is-narrow .het-grid--3 {
	grid-template-columns: minmax(0, 1fr);
}

.het-app.is-narrow .het-screen__head {
	align-items: flex-start;
	flex-direction: column;
}

.het-app.is-narrow .het-screen__actions {
	width: 100%;
}

.het-app.is-narrow .het-screen__actions .het-btn {
	flex: 1 1 auto;
}

.het-app.is-narrow .het-form__row,
.het-app.is-narrow .het-filters__form,
.het-app.is-narrow .het-report-filters {
	grid-template-columns: minmax(0, 1fr);
}

/* Below this width a wide table stops being readable, so rows become cards. */
.het-app.is-narrow .het-tablewrap {
	display: none;
}

.het-app.is-narrow .het-txcards {
	display: flex;
}

.het-app.is-narrow .het-cards {
	grid-template-columns: minmax(0, 1fr);
}

.het-app.is-narrow .het-bottomnav {
	position: fixed;
	left: 0;
	right: 0;
	bottom: 0;
	z-index: 99997;
	display: grid;
	grid-auto-flow: column;
	grid-auto-columns: 1fr;
	background: var(--het-surface);
	border-top: 1px solid var(--het-border);
	padding: 4px 2px calc(4px + env(safe-area-inset-bottom, 0px));
}

.het-bottomnav__item {
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	gap: 3px;
	min-height: 56px;
	border: 0;
	background: transparent;
	font: inherit;
	font-size: 11px;
	color: var(--het-text-muted);
	cursor: pointer;
}

.het-bottomnav__item.is-active {
	color: var(--het-primary-dark);
	font-weight: 600;
}

.het-bottomnav__item .het-icon {
	width: 20px;
	height: 20px;
	opacity: 0.65;
}

.het-bottomnav__item.is-active .het-icon {
	opacity: 1;
}

.het-app.is-narrow .het-chart {
	height: 240px;
}

.het-app.is-narrow .het-modal {
	align-items: flex-end;
	padding: 0;
}

.het-app.is-narrow .het-modal__panel {
	width: 100%;
	max-height: 92vh;
	border-radius: var(--het-radius) var(--het-radius) 0 0;
}

.het-app.is-narrow .het-toasts {
	left: 12px;
	right: 12px;
	bottom: 76px;
	max-width: none;
}

.het-app.is-tiny {
	padding: 10px;
	padding-bottom: 84px;
}

.het-app.is-tiny .het-card {
	padding: 14px;
}

.het-app.is-tiny .het-screen__title {
	font-size: 20px;
}

.het-app.is-tiny .het-kpis {
	grid-template-columns: repeat(2, minmax(0, 1fr));
}

.het-app.is-tiny .het-kpi__value {
	font-size: 17px;
}

.het-app.is-tiny .het-chart {
	height: 200px;
}

/* No-JS fallback: stands down once the observer has measured. */
@media (max-width: 900px) {
	.het-app:not(.is-measured) {
		grid-template-columns: minmax(0, 1fr);
		grid-template-areas:
			"topbar"
			"main";
		padding: 12px;
		padding-bottom: 84px;
	}

	.het-app:not(.is-measured) .het-topbar {
		display: flex;
		grid-area: topbar;
	}

	.het-app:not(.is-measured) .het-sidebar {
		position: fixed;
		top: 0;
		left: 0;
		bottom: 0;
		width: min(280px, 84vw);
		z-index: 99999;
		border-radius: 0;
		transform: translateX(-102%);
		overflow-y: auto;
	}

	.het-app:not(.is-measured) .het-sidebar.is-open {
		transform: translateX(0);
	}

	.het-app:not(.is-measured) .het-grid--2,
	.het-app:not(.is-measured) .het-grid--3,
	.het-app:not(.is-measured) .het-form__row {
		grid-template-columns: minmax(0, 1fr);
	}

	.het-app:not(.is-measured) .het-tablewrap {
		display: none;
	}

	.het-app:not(.is-measured) .het-txcards {
		display: flex;
	}
}
