/*
 * Tetê da Lara - PWA styles.
 *
 * The palette comes from the app icon: butter yellow, peach and terracotta.
 * Dark mode follows the device, because most of this app's use happens at night.
 * Every colour is a token below; nothing else in the file hard-codes one.
 */

:root {
	color-scheme: light dark;

	--bg: #fff9f0;
	--surface: #ffffff;
	--surface-2: #fcf0e2;
	--line: #f0e1d0;
	--line-strong: #dcc8b4;
	--text: #3a2a22;
	--muted: #7a6555;

	--accent: #ffd629;
	--on-accent: #3a2a22;
	--accent-soft: #fff1b8;

	--brand: #b5533a;
	--brand-soft: #fbe7dd;
	--brand-strong: #b5533a;
	--on-brand: #ffffff;
	--brand-glow: rgb(181 83 58 / 0.45);

	--danger: #b3261e;
	--danger-soft: #fde8e6;
	--on-danger: #ffffff;

	--bar: #c96a4b;
	--switch-off: #9c8878;
	--shadow: 0 1px 2px rgb(58 42 34 / 0.06), 0 6px 20px rgb(58 42 34 / 0.06);

	--radius: 18px;
	--tab-height: 64px;
	--safe-bottom: env(safe-area-inset-bottom, 0px);
	--safe-top: env(safe-area-inset-top, 0px);
}

@media (prefers-color-scheme: dark) {
	:root {
		--bg: #1d1613;
		--surface: #2a201b;
		--surface-2: #362a23;
		--line: #43352c;
		--line-strong: #5a483c;
		--text: #f6e9dc;
		--muted: #bba898;

		--accent-soft: #4a3f14;

		--brand: #f0a184;
		--brand-soft: #4a2f25;
		--brand-strong: #f0a184;
		--on-brand: #2a1710;
		--brand-glow: rgb(240 161 132 / 0.45);

		--danger: #f2857c;
		--danger-soft: #4b2521;
		--on-danger: #2a0f0c;

		--bar: #e8916f;
		--switch-off: #6b5a4e;
		--shadow: 0 1px 2px rgb(0 0 0 / 0.3), 0 6px 20px rgb(0 0 0 / 0.25);
	}
}

*,
*::before,
*::after {
	box-sizing: border-box;
}

[hidden] {
	display: none !important;
}

html {
	-webkit-text-size-adjust: 100%;
}

body {
	margin: 0;
	background: var(--bg);
	color: var(--text);
	font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
	-webkit-tap-highlight-color: transparent;
	/* Room for the floating action and the tab bar. */
	padding-bottom: calc(var(--tab-height) + var(--safe-bottom) + 88px);
}

body.sheet-open {
	overflow: hidden;
}

h1,
h2,
h3,
p {
	margin: 0;
}

button,
input,
select,
textarea {
	font: inherit;
	color: inherit;
}

button {
	cursor: pointer;
}

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

:focus-visible {
	outline: 3px solid var(--brand);
	outline-offset: 2px;
}

.muted {
	color: var(--muted);
}

.icon {
	width: 22px;
	height: 22px;
	flex: none;
	fill: none;
	stroke: currentColor;
	stroke-width: 2;
	stroke-linecap: round;
	stroke-linejoin: round;
}

.icon.solid {
	fill: currentColor;
	stroke: none;
}

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

#app {
	display: flex;
	flex-direction: column;
	gap: 16px;
	max-width: 560px;
	margin: 0 auto;
	padding: calc(20px + var(--safe-top)) 16px 24px;
}

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

.page-head h1 {
	font-size: 1.6rem;
	font-weight: 800;
	letter-spacing: -0.02em;
	line-height: 1.15;
}

.back {
	display: inline-flex;
	align-items: center;
	gap: 2px;
	flex-basis: 100%;
	min-height: 32px;
	margin-left: -6px;
	color: var(--brand);
	font-weight: 700;
}

