:root {
	--color-bg: #f5f7fa;
	--color-card: #ffffff;
	--color-text: #1f2937;
	--color-muted: #6b7280;
	--color-primary: #2563eb;
	--color-primary-dark: #1d4ed8;
	--color-danger: #dc2626;
	--color-border: #e5e7eb;
	--color-good: #16a34a;
	--radius: 12px;
}

* {
	box-sizing: border-box;
}

html {
	overflow-x: hidden;
}

body {
	margin: 0;
	font-family:
		-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
	background: var(--color-bg);
	color: var(--color-text);
	min-height: 100vh;
	overflow-x: hidden;
}

a {
	color: var(--color-primary);
	text-decoration: none;
}

a:hover {
	text-decoration: underline;
}

.topbar {
	display: flex;
	flex-wrap: wrap;
	justify-content: space-between;
	align-items: center;
	gap: 0.5rem;
	padding: 0.75rem 1.25rem;
	background: var(--color-card);
	border-bottom: 1px solid var(--color-border);
	position: sticky;
	top: 0;
	z-index: 10;
}

.brand {
	font-weight: 700;
	font-size: 1.1rem;
	color: var(--color-text);
}

#nav {
	display: flex;
	flex-wrap: wrap;
	gap: 0.4rem 1rem;
	align-items: center;
}

.link-button {
	background: none;
	border: none;
	color: var(--color-primary);
	font: inherit;
	cursor: pointer;
	padding: 0;
}

.link-button:hover {
	text-decoration: underline;
}

main#app {
	max-width: 640px;
	margin: 0 auto;
	padding: 1.25rem;
	/* clear the fixed bottom bar (~56px) + a small gap + safe area */
	padding-bottom: calc(56px + 0.25rem + env(safe-area-inset-bottom));
}

.card {
	background: var(--color-card);
	border-radius: var(--radius);
	border: 1px solid var(--color-border);
	padding: 1.25rem;
	margin-bottom: 1rem;
}

.card h1 {
	margin-top: 0;
	font-size: 1.4rem;
}

.card h2 {
	margin-top: 0;
	font-size: 0.95rem;
	color: var(--color-muted);
	font-weight: 600;
	text-transform: uppercase;
	letter-spacing: 0.03em;
}

.card h3 {
	font-size: 0.95rem;
	font-weight: 600;
	margin: 1.25rem 0 0.5rem;
}

.form label {
	display: block;
	margin-bottom: 0.9rem;
	font-size: 0.9rem;
	color: var(--color-muted);
}

.form input {
	display: block;
	width: 100%;
	margin-top: 0.3rem;
	padding: 0.6rem 0.7rem;
	border: 1px solid var(--color-border);
	border-radius: 8px;
	font-size: 1rem;
}

.form button {
	width: 100%;
	padding: 0.7rem;
	background: var(--color-primary);
	color: white;
	border: none;
	border-radius: 8px;
	font-size: 1rem;
	font-weight: 600;
	cursor: pointer;
}

.form button:hover {
	background: var(--color-primary-dark);
}

.form-error {
	color: var(--color-danger);
	font-size: 0.9rem;
}

.form-hint {
	color: var(--color-muted);
	font-size: 0.9rem;
}

.loading,
.empty {
	color: var(--color-muted);
	text-align: center;
	padding: 1rem 0;
}

.error {
	color: var(--color-danger);
}

.success-text {
	color: var(--color-good);
}

.dashboard {
	display: grid;
	gap: 1rem;
}

.glucose-value {
	font-size: 2.4rem;
	font-weight: 700;
	margin: 0.2rem 0;
}

.glucose-value .unit {
	font-size: 1rem;
	font-weight: 400;
	color: var(--color-muted);
}

.glucose-trend,
.glucose-time {
	margin: 0.15rem 0;
	color: var(--color-muted);
}

.tir-value {
	font-size: 2rem;
	font-weight: 700;
	color: var(--color-good);
	margin: 0.2rem 0;
}

.tir-detail,
.macros-detail,
.iob-detail {
	color: var(--color-muted);
	margin: 0.15rem 0;
}

.iob-value {
	font-size: 2rem;
	font-weight: 700;
	color: var(--color-primary);
	margin: 0.2rem 0;
}

.macros-kcal {
	font-size: 1.6rem;
	font-weight: 700;
	margin: 0.2rem 0;
}

.fab {
	position: fixed;
	right: 1.25rem;
	bottom: 1.25rem;
	width: 56px;
	height: 56px;
	border-radius: 50%;
	background: var(--color-primary);
	color: white;
	display: flex;
	align-items: center;
	justify-content: center;
	font-size: 1.8rem;
	line-height: 1;
	box-shadow: 0 4px 12px rgba(37, 99, 235, 0.4);
	text-decoration: none;
}

.fab:hover {
	background: var(--color-primary-dark);
	text-decoration: none;
}

.section {
	margin-bottom: 1.25rem;
	padding-bottom: 1.25rem;
	border-bottom: 1px solid var(--color-border);
}

.section:last-of-type {
	border-bottom: none;
}

.section label {
	display: block;
	margin-bottom: 0.5rem;
	font-size: 0.9rem;
	color: var(--color-muted);
}

.section input,
.section select {
	display: block;
	width: 100%;
	margin-top: 0.3rem;
	padding: 0.55rem 0.65rem;
	border: 1px solid var(--color-border);
	border-radius: 8px;
	font-size: 1rem;
}

button {
	font: inherit;
	cursor: pointer;
	padding: 0.5rem 0.9rem;
	border: 1px solid var(--color-primary);
	border-radius: 8px;
	background: white;
	color: var(--color-primary);
}

button:hover {
	background: #eff6ff;
}

button:disabled {
	opacity: 0.6;
	cursor: not-allowed;
}

.form-button {
	display: block;
	width: 100%;
	padding: 0.75rem;
	background: var(--color-primary);
	color: white;
	border: none;
	border-radius: 8px;
	font-size: 1rem;
	font-weight: 600;
}

.form-button:hover {
	background: var(--color-primary-dark);
}

.mode-tabs {
	display: flex;
	flex-wrap: wrap;
	gap: 0.5rem;
}

.mode-tabs + .mode-tabs {
	margin-top: 0.5rem;
}

.mode-tab {
	flex: 1;
}

#chart-container {
	min-height: 260px;
}

.chart-tooltip {
	position: absolute;
	display: none;
	pointer-events: none;
	background: #1f2937;
	color: #fff;
	padding: 0.2rem 0.5rem;
	border-radius: 4px;
	font-size: 0.8rem;
	white-space: nowrap;
	z-index: 10;
}

.mode-tab.active {
	background: var(--color-primary);
	color: white;
}

.checkbox-label {
	display: flex;
	align-items: center;
	gap: 0.5rem;
	font-size: 0.95rem;
	color: var(--color-text);
}

.checkbox-label input {
	width: auto;
	margin: 0;
}

.product-row {
	display: flex;
	justify-content: space-between;
	align-items: center;
	gap: 0.75rem;
	padding: 0.6rem 0;
	border-bottom: 1px solid var(--color-border);
}

.product-row:last-child {
	border-bottom: none;
}

.add-row {
	display: flex;
	align-items: center;
	gap: 0.4rem;
	flex-wrap: wrap;
}
/* ± amount stepper (portions/grams) — keyboard-free adjust, keyboard as fallback */
.amount-stepper {
	display: inline-flex;
	align-items: center;
	gap: 4px;
	flex: none;
}
.amount-stepper .amount-step {
	width: 34px;
	height: 40px;
	padding: 0;
	font-size: 1.3rem;
	line-height: 1;
	display: grid;
	place-items: center;
	flex: none;
}
.add-row .amount-stepper .amount-input {
	width: 4rem;
	text-align: center;
	padding-left: 4px;
	padding-right: 4px;
	-moz-appearance: textfield;
	appearance: textfield;
}
.amount-stepper .amount-input::-webkit-inner-spin-button,
.amount-stepper .amount-input::-webkit-outer-spin-button {
	-webkit-appearance: none;
	margin: 0;
}

.product-row-actions {
	display: flex;
	flex-direction: column;
	align-items: flex-end;
	gap: 0.3rem;
}

.save-to-mine-btn {
	font-size: 0.85rem;
}

.amount-input {
	width: 4.5rem;
	padding: 0.4rem;
	border: 1px solid var(--color-border);
	border-radius: 8px;
}

