/* ==========================================================================
   Metula CRM — Manager Dashboard shell
   Reuses brand tokens (--mc-navy etc.), cards (.metula-dash-*), stat tiles
   (.metula-stat-tile) and buttons (.metula-btn) already defined in
   frontend.css. This file only adds the shell layout: top bar, sidebar,
   breadcrumb, and the mobile nav drawer.
   ========================================================================== */

.metula-mgr {
	min-height: 100vh;
	background: #f4f7f4;
	font-family: Heebo, Arial, Helvetica, sans-serif;
	/* .metula-mgr is scoped-into frontend.css's --mc-* variable block (for
	   the brand colors), but that same block also sets max-width:920px for
	   the narrow farmer-facing portal — cancel it here so the dashboard can
	   use the full width its own shell (.metula-mgr-shell) manages. */
	max-width: none;
	margin: 0;
	font-size: 15px;
	line-height: 1.5;
}

.metula-mgr-nav-toggle-input { position: absolute; opacity: 0; pointer-events: none; }

/* ---------- Top bar ---------- */

.metula-mgr-topbar {
	background: #ffffff;
	border-bottom: 1px solid #e1eadf;
	position: sticky;
	top: 0;
	z-index: 40;
}

.metula-mgr-topbar-inner {
	max-width: 1400px;
	margin: 0 auto;
	display: flex;
	align-items: center;
	gap: 16px;
	padding: 10px 20px;
}

.metula-mgr-burger {
	display: none;
	cursor: pointer;
	color: var(--mc-navy-dark);
	padding: 6px;
}
.metula-mgr-burger .metula-svg { width: 24px; height: 24px; }

.metula-mgr-brand {
	display: flex;
	align-items: center;
	gap: 10px;
	text-decoration: none;
	color: var(--mc-navy-dark);
	font-weight: 800;
	font-size: 16px;
}
.metula-mgr-brand img { width: 240px; height: 90px; object-fit: contain; }

.metula-mgr-topbar-user {
	margin-right: auto;
	display: flex;
	align-items: center;
	gap: 10px;
}

.metula-mgr-username {
	font-weight: 700;
	color: var(--mc-navy-dark);
	font-size: 14px;
}

