/* =============================================================================
   42 — Portal mobile layout fixes (client + firm shells)
   2026-11-02 — client report: "some text and tables overlap when the portal is
   viewed on a phone". Audited every portal + firm view at 360/375px with a
   headless phone viewport; the root causes fixed here:
     1. Phone browsers' text auto-sizing ("font boosting") inflates text inside
        fixed-size boxes → overlap. Disabled for the portal shells.
     2. Firm Messages: the two-pane card kept a desktop max-height + overflow
        hidden after stacking → the open conversation and reply box were cut off.
     3. Firm matter page: the time-log table forced the page to 590px wide.
     4. Firm dashboard "Recent Matters" table fell apart into loose rows.
     5. Raise-invoice line items ran off-screen; appointment search squashed;
        time-log form had a 240px empty gap; matter rail stayed 2 columns.
   Loaded automatically after 41-portal-finish.css (glob order).
   ============================================================================= */

/* ---- 1. Global safety nets (both shells, all widths) ---------------------- */
body.portal-shell{-webkit-text-size-adjust:100%;text-size-adjust:100%}
body.portal-shell .main,
body.portal-shell .content,
body.portal-shell .content > *{min-width:0}
body.portal-shell .content img,
body.portal-shell .content video{max-width:100%;height:auto}
body.portal-shell .content p,
body.portal-shell .content td,
body.portal-shell .content li,
body.portal-shell .content .bubble{overflow-wrap:break-word;word-wrap:break-word}
/* Long file names / emails / refs must wrap, never push past the card edge. */
body.portal-shell .content .doc-name,
body.portal-shell .content a[href^="mailto:"]{overflow-wrap:anywhere}

/* ---- 2. Firm Messages + Team: stacked panes must not clip ----------------- */
@media (max-width:820px){
	.portal-shell.firm-shell .ft-grid{
		max-height:none !important;
		min-height:0 !important;
		overflow:visible;
	}
	.portal-shell.firm-shell .ft-grid .ft-pane-list{
		max-height:340px;
		overflow-y:auto;
		-webkit-overflow-scrolling:touch;
		border-right:0;
		border-bottom:1px solid var(--hair);
	}
	.portal-shell.firm-shell .ft-grid.ft-has-active .ft-pane-list{max-height:190px}
	.portal-shell.firm-shell .ft-grid .ft-pane-thread{min-height:0;overflow:visible}
	.portal-shell.firm-shell .ft-pane-thread .msg-thread,
	.portal-shell.firm-shell .ft-log{max-height:58vh;overflow-y:auto;-webkit-overflow-scrolling:touch}
	.portal-shell.firm-shell .ft-pane-thread .msg-compose{position:static}
}

/* ---- 3. Firm matter workspace ------------------------------------------- */
@media (max-width:820px){
	.portal-shell.firm-shell .md-rail{grid-template-columns:minmax(0,1fr) !important}
	.portal-shell.firm-shell .md-table-wrap{max-width:100%;overflow-x:auto}
	/* Time-log form stacks in a column: a 240px flex-basis became a 240px gap. */
	.portal-shell.firm-shell .md-time-form .md-time-desc,
	.portal-shell.firm-shell .finlaw-tt-row .finlaw-tt-field{flex:0 0 auto;min-width:0}
}
@media (max-width:640px){
	/* Time log → compact stacked rows instead of a 520px table. */
	.portal-shell.firm-shell .finlaw-time-table{min-width:0;width:100%}
	.portal-shell.firm-shell .finlaw-time-table thead{display:none}
	.portal-shell.firm-shell .finlaw-time-table,
	.portal-shell.firm-shell .finlaw-time-table tbody{display:block}
	.portal-shell.firm-shell .finlaw-time-table tr{
		display:grid;grid-template-columns:auto minmax(0,1fr) auto;gap:4px 10px;
		padding:12px 0;border-bottom:1px solid var(--hair);align-items:center;
	}
	.portal-shell.firm-shell .finlaw-time-table td{display:block;padding:0 !important;border:0 !important;white-space:normal !important}
	.portal-shell.firm-shell .finlaw-time-table td.desc{grid-column:1 / -1;font-size:13px}
	.portal-shell.firm-shell .finlaw-time-table td:has(form){grid-column:3;grid-row:1}
	.portal-shell.firm-shell .finlaw-time-bill{display:inline-block;margin-left:4px}
}