.section-title {
	margin: 8px 4px -4px;
	font-size: 0.85rem;
	font-weight: 800;
	letter-spacing: 0.06em;
	text-transform: uppercase;
	color: var(--muted);
}

.card {
	background: var(--surface);
	border: 1px solid var(--line);
	border-radius: var(--radius);
	box-shadow: var(--shadow);
	padding: 16px;
}

.empty {
	text-align: center;
	color: var(--muted);
	padding: 28px 16px;
}

.empty .btn {
	margin-top: 14px;
}

/* ---------- Home ---------- */

.baby-head {
	display: flex;
	align-items: center;
	gap: 12px;
}

.avatar {
	width: 52px;
	height: 52px;
	flex: none;
	border-radius: 50%;
	box-shadow: var(--shadow);
}

.head-button {
	display: grid;
	place-items: center;
	width: 44px;
	height: 44px;
	flex: none;
	margin-left: auto;
	border-radius: 50%;
	background: var(--surface);
	border: 1px solid var(--line);
	box-shadow: var(--shadow);
	color: var(--text);
}

.baby-head h1 {
	font-size: 1.5rem;
	font-weight: 800;
	letter-spacing: -0.02em;
	line-height: 1.15;
}

.muted-link {
	color: var(--brand);
	font-weight: 600;
}

.status {
	padding: 20px;
	border: 1px solid var(--line);
	border-radius: 24px;
	background: linear-gradient(140deg, var(--accent-soft), var(--brand-soft));
}

.status-label {
	display: flex;
	align-items: center;
	gap: 8px;
	font-size: 0.8rem;
	font-weight: 800;
	letter-spacing: 0.06em;
	text-transform: uppercase;
	color: var(--muted);
}

.status-value {
	margin: 6px 0 4px;
	font-size: 2.75rem;
	font-weight: 800;
	letter-spacing: -0.03em;
	line-height: 1.1;
	font-variant-numeric: tabular-nums;
}

.status-value.is-text {
	font-size: 1.9rem;
}

.status-sub {
	color: var(--muted);
}

.live-dot {
	width: 10px;
	height: 10px;
	border-radius: 50%;
	background: var(--brand-strong);
	animation: pulse 1.6s ease-out infinite;
}

.tiles {
	display: grid;
	grid-template-columns: repeat(3, 1fr);
	gap: 10px;
}

.tile {
	padding: 12px;
	background: var(--surface);
	border: 1px solid var(--line);
	border-radius: 16px;
	box-shadow: var(--shadow);
}

.tile span {
	display: block;
	font-size: 0.78rem;
	font-weight: 600;
	color: var(--muted);
}

.tile b {
	display: block;
	margin-top: 2px;
	font-size: 1.3rem;
	font-weight: 800;
	font-variant-numeric: tabular-nums;
}

/* ---------- Lists ---------- */

.group {
	display: flex;
	flex-direction: column;
	gap: 8px;
}

.group-title {
	margin: 8px 4px 0;
	font-size: 0.85rem;
	font-weight: 700;
	color: var(--muted);
}

.list {
	overflow: hidden;
	background: var(--surface);
	border: 1px solid var(--line);
	border-radius: var(--radius);
	box-shadow: var(--shadow);
}

.item {
	display: flex;
	align-items: center;
	gap: 12px;
	width: 100%;
	min-height: 60px;
	padding: 12px 16px;
	background: none;
	border: 0;
	border-bottom: 1px solid var(--line);
	text-align: left;
}

.item:last-child {
	border-bottom: 0;
}

.item:active {
	background: var(--surface-2);
}

.item > .icon {
	color: var(--muted);
}

.item-icon {
	display: grid;
	place-items: center;
	width: 38px;
	height: 38px;
	flex: none;
	border-radius: 12px;
	background: var(--surface-2);
	color: var(--brand);
}

.item-main {
	display: flex;
	flex: 1;
	flex-direction: column;
	min-width: 0;
}

