/* styles.css — medicine_tracker frontend.
 *
 * Plain CSS, no framework. Mobile-first with a couple of responsive
 * breakpoints. The design is driven by CSS custom properties so the palette,
 * spacing, and elevation are easy to tweak in one place.
 *
 * The JS targets element IDs, `data-*` attributes, form field names, and a
 * small set of classes. Any selector the JS relies on (`.btn`, `.card`,
 * `.grid`, `.slot`, `.badge-*`, `.inline-form`, etc.) is preserved here.
 */

:root {
	/* Palette — calm clinical teal as the brand accent. */
	--bg: #f4f7fb;
	--bg-grad: #eef3fb;
	--surface: #ffffff;
	--surface-2: #f8fafc;
	--surface-3: #f1f5f9;
	--border: #e3e9f2;
	--border-strong: #d2dae6;
	--text: #0f172a;
	--text-soft: #334155;
	--muted: #64748b;
	--muted-2: #94a3b8;

	--primary: #0d9488;
	--primary-hover: #0f766e;
	--primary-soft: #ccfbf1;
	--primary-tint: #f0fdfa;

	--danger: #e11d48;
	--danger-hover: #be123c;
	--danger-soft: #ffe4e6;

	--warn: #f59e0b;
	--warn-soft: #fef3c7;
	--warn-ink: #92400e;

	--ok: #16a34a;
	--ok-soft: #dcfce7;
	--ok-ink: #166534;

	--info-soft: #dbeafe;
	--info-ink: #1e40af;

	/* Shape & elevation */
	--radius: 16px;
	--radius-sm: 10px;
	--radius-xs: 8px;
	--radius-pill: 999px;

	--gap: 1rem;
	--gap-sm: 0.5rem;
	--gap-lg: 1.5rem;

	--shadow-xs: 0 1px 2px rgba(15, 23, 42, 0.04);
	--shadow-sm: 0 1px 3px rgba(15, 23, 42, 0.06), 0 1px 2px rgba(15, 23, 42, 0.04);
	--shadow-md: 0 4px 16px rgba(15, 23, 42, 0.08);
	--shadow-lg: 0 18px 40px -12px rgba(15, 23, 42, 0.18);
	--shadow-primary: 0 8px 20px -6px rgba(13, 148, 136, 0.45);
}

* {
	box-sizing: border-box;
}

html,
body {
	height: 100%;
}

body {
	margin: 0;
	font-family: system-ui, -apple-system, "Segoe UI", Roboto,
		"Helvetica Neue", Arial, sans-serif;
	background: var(--bg);
	background-image: radial-gradient(
			1200px 480px at 100% -10%,
			var(--primary-tint),
			transparent 60%
		),
		radial-gradient(900px 420px at -10% 0%, var(--bg-grad), transparent 55%);
	background-attachment: fixed;
	color: var(--text);
	line-height: 1.55;
	-webkit-font-smoothing: antialiased;
	text-rendering: optimizeLegibility;
}

a {
	color: var(--primary);
}

/* --- Navigation ---------------------------------------------------------- */

.nav {
	position: sticky;
	top: 0;
	z-index: 50;
	display: flex;
	align-items: center;
	gap: var(--gap);
	padding: 0.7rem 1.25rem;
	background: rgba(255, 255, 255, 0.82);
	backdrop-filter: saturate(180%) blur(12px);
	-webkit-backdrop-filter: saturate(180%) blur(12px);
	border-bottom: 1px solid var(--border);
	box-shadow: var(--shadow-xs);
	flex-wrap: wrap;
}

.nav-brand {
	display: inline-flex;
	align-items: center;
	gap: 0.55rem;
	font-weight: 800;
	font-size: 1.08rem;
	letter-spacing: -0.01em;
	margin-right: auto;
	color: var(--text);
}