.cart-row {
	display: flex;
	justify-content: space-between;
	align-items: center;
	gap: 0.6rem;
	padding: 0.4rem 0;
}
.cart-name {
	display: flex;
	flex-direction: column;
	gap: 3px;
	min-width: 0;
}
/* per-product КБЖУ, small under the name (secondary to the boxed total below) */
.cart-macros {
	font-size: 0.78rem;
	color: var(--color-muted);
}

.remove-btn {
	border: none;
	background: none;
	color: var(--color-danger);
	padding: 0 0.3rem;
}

.remove-btn:hover {
	background: none;
	text-decoration: underline;
}

.custom-form-fields label {
	margin-bottom: 0.7rem;
}

.tir-bar {
	display: flex;
	height: 20px;
	border-radius: 999px;
	overflow: hidden;
	background: var(--color-border);
}

.tir-bar-segment {
	height: 100%;
}

.tir-bar-segment.tir-below {
	background: var(--color-danger);
}

.tir-bar-segment.tir-in-range {
	background: var(--color-good);
}

.tir-bar-segment.tir-above {
	background: #d97706;
}

.stats-grid {
	display: grid;
	grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
	gap: 0.8rem;
	margin-top: 0.8rem;
	text-align: center;
}

.stats-cards-grid {
	display: grid;
	grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
	gap: 1rem;
}

.stat-card-headline {
	font-size: 1.6rem;
	font-weight: 700;
	margin: 0.2rem 0 0;
}
/* a stat card that launches a report — whole card is a click target */
.stat-card-link { cursor: pointer; transition: border-color 0.12s; }
body.app-dark .stat-card-link:hover { border-color: var(--color-primary); }
.stat-card-titlerow { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.stat-card-titlerow h2 { margin: 0; }
.stat-card-open { flex: none; font-size: 0.78rem; font-weight: 600; color: var(--color-primary); }
.stat-card-headline small {
	font-size: 0.95rem;
	font-weight: 600;
	color: var(--color-muted);
}

.stat-card-chart {
	margin-top: 0.5rem;
}

.stat-card-partial-badge {
	display: inline-block;
	margin-top: 0.35rem;
	font-size: 0.72rem;
	font-weight: 600;
	color: var(--color-muted);
	background: var(--color-bg);
	border: 1px solid var(--color-border);
	border-radius: 999px;
	padding: 0.1rem 0.5rem;
	white-space: nowrap;
}

/* stat-card trend chart — legend (dataviz: ≥2 series always labelled) + tooltip */
.spark-legend {
	display: flex;
	flex-wrap: wrap;
	gap: 0.3rem 0.9rem;
	margin: 0.5rem 0 0.1rem;
	font-size: 0.8rem;
	color: var(--color-muted);
}
.spark-legend span {
	display: inline-flex;
	align-items: center;
	gap: 0.35rem;
}
.spark-legend i {
	width: 10px;
	height: 10px;
	border-radius: 3px;
	flex: none;
}
.spark-wrap {
	position: relative;
}
.spark-tip {
	position: absolute;
	display: none;
	pointer-events: none;
	top: 0;
	transform: translateX(-50%);
	z-index: 6;
	background: #050a12;
	border: 1px solid rgba(255, 255, 255, 0.14);
	border-radius: 8px;
	padding: 5px 8px;
	font-size: 11px;
	line-height: 1.5;
	color: #eef2f8;
	white-space: nowrap;
	box-shadow: 0 8px 24px -8px #000;
}
.spark-tip .st-day {
	font-weight: 700;
	margin-bottom: 2px;
}
.spark-tip .st-row {
	display: block;
}
.spark-tip .st-row i {
	display: inline-block;
	width: 8px;
	height: 8px;
	border-radius: 2px;
	margin-right: 5px;
}

/* ============================================================
   "Сейчас" screen — dark instrument + light sheet (Milestone 13)
   ============================================================ */
:root {
	--gl-lo: #f26d6d;
	--gl-mid: #3ed598;
	--gl-hi: #f5b740;
	--gl-iob: #6e8bff;
	--gl-bolus: #4aa2ff;
	--gl-meal: #f2a93b;
	--gl-basal: #b98cff;
	--gl-forecast: #e26fc4;
	--gl-ink: #0e1522;
	--gl-inkText: #e9eef6;
	--gl-inkMuted: #8b9bb4;
	--gl-axis: #6a7a92;
}

.now-screen {
	max-width: 460px;
	margin: 0 auto;
	padding: 0.75rem;
	display: flex;
	flex-direction: column;
	gap: 0.75rem;
}

.now-instrument {
	background: var(--gl-ink);
	color: var(--gl-inkText);
	border-radius: 16px;
	padding: 14px 10px 8px;
}
.now-hero {
	display: flex;
	align-items: flex-start;
	gap: 12px;
	padding: 0 4px;
}
.now-bg {
	display: flex;
	align-items: baseline;
	gap: 8px;
}
.now-bg-val {
	font-size: 56px;
	font-weight: 700;
	line-height: 0.9;
	letter-spacing: -0.02em;
	font-variant-numeric: tabular-nums;
}
.now-bg-val.empty {
	color: var(--gl-inkMuted);
}
.now-bg-arrow {
	font-size: 40px;
	font-weight: 600;
	opacity: 0.9;
}
.now-bg-sub {
	margin-top: 6px;
	font-size: 12px;
	color: var(--gl-inkMuted);
}
.now-iob {
	margin-left: auto;
	text-align: right;
}
.now-iob-val {
	font-size: 26px;
	font-weight: 700;
	color: var(--gl-iob);
	font-variant-numeric: tabular-nums;
	line-height: 1;
}
.now-iob-lab {
	font-size: 10px;
	text-transform: uppercase;
	letter-spacing: 0.09em;
	color: var(--gl-inkMuted);
	margin-top: 5px;
}

.now-controls {
	display: flex;
	align-items: center;
	gap: 8px;
	margin: 12px 2px 8px;
}
.now-tabs {
	display: inline-flex;
	background: rgba(255, 255, 255, 0.06);
	border-radius: 9px;
	padding: 3px;
}
.now-tabs button {
	border: 0;
	background: transparent;
	color: var(--gl-inkMuted);
	font: inherit;
	font-size: 12.5px;
	font-weight: 600;
	padding: 5px 11px;
	border-radius: 6px;
	cursor: pointer;
	font-variant-numeric: tabular-nums;
}
.now-tabs button.on {
	background: rgba(255, 255, 255, 0.12);
	color: var(--gl-inkText);
}
.now-toggles {
	margin-left: auto;
	display: flex;
	gap: 6px;
}
.now-tg {
	border: 0;
	background: rgba(255, 255, 255, 0.05);
	color: var(--gl-inkMuted);
	font: inherit;
	font-size: 11.5px;
	font-weight: 600;
	padding: 5px 9px;
	border-radius: 7px;
	cursor: pointer;
	display: inline-flex;
	align-items: center;
	gap: 6px;
}
.now-tg .sw {
	width: 8px;
	height: 8px;
	border-radius: 50%;
	background: currentColor;
	opacity: 0.35;
}
.now-tg.on {
	color: var(--gl-inkText);
	background: rgba(255, 255, 255, 0.09);
}
.now-tg.on.iob {
	color: var(--gl-iob);
}
.now-tg.on.fc {
	color: var(--gl-forecast);
}
.now-tg.on .sw {
	opacity: 1;
}

.now-chartbox {
	position: relative;
}
#now-main {
	width: 100%;
	height: 230px;
	display: block;
	cursor: grab;
	touch-action: none;
}
#now-main:active {
	cursor: grabbing;
}
#now-overview {
	width: 100%;
	height: 82px;
	display: block;
	margin-top: 2px;
	cursor: grab;
	touch-action: none;
}
.now-tonow {
	position: absolute;
	right: 6px;
	top: calc(50% - 30px);
	width: 30px;
	height: 30px;
	border-radius: 50%;
	border: 1px solid rgba(255, 255, 255, 0.28);
	background: rgba(18, 28, 44, 0.9);
	color: #eaf0f7;
	font-size: 16px;
	line-height: 1;
	padding: 0;
	cursor: pointer;
	display: none;
	align-items: center;
	justify-content: center;
	z-index: 6;
}
.now-tonow.show {
	display: flex;
}
.now-tip {
	position: absolute;
	pointer-events: none;
	z-index: 5;
	background: #050a12;
	border: 1px solid rgba(255, 255, 255, 0.14);
	border-radius: 9px;
	padding: 7px 9px;
	font-size: 11.5px;
	line-height: 1.5;
	color: #eef2f8;
	box-shadow: 0 8px 24px -8px #000;
	transform: translate(-50%, -115%);
	white-space: nowrap;
	opacity: 0;
	transition: opacity 0.12s;
}
.now-tip.show {
	opacity: 1;
}
.now-tip.below {
	transform: translate(-50%, 15%);
}
.now-tip .h {
	font-weight: 700;
	font-variant-numeric: tabular-nums;
}
.now-tip .r {
	color: #a9b7cd;
}
.now-tip .r b {
	color: #eef2f8;
	font-weight: 600;
}
.gl-chip {
	display: inline-block;
	width: 8px;
	height: 8px;
	border-radius: 2px;
	vertical-align: middle;
	margin-right: 5px;
}