.item-main b {
	font-weight: 700;
	font-variant-numeric: tabular-nums;
}

.item-sub {
	overflow: hidden;
	font-size: 0.88rem;
	color: var(--muted);
	text-overflow: ellipsis;
	white-space: nowrap;
}

.item.danger,
.item.danger .item-icon {
	color: var(--danger);
}

.pill {
	flex: none;
	padding: 4px 10px;
	border-radius: 999px;
	background: var(--surface-2);
	font-size: 0.85rem;
	font-weight: 700;
	font-variant-numeric: tabular-nums;
}

.pill.live {
	background: var(--accent);
	color: var(--on-accent);
}

.pill.ok {
	background: var(--brand-soft);
	color: var(--brand);
}

.weight-hero {
	text-align: center;
}

.weight-hero b {
	display: block;
	font-size: 2.4rem;
	font-weight: 800;
	letter-spacing: -0.02em;
	font-variant-numeric: tabular-nums;
}

/* ---------- Charts ---------- */

.chart-card {
	display: flex;
	flex-direction: column;
	gap: 18px;
}

.axis {
	position: relative;
	height: 1.1em;
	font-size: 0.72rem;
	color: var(--muted);
}

.axis span {
	position: absolute;
	transform: translateX(-50%);
}

.axis span:first-child {
	transform: none;
}

.axis span:last-child {
	transform: translateX(-100%);
}

.day-head {
	display: flex;
	align-items: baseline;
	justify-content: space-between;
	margin-bottom: 8px;
}

.day-head h3 {
	font-size: 1rem;
	font-weight: 800;
}

.track {
	position: relative;
	height: 24px;
	overflow: hidden;
	border-radius: 8px;
	background-color: var(--surface-2);
	background-image: linear-gradient(90deg, var(--line-strong) 1px, transparent 1px);
	background-size: 25% 100%;
}

.seg {
	position: absolute;
	top: 3px;
	bottom: 3px;
	min-width: 4px;
	border-radius: 4px;
	background: var(--bar);
}

.seg.open {
	background: repeating-linear-gradient(45deg, var(--bar) 0 4px, var(--accent) 4px 8px);
}

.day-meta {
	margin-top: 6px;
	font-size: 0.85rem;
	color: var(--muted);
}

.day-meta b {
	color: var(--text);
}

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

.field {
	display: flex;
	flex-direction: column;
	gap: 6px;
	margin-bottom: 14px;
}

.field > span {
	font-size: 0.85rem;
	font-weight: 700;
	color: var(--muted);
}

.field small {
	font-weight: 500;
}

.field input:not([type="checkbox"]),
.field select,
.field textarea {
	display: block;
	width: 100%;
	/* Date/time inputs carry an intrinsic min-width on phones and would
	   otherwise spill past the sheet; appearance:none lets width win. */
	min-width: 0;
	max-width: 100%;
	min-height: 48px;
	padding: 12px 14px;
	background: var(--surface-2);
	border: 1.5px solid transparent;
	border-radius: 12px;
	-webkit-appearance: none;
	appearance: none;
}

.field input::-webkit-date-and-time-value {
	text-align: left;
}

.field select {
	/* The shared rule strips native styling; a select without it loses its arrow. */
	-webkit-appearance: menulist-button;
	appearance: auto;
}

/* Two short numbers side by side: weight and length, weeks and days. */
.field-row {
	display: grid;
	grid-template-columns: 1fr 1fr;
	gap: 12px;
}

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

.switch {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 16px;
	padding: 14px 0;
	border-bottom: 1px solid var(--line);
	font-weight: 600;
}

.switch input {
	position: relative;
	width: 50px;
	height: 30px;
	flex: none;
	margin: 0;
	border-radius: 15px;
	background: var(--switch-off);
	cursor: pointer;
	transition: background 0.2s;
	appearance: none;
	-webkit-appearance: none;
}

