/*
Mobile-first design system for the Reading app. No framework dependency
(no Bootstrap/ACE) - this is meant to feel like an app, not a desktop admin
panel shrunk down. Works as a plain responsive site too (wider screens just
center the same single-column layout), but every decision below is made for
a phone screen and a thumb first.
*/

:root {
	--brand: #0F4C81;
	--brand-dark: #0A3660;
	--accent: #E6007E;
	--gold: #F5A623;
	--good: #1E9E5A;
	--due: #E08A00;
	--danger: #D0342C;

	--bg: #F4F6F9;
	--surface: #FFFFFF;
	--text: #1B2430;
	--text-muted: #667085;
	--border: #E3E8EF;

	--radius: 14px;
	--radius-sm: 10px;
	--gap: 16px;
	--tap: 48px;

	--safe-top: env(safe-area-inset-top, 0px);
	--safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html, body {
	margin: 0;
	padding: 0;
	background: var(--bg);
	color: var(--text);
	font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
	font-size: 16px;
	line-height: 1.45;
	-webkit-tap-highlight-color: transparent;
}

a { color: inherit; text-decoration: none; }

.app {
	max-width: 560px;
	margin: 0 auto;
	min-height: 100vh;
	background: var(--bg);
	display: flex;
	flex-direction: column;
}

/* ---- Top bar ---- */
.topbar {
	position: sticky;
	top: 0;
	z-index: 10;
	background: var(--brand);
	color: #fff;
	padding: calc(14px + var(--safe-top)) var(--gap) 14px;
	display: flex;
	align-items: center;
	gap: 12px;
	box-shadow: 0 2px 8px rgba(15, 76, 129, 0.25);
}

.topbar-titles {
	flex: 1;
	min-width: 0;
}

.topbar h1 {
	font-size: 18px;
	font-weight: 600;
	margin: 0;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

.topbar .back {
	width: 32px;
	height: 32px;
	display: flex;
	align-items: center;
	justify-content: center;
	font-size: 20px;
	flex-shrink: 0;
}

.topbar-user {
	flex-shrink: 0;
	max-width: 130px;
	display: flex;
	align-items: center;
	gap: 4px;
	font-size: 12px;
	font-weight: 600;
	opacity: 0.92;
	background: rgba(255,255,255,0.15);
	padding: 5px 10px;
	border-radius: 999px;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}
.topbar-user .icon { font-size: 12px; flex-shrink: 0; }

.topbar .sub {
	font-size: 12.5px;
	opacity: 0.85;
	margin-top: 2px;
}

/* ---- Content area ---- */
.content {
	flex: 1;
	padding: var(--gap) var(--gap) calc(80px + var(--safe-bottom));
}

/* ---- Bottom nav ---- */
.bottomnav {
	position: fixed;
	left: 0;
	right: 0;
	bottom: 0;
	max-width: 560px;
	margin: 0 auto;
	background: var(--surface);
	border-top: 1px solid var(--border);
	display: flex;
	padding-bottom: var(--safe-bottom);
	z-index: 10;
}

.bottomnav a {
	flex: 1;
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	gap: 3px;
	padding: 10px 0 8px;
	font-size: 11.5px;
	color: var(--text-muted);
}

.bottomnav a.active { color: var(--brand); }
.bottomnav .icon { font-size: 20px; line-height: 1; }

/* ---- Cards ---- */
.card {
	background: var(--surface);
	border: 1px solid var(--border);
	border-radius: var(--radius);
	padding: 14px 16px;
	margin-bottom: 12px;
}

.card-link {
	display: block;
	background: var(--surface);
	border: 1px solid var(--border);
	border-radius: var(--radius);
	padding: 14px 16px;
	margin-bottom: 12px;
}

.card-link:active { background: #EEF2F7; }

.card-title {
	font-weight: 600;
	font-size: 16px;
	margin-bottom: 2px;
}

.card-sub {
	font-size: 13.5px;
	color: var(--text-muted);
}

.card-row {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 10px;
}

/* ---- Badges ---- */
.badge {
	display: inline-block;
	font-size: 12px;
	font-weight: 600;
	padding: 3px 10px;
	border-radius: 999px;
	white-space: nowrap;
}
.badge-due { background: #FFF3E0; color: var(--due); }
.badge-good { background: #E6F6ED; color: var(--good); }
.badge-neutral { background: #EEF1F5; color: var(--text-muted); }

/* ---- Forms ---- */
.field { margin-bottom: 16px; }

.field label {
	display: block;
	font-size: 13.5px;
	font-weight: 600;
	color: var(--text-muted);
	margin-bottom: 6px;
}

.field input[type=text],
.field input[type=password],
.field input[type=number],
.field input[type=date],
.field input[type=tel],
.field input[type=email],
.field select,
.field textarea {
	width: 100%;
	min-height: var(--tap);
	padding: 10px 14px;
	font-size: 16px;
	border: 1.5px solid var(--border);
	border-radius: var(--radius-sm);
	background: var(--surface);
	color: var(--text);
	font-family: inherit;
}

.field input:focus, .field select:focus, .field textarea:focus {
	outline: none;
	border-color: var(--brand);
}

.field textarea { min-height: 96px; padding-top: 12px; resize: vertical; }

.hint { font-size: 12.5px; color: var(--text-muted); margin-top: 6px; }

/* Visually hidden but still reachable/triggerable - used to hide a raw
   <input type=file> behind a styled <label class="btn"> "button" (a plain
   display:none input isn't reliably clickable-via-label on some older
   mobile browsers, this pattern is). */
.file-input-hidden {
	position: absolute;
	width: 1px;
	height: 1px;
	padding: 0;
	margin: -1px;
	overflow: hidden;
	clip: rect(0, 0, 0, 0);
	white-space: nowrap;
	border: 0;
}

/* ---- Buttons ---- */
.btn {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 100%;
	min-height: var(--tap);
	padding: 12px 18px;
	font-size: 16px;
	font-weight: 600;
	border-radius: var(--radius-sm);
	border: none;
	cursor: pointer;
	font-family: inherit;
}

.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:active { background: var(--brand-dark); }

.btn-accent { background: var(--accent); color: #fff; }

.btn-outline {
	background: transparent;
	color: var(--brand);
	border: 1.5px solid var(--brand);
}

.btn-row { display: flex; gap: 10px; }
.btn-row .btn { width: auto; flex: 1; }

/* Submit spinner - avLockSubmit() injects this into a button so a slow
   request (a photo upload especially) reads as "working", not "stuck". */
.btn-spinner {
	display: inline-block;
	width: 16px;
	height: 16px;
	margin-right: 8px;
	border: 2px solid rgba(255, 255, 255, 0.4);
	border-top-color: #fff;
	border-radius: 50%;
	animation: av-spin 0.7s linear infinite;
	vertical-align: -3px;
}
.btn-outline .btn-spinner { border-color: rgba(15, 76, 129, 0.3); border-top-color: var(--brand); }
@keyframes av-spin { to { transform: rotate(360deg); } }

/* ---- Misc ---- */
.section-title {
	font-size: 13px;
	font-weight: 700;
	letter-spacing: .03em;
	text-transform: uppercase;
	color: var(--text-muted);
	margin: 4px 0 10px;
}

.empty {
	text-align: center;
	color: var(--text-muted);
	padding: 48px 16px;
	font-size: 14.5px;
}

.empty .icon { font-size: 40px; display: block; margin-bottom: 10px; }

.divider { height: 1px; background: var(--border); margin: 18px 0; }

/* ---- Stat tiles + bar chart (dashboard) ---- */
.stat-grid {
	display: grid;
	grid-template-columns: 1fr 1fr;
	gap: 10px;
	margin-bottom: 16px;
}

.stat-tile {
	display: block;
	background: var(--surface);
	border: 1px solid var(--border);
	border-radius: var(--radius);
	padding: 14px;
	text-decoration: none;
}
a.stat-tile:active { background: #EEF2F7; }
.stat-tile .stat-num { font-size: 26px; font-weight: 700; color: var(--brand); line-height: 1.1; }
.stat-tile .stat-label { font-size: 12.5px; color: var(--text-muted); margin-top: 4px; }

.chart-bars {
	display: flex;
	align-items: flex-end;
	gap: 8px;
	height: 140px;
	padding-top: 22px;
}

.chart-bar-col {
	flex: 1;
	display: flex;
	flex-direction: column;
	align-items: center;
	height: 100%;
}

.chart-bar-value {
	font-size: 12px;
	font-weight: 700;
	color: var(--text);
	margin-bottom: 4px;
}

.chart-bar-track {
	flex: 1;
	width: 100%;
	display: flex;
	align-items: flex-end;
	justify-content: center;
}

.chart-bar {
	width: 60%;
	max-width: 28px;
	background: var(--brand);
	border-radius: 4px 4px 0 0;
	min-height: 3px;
}

.chart-bar-col.is-today .chart-bar { background: var(--gold); }

.chart-bar-label {
	font-size: 11px;
	color: var(--text-muted);
	margin-top: 6px;
}

.toast {
	position: fixed;
	left: 50%;
	bottom: calc(90px + var(--safe-bottom));
	transform: translateX(-50%);
	background: var(--text);
	color: #fff;
	padding: 10px 18px;
	border-radius: 999px;
	font-size: 13.5px;
	z-index: 50;
	box-shadow: 0 4px 14px rgba(0,0,0,.2);
}

.readout-grid {
	display: grid;
	grid-template-columns: 1fr 1fr;
	gap: 10px;
}
@media (max-width: 360px) {
	.readout-grid { grid-template-columns: 1fr; }
}

.stat {
	background: #F0F5FA;
	border-radius: var(--radius-sm);
	padding: 12px 14px;
}
.stat .label { font-size: 12px; color: var(--text-muted); }
.stat .value { font-size: 17px; font-weight: 700; margin-top: 2px; }

.login-wrap {
	min-height: 100vh;
	display: flex;
	flex-direction: column;
	justify-content: center;
	padding: 32px var(--gap);
	background: linear-gradient(180deg, var(--brand) 0%, var(--brand) 220px, var(--bg) 220px);
}

.login-logo {
	display: block;
	max-width: 200px;
	margin: 0 auto 28px;
}

.login-card {
	background: var(--surface);
	border-radius: var(--radius);
	padding: 24px 20px;
	box-shadow: 0 10px 30px rgba(15,76,129,.15);
}

.login-card h2 {
	margin: 0 0 4px;
	font-size: 20px;
}
.login-card p.hint { margin-bottom: 20px; }

.error-msg {
	background: #FDEDEC;
	color: var(--danger);
	border-radius: var(--radius-sm);
	padding: 10px 14px;
	font-size: 13.5px;
	margin-bottom: 16px;
}