.now-ovlabel {
	display: flex;
	align-items: center;
	justify-content: space-between;
	color: var(--gl-inkMuted);
	font-size: 10px;
	letter-spacing: 0.03em;
	padding: 2px 4px 7px;
}
.now-ovlabel .lg {
	display: inline-flex;
	gap: 11px;
}
.now-ovlabel .lg s {
	text-decoration: none;
	display: inline-flex;
	align-items: center;
	gap: 4px;
}
.now-ovlabel .lg s::before {
	content: "";
	width: 6px;
	height: 6px;
	border-radius: 50%;
	background: var(--c);
}

.now-sheet {
	display: flex;
	flex-direction: column;
	gap: 10px;
}
.now-sec {
	color: var(--color-muted);
	font-size: 11px;
	font-weight: 700;
	text-transform: uppercase;
	letter-spacing: 0.08em;
	margin: 2px 2px 0;
}
.now-tir {
	background: var(--color-card);
	border: 1px solid var(--color-border);
	border-radius: 14px;
	padding: 12px 13px;
}
.now-tir-top {
	display: flex;
	align-items: baseline;
	justify-content: space-between;
}
.now-tir-top .v {
	font-size: 19px;
	font-weight: 700;
	font-variant-numeric: tabular-nums;
}
.now-tir-top .lab {
	color: var(--color-muted);
	font-size: 12px;
}
.now-bar {
	display: flex;
	height: 9px;
	border-radius: 5px;
	overflow: hidden;
	margin-top: 10px;
	background: var(--color-border);
}
.now-bar i {
	display: block;
	height: 100%;
}
.now-barlegend {
	display: flex;
	gap: 14px;
	margin-top: 9px;
	color: var(--color-muted);
	font-size: 11px;
}
.now-barlegend s {
	text-decoration: none;
	display: inline-flex;
	align-items: center;
	gap: 5px;
	font-variant-numeric: tabular-nums;
}
.now-barlegend s::before {
	content: "";
	width: 8px;
	height: 8px;
	border-radius: 2px;
	background: var(--c);
}
.now-cards {
	display: grid;
	grid-template-columns: 1fr 1fr;
	gap: 10px;
}
.now-card {
	background: var(--color-card);
	border: 1px solid var(--color-border);
	border-radius: 14px;
	padding: 11px 13px;
}
.now-card .v {
	font-size: 20px;
	font-weight: 700;
	font-variant-numeric: tabular-nums;
}
.now-card .v small {
	font-size: 12px;
	font-weight: 600;
	color: var(--color-muted);
}
.now-card .l {
	color: var(--color-muted);
	font-size: 11.5px;
	margin-top: 3px;
}

.now-events {
	display: flex;
	flex-direction: column;
	gap: 1px;
	border: 1px solid var(--color-border);
	border-radius: 14px;
	overflow-y: auto;
	max-height: 240px;
	scrollbar-width: thin;
	scrollbar-color: var(--color-border) transparent;
}
.now-events::-webkit-scrollbar {
	width: 8px;
}
.now-events::-webkit-scrollbar-thumb {
	background: var(--color-border);
	border-radius: 8px;
	border: 2px solid var(--color-card);
	background-clip: padding-box;
}
.now-ev {
	display: flex;
	align-items: center;
	gap: 11px;
	padding: 11px 13px;
	background: var(--color-card);
}
.now-ev .ic {
	width: 30px;
	height: 30px;
	border-radius: 9px;
	flex: none;
	display: grid;
	place-items: center;
	font-size: 14px;
}
.now-ev .ic.ins {
	background: rgba(74, 162, 255, 0.16);
}
.now-ev .ic.basal {
	background: rgba(185, 140, 255, 0.18);
}
.now-ev .ic.food {
	background: rgba(242, 169, 59, 0.16);
}
.now-ev .tt {
	font-size: 13.5px;
	font-weight: 600;
}
.now-ev .dd {
	color: var(--color-muted);
	font-size: 12px;
	margin-top: 1px;
}
.now-ev .tm {
	margin-left: auto;
	color: var(--color-muted);
	font-size: 12px;
	font-variant-numeric: tabular-nums;
}

/* F4 additions: zone-tinted hero number (opt-in) + settings checkboxes */
.now-bg-val.zone-lo {
	color: var(--gl-lo);
}
.now-bg-val.zone-mid {
	color: var(--gl-mid);
}
.now-bg-val.zone-hi {
	color: var(--gl-hi);
}
.checkbox-label {
	display: flex;
	align-items: center;
	gap: 0.55rem;
	font-weight: normal;
}
.checkbox-label input[type="checkbox"] {
	width: auto;
	margin: 0;
	flex: none;
}

/* Narrower side margins on phones — give the "Сейчас" chart more width.
   main#app contributes 1.25rem and .now-screen 0.75rem each side (~32px total);
   on narrow screens trim both so the instrument sits close to the edges. */
@media (max-width: 520px) {
	main#app {
		padding-left: 0.5rem;
		padding-right: 0.5rem;
	}
	.now-screen {
		padding-left: 0;
		padding-right: 0;
	}
}

/* ============================================================
   F1 — fixed 100dvh app-shell, only on the "Сейчас" route
   (body.route-now, toggled in app.js). Other routes scroll normally.
   ============================================================ */
body.route-now {
	height: 100vh;
	/* dvh (current visible height), not svh: coming from a scrolled page the
	   browser toolbar may be hidden, making the visible area larger than svh —
	   with svh the fixed bottom nav landed below the shell's box and got clipped
	   by html{overflow:hidden}. dvh matches whatever is actually visible. */
	height: 100dvh;
	overflow: hidden;
	display: flex;
	flex-direction: column;
}
body.route-now .topbar {
	display: none;
}
body.route-now main#app {
	flex: 1 1 auto;
	min-height: 0;
	max-width: none;
	margin: 0;
	padding: 0;
	overflow: hidden;
}
body.route-now .now-screen {
	height: 100%;
	max-width: 480px;
	margin: 0 auto;
	padding: 0;
	gap: 0;
}
body.route-now .now-instrument {
	flex: none;
	border-radius: 0;
}
body.route-now .now-sheet {
	flex: 1 1 auto;
	min-height: 0;
	overflow-y: auto;
	padding: 12px 12px 8px;
	scrollbar-width: thin;
	scrollbar-color: var(--color-border) transparent;
}
body.route-now .now-sheet::-webkit-scrollbar {
	width: 8px;
}
body.route-now .now-sheet::-webkit-scrollbar-thumb {
	background: var(--color-border);
	border-radius: 8px;
	border: 2px solid var(--color-bg);
	background-clip: padding-box;
}

/* Global bottom navigation with a raised centre "+" (mobile app-shell pattern).
   Fixed to the viewport bottom on every authenticated screen; centred and capped
   at the shell width on wider viewports. Always dark (see the --gl-* overrides
   further down) so it reads as one persistent app chrome across light and dark
   screens. */
.now-nav {
	position: fixed;
	bottom: 0;
	left: 0;
	right: 0;
	z-index: 50;
	max-width: 480px;
	margin: 0 auto;
	display: flex;
	border-top: 1px solid var(--color-border);
	background: var(--color-card);
	padding-bottom: env(safe-area-inset-bottom);
}
.now-nav a,
.now-nav button {
	flex: 1;
	text-align: center;
	padding: 8px 2px 10px;
	color: var(--color-muted);
	font-size: 10.5px;
	text-decoration: none;
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 3px;
	background: none;
	border: none;
	cursor: pointer;
	font-family: inherit;
}
.now-nav a:hover,
.now-nav button:hover {
	text-decoration: none;
	background: none;
}
.now-nav a .g,
.now-nav button .g {
	font-size: 17px;
	line-height: 1;
	display: flex;
}
.now-nav .g svg {
	display: block;
}
.now-nav a.on,
.now-nav button.on {
	color: var(--color-primary);
	font-weight: 600;
}
.now-nav a.add {
	flex: 0 0 auto;
	padding: 0 8px;
	justify-content: center;
}
.now-nav a.add .plus {
	width: 46px;
	height: 46px;
	margin-top: -16px;
	border-radius: 50%;
	color: #fff;
	font-size: 29px;
	font-weight: 300;
	line-height: 1;
	display: grid;
	place-items: center;
	background: linear-gradient(150deg, #4d7dea, #2a53bd);
	box-shadow: 0 8px 18px -5px rgba(24, 52, 120, 0.55);
	border: 3px solid var(--color-card);
}
/* Reserve room so fixed-bar doesn't cover content. Scrolling screens already
   have main#app padding-bottom; the fixed 100svh "Сейчас" shell needs its own. */
body.route-now {
	padding-bottom: calc(56px + env(safe-area-inset-bottom));
}
#appnav[hidden] {
	display: none;
}