.switch input::before {
	content: "";
	position: absolute;
	top: 3px;
	left: 3px;
	width: 24px;
	height: 24px;
	border-radius: 50%;
	background: #ffffff;
	box-shadow: 0 1px 3px rgb(0 0 0 / 0.3);
	transition: transform 0.2s;
}

.switch input:checked {
	background: var(--brand-strong);
}

.switch input:checked::before {
	transform: translateX(20px);
}

.form-actions {
	margin-top: 18px;
}

.form-error {
	margin-bottom: 12px;
	padding: 10px 12px;
	border-radius: 12px;
	background: var(--danger-soft);
	color: var(--danger);
	font-weight: 600;
}

.btn {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: 8px;
	min-height: 48px;
	padding: 0 20px;
	border: 0;
	border-radius: 14px;
	font-weight: 700;
	transition: transform 0.1s;
}

.btn:active {
	transform: scale(0.98);
}

.btn:disabled {
	opacity: 0.6;
}

.btn.primary {
	background: var(--accent);
	color: var(--on-accent);
}

.btn.secondary {
	background: var(--surface-2);
	color: var(--text);
}

.btn.danger {
	background: var(--danger);
	color: var(--on-danger);
}

.btn.small {
	min-height: 40px;
	padding: 0 14px;
	font-size: 0.9rem;
}

.btn.block {
	width: 100%;
}

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

/* ---------- Chat ---------- */

/* Sticky inside #app: the negative margins reach past its padding to the
   screen edges and the top, so messages scroll under an opaque bar instead of
   showing through the gap above it. */
.chat-bar {
	position: sticky;
	top: 0;
	z-index: 10;
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 12px;
	margin: calc(-20px - var(--safe-top)) -16px 0;
	padding: calc(10px + var(--safe-top)) 16px 10px;
	background: var(--bg);
	border-bottom: 1px solid var(--line);
}

.chat-bar .back {
	flex-basis: auto;
}

.chat-title {
	font-size: 1.6rem;
	font-weight: 800;
	letter-spacing: -0.02em;
	line-height: 1.15;
}

.chat-log {
	display: flex;
	flex-direction: column;
	gap: 10px;
	/* The composer floats over the bottom of the page; keep the last bubble clear of it. */
	padding-bottom: 24px;
}

.chat-note {
	text-align: center;
	font-size: 0.8rem;
	color: var(--muted);
}

.chat-older {
	align-self: center;
}

.chat-intro p {
	color: var(--muted);
}

.chips {
	display: flex;
	flex-wrap: wrap;
	gap: 8px;
	margin-top: 14px;
}

.chip {
	min-height: 40px;
	padding: 8px 14px;
	border: 1px solid var(--line-strong);
	border-radius: 20px;
	background: var(--surface);
	font-weight: 600;
	text-align: left;
}

.chip:active {
	background: var(--surface-2);
}

.bubble {
	max-width: 88%;
	padding: 10px 14px;
	border-radius: 18px;
	line-height: 1.5;
	overflow-wrap: anywhere;
}

/* The model's line breaks are the only structure its answers have. */
.bubble p {
	white-space: pre-wrap;
}

.bubble.user {
	align-self: flex-end;
	border-bottom-right-radius: 6px;
	background: var(--accent);
	color: var(--on-accent);
}

.bubble.assistant {
	align-self: flex-start;
	border-bottom-left-radius: 6px;
	background: var(--surface);
	border: 1px solid var(--line);
	box-shadow: var(--shadow);
}

.bubble-meta {
	display: block;
	margin-top: 4px;
	font-size: 0.72rem;
	opacity: 0.7;
}

.pending {
	display: contents;
}

.typing {
	display: flex;
	gap: 5px;
	padding: 14px 16px;
}

.typing i {
	width: 7px;
	height: 7px;
	border-radius: 50%;
	background: var(--muted);
	animation: typing 1.2s ease-in-out infinite;
}

.typing i:nth-child(2) {
	animation-delay: 0.15s;
}

