/* ==========================================================================
   Phone layout (Sept 29 2026). One app, two layouts: everything here only
   applies on screens narrower than 768px. Desktops are untouched. With
   "Desktop view" switched on, the page is laid out 1280px wide, so none of
   this applies either (see _base/head.php).
   ========================================================================== */

/* Hidden everywhere except phones. */
.nd-mnav, .nd-msheet { display: none; }
.nd-mview-pill { display: none; }

@media (max-width: 767.98px) {

	/* ---------- bottom menu bar ---------- */
	:root { --nd-mnav-h: 62px; }
	.nd-mnav {
		display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 1040;
		height: calc(var(--nd-mnav-h) + env(safe-area-inset-bottom, 0px));
		padding-bottom: env(safe-area-inset-bottom, 0px);
		background: var(--db-card-bg); border-top: 1px solid var(--db-border);
		box-shadow: 0 -4px 16px rgba(16, 24, 40, 0.06);
	}
	.nd-mnav__item {
		flex: 1 1 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
		border: 0; background: none; padding: 0; position: relative;
		color: var(--db-muted) !important; text-decoration: none !important; font-size: 0.68rem; font-weight: 600;
		-webkit-tap-highlight-color: transparent;
	}
	.nd-mnav__item i { font-size: 1.15rem; }
	.nd-mnav__item.is-active { color: var(--db-primary) !important; }
	.nd-mnav__plus {
		width: 46px; height: 46px; margin-top: -22px; border-radius: 50%;
		display: flex; align-items: center; justify-content: center;
		background: linear-gradient(135deg, var(--db-primary), var(--db-primary-dark)); color: #fff;
		box-shadow: 0 6px 16px rgba(var(--db-primary-rgb, 83, 74, 183), 0.35); border: 3px solid var(--db-card-bg);
	}
	.nd-mnav__plus i { font-size: 1.1rem; }
	.nd-mnav__badge {
		position: absolute; top: 6px; left: calc(50% + 6px); min-width: 17px; height: 17px; padding: 0 4px;
		border-radius: 999px; background: var(--db-expense); color: #fff; font-size: 10px; font-style: normal; font-weight: 800; line-height: 17px; text-align: center;
	}
	.nd-mnav__badge[hidden] { display: none; }

	/* ---------- "+ New" sheet ---------- */
	.nd-msheet { display: block; position: fixed; inset: 0; z-index: 1050; }
	.nd-msheet[hidden] { display: none; }
	.nd-msheet__backdrop { position: absolute; inset: 0; background: rgba(16, 24, 40, 0.45); }
	.nd-msheet__panel {
		position: absolute; left: 0; right: 0; bottom: 0; background: var(--db-card-bg); border-radius: 18px 18px 0 0;
		padding: 8px 16px calc(16px + env(safe-area-inset-bottom, 0px)); max-height: 85vh; overflow-y: auto;
		animation: nd-sheet-up 0.18s ease-out;
	}
	@keyframes nd-sheet-up { from { transform: translateY(40px); opacity: 0.4; } to { transform: none; opacity: 1; } }
	.nd-msheet__grip { width: 40px; height: 4px; border-radius: 4px; background: var(--db-border); margin: 4px auto 10px; }
	.nd-msheet__title { font-weight: 800; font-size: 0.95rem; color: var(--db-ink); margin-bottom: 12px; }
	.nd-msheet__grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
	.nd-msheet__action {
		display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 14px 6px; border-radius: 14px;
		background: var(--db-page-bg); color: var(--db-ink) !important; text-decoration: none !important; font-size: 0.78rem; font-weight: 600; text-align: center;
	}
	.nd-msheet__action i { width: 40px; height: 40px; border-radius: 12px; display: flex; align-items: center; justify-content: center; font-size: 1.05rem; color: #fff; background: var(--db-primary); }
	.nd-msheet__action--buy i { background: var(--db-expense); }
	.nd-msheet__action--other i { background: var(--db-accent); }
	.nd-msheet__foot { display: flex; flex-wrap: wrap; gap: 8px; justify-content: space-between; margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--db-border); }
	.nd-msheet__link { border: 0; background: none; color: var(--db-primary); font-weight: 600; font-size: 0.85rem; padding: 6px 0; }
	.nd-msheet__link[hidden] { display: none; }

	/* ---------- page frame ---------- */
	.main-footer { display: none !important; }
	.content-wrapper { padding-bottom: calc(var(--nd-mnav-h) + 16px + env(safe-area-inset-bottom, 0px)) !important; }
	.content-wrapper > .content, section.content { padding-left: 10px !important; padding-right: 10px !important; }
	.content-header { padding: 10px 12px 4px !important; }

	/* top bar: keep it to search, company, bell and the user */
	.main-header .nav-item:has(> [data-widget="fullscreen"]),
	.main-header .nav-item:has(> #toggle-dark-mode) { display: none !important; }
	.main-header [data-widget="fullscreen"], .main-header #toggle-dark-mode { display: none !important; }
	.topbar-account-pill { font-size: 0 !important; padding: 6px 10px !important; max-width: 150px; }
	.topbar-account-pill strong { font-size: 0.78rem; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 130px; }
	.nd-bell__menu { position: fixed !important; left: 8px !important; right: 8px !important; top: 58px !important; width: auto !important; transform: none !important; }

	/* ---------- forms ---------- */
	input.form-control, select.form-control, textarea.form-control, .select2-container .select2-selection, .date-field-input { font-size: 16px !important; }
	form > .form-actions { bottom: calc(var(--nd-mnav-h) + env(safe-area-inset-bottom, 0px)) !important; margin-left: -10px; margin-right: -10px; padding-left: 12px; padding-right: 12px; }
	.form-actions .btn-save, .form-actions .btn-cancel { padding: 11px 18px; font-size: 0.9rem; }
	.form-actions .btn-save { flex: 1 1 auto; }

	/* ---------- stat tiles: two per row instead of six squeezed ---------- */
	.stat-bar { display: grid !important; grid-template-columns: repeat(2, 1fr); gap: 10px; }
	.stat-bar__item { min-width: 0 !important; }
	.stat-bar__value { font-size: 1.1rem !important; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

	/* ---------- lists: each table row becomes a card ---------- */
	.table-responsive:has(> table.nd-cards) { overflow: visible; }
	table.nd-cards, table.nd-cards > tbody, table.nd-cards > tbody > tr, table.nd-cards > tbody > tr > td { display: block; width: 100% !important; }
	table.nd-cards > thead { display: none; }
	table.nd-cards > tfoot { display: block; }
	table.nd-cards > tfoot > tr { display: flex; flex-wrap: wrap; justify-content: space-between; }
	table.nd-cards > tbody > tr {
		position: relative; margin: 0 0 10px; padding: 10px 44px 10px 12px;
		border: 1px solid var(--db-border) !important; border-radius: 12px; background: var(--db-card-bg) !important;
	}
	table.nd-cards > tbody > tr > td {
		display: flex; justify-content: space-between; align-items: baseline; gap: 12px;
		padding: 3px 0 !important; border: 0 !important; text-align: right !important; font-size: 0.86rem; min-height: 0;
		flex-wrap: wrap; overflow-wrap: anywhere;
	}
	table.nd-cards > tbody > tr > td::before {
		content: attr(data-label); flex: 0 0 auto; text-align: left; color: var(--db-muted);
		font-size: 0.72rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.02em;
	}
	table.nd-cards > tbody > tr > td[data-label=""]::before { content: none; }
	/* first cell = the card's title */
	table.nd-cards > tbody > tr > td:first-child { display: block; text-align: left !important; font-size: 0.98rem; font-weight: 700; padding-bottom: 6px !important; }
	table.nd-cards > tbody > tr > td:first-child::before { display: none; }
	/* the ⋮ actions menu sits in the card's top-right corner */
	table.nd-cards > tbody > tr > td.nd-card-actions { position: absolute; top: 6px; right: 4px; width: auto !important; padding: 0 !important; }
	table.nd-cards > tbody > tr > td.nd-card-actions::before { display: none; }
	table.nd-cards > tbody > tr > td:empty { display: none; }
	/* "no records" rows stay plain */
	table.nd-cards > tbody > tr.nd-card-plain { padding: 16px 12px; text-align: center; }
	table.nd-cards > tbody > tr.nd-card-plain > td { display: block; text-align: center !important; }
	table.nd-cards > tbody > tr.nd-card-plain > td::before { display: none; }

	/* line-item tables on forms (invoice, bill ...): one card per line,
	   each field labelled and full width */
	table.nd-cards--form > tbody > tr { padding: 12px; }
	table.nd-cards--form > tbody > tr > td { display: block; text-align: left !important; padding: 4px 0 !important; }
	table.nd-cards--form > tbody > tr > td::before { display: block; margin-bottom: 3px; }
	table.nd-cards--form > tbody > tr > td:first-child { font-size: inherit; font-weight: normal; }
	table.nd-cards--form > tbody > tr > td:first-child::before { display: block; }
	table.nd-cards--form input, table.nd-cards--form select, table.nd-cards--form textarea, table.nd-cards--form .select2-container { width: 100% !important; max-width: none !important; }
	table.nd-cards--form > tbody > tr > td:last-child:has(> .btn, > button, > a) { position: absolute; top: 8px; right: 8px; width: auto !important; padding: 0 !important; }
	table.nd-cards--form > tbody > tr > td:last-child:has(> .btn, > button, > a)::before { display: none; }

	/* reports stay tables, but can scroll sideways */
	.nd-report-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }

	/* card headers: title on its own line, buttons wrap under it */
	.card-header { flex-wrap: wrap; }
	.dashboard-card__title { font-size: 1rem !important; }

	/* installed app (no browser bar): leave room for the phone's notch */
	@media (display-mode: standalone) {
		.main-header { padding-top: env(safe-area-inset-top, 0px); }
	}
}

/* In "Desktop view" on a phone: a small pill to switch back. */
.nd-mview-pill {
	position: fixed; right: 16px; bottom: 16px; z-index: 2000; align-items: center; gap: 8px;
	padding: 12px 18px; border-radius: 999px; border: 0; font-size: 22px; font-weight: 700;
	background: var(--db-primary); color: #fff; box-shadow: 0 6px 18px rgba(0, 0, 0, 0.25);
}
.nd-mview-pill.is-shown { display: inline-flex; }

/* Buttons (Sept 30 2026) - form-actions.js */
@media (max-width: 767.98px) {
	.form-actions .btn-save-alt { padding: 11px 12px; font-size: 0.85rem; }
	.form-actions .btn-cancel { padding-left: 12px; padding-right: 12px; }
	.form-actions { gap: 6px; }
	.form-actions .btn { white-space: nowrap; }
	/* the bottom "+" does the job of + New on phones */
	.nd-newbtn-item { display: none !important; }
	.nd-co { gap: 8px; padding-right: 4px; }
	.nd-co__logo { width: 30px; height: 30px; }
	.nd-co__text small { display: none; }
	.nd-co__text b { font-size: 13.5px; max-width: 170px; }
	.form-actions.nd-bar--out { bottom: calc(var(--nd-mnav-h) + env(safe-area-inset-bottom, 0px)) !important; margin-left: -10px; margin-right: -10px; padding-left: 12px; padding-right: 12px; }
	.nd-doc-head { top: var(--nd-nav-h, 57px); }
	.nd-tools { justify-content: flex-start; width: 100%; }
	.nd-tools .nd-more { margin-left: auto; }
	.nd-tools .btn { padding: 7px 11px; }
	/* the main action (Issue, Receive Payment ...) full width on its own row */
	.nd-tools > .nd-primary { flex: 1 1 100%; order: 10; }
	.nd-tools > .nd-primary.btn, .nd-tools > .nd-primary .btn { width: 100%; justify-content: center; padding: 10px 12px; font-size: 0.92rem; }
	/* the More menu opens as a sheet above the bottom bar */
	.nd-more__menu {
		position: fixed; left: 8px; right: 8px; top: auto; min-width: 0;
		bottom: calc(var(--nd-mnav-h, 62px) + 8px + env(safe-area-inset-bottom, 0px));
		max-height: 70vh; overflow-y: auto; border-radius: 14px; box-shadow: 0 -6px 24px rgba(16, 24, 40, 0.2);
	}
	.nd-more__item { padding: 12px 16px !important; font-size: 0.95rem; }
	.nd-confirm .modal-footer .btn { flex: 1 1 0; }
}
