/* Al-Khairat manager panel. Brand tokens mirror the theme (docs/DESIGN_SYSTEM.md). */

:root {
	--kh-canvas: #f4f6f3;
	--kh-surface: #fff;
	--kh-text: #182019;
	--kh-muted: #5c665d;
	--kh-primary: #0e7c43;
	--kh-primary-hover: #0a6335;
	--kh-deep: #17251c;
	--kh-soft: #edf1ec;
	--kh-border: #e3e6e1;
	--kh-danger: #a43d3d;
	--kh-success: #2f6b46;
	--kh-radius: 14px;
	--kh-radius-s: 10px;
	--kh-shadow: 0 1px 3px rgba(24, 32, 25, 0.05), 0 8px 24px rgba(24, 32, 25, 0.06);
	--kh-font: 'Tajawal', 'IBM Plex Sans Arabic', 'Segoe UI', system-ui, sans-serif;
}

* { box-sizing: border-box; }

/* display:flex on components would otherwise defeat the hidden attribute. */
[hidden] { display: none !important; }

body {
	margin: 0;
	font-family: var(--kh-font);
	background: var(--kh-canvas);
	color: var(--kh-text);
	line-height: 1.7;
	font-size: 16px;
}

a { color: var(--kh-primary); }

h1 { font-size: 1.5rem; margin: 0 0 16px; }
h2 { font-size: 1.1rem; margin: 0 0 12px; }

.kh-visually-hidden {
	position: absolute;
	width: 1px;
	height: 1px;
	overflow: hidden;
	clip: rect(0 0 0 0);
	white-space: nowrap;
}

.kh-skip {
	position: absolute;
	inset-inline-start: -999px;
	top: 0;
	background: var(--kh-primary);
	color: #fff;
	padding: 8px 16px;
	z-index: 100;
}
.kh-skip:focus { inset-inline-start: 0; }

/* Topbar */
.kh-topbar {
	display: flex;
	align-items: center;
	gap: 12px;
	background: var(--kh-surface);
	border-bottom: 1px solid var(--kh-border);
	padding: 10px 16px;
	position: sticky;
	top: 0;
	z-index: 20;
}
.kh-topbar__brand { font-weight: 600; }
.kh-topbar__who { display: inline-flex; align-items: center; gap: 6px; margin-inline-start: 14px; font-size: 0.85rem; min-width: 0; }
.kh-topbar__who b { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 12ch; }
.kh-topbar__role { font-style: normal; font-size: 0.72rem; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: var(--kh-soft); color: var(--kh-primary); white-space: nowrap; }
@media (max-width: 560px) { .kh-topbar__who { margin-inline-start: 8px; } .kh-topbar__who b { display: none; } }
.kh-topbar__actions { margin-inline-start: auto; display: flex; gap: 16px; }
.kh-topbar__actions a, .kh-topbar__push { display: inline-flex; align-items: center; gap: 6px; text-decoration: none; font-size: 0.9rem; min-height: 44px; }
.kh-topbar__push { background: none; border: 0; padding: 0; color: inherit; font: inherit; cursor: pointer; }
.kh-topbar__push[hidden] { display: none; }
.kh-topbar__menu {
	display: none;
	background: none;
	border: 1px solid var(--kh-border);
	border-radius: var(--kh-radius-s);
	padding: 8px 10px;
	cursor: pointer;
	min-width: 44px;
	min-height: 44px;
}
.kh-burger { display: block; width: 18px; }
.kh-burger i { display: block; height: 2px; background: var(--kh-text); margin: 4px 0; border-radius: 1px; }

/* Shell */
.kh-shell { display: flex; min-height: calc(100vh - 65px); }
.kh-sidebar {
	width: 232px;
	flex-shrink: 0;
	display: flex;
	flex-direction: column;
	border-inline-end: 1px solid var(--kh-border);
	background: var(--kh-surface);
	padding: 12px 10px;
	transition: width 200ms;
}
.kh-sidebar ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.kh-sidebar a {
	display: flex;
	align-items: center;
	gap: 12px;
	padding: 11px 14px;
	border-radius: var(--kh-radius-s);
	text-decoration: none;
	color: var(--kh-text);
	white-space: nowrap;
}
.kh-sidebar__ico { flex-shrink: 0; color: var(--kh-muted); }
.kh-sidebar a:hover { background: var(--kh-soft); }
.kh-sidebar a[aria-current='page'] { background: var(--kh-primary); color: #fff; font-weight: 600; }
.kh-sidebar a[aria-current='page'] .kh-sidebar__ico { color: #fff; }
.kh-sidebar__collapse {
	margin-top: auto;
	display: flex;
	align-items: center;
	gap: 12px;
	padding: 11px 14px;
	border: 0;
	border-radius: var(--kh-radius-s);
	background: none;
	color: var(--kh-muted);
	font: inherit;
	font-size: 0.85rem;
	cursor: pointer;
	white-space: nowrap;
}
.kh-sidebar__collapse:hover { background: var(--kh-soft); }
.kh-sidebar__collapse svg { transition: transform 200ms; }

/* Collapsed (desktop): icons only. */
@media (min-width: 761px) {
	.kh-collapsed .kh-sidebar { width: 68px; }
	.kh-collapsed .kh-sidebar__label { display: none; }
	.kh-collapsed .kh-sidebar__collapse svg { transform: scaleX(-1); }
}
.kh-main { flex: 1; padding: 24px; min-width: 0; max-width: 1080px; }

/* Cards / layout */
.kh-card {
	background: var(--kh-surface);
	border: 1px solid var(--kh-border);
	border-radius: var(--kh-radius);
	box-shadow: var(--kh-shadow);
	padding: 20px;
	margin-bottom: 20px;
}
.kh-cols { display: grid; gap: 20px; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); align-items: start; }
.kh-cols > *, .kh-dash-grid > * { min-width: 0; } /* Grid items refuse to shrink below content (min-width:auto) — wide charts were stretching phones sideways. */
.kh-cols--sidebar { grid-template-columns: minmax(300px, 420px) 1fr; }
.kh-grid-2 { display: grid; gap: 0 16px; grid-template-columns: 1fr 1fr; }
.kh-grid-3 { display: grid; gap: 0 16px; grid-template-columns: repeat(3, 1fr); }
.kh-screen-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }

/* Forms */
.kh-field { margin: 0 0 16px; }
.kh-field label, .kh-label { display: block; font-size: 0.9rem; font-weight: 500; margin-bottom: 4px; }
.kh-field input[type='text'],
.kh-field input[type='search'],
.kh-field input[type='url'],
.kh-field input[type='email'],
.kh-field input[type='number'],
.kh-field input[type='password'],
.kh-field input[type='date'],
.kh-field select,
.kh-field textarea,
.kh-toolbar input[type='search'],
.kh-row-2 input, .kh-row-2 select,
.kh-variant-row input, .kh-variant-row select {
	width: 100%;
	padding: 10px 12px;
	font: inherit;
	font-size: 16px;
	border: 1px solid var(--kh-border);
	border-radius: var(--kh-radius-s);
	background: var(--kh-surface);
	color: var(--kh-text);
}
.kh-field textarea { resize: vertical; }
.kh-field :focus-visible, .kh-btn:focus-visible, a:focus-visible, button:focus-visible {
	outline: 2px solid var(--kh-primary);
	outline-offset: 2px;
}
.kh-field--inline label { display: inline-flex; gap: 8px; align-items: center; font-weight: 400; }
.kh-check { display: inline-flex; gap: 8px; align-items: center; margin: 0 0 12px; }
.kh-checks { display: flex; flex-wrap: wrap; gap: 8px 20px; }
.kh-checks label { display: inline-flex; align-items: center; gap: 6px; }
.kh-checks label { display: inline-flex; gap: 6px; align-items: center; }
.kh-checks--scroll { max-height: 240px; overflow-y: auto; display: block; columns: 2; }
.kh-checks--scroll label { display: flex; margin-bottom: 6px; }
.kh-req { color: var(--kh-danger); }
.kh-hint { color: var(--kh-muted); font-size: 0.85rem; margin: 4px 0 12px; }
.kh-hint--error { color: var(--kh-danger); font-weight: 600; }
.kh-grid-2 > .kh-field--wide { grid-column: 1 / -1; margin-top: 0; }
.kh-field .kh-check--soldout { display: inline-flex; gap: 8px; align-items: center; margin: 10px 0 2px; font-weight: 700; color: var(--kh-danger); cursor: pointer; }
.kh-field .kh-check--soldout input { width: 20px; height: 20px; min-height: 0; margin: 0; padding: 0; accent-color: var(--kh-danger); }
.kh-muted { color: var(--kh-muted); font-size: 0.9rem; }
.kh-form__actions {
	position: sticky;
	bottom: 0;
	background: var(--kh-canvas);
	padding: 12px 0;
	display: flex;
	gap: 12px;
}

