/*
 * 📌 Path: client/assets/css/mobile.css
 *
 * Additive phone-only UI layer for the authenticated SPA shell.
 * Every rule is scoped to <= 767.98px, so tablet/desktop layouts keep their
 * existing styles byte-for-byte. Loaded after assets/css/style.css.
 */

@media screen and (max-width: 767.98px) {
	/* =========================================================
	   1. SHELL, HEADER & SAFE AREAS
	   ========================================================= */
	html,
	body {
		overflow-x: hidden;
		-webkit-text-size-adjust: 100%;
	}

	#top-header {
		height: auto;
		min-height: 56px;
		padding: max(6px, env(safe-area-inset-top)) 8px 6px;
		gap: 6px;
	}

	#top-header > div {
		min-width: 0;
	}

	#top-header > div:first-child,
	#top-header > div:first-child > div {
		gap: 5px;
	}

	#top-header > div:last-child {
		gap: 4px;
	}

	#top-header button,
	#top-header > div:last-child > a,
	#top-header #notificationBell,
	#top-header a[href="/pages/auth/changepassword.html"],
	#top-header > div:last-child > button {
		display: inline-flex;
		align-items: center;
		justify-content: center;
		min-width: 44px;
		min-height: 44px;
		padding: 0;
		flex: 0 0 auto;
	}

	/* The decorative glyph before the wordmark renders as a broken character
	   on phones, so keep the mobile lockup clean. */
	#top-header .tw-bg-whitex strong {
		display: none;
	}

	#top-header #notificationBell svg {
		width: 20px;
		height: 20px;
	}

	#top-header img {
		width: 44px;
		height: 34px;
	}

	#top-header .tw-min-w-0 {
		overflow: hidden;
	}

	main {
		padding-bottom: calc(56px + env(safe-area-inset-bottom)) !important;
	}

	#sidebar {
		width: min(18rem, calc(100vw - 3.25rem)) !important;
		max-width: 86vw;
		overflow-y: auto;
		overscroll-behavior: contain;
		padding-bottom: env(safe-area-inset-bottom);
		box-shadow: 28px 0 70px -36px rgba(2, 6, 23, 0.9);
	}

	#sidebar #main-sidebar-navigation {
		overflow-y: auto;
		overscroll-behavior: contain;
		padding-bottom: 12px;
	}

	#sidebar #main-sidebar-navigation a,
	#sidebar #main-sidebar-navigation button {
		min-height: 44px;
		padding-top: 10px;
		padding-bottom: 10px;
	}

	/* Fixed bottom navigation */
	body > nav.tw-fixed {
		height: auto !important;
		min-height: 56px;
		padding-top: 2px;
		padding-bottom: max(2px, env(safe-area-inset-bottom));
	}

	body > nav.tw-fixed button,
	body > nav.tw-fixed a {
		min-height: 48px;
		padding-top: 4px;
		padding-bottom: 4px;
	}

	body > nav.tw-fixed span {
		white-space: nowrap;
		line-height: 1.2;
	}

	/* Toast sits clear of the fixed bottom navigation. Keep it a compact
	   floating pill: stretching left+right across the viewport turned error
	   toasts (tw-bg-red-500 from the tab permission check) into a full-width
	   red bar directly above the nav. Shrink-to-fit preserves the message
	   while the red still reads as an alert instead of a page-level banner. */
	#toast {
		left: 12px;
		right: auto;
		width: auto;
		max-width: calc(100vw - 24px);
		min-height: 44px;
		bottom: calc(72px + env(safe-area-inset-bottom)) !important;
		padding: 8px 14px !important;
		border-radius: 9999px !important;
		justify-content: flex-start;
		text-align: left;
	}

	/* =========================================================
	   2. SCROLL STAGE & CONTENT RHYTHM
	   ========================================================= */
	#scrollableContent {
		padding: 10px;
		overflow-x: hidden;
		overscroll-behavior-y: contain;
		-webkit-overflow-scrolling: touch;
	}

	#scrollableContent,
	#mainForm,
	#view-dashboard,
	#view-modules,
	#moduleContener {
		min-width: 0;
		max-width: 100%;
	}

	#scrollableContent img {
		max-width: 100%;
		height: auto;
	}

	#scrollableContent [class*="overflow-x-auto"],
	#scrollableContent [class*="table-scroll"] {
		max-width: 100%;
		-webkit-overflow-scrolling: touch;
	}

	/* =========================================================
	   3. MODULE HERO, TAB STRIP & SEARCH ROW
	   ========================================================= */
	/* A 250px sticky hero leaves almost no reading room on a phone. Let the
	   whole hero scroll away with the content instead. */
	#stickyContent {
		position: static !important;
		box-shadow: none;
	}

	#gradientHero {
		padding: 10px 12px !important;
		background-image: linear-gradient(
			118deg,
			#0b2a4a 0%,
			#123a63 52%,
			#155e75 100%
		) !important;
	}

	#hero-header-container #tabTitle-header {
		font-size: 14px !important;
		line-height: 1.3;
	}

	#hero-header-container #tabDesc-header {
		margin-top: 2px !important;
		font-size: 11.5px !important;
		line-height: 1.45;
		color: #cffafe !important;
	}

	#top-right-container-tabs:not(:has(button)) {
		display: none !important;
	}

	#top-right-container-tabs {
		display: flex !important;
		flex-wrap: nowrap !important;
		justify-content: flex-start !important;
		width: 100%;
		max-width: 100%;
		overflow-x: auto;
		overflow-y: hidden;
		padding: 4px !important;
		border-radius: 10px;
		scrollbar-width: none;
		-ms-overflow-style: none;
		scroll-behavior: smooth;
		scroll-padding-inline: 4px;
		-webkit-overflow-scrolling: touch;
	}

	#top-right-container-tabs::-webkit-scrollbar {
		display: none;
	}

	/* Compact, icon-focused sub-tabs. Labels stay visible (several containers
	   share the same icon) but padding is tightened so more tabs fit before the
	   strip needs to scroll. */
	#top-right-container-tabs button {
		flex: 0 0 auto;
		min-height: 44px;
		padding: 7px 10px !important;
		gap: 6px !important;
		white-space: nowrap;
	}

	/* Icon-only container tabs. Labels move to aria-label/title in JS.
	   Keyed off data-m-icon as well because rbac-navigation.js rewrites
	   button.className on every tab click and would briefly drop the class. */
	#top-right-container-tabs button.m-icon-btn,
	#top-right-container-tabs button[data-m-icon="1"] {
		width: 36px !important;
		min-width: 36px !important;
		height: 36px !important;
		min-height: 36px !important;
		padding: 0 !important;
		gap: 0 !important;
		justify-content: center;
	}

	#top-right-container-tabs button[data-m-icon="1"] .m-btn-label {
		display: none !important;
	}

	#top-right-container-tabs button svg {
		width: 16px !important;
		height: 16px !important;
		margin: 0 !important;
		flex: 0 0 auto;
	}

	/* Dashboard scope group and year badge stay intact and unscrunched inside
	   the scrollable icon strip. */
	#top-right-container-tabs #rdHeaderControls,
	#top-right-container-tabs #rdScopeToggle,
	#top-right-container-tabs #rdYearBadge {
		flex: 0 0 auto;
	}

	#top-right-container-tabs button.m-icon-btn:focus-visible,
	#top-right-container-tabs button[data-m-icon="1"]:focus-visible {
		outline: 2px solid #2563eb;
		outline-offset: 2px;
	}

	#hero-header-container > div:last-child {
		display: flex;
		flex-wrap: wrap;
		align-items: stretch;
		gap: 8px;
		padding: 8px 10px !important;
	}

	#hero-header-container #search-control-input {
		flex: 1 1 100%;
		max-width: none;
	}

	/* Search scope and quick actions share the second row so the hero does not
	   waste a whole row on empty space. */
	#hero-header-container #search-control-select {
		flex: 1 1 0;
		min-width: 0;
		max-width: none;
	}

	#hero-header-container #search-control-input input,
	#hero-header-container #search-control-select select {
		width: 100%;
		height: 44px !important;
		font-size: 16px !important;
		border-radius: 8px;
	}

	#hero-header-container > div:last-child > div:last-child {
		width: auto;
		flex: 0 0 auto;
		margin-left: auto;
		justify-content: flex-end;
		gap: 8px;
	}

	/* The amber/yellow + indigo quick actions are already icon-only on phones.
	   Shrink the colored chip to 36px and keep a 44px transparent tap target. */
	#hero-header-container #resatRecordBtn-header,
	#hero-header-container #addRecordBtn-header {
		position: relative;
		width: 36px !important;
		height: 36px !important;
		min-width: 36px !important;
		min-height: 36px !important;
		padding: 0 !important;
		gap: 0 !important;
		justify-content: center;
		font-size: 12px !important;
	}

	#hero-header-container #resatRecordBtn-header::after,
	#hero-header-container #addRecordBtn-header::after {
		content: "";
		position: absolute;
		inset: -4px;
		border-radius: inherit;
	}

	#hero-header-container #resatRecordBtn-header > span,
	#hero-header-container #addRecordBtn-header > span {
		display: none !important;
	}

	/* =========================================================
	   4. FORM CONTROLS & TOUCH TARGETS
	   ========================================================= */
	#scrollableContent input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]):not([type="color"]):not([type="range"]),
	#scrollableContent select,
	#stickyContent input,
	#stickyContent select,
	#recordModal input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]),
	#recordModal select,
	#confirmModal input {
		min-height: 44px;
		font-size: 16px !important;
	}

	#scrollableContent textarea,
	#recordModal textarea {
		min-height: 88px;
		padding: 10px 12px;
		font-size: 16px !important;
		line-height: 1.5;
	}

	#scrollableContent input[type="checkbox"],
	#scrollableContent input[type="radio"] {
		width: 20px;
		height: 20px;
		min-width: 20px;
		min-height: 20px;
		flex: 0 0 auto;
	}

	/* Labeled controls (tabs, section buttons) keep the comfortable 44px
	   minimum. Icon-only actions get a smaller visible chip below. */
	#scrollableContent button,
	#stickyContent button,
	#confirmModal button,
	#recordModal button {
		min-height: 44px;
	}

	#scrollableContent button:has(svg.lucide) > span:empty,
	#stickyContent button:has(svg.lucide) > span:empty {
		display: none;
	}

	/* Compact icon actions -------------------------------------------------
	   36px visual chip + a transparent 44px tap target (::after extends 4px
	   on every side). This removes the bulky full-size color blocks caused by
	   the old blanket 44px min-width/min-height without shrinking the touch
	   area. .m-icon-btn is applied by assets/js/mobile.js to every icon-only
	   control, including ones that were already icon-only. */
	.m-icon-btn {
		position: relative;
		overflow: visible !important;
		min-width: 36px !important;
		min-height: 36px !important;
		width: 36px !important;
		height: 36px !important;
		padding: 0 !important;
		gap: 0 !important;
		flex: 0 0 auto;
		align-items: center;
		justify-content: center;
	}

	.m-icon-btn::after {
		content: "";
		position: absolute;
		inset: -4px;
		border-radius: inherit;
	}

	.m-icon-btn .m-btn-label {
		display: none !important;
	}

	.m-icon-btn svg,
	.m-injected-icon {
		width: 17px !important;
		height: 17px !important;
		margin: 0 !important;
		flex: 0 0 auto;
	}

	/* Injected icon replaces a text label that is hidden by .m-icon-btn. */
	.m-injected-icon {
		display: inline-flex;
		align-items: center;
		justify-content: center;
	}

	/* Declaration / payment source pills and checkbox rows are click targets,
	   so the label itself must clear 44px even though the radio stays compact. */
	#revenue-tax-module .rt-source-option {
		min-height: 44px;
		padding: 8px 12px;
		font-size: 12px;
	}

	#revenue-tax-module .rt-source-option input {
		width: 20px;
		height: 20px;
	}

	#revenue-tax-module .rt-overlay label:has(> input[type="checkbox"]),
	#revenue-tax-module .rt-overlay label:has(> input[type="radio"]) {
		min-height: 44px;
		display: inline-flex;
		align-items: center;
		gap: 8px;
	}

	/* Module row actions: compact 36px chips with a 44px transparent tap
	   target, matching .m-icon-btn for controls JS has not upgraded yet. */
	#scrollableContent .tp-icon-btn,
	#taxpayer-module .tp-icon-btn {
		position: relative;
		width: 36px !important;
		height: 36px !important;
		min-width: 36px !important;
		min-height: 36px !important;
		padding: 0 !important;
		gap: 0 !important;
		display: inline-flex;
		align-items: center;
		justify-content: center;
	}

	#scrollableContent .tp-icon-btn::after,
	#taxpayer-module .tp-icon-btn::after {
		content: "";
		position: absolute;
		inset: -4px;
		border-radius: inherit;
	}

	/* =========================================================
	   5. MOBILE CARD LISTS (company / users)
	   ========================================================= */
	#scrollableContent [id^="Mob-list-"] {
		display: flex;
		flex-direction: column;
		gap: 10px;
	}

	#scrollableContent [id^="Mob-list-"] > div {
		gap: 5px !important;
		padding: 12px !important;
		border-radius: 12px !important;
		box-shadow:
			0 1px 2px rgba(15, 23, 42, 0.06),
			0 10px 24px -22px rgba(15, 23, 42, 0.45) !important;
	}

	#scrollableContent [id^="Mob-list-"] > div > div:first-child > span:first-child {
		min-width: 0;
		overflow: hidden;
		text-overflow: ellipsis;
		white-space: nowrap;
		font-size: 13px !important;
		line-height: 1.35;
	}

	#scrollableContent [id^="Mob-list-"] > div > div:last-child {
		gap: 8px !important;
		margin-top: 4px !important;
		padding-top: 8px !important;
	}

	#scrollableContent [id^="Mob-list-"] button {
		width: 44px;
		min-width: 44px;
		height: 44px !important;
		min-height: 44px;
		padding: 0 !important;
		justify-content: center;
		border-radius: 10px;
	}

	#scrollableContent [id^="Mob-list-"] button svg {
		width: 18px;
		height: 18px;
	}

	/* 9-10px card metadata is unreadable on a phone. */
	#scrollableContent [id^="Mob-list-"] [class*="tw-text-[9px]"],
	#scrollableContent [id^="Mob-list-"] [class*="tw-text-[10px]"] {
		font-size: 11.5px !important;
		line-height: 1.45;
	}

	/* Empty states read comfortably on a phone */
	#scrollableContent [id^="empty-Mob-list-"] {
		padding: 32px 16px;
	}

	#scrollableContent [id^="empty-Mob-list-"] p {
		font-size: 12.5px !important;
		line-height: 1.5;
	}

	/* =========================================================
	   6. COMPACT COMPANY / USER FORMS
	   ========================================================= */
	#scrollableContent .compact-input-company:has(> label) {
		display: flex !important;
		flex-direction: column !important;
		align-items: stretch !important;
		gap: 4px;
		box-shadow: none;
	}

	#scrollableContent .compact-input-company:has(> label):has(> button) {
		display: grid !important;
		grid-template-columns: minmax(0, 1fr) 44px;
		align-items: stretch;
		gap: 6px;
	}

	#scrollableContent .compact-input-company:has(> label):has(> button) > label {
		grid-column: 1 / -1;
	}

	#scrollableContent .compact-input-company > .compact-label-company {
		width: auto !important;
		height: auto !important;
		min-height: 0 !important;
		padding: 0 2px !important;
		border: 0 !important;
		border-radius: 0 !important;
		background: transparent !important;
		color: #334155 !important;
		font-size: 12px !important;
		font-weight: 600 !important;
		line-height: 1.4;
	}

	#scrollableContent .compact-input-company > input,
	#scrollableContent .compact-input-company > select,
	#scrollableContent .compact-input-company > textarea {
		width: 100% !important;
		min-height: 44px !important;
		height: auto !important;
		padding: 10px 12px !important;
		border: 1px solid #cbd5e1 !important;
		border-radius: 8px !important;
		font-size: 16px !important;
		line-height: 1.4;
		background-color: #fff;
	}

	#scrollableContent .compact-input-company > input:focus,
	#scrollableContent .compact-input-company > select:focus,
	#scrollableContent .compact-input-company > textarea:focus {
		border-color: #0284c7 !important;
		box-shadow: 0 0 0 3px rgba(2, 132, 199, 0.14);
		outline: none;
	}

	#scrollableContent .compact-input-company > input[readonly],
	#scrollableContent .compact-input-company > input:disabled,
	#scrollableContent .compact-input-company > select:disabled {
		background-color: #f1f5f9 !important;
		color: #475569 !important;
	}

	#scrollableContent .compact-input-company > button {
		min-width: 44px;
		padding: 0 !important;
		justify-content: center;
	}

	/* Responsive grid helpers: one readable field per row on phones */
	#scrollableContent [class*="sm:tw-grid-cols-"]:not([class*="sm:tw-grid-cols-1"]) {
		grid-template-columns: minmax(0, 1fr) !important;
	}

	/* Section banner buttons and list-header banners */
	#scrollableContent .tw-bg-emerald-700.tw-w-full,
	#scrollableContent .tw-bg-red-700.tw-w-full {
		flex-wrap: wrap;
		row-gap: 6px;
		min-height: 44px;
		padding: 9px 12px !important;
		font-size: 12px !important;
		line-height: 1.4;
		letter-spacing: 0.02em;
	}

	#scrollableContent .tw-bg-emerald-700.tw-w-full h5,
	#scrollableContent .tw-bg-red-700.tw-w-full h5 {
		display: flex;
		align-items: center;
		gap: 6px;
		flex: 1 1 150px;
		min-width: 0;
		font-size: 10.5px !important;
		line-height: 1.45;
		letter-spacing: 0.03em;
	}

	#scrollableContent .tw-bg-emerald-700.tw-w-full > div,
	#scrollableContent .tw-bg-red-700.tw-w-full > div {
		flex: 0 0 auto;
		margin-left: auto;
	}

	#scrollableContent .tw-bg-emerald-700.tw-w-full button,
	#scrollableContent .tw-bg-red-700.tw-w-full button {
		min-width: 44px;
		min-height: 44px;
		padding: 0 8px !important;
		font-size: 10.5px !important;
		white-space: nowrap;
	}

	#scrollableContent .tw-bg-emerald-700.tw-w-full > button,
	#scrollableContent .tw-bg-red-700.tw-w-full > button {
		margin-left: auto;
	}

	/* =========================================================
	   7. TABLES & DENSE PANELS
	   ========================================================= */
	#scrollableContent table {
		max-width: 100%;
	}

	#scrollableContent td button,
	#scrollableContent th button {
		min-width: 44px;
		min-height: 44px;
		padding: 0;
		justify-content: center;
	}

	#scrollableContent .scrollable-table tbody {
		max-height: 60vh;
		-webkit-overflow-scrolling: touch;
	}

	/* =========================================================
	   8. CONFIRMATION, RECORD MODAL & SHEETS
	   ========================================================= */
	#confirmModal {
		padding: 16px !important;
	}

	#confirmModal > div {
		width: 100%;
		max-width: 22rem;
		padding: 20px !important;
		border-radius: 16px !important;
	}

	#confirmModal h3 {
		font-size: 14px;
		line-height: 1.4;
	}

	#confirmModal p {
		font-size: 12.5px !important;
		line-height: 1.5;
	}

	#confirmModal button {
		height: 44px !important;
		min-height: 44px;
		min-width: 96px;
		padding: 0 18px !important;
		font-size: 13px !important;
	}

	#recordModal {
		align-items: flex-end !important;
		padding: 0 !important;
	}

	#recordModal > div {
		display: flex;
		flex-direction: column;
		width: 100%;
		max-width: none !important;
		max-height: 92dvh;
		border-radius: 18px 18px 0 0 !important;
	}

	#recordModal #modalHeaderBg {
		flex: 0 0 auto;
		padding: 12px 16px !important;
		font-size: 14px !important;
		line-height: 1.4;
		/* Runtime code swaps in a gradient; this keeps white text readable if
		   the gradient class has not been applied yet. */
		background-color: #1e293b;
		color: #fff;
	}

	#recordModal #modalHeaderBg button {
		min-width: 44px;
		min-height: 44px;
		padding: 0 !important;
	}

	#recordModal #recordForm {
		display: block;
		flex: 1 1 auto;
		min-height: 0;
		overflow-y: auto;
		overscroll-behavior: contain;
		padding: 0 !important;
		-webkit-overflow-scrolling: touch;
	}

	#recordModal #dynamicFormFields {
		padding: 14px 16px 6px;
	}

	#recordModal #seccMsg,
	#recordModal #errMsg {
		max-width: none;
		margin: 6px 16px 0;
	}

	#recordModal #recordForm > div:last-child {
		position: sticky;
		bottom: 0;
		z-index: 1;
		margin-top: 0 !important;
		padding: 10px 16px calc(12px + env(safe-area-inset-bottom)) !important;
		background: #fff;
		border-top: 1px solid #e2e8f0 !important;
	}

	#recordModal #recordForm > div:last-child button,
	#recordModal #recordForm > div:last-child a {
		height: 44px !important;
		min-height: 44px;
		padding: 0 16px !important;
		display: inline-flex;
		align-items: center;
		justify-content: center;
		font-size: 13px !important;
	}

	/* =========================================================
	   9. WIZARD / MODAL ICON-ONLY ACTIONS
	   ========================================================= */
	/* Step navigation stays swipeable but drops the chunky native scrollbar
	   and tightens each chip so all five steps fit with less scrolling. */
	#taxpayer-form-overlay nav.enterprise-scroll {
		scrollbar-width: none !important;
		-ms-overflow-style: none !important;
		scroll-behavior: smooth;
		scroll-padding-inline: 8px;
		padding-bottom: 4px !important;
	}

	#taxpayer-form-overlay nav.enterprise-scroll::-webkit-scrollbar {
		display: none !important;
		width: 0 !important;
		height: 0 !important;
	}

	#taxpayer-form-overlay nav .wizard-tab {
		flex: 0 0 auto;
		min-height: 40px !important;
		padding: 6px 10px !important;
		gap: 6px !important;
	}

	#taxpayer-form-overlay nav .wizard-tab .step-badge {
		width: 18px !important;
		height: 18px !important;
		flex: 0 0 auto;
	}

	/* Icon-only step tabs: number badge + step glyph, text label hidden. */
	#taxpayer-form-overlay nav .wizard-tab.m-icon-btn {
		width: auto !important;
		min-width: 44px !important;
		height: 40px !important;
		min-height: 40px !important;
		padding: 0 9px !important;
		gap: 5px !important;
		justify-content: center;
	}

	#taxpayer-form-overlay nav .wizard-tab.m-icon-btn svg {
		width: 16px !important;
		height: 16px !important;
	}

	/* Wizard footer secondary actions become compact icon chips on phones.
	   Labels are hidden by .m-icon-btn; aria-label/title are set in JS. The
	   final "Save & Register" submit button keeps its label by design. */
	#taxpayer-form-overlay footer {
		gap: 6px !important;
		padding-left: 10px !important;
		padding-right: 10px !important;
	}

	#taxpayer-form-overlay footer button.m-icon-btn {
		width: 36px !important;
		height: 36px !important;
		min-width: 36px !important;
		min-height: 36px !important;
		padding: 0 !important;
		gap: 0 !important;
	}

	/* Keep the extended ::after tap target from being clipped by compact rows. */
	.rt-toolbar,
	.tp-toolbar,
	.rt-mobile-actions,
	[id^="Mob-list-"] {
		overflow: visible !important;
	}

	/* =========================================================
	   10. VERY NARROW PHONES (<= 359px)
	   ========================================================= */
	@media screen and (max-width: 359.98px) {
		#top-header .tw-bg-whitex {
			display: none;
		}

		#scrollableContent {
			padding-left: 8px;
			padding-right: 8px;
		}

		#hero-header-container > div:last-child {
			padding-left: 8px !important;
			padding-right: 8px !important;
		}
	}
}
