/* opsnext shared styles - phone first, then wider screens. Older ops pages keep jQuery Mobile. */
:root {
	--bg: #eef2ef;
	--surface: #ffffff;
	--surface-2: #f6f8f7;
	--text: #18211c;
	--muted: #5b6a61;
	--border: #d6ded9;
	--brand: #1f6f43;          /* Papermake green */
	--brand-2: #2e9a5e;
	--brand-text: #ffffff;
	--accent: var(--brand);    /* replaced per territory below */
	--accent-soft: #e3f3ea;

	/* visit status colours */
	--overdue: #c62828;   --overdue-bg: #fdecea;
	--micro: #7b3fb8;     --micro-bg: #f2eafb;
	--perpetual: #1e63c4; --perpetual-bg: #e7f0fc;
	--addon: #b26a00;     --addon-bg: #fff3dc;
	--done: #7b847f;      --done-bg: #eceeed;
	--ok: #1f7a46;        --ok-bg: #e3f3ea;

	--danger: #b42318;
	--radius: 12px;
	--shadow: 0 1px 2px rgba(16, 24, 20, .06), 0 2px 8px rgba(16, 24, 20, .06);
	--tap: 48px;               /* minimum touch target */
	--on-accent: #ffffff;      /* text on solid accent / success buttons */
	color-scheme: light;
}
@media (prefers-color-scheme: dark) {
	:root {
		--bg: #101512;
		--surface: #19201c;
		--surface-2: #1f2823;
		--text: #e5ece8;
		--muted: #9aaba1;
		--border: #2f3a34;
		--brand: #2f9a5e;
		--brand-2: #46b877;
		--brand-text: #ffffff;
		--accent-soft: #183326;
		--overdue: #ff8a80;   --overdue-bg: #3a1c1a;
		--micro: #c9a3f5;     --micro-bg: #2c2140;
		--perpetual: #8ab8ff; --perpetual-bg: #1a2a42;
		--addon: #ffc266;     --addon-bg: #3a2c12;
		--done: #8f9a94;      --done-bg: #262d29;
		--ok: #6fd39b;        --ok-bg: #183326;
		--danger: #ff8a80;
		--shadow: 0 1px 2px rgba(0,0,0,.4);
		--on-accent: #0b130e;
		color-scheme: dark;
	}
}