/* In the fixed shell the whole sheet scrolls, so the events list flows
   naturally (no nested inner scroll). */
body.route-now .now-events {
	max-height: none;
	overflow: visible;
}

/* ============================================================
   Dashboard "Сейчас" — full dark theme (instrument + sheet + nav)
   ============================================================ */
:root {
	--gl-surface: #141c2a;
	--gl-border: #232e40;
	--gl-screen: #0a0f19;
}
body.route-now,
body.route-now main#app {
	background: var(--gl-screen);
}
.now-screen {
	background: var(--gl-screen);
}
.now-sheet {
	color: var(--gl-inkText);
}
.now-sheet .now-sec {
	color: var(--gl-inkMuted);
}
.now-tir,
.now-card {
	background: var(--gl-surface);
	border-color: var(--gl-border);
}
.now-tir-top .lab,
.now-card .l,
.now-card .v small,
.now-barlegend,
.now-barlegend s {
	color: var(--gl-inkMuted);
}
.now-bar {
	background: var(--gl-border);
}
.now-events {
	border-color: var(--gl-border);
}
.now-ev {
	background: var(--gl-surface);
}
.now-ev .dd,
.now-ev .tm {
	color: var(--gl-inkMuted);
}
body.route-now .now-sheet::-webkit-scrollbar-thumb {
	border-color: var(--gl-screen);
}
.now-nav {
	background: var(--gl-ink);
	border-top-color: var(--gl-border);
}
.now-nav a,
.now-nav button {
	color: var(--gl-inkMuted);
}
.now-nav a.on,
.now-nav button.on {
	color: var(--gl-iob);
}
.now-nav a.add .plus {
	border-color: var(--gl-ink);
}
/* The "Ещё" item is a <button>, so `body.app-dark button {color:--color-text}`
   (0,1,2) was overriding the muted nav colour and making it brighter than the
   <a> items. Re-assert the nav colours at higher specificity + transparent bg. */
body.app-dark .now-nav a,
body.app-dark .now-nav button {
	color: var(--gl-inkMuted);
	background: none;
}
body.app-dark .now-nav a.on,
body.app-dark .now-nav button.on {
	color: var(--gl-iob);
}
body.app-dark .now-nav button:hover {
	background: none;
}

/* Mobile fix: the base `body { min-height: 100vh }` forced the shell to the
   LARGE viewport, re-introducing a pannable strip. Pin <html> to the dynamic
   viewport (dvh = currently visible), not svh — svh clipped the fixed bottom
   nav when arriving with the toolbar hidden (see body.route-now above). */
html:has(body.route-now) {
	height: 100dvh;
	overflow: hidden;
}
body.route-now {
	min-height: 0;
}

/* faint exact reading clock-time next to the relative "N мин назад" */
.now-bg-time {
	opacity: 0.55;
	font-variant-numeric: tabular-nums;
}

/* ============================================================
   App-wide dark theme (body.app-dark, set statically in index.html).
   The whole mobile app is dark; redefine the theme tokens so every
   shared .card/.section/input/button component goes dark, then patch
   the few components that hardcode light colours. "Сейчас" (route-now)
   and "Добавить запись" (route-add) layer their specifics on top.
   ============================================================ */
body.app-dark {
	--color-bg: #0a0f19;
	--color-card: #141c2a;
	--color-text: #e9eef6;
	--color-muted: #8b9bb4;
	--color-border: #232e40;
	background: var(--color-bg);
	color: var(--color-text);
}
body.app-dark input,
body.app-dark select,
body.app-dark textarea {
	background: #0e1522;
	color: var(--color-text);
	border-color: var(--color-border);
}
body.app-dark input::placeholder {
	color: var(--color-muted);
}
/* Chrome autofill paints its own light background over our dark inputs; the
   inset box-shadow trick masks it and keeps the text light. */
body.app-dark input:-webkit-autofill,
body.app-dark input:-webkit-autofill:hover,
body.app-dark input:-webkit-autofill:focus {
	-webkit-text-fill-color: var(--color-text);
	-webkit-box-shadow: 0 0 0 1000px #0e1522 inset;
	caret-color: var(--color-text);
}
/* secondary buttons dark; primary / active-tab / link re-asserted below */
body.app-dark button {
	background: #0e1522;
	color: var(--color-text);
	border-color: var(--color-border);
}
body.app-dark button:hover {
	background: #1a2536;
}
body.app-dark button:disabled {
	opacity: 0.5;
}
body.app-dark .form-button {
	background: var(--color-primary);
	color: #fff;
	border: none;
}
body.app-dark .mode-tab.active {
	background: var(--color-primary);
	color: #fff;
}
body.app-dark .link-button {
	background: none;
	border: none;
	color: var(--color-primary);
}
body.app-dark .remove-btn {
	background: none;
	border: none;
	color: var(--color-danger);
}
body.app-dark .remove-btn:hover {
	background: none;
}

/* Add-entry quick-add chips (Milestone 14) + barcode scanner overlay */
.chip-row {
	display: flex;
	gap: 6px;
	overflow-x: auto;
	padding-bottom: 3px;
	scrollbar-width: none;
}
.chip-row::-webkit-scrollbar {
	display: none;
}
.chip-row:empty {
	display: none;
}
.chip-row + .chip-row {
	margin-top: 6px;
}
.chip {
	flex: none;
	white-space: nowrap;
	padding: 0.5rem 0.8rem;
	border-radius: 999px;
	color: var(--color-text);
	font-size: 0.85rem;
	line-height: 1.1;
	cursor: pointer;
	/* kill the default square Android tap-flash — feedback comes from the pill's
	   own :active background below, which follows the rounded shape */
	-webkit-tap-highlight-color: transparent;
}
body.route-add .chip:active {
	background: #2c3f60;
}
/* distinct "food chip" surface — lighter/tinted so it reads apart from the flat
   dark control buttons (Изменить / Укол без еды). Scoped under body.route-add so
   it wins over `body.route-add button`(0,1,2), which otherwise painted plain
   `.chip`(0,1,0) the same #0e1522 as the control buttons. */
body.route-add .chip {
	background: #243450;
	border-color: #37507a;
}
/* hover only on real pointers — on touch it sticks after a tap and looks like a
   confusing "selected" highlight on the last chip */
@media (hover: hover) {
	body.route-add .chip:hover {
		background: #2c3f60;
	}
}
.chip .chip-g {
	color: var(--color-muted);
	font-size: 0.78rem;
}
/* amber "my meals" chip — scoped to out-specify body.route-add .chip(0,2,1) too */
body.route-add .chip-meal {
	border-color: #3a2f18;
	background: #241d10;
	color: var(--gl-meal);
	font-weight: 600;
}

/* Template chip is a two-zone pill: tap the label to add, tap the ✎ to manage.
   The <span> keeps the pill look; the two inner <button>s are transparent (reset
   scoped under body.route-add to beat `body.route-add button`'s dark fill). */
.chip-tpl {
	display: inline-flex;
	align-items: stretch;
	padding: 0;
	overflow: hidden;
}
body.route-add .chip-tpl button {
	background: none;
	border: none;
	color: inherit;
	font: inherit;
	font-weight: 600;
	cursor: pointer;
	border-radius: 0;
}
.chip-tpl .chip-tpl-main {
	padding: 0.5rem 0.55rem 0.5rem 0.8rem;
}
.chip-tpl .chip-tpl-edit {
	display: grid;
	place-items: center;
	padding: 0 0.6rem;
	border-left: 1px solid #3a2f18 !important;
	color: var(--color-muted);
}
body.route-add .chip-tpl button:active {
	background: #2c220f;
}

