/* ============================================================
   OUR DAIRY - design system
   Green / cream / white branding. Mobile-first; bottom nav on
   phones, sidebar on desktop. Touch targets >= 44px.
   ============================================================ */

:root {
	--green-900: #0b3d1f;
	--green-700: #14572b;
	--green-600: #1a7a3a;
	--green-500: #24924a;
	--green-100: #dcefe0;
	--green-50:  #eef7f0;
	--cream:     #faf6ec;
	--cream-2:   #f3ecdb;
	--white:     #ffffff;
	--ink:       #1c2420;
	--ink-2:     #55605a;
	--line:      #e3e0d5;
	--danger:    #b3261e;
	--danger-bg: #fdecea;
	--warn:      #9a6b00;
	--warn-bg:   #fdf3d7;
	--ok-bg:     #e5f4e8;
	--radius: 14px;
	--radius-sm: 9px;
	--shadow: 0 1px 3px rgba(20, 60, 35, .08), 0 4px 14px rgba(20, 60, 35, .06);
	--font: -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
	margin: 0;
	font-family: var(--font);
	font-size: 16px;
	line-height: 1.45;
	color: var(--ink);
	background: var(--cream);
	min-height: 100dvh;
}
h1, h2, h3 { line-height: 1.2; margin: 0 0 .5rem; }
h1 { font-size: 1.45rem; }
h2 { font-size: 1.15rem; }
a { color: var(--green-600); }
img, svg { vertical-align: middle; }

/* ---------- layout ---------- */
.app-shell { display: flex; min-height: 100dvh; }
.sidebar {
	display: none;
	width: 232px;
	flex-shrink: 0;
	background: var(--green-900);
	color: #e8f2ea;
	padding: 14px 10px;
	position: sticky; top: 0; height: 100dvh; overflow-y: auto;
}
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
	background: var(--green-700);
	color: #fff;
	padding: 12px 16px;
	display: flex; align-items: center; gap: 10px;
	position: sticky; top: 0; z-index: 30;
}
.topbar .brand { font-weight: 700; letter-spacing: .4px; font-size: 1.05rem; }
.topbar .spacer { flex: 1; }
.topbar .who { font-size: .82rem; opacity: .9; text-align: right; line-height: 1.15; }
.content { padding: 14px 14px 88px; max-width: 980px; width: 100%; margin: 0 auto; }
/* The SPA moves focus to #view after each render so assistive technology
   announces the new screen. #view is not an interactive control, so suppress
   the browser's focus ring here; normal control focus indicators remain. */
.content:focus { outline: none; }

/* bottom nav (mobile) */
.bottom-nav {
	position: fixed; bottom: 0; left: 0; right: 0;
	display: flex;
	background: var(--white);
	border-top: 1px solid var(--line);
	padding-bottom: env(safe-area-inset-bottom);
	z-index: 40;
}
.bottom-nav a {
	flex: 1;
	display: flex; flex-direction: column; align-items: center; gap: 2px;
	padding: 8px 2px 7px;
	font-size: .68rem;
	color: var(--ink-2);
	text-decoration: none;
	min-height: 54px;
	justify-content: center;
}
.bottom-nav a .ico { font-size: 1.25rem; line-height: 1; }
.bottom-nav a.active { color: var(--green-700); font-weight: 600; }