.typing i:nth-child(3) {
	animation-delay: 0.3s;
}

/* Same slot as the floating feed button, which the chat screens do not show. */
.composer {
	position: fixed;
	z-index: 20;
	left: 0;
	right: 0;
	bottom: calc(var(--tab-height) + var(--safe-bottom) + 12px);
	display: flex;
	align-items: flex-end;
	gap: 8px;
	width: min(calc(100% - 32px), 528px);
	margin: 0 auto;
	padding: 6px 6px 6px 16px;
	background: var(--surface);
	border: 1px solid var(--line-strong);
	border-radius: 26px;
	box-shadow: var(--shadow);
}

.composer textarea {
	flex: 1;
	min-width: 0;
	max-height: 140px;
	padding: 10px 0;
	border: 0;
	background: transparent;
	line-height: 1.4;
	resize: none;
}

.composer textarea:focus {
	outline: none;
}

.composer-send {
	display: grid;
	place-items: center;
	width: 42px;
	height: 42px;
	flex: none;
	border: 0;
	border-radius: 50%;
	background: var(--brand-strong);
	color: var(--on-brand);
}

.composer-send:disabled {
	opacity: 0.5;
}

/* ---------- Floating action and tab bar ---------- */

.feed-action {
	position: fixed;
	z-index: 20;
	left: 0;
	right: 0;
	bottom: calc(var(--tab-height) + var(--safe-bottom) + 12px);
	display: flex;
	align-items: center;
	justify-content: center;
	gap: 10px;
	width: min(calc(100% - 32px), 528px);
	min-height: 58px;
	margin: 0 auto;
	border: 0;
	border-radius: 29px;
	background: var(--accent);
	color: var(--on-accent);
	font-size: 1.05rem;
	font-weight: 800;
	box-shadow: 0 8px 24px rgb(120 90 0 / 0.35);
}

.feed-action.is-open {
	background: var(--brand-strong);
	color: var(--on-brand);
	box-shadow: 0 8px 24px rgb(90 30 15 / 0.35);
}

.feed-action small {
	font-size: 0.95rem;
	font-weight: 600;
	opacity: 0.85;
}

.tabbar {
	position: fixed;
	z-index: 30;
	left: 0;
	right: 0;
	bottom: 0;
	padding-bottom: var(--safe-bottom);
	background: var(--surface);
	border-top: 1px solid var(--line);
}

.tabbar-inner {
	display: grid;
	grid-template-columns: repeat(5, 1fr);
	max-width: 560px;
	height: var(--tab-height);
	margin: 0 auto;
}

.tabbar a {
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	gap: 2px;
	font-size: 0.72rem;
	font-weight: 700;
	color: var(--muted);
}

.tab-icon {
	display: grid;
	place-items: center;
	width: 56px;
	height: 30px;
	border-radius: 15px;
	transition: background 0.2s;
}

.tabbar a[aria-current="page"] {
	color: var(--text);
}

.tabbar a[aria-current="page"] .tab-icon {
	background: var(--accent);
	color: var(--on-accent);
}

/* ---------- Sheets and toast ---------- */

#sheet-root:empty {
	display: none;
}

.sheet-backdrop {
	position: fixed;
	z-index: 40;
	inset: 0;
	background: rgb(20 12 8 / 0.5);
	animation: fade 0.2s ease-out;
}