/* Bottom-sheet modal (manage a saved meal: rename / delete) */
.sheet-overlay {
	position: fixed;
	inset: 0;
	z-index: 1100;
	background: rgba(0, 0, 0, 0.55);
	display: flex;
	align-items: flex-end;
	justify-content: center;
}
.sheet {
	/* Sheets pair with the always-dark bottom bar / dark task screens, so pin
	   dark tokens here — children (links, inputs) inherit them regardless of the
	   screen the sheet was opened over. */
	--color-card: #141c2a;
	--color-bg: #0a0f19;
	--color-text: #e9eef6;
	--color-border: #232e40;
	--color-muted: #8b9bb4;
	width: 100%;
	max-width: 640px;
	background: var(--color-card);
	color: var(--color-text);
	border-radius: 16px 16px 0 0;
	border: 1px solid var(--color-border);
	padding: 1.1rem 1.1rem 1.5rem;
	display: flex;
	flex-direction: column;
	gap: 0.7rem;
}
.sheet-title {
	margin: 0;
	font-size: 1.05rem;
}
.sheet-field {
	display: flex;
	flex-direction: column;
	gap: 0.3rem;
	font-size: 0.85rem;
	color: var(--color-muted);
}
.sheet-field input {
	padding: 0.7rem 0.8rem;
	font-size: 1.05rem;
	background: #0e1522;
	color: var(--color-text);
	border: 1px solid var(--color-border);
	border-radius: 8px;
}
.sheet .form-button {
	padding: 0.7rem;
	background: var(--color-primary);
	color: #fff;
	border: none;
	border-radius: 8px;
	font-size: 1rem;
	font-weight: 600;
	cursor: pointer;
}
.sheet-link {
	text-align: center;
	color: var(--color-primary);
	padding: 0.5rem;
	text-decoration: none;
}
.sheet-delete {
	padding: 0.7rem;
	background: none;
	border: 1px solid var(--color-danger);
	color: var(--color-danger);
	border-radius: 8px;
	font-size: 0.95rem;
	cursor: pointer;
}
.sheet-cancel {
	text-align: center;
	padding: 0.4rem;
}
/* "Ещё" menu entries — raised surface so they read clearly on the dark sheet */
.more-link {
	display: block;
	padding: 0.85rem 0.8rem;
	background: #1e2a3d;
	border: 1px solid #33455f;
	border-radius: 8px;
	color: var(--color-text);
	text-decoration: none;
	font-size: 1rem;
}
.more-link:hover {
	background: #263650;
	text-decoration: none;
}
/* <button class="more-link"> (mode picker) needs to outweigh the global
   `body.app-dark button` rule so it renders like the <a> menu items */
body.app-dark .sheet button.more-link {
	width: 100%;
	text-align: left;
	background: #1e2a3d;
	border: 1px solid #33455f;
	color: var(--color-text);
	font: inherit;
}
body.app-dark .sheet button.more-link:hover {
	background: #263650;
}
/* "Выйти" — muted red on the same raised surface, not the vivid danger red */
.sheet .more-logout {
	background: #1e2a3d;
	border-color: #33455f;
	color: #d98b8b;
}
.sheet .more-logout:hover {
	background: #263650;
}
.scan-overlay {
	position: fixed;
	inset: 0;
	z-index: 1000;
	background: #000;
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	gap: 1rem;
}
.scan-overlay video {
	width: 100%;
	max-height: 70vh;
	object-fit: cover;
}
.scan-hint {
	color: #fff;
	margin: 0;
}
.scan-cancel {
	background: #fff;
	color: #111;
	border: none;
	padding: 0.6rem 1.4rem;
	border-radius: 8px;
	font-size: 1rem;
}

/* "Часто ем" — two-row horizontally-scrolling grid (shows more at once, still
   compact); templates stay a single scroll row. */
#frequent-chips {
	display: grid;
	grid-auto-flow: column;
	grid-template-rows: repeat(2, auto);
	grid-auto-columns: max-content;
}

/* Bolus dose field: editable dose with −/+ stepper, assumptions, breakdown */
.dose-label {
	display: block;
	font-size: 0.82rem;
	color: var(--color-muted);
	margin-bottom: 0.35rem;
}
.dose-stepper {
	display: flex;
	align-items: center;
	gap: 8px;
}
.dose-step {
	width: 40px;
	height: 48px;
	padding: 0;
	font-size: 1.4rem;
	line-height: 1;
	display: grid;
	place-items: center;
	flex: none;
}
#confirmed-dose,
#standalone-confirmed-dose,
#standalone-basal-units,
#activity-duration,
#quick-carbs-input {
	width: 5rem;
	margin: 0;
	padding: 0.3rem;
	font-size: 1.6rem;
	font-weight: 800;
	text-align: center;
	font-variant-numeric: tabular-nums;
}
/* hide number spinners on the big steppers (they'd eat width / clash on dark) */
#activity-duration::-webkit-inner-spin-button,
#activity-duration::-webkit-outer-spin-button,
#quick-carbs-input::-webkit-inner-spin-button,
#quick-carbs-input::-webkit-outer-spin-button {
	-webkit-appearance: none;
	margin: 0;
}
#quick-carbs-input {
	-moz-appearance: textfield;
	appearance: textfield;
}
#activity-duration {
	-moz-appearance: textfield;
	appearance: textfield;
}
.dose-calcnote {
	margin: 0.6rem 0 0;
	font-size: 0.85rem;
	color: var(--color-muted);
}
.dose-calcnote b {
	color: var(--color-text);
}
.dose-why {
	margin-top: 0.7rem;
}
.dose-why summary {
	cursor: pointer;
	color: #8fa3bf;
	font-size: 0.85rem;
}
.dose-breakdown {
	margin: 0.5rem 0;
}
.bd-table {
	width: 100%;
	border-collapse: collapse;
	font-size: 0.85rem;
}
.bd-table td {
	padding: 2px 0;
	color: var(--color-muted);
}
.bd-table td.bd-v {
	text-align: right;
	color: var(--color-text);
	font-variant-numeric: tabular-nums;
}
.bd-table tr.bd-total td {
	color: var(--color-text);
	font-weight: 600;
	padding-top: 5px;
}

/* Add/edit product rows: fixed-width amount field so values line up, and a
   content-width unit select (overrides the base `.section input/select {
   width:100% }`, which otherwise made the flex row fight and clip). */
.add-row .amount-input {
	width: 4.5rem;
	flex: 0 0 auto;
	margin: 0;
}
.add-row .unit-select,
.add-row .cart-edit-unit {
	width: auto;
	flex: 0 1 auto;
	min-width: 3rem;
	margin: 0;
}

/* compact time row ("Сейчас · HH:MM · изменить") + inline flat button icons */
.compact-time {
	display: flex;
	align-items: center;
	gap: 8px;
	color: var(--color-muted);
	font-size: 0.92rem;
	margin-bottom: 0.5rem;
}
.btn-ic {
	display: inline-flex;
	vertical-align: -3px;
	margin-right: 5px;
}

/* the `hidden` attribute must always win — base `.section label{display:block}`
   was overriding it (e.g. the collapsed time picker showed anyway) */
[hidden] {
	display: none !important;
}
/* macro readout: each value boxed for readability ([30]У [20]Б [10]Ж),
   carbs box brighter since it drives the bolus. */
.mbox {
	display: inline-block;
	min-width: 1.5em;
	padding: 1px 5px;
	text-align: center;
	border: 1px solid var(--color-border);
	border-radius: 6px;
	font-weight: 700;
	color: var(--color-text);
	font-variant-numeric: tabular-nums;
}
.mbox-c {
	border-color: #4aa2ff;
	color: #cfe4ff;
}
.ml {
	color: var(--color-muted);
	font-size: 0.82em;
	font-weight: 600;
	margin: 0 0.7em 0 2px;
}
.ml:last-child {
	margin-right: 0;
}

/* unified search field with an inline scan icon + the toggle/custom subrow */
.searchwrap {
	position: relative;
	margin-top: 0.3rem;
}
/* Taller, framed search field — the visual anchor of the screen. Scoped under
   body.route-add so its border wins over `body.route-add input`(0,1,2). */