/* hamburger: opens the full sidebar menu on small screens */
.nav-toggle {
	min-width: 44px; min-height: 44px;
	display: inline-flex; align-items: center; justify-content: center;
	font-size: 1.25rem; line-height: 1;
	background: rgba(255,255,255,.12); color: #fff;
	border: 1px solid rgba(255,255,255,.28); border-radius: var(--radius-sm);
	cursor: pointer; padding: 0;
}
.nav-toggle:hover { background: rgba(255,255,255,.22); }
.nav-scrim {
	position: fixed; inset: 0;
	background: rgba(12,30,18,.5);
	z-index: 45;
}
/* small screens: sidebar becomes a slide-over drawer */
@media (max-width: 899.99px) {
	.sidebar {
		display: block;
		position: fixed; left: 0; top: 0;
		height: 100dvh;
		width: min(78vw, 300px);
		z-index: 50;
		transform: translateX(-105%);
		visibility: hidden;
		transition: transform .18s ease, visibility 0s linear .18s;
		box-shadow: 6px 0 24px rgba(0,0,0,.35);
	}
	body.nav-open .sidebar {
		transform: none;
		visibility: visible;
		transition: transform .18s ease, visibility 0s;
	}
	.sidebar nav a {
		display: flex; gap: 10px; align-items: center;
		padding: 11px 12px;
		color: #d7e8db; text-decoration: none;
		border-radius: var(--radius-sm);
		font-size: .95rem;
		min-height: 44px;
	}
	.sidebar nav a.active { background: var(--green-600); color: #fff; font-weight: 600; }
	.sidebar .brand {
		font-weight: 800; font-size: 1.15rem; color: #fff;
		padding: 6px 10px 14px; letter-spacing: .5px;
	}
	.sidebar .side-foot { margin-top: 18px; padding: 10px 12px; font-size: .8rem; color: #b9d3c0; }
	.sidebar .side-foot button { margin-top: 8px; width: 100%; }
}

@media (min-width: 900px) {
	.sidebar { display: block; }
	.bottom-nav { display: none; }
	.content { padding: 22px 26px 40px; }
	.topbar { display: none; }
	.nav-toggle, .nav-scrim { display: none !important; }
	.sidebar .brand {
		font-weight: 800; font-size: 1.15rem; color: #fff;
		padding: 6px 10px 14px; letter-spacing: .5px;
	}
	.sidebar nav a {
		display: flex; gap: 10px; align-items: center;
		padding: 11px 12px;
		color: #d7e8db; text-decoration: none;
		border-radius: var(--radius-sm);
		font-size: .95rem;
		min-height: 44px;
	}
	.sidebar nav a:hover { background: rgba(255,255,255,.08); }
	.sidebar nav a.active { background: var(--green-600); color: #fff; font-weight: 600; }
	.sidebar .side-foot { margin-top: 18px; padding: 10px 12px; font-size: .8rem; color: #b9d3c0; }
	.sidebar .side-foot button { margin-top: 8px; width: 100%; }
}

/* ---------- cards & grids ---------- */
.card {
	background: var(--white);
	border: 1px solid var(--line);
	border-radius: var(--radius);
	box-shadow: var(--shadow);
	padding: 14px;
	margin-bottom: 14px;
}
.card h2 { font-size: 1rem; color: var(--green-900); margin-bottom: 10px; }
.grid { display: grid; gap: 10px; }
.grid-2 { grid-template-columns: 1fr; }
.grid-3 { grid-template-columns: 1fr 1fr; }
@media (min-width: 700px) {
	.grid-2 { grid-template-columns: 1fr 1fr; }
	.grid-3 { grid-template-columns: repeat(3, 1fr); }
}
.stat {
	background: var(--white);
	border: 1px solid var(--line);
	border-radius: var(--radius);
	padding: 12px 14px;
	box-shadow: var(--shadow);
}
.stat .label { font-size: .78rem; color: var(--ink-2); }
.stat .value { font-size: 1.35rem; font-weight: 700; color: var(--green-900); margin-top: 2px; word-break: break-all; }
.stat .value.money { color: var(--green-700); }
.stat .sub { font-size: .75rem; color: var(--ink-2); margin-top: 2px; }

/* ---------- forms ---------- */
label.field { display: block; margin-bottom: 10px; font-size: .85rem; color: var(--ink-2); }
label.field > span { display: block; margin-bottom: 4px; font-weight: 600; color: var(--ink); }
input, select, textarea {
	width: 100%;
	padding: 11px 12px;
	font-size: 1rem;
	font-family: var(--font);
	border: 1.5px solid var(--line);
	border-radius: var(--radius-sm);
	background: var(--white);
	color: var(--ink);
	min-height: 46px;
}
input:focus, select:focus, textarea:focus {
	outline: none;
	border-color: var(--green-500);
	box-shadow: 0 0 0 3px var(--green-100);
}
textarea { min-height: 70px; resize: vertical; }
.form-row { display: grid; gap: 10px; grid-template-columns: 1fr; }
@media (min-width: 620px) { .form-row.c2 { grid-template-columns: 1fr 1fr; } .form-row.c3 { grid-template-columns: 1fr 1fr 1fr; } }

.btn {
	display: inline-flex; align-items: center; justify-content: center; gap: 7px;
	padding: 11px 18px;
	min-height: 46px;
	font-size: .95rem; font-weight: 600;
	border-radius: var(--radius-sm);
	border: 1.5px solid transparent;
	cursor: pointer;
	text-decoration: none;
	font-family: var(--font);
	transition: filter .15s ease;
}
.btn:active { filter: brightness(.92); }
.btn-primary { background: var(--green-600); color: #fff; }
.btn-primary:hover { background: var(--green-700); }
.btn-outline { background: var(--white); border-color: var(--green-600); color: var(--green-700); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-ghost { background: transparent; color: var(--green-700); }
.btn-sm { padding: 7px 12px; min-height: 36px; font-size: .85rem; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }
.btn-block { width: 100%; }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.tbl { width: 100%; border-collapse: collapse; font-size: .9rem; }
.tbl th {
	text-align: left; font-size: .72rem; text-transform: uppercase; letter-spacing: .4px;
	color: var(--ink-2); padding: 8px 10px; border-bottom: 2px solid var(--line);
	white-space: nowrap;
}
.tbl td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
.tbl tr:last-child td { border-bottom: none; }
.tbl .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ---------- badges & states ---------- */
.badge {
	display: inline-block; padding: 3px 9px; font-size: .72rem; font-weight: 700;
	border-radius: 999px; background: var(--green-50); color: var(--green-900);
	white-space: nowrap;
}
.badge.gray { background: #eceff1; color: #455a64; }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.danger { background: var(--danger-bg); color: var(--danger); }
.badge.ok { background: var(--ok-bg); color: var(--green-700); }

.empty {
	text-align: center; color: var(--ink-2);
	padding: 30px 14px; font-size: .92rem;
}
.empty .big { font-size: 1.9rem; display: block; margin-bottom: 6px; }

.alert { border-radius: var(--radius-sm); padding: 11px 13px; font-size: .9rem; margin-bottom: 12px; }
.alert.error { background: var(--danger-bg); color: var(--danger); border: 1px solid #f2b8b5; }
.alert.success { background: var(--ok-bg); color: var(--green-700); border: 1px solid #bfe3c8; }
.alert.info { background: #e8f1fb; color: #1c4d8f; border: 1px solid #c4d9f2; }
.alert ul { margin: 4px 0 0 18px; padding: 0; }

/* ---------- misc ---------- */
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.page-head h1 { margin: 0; }
.section-title { font-size: .8rem; text-transform: uppercase; letter-spacing: .5px; color: var(--ink-2); margin: 18px 0 8px; font-weight: 700; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.settings-tabs { margin-top: 4px; }
.settings-panel[hidden] { display: none !important; }
.people-tabs { margin-top: 4px; }
.people-search { display: flex; gap: 8px; margin: 0 0 12px; max-width: 560px; }
.people-search input { flex: 1; min-width: 0; }

/* Sale form: type-to-find customer (name or mobile) */
.cust-pick { position: relative; }
.cust-pick-chosen {
	display: flex; align-items: center; flex-wrap: wrap; gap: 6px;
	padding: 10px 12px; margin-bottom: 8px;
	background: var(--green-50); border: 1px solid var(--green-100);
	border-radius: var(--radius-sm); font-size: .95rem;
}
.cust-pick-row {
	display: flex; align-items: stretch; gap: 0;
}
.cust-pick-q {
	margin-bottom: 0; flex: 1; min-width: 0;
	border-top-right-radius: 0; border-bottom-right-radius: 0;
}
.cust-pick-drop {
	min-width: 46px; min-height: 46px; padding: 0 12px;
	border-top-left-radius: 0; border-bottom-left-radius: 0;
	border-left: 0; font-size: 1.1rem; line-height: 1;
}
.cust-pick-list {
	position: absolute; left: 0; right: 0; z-index: 20;
	max-height: 220px; overflow-y: auto;
	background: var(--white); border: 1.5px solid var(--line);
	border-radius: var(--radius-sm); box-shadow: var(--shadow);
	margin-top: 4px;
}
.cust-pick-item {
	display: flex; flex-direction: column; align-items: flex-start; gap: 2px;
	width: 100%; text-align: left; padding: 10px 12px;
	border: 0; border-bottom: 1px solid var(--line);
	background: transparent; font: inherit; cursor: pointer; min-height: 44px;
}
.cust-pick-item:last-child { border-bottom: none; }
.cust-pick-item:hover, .cust-pick-item:focus { background: var(--green-50); outline: none; }
.cust-pick-empty { padding: 12px; color: var(--ink-2); font-size: .88rem; }
.people-actions { white-space: nowrap; }
.people-actions .btn { margin: 2px; }
.people-pager { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 12px 4px; color: var(--ink-2); font-size: .9rem; }
.chip {
	padding: 8px 14px; border-radius: 999px; border: 1.5px solid var(--line);
	background: var(--white); font-size: .85rem; cursor: pointer; min-height: 38px;
	display: inline-flex; align-items: center;
}
.chip.active { background: var(--green-600); border-color: var(--green-600); color: #fff; font-weight: 600; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 14px; font-size: .92rem; }
.kv dt { color: var(--ink-2); }
.kv dd { margin: 0; font-weight: 600; text-align: right; }
.filters { display: grid; gap: 8px; grid-template-columns: 1fr 1fr; margin-bottom: 12px; }
.filters .wide { grid-column: 1 / -1; }
.loading { text-align: center; color: var(--ink-2); padding: 26px; }
.spinner {
	width: 26px; height: 26px; margin: 0 auto 8px;
	border: 3px solid var(--green-100); border-top-color: var(--green-600);
	border-radius: 50%; animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.offline-bar {
	display: none; background: var(--warn-bg); color: var(--warn);
	text-align: center; padding: 7px; font-size: .85rem; font-weight: 600;
}
body.offline .offline-bar { display: block; }
.fab {
	position: fixed; right: 16px; bottom: 74px;
	width: 56px; height: 56px; border-radius: 50%;
	background: var(--green-600); color: #fff; font-size: 1.7rem;
	border: none; box-shadow: var(--shadow); cursor: pointer; z-index: 35;
	display: flex; align-items: center; justify-content: center;
}
@media (min-width: 900px) { .fab { bottom: 26px; } }

/* login */
.login-wrap { min-height: 100dvh; display: flex; align-items: center; justify-content: center; padding: 18px; }
.login-card { width: 100%; max-width: 380px; }
.login-brand { text-align: center; margin-bottom: 18px; }
.login-brand .logo {
	width: 74px; height: 74px; border-radius: 22px;
	background: var(--green-600); color: #fff;
	display: inline-flex; align-items: center; justify-content: center;
	font-size: 2rem; font-weight: 800; box-shadow: var(--shadow);
}
.login-brand h1 { margin: 10px 0 2px; color: var(--green-900); }
.login-brand p { margin: 0; color: var(--ink-2); font-size: .9rem; }

/* receipt */
.receipt { max-width: 420px; margin: 0 auto; background: #fff; padding: 22px; border-radius: var(--radius); box-shadow: var(--shadow); }
.receipt table { width: 100%; border-collapse: collapse; font-size: .92rem; }
.receipt td, .receipt th { padding: 6px 4px; text-align: left; }
.receipt .r-num { text-align: right; font-variant-numeric: tabular-nums; }
.receipt .total-row td { border-top: 2px solid var(--ink); font-weight: 700; font-size: 1rem; }
.receipt-head { text-align: center; margin-bottom: 14px; }
.receipt-head h1 { font-size: 1.3rem; color: var(--green-900); }
@media print {
	.topbar, .sidebar, .bottom-nav, .no-print { display: none !important; }
	body { background: #fff; }
	.receipt { box-shadow: none; }
}

/* toast */
#toast {
	position: fixed; left: 50%; transform: translateX(-50%);
	bottom: 84px; z-index: 100;
	background: var(--green-900); color: #fff;
	padding: 11px 20px; border-radius: 999px;
	font-size: .9rem; box-shadow: var(--shadow);
	opacity: 0; pointer-events: none; transition: opacity .25s ease;
	max-width: 88vw; text-align: center;
}
#toast.show { opacity: 1; }
#toast.error { background: var(--danger); }