/* Buttons */
.kh-btn {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: 6px;
	padding: 10px 18px;
	min-height: 44px;
	font: inherit;
	font-weight: 500;
	color: var(--kh-text);
	background: var(--kh-surface);
	border: 1px solid var(--kh-border);
	border-radius: var(--kh-radius-s);
	cursor: pointer;
	text-decoration: none;
	transition: background 150ms, border-color 150ms;
}
.kh-btn:hover { border-color: var(--kh-primary); }
.kh-btn--primary { background: var(--kh-primary); border-color: var(--kh-primary); color: #fff; }
.kh-btn--primary:hover { background: var(--kh-primary-hover); }
.kh-btn--danger { color: var(--kh-danger); }
.kh-btn--danger:hover { border-color: var(--kh-danger); }
.kh-btn--small { padding: 6px 12px; min-height: 36px; font-size: 0.85rem; }
.kh-btn--large { padding: 12px 28px; }
.kh-btn--block { width: 100%; }

/* Alerts */
.kh-alert {
	padding: 12px 16px;
	border-radius: var(--kh-radius-s);
	margin: 0 0 16px;
	border: 1px solid;
}
.kh-alert--success { background: #eef5ef; border-color: var(--kh-success); color: var(--kh-success); }
.kh-alert--error { background: #f9efef; border-color: var(--kh-danger); color: var(--kh-danger); }

/* ===== Dashboard ===== */
:root {
	--kh-gold: #b08d2f;
	--kh-gold-soft: #f6f1e4;
	--kh-wa: #1f9d55;
	--kh-wa-soft: #e6f6ec;
	--kh-info: #2f6b9a;
	--kh-info-soft: #e9f1f8;
	--kh-danger-soft: #f9efef;
}

/* Greeting band */
.kh-hello {
	position: relative;
	overflow: hidden;
	display: flex;
	align-items: flex-end;
	justify-content: space-between;
	gap: 20px;
	flex-wrap: wrap;
	margin-bottom: 20px;
	padding: 28px 28px 24px;
	border-radius: calc(var(--kh-radius) + 4px);
	color: #fff;
	background:
		radial-gradient(120% 140% at 100% 0%, rgba(255, 255, 255, 0.14) 0, transparent 55%),
		linear-gradient(135deg, #0f6b3c 0%, var(--kh-primary) 45%, #17251c 100%);
	box-shadow: 0 14px 36px rgba(14, 124, 67, 0.22);
}
.kh-hello__text { position: relative; z-index: 1; min-width: 0; }
.kh-hello__date { margin: 0 0 6px; font-size: 0.85rem; opacity: 0.8; }
.kh-hello h1 { margin: 0 0 6px; font-size: clamp(1.4rem, 1rem + 1.6vw, 2rem); line-height: 1.3; color: #fff; }
.kh-hello__sub { margin: 0; font-size: 0.95rem; opacity: 0.92; }
.kh-hello__actions { position: relative; z-index: 1; display: flex; gap: 8px; flex-wrap: wrap; }
.kh-hello__btn {
	display: inline-flex;
	align-items: center;
	gap: 8px;
	min-height: 44px;
	padding: 10px 16px;
	border-radius: 999px;
	border: 1px solid rgba(255, 255, 255, 0.28);
	background: rgba(255, 255, 255, 0.12);
	color: #fff;
	font-weight: 500;
	text-decoration: none;
	backdrop-filter: blur(6px);
	transition: background 150ms, transform 150ms;
}
.kh-hello__btn:hover { background: rgba(255, 255, 255, 0.22); transform: translateY(-1px); }
.kh-hello__btn--primary { background: #fff; border-color: #fff; color: var(--kh-primary); font-weight: 700; }
.kh-hello__btn--primary:hover { background: #f1f6f2; }
.kh-hello__btn .kh-ico { width: 18px; height: 18px; }
.kh-hello__pill {
	min-width: 22px;
	height: 22px;
	padding: 0 7px;
	display: inline-grid;
	place-items: center;
	border-radius: 999px;
	background: var(--kh-gold);
	color: #fff;
	font-size: 0.75rem;
	font-weight: 700;
}
.kh-hello__leaf {
	position: absolute;
	inset-inline-start: -30px;
	bottom: -60px;
	width: 220px;
	height: 220px;
	color: #fff;
	opacity: 0.08;
	pointer-events: none;
}

/* KPI cards */
.kh-stats { display: grid; gap: 12px; grid-template-columns: repeat(5, minmax(0, 1fr)); margin-bottom: 20px; }
.kh-stat {
	--tone: var(--kh-primary);
	--tone-soft: var(--kh-soft);
	position: relative;
	display: flex;
	flex-direction: column;
	gap: 2px;
	padding: 16px;
	background: var(--kh-surface);
	border: 1px solid var(--kh-border);
	border-radius: var(--kh-radius);
	box-shadow: var(--kh-shadow);
	color: var(--kh-text);
	text-decoration: none;
	transition: transform 150ms, box-shadow 150ms, border-color 150ms;
}
.kh-stat::after {
	content: '';
	position: absolute;
	inset-inline: 16px;
	bottom: 0;
	height: 3px;
	border-radius: 3px 3px 0 0;
	background: var(--tone);
	opacity: 0;
	transition: opacity 150ms;
}
a.kh-stat:hover { transform: translateY(-3px); box-shadow: 0 10px 28px rgba(24, 32, 25, 0.12); border-color: transparent; }
a.kh-stat:hover::after { opacity: 1; }
.kh-stat__ico {
	display: inline-grid;
	place-items: center;
	width: 40px;
	height: 40px;
	margin-bottom: 10px;
	border-radius: 12px;
	background: var(--tone-soft);
	color: var(--tone);
}
.kh-stat__ico .kh-ico { width: 20px; height: 20px; }
.kh-stat__n { font-size: 1.9rem; font-weight: 800; line-height: 1.1; color: var(--kh-text); letter-spacing: -0.01em; }
.kh-stat__l { font-size: 0.82rem; color: var(--kh-muted); }
.kh-stat--danger { --tone: var(--kh-danger); --tone-soft: var(--kh-danger-soft); }
.kh-stat--wa { --tone: var(--kh-wa); --tone-soft: var(--kh-wa-soft); }
.kh-stat--gold { --tone: #8a6d1d; --tone-soft: var(--kh-gold-soft); }
.kh-stat--attention { border-color: var(--kh-gold); }
.kh-stat--attention .kh-stat__n { color: #8a6d1d; }

/* Card chrome shared by dashboard panels */
.kh-dash-grid { display: grid; gap: 20px; grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); align-items: start; margin-bottom: 20px; }
.kh-card--flush { padding: 18px 20px 16px; }
.kh-card__head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.kh-card__head h2 { margin: 0; font-size: 1rem; display: flex; align-items: center; gap: 6px; }
.kh-card__empty { margin: 8px 0 4px; }
.kh-legend { list-style: none; margin: 0; padding: 0; display: flex; gap: 14px; font-size: 0.8rem; color: var(--kh-muted); }
.kh-legend li { display: inline-flex; align-items: center; gap: 6px; }
.kh-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--kh-primary); flex-shrink: 0; }
.kh-dot--views, .kh-dot--ok { background: var(--kh-primary); }
.kh-dot--wa { background: var(--kh-wa); }
.kh-dot--gold { background: var(--kh-gold); }
.kh-dot--info { background: var(--kh-info); }
.kh-dot--muted { background: #aab3ab; }
.kh-dot--danger { background: var(--kh-danger); }

/* 14-day activity chart (pure CSS bars) */
.kh-chart { display: flex; gap: 6px; align-items: stretch; height: 150px; }
.kh-chart__day { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.kh-chart__bars {
	flex: 1;
	display: flex;
	align-items: flex-end;
	justify-content: center;
	gap: 2px;
	border-bottom: 1px solid var(--kh-border);
}
.kh-chart__bar {
	display: block;
	width: 44%;
	max-width: 14px;
	height: max(var(--h), 2px);
	border-radius: 4px 4px 1px 1px;
	transform-origin: bottom;
	animation: kh-grow 500ms ease-out both;
}
.kh-chart__bar--views { background: var(--kh-primary); }
.kh-chart__bar--wa { background: var(--kh-wa); opacity: 0.85; }
.kh-chart__label { font-size: 0.7rem; color: var(--kh-muted); text-align: center; line-height: 1; }
@keyframes kh-grow {
	from { transform: scaleY(0); }
}

/* Availability breakdown */
.kh-segbar { display: flex; gap: 2px; height: 12px; border-radius: 999px; overflow: hidden; background: var(--kh-soft); margin-bottom: 14px; }
.kh-seg { display: block; width: var(--w); min-width: 4px; background: var(--kh-primary); }
.kh-seg--gold { background: var(--kh-gold); }
.kh-seg--info { background: var(--kh-info); }
.kh-seg--muted { background: #aab3ab; }
.kh-seg--danger { background: var(--kh-danger); }
.kh-avail { list-style: none; margin: 0; padding: 0; }
.kh-avail li + li { border-top: 1px solid var(--kh-border); }
.kh-avail a {
	display: flex;
	align-items: center;
	gap: 10px;
	min-height: 42px;
	padding: 4px 0;
	color: var(--kh-text);
	text-decoration: none;
	font-size: 0.92rem;
}
.kh-avail a:hover .kh-avail__l { color: var(--kh-primary); }
.kh-avail__l { flex: 1; }
.kh-avail__n { font-weight: 700; font-variant-numeric: tabular-nums; }

/* Ranked lists with proportional bars */
.kh-cols--insights { margin-bottom: 20px; }
.kh-rank { list-style: none; margin: 0; padding: 0; counter-reset: kh-rank; }
.kh-rank__item {
	position: relative;
	display: grid;
	grid-template-columns: 22px minmax(0, 1fr) auto;
	grid-template-areas: 'num label n' '. bar bar';
	align-items: center;
	column-gap: 8px;
	row-gap: 4px;
	padding: 8px 0;
	counter-increment: kh-rank;
}
.kh-rank__item + .kh-rank__item { border-top: 1px solid var(--kh-border); }
.kh-rank__item::before {
	content: counter(kh-rank);
	grid-area: num;
	width: 22px;
	height: 22px;
	display: grid;
	place-items: center;
	border-radius: 7px;
	background: var(--kh-soft);
	color: var(--kh-primary);
	font-size: 0.75rem;
	font-weight: 700;
}
.kh-rank__item:first-child::before { background: var(--kh-primary); color: #fff; }
.kh-rank__label { grid-area: label; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--kh-text); text-decoration: none; font-weight: 500; font-size: 0.92rem; }
a.kh-rank__label:hover { color: var(--kh-primary); }
.kh-rank__n { grid-area: n; font-weight: 700; font-variant-numeric: tabular-nums; font-size: 0.9rem; }
.kh-rank__bar { grid-area: bar; display: block; height: 5px; border-radius: 999px; background: var(--kh-soft); overflow: hidden; }
.kh-rank__bar::after {
	content: '';
	display: block;
	height: 100%;
	width: var(--w);
	border-radius: inherit;
	background: linear-gradient(90deg, var(--kh-primary), #49a56f);
	transform-origin: 100% 50%;
	animation: kh-grow-x 600ms ease-out both;
}
html[dir='ltr'] .kh-rank__bar::after { transform-origin: 0 50%; }
@keyframes kh-grow-x {
	from { transform: scaleX(0); }
}

/* Shortcuts */
.kh-shortcuts { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); margin-top: 4px; }
.kh-shortcut {
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	gap: 10px;
	min-height: 96px;
	padding: 14px 10px;
	background: var(--kh-surface);
	border: 1px solid var(--kh-border);
	border-radius: var(--kh-radius);
	box-shadow: var(--kh-shadow);
	color: var(--kh-text);
	text-decoration: none;
	font-weight: 500;
	font-size: 0.9rem;
	text-align: center;
	transition: border-color 150ms, transform 150ms, background 150ms;
}
.kh-shortcut .kh-ico {
	width: 40px;
	height: 40px;
	padding: 10px;
	border-radius: 12px;
	background: var(--kh-soft);
	color: var(--kh-primary);
	transition: background 150ms, color 150ms;
}
.kh-shortcut:hover { border-color: var(--kh-primary); transform: translateY(-2px); }
.kh-shortcut:hover .kh-ico { background: var(--kh-primary); color: #fff; }
.kh-list { margin: 0; padding-inline-start: 20px; }
.kh-list li { margin-bottom: 6px; }

/* Dashboard: tablets */
@media (max-width: 1100px) {
	.kh-stats { grid-template-columns: repeat(3, minmax(0, 1fr)); }
	.kh-dash-grid { grid-template-columns: 1fr; }
}
/* Dashboard: phones */
@media (max-width: 760px) {
	.kh-hello { padding: 22px 18px 18px; border-radius: var(--kh-radius); align-items: stretch; }
	.kh-hello__actions { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; width: 100%; }
	.kh-hello__btn { flex-direction: column; gap: 4px; padding: 10px 6px; border-radius: var(--kh-radius-s); font-size: 0.8rem; text-align: center; position: relative; }
	.kh-hello__pill { position: absolute; top: 6px; inset-inline-end: 6px; }
	.kh-hello__leaf { width: 160px; height: 160px; bottom: -50px; }
	.kh-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
	.kh-stat { padding: 14px; }
	.kh-stat:last-child:nth-child(odd) { grid-column: 1 / -1; flex-direction: row; align-items: center; gap: 12px; }
	.kh-stat:last-child:nth-child(odd) .kh-stat__ico { margin: 0; }
	.kh-stat:last-child:nth-child(odd) .kh-stat__n { margin-inline-start: auto; }
	.kh-stat__n { font-size: 1.6rem; }
	.kh-card--flush { padding: 16px; }
	.kh-chart { height: 130px; gap: 3px; }
	.kh-chart__day:nth-child(even) .kh-chart__label { visibility: hidden; }
	.kh-shortcuts { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
	.kh-shortcut { min-height: 84px; font-size: 0.8rem; padding: 12px 6px; }
}
@media (max-width: 480px) {
	/* Dense charts: tighter gaps so all columns fit a narrow phone; squeezed labels clip instead of overpainting neighbours. */
	.kh-chart { gap: 3px; }
	.kh-chart__bars { gap: 3px; }
	.kh-chart__label { overflow: hidden; }
}
@media (max-width: 380px) {
	.kh-shortcuts { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (prefers-reduced-motion: reduce) {
	.kh-chart__bar, .kh-rank__bar::after { animation: none; }
}

/* Icons inside buttons/headings */
.kh-ico { flex-shrink: 0; vertical-align: -3px; }
h2 .kh-ico { color: var(--kh-primary); margin-inline-end: 4px; }

/* Lists toolbar: search + filter dropdowns */
.kh-toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 16px; }
.kh-toolbar input[type='search'] { max-width: 320px; }
.kh-toolbar select {
	padding: 10px 12px;
	font: inherit;
	font-size: 16px; /* Under 16px iOS zooms the page on focus and never zooms back. */
	border: 1px solid var(--kh-border);
	border-radius: var(--kh-radius-s);
	background: var(--kh-surface);
	color: var(--kh-text);
	min-height: 44px;
	cursor: pointer;
}
.kh-toolbar select:hover, .kh-toolbar select:focus { border-color: var(--kh-primary); }

/* Navigation progress bar (page-to-page loading feedback). */
.kh-progress {
	position: fixed;
	top: 0;
	inset-inline-start: 0;
	height: 3px;
	width: 0;
	background: var(--kh-primary);
	z-index: 200;
	pointer-events: none;
}
.kh-navigating .kh-progress { animation: kh-progress 1.4s ease-out forwards; }
@keyframes kh-progress {
	0% { width: 0; opacity: 1; }
	100% { width: 85%; opacity: 1; }
}
.kh-toolbar__views { display: flex; gap: 12px; margin-inline-start: auto; }
.kh-toolbar__views a { text-decoration: none; padding: 10px 8px; min-height: 44px; display: inline-flex; align-items: center; }
.kh-toolbar__views a[aria-current='page'] { font-weight: 600; border-bottom: 2px solid var(--kh-primary); }
.kh-plist { list-style: none; margin: 0; padding: 0; }
.kh-plist__item {
	display: flex;
	gap: 12px;
	align-items: center;
	background: var(--kh-surface);
	border: 1px solid var(--kh-border);
	border-radius: var(--kh-radius);
	padding: 10px 14px;
	margin-bottom: 8px;
}
.kh-plist__thumb { width: 56px; height: 56px; flex-shrink: 0; border-radius: var(--kh-radius-s); overflow: hidden; background: var(--kh-soft); }
.kh-plist__thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.kh-plist__body { min-width: 0; flex: 1; }
.kh-plist__name { font-weight: 600; text-decoration: none; display: block; }
.kh-plist__meta { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.kh-plist__actions { display: flex; gap: 6px; flex-wrap: wrap; }
.kh-plist__actions form { margin: 0; }

.kh-badge {
	display: inline-block;
	font-size: 0.75rem;
	padding: 2px 10px;
	border-radius: 999px;
	background: var(--kh-soft);
	color: var(--kh-primary);
}
.kh-badge--out, .kh-badge--soon { background: #f3f0ea; color: var(--kh-muted); }
.kh-badge--limited { background: #f6f1e4; color: #7a6428; }

.kh-pagination { display: flex; gap: 6px; margin-top: 16px; flex-wrap: wrap; }
.kh-pagination a {
	padding: 10px 14px;
	min-height: 44px;
	min-width: 44px;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	border: 1px solid var(--kh-border);
	border-radius: var(--kh-radius-s);
	text-decoration: none;
}
.kh-pagination a[aria-current='page'] { background: var(--kh-primary); color: #fff; border-color: var(--kh-primary); }

/* Term lists / review list */
.kh-tlist { list-style: none; margin: 0; padding: 0; }
.kh-tlist li {
	display: flex;
	justify-content: space-between;
	align-items: center;
	gap: 8px;
	padding: 10px 0;
	border-bottom: 1px solid var(--kh-border);
}
.kh-tlist li:last-child { border-bottom: 0; }
.kh-tlist__actions { display: flex; gap: 6px; }
.kh-tlist__actions form { margin: 0; }
.kh-thumb img { border-radius: var(--kh-radius-s); display: block; margin-bottom: 8px; max-width: 96px; height: auto; }
.kh-thumb--wide img { max-width: 240px; }

.kh-tabs { display: flex; gap: 16px; border-bottom: 1px solid var(--kh-border); margin-bottom: 16px; flex-wrap: wrap; }
.kh-tabs a { text-decoration: none; padding: 10px 8px; min-height: 44px; display: inline-flex; align-items: center; }
.kh-tabs a[aria-current='page'] { font-weight: 600; border-bottom: 2px solid var(--kh-primary); }
.kh-rlist { list-style: none; margin: 0; padding: 0; }
.kh-rlist__head { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.kh-stars { color: #b08d2f; letter-spacing: 2px; }
.kh-rlist__actions { display: flex; gap: 6px; flex-wrap: wrap; }
.kh-rlist__actions form { margin: 0; }

/* Empty state */
.kh-empty {
	text-align: center;
	padding: 48px 20px;
	background: var(--kh-surface);
	border: 1px dashed var(--kh-border);
	border-radius: var(--kh-radius);
	color: var(--kh-muted);
}

/* Uploader */
.kh-uploader__list { list-style: none; display: flex; flex-wrap: wrap; gap: 10px; margin: 0 0 10px; padding: 0; }
.kh-uploader__item {
	position: relative;
	width: 88px;
	height: 88px;
	border-radius: var(--kh-radius-s);
	overflow: hidden;
	border: 1px solid var(--kh-border);
	cursor: grab;
}
.kh-uploader__item img { width: 100%; height: 100%; object-fit: cover; display: block; }
.kh-uploader__item.kh-dragging { opacity: 0.5; }
.kh-uploader__main {
	position: absolute;
	bottom: 0;
	inset-inline: 0;
	background: rgba(24, 32, 25, 0.75);
	color: #fff;
	font-size: 0.7rem;
	text-align: center;
	padding: 2px;
}
.kh-uploader__remove {
	position: absolute;
	top: 2px;
	inset-inline-end: 2px;
	width: 36px;
	height: 36px;
	border-radius: 50%;
	border: 0;
	background: rgba(24, 32, 25, 0.7);
	color: #fff;
	cursor: pointer;
	line-height: 1;
}
/* Touch fallback for drag-reorder: one tap moves the image to first (= main). */
.kh-uploader__first {
	position: absolute;
	bottom: 0;
	inset-inline: 0;
	border: 0;
	background: rgba(24, 32, 25, 0.75);
	color: #fff;
	font-size: 0.7rem;
	padding: 8px 2px;
	cursor: pointer;
}
.kh-uploader__first[hidden] { display: none; }
/* Touch fallback for section drag-reorder. */
.kh-sections__move { margin-inline-start: auto; display: flex; gap: 4px; }
.kh-sections__movebtn {
	width: 44px;
	min-height: 40px;
	display: grid;
	place-items: center;
	border: 1px solid var(--kh-border);
	border-radius: var(--kh-radius-s);
	background: var(--kh-surface);
	color: var(--kh-text);
	cursor: pointer;
}
.kh-sections__movebtn:hover { border-color: var(--kh-primary); color: var(--kh-primary); }

.kh-uploader__drop {
	display: block;
	border: 2px dashed var(--kh-border);
	border-radius: var(--kh-radius-s);
	padding: 24px;
	text-align: center;
	color: var(--kh-muted);
	cursor: pointer;
	transition: border-color 150ms, background 150ms;
}
.kh-uploader__drop:hover, .kh-uploader__drop.kh-dragover { border-color: var(--kh-primary); background: var(--kh-soft); }
.kh-uploader__drop input[type='file'] { position: absolute; inset-inline-start: 0; top: 0; width: 1px; min-width: 0; height: 1px; padding: 0; border: 0; opacity: 0; }

/* Variant rows */
.kh-variant-row {
	display: grid;
	grid-template-columns: 2fr 1fr 1fr 1fr 1fr 1.4fr;
	gap: 8px;
	border: 0;
	padding: 0;
	margin: 0 0 8px;
}
.kh-row-2 { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.kh-row-2 select { flex: 0 0 160px; }
.kh-row-2 input { flex: 1; min-width: 0; }
.kh-row-2 [data-kh-remove-row] { flex-shrink: 0; }

/* Multi-video field */
.kh-videos__list { list-style: none; margin: 0 0 12px; padding: 0; display: grid; gap: 8px; }
.kh-videos__item {
	display: flex;
	align-items: center;
	gap: 10px;
	background: var(--kh-canvas);
	border: 1px solid var(--kh-border);
	border-radius: var(--kh-radius-s);
	padding: 8px 12px;
}
.kh-videos__kind {
	flex-shrink: 0;
	font-size: 12px;
	font-weight: 600;
	color: var(--kh-primary);
	background: var(--kh-surface);
	border: 1px solid var(--kh-border);
	border-radius: 999px;
	padding: 1px 10px;
}
.kh-videos__label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; color: var(--kh-muted); text-align: left; }
.kh-videos__add { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.kh-videos__add input[type='url'] { flex: 1; min-width: 220px; padding: 10px 12px; font: inherit; font-size: 16px; border: 1px solid var(--kh-border); border-radius: var(--kh-radius-s); background: var(--kh-surface); }
.kh-videos__upload { cursor: pointer; }
.kh-videos__progress { display: flex; align-items: center; gap: 10px; margin-top: 12px; }
.kh-videos__track { flex: 1; height: 8px; background: var(--kh-canvas); border: 1px solid var(--kh-border); border-radius: 999px; overflow: hidden; }
.kh-videos__bar { height: 100%; width: 0; background: var(--kh-primary); border-radius: 999px; transition: width 150ms; }
.kh-videos__pct { font-size: 12px; font-weight: 600; min-width: 36px; }
.kh-videos__fname { font-size: 12px; color: var(--kh-muted); max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.kh-videos__error { color: var(--kh-danger); }

/* Media screen: video thumb placeholder */
.kh-media-video { display: grid; place-items: center; width: 100%; height: 100%; background: var(--kh-primary-deep, #182019); color: #fff; border-radius: inherit; }

/* Previously-uploaded videos library */
.kh-vlib { margin-top: 12px; border: 1px solid var(--kh-border); border-radius: var(--kh-radius-s); background: var(--kh-canvas); padding: 12px; }
.kh-vlib__search { width: 100%; padding: 10px 12px; font: inherit; font-size: 16px; border: 1px solid var(--kh-border); border-radius: var(--kh-radius-s); background: var(--kh-surface); margin-bottom: 10px; }
.kh-vlib__list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; max-height: 280px; overflow-y: auto; }
.kh-vlib__item { display: flex; align-items: center; gap: 10px; background: var(--kh-surface); border: 1px solid var(--kh-border); border-radius: var(--kh-radius-s); padding: 8px 12px; }
.kh-vlib__name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.kh-vlib__meta { flex-shrink: 0; font-size: 12px; color: var(--kh-muted); }
.kh-vlib__preview { flex-shrink: 0; font-size: 13px; }
.kh-vlib__empty { margin: 8px 0 0; }

/* Sections order */
.kh-sections { list-style: none; margin: 0; padding: 0; }
.kh-sections__item {
	display: flex;
	gap: 10px;
	align-items: center;
	background: var(--kh-canvas);
	border: 1px solid var(--kh-border);
	border-radius: var(--kh-radius-s);
	padding: 10px 14px;
	margin-bottom: 6px;
	cursor: grab;
}
.kh-sections__item.kh-dragging { opacity: 0.5; }
.kh-sections__handle { color: var(--kh-muted); user-select: none; }
.kh-sections__item label { display: inline-flex; gap: 8px; align-items: center; }

/* Details/summary */
.kh-details summary {
	cursor: pointer;
	font-weight: 600;
	font-size: 1.05rem;
	list-style-position: inside;
}
.kh-details[open] summary { margin-bottom: 12px; }

/* Login */
.kh-login-page {
	display: grid;
	place-items: center;
	min-height: 100vh;
	background: var(--kh-canvas);
	padding: 20px;
}
.kh-login { width: 100%; max-width: 380px; }
.kh-login__brand { text-align: center; margin-bottom: 24px; }
.kh-login__name { display: block; font-size: 1.5rem; font-weight: 700; color: var(--kh-primary); }
.kh-login__sub { color: var(--kh-muted); font-size: 0.9rem; }
.kh-login__form {
	background: var(--kh-surface);
	border: 1px solid var(--kh-border);
	border-radius: var(--kh-radius);
	padding: 24px;
}
.kh-login__forgot { text-align: center; margin: 16px 0 0; font-size: 0.9rem; }

/* Responsive */
@media (max-width: 900px) {
	.kh-cols--sidebar { grid-template-columns: 1fr; }
	.kh-variant-row { grid-template-columns: 1fr 1fr; }
	/* Stacked variant rows blur together — separate each variant visually. */
	.kh-variant-row { border-block-end: 1px solid var(--kh-border); padding-block-end: 12px; margin-bottom: 12px; }
}
@media (max-width: 760px) {
	.kh-topbar__menu { display: inline-flex; align-items: center; justify-content: center; }
	.kh-btn--small { min-height: 44px; }
	.kh-checks--scroll { columns: 1; }
	.kh-sidebar__collapse { display: none; }
	.kh-sidebar {
		position: fixed;
		inset-block: 0;
		inset-inline-start: 0;
		z-index: 30;
		transform: translateX(100%);
		transition: transform 200ms;
		box-shadow: 0 0 40px rgba(24, 32, 25, 0.15);
	}
	html[dir='ltr'] .kh-sidebar { transform: translateX(-100%); }
	.kh-sidebar.kh-open { transform: translateX(0); }
	/* Off-canvas menu is invisible + unfocusable until opened; the page itself can never scroll sideways,
	   so an overflowing widget can no longer zoom the phone out and expose the drawer. */
	.kh-sidebar:not(.kh-open) { visibility: hidden; transition: transform 200ms, visibility 0s 200ms; }
	html { overflow-x: hidden; }
	.kh-shell { overflow-x: clip; }
	.kh-main { padding: 16px; width: 100%; }
	.kh-grid-2, .kh-grid-3 { grid-template-columns: 1fr; }
	.kh-row-2 { flex-wrap: wrap; }
	.kh-row-2 select { flex-basis: 100%; }
	.kh-plist__item { flex-wrap: wrap; }
	.kh-plist__actions { width: 100%; }
}
/* Confirm dialog (native <dialog>) */
.kh-dialog {
	border: 0;
	border-radius: var(--kh-radius);
	box-shadow: 0 24px 64px rgba(24, 32, 25, 0.25);
	padding: 24px;
	max-width: 380px;
	width: calc(100% - 40px);
	font-family: var(--kh-font);
	color: var(--kh-text);
}
.kh-dialog::backdrop { background: rgba(24, 32, 25, 0.45); }
.kh-dialog__text { margin: 0 0 18px; font-size: 1.05rem; line-height: 1.7; }
.kh-dialog__actions { display: flex; gap: 10px; justify-content: flex-start; }

/* Loading state — spinner replaces button label while a form submits. */
.kh-btn.kh-loading { position: relative; color: transparent !important; pointer-events: none; }
.kh-btn.kh-loading::after {
	content: '';
	position: absolute;
	inset: 0;
	margin: auto;
	width: 18px;
	height: 18px;
	border: 2px solid rgba(24, 32, 25, 0.25);
	border-top-color: currentcolor;
	border-radius: 50%;
	color: var(--kh-primary);
	animation: kh-spin 700ms linear infinite;
}
.kh-btn--primary.kh-loading::after { border-color: rgba(255, 255, 255, 0.35); border-top-color: #fff; color: #fff; }
@keyframes kh-spin {
	to { transform: rotate(360deg); }
}

/* Single-file inputs — dropzone look (matches the gallery uploader). */
.kh-field input[type='file'] {
	display: block;
	width: 100%;
	padding: 14px;
	border: 2px dashed var(--kh-border);
	border-radius: var(--kh-radius-s);
	background: var(--kh-canvas);
	color: var(--kh-muted);
	font: inherit;
	font-size: 0.9rem;
	cursor: pointer;
	transition: border-color 150ms, background 150ms;
}
.kh-field input[type='file']:hover, .kh-field input[type='file'].kh-dragover { border-color: var(--kh-primary); background: var(--kh-soft); }
/* The gallery uploader hides its real input behind the drop label — the dropzone look must not resurrect it. */
.kh-field .kh-uploader__drop input[type='file'] { display: block; width: 1px; padding: 0; border: 0; }
/* Native file inputs have a wide intrinsic size — never let one stretch the page on phones. */
input[type='file'] { max-width: 100%; min-width: 0; }
.kh-field input[type='file']::file-selector-button {
	margin-inline-end: 12px;
	padding: 8px 14px;
	border: 1px solid var(--kh-border);
	border-radius: var(--kh-radius-s);
	background: var(--kh-surface);
	color: var(--kh-text);
	font: inherit;
	font-size: 0.85rem;
	cursor: pointer;
}

/* Color pickers */
.kh-field input[type='color'] {
	width: 100%;
	height: 48px;
	padding: 4px;
	border: 1px solid var(--kh-border);
	border-radius: var(--kh-radius-s);
	background: var(--kh-surface);
	cursor: pointer;
}

@media (prefers-reduced-motion: reduce) {
	.kh-sidebar, .kh-btn, .kh-sidebar__collapse svg { transition: none; }
	.kh-btn.kh-loading::after { animation-duration: 1.6s; }
}

/* Settings: logo preview + clients rows (name, image, file). */
.kh-thumb--logo { display: grid; justify-items: start; gap: 4px; margin-bottom: 8px; }
.kh-thumb--logo img { max-width: 120px; background: #fff; border: 1px solid var(--kh-border, #e3e6e1); padding: 6px; margin-bottom: 0; }
.kh-row-client { flex-wrap: wrap; }
.kh-row-client .kh-thumb--client { flex: 0 0 52px; width: 52px; height: 52px; border-radius: var(--kh-radius-s); background: #edf1ec; overflow: hidden; }
.kh-row-client .kh-thumb--client img { width: 100%; height: 100%; max-width: none; object-fit: cover; margin: 0; border-radius: 0; }
.kh-row-client input[type="text"] { flex: 1 1 180px; }
.kh-row-client input[type="file"] { flex: 1 1 200px; min-width: 0; }

/* Analytics screen: single-series charts + customers table */
.kh-chart--single { height: 120px; gap: 3px; }
.kh-chart--single .kh-chart__bar { width: 70%; max-width: 22px; }
.kh-chart--single .kh-chart__day:nth-child(even) .kh-chart__label { visibility: hidden; }
.kh-tablewrap { overflow-x: auto; margin: 0 -16px -16px; padding: 0 16px 16px; }
.kh-table { width: 100%; border-collapse: collapse; font-size: 0.92rem; white-space: nowrap; }
.kh-table th, .kh-table td { padding: 10px 12px; text-align: start; border-bottom: 1px solid var(--kh-border); vertical-align: middle; }
.kh-table th { font-weight: 600; color: var(--kh-muted); font-size: 0.82rem; }
.kh-table tbody tr:hover { background: var(--kh-soft); }
.kh-table__phone { font-variant-numeric: tabular-nums; }
.kh-table__phone a:first-child { text-decoration: none; color: var(--kh-text); margin-inline-end: 6px; }

/* Orders screen */
.kh-badge--created { background: #f6f1e4; color: #7a6428; }
.kh-badge--opened { background: #e7f1ff; color: #2b5b9a; }
.kh-badge--confirmed { background: var(--kh-soft); color: var(--kh-primary); font-weight: 600; }
.kh-table__items { white-space: normal; min-width: 160px; max-width: 300px; line-height: 1.5; }
.kh-table__ref { font-variant-numeric: tabular-nums; font-weight: 600; }
.kh-table__actions { display: flex; gap: 6px; align-items: center; }
.kh-table__actions form { margin: 0; }
.kh-ostats { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; }
.kh-ostat { display: inline-flex; align-items: center; gap: 8px; padding: 8px 14px; border-radius: 999px; background: var(--kh-surface, #fff); border: 1px solid var(--kh-border); text-decoration: none; color: var(--kh-text); font-size: 0.9rem; }
.kh-ostat[aria-current='page'] { border-color: var(--kh-primary); box-shadow: inset 0 0 0 1px var(--kh-primary); }
.kh-ostat b { font-variant-numeric: tabular-nums; }

/* Stock + accounts screen */
.kh-stats--4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.kh-stats .kh-stat__n small { font-size: 0.9rem; font-weight: 500; }
.kh-table__product { display: flex; gap: 10px; align-items: center; white-space: normal; min-width: 200px; }
.kh-table__product .kh-plist__thumb { width: 44px; height: 44px; }
.kh-table__product .kh-plist__name { margin-bottom: 2px; }
.kh-table__n { font-variant-numeric: tabular-nums; font-weight: 700; font-size: 1.05rem; }
.kh-table__n--danger { color: var(--kh-danger); }
.kh-table__n--gold { color: #8a6d1d; }
.kh-table__n--ok { color: var(--kh-success); }
.kh-badge--move-purchase, .kh-badge--move-return { background: #eef5ef; color: var(--kh-success); }
.kh-badge--move-sale { background: var(--kh-wa-soft, #e6f4ea); color: var(--kh-wa, #1f7a4d); }
.kh-badge--move-loss { background: #f9efef; color: var(--kh-danger); }
.kh-badge--move-adjust { background: #f6f1e4; color: #7a6428; }
.kh-dialog--form { max-width: 460px; text-align: start; }
.kh-dialog__title { margin: 0 0 4px; font-size: 1.15rem; }
.kh-dialog--form .kh-form { margin: 0; }
.kh-dialog--form .kh-dialog__actions { margin-top: 4px; }

/* Order dialogs: one bordered card per line (#, product, qty, unit price,
	line total, remove) so several products never blur into one another —
	phones get the same card stacked over two rows with visible captions. */
.kh-dialog--order { max-width: 680px; width: min(680px, 94vw); max-height: 92vh; overflow-y: auto; }
/* The order dialog scrolls; its buttons stay reachable at the bottom edge. */
.kh-dialog--order .kh-dialog__actions { position: sticky; bottom: -24px; z-index: 2; margin-top: 8px; padding: 10px 0 12px; background: var(--kh-surface); box-shadow: 0 -10px 18px -14px rgba(24, 32, 25, 0.55); }
.kh-olines { display: flex; flex-direction: column; gap: 8px; margin-bottom: 8px; }
.kh-oline {
	display: grid;
	grid-template-columns: 22px minmax(0, 1fr) 64px 104px 82px 36px;
	gap: 8px; align-items: center;
}
.kh-olines .kh-oline { padding: 8px; border: 1px solid var(--kh-border); border-radius: var(--kh-radius-s); background: var(--kh-surface); }
.kh-olines .kh-oline:focus-within { border-color: var(--kh-primary); box-shadow: 0 0 0 3px rgba(14, 124, 67, 0.12); }
.kh-oline--head { margin-bottom: 4px; padding: 0 9px; font-size: 0.78rem; color: var(--kh-muted); grid-template-columns: 22px minmax(0, 1fr) 64px 104px 82px 36px; }
.kh-oline--head span:first-child { visibility: hidden; }
.kh-oline--head span:nth-child(5) { text-align: end; }
.kh-oline__no { font-size: 0.78rem; font-weight: 700; color: var(--kh-muted); text-align: center; font-variant-numeric: tabular-nums; }
.kh-oline__prod { display: flex; flex-direction: column; min-width: 0; }
.kh-oline__prod small { font-size: 0.75rem; }
.kh-oline__pname { font-weight: 600; font-size: 0.9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.kh-oline input[type="text"], .kh-oline input[type="number"] { min-height: 40px; min-width: 0; width: 100%; padding: 4px 8px; border: 1px solid var(--kh-border); border-radius: var(--kh-radius-s); font: inherit; font-size: 0.9rem; }
.kh-oline__qty, .kh-oline__price, .kh-oline__sum { display: flex; flex-direction: column; min-width: 0; }
.kh-oline__sum { text-align: end; font-variant-numeric: tabular-nums; font-weight: 700; font-size: 0.9rem; overflow: hidden; }
.kh-oline__cap { display: none; font-style: normal; font-size: 0.68rem; color: var(--kh-muted); margin-bottom: 2px; }
/* Flexible sale price: the input plus, when it is under the listed price, how big the discount is. */
.kh-oline__disc { font-size: 0.7rem; line-height: 1.3; color: var(--kh-primary); font-weight: 600; }
.kh-oline__del { min-height: 36px; padding: 0; justify-content: center; }
.kh-olines__empty { margin: 0 0 8px; padding: 14px; border: 1px dashed var(--kh-border); border-radius: var(--kh-radius-s); color: var(--kh-muted); font-size: 0.88rem; text-align: center; }
.kh-olines__add { display: flex; gap: 6px; margin: 10px 0 4px; flex-wrap: wrap; }
.kh-olines__add select { flex: 1 1 200px; min-width: 0; min-height: 40px; padding: 4px 8px; border: 1px solid var(--kh-border); border-radius: var(--kh-radius-s); font: inherit; font-size: 0.9rem; background: var(--kh-surface); color: var(--kh-text); }
.kh-olines__total { margin: 8px 0 12px; font-size: 1.05rem; }
.kh-olines__total b { color: var(--kh-primary); font-variant-numeric: tabular-nums; }

/* Invoice discount: kind (none / percent / amount) + value. */
.kh-odisc { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; margin: 12px 0 8px; padding: 10px 12px; border: 1px solid var(--kh-border); border-radius: var(--kh-radius-s); background: var(--kh-soft); }
.kh-odisc__label { font-size: 0.9rem; font-weight: 600; }
.kh-odisc__controls { display: flex; gap: 8px; flex: 1 1 240px; min-width: 0; }
.kh-odisc select, .kh-odisc input[type="number"] { min-height: 44px; min-width: 0; padding: 4px 10px; border: 1px solid var(--kh-border); border-radius: var(--kh-radius-s); font: inherit; font-size: 0.95rem; background: var(--kh-surface); color: var(--kh-text); }
.kh-odisc select { flex: 1 1 130px; }
.kh-odisc input[type="number"] { flex: 1 1 100px; font-variant-numeric: tabular-nums; }
.kh-odisc input[type="number"]:disabled { background: var(--kh-soft); color: var(--kh-muted); }

/* Money summary under the lines: subtotal, discount, net. */
.kh-osum { margin: 0 0 12px; display: flex; flex-direction: column; gap: 4px; }
.kh-osum > div { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.kh-osum dt, .kh-osum dd { margin: 0; font-size: 0.92rem; }
.kh-osum dd { font-variant-numeric: tabular-nums; }
.kh-osum__disc dt, .kh-osum__disc dd { color: var(--kh-danger); font-weight: 600; }
.kh-osum__net { padding-top: 6px; border-top: 1px solid var(--kh-border); }
.kh-osum__net dt { font-weight: 700; font-size: 1rem; }
.kh-osum__net dd { font-size: 1.15rem; font-weight: 800; color: var(--kh-primary); }

/* Preview before approval: the receipt as it will print. */
.kh-opreview { margin: 0 0 12px; padding: 12px; border: 2px solid var(--kh-primary); border-radius: var(--kh-radius-s); background: var(--kh-surface); }
.kh-opreview h3 { margin: 0 0 8px; font-size: 0.98rem; color: var(--kh-primary); }
.kh-opreview__meta { display: flex; flex-wrap: wrap; gap: 4px 16px; margin-bottom: 8px; font-size: 0.86rem; }
.kh-opreview [data-kh-preview-body] { overflow-x: auto; } /* the 5-column table scrolls, the dialog never does sideways */
.kh-opreview__table { width: 100%; min-width: 320px; border-collapse: collapse; font-size: 0.86rem; }
.kh-opreview__table th, .kh-opreview__table td { border: 1px solid var(--kh-border); padding: 6px 8px; text-align: start; }
.kh-opreview__table th { background: var(--kh-soft); font-weight: 600; }
.kh-opreview__table tfoot td { font-weight: 700; background: var(--kh-soft); }
.kh-opreview__net td { font-size: 1rem; color: var(--kh-primary); }
.kh-opreview .kh-hint { margin: 8px 0 0; }

/* AI screen: the generated brief, read-only and monospaced-numbers. */
.kh-ai-text { width: 100%; min-height: 320px; padding: 12px; border: 1px solid var(--kh-border); border-radius: var(--kh-radius-s); background: var(--kh-soft); color: var(--kh-text); font: inherit; font-size: 0.85rem; line-height: 1.7; resize: vertical; }

/* Orders list: how big the discount on a sale was. */
.kh-disc-note { color: var(--kh-danger); font-weight: 600; }
.kh-table__staff { white-space: normal; min-width: 150px; font-size: 0.85rem; }

@media (max-width: 620px) {
	/* Phone: the line becomes a two-row card — number + product name on top,
		the three numbers labelled underneath, delete in the corner. */
	.kh-oline {
		grid-template-columns: 26px repeat(3, minmax(0, 1fr));
		grid-template-areas: "no prod prod del" "qty qty price sum";
		gap: 8px; align-items: end;
	}
	.kh-oline--head { display: none; }
	.kh-oline__no { grid-area: no; align-self: center; text-align: start; }
	.kh-oline__prod { grid-area: prod; }
	.kh-oline__qty { grid-area: qty; }
	.kh-oline__price { grid-area: price; }
	.kh-oline__sum { grid-area: sum; text-align: start; }
	.kh-oline__del { grid-area: del; align-self: center; justify-self: end; width: 36px; }
	.kh-oline__cap { display: block; }
	.kh-oline__sum b { min-height: 40px; display: flex; align-items: center; }
	.kh-odisc__label { flex: 1 1 100%; }
	.kh-osum dt, .kh-osum dd { font-size: 0.95rem; }
	/* Dialog buttons stack full width: no mis-taps between «معاينة» and «اعتماد». */
	.kh-dialog--order .kh-dialog__actions { flex-direction: column; align-items: stretch; }
	.kh-dialog--order .kh-dialog__actions .kh-btn { width: 100%; justify-content: center; min-height: 46px; }
}
@media (max-width: 760px) {
	.kh-stats--4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
	/* Phone: card tables (stock, orders) — each row becomes a block: heading, inline labelled numbers, full-width buttons. */
	.kh-table--cards, .kh-table--cards tbody, .kh-table--cards tr, .kh-table--cards td { display: block; white-space: normal; }
	.kh-table--cards thead { display: none; }
	.kh-table--cards tr { padding: 10px 0; border-bottom: 1px solid var(--kh-border); }
	.kh-table--cards td { border: 0; padding: 4px 0; }
	.kh-table--cards td[data-l] { display: inline-block; margin-inline-end: 16px; font-size: 0.95rem; }
	.kh-table--cards td[data-l]::before { content: attr(data-l) ': '; color: var(--kh-muted); font-size: 0.8rem; font-weight: 400; }
	.kh-table--cards .kh-table__actions { flex-wrap: wrap; }
	.kh-table--cards .kh-table__actions .kh-btn { flex: 1 1 auto; justify-content: center; }
	.kh-table--cards .kh-table__actions form { display: flex; flex: 1 1 100%; gap: 6px; }
	.kh-table--cards .kh-table__actions form .kh-btn { flex: 1 1 auto; }
}

/* Category icon picker: preview disc + library dialog with Arabic/English keyword search. */
.kh-plist__thumb svg { width: 60%; height: 60%; margin: 20%; color: var(--kh-primary); display: block; }
.kh-iconpick { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin-bottom: 10px; }
.kh-iconpick__preview { width: 72px; height: 72px; flex-shrink: 0; display: grid; place-items: center; border-radius: 50%; background: var(--kh-soft); color: var(--kh-primary); overflow: hidden; }
.kh-iconpick__preview img { width: 100%; height: 100%; object-fit: cover; display: block; }
.kh-iconpick__preview svg { width: 36px; height: 36px; }
.kh-iconpick__hint { flex-basis: 100%; }
.kh-iconlib { width: min(760px, 94vw); max-height: 88vh; padding: 16px; border: 0; border-radius: var(--kh-radius); background: var(--kh-surface); color: var(--kh-text); box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25); }
.kh-iconlib::backdrop { background: rgba(24, 32, 25, 0.5); }
.kh-iconlib__head { display: flex; gap: 8px; margin-bottom: 6px; }
.kh-iconlib__search { flex: 1; min-width: 0; min-height: 44px; padding: 0 12px; border: 1px solid var(--kh-border); border-radius: var(--kh-radius-s); font: inherit; font-size: 16px; }
.kh-iconlib__search:focus { outline: none; border-color: var(--kh-primary); box-shadow: 0 0 0 3px rgba(14, 124, 67, 0.18); }
.kh-iconlib__count { margin: 0 0 8px; font-size: 0.8rem; }
.kh-iconlib__grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(88px, 1fr)); gap: 6px; max-height: 62vh; overflow-y: auto; padding: 2px; }
.kh-iconlib__item { display: flex; flex-direction: column; align-items: center; gap: 6px; min-width: 0; padding: 10px 4px; border: 1px solid var(--kh-border); border-radius: var(--kh-radius-s); background: var(--kh-surface); color: var(--kh-text); font: inherit; font-size: 0.72rem; cursor: pointer; }
.kh-iconlib__item span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.kh-iconlib__item svg { width: 28px; height: 28px; color: var(--kh-primary); }
.kh-iconlib__item:hover, .kh-iconlib__item:focus-visible { border-color: var(--kh-primary); background: var(--kh-soft); }
.kh-iconlib__item.is-selected { border-color: var(--kh-primary); box-shadow: inset 0 0 0 2px var(--kh-primary); }
.kh-iconlib__item[hidden] { display: none; }
@media (max-width: 480px) { .kh-iconlib { padding: 12px; } .kh-iconlib__grid { grid-template-columns: repeat(auto-fill, minmax(72px, 1fr)); } }

/* Settings: sub-headings inside a card + wide thumbnail (home background preview). */
.kh-subhead { margin: 18px 0 8px; font-size: 1rem; color: var(--kh-primary); }
.kh-plist__thumb--wide { display: block; width: 100%; max-width: 320px; height: auto; aspect-ratio: 16 / 9; margin-bottom: 8px; }
.kh-plist__thumb--wide img { width: 100%; height: 100%; object-fit: cover; border-radius: var(--kh-radius-s); }

/* Product/customer picker: search box + suggestion list (orders, purchases dialogs). */
.kh-pick { position: relative; flex: 1 1 220px; min-width: 0; }
.kh-pick__input { width: 100%; min-height: 40px; padding: 4px 36px 4px 10px; border: 1px solid var(--kh-border); border-radius: var(--kh-radius-s); font: inherit; font-size: 0.95rem; background: var(--kh-surface); color: var(--kh-text); }
.kh-pick__input:focus { outline: none; border-color: var(--kh-primary); box-shadow: 0 0 0 3px rgba(14, 124, 67, 0.18); }
.kh-pick__ico { position: absolute; top: 12px; inset-inline-end: 12px; width: 16px; height: 16px; color: var(--kh-muted); pointer-events: none; }
.kh-pick__list { position: absolute; z-index: 5; inset-inline: 0; top: calc(100% + 4px); max-height: 260px; overflow-y: auto; margin: 0; padding: 4px; list-style: none; background: var(--kh-surface); border: 1px solid var(--kh-border); border-radius: var(--kh-radius-s); box-shadow: 0 12px 32px rgba(0, 0, 0, 0.16); }
.kh-pick__list[hidden] { display: none; }
.kh-pick__item { display: flex; align-items: center; justify-content: space-between; gap: 10px; width: 100%; padding: 8px 10px; border: 0; border-radius: var(--kh-radius-s); background: none; font: inherit; text-align: start; color: var(--kh-text); cursor: pointer; }
.kh-pick__item:hover, .kh-pick__item.is-active { background: var(--kh-soft); color: var(--kh-primary); }
.kh-pick__item b { font-weight: 600; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.kh-pick__item small { flex-shrink: 0; color: var(--kh-muted); font-size: 0.78rem; }
.kh-pick__empty { padding: 10px; color: var(--kh-muted); font-size: 0.85rem; }
.kh-dialog--order .kh-grid-2 { margin-bottom: 8px; }

/* Consultations (الاستشارة الزراعية): one card per question with its answer form. */
.kh-clist { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; }
.kh-clist__item { position: relative; margin: 0; }
.kh-clist__who { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin: 0 0 6px; }
.kh-clist__who a { text-decoration: none; }
.kh-clist__q { margin: 0 0 12px; padding: 12px 14px; border-inline-start: 3px solid var(--kh-primary); background: var(--kh-soft); border-radius: var(--kh-radius-s); white-space: pre-line; line-height: 1.8; }
.kh-clist__form { margin: 0; }
.kh-clist__form .kh-field { margin-bottom: 10px; }
.kh-clist__actions { display: flex; gap: 8px; flex-wrap: wrap; }
.kh-clist__delete { position: absolute; top: 14px; inset-inline-end: 16px; margin: 0; }
@media (max-width: 560px) { .kh-clist__delete { position: static; margin-top: 8px; } }
.kh-sidebar__count { display: inline-block; min-width: 20px; padding: 0 6px; border-radius: 999px; background: var(--kh-danger); color: #fff; font-size: 0.72rem; line-height: 20px; text-align: center; }
.kh-sidebar a[aria-current='page'] .kh-sidebar__count { background: #fff; color: var(--kh-primary); }
.kh-collapsed .kh-sidebar__count { display: none; }
.kh-row-service select { flex: 0 0 170px; }