body.route-add .searchwrap input {
	margin-top: 0;
	padding: 0.85rem 3rem 0.85rem 0.9rem;
	font-size: 1.05rem;
	border: 2px solid rgba(47, 111, 230, 0.55);
	border-radius: 10px;
}
body.route-add .searchwrap input:focus {
	outline: none;
	border-color: var(--color-primary);
	box-shadow: 0 0 0 3px rgba(47, 111, 230, 0.2);
}
/* uppercase section-style caption over the search field (matches the mock) */
#search-label {
	text-transform: uppercase;
	letter-spacing: 0.05em;
	font-weight: 700;
	font-size: 0.72rem;
}
.search-scan {
	position: absolute;
	right: 5px;
	top: 50%;
	transform: translateY(-50%);
	width: 36px;
	height: 36px;
	padding: 0;
	display: grid;
	place-items: center;
}
.subrow {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 12px;
	flex-wrap: wrap;
	margin-top: 10px;
}

/* Checkbox + its text must stay on one line — base `.section label{display:block}`
   (0,1,1) was beating `.checkbox-label`(0,1,0), so the box floated above the text.
   `.section .checkbox-label` (0,2,0) wins it back. */
.section .checkbox-label {
	display: flex;
	align-items: center;
	gap: 0.5rem;
	margin-bottom: 0;
}
.subrow .checkbox-label {
	color: var(--color-muted);
	font-size: 0.85rem;
}

/* Tighter vertical rhythm on the add-entry screen — the default 1.25rem
   margin+padding per section left big empty gaps on the phone. */
body.route-add .section {
	margin-bottom: 0.85rem;
	padding-bottom: 0.85rem;
}
body.route-add .card {
	padding: 1rem 0.9rem;
}
body.route-add #cart-totals.empty {
	padding: 0.3rem 0;
	margin: 0.3rem 0 0;
}
/* the summed total, set apart from the item list by a rule above it */
#cart-totals:not(.empty) {
	margin-top: 0.6rem;
	padding-top: 0.7rem;
	border-top: 1px solid var(--color-border);
	font-size: 1.02rem;
}

/* Bolus block gets a framed card so it reads as a distinct, confirmable unit
   (matches the design mock's bordered .bolus). */
#bolus-form:not([hidden]) {
	background: #0e1522;
	border: 1px solid var(--color-border);
	border-radius: 12px;
	padding: 12px 13px;
	margin-top: 10px;
}
/* The dose input inside the framed card needs to stand out from the same-color
   card background. */
#bolus-form #confirmed-dose {
	background: #141c2a;
}

/* Compact meta row: "Сейчас · HH:MM · изменить" on the left, a content-width
   category dropdown on the right (was a full-width select). */
.meta-row {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 10px;
}
.meta-row .compact-time {
	margin-bottom: 0;
}
.cat-pick {
	display: flex;
	align-items: center;
	gap: 6px;
	flex: 0 0 auto;
}
.cat-icon {
	display: inline-flex;
	color: var(--color-muted);
}
.cat-icon svg {
	display: block;
}
.meal-details .cat-select {
	width: auto;
	margin: 0;
	flex: 0 0 auto;
	padding: 0.4rem 0.6rem;
	font-size: 0.9rem;
}

/* "← Отмена" — centered, a touch larger than the old form-hint size */
.cancel-row {
	text-align: center;
	margin-top: 1rem;
}
.cancel-row a {
	font-size: 1rem;
	color: var(--color-primary);
}

/* "Мои блюда" header over the template chips, with the link to /meal-templates */
.quick-head {
	display: flex;
	justify-content: space-between;
	align-items: center;
	margin: 0.7rem 0 0.4rem;
	font-size: 0.72rem;
	color: var(--color-muted);
	text-transform: uppercase;
	letter-spacing: 0.05em;
	font-weight: 700;
}
.quick-head .link-button {
	text-transform: none;
	letter-spacing: 0;
	font-weight: 500;
	font-size: 0.85rem;
}

/* ============================================================
   /meal-templates management screen (default light theme)
   ============================================================ */
.tpl-card {
	border: 1px solid var(--color-border);
	border-radius: var(--radius);
	padding: 0.9rem;
	margin-bottom: 1rem;
}
.tpl-card input {
	font: inherit;
	padding: 0.45rem 0.55rem;
	border: 1px solid var(--color-border);
	border-radius: 8px;
	background: var(--color-bg);
	color: var(--color-text);
}
.tpl-name {
	width: 100%;
	font-size: 1.05rem;
	font-weight: 600;
}
.tpl-items {
	margin: 0.7rem 0 0;
}
.tpl-item {
	display: flex;
	align-items: center;
	gap: 0.6rem;
	padding: 0.4rem 0;
	border-bottom: 1px solid var(--color-border);
}
.tpl-item:last-child {
	border-bottom: none;
}
.tpl-item-name {
	flex: 1;
	min-width: 0;
}
.tpl-item-amount {
	color: var(--color-muted);
	white-space: nowrap;
	font-size: 0.9rem;
}
.tpl-grams {
	width: 4rem;
	text-align: right;
}
.tpl-totals {
	margin: 0.6rem 0 0.7rem;
	font-variant-numeric: tabular-nums;
}
.tpl-search {
	width: 100%;
}
.tpl-results {
	display: flex;
	flex-direction: column;
	gap: 3px;
	margin-top: 5px;
}
.tpl-result {
	text-align: left;
	background: var(--color-bg);
	border: 1px solid var(--color-border);
	color: var(--color-text);
	border-radius: 6px;
	padding: 0.45rem 0.6rem;
}
.tpl-result:hover {
	background: #1a2536;
}
.tpl-result small {
	color: var(--color-muted);
}
.tpl-actions {
	display: flex;
	justify-content: space-between;
	align-items: center;
	gap: 0.8rem;
	margin-top: 0.9rem;
}
.tpl-actions .form-button {
	width: auto;
	flex: 0 0 auto;
	padding: 0.55rem 1.2rem;
}
.tpl-delete {
	background: none;
	border: none;
	color: var(--color-danger);
	padding: 0.4rem;
}
.tpl-delete:hover {
	background: none;
	text-decoration: underline;
}

/* ============================================================
   Diary screen (/diary) — history review, dark. Reuses the "Сейчас" chart
   engine (.now-chartbox/.now-tip) + IOB/forecast toggles (.now-tg).
   ============================================================ */