/* territory accents */
.cal-h1h5 { --accent: #0f8a7e; --accent-soft: #dff4f1; }
.cal-h2   { --accent: #d4621a; --accent-soft: #fdeee3; }
.cal-h3   { --accent: #4a4fc4; --accent-soft: #e9eafb; }
.cal-h4   { --accent: #b8327a; --accent-soft: #fbe6f1; }
@media (prefers-color-scheme: dark) {
	.cal-h1h5 { --accent: #3cc4b6; --accent-soft: #143430; }
	.cal-h2   { --accent: #ff9a52; --accent-soft: #3a2414; }
	.cal-h3   { --accent: #8f94ff; --accent-soft: #23254a; }
	.cal-h4   { --accent: #f07ab8; --accent-soft: #3d1a2d; }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
	margin: 0;
	background: var(--bg);
	color: var(--text);
	font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
	padding-bottom: calc(68px + env(safe-area-inset-bottom)); /* room for the bottom tab bar */
}
body.no-tabs { padding-bottom: 0; }
a { color: var(--accent); }
[hidden] { display: none !important; }

/* ---------- top bar ---------- */
.topbar {
	position: sticky; top: 0; z-index: 20;
	display: flex; align-items: center; gap: 10px;
	padding: 10px 16px; padding-top: calc(10px + env(safe-area-inset-top));
	background: linear-gradient(120deg, var(--brand) 0%, var(--brand-2) 100%);
	color: var(--brand-text);
	box-shadow: 0 2px 6px rgba(0,0,0,.15);
}
.topbar a { color: var(--brand-text); text-decoration: none; }
.topbar .brand { font-weight: 800; letter-spacing: .01em; white-space: nowrap; }
.topbar .spacer { flex: 1; }
.topbar .who { opacity: .85; font-size: 14px; }
.topbar .menu-link { font-size: 14px; padding: 8px 4px; white-space: nowrap; }
@media (max-width: 480px) { .topbar .menu-link.wide-only { display: none; } .topbar { gap: 8px; } }
.terr-switch {
	appearance: none; -webkit-appearance: none;
	background: rgba(255,255,255,.18); color: #fff; border: 1px solid rgba(255,255,255,.35);
	border-radius: 999px; padding: 8px 32px 8px 14px; font-weight: 700; font-size: 15px; min-height: 40px; width: auto; max-width: 50vw;
	background-image: linear-gradient(45deg, transparent 50%, #fff 50%), linear-gradient(135deg, #fff 50%, transparent 50%);
	background-position: calc(100% - 16px) 50%, calc(100% - 11px) 50%; background-size: 5px 5px; background-repeat: no-repeat;
}
.terr-switch option { color: #000; }
.terr-band { height: 4px; background: var(--accent); }

/* ---------- layout ---------- */
.page { max-width: 1100px; margin: 0 auto; padding: 14px 12px; }
.card {
	background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
	padding: 16px; box-shadow: var(--shadow);
}
.narrow { max-width: 400px; margin: 8vh auto 0; }
.stack > * + * { margin-top: 10px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }

h1 { font-size: 21px; margin: 0 0 12px; }
h2 { font-size: 17px; margin: 18px 0 8px; }
label { display: block; font-weight: 600; margin: 12px 0 4px; }
.hint { color: var(--muted); font-size: 14px; }

input[type=text], input[type=password], input[type=date], input[type=search], select, textarea {
	width: 100%; min-height: var(--tap); padding: 10px 12px; font-size: 16px; /* 16px stops iOS zoom */
	border: 1px solid var(--border); border-radius: 10px; background: var(--surface-2); color: var(--text);
}
textarea { min-height: 90px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 3px solid var(--accent-soft); border-color: var(--accent); }

/* ---------- buttons ---------- */
button, .btn {
	display: inline-flex; align-items: center; justify-content: center; gap: 6px;
	min-height: var(--tap); padding: 10px 18px; font-size: 16px; font-weight: 700; cursor: pointer;
	border: 1px solid var(--accent); border-radius: 10px; background: var(--accent); color: var(--on-accent);
	text-decoration: none; -webkit-tap-highlight-color: transparent;
}
button:active, .btn:active { transform: translateY(1px); }
button.secondary, .btn.secondary { background: var(--surface); color: var(--accent); }
button.ghost, .btn.ghost { background: transparent; border-color: transparent; color: var(--accent); }
button.danger, .btn.danger { background: var(--danger); border-color: var(--danger); }
button.success, .btn.success { background: var(--ok); border-color: var(--ok); }
button:disabled { opacity: .5; cursor: default; }
.block { width: 100%; margin-top: 16px; }
.btn-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.btn-row.three { grid-template-columns: 1fr 1fr 1fr; }

/* ---------- alerts & chips ---------- */
.alert { padding: 12px 14px; border-radius: 10px; margin-bottom: 12px; }
.alert.error { background: var(--overdue-bg); color: var(--overdue); }
.alert.ok { background: var(--ok-bg); color: var(--ok); }
.chip {
	display: inline-flex; align-items: center; gap: 4px; padding: 3px 9px; border-radius: 999px;
	font-size: 12px; font-weight: 700; letter-spacing: .02em; white-space: nowrap;
	background: var(--accent-soft); color: var(--accent);
}
.chip.overdue   { background: var(--overdue-bg);   color: var(--overdue); }
.chip.micro     { background: var(--micro-bg);     color: var(--micro); }
.chip.perpetual { background: var(--perpetual-bg); color: var(--perpetual); }
.chip.addon     { background: var(--addon-bg);     color: var(--addon); }
.chip.done      { background: var(--done-bg);      color: var(--done); }
.chip.ok        { background: var(--ok-bg);        color: var(--ok); }
.legend { display: flex; gap: 6px; flex-wrap: wrap; margin: 8px 0 4px; }

/* ---------- lists / tables ---------- */
table.list { width: 100%; border-collapse: collapse; background: var(--surface); }
table.list th, table.list td { padding: 10px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
table.list th { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.table-wrap { overflow-x: auto; border-radius: var(--radius); border: 1px solid var(--border); }

/* ---------- bottom tab bar (phones) ---------- */
.tabs {
	position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
	display: grid; grid-template-columns: repeat(4, 1fr);
	background: var(--surface); border-top: 1px solid var(--border);
	padding-bottom: env(safe-area-inset-bottom);
	box-shadow: 0 -2px 10px rgba(0,0,0,.06);
}
.tabs a {
	display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
	min-height: 60px; font-size: 12px; font-weight: 600; color: var(--muted); text-decoration: none;
}
.tabs a svg { width: 24px; height: 24px; }
.tabs a.active { color: var(--accent); }
.tabs a.active svg { filter: drop-shadow(0 0 6px var(--accent-soft)); }

/* ---------- bottom sheet (event details on phones) ---------- */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 40; }
.sheet {
	position: fixed; left: 0; right: 0; bottom: 0; z-index: 41; max-height: 88vh; overflow-y: auto;
	background: var(--surface); border-radius: 18px 18px 0 0; padding: 8px 16px calc(16px + env(safe-area-inset-bottom));
	box-shadow: 0 -6px 24px rgba(0,0,0,.2);
}
.sheet .grab { width: 44px; height: 5px; border-radius: 3px; background: var(--border); margin: 6px auto 10px; }
.sheet .head { border-left: 5px solid var(--accent); padding-left: 10px; margin-bottom: 10px; }
.sheet dl { display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; margin: 10px 0; }
.sheet dt { color: var(--muted); font-size: 14px; }
.sheet dd { margin: 0; }

/* ---------- toast ---------- */
.toast {
	position: fixed; left: 50%; bottom: calc(80px + env(safe-area-inset-bottom)); transform: translateX(-50%);
	background: #1d2520; color: #fff; padding: 12px 18px; border-radius: 10px; z-index: 60;
	box-shadow: 0 4px 16px rgba(0,0,0,.3); max-width: calc(100% - 32px); font-weight: 600;
}

/* ---------- wider screens ---------- */
@media (min-width: 900px) {
	body { padding-bottom: 0; }
	.tabs {
		position: static; display: flex; justify-content: center; gap: 4px; padding: 6px;
		background: var(--surface); border-top: 0; border-bottom: 1px solid var(--border); box-shadow: none;
	}
	.tabs a { flex-direction: row; min-height: 40px; padding: 0 16px; font-size: 14px; border-radius: 8px; }
	.tabs a.active { background: var(--accent-soft); }
	.tabs a svg { width: 18px; height: 18px; }
	.page { padding: 20px; }
	.sheet { left: auto; right: 16px; bottom: 16px; top: 80px; width: 420px; max-height: none; border-radius: 16px; }
	.toast { bottom: 24px; }
}

@media print {
	.topbar, .tabs, .no-print, .terr-band { display: none !important; }
	body { background: #fff; color: #000; padding: 0; }
	.card { box-shadow: none; border-color: #999; }
}