/* ---- 4. Firm dashboard "Recent Matters" → tidy cards on phones ---------- */
@media (max-width:760px){
	.portal-shell.firm-shell .fd-table-wrap{overflow:visible}
	.portal-shell.firm-shell .data-table.fd-matters{min-width:0 !important;width:100%;display:block}
	.portal-shell.firm-shell .data-table.fd-matters thead{display:none}
	.portal-shell.firm-shell .data-table.fd-matters tbody{display:block}
	.portal-shell.firm-shell .data-table.fd-matters tr{
		display:grid !important;grid-template-columns:minmax(0,1fr) auto;gap:6px 12px;
		padding:14px 18px;border-bottom:1px solid #eef0f4;
	}
	.portal-shell.firm-shell .data-table.fd-matters tbody tr:last-child{border-bottom:0}
	.portal-shell.firm-shell .data-table.fd-matters td{
		display:block !important;min-width:0 !important;width:auto !important;
		padding:0 !important;border:0 !important;text-align:left !important;white-space:normal;
		background:none !important;
	}
	.portal-shell.firm-shell .data-table.fd-matters td::before{display:none !important;content:none !important}
	.portal-shell.firm-shell .data-table.fd-matters td[data-label="Matter"],
	.portal-shell.firm-shell .data-table.fd-matters td[data-label="Client"]{grid-column:1 / -1}
	.portal-shell.firm-shell .data-table.fd-matters td[data-label="Client"]{font-size:13px;color:var(--mid)}
	.portal-shell.firm-shell .data-table.fd-matters td[data-label="Status"]{grid-column:1;align-self:center}
	.portal-shell.firm-shell .data-table.fd-matters td *{text-align:left !important}
	.portal-shell.firm-shell .data-table.fd-matters td.fd-num{grid-column:2;text-align:right !important;align-self:center;white-space:nowrap}
}

/* ---- 5. Forms + filters ---------------------------------------------------- */
@media (max-width:640px){
	/* Raise invoice: description on its own row, amount + remove below. */
	.portal-shell.firm-shell .inv-line{
		display:grid !important;grid-template-columns:minmax(0,1fr) 40px;gap:8px;
	}
	.portal-shell.firm-shell .inv-line input[name="li_desc[]"]{grid-column:1 / -1;min-width:0;width:100%}
	.portal-shell.firm-shell .inv-line .inv-amount{min-width:0;width:100%}
	.portal-shell.firm-shell .firm-form-actions{flex-wrap:wrap}
	.portal-shell.firm-shell .firm-form-actions .btn{flex:1 1 auto;justify-content:center}

	/* Appointment queue search: flex:1 in a column = zero height. */
	.portal-shell.firm-shell #firmApptFilter .tb-search{flex:0 0 auto;min-width:0;width:100%;min-height:42px}

	/* KPI amounts: allow wrapping instead of "TZS 11,014,666.00 outs…". */
	body.portal-shell.firm-shell .stat-card .stat-sub,
	body.portal-shell .stat-card .stat-sub,
	body.portal-shell .stat-card .stat-label{white-space:normal;overflow:visible;text-overflow:clip}

	/* Generic grids inside cards collapse to one column. */
	.portal-shell .firm-grid,
	.portal-shell .c360-meta-grid{grid-template-columns:minmax(0,1fr) !important}

	/* Any table not given a phone layout scrolls inside its card, never the page. */
	.portal-shell .panel{max-width:100%}
	.portal-shell .panel > table:not(.data-table){display:block;overflow-x:auto}
}

/* ---- 6. Client portal ------------------------------------------------------ */
@media (max-width:640px){
	body.portal-shell.portal-dash-body .content{padding:20px 14px 40px}
	/* Offline-payment note: keep the email + phone on their own lines. */
	body.portal-shell.portal-dash-body .portal-notice{overflow-wrap:anywhere}
	/* Invoice card footer actions wrap instead of overlapping. */
	body.portal-shell.portal-dash-body .fl-inv-actions{display:flex;flex-wrap:wrap;gap:8px 14px}
	/* Message bubbles use the available width on small phones. */
	body.portal-shell.portal-dash-body .msg-thread .bubble{max-width:88%}
}
@media (max-width:380px){
	body.portal-shell .content .section-title{font-size:26px;line-height:1.15}
	body.portal-shell .stat-card .stat-num{font-size:22px;overflow-wrap:anywhere}
}

/* ---- 7. "New updates" bar (finlaw-notify.js) -------------------------------
   Shown when new activity arrives while the user is typing; quiet pages simply
   reload themselves. */
.fl-stale-bar{
	position:fixed;left:50%;bottom:18px;transform:translateX(-50%);z-index:9999;
	display:flex;align-items:center;gap:14px;max-width:calc(100vw - 24px);
	padding:10px 12px 10px 18px;border-radius:999px;
	background:var(--blue-ink,#0b1f4b);color:#fff;font-size:14px;font-weight:500;
	box-shadow:0 10px 30px rgba(11,31,75,.28);
}
.fl-stale-bar button{
	border:0;border-radius:999px;padding:7px 14px;cursor:pointer;
	background:var(--red,#ed1c24);color:#fff;font:inherit;font-weight:600;
}