.diary h1 { font-size: 1.5rem; margin: 0 0 12px; }
.diary .daterow { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.diary .daterow .dlab { flex: 1; text-align: center; font-size: 1.05rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.diary .daterow button { width: 42px; height: 38px; display: grid; place-items: center; font-size: 1.2rem;
	background: var(--gl-ink); color: var(--color-text); border: 1px solid var(--color-border); border-radius: 9px; cursor: pointer; }
.diary .daterow button:disabled { opacity: 0.35; cursor: default; }
.diary .periods { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; margin-bottom: 14px; }
.diary .periods::-webkit-scrollbar { display: none; }
.diary .periods button { flex: none; padding: 0.42rem 0.7rem; border-radius: 8px; background: var(--gl-ink); color: var(--color-text);
	border: 1px solid var(--color-border); font-size: 0.85rem; cursor: pointer; white-space: nowrap; }
.diary .periods button.on { background: var(--color-primary); border-color: var(--color-primary); color: #fff; font-weight: 600; }
.d-chartcard { background: var(--gl-surface); border: 1px solid var(--color-border); border-radius: 14px; padding: 10px 10px 8px; }
.d-chart-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 6px; }
.d-legend { display: flex; gap: 11px; font-size: 0.72rem; color: var(--color-muted); }
.d-legend s { text-decoration: none; display: inline-flex; align-items: center; gap: 4px; }
.d-legend s::before { content: ""; width: 9px; height: 9px; border-radius: 2px; background: var(--c); }
#d-chart { width: 100%; height: 230px; display: block; touch-action: none; cursor: grab; }
#d-chart:active { cursor: grabbing; }
.d-summary { display: flex; align-items: stretch; gap: 10px; margin-top: 8px; }
.d-tir { flex: 1; }
.d-bar { height: 9px; border-radius: 5px; overflow: hidden; display: flex; background: var(--color-border); }
.d-bar i { display: block; height: 100%; }
.d-tirlab { margin-top: 5px; font-size: 0.75rem; color: var(--color-muted); }
.d-tirlab b { color: var(--gl-mid); }
.d-stat { text-align: right; }
.d-stat .v { font-size: 1rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.d-stat .l { font-size: 0.68rem; color: var(--color-muted); text-transform: uppercase; letter-spacing: 0.04em; }
.d-sec { font-size: 0.72rem; color: var(--color-muted); font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; margin: 16px 0 8px; }
.d-typefilter { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; margin: 0 0 12px; }
.d-typefilter::-webkit-scrollbar { display: none; }
.d-typefilter button { flex: none; padding: 0.3rem 0.62rem; border-radius: 999px; background: var(--gl-ink); color: var(--color-muted);
	border: 1px solid var(--color-border); font-size: 0.78rem; cursor: pointer; white-space: nowrap; }
.d-typefilter button.on { background: var(--color-primary); border-color: var(--color-primary); color: #fff; font-weight: 600; }
.d-loadmore { display: flex; justify-content: center; margin: 2px 0 10px; }
.d-loadmore button { padding: 0.5rem 1.2rem; border-radius: 9px; background: var(--gl-surface); color: var(--color-text);
	border: 1px solid var(--color-border); font-size: 0.85rem; cursor: pointer; }
.d-loadmore button:hover { border-color: #31435e; }
.d-loadmore button:disabled { opacity: 0.6; cursor: default; }
.d-ev { display: flex; gap: 10px; background: var(--gl-surface); border: 1px solid var(--color-border); border-radius: 11px;
	padding: 10px 11px; margin-bottom: 8px; align-items: flex-start; cursor: pointer; }
.d-ev:hover { border-color: #31435e; }
.d-ic { flex: none; width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center; margin-top: 1px; font-size: 16px; }
.d-ev.meal .d-ic { background: rgba(242, 169, 59, 0.14); }
.d-ev.treatment .d-ic { background: rgba(110, 139, 255, 0.14); }
.d-body { flex: 1; min-width: 0; }
.d-tt { display: flex; align-items: baseline; gap: 8px; }
.d-tm { font-size: 0.8rem; color: var(--color-muted); font-variant-numeric: tabular-nums; }
.d-nm { font-weight: 600; }
.d-dose { margin-left: auto; font-weight: 700; color: var(--gl-bolus); font-variant-numeric: tabular-nums; white-space: nowrap; }
.d-dose.basal { color: var(--gl-basal); }
.d-det { color: var(--color-muted); font-size: 0.82rem; margin-top: 3px; line-height: 1.4; }
.d-mac { margin-top: 5px; font-size: 0.78rem; display: flex; align-items: center; gap: 8px; }
.d-bolusbadge { display: inline-flex; align-items: center; gap: 5px; margin-left: auto; padding: 2px 10px; border-radius: 999px;
	background: rgba(74, 162, 255, 0.16); border: 1px solid rgba(74, 162, 255, 0.5); color: #bcd8ff;
	font-size: 0.92rem; font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; line-height: 1.35; }
.d-bolusbadge svg { display: block; width: 13px; height: 13px; }
.d-detrow { display: flex; align-items: center; gap: 8px; margin-top: 4px; }
.d-detrow .d-det { margin-top: 0; }
.d-actions { flex: none; align-self: center; display: flex; align-items: center; justify-content: flex-end; gap: 2px; width: 48px; }
.d-chev { color: #3a4c68; font-size: 1.3rem; line-height: 1; }
/* .d-actions specificity (0,2,0) beats body.app-dark button (0,1,2) so this
   works on both /diary and the "Сейчас" sheet (neither needs the .diary scope) */
.d-actions .d-qdel { background: none; border: none; color: #d98b8b; cursor: pointer; padding: 6px; display: grid; place-items: center; }
.d-actions .d-qdel:hover { background: none; color: var(--gl-lo); }
.d-qdel svg { display: block; }
.d-evday { font-size: 0.72rem; color: var(--color-muted); font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; margin: 14px 0 8px; }
.d-bolusbadge.basal { background: rgba(185, 140, 255, 0.16); border-color: rgba(185, 140, 255, 0.5); color: #d6c2ff; }
/* activity feed card — green family (distinct from insulin blue/purple) */
.d-ev.activity .d-ic { background: rgba(62, 213, 152, 0.14); }
.d-actbadge { display: inline-flex; align-items: center; margin-left: auto; padding: 2px 10px; border-radius: 999px;
	background: rgba(62, 213, 152, 0.16); border: 1px solid rgba(62, 213, 152, 0.5); color: #bff0d8;
	font-size: 0.92rem; font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
/* note feed card — neutral slate icon; attached-note line slightly dimmer */
.d-ev.note .d-ic { background: rgba(139, 155, 180, 0.16); }
.d-note { opacity: 0.92; }
/* health-metric feed card — teal tint, distinct from the others */
.d-ev.measurement .d-ic { background: rgba(56, 189, 208, 0.16); }
/* blood-pressure entry: three stacked number fields */
.bp-row label { margin-bottom: 0.7rem; }
/* textareas (notes) — full width + tidy, matching inputs (the .section input
   width rule doesn't cover textarea, so they rendered narrow/ragged) */
.section textarea {
	display: block;
	width: 100%;
	margin-top: 0.3rem;
	padding: 0.55rem 0.65rem;
	border: 1px solid var(--color-border);
	border-radius: 8px;
	font: inherit;
	resize: vertical;
	min-height: 2.6rem;
}
/* Optional note under a spoiler in the meal/injection forms — collapsed by
   default (almost never needed), auto-opened when editing a record that
   already has a note (the `open` attribute is set inline in that case). */
.opt-note {
	margin-top: 0.3rem;
}
.opt-note > summary {
	cursor: pointer;
	list-style: none;
	display: inline-flex;
	align-items: center;
	gap: 0.35rem;
	padding: 0.2rem 0;
	color: var(--color-muted);
	font-size: 0.9rem;
}
.opt-note > summary::-webkit-details-marker {
	display: none;
}
.opt-note-ic {
	flex: none;
}
.opt-note[open] > summary {
	margin-bottom: 0.2rem;
}
/* night-hours row in Settings — two compact number inputs inline ("Ночь с [0] до [6] ч") */
.night-range {
	display: flex;
	align-items: center;
	gap: 0.5rem;
	flex-wrap: wrap;
	margin-bottom: 0.5rem;
}
.night-range label {
	display: inline-flex;
	align-items: center;
	gap: 0.4rem;
	margin: 0;
}
.night-range input[type="number"] {
	width: 4rem;
	margin-top: 0;
	text-align: center;
}
.night-sep {
	color: var(--color-muted);
}
/* delete button on the add-entry edit screen — only way to remove a past record
   (quick-delete lives only on the newest card). Destructive, subdued outline so
   it reads clearly below the primary "Сохранить изменения". */
/* selector carries body.app-dark so it outweighs the global `body.app-dark
   button` rule (0,1,2), which would otherwise recolour the text light */
body.app-dark .delete-entry-btn {
	display: block;
	width: 100%;
	margin-top: 0.6rem;
	padding: 0.7rem;
	background: #1e2a3d;
	border: 1px solid #33455f;
	color: #d98b8b;
	border-radius: 8px;
	font-size: 0.95rem;
	font-weight: 600;
}
body.app-dark .delete-entry-btn:hover {
	background: #263650;
}
/* Settings → "Данные" link-button (navigates to the Trash screen) */
body.app-dark .settings-link-btn {
	display: block;
	padding: 0.7rem 0.8rem;
	background: #1e2a3d;
	border: 1px solid #33455f;
	border-radius: 8px;
	color: var(--color-text);
	text-decoration: none;
}
body.app-dark .settings-link-btn:hover {
	background: #263650;
	text-decoration: none;
}

/* Trash screen — deleted records with a per-row restore */
.trash-item {
	display: flex;
	align-items: center;
	gap: 0.7rem;
	padding: 0.6rem 0;
	border-bottom: 1px solid var(--color-border);
}
.trash-item:last-child {
	border-bottom: none;
}
.trash-item .d-ic {
	font-size: 1.1rem;
	flex: none;
}
.trash-body {
	flex: 1;
	min-width: 0;
}
.trash-sum {
	font-size: 0.92rem;
}
.trash-when {
	color: var(--color-muted);
	font-size: 0.8rem;
	margin-top: 0.15rem;
}
body.app-dark .trash-restore {
	flex: none;
	padding: 0.4rem 0.7rem;
	font-size: 0.85rem;
	background: #1e2a3d;
	border: 1px solid #33455f;
	color: #9fd3b0;
	border-radius: 8px;
}
body.app-dark .trash-restore:hover {
	background: #263650;
}
/* Basal reminder times editor (Settings) — rows of a time input + remove */
.btime-row {
	display: flex;
	align-items: center;
	gap: 0.5rem;
	margin-bottom: 0.4rem;
}
.btime-row input[type="time"] {
	width: auto;
	margin-top: 0;
}
body.app-dark .btime-del {
	flex: none;
	width: 34px;
	height: 34px;
	padding: 0;
	font-size: 1.2rem;
	line-height: 1;
	background: #1e2a3d;
	border: 1px solid #33455f;
	color: #d98b8b;
	border-radius: 8px;
}

/* Centered modal (basal reminder) */
.modal-overlay {
	position: fixed;
	inset: 0;
	z-index: 60;
	display: flex;
	align-items: center;
	justify-content: center;
	padding: 1.25rem;
	background: rgba(0, 0, 0, 0.55);
}
.modal-card {
	width: 100%;
	max-width: 360px;
	background: #131b2a;
	border: 1px solid #2a3a55;
	border-radius: 14px;
	padding: 1.25rem;
	box-shadow: 0 18px 50px -12px #000;
}
.modal-card h3 {
	margin: 0 0 0.4rem;
	font-size: 1.1rem;
}
.modal-card p {
	margin: 0 0 1rem;
	color: #c7d2e2;
	font-size: 0.95rem;
}
.modal-card .form-button {
	margin-bottom: 0.5rem;
}
body.app-dark .modal-card .br-secondary {
	display: block;
	width: 100%;
	margin-top: 0.4rem;
	padding: 0.6rem;
	background: #1e2a3d;
	border: 1px solid #33455f;
	color: var(--color-text);
	border-radius: 8px;
	font-size: 0.95rem;
}
body.app-dark .modal-card .br-secondary:hover {
	background: #263650;
}
/* protein split-bolus toggle in the meal bolus form */
.protein-split {
	margin: 0.4rem 0 0.2rem;
}
.protein-split .checkbox-label {
	font-size: 0.92rem;
}
.protein-split .form-hint {
	margin-top: 0.25rem;
}
/* Period report (for the endocrinologist) — clean rows + print stylesheet */
.report-actions {
	display: flex;
	flex-wrap: wrap;
	justify-content: space-between;
	align-items: center;
	gap: 0.6rem;
	margin-bottom: 1rem;
}
.report-periods {
	display: flex;
	flex-wrap: wrap;
	gap: 0.4rem;
}
/* Period reports («Инсулин по дням», «Углеводы по дням») — shared KPI tiles,
   legend/caption and per-day bar chart styles */
.ri-kpis { display: flex; gap: 10px; margin: 14px 0 6px; }
.ri-kpis.sub { margin: 4px 0 12px; }
.ri-kpi { flex: 1; background: var(--gl-surface); border: 1px solid var(--color-border); border-radius: 12px; padding: 11px 8px; text-align: center; }
.ri-kpi[data-filter] { cursor: pointer; transition: border-color 0.12s, background 0.12s; }
.ri-kpi[data-filter]:hover { border-color: #31435e; }
.ri-kpi[data-filter].on { border-color: var(--color-primary); background: rgba(57, 135, 229, 0.12); }
.ri-filterhint { margin: 2px 0 6px; }
.ri-kpi .ri-v { font-size: 1.15rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.ri-kpi.big .ri-v { font-size: 1.7rem; }
.ri-kpi .ri-l { font-size: 0.68rem; color: var(--color-muted); margin-top: 3px; }
.ri-legend { display: flex; flex-wrap: wrap; gap: 6px 14px; justify-content: center; font-size: 0.75rem; color: var(--color-muted); margin: 8px 0 2px; }
.ri-legend span { display: inline-flex; align-items: center; }
.ri-legend i, .bars-tip-row i { display: inline-block; width: 9px; height: 9px; border-radius: 2px; margin-right: 5px; }
.ri-chart { position: relative; margin: 6px 0 4px; }
.bars-svg { display: block; }
.bars-grid { stroke: rgba(255, 255, 255, 0.08); stroke-width: 1; }
.bars-axlab { fill: #8b9bb4; font: 10px system-ui, sans-serif; }
.bars-vallab { font: 700 10px system-ui, sans-serif; }
.bars-tip { position: absolute; top: 2px; transform: translateX(-50%); background: #0e1522; border: 1px solid var(--color-border);
	border-radius: 8px; padding: 7px 9px; font-size: 0.75rem; color: var(--color-text); pointer-events: none; white-space: nowrap; z-index: 5; box-shadow: 0 4px 14px rgba(0, 0, 0, 0.4); }
.bars-tip-day { font-weight: 700; margin-bottom: 4px; }
.bars-tip-row { display: flex; align-items: center; }
.bars-tip-row b { margin-left: 14px; font-variant-numeric: tabular-nums; }
.bars-tip-row.total { border-top: 1px solid var(--color-border); margin-top: 4px; padding-top: 4px; justify-content: space-between; }
.bars-tip-row.total b { margin-left: 10px; }
body.app-dark .report-periods button {
	padding: 0.35rem 0.7rem;
	font-size: 0.9rem;
	background: #1e2a3d;
	border: 1px solid #33455f;
	color: var(--color-text);
	border-radius: 8px;
}
body.app-dark .report-periods button.on {
	background: var(--color-primary);
	border-color: var(--color-primary);
	color: #fff;
}
.report-export {
	display: flex;
	gap: 0.4rem;
}
body.app-dark .report-export button {
	padding: 0.35rem 0.7rem;
	font-size: 0.9rem;
	background: #1e2a3d;
	border: 1px solid #33455f;
	color: var(--color-text);
	border-radius: 8px;
}
.report-title {
	margin: 0.2rem 0 0.1rem;
	font-size: 1.4rem;
}
.report-sub {
	color: var(--color-muted);
	font-size: 0.9rem;
	margin: 0 0 1rem;
}
.report-card h2 {
	margin-top: 1.25rem;
}
.report-row {
	display: flex;
	justify-content: space-between;
	gap: 1rem;
	padding: 0.4rem 0;
	border-bottom: 1px solid var(--color-border);
	font-size: 0.95rem;
}
.report-row:last-child {
	border-bottom: none;
}
.report-strong {
	font-weight: 700;
}
.report-tir {
	margin: 0.6rem 0;
}

@media print {
	/* Print on white for the doctor: light, ink-friendly, no chrome. */
	#appnav,
	.report-actions,
	.fab {
		display: none !important;
	}
	body.app-dark,
	body.app-dark .card.report-card {
		background: #fff !important;
		color: #000 !important;
	}
	body.app-dark .report-card,
	.report-card {
		border: none;
		box-shadow: none;
		max-width: 100%;
	}
	.report-sub,
	.form-hint {
		color: #444 !important;
	}
	.report-row {
		border-bottom: 1px solid #ccc;
	}
	main#app {
		padding: 0;
	}
}
/* Analytics custom date-range panel (period chip "Свой") */
.ana-custom {
	display: flex;
	align-items: center;
	gap: 0.5rem;
	flex-wrap: wrap;
	margin: 0.6rem 0;
}
.ana-custom input[type="date"] {
	width: auto;
	margin-top: 0;
}
body.app-dark #ana-apply {
	padding: 0.4rem 0.8rem;
	background: var(--color-primary);
	border: 1px solid var(--color-primary);
	color: #fff;
	border-radius: 8px;
}
/* Analytics period chips reuse .report-periods; add the .on active state under app-dark
   (report-periods .on already styled, but analytics uses it too — shared) */
/* Push notifications toggle in Settings */
.push-block {
	margin: 0.5rem 0;
}
body.app-dark #push-toggle-btn,
body.app-dark #push-test-btn {
	display: block;
	width: 100%;
	margin-top: 0.4rem;
	padding: 0.55rem 0.9rem;
	background: #1e2a3d;
	border: 1px solid #33455f;
	color: var(--color-text);
	border-radius: 8px;
	font-size: 0.92rem;
}
body.app-dark #push-toggle-btn[data-on="1"] {
	color: #d98b8b;
}
/* 5-zone AGP glucose breakdown (Аналитика/Отчёт) */
.tir-bar-5 .tir-bar-segment {
	border-radius: 0;
}
.zone-list {
	margin: 0.5rem 0 0.3rem;
}
.zone-row {
	display: flex;
	align-items: center;
	gap: 0.6rem;
	padding: 0.22rem 0;
	font-size: 0.92rem;
}
.zone-row > span:first-child {
	display: inline-flex;
	align-items: center;
	gap: 0.4rem;
	flex: 1;
}
.zone-row i {
	width: 10px;
	height: 10px;
	border-radius: 3px;
	flex: none;
}
.zone-range {
	color: var(--color-muted);
	font-size: 0.82rem;
	white-space: nowrap;
}
.zone-val {
	font-weight: 700;
	min-width: 3.2em;
	text-align: right;
	font-variant-numeric: tabular-nums;
}
/* medication feed card — violet tint */
.d-ev.medication .d-ic { background: rgba(168, 130, 220, 0.18); }