.metula-mgr-logout {
	display: flex;
	align-items: center;
	gap: 4px;
	color: #8a958c;
	text-decoration: none;
	font-size: 13px;
	padding: 6px 10px;
	border-radius: 6px;
	transition: background 0.14s ease, color 0.14s ease;
}
.metula-mgr-logout:hover { background: #f1f5ef; color: var(--mc-navy-dark); }
.metula-mgr-logout .metula-svg { width: 18px; height: 18px; }

/* ---------- Shell: sidebar + main ---------- */

.metula-mgr-shell {
	max-width: 1400px;
	margin: 0 auto;
	display: flex;
	align-items: flex-start;
	gap: 0;
}

.metula-mgr-scrim {
	display: none;
}

.metula-mgr-sidebar {
	width: 240px;
	flex: 0 0 240px;
	padding: 20px 12px;
	position: sticky;
	top: 57px;
	align-self: flex-start;
	max-height: calc(100vh - 57px);
	overflow-y: auto;
}

.metula-mgr-sidebar ul {
	list-style: none;
	margin: 0;
	padding: 0;
	display: flex;
	flex-direction: column;
	gap: 4px;
}

.metula-mgr-navitem {
	display: flex;
	align-items: center;
	gap: 12px;
	padding: 11px 14px;
	border-radius: 8px;
	color: #4a564a;
	text-decoration: none;
	font-weight: 600;
	font-size: 14.5px;
	transition: background 0.14s ease, color 0.14s ease;
}
.metula-mgr-navitem .metula-svg { width: 20px; height: 20px; flex-shrink: 0; }
.metula-mgr-navitem:hover { background: #eef4ec; color: var(--mc-navy-dark); }
.metula-mgr-navitem.is-active {
	background: var(--mc-navy);
	color: #fff;
}

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

.metula-mgr-main {
	flex: 1 1 0;
	min-width: 0;
	padding: 20px 24px 60px;
}

.metula-mgr-breadcrumb {
	display: flex;
	align-items: center;
	gap: 8px;
	margin-bottom: 18px;
	font-size: 13px;
	color: #8a958c;
}
.metula-mgr-breadcrumb a {
	color: #8a958c;
	text-decoration: none;
}
.metula-mgr-breadcrumb a:hover { color: var(--mc-navy); }
.metula-mgr-crumb-sep { color: #c3d0c3; }
.metula-mgr-crumb-current { color: var(--mc-navy-dark); font-weight: 700; }

.metula-mgr-stub {
	text-align: center;
	padding: 48px 24px;
}

/* ---------- Responsive: collapsible drawer on mobile ---------- */

@media (max-width: 900px) {
	.metula-mgr-burger { display: inline-flex; }

	.metula-mgr-sidebar {
		position: fixed;
		top: 0;
		right: -280px;
		height: 100vh;
		max-height: 100vh;
		width: 260px;
		background: #ffffff;
		box-shadow: -8px 0 24px rgba(0, 0, 0, 0.12);
		transition: right 0.2s ease;
		z-index: 60;
		padding-top: 70px;
	}

	.metula-mgr-nav-toggle-input:checked ~ .metula-mgr-shell .metula-mgr-sidebar {
		right: 0;
	}

	.metula-mgr-nav-toggle-input:checked ~ .metula-mgr-shell .metula-mgr-scrim {
		display: block;
		position: fixed;
		inset: 0;
		background: rgba(0, 0, 0, 0.35);
		z-index: 50;
	}

	.metula-mgr-main { padding: 16px 14px 40px; }
}

@media (max-width: 560px) {
	.metula-mgr-username { display: none; }
	.metula-mgr-logout span { display: none; }
}

/* Debts KPI row: 5 tiles, so it needs its own column count to avoid the
   5th tile wrapping alone onto a new row (base .metula-home-stats is 4). */
@media (min-width: 760px) {
	.metula-mgr-kpis { grid-template-columns: repeat(5, 1fr); }
}

/* ---------- Partners: list + detail ---------- */

.metula-mgr-collapsible summary {
	cursor: pointer;
	font-weight: 700;
	color: var(--mc-navy-dark);
	font-size: 15px;
	list-style: none;
}
.metula-mgr-collapsible summary::-webkit-details-marker { display: none; }
.metula-mgr-collapsible summary::before {
	content: '+';
	display: inline-block;
	width: 18px;
	color: var(--mc-navy);
	font-weight: 800;
}
.metula-mgr-collapsible[open] summary::before { content: '−'; }
.metula-mgr-collapsible form { margin-top: 14px; }

.metula-mgr-form-grid {
	display: grid;
	grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
	gap: 12px;
	align-items: end;
}
.metula-mgr-form-grid .metula-btn { grid-column: 1 / -1; width: max-content; }

/* Password card: only 2 fields, so the submit button fits beside them on the
   same row instead of .metula-mgr-form-grid's usual forced own-row button —
   saves a row of vertical space. Falls back to stacked on narrow screens. */
.metula-mgr-pw-form {
	display: grid;
	grid-template-columns: minmax(140px, 1fr) minmax(140px, 1fr) auto;
	gap: 12px;
	align-items: end;
}
.metula-mgr-pw-form .metula-btn.metula-btn--primary {
	width: max-content;
	margin-top: 0;
}
@media (max-width: 520px) {
	.metula-mgr-pw-form {
		grid-template-columns: 1fr;
	}
	.metula-mgr-pw-form .metula-btn.metula-btn--primary {
		width: 100%;
		margin-top: 4px;
	}
}

.metula-mgr-form-inline {
	display: flex;
	flex-wrap: wrap;
	gap: 10px;
	align-items: center;
}

/* Site-wide rule (see .metula-mgr-add-actions above): filled/green button
   always renders left of an outline sibling in the same row. */
.metula-mgr-form-inline .metula-btn--outline,
.metula-mgr-prow-actions .metula-btn--outline {
	order: 1;
}
.metula-mgr-form-inline .metula-btn:not(.metula-btn--outline),
.metula-mgr-prow-actions .metula-btn:not(.metula-btn--outline) {
	order: 2;
}

.metula-mgr-checkbox {
	display: flex;
	align-items: center;
	gap: 6px;
	font-size: 13.5px;
	color: var(--mc-text);
}

/* Settings: selectable radio "cards" (e.g. upload-notification frequency) —
   each option reads as a labeled row instead of a bare radio + one-liner. */
.metula-mgr-radio-group {
	display: flex;
	flex-direction: column;
	gap: 8px;
}
.metula-mgr-radio-option {
	display: flex;
	align-items: flex-start;
	gap: 10px;
	padding: 12px 14px;
	border: 1.5px solid var(--mc-border);
	border-radius: 8px;
	cursor: pointer;
	transition: border-color 0.14s ease, background 0.14s ease;
}
.metula-mgr-radio-option:hover { border-color: #c7d6c3; background: #fafcf9; }
.metula-mgr-radio-option:has(input:checked) { border-color: var(--mc-navy); background: #f3f8f2; }
.metula-mgr-radio-option input[type="radio"] { margin-top: 3px; accent-color: var(--mc-navy); flex-shrink: 0; }
.metula-mgr-radio-option-body { display: flex; flex-direction: column; gap: 2px; }
.metula-mgr-radio-option-body strong { font-size: 14.5px; color: var(--mc-navy-dark); }
.metula-mgr-radio-option-body span:last-child { font-size: 12.5px; color: var(--mc-muted); }

.metula-mgr-search {
	display: flex;
	gap: 8px;
	margin: 12px 0 16px;
	flex-wrap: wrap;
}
.metula-mgr-search .metula-input { flex: 1; min-width: 220px; }

/* Responsive partner rows — flex-wrap instead of a fixed-width table, so
   nothing ever needs horizontal scrolling regardless of viewport width. */
.metula-mgr-plist {
	display: flex;
	flex-direction: column;
	gap: 2px;
}

.metula-mgr-prow {
	display: flex;
	align-items: center;
	gap: 14px;
	padding: 12px 10px;
	border-radius: 8px;
	text-decoration: none;
	color: inherit;
	flex-wrap: wrap;
	border-bottom: 1px solid var(--mc-border);
}
.metula-mgr-prow:last-child { border-bottom: none; }
.metula-mgr-prow:hover { background: #f6f9f5; }

.metula-mgr-prow-avatar {
	flex: 0 0 auto;
	width: 36px;
	height: 36px;
	border-radius: 50%;
	background: rgba(63, 112, 68, 0.12);
	color: var(--mc-navy-dark);
	display: flex;
	align-items: center;
	justify-content: center;
	font-size: 13px;
	font-weight: 700;
}

.metula-mgr-prow-main {
	display: flex;
	flex-direction: column;
	gap: 2px;
	flex: 1 1 220px;
	min-width: 0;
}
.metula-mgr-prow-name { font-weight: 700; color: var(--mc-navy-dark); font-size: 14.5px; }
.metula-mgr-prow-sub {
	font-size: 12.5px;
	color: var(--mc-muted);
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

.metula-mgr-prow-farm {
	flex: 0 0 auto;
	font-size: 13px;
	color: var(--mc-text);
	min-width: 90px;
}

.metula-mgr-prow-status { flex: 0 0 auto; }

.metula-mgr-prow-debt {
	flex: 0 0 auto;
	min-width: 90px;
	text-align: left;
	font-weight: 700;
	font-size: 13.5px;
	color: var(--mc-muted);
}
.metula-mgr-prow-debt.has-debt { color: #b32d2e; }

@media (max-width: 720px) {
	.metula-mgr-prow { gap: 10px; }
	.metula-mgr-prow-farm { display: none; }
	.metula-mgr-prow-main { flex-basis: 100%; order: 1; }
	.metula-mgr-prow-status { order: 2; }
	.metula-mgr-prow-debt { order: 3; margin-right: auto; }
}

.metula-mgr-pager {
	display: flex;
	gap: 6px;
	margin-top: 16px;
	flex-wrap: wrap;
}
.metula-mgr-pager-item {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	min-width: 32px;
	height: 32px;
	padding: 0 8px;
	border-radius: 6px;
	background: #f1f5ef;
	color: var(--mc-navy-dark);
	text-decoration: none;
	font-size: 13px;
	font-weight: 600;
}
.metula-mgr-pager-item.is-active { background: var(--mc-navy); color: #fff; }

.metula-mgr-pill {
	display: inline-block;
	padding: 2px 10px;
	border-radius: 10px;
	font-size: 11.5px;
	font-weight: 700;
}
.metula-mgr-pill--success { background: #e6f4ea; color: #1a7f37; }
.metula-mgr-pill--pending { background: #fff4e5; color: #b26a00; }
.metula-mgr-pill--error   { background: #fbeaea; color: #b32d2e; }

.metula-mgr-detail-head {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 12px;
	flex-wrap: wrap;
	margin-bottom: 18px;
}

.metula-mgr-detail-grid {
	display: grid;
	grid-template-columns: repeat(2, 1fr);
	gap: 16px;
}
@media (max-width: 800px) {
	.metula-mgr-detail-grid { grid-template-columns: 1fr; }
}

.metula-mgr-debt-line { margin: 14px 0 0; font-size: 15px; }

.metula-mgr-danger-link {
	background: transparent !important;
	color: #b32d2e !important;
	border-color: #f0c8c8 !important;
}
.metula-mgr-danger-link:hover { background: #fbeaea !important; }

/* ---------- Home: hero banner + stat icons + feed ---------- */

.metula-mgr-hero {
	position: relative;
	overflow: hidden;
	min-height: 120px;
	display: flex;
	align-items: flex-end;
}

.metula-mgr-hero-svg {
	position: absolute;
	inset: 0;
	width: 100%;
	height: 100%;
}

.metula-mgr-hero-text {
	position: relative;
	z-index: 1;
}

.metula-mgr-hero-text .metula-dash-date {
	font-weight: 700;
	color: var(--mc-text);
}

.metula-stat-ico {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 36px;
	height: 36px;
	border-radius: 50%;
	background: rgba(63, 112, 68, 0.1);
	margin-bottom: 6px;
}
.metula-stat-ico .metula-svg { width: 18px; height: 18px; color: var(--mc-navy); }
.metula-stat-tile--debt .metula-stat-ico { background: rgba(255, 255, 255, 0.18); }
.metula-stat-tile--debt .metula-stat-ico .metula-svg { color: #fff; }

.metula-mgr-feed-more {
	display: block;
	width: max-content;
	margin: 12px auto 0;
}

/* Recent-activity feed: one compact row per audit-log entry. */
.metula-mgr-activity-list {
	display: flex;
	flex-direction: column;
	gap: 2px;
}

.metula-mgr-activity-row {
	display: flex;
	align-items: center;
	gap: 12px;
	padding: 10px 6px;
	border-bottom: 1px solid var(--mc-border);
	text-decoration: none;
	color: inherit;
}
.metula-mgr-activity-row:last-child { border-bottom: none; }
a.metula-mgr-activity-row:hover { background: #f6f9f5; }

.metula-mgr-activity-icon {
	flex: 0 0 auto;
	width: 30px;
	height: 30px;
	border-radius: 50%;
	background: rgba(63, 112, 68, 0.1);
	display: flex;
	align-items: center;
	justify-content: center;
}
.metula-mgr-activity-icon .metula-svg { width: 15px; height: 15px; color: var(--mc-navy); }

.metula-mgr-activity-text {
	font-size: 13.5px;
	color: var(--mc-navy-dark);
	min-width: 0;
}

.metula-mgr-activity-meta {
	display: block;
	font-size: 11.5px;
	color: var(--mc-muted);
	margin-top: 2px;
}

/* Give the activity feed more room than the quick-actions card (30/70) —
   overrides frontend.css's shared 1fr/1fr .metula-dash-grid, scoped to the
   manager dashboard only so the farmer portal's own two-card grid is unaffected. */
@media (min-width: 760px) {
	.metula-mgr .metula-dash-grid { grid-template-columns: 30fr 70fr; }
}

/* ---------- Debts + Inbox ---------- */

.metula-mgr-filters { align-items: end; }

#metula-mgr-debt-chart { max-width: 100%; }

.metula-mgr-prow--unread { background: #f6faf6; }
.metula-mgr-prow--unread .metula-mgr-prow-name { font-weight: 800; }

.metula-mgr-dot {
	display: inline-block;
	width: 7px;
	height: 7px;
	border-radius: 50%;
	background: var(--mc-navy);
	vertical-align: middle;
	margin-right: 4px;
}

/* ---------- Farms ---------- */

/* A <form> is block-level by default — display:contents lets its button sit
   as a normal flex item inside .metula-mgr-prow instead of forcing a break. */
.metula-mgr-prow form { display: contents; }

.metula-mgr-farm-edit {
	padding: 12px 10px;
	border-bottom: 1px solid var(--mc-border);
}

/* ---------- Partners: "add" header with two button toggles ---------- */

.metula-mgr-add-actions {
	display: flex;
	flex-wrap: wrap;
	gap: 10px;
	margin-top: 12px;
}

/* Site-wide rule: the filled/green action always sits to the visual left of
   an outline sibling in the same row. In RTL, later `order` = further along
   the main axis = further left, so outline gets a lower order than filled. */
.metula-mgr-add-actions .metula-mgr-add-toggle:has(> summary.metula-btn--outline) {
	order: 1;
}
.metula-mgr-add-actions .metula-mgr-add-toggle:has(> summary.metula-btn--primary) {
	order: 2;
}

/* .metula-btn is repeated here to out-specificity .metula-btn.metula-btn--primary
   (frontend.css), which sets margin-top: 20px and width: 100% for standalone
   CTA buttons — without this, "הוספת שותף ידנית" drifted lower and stretched
   wider than the "ייבוא מקובץ" toggle next to it. */
.metula-mgr-add-toggle summary.metula-btn {
	cursor: pointer;
	list-style: none;
	width: max-content;
	margin-top: 0;
}
.metula-mgr-add-toggle summary::-webkit-details-marker { display: none; }
.metula-mgr-add-toggle summary::marker { content: ''; }

.metula-mgr-add-toggle form,
.metula-mgr-add-toggle > p {
	margin-top: 14px;
}

.metula-mgr-add-toggle[open] {
	flex-basis: 100%;
	width: 100%;
}

/* ---------- Partners: quick-send (home dashboard) ---------- */

.metula-mgr-quicksend {
	margin-top: 16px;
	padding-top: 14px;
	border-top: 1px solid var(--mc-border);
}
.metula-mgr-quicksend .metula-mgr-form-inline { margin-top: 6px; }
.metula-mgr-quicksend-hint { margin-top: 6px; font-size: 12.5px; }

/* ---------- Partners: message history (send / edit / thread / payments) ---------- */

.metula-mgr-msg-card {
	border: 1px solid var(--mc-border);
	border-radius: 10px;
	padding: 14px;
	margin-top: 12px;
}

.metula-mgr-msg-head {
	display: flex;
	flex-wrap: wrap;
	justify-content: space-between;
	align-items: center;
	gap: 10px;
}

.metula-mgr-msg-info {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 8px;
	font-size: 13.5px;
}

.metula-mgr-msg-actions {
	display: flex;
	gap: 8px;
	flex-wrap: wrap;
}

.metula-mgr-thread {
	margin-top: 12px;
	display: flex;
	flex-direction: column;
	gap: 8px;
}

.metula-mgr-thread-msg {
	border-radius: 8px;
	padding: 8px 12px;
	max-width: 85%;
	font-size: 13.5px;
}
.metula-mgr-thread-msg.is-admin {
	background: #eef4ec;
	align-self: flex-start;
}
.metula-mgr-thread-msg.is-farmer {
	background: #f2f2f2;
	align-self: flex-end;
}
.metula-mgr-thread-label {
	display: block;
	font-size: 11px;
	font-weight: 700;
	color: var(--mc-muted);
	margin-bottom: 3px;
}
.metula-mgr-thread-body :first-child { margin-top: 0; }
.metula-mgr-thread-body :last-child { margin-bottom: 0; }

.metula-mgr-pay-panel {
	margin-top: 12px;
	padding: 10px 12px;
	background: #fbfbf9;
	border-radius: 8px;
	border: 1px solid var(--mc-border);
}
.metula-mgr-pay-summary { margin: 0; font-size: 13.5px; }

/* Debt summary line + the payment mini-form share one row instead of
   stacking — saves a row of vertical space per message with an open debt. */
.metula-mgr-pay-row {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	gap: 10px 16px;
	margin-top: 8px;
}
.metula-mgr-pay-row:first-child { margin-top: 0; }
.metula-mgr-pay-row .metula-mgr-pay-summary {
	flex: 1 1 auto;
	min-width: 160px;
}
.metula-mgr-pay-row .metula-mgr-form-inline {
	flex: 2 1 auto;
}
.metula-mgr-pay-log {
	list-style: none;
	margin: 8px 0 0;
	padding: 0;
	font-size: 12.5px;
	color: var(--mc-muted);
}
.metula-mgr-pay-log li { padding: 2px 0; }

/* The bare .metula-input (frontend.css) is ~45px tall, next to the --sm
   "סמן תשלום" button (34px) that sits beside it. Scale these two fields
   down to match the button's height exactly. */
.metula-mgr-pay-panel .metula-input {
	width: auto;
	min-height: 34px;
	padding: 6px 10px;
	font-size: 14px;
	line-height: 1.2;
	border: 1px solid #d1d9cf;
	border-radius: 6px;
}
.metula-mgr-pay-panel input[name="pay_amount"] { max-width: 130px; }
.metula-mgr-pay-panel input[name="pay_note"] { max-width: 240px; flex: 1; }

.metula-mgr-reply-form {
	margin-top: 12px;
	display: flex;
	gap: 8px;
	align-items: flex-start;
}
.metula-mgr-reply-form textarea { flex: 1; resize: vertical; }

/* ---------- Templates / Takanon / Settings ---------- */

.metula-mgr-preview-frame {
	width: 100%;
	height: 520px;
	border: 1px solid var(--mc-border);
	border-radius: 8px;
	margin-top: 8px;
}

.metula-mgr-tpl-tokens {
	margin-top: 14px;
	font-size: 13px;
	line-height: 2.1;
}

.metula-mgr-pill--token {
	background: #eef2f6;
	color: #3a4a5c;
	font-weight: 600;
	font-family: monospace;
	margin-left: 6px;
}

/* ---------- Approvals ---------- */

.metula-mgr-prow-actions {
	display: flex;
	gap: 8px;
	flex: 0 0 auto;
}