.nav-brand .logo {
	display: grid;
	place-items: center;
	width: 34px;
	height: 34px;
	border-radius: 10px;
	background: linear-gradient(140deg, var(--primary), #14b8a6);
	color: #fff;
	box-shadow: var(--shadow-primary);
	flex: 0 0 auto;
}

.nav-brand .logo svg {
	width: 19px;
	height: 19px;
}

.nav-links {
	display: flex;
	gap: 0.25rem;
}

.nav-links a {
	position: relative;
	color: var(--text-soft);
	text-decoration: none;
	font-weight: 600;
	font-size: 0.94rem;
	padding: 0.45rem 0.8rem;
	border-radius: var(--radius-pill);
	transition: background 0.15s ease, color 0.15s ease;
}

.nav-links a:hover {
	background: var(--primary-tint);
	color: var(--primary-hover);
}

.nav-links a.active {
	background: var(--primary);
	color: #fff;
}

.nav-user {
	display: flex;
	align-items: center;
	gap: 0.6rem;
}

.nav-email {
	display: inline-flex;
	align-items: center;
	gap: 0.4rem;
	max-width: 200px;
	color: var(--text);
	text-decoration: none;
	font-size: 0.88rem;
	font-weight: 600;
	padding: 0.35rem 0.35rem 0.35rem 0.4rem;
	border-radius: var(--radius-pill);
	background: var(--surface-3);
	border: 1px solid var(--border);
	transition: background 0.15s ease, border-color 0.15s ease;
}

.nav-email:hover {
	background: var(--primary-tint);
	border-color: var(--primary-soft);
	color: var(--primary-hover);
}

.nav-email .avatar {
	display: grid;
	place-items: center;
	width: 24px;
	height: 24px;
	border-radius: 50%;
	background: linear-gradient(140deg, var(--primary), #14b8a6);
	color: #fff;
	font-size: 0.72rem;
	font-weight: 700;
	text-transform: uppercase;
	flex: 0 0 auto;
}

.nav-email span {
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

/* --- Layout -------------------------------------------------------------- */

.view {
	max-width: 960px;
	margin: 0 auto;
	padding: 1.75rem 1.25rem 5rem;
}

.page {
	display: flex;
	flex-direction: column;
	gap: var(--gap-lg);
}

.page-head {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 1rem;
	flex-wrap: wrap;
}

.page-head h1 {
	margin: 0;
}

.toolbar {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 0.75rem;
	padding: 0.6rem 0.9rem;
	background: var(--surface);
	border: 1px solid var(--border);
	border-radius: var(--radius);
}

.back {
	display: inline-flex;
	align-items: center;
	gap: 0.35rem;
	color: var(--primary);
	text-decoration: none;
	font-weight: 600;
	font-size: 0.92rem;
	width: max-content;
}

.back:hover {
	color: var(--primary-hover);
}

h1 {
	margin: 0 0 0.25rem;
	font-size: 1.6rem;
	font-weight: 800;
	letter-spacing: -0.02em;
}

h2 {
	margin: 0 0 0.5rem;
	font-size: 1.15rem;
	font-weight: 700;
	letter-spacing: -0.01em;
}

h3 {
	margin: 0;
	font-size: 1.08rem;
	font-weight: 700;
	letter-spacing: -0.01em;
}

.big {
	font-size: 1.5rem;
	font-weight: 800;
	margin: 0.35rem 0;
	letter-spacing: -0.02em;
}

.muted {
	color: var(--muted);
	margin: 0.25rem 0;
}

/* --- Cards & grid -------------------------------------------------------- */

.card {
	background: var(--surface);
	border: 1px solid var(--border);
	border-radius: var(--radius);
	padding: 1.35rem;
	box-shadow: var(--shadow-sm);
	transition: box-shadow 0.18s ease, transform 0.18s ease,
		border-color 0.18s ease;
}

.auth-card {
	max-width: 440px;
	margin: 2.5rem auto 1rem;
	padding: 2rem 2rem 1.75rem;
	box-shadow: var(--shadow-lg);
	text-align: left;
}

.auth-card h1 {
	text-align: center;
}

.card-head {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 0.75rem;
}

.grid {
	display: grid;
	grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
	gap: var(--gap);
}

/* --- Forms --------------------------------------------------------------- */

.form {
	display: flex;
	flex-direction: column;
	gap: 0.95rem;
}

.form-grid {
	display: grid;
	grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
	gap: 0.95rem;
}

label {
	display: flex;
	flex-direction: column;
	gap: 0.35rem;
	font-size: 0.85rem;
	font-weight: 600;
	color: var(--text-soft);
}

/* A label containing a single checkbox lays out inline (checkbox + caption on
   one row) and spans the full grid row so it reads as one control. */
.checkbox-field {
	flex-direction: row;
	align-items: center;
	gap: 0.55rem;
	grid-column: 1 / -1;
	padding: 0.6rem 0.8rem;
	background: var(--surface-2);
	border: 1px solid var(--border);
	border-radius: var(--radius-sm);
	font-size: 0.92rem;
	color: var(--text);
	cursor: pointer;
}

.checkbox-field input[type="checkbox"] {
	width: 18px;
	height: 18px;
	accent-color: var(--primary);
}

input,
select {
	width: 100%;
	padding: 0.65rem 0.75rem;
	border: 1px solid var(--border-strong);
	border-radius: var(--radius-sm);
	font-size: 0.98rem;
	font-family: inherit;
	color: var(--text);
	background: var(--surface);
	transition: border-color 0.15s ease, box-shadow 0.15s ease,
		background 0.15s ease;
}

input::placeholder {
	color: var(--muted-2);
}

input:hover,
select:hover {
	border-color: var(--primary);
}

input:focus,
select:focus {
	outline: none;
	border-color: var(--primary);
	box-shadow: 0 0 0 3px var(--primary-soft);
}

.form-actions {
	display: flex;
	gap: 0.75rem;
	align-items: center;
}

.inline-form {
	display: flex;
	gap: 0.5rem;
	align-items: center;
	margin-top: 0.5rem;
}

.inline-form input,
.inline-form select {
	flex: 1 1 0;
	min-width: 0;
}

/* --- Buttons ------------------------------------------------------------- */

.btn {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: 0.4rem;
	padding: 0.58rem 1rem;
	border: 1px solid var(--border-strong);
	border-radius: var(--radius-sm);
	background: var(--surface);
	color: var(--text);
	font-family: inherit;
	font-size: 0.92rem;
	font-weight: 600;
	cursor: pointer;
	transition: background 0.15s ease, border-color 0.15s ease,
		color 0.15s ease, transform 0.06s ease, box-shadow 0.15s ease;
}

.btn:hover {
	background: var(--surface-3);
	border-color: var(--border-strong);
}

.btn:active {
	transform: translateY(1px);
}

.btn-primary {
	background: linear-gradient(140deg, var(--primary), #14b8a6);
	border-color: transparent;
	color: #fff;
	box-shadow: var(--shadow-primary);
}

.btn-primary:hover {
	background: linear-gradient(140deg, var(--primary-hover), #0d9488);
	border-color: transparent;
	color: #fff;
}

.btn-secondary {
	background: var(--surface-3);
	border-color: var(--border);
}

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

.btn-danger:hover {
	background: var(--danger-hover);
	border-color: var(--danger-hover);
	color: #fff;
}

.btn-sm {
	padding: 0.4rem 0.7rem;
	font-size: 0.84rem;
	border-radius: var(--radius-xs);
}

.btn:disabled {
	opacity: 0.5;
	cursor: not-allowed;
	transform: none;
	box-shadow: none;
}

/* --- Badges -------------------------------------------------------------- */

.badge {
	display: inline-flex;
	align-items: center;
	gap: 0.3rem;
	padding: 0.2rem 0.6rem;
	border-radius: var(--radius-pill);
	font-size: 0.7rem;
	font-weight: 700;
	text-transform: uppercase;
	letter-spacing: 0.04em;
	white-space: nowrap;
}

.badge-warn {
	background: var(--warn-soft);
	color: var(--warn-ink);
}

.badge-ok {
	background: var(--ok-soft);
	color: var(--ok-ink);
}

.badge-auto {
	background: var(--info-soft);
	color: var(--info-ink);
}

.badge-manual {
	background: var(--surface-3);
	color: var(--text-soft);
}

/* --- Slots & doses ------------------------------------------------------- */

.slot {
	border-top: 1px solid var(--border);
	padding-top: 1rem;
	margin-top: 1rem;
}

.slot:first-child {
	border-top: none;
	padding-top: 0;
	margin-top: 0;
}

.slot-head {
	display: flex;
	align-items: center;
	gap: 0.6rem;
	margin-bottom: 0.5rem;
	flex-wrap: wrap;
}

.slot-head strong {
	font-size: 1.05rem;
	font-variant-numeric: tabular-nums;
}

.doses {
	list-style: none;
	padding: 0;
	margin: 0 0 0.4rem;
	display: flex;
	flex-direction: column;
	gap: 0.35rem;
}

.dose-row {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 0.5rem;
	padding: 0.45rem 0.7rem;
	background: var(--surface-2);
	border: 1px solid var(--border);
	border-radius: var(--radius-sm);
	font-size: 0.92rem;
}

.dose-row > span {
	color: var(--text-soft);
}

.slot-actions {
	display: flex;
	flex-wrap: wrap;
	gap: 0.5rem;
	align-items: center;
	margin-top: 0.5rem;
}

.slot-actions .add-dose {
	flex: 1 1 240px;
}

/* --- Feedback ------------------------------------------------------------ */

.error,
.slot-err {
	color: var(--danger);
	font-size: 0.86rem;
}

.success {
	color: var(--ok);
	font-size: 0.86rem;
}

/* --- Medicine card specifics -------------------------------------------- */

.med-stock {
	margin: 0.35rem 0 0.15rem;
}

.med-stock .big {
	display: inline-flex;
	align-items: baseline;
	gap: 0.35rem;
}

.med-stock .unit {
	font-size: 0.9rem;
	font-weight: 600;
	color: var(--muted);
}

.stock-bar {
	position: relative;
	height: 8px;
	border-radius: var(--radius-pill);
	background: var(--surface-3);
	overflow: hidden;
	margin: 0.5rem 0 0.15rem;
}

.stock-bar > span {
	position: absolute;
	inset: 0;
	width: var(--fill, 0%);
	border-radius: inherit;
	background: linear-gradient(90deg, #14b8a6, var(--primary));
	transition: width 0.3s ease, background 0.3s ease;
}

.stock-bar.low > span {
	background: linear-gradient(90deg, #f59e0b, #d97706);
}

.stock-bar.empty > span {
	background: linear-gradient(90deg, #fb7185, var(--danger));
}

.med-meta {
	display: flex;
	flex-wrap: wrap;
	gap: 0.4rem 1rem;
	color: var(--muted);
	font-size: 0.85rem;
	margin: 0.1rem 0 0.4rem;
}

.med-meta span {
	display: inline-flex;
	align-items: center;
	gap: 0.3rem;
}

.med-actions {
	display: flex;
	flex-direction: column;
	gap: 0.5rem;
	margin-top: 0.65rem;
}

.med-actions .btn-danger {
	margin-top: 0.25rem;
}

.med-form-tag {
	display: inline-flex;
	align-items: center;
	gap: 0.35rem;
	padding: 0.2rem 0.6rem;
	border-radius: var(--radius-pill);
	background: var(--surface-3);
	border: 1px solid var(--border);
	font-size: 0.78rem;
	font-weight: 600;
	color: var(--text-soft);
	text-transform: capitalize;
	margin-top: 0.35rem;
}

/* --- Empty & loading states --------------------------------------------- */

.empty-state {
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	text-align: center;
	gap: 0.75rem;
	padding: 2.5rem 1.5rem;
	border: 1.5px dashed var(--border-strong);
	border-radius: var(--radius);
	background: var(--surface);
	color: var(--muted);
}

.empty-state .ico {
	display: grid;
	place-items: center;
	width: 56px;
	height: 56px;
	border-radius: 16px;
	background: var(--primary-tint);
	color: var(--primary);
}

.empty-state .ico svg {
	width: 28px;
	height: 28px;
}

.empty-state p {
	margin: 0;
	max-width: 32ch;
}

.spinner {
	display: inline-block;
	width: 16px;
	height: 16px;
	border: 2px solid var(--primary-soft);
	border-top-color: var(--primary);
	border-radius: 50%;
	animation: spin 0.7s linear infinite;
	vertical-align: -3px;
}

@keyframes spin {
	to {
		transform: rotate(360deg);
	}
}

/* --- Auth helpers -------------------------------------------------------- */

.auth-brand {
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 0.6rem;
	margin-bottom: 1.25rem;
}

.auth-brand .logo {
	display: grid;
	place-items: center;
	width: 56px;
	height: 56px;
	border-radius: 16px;
	background: linear-gradient(140deg, var(--primary), #14b8a6);
	color: #fff;
	box-shadow: var(--shadow-primary);
}

.auth-brand .logo svg {
	width: 30px;
	height: 30px;
}

.auth-brand .title {
	font-size: 1.15rem;
	font-weight: 800;
	letter-spacing: -0.01em;
}

.auth-brand .subtitle {
	font-size: 0.88rem;
	color: var(--muted);
}

.auth-switch {
	text-align: center;
	margin-top: 1.25rem;
	font-size: 0.9rem;
	color: var(--muted);
}

.auth-switch a {
	font-weight: 600;
}

/* --- Small screens ------------------------------------------------------- */

@media (max-width: 540px) {
	.nav {
		padding: 0.6rem 0.9rem;
		gap: 0.5rem;
	}
	.nav-brand {
		font-size: 0.98rem;
	}
	.nav-brand .logo {
		width: 30px;
		height: 30px;
		border-radius: 8px;
	}
	.nav-brand .logo svg {
		width: 16px;
		height: 16px;
	}
	.nav-links a {
		padding: 0.4rem 0.6rem;
		font-size: 0.88rem;
	}
	.nav-email {
		max-width: 120px;
	}
	.nav-email span {
		display: none;
	}
	.view {
		padding: 1.1rem 0.9rem 4rem;
	}
	.form-actions {
		flex-wrap: wrap;
	}
	.form-actions .btn {
		flex: 1 1 auto;
	}
	h1 {
		font-size: 1.4rem;
	}
	.auth-card {
		margin: 1rem 0;
		padding: 1.5rem 1.25rem;
	}
}

@media (max-width: 380px) {
	.nav-links a {
		padding: 0.35rem 0.45rem;
	}
}

/* --- Install help modal ----------------------------------------------- */
/* Platform-aware "Add to Home Screen" instructions shown when the native
   beforeinstallprompt isn't available (iOS Safari, or Chromium before the
   browser is eligible). Injected/removed dynamically by app.js. */
.modal-overlay {
	position: fixed;
	inset: 0;
	z-index: 100;
	display: grid;
	place-items: center;
	padding: 1.25rem;
	background: rgba(15, 23, 42, 0.45);
	backdrop-filter: blur(2px);
	-webkit-backdrop-filter: blur(2px);
	animation: modal-fade 0.15s ease;
}

.modal {
	position: relative;
	width: 100%;
	max-width: 380px;
	padding: 1.75rem 1.5rem 1.5rem;
	background: var(--surface);
	border: 1px solid var(--border);
	border-radius: var(--radius);
	box-shadow: var(--shadow-lg);
	animation: modal-pop 0.18s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.modal h2 {
	margin: 0 0 0.5rem;
	font-size: 1.2rem;
	color: var(--text);
}

.modal p {
	margin: 0 0 1rem;
	color: var(--muted);
	font-size: 0.92rem;
	line-height: 1.5;
}

.modal-steps {
	margin: 0 0 1.5rem;
	padding: 0 0 0 1.25rem;
	color: var(--text-soft);
	font-size: 0.95rem;
	line-height: 1.6;
}

.modal-steps li {
	margin-bottom: 0.5rem;
}

.modal-close {
	position: absolute;
	top: 0.5rem;
	right: 0.6rem;
	width: 2rem;
	height: 2rem;
	display: grid;
	place-items: center;
	border: none;
	border-radius: var(--radius-xs);
	background: transparent;
	color: var(--muted);
	font-size: 1.4rem;
	line-height: 1;
	cursor: pointer;
	transition: background 0.15s ease, color 0.15s ease;
}

.modal-close:hover {
	background: var(--surface-3);
	color: var(--text);
}

.modal-dismiss {
	width: 100%;
}

@keyframes modal-fade {
	from { opacity: 0; }
	to { opacity: 1; }
}

@keyframes modal-pop {
	from { opacity: 0; transform: translateY(8px) scale(0.98); }
	to { opacity: 1; transform: translateY(0) scale(1); }
}

@media (prefers-reduced-motion: reduce) {
	.modal-overlay,
	.modal {
		animation: none;
	}
}
