/* Финансы — мини-приложение. Тема наследуется от Telegram, фолбэки нужны
   для открытия в обычном браузере. */

:root
{
	--bg:            var(--tg-theme-bg-color, #f2f2f7);
	--bg-elevated:   var(--tg-theme-section-bg-color, #ffffff);
	--bg-secondary:  var(--tg-theme-secondary-bg-color, #ffffff);
	--text:          var(--tg-theme-text-color, #000000);
	--text-hint:     var(--tg-theme-hint-color, #8a8a8e);
	--accent:        var(--tg-theme-button-color, #007aff);
	--accent-text:   var(--tg-theme-button-text-color, #ffffff);
	--destructive:   var(--tg-theme-destructive-text-color, #e5484d);

	/* Первая пара значений — фолбэк для WebView без color-mix: там вся
	   декларация с color-mix отбрасывается и остаётся предыдущая. */
	--separator:     rgba(128, 128, 128, 0.22);
	--fill:          rgba(128, 128, 128, 0.14);
	--fill-strong:   rgba(128, 128, 128, 0.26);

	--separator:     color-mix(in srgb, var(--text) 10%, transparent);
	--fill:          color-mix(in srgb, var(--text) 6%, transparent);
	--fill-strong:   color-mix(in srgb, var(--text) 12%, transparent);

	--positive:      #2f9e5b;
	--negative:      #e5484d;

	--radius-card:   18px;
	--radius-tile:   14px;
	--radius-pill:   999px;

	--pad:           16px;
	--tabbar-h:      calc(58px + env(safe-area-inset-bottom));

	--c1: #4a86ff;
	--c2: #e8674b;
	--c3: #3fa66b;
	--c4: #b36bd4;
	--c5: #e2a13a;
	--c6: #35b6c4;
	--c7: #d4567f;
	--c8: #7c8797;

	font: 100%/1.5 -apple-system, BlinkMacSystemFont, system-ui, "SF Pro Text", Roboto, sans-serif;
	font-optical-sizing: auto;
	-webkit-text-size-adjust: 100%;
}

*
{
	box-sizing: border-box;
	-webkit-tap-highlight-color: transparent;
}

html, body
{
	margin: 0;
	padding: 0;
	background: var(--bg);
	color: var(--text);
	overscroll-behavior-y: none;
}

body
{
	min-height: 100vh;
}

button
{
	font: inherit;
	color: inherit;
	border: 0;
	background: none;
	cursor: pointer;
}

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

[hidden]
{
	display: none !important;
}

/* -------------------------------------------------------------------------
   Загрузка
   ------------------------------------------------------------------------- */

.boot
{
	position: fixed;
	inset: 0;
	display: grid;
	place-items: center;
}

.boot__spinner
{
	width: 28px;
	height: 28px;
	border: 2.5px solid var(--fill-strong);
	border-top-color: var(--accent);
	border-radius: 50%;
	animation: spin 700ms linear infinite;
}

.boot--error
{
	padding: 0 40px;
	text-align: center;
	color: var(--text-hint);
	font-size: 15px;
	line-height: 1.45;
}

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

/* -------------------------------------------------------------------------
   Каркас
   ------------------------------------------------------------------------- */

.screens
{
	padding: 8px var(--pad) calc(var(--tabbar-h) + 24px);
	max-width: 620px;
	margin: 0 auto;
}

.screen
{
	animation: screen-in 260ms cubic-bezier(0.2, 0.8, 0.2, 1);
}

@keyframes screen-in
{
	from { opacity: 0; transform: translateY(6px); }
	to   { opacity: 1; transform: none; }
}

/* Панель вкладок — плавающий полупрозрачный слой, контент уходит под него. */
.tabbar
{
	position: fixed;
	left: 0;
	right: 0;
	bottom: 0;
	z-index: 40;
	display: grid;
	grid-template-columns: repeat(3, 1fr);
	padding-bottom: env(safe-area-inset-bottom);
	background: var(--bg);
	background: color-mix(in srgb, var(--bg) 72%, transparent);
	backdrop-filter: blur(24px) saturate(180%);
	-webkit-backdrop-filter: blur(24px) saturate(180%);
	border-top: 1px solid var(--separator);
}

.tab
{
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 3px;
	padding: 8px 0 7px;
	color: var(--text-hint);
	font-size: 10px;
	letter-spacing: 0.01em;
	transition: color 120ms ease-out, transform 120ms ease-out;
}

.tab svg
{
	width: 25px;
	height: 25px;
	fill: currentColor;
}

.tab:active
{
	transform: scale(0.93);
}

.tab.is-active
{
	color: var(--accent);
}

/* -------------------------------------------------------------------------
   Типографика и общие блоки
   ------------------------------------------------------------------------- */

.page-head
{
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 10px;
	padding: 10px 4px 14px;
}

.page-title
{
	margin: 0;
	font-size: 30px;
	font-weight: 700;
	line-height: 1.08;
	letter-spacing: -0.025em;
}

/* Крупный заголовок сам работает переключателем месяца: дублировать
   название рядом в отдельном контроле незачем. */
.title-picker
{
	position: relative;
	display: inline-flex;
	align-items: center;
	gap: 7px;
	transition: opacity 110ms ease-out;
}

.title-picker:active
{
	opacity: 0.55;
}

.title-picker select
{
	position: absolute;
	inset: 0;
	width: 100%;
	height: 100%;
	opacity: 0;
	appearance: none;
	border: 0;
	background: none;
}

.title-picker__chevron
{
	flex: 0 0 auto;
	width: 26px;
	height: 26px;
	display: grid;
	place-items: center;
	border-radius: 50%;
	background: var(--fill);
	margin-top: 4px;
}

.title-picker__chevron::after
{
	content: '';
	width: 7px;
	height: 7px;
	border-right: 2px solid var(--text-hint);
	border-bottom: 2px solid var(--text-hint);
	transform: translateY(-2px) rotate(45deg);
}

.page-sub
{
	margin: 2px 0 0;
	font-size: 13px;
	color: var(--text-hint);
	letter-spacing: 0;
}

.section-title
{
	margin: 22px 4px 9px;
	font-size: 13px;
	font-weight: 600;
	letter-spacing: 0.02em;
	text-transform: uppercase;
	color: var(--text-hint);
}

.card
{
	background: var(--bg-elevated);
	border-radius: var(--radius-card);
	padding: 16px;
	margin-bottom: 12px;
}

.card--tight
{
	padding: 6px 16px;
}

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

.nowrap
{
	white-space: nowrap;
}

/* -------------------------------------------------------------------------
   Плитки с числами
   ------------------------------------------------------------------------- */

.hero
{
	background: var(--bg-elevated);
	border-radius: var(--radius-card);
	padding: 18px 18px 16px;
	margin-bottom: 12px;
}

.hero__label
{
	font-size: 13px;
	font-weight: 600;
	color: var(--text-hint);
	letter-spacing: 0.01em;
}

.hero__value
{
	margin-top: 5px;
	font-size: 34px;
	font-weight: 700;
	line-height: 1.06;
	letter-spacing: -0.03em;
	font-variant-numeric: tabular-nums;
}

.hero__value--positive { color: var(--positive); }
.hero__value--negative { color: var(--negative); }

.hero__forecast
{
	margin-top: 8px;
	display: inline-flex;
	align-items: center;
	gap: 6px;
	padding: 5px 10px;
	border-radius: var(--radius-pill);
	background: var(--fill);
	font-size: 13px;
	color: var(--text-hint);
	font-variant-numeric: tabular-nums;
}

.hero__forecast b
{
	color: var(--text);
	font-weight: 600;
}

.hero__meta
{
	margin-top: 10px;
	font-size: 12.5px;
	color: var(--text-hint);
	line-height: 1.45;
}

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

.tile
{
	background: var(--bg-elevated);
	border-radius: var(--radius-tile);
	padding: 13px 14px;
	min-width: 0;
}

.tile__label
{
	font-size: 12px;
	color: var(--text-hint);
	letter-spacing: 0.01em;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

.tile__value
{
	margin-top: 4px;
	font-size: 21px;
	font-weight: 650;
	letter-spacing: -0.02em;
	font-variant-numeric: tabular-nums;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

.tile__hint
{
	margin-top: 3px;
	font-size: 11.5px;
	color: var(--text-hint);
	font-variant-numeric: tabular-nums;
}

.delta--up   { color: var(--positive); }
.delta--down { color: var(--negative); }

/* -------------------------------------------------------------------------
   Сегментированный переключатель и выбор месяца
   ------------------------------------------------------------------------- */

.segmented
{
	display: grid;
	grid-auto-flow: column;
	grid-auto-columns: 1fr;
	gap: 2px;
	padding: 2px;
	background: var(--fill);
	border-radius: 10px;
	margin-bottom: 14px;
}

.segmented button
{
	padding: 7px 10px;
	border-radius: 8px;
	font-size: 13.5px;
	font-weight: 550;
	color: var(--text-hint);
	transition: background 160ms ease-out, color 160ms ease-out;
}

.segmented button.is-active
{
	background: var(--bg-elevated);
	color: var(--text);
	box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

.month-picker
{
	display: inline-flex;
	align-items: center;
	gap: 4px;
	padding: 6px 8px 6px 12px;
	border-radius: var(--radius-pill);
	background: var(--fill);
	font-size: 13.5px;
	font-weight: 550;
}

.month-picker select
{
	appearance: none;
	background: none;
	border: 0;
	padding: 0 16px 0 0;
	font-size: 13.5px;
	font-weight: 550;
	outline: none;
}

.month-picker::after
{
	content: '';
	width: 8px;
	height: 8px;
	margin-left: -18px;
	border-right: 1.8px solid var(--text-hint);
	border-bottom: 1.8px solid var(--text-hint);
	transform: translateY(-2px) rotate(45deg);
	pointer-events: none;
}

/* -------------------------------------------------------------------------
   Графики
   ------------------------------------------------------------------------- */

.chart
{
	margin-bottom: 12px;
}

.chart__head
{
	display: flex;
	align-items: baseline;
	justify-content: space-between;
	gap: 10px;
	margin-bottom: 12px;
}

.chart__title
{
	font-size: 15px;
	font-weight: 600;
	letter-spacing: -0.01em;
}

.chart__peak
{
	font-size: 12px;
	color: var(--text-hint);
	font-variant-numeric: tabular-nums;
}

.chart svg
{
	display: block;
	width: 100%;
	overflow: visible;
}

.chart__bar
{
	fill: var(--c1);
	transition: opacity 120ms ease-out;
}

.chart__bar--forecast
{
	fill: var(--c1);
	opacity: 0.42;
}

.chart__bar.is-dim
{
	opacity: 0.3;
}

.chart__axis
{
	font-size: 10px;
	fill: var(--text-hint);
}

.chart__grid
{
	stroke: var(--separator);
	stroke-width: 1;
}

.chart__line
{
	fill: none;
	stroke: var(--c1);
	stroke-width: 2.2;
	stroke-linecap: round;
	stroke-linejoin: round;
}

.chart__area
{
	fill: var(--c1);
	opacity: 0.11;
}

.chart__dot
{
	fill: var(--c1);
}

.chart__readout
{
	display: flex;
	align-items: baseline;
	gap: 8px;
	margin-top: 10px;
	min-height: 20px;
	font-size: 13px;
	color: var(--text-hint);
	font-variant-numeric: tabular-nums;
}

.chart__readout b
{
	color: var(--text);
	font-size: 15px;
	font-weight: 650;
	letter-spacing: -0.01em;
}

/* Кольцевая диаграмма по категориям. */
.donut
{
	display: flex;
	align-items: center;
	gap: 18px;
}

.donut svg
{
	width: 122px;
	height: 122px;
	flex: 0 0 auto;
}

.donut__center
{
	font-variant-numeric: tabular-nums;
}

.donut__legend
{
	flex: 1 1 auto;
	min-width: 0;
	display: flex;
	flex-direction: column;
	gap: 7px;
}

.legend-row
{
	display: flex;
	align-items: center;
	gap: 8px;
	font-size: 13px;
	min-width: 0;
}

.legend-dot
{
	width: 9px;
	height: 9px;
	border-radius: 3px;
	flex: 0 0 auto;
}

.legend-title
{
	flex: 1 1 auto;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

.legend-value
{
	font-variant-numeric: tabular-nums;
	font-weight: 600;
	white-space: nowrap;
}

/* -------------------------------------------------------------------------
   Списки
   ------------------------------------------------------------------------- */

.day-group
{
	margin-bottom: 12px;
}

.day-group__head
{
	display: flex;
	align-items: baseline;
	justify-content: space-between;
	padding: 0 4px 7px;
	font-size: 13px;
	color: var(--text-hint);
}

.day-group__sum
{
	font-variant-numeric: tabular-nums;
	font-weight: 600;
}

.list
{
	background: var(--bg-elevated);
	border-radius: var(--radius-card);
	overflow: hidden;
}

.row
{
	display: flex;
	align-items: center;
	gap: 12px;
	width: 100%;
	padding: 11px 14px;
	text-align: left;
	transition: background 90ms ease-out;
}

.row:active
{
	background: var(--fill);
}

.row + .row
{
	box-shadow: inset 0 1px 0 var(--separator);
}

.row__icon
{
	width: 38px;
	height: 38px;
	flex: 0 0 auto;
	display: grid;
	place-items: center;
	border-radius: 11px;
	font-size: 18px;
	background: var(--fill);
}

.row__body
{
	flex: 1 1 auto;
	min-width: 0;
}

.row__title
{
	display: block;
	font-size: 15px;
	font-weight: 500;
	letter-spacing: -0.01em;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

.row__sub
{
	display: block;
	margin-top: 1px;
	font-size: 12.5px;
	color: var(--text-hint);
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

.row__amount
{
	display: block;
	flex: 0 0 auto;
	text-align: right;
	font-size: 15.5px;
	font-weight: 600;
	letter-spacing: -0.01em;
	font-variant-numeric: tabular-nums;
}

.row__amount small
{
	display: block;
	margin-top: 1px;
	font-size: 11.5px;
	font-weight: 400;
	color: var(--text-hint);
}

.empty
{
	padding: 34px 20px;
	text-align: center;
	color: var(--text-hint);
	font-size: 14px;
	line-height: 1.5;
}

/* -------------------------------------------------------------------------
   Кнопки
   ------------------------------------------------------------------------- */

.btn
{
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: 7px;
	padding: 13px 18px;
	border-radius: 13px;
	background: var(--accent);
	color: var(--accent-text);
	font-size: 16px;
	font-weight: 600;
	letter-spacing: -0.01em;
	transition: transform 110ms ease-out, opacity 110ms ease-out;
}

.btn:active
{
	transform: scale(0.975);
	opacity: 0.9;
}

.btn--full
{
	width: 100%;
}

.btn--ghost
{
	background: var(--fill);
	color: var(--text);
}

.btn--danger
{
	background: var(--fill);
	background: color-mix(in srgb, var(--destructive) 12%, transparent);
	color: var(--destructive);
}

.btn--small
{
	padding: 8px 13px;
	border-radius: 10px;
	font-size: 13.5px;
}

/* Плавающая кнопка добавления траты. */
.fab
{
	position: fixed;
	right: 18px;
	bottom: calc(var(--tabbar-h) + 14px);
	z-index: 35;
	width: 54px;
	height: 54px;
	border-radius: 50%;
	display: grid;
	place-items: center;
	background: var(--accent);
	color: var(--accent-text);
	box-shadow: 0 6px 20px rgba(0, 0, 0, 0.22);
	box-shadow: 0 6px 20px color-mix(in srgb, var(--accent) 38%, transparent);
	transition: transform 120ms cubic-bezier(0.2, 0.8, 0.2, 1);
}

.fab:active
{
	transform: scale(0.9);
}

.fab svg
{
	width: 26px;
	height: 26px;
	fill: currentColor;
}

/* -------------------------------------------------------------------------
   Нижняя шторка
   ------------------------------------------------------------------------- */

.scrim
{
	position: fixed;
	inset: 0;
	z-index: 50;
	background: rgba(0, 0, 0, 0.42);
	opacity: 0;
	will-change: opacity;
}

.sheet
{
	position: fixed;
	left: 0;
	right: 0;
	bottom: 0;
	z-index: 51;
	max-height: 92vh;
	display: flex;
	flex-direction: column;
	background: var(--bg-secondary);
	border-radius: 20px 20px 0 0;
	box-shadow: 0 -8px 40px rgba(0, 0, 0, 0.22);
	transform: translate3d(0, 100%, 0);
	will-change: transform;
	touch-action: none;
}

.sheet__inner
{
	max-width: 620px;
	width: 100%;
	margin: 0 auto;
	display: flex;
	flex-direction: column;
	min-height: 0;
}

.sheet__grip
{
	padding: 9px 0 4px;
	display: grid;
	place-items: center;
	flex: 0 0 auto;
}

.sheet__grip i
{
	width: 38px;
	height: 5px;
	border-radius: 3px;
	background: var(--fill-strong);
}

.sheet__head
{
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 10px;
	padding: 4px 18px 10px;
	flex: 0 0 auto;
}

.sheet__title
{
	font-size: 19px;
	font-weight: 650;
	letter-spacing: -0.02em;
}

.sheet__body
{
	padding: 0 18px 18px;
	overflow-y: auto;
	overscroll-behavior: contain;
	-webkit-overflow-scrolling: touch;
	touch-action: pan-y;
	padding-bottom: calc(18px + env(safe-area-inset-bottom));
}

/* -------------------------------------------------------------------------
   Формы
   ------------------------------------------------------------------------- */

.field
{
	margin-bottom: 13px;
}

.field__label
{
	display: block;
	margin: 0 0 6px 2px;
	font-size: 12.5px;
	font-weight: 600;
	color: var(--text-hint);
	letter-spacing: 0.01em;
}

.field__control
{
	width: 100%;
	padding: 13px 14px;
	border-radius: 12px;
	background: var(--fill);
	border: 1.5px solid transparent;
	outline: none;
	font-size: 16px;
	transition: border-color 140ms ease-out;
}

.field__control:focus
{
	border-color: var(--accent);
}

.field__row
{
	display: grid;
	grid-template-columns: 1fr 104px;
	gap: 9px;
}

.field__hint
{
	margin: 6px 2px 0;
	font-size: 12px;
	color: var(--text-hint);
}

.chips
{
	display: flex;
	flex-wrap: wrap;
	gap: 7px;
}

.chip
{
	padding: 8px 13px;
	border-radius: var(--radius-pill);
	background: var(--fill);
	font-size: 13.5px;
	font-weight: 500;
	transition: background 130ms ease-out, color 130ms ease-out, transform 110ms ease-out;
}

.chip:active
{
	transform: scale(0.95);
}

.chip.is-active
{
	background: var(--accent);
	color: var(--accent-text);
}

.chip--add
{
	background: transparent;
	box-shadow: inset 0 0 0 1.5px var(--fill-strong);
	color: var(--text-hint);
}

.form-actions
{
	display: flex;
	gap: 9px;
	margin-top: 18px;
}

.form-actions .btn
{
	flex: 1 1 auto;
}

.form-error
{
	margin: 10px 2px 0;
	font-size: 13.5px;
	color: var(--destructive);
}

/* -------------------------------------------------------------------------
   Тосты
   ------------------------------------------------------------------------- */

.toast-root
{
	position: fixed;
	left: 0;
	right: 0;
	bottom: calc(var(--tabbar-h) + 16px);
	z-index: 60;
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 8px;
	pointer-events: none;
}

.toast
{
	max-width: min(420px, calc(100vw - 32px));
	padding: 11px 17px;
	border-radius: var(--radius-pill);
	background: rgba(40, 40, 40, 0.94);
	background: color-mix(in srgb, var(--text) 88%, transparent);
	color: var(--bg);
	font-size: 14px;
	font-weight: 500;
	box-shadow: 0 6px 22px rgba(0, 0, 0, 0.2);
	animation: toast-in 240ms cubic-bezier(0.2, 0.8, 0.2, 1);
}

.toast--error
{
	background: var(--destructive);
	color: #fff;
}

@keyframes toast-in
{
	from { opacity: 0; transform: translateY(10px) scale(0.96); }
	to   { opacity: 1; transform: none; }
}

/* -------------------------------------------------------------------------
   Доступность
   ------------------------------------------------------------------------- */

@media (prefers-reduced-motion: reduce)
{
	*, *::before, *::after
	{
		animation-duration: 0.01ms !important;
		animation-iteration-count: 1 !important;
		transition-duration: 120ms !important;
	}

	.screen
	{
		animation: none;
	}
}

@media (prefers-reduced-transparency: reduce)
{
	.tabbar
	{
		background: var(--bg);
		backdrop-filter: none;
		-webkit-backdrop-filter: none;
	}
}

@media (prefers-contrast: more)
{
	.card, .tile, .hero, .list
	{
		box-shadow: inset 0 0 0 1px var(--separator);
	}
}