.sheet {
	position: fixed;
	z-index: 41;
	left: 0;
	right: 0;
	bottom: 0;
	width: 100%;
	max-width: 560px;
	max-height: 92vh;
	max-height: 92dvh;
	margin: 0 auto;
	padding: 10px 20px calc(20px + var(--safe-bottom));
	overflow: auto;
	background: var(--surface);
	border-radius: 26px 26px 0 0;
	box-shadow: 0 -10px 40px rgb(0 0 0 / 0.25);
	animation: rise 0.25s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.sheet:focus {
	outline: none;
}

.sheet-grip {
	width: 40px;
	height: 5px;
	margin: 0 auto 14px;
	border-radius: 3px;
	background: var(--line-strong);
}

.sheet h2 {
	font-size: 1.25rem;
	font-weight: 800;
}

.sheet-body {
	margin-top: 16px;
}

.sheet-actions {
	display: flex;
	gap: 10px;
	margin-top: 6px;
}

.sheet-actions .btn {
	flex: 1;
}

.menu {
	display: flex;
	flex-direction: column;
	gap: 8px;
	margin-bottom: 12px;
}

.menu-item {
	display: flex;
	align-items: center;
	gap: 12px;
	min-height: 52px;
	padding: 0 16px;
	border: 0;
	border-radius: 14px;
	background: var(--surface-2);
	font-weight: 700;
	text-align: left;
}

.menu-item.danger {
	color: var(--danger);
}

.toast {
	position: fixed;
	z-index: 60;
	top: calc(12px + var(--safe-top));
	left: 50%;
	width: max-content;
	max-width: min(92vw, 520px);
	padding: 12px 18px;
	border-radius: 14px;
	background: var(--text);
	color: var(--bg);
	font-weight: 600;
	box-shadow: var(--shadow);
	opacity: 0;
	transform: translate(-50%, -150%);
	transition: transform 0.25s, opacity 0.25s;
	pointer-events: none;
}

.toast.show {
	opacity: 1;
	transform: translate(-50%, 0);
}

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

/* ---------- Loading ---------- */

.skeleton {
	border-radius: var(--radius);
	background: linear-gradient(90deg, var(--surface-2) 25%, var(--line) 50%, var(--surface-2) 75%);
	background-size: 200% 100%;
	animation: shimmer 1.4s linear infinite;
}

/* ---------- Login ---------- */

.login-page {
	display: grid;
	place-items: center;
	min-height: 100vh;
	min-height: 100dvh;
	padding: 20px;
	background: radial-gradient(120% 60% at 50% 0%, var(--accent-soft), var(--bg) 70%);
}

.login-card {
	width: 100%;
	max-width: 380px;
	padding: 28px;
	background: var(--surface);
	border: 1px solid var(--line);
	border-radius: 28px;
	box-shadow: var(--shadow);
}

.login-icon {
	display: block;
	width: 84px;
	height: 84px;
	margin: 0 auto 14px;
	border-radius: 50%;
	box-shadow: var(--shadow);
}

.login-card h1 {
	font-size: 1.6rem;
	font-weight: 800;
	letter-spacing: -0.02em;
	text-align: center;
}

.login-card .lead {
	margin: 4px 0 20px;
	text-align: center;
	color: var(--muted);
}

.login-card .notice {
	margin-bottom: 14px;
	padding: 10px 12px;
	border-radius: 12px;
	background: var(--danger-soft);
	color: var(--danger);
	font-weight: 600;
}

.remember {
	display: flex;
	align-items: center;
	gap: 10px;
	margin: 4px 0 18px;
	font-size: 0.95rem;
}

.remember input {
	width: 20px;
	height: 20px;
	margin: 0;
	accent-color: var(--brand-strong);
}

/* ---------- Motion ---------- */

@keyframes typing {
	0%, 60%, 100% { opacity: 0.3; transform: translateY(0); }
	30% { opacity: 1; transform: translateY(-3px); }
}

@keyframes pulse {
	0% {
		box-shadow: 0 0 0 0 var(--brand-glow);
	}

	100% {
		box-shadow: 0 0 0 10px transparent;
	}
}

@keyframes fade {
	from {
		opacity: 0;
	}
}

@keyframes rise {
	from {
		transform: translateY(40px);
		opacity: 0;
	}
}

@keyframes shimmer {
	to {
		background-position: -200% 0;
	}
}

@media (prefers-reduced-motion: reduce) {
	*,
	*::before,
	*::after {
		animation: none !important;
		transition: none !important;
	}
}
