:root {
  color-scheme: light;
  --bg: var(--tg-theme-bg-color, #f4f7fb);
  --surface: var(--tg-theme-section-bg-color, var(--tg-theme-secondary-bg-color, #ffffff));
  --ink: var(--tg-theme-text-color, #11223d);
  --muted: var(--tg-theme-hint-color, #687a96);
  --border: var(--tg-theme-section-separator-color, #dce5f0);
  --border-strong: #c7d4e4;
  --blue: var(--tg-theme-link-color, #1768e5);
  --income: #078f4c;
  --income-strong: #057b41;
  --income-soft: #eaf8f0;
  --expense: #e43e48;
  --expense-soft: #fff0f1;
  --net: #7357d8;
  --net-strong: #6043c8;
  --net-soft: #f1effc;
  --focus: var(--tg-theme-accent-text-color, var(--tg-theme-button-color, #3b82f6));
  --radius: 14px;
  --radius-control: 10px;
  --shadow: 0 1px 2px rgb(23 45 77 / 5%), 0 10px 30px rgb(23 45 77 / 4%);
  --ui: "Segoe UI Variable", "Segoe UI", Arial, sans-serif;
  --data: "Bahnschrift", "Arial Narrow", "Segoe UI", sans-serif;
  --mono: "Cascadia Mono", "Consolas", monospace;
  --telegram-safe-top: 0px;
  --telegram-safe-right: 0px;
  --telegram-safe-bottom: 0px;
  --telegram-safe-left: 0px;
  --app-safe-top: max(env(safe-area-inset-top, 0px), var(--tg-safe-area-inset-top, 0px), var(--tg-content-safe-area-inset-top, 0px), var(--telegram-safe-top));
  --app-safe-right: max(env(safe-area-inset-right, 0px), var(--tg-safe-area-inset-right, 0px), var(--tg-content-safe-area-inset-right, 0px), var(--telegram-safe-right));
  --app-safe-bottom: max(env(safe-area-inset-bottom, 0px), var(--tg-safe-area-inset-bottom, 0px), var(--tg-content-safe-area-inset-bottom, 0px), var(--telegram-safe-bottom));
  --app-safe-left: max(env(safe-area-inset-left, 0px), var(--tg-safe-area-inset-left, 0px), var(--tg-content-safe-area-inset-left, 0px), var(--telegram-safe-left));
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html { min-width: 320px; min-height: 100%; background: var(--bg); }

body {
  margin: 0;
  min-height: var(--telegram-viewport-height, var(--tg-viewport-stable-height, 100dvh));
  color: var(--ink);
  background: var(--bg);
  font-family: var(--ui);
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
}

button, input, select { font: 600 15px/1.2 var(--ui); color: var(--ink); }
button, select { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .48; }

:focus-visible {
  outline: 3px solid rgb(59 130 246 / 24%);
  outline-offset: 2px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.skip-link { position: fixed; z-index: 30; top: 8px; left: 8px; padding: 10px 14px; transform: translateY(-150%); border-radius: 8px; color: white; background: var(--blue); text-decoration: none; }
.skip-link:focus { transform: translateY(0); }

.shell { width: min(1380px, calc(100% - 48px)); margin: 0 auto; padding: calc(22px + var(--app-safe-top)) var(--app-safe-right) calc(40px + var(--app-safe-bottom)) var(--app-safe-left); }

.topbar { display: flex; align-items: center; justify-content: space-between; gap: 24px; min-height: 48px; margin-bottom: 16px; }
.brand-lockup { display: flex; align-items: center; gap: 18px; min-width: 0; }
.brand-lockup h1 { margin: 0; font: 700 38px/.95 var(--data); letter-spacing: -.04em; }
.sync-state { display: inline-flex; align-items: center; gap: 9px; color: var(--muted); font-size: 14px; white-space: nowrap; }
.sync-dot { width: 10px; height: 10px; border-radius: 50%; background: #22bd6b; box-shadow: 0 0 0 4px rgb(34 189 107 / 10%); }
.sync-state.is-error .sync-dot { background: var(--expense); box-shadow: 0 0 0 4px rgb(228 62 72 / 10%); }

.period-switch { display: grid; grid-template-columns: repeat(3, 1fr); padding: 3px; border: 1px solid var(--border-strong); border-radius: 11px; background: rgb(255 255 255 / 72%); }
.period-switch button { min-width: 108px; min-height: 40px; padding: 0 16px; border: 0; border-radius: 8px; background: transparent; color: #3e506d; font-size: 14px; }
.period-switch button.is-active { color: var(--blue); background: var(--surface); box-shadow: 0 1px 5px rgb(20 42 74 / 12%); }

.workspace-switch { width: fit-content; margin: 0 0 14px; padding: 4px; display: grid; grid-template-columns: 1fr 1fr; border: 1px solid var(--border-strong); border-radius: 12px; background: rgb(255 255 255 / 72%); }
.workspace-switch button { min-width: 180px; min-height: 44px; padding: 0 18px; border: 0; border-radius: 8px; color: #435674; background: transparent; }
.workspace-switch button.is-active { color: white; background: #203a62; box-shadow: 0 4px 12px rgb(21 45 80 / 16%); }
.workspace-switch button[data-section="net-percent"].is-active { background: var(--net); box-shadow: 0 4px 12px rgb(115 87 216 / 20%); }

.summary-strip, .entry-panel, .operations-panel { border: 1px solid var(--border); background: rgb(255 255 255 / 92%); box-shadow: var(--shadow); }
.summary-strip { display: grid; grid-template-columns: repeat(3, 1fr) minmax(160px, .65fr); border-radius: var(--radius); margin-bottom: 14px; overflow: hidden; }
.summary-stat, .summary-meta { min-width: 0; min-height: 112px; padding: 22px 30px; display: flex; flex-direction: column; justify-content: center; }
.summary-stat + .summary-stat, .summary-meta { border-left: 1px solid var(--border); }
.summary-stat span, .summary-meta label { color: var(--muted); font-size: 14px; }
.summary-stat strong { margin-top: 6px; overflow: hidden; font: 700 34px/1 var(--data); letter-spacing: -.025em; font-variant-numeric: tabular-nums; text-overflow: ellipsis; white-space: nowrap; }
.income-stat strong { color: var(--income-strong); }
.expense-stat strong { color: var(--expense); }
.payout-stat strong { color: #516783; }
.net-stat strong { color: var(--net-strong); }
.summary-meta { gap: 8px; }
.summary-meta select { width: 100%; height: 34px; padding: 0 30px 0 9px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); font-size: 13px; }
.summary-meta span { color: var(--muted); font-size: 12px; }

.entry-panel { padding: 18px; border-radius: var(--radius); margin-bottom: 14px; }
#entry-form { display: grid; grid-template-columns: minmax(210px, 1.2fr) minmax(170px, .9fr) minmax(150px, .8fr) 145px 100px minmax(190px, 1fr) minmax(170px, .85fr); gap: 14px; align-items: end; }
.mode-switch { grid-column: 1 / -1; width: 310px; display: grid; grid-template-columns: 1fr 1fr; padding: 3px; border-radius: 11px; background: #eef3f8; }
.mode-button { height: 42px; border: 0; border-radius: 8px; background: transparent; display: flex; align-items: center; justify-content: center; gap: 8px; color: #40516d; }
.mode-button svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.mode-button.is-active[data-kind="income"] { color: white; background: var(--income); box-shadow: 0 4px 12px rgb(7 143 76 / 18%); }
.mode-button.is-active[data-kind="expense"] { color: white; background: var(--expense); box-shadow: 0 4px 12px rgb(228 62 72 / 16%); }

.field { display: flex; flex-direction: column; gap: 7px; min-width: 0; }
.field label { color: #425471; font-size: 13px; font-weight: 650; }
.field label span { color: var(--muted); font-weight: 500; }
.field input, .field select, .search-control input { width: 100%; height: 48px; border: 1px solid var(--border-strong); border-radius: var(--radius-control); background: var(--surface); padding: 0 14px; transition: border-color .15s, box-shadow .15s; }
.field input:hover, .field select:hover, .search-control:hover { border-color: #aebfd3; }
.field input:focus, .field select:focus, .search-control:focus-within { outline: 0; border-color: var(--focus); box-shadow: 0 0 0 3px rgb(59 130 246 / 13%); }
.field small { color: var(--muted); font-size: 12px; font-weight: 500; }
.amount-field input { padding-right: 44px; font: 600 18px/1 var(--data); font-variant-numeric: tabular-nums; }
.input-shell { position: relative; }
.clear-input { position: absolute; right: 8px; top: 8px; }
.icon-button { width: 32px; height: 32px; padding: 0; display: inline-grid; place-items: center; color: #536681; border: 0; border-radius: 8px; background: transparent; }
.icon-button:hover { background: #eef3f8; color: var(--ink); }
.icon-button svg, .undo-button svg, .search-control svg, .row-action svg, .calendar-arrow svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.equation-box { min-height: 48px; padding: 7px 14px; display: flex; flex-direction: column; align-items: center; justify-content: center; border-radius: var(--radius-control); background: var(--income-soft); color: #3d5670; text-align: center; }
.equation-box span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font: 500 12px/1.2 var(--mono); }
.equation-box strong { color: var(--income-strong); font: 700 22px/1.1 var(--data); font-variant-numeric: tabular-nums; }
.entry-panel[data-kind="expense"] .equation-box { background: var(--expense-soft); }
.entry-panel[data-kind="expense"] .equation-box strong { color: var(--expense); }

.primary-action, .secondary-action, .danger-action { min-height: 48px; padding: 0 20px; border-radius: var(--radius-control); border: 0; font-size: 14px; white-space: nowrap; }
.primary-action { color: white; background: var(--income); box-shadow: 0 6px 16px rgb(7 143 76 / 16%); }
.entry-panel[data-kind="expense"] .primary-action { background: var(--expense); box-shadow: 0 6px 16px rgb(228 62 72 / 14%); }
.primary-action:hover:not(:disabled) { filter: brightness(.94); }
.secondary-action { color: var(--ink); border: 1px solid var(--border-strong); background: var(--surface); }
.danger-action { color: white; background: var(--expense); }
.form-error { grid-column: 1 / -1; margin: 0; color: #bd2832; font-size: 13px; }

.net-summary-meta strong { color: var(--net-strong); font: 750 21px/1 var(--data); font-variant-numeric: tabular-nums; }
.net-entry-panel { border-top: 3px solid var(--net); }
.net-panel-heading { margin-bottom: 16px; display: flex; align-items: end; justify-content: space-between; gap: 20px; }
.net-panel-heading span { color: var(--net); font-size: 12px; font-weight: 750; text-transform: uppercase; letter-spacing: .06em; }
.net-panel-heading h2 { margin: 3px 0 0; font: 700 25px/1 var(--data); letter-spacing: -.02em; }
.net-panel-heading p { margin: 0; color: var(--muted); font-size: 13px; }
#net-entry-form { display: grid; grid-template-columns: minmax(170px, 1fr) minmax(170px, 1fr) minmax(270px, 1.35fr) 145px 100px minmax(190px, 1fr) minmax(165px, .8fr); gap: 14px; align-items: end; }
.net-live-result { min-height: 72px; padding: 10px 14px; display: grid; grid-template-columns: 1fr 1fr; gap: 7px 14px; border-radius: var(--radius-control); background: var(--net-soft); }
.net-live-result div { min-width: 0; display: flex; flex-direction: column; justify-content: center; }
.net-live-result div + div { padding-left: 14px; border-left: 1px solid rgb(115 87 216 / 18%); }
.net-live-result span { color: #625b7e; font-size: 11px; }
.net-live-result strong { margin-top: 3px; overflow: hidden; color: var(--net-strong); font: 750 22px/1 var(--data); font-variant-numeric: tabular-nums; text-overflow: ellipsis; white-space: nowrap; }
.net-live-result small { grid-column: 1 / -1; overflow: hidden; color: #756d8e; font: 500 10px/1.2 var(--mono); text-overflow: ellipsis; white-space: nowrap; }
.net-primary-action { background: var(--net); box-shadow: 0 6px 16px rgb(115 87 216 / 18%); }
.net-operations-toolbar { grid-template-columns: auto minmax(220px, 430px); justify-content: space-between; }
.net-operations-toolbar .search-control { justify-self: end; width: 100%; }
.net-table th:nth-child(1) { width: 130px; }
.net-table th:nth-child(2), .net-table th:nth-child(3), .net-table th:nth-child(4) { width: 145px; }
.net-table th:nth-child(5) { width: 105px; }
.net-table th:nth-child(6) { width: auto; }
.net-table th:nth-child(7) { width: 110px; }
.net-money { display: block; max-width: 100%; overflow: hidden; font: 700 15px/1 var(--data); font-variant-numeric: tabular-nums; text-overflow: ellipsis; white-space: nowrap; }
.net-money.sum { color: var(--income); }
.net-money.payout { color: #516783; }
.net-money.balance, .net-rate { color: var(--net-strong); }
.net-rate { font: 750 15px/1 var(--data); font-variant-numeric: tabular-nums; white-space: nowrap; }
.net-note { overflow: hidden; color: var(--muted); text-overflow: ellipsis; white-space: nowrap; }

.operations-panel { border-radius: var(--radius); overflow: hidden; }
.operations-toolbar { min-height: 72px; padding: 13px 18px; display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 22px; border-bottom: 1px solid var(--border); }
.operations-toolbar h2 { margin: 0; font: 700 24px/1 var(--data); letter-spacing: -.02em; }
.operations-title { display: flex; align-items: center; gap: 14px; }
.view-switch { display: grid; grid-template-columns: 1fr 1fr; padding: 3px; border-radius: 9px; background: #eef3f8; }
.view-switch button { min-height: 34px; padding: 0 12px; border: 0; border-radius: 7px; background: transparent; color: #536681; font-size: 12px; }
.view-switch button.is-active { color: var(--blue); background: var(--surface); box-shadow: 0 1px 5px rgb(20 42 74 / 10%); }
.history-controls { display: flex; align-items: center; gap: 10px; max-width: 700px; }
.select-control select { height: 42px; min-width: 170px; padding: 0 34px 0 12px; border: 1px solid var(--border-strong); border-radius: 9px; background: var(--surface); font-size: 13px; }
.search-control { height: 42px; min-width: 220px; max-width: 430px; flex: 1; display: flex; align-items: center; gap: 9px; padding: 0 12px; border: 1px solid var(--border-strong); border-radius: 9px; background: var(--surface); }
.search-control input { height: auto; padding: 0; border: 0; border-radius: 0; box-shadow: none !important; font-weight: 500; }
.search-control svg { flex: 0 0 18px; color: #526984; }
.undo-button { min-height: 40px; padding: 0 4px; display: flex; align-items: center; gap: 8px; border: 0; background: transparent; color: var(--blue); font-size: 13px; }
.undo-button:hover:not(:disabled) { color: #0d4fb9; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; table-layout: fixed; }
th { height: 42px; padding: 0 18px; color: #546680; background: #f8fafc; border-bottom: 1px solid var(--border); font-size: 12px; text-align: left; }
td { height: 58px; padding: 9px 18px; border-bottom: 1px solid var(--border); color: #263a57; font-size: 13px; vertical-align: middle; }
th:nth-child(1) { width: 150px; }
th:nth-child(2) { width: 180px; }
th:nth-child(3) { width: 140px; }
th:nth-child(5) { width: 150px; }
th:nth-child(6) { width: 110px; }
tbody tr:hover { background: #f9fbfd; }
.type-label { display: inline-flex; align-items: center; gap: 7px; font-weight: 650; }
.type-label::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.type-label.income, .signed-amount.income { color: var(--income); }
.type-label.expense, .signed-amount.expense { color: var(--expense); }
.calculation { color: var(--muted); font-family: var(--mono); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.signed-amount { font: 700 16px/1 var(--data); font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.actions { display: flex; justify-content: flex-end; gap: 3px; }
.row-action { width: 32px; height: 32px; display: grid; place-items: center; border: 0; border-radius: 8px; background: transparent; color: #4c617c; }
.row-action:hover { background: #edf3f8; color: var(--ink); }
.row-action.delete:hover { color: var(--expense); background: var(--expense-soft); }
.operations-footer { min-height: 48px; padding: 0 18px; display: flex; justify-content: space-between; align-items: center; color: var(--muted); font-size: 12px; }
.empty-state { min-height: 180px; display: grid; place-content: center; gap: 6px; text-align: center; color: var(--muted); }
.empty-state strong { color: var(--ink); font-size: 16px; }

.operations-panel[data-view="calendar"] .search-control { display: none; }
.calendar-view { padding: 0 18px 18px; }
.calendar-toolbar { min-height: 64px; display: flex; align-items: center; justify-content: space-between; gap: 18px; }
.calendar-navigation { display: flex; align-items: center; gap: 8px; }
.calendar-navigation h3 { min-width: 190px; margin: 0; text-align: center; font: 700 20px/1.1 var(--data); }
.calendar-arrow { width: 44px; height: 44px; padding: 0; display: grid; place-items: center; border: 1px solid var(--border); border-radius: 9px; background: var(--surface); color: #405675; }
.calendar-arrow:hover { border-color: #aebfd3; color: var(--blue); }
.calendar-today { min-height: 44px; padding: 0 12px; border: 0; border-radius: 8px; background: #edf4ff; color: var(--blue); font-size: 12px; }
.calendar-legend { display: flex; align-items: center; gap: 16px; color: var(--muted); font-size: 12px; }
.calendar-legend span::before { content: ""; display: inline-block; width: 7px; height: 7px; margin-right: 6px; border-radius: 50%; background: currentColor; }
.calendar-legend .income, .daily-summary .income { color: var(--income); }
.calendar-legend .expense, .daily-summary .expense { color: var(--expense); }
.calendar-legend .profit { color: var(--blue); }
.calendar-legend .other { color: #8b5cf6; }
.calendar-layout { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 18px; }
.calendar-main { min-width: 0; }
.calendar-weekdays, .calendar-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 6px; }
.calendar-weekdays { margin-bottom: 6px; color: var(--muted); font-size: 11px; font-weight: 700; text-align: center; text-transform: uppercase; }
.calendar-weekdays span { padding: 5px 0; }
.calendar-grid { align-items: stretch; }
.calendar-day { min-width: 0; min-height: 96px; padding: 8px; display: flex; flex-direction: column; gap: 3px; overflow: hidden; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); color: var(--ink); text-align: left; touch-action: manipulation; }
.calendar-day:nth-child(7n), .calendar-day:nth-child(7n - 1) { background: #fafbfd; }
.calendar-day:hover { border-color: #adc3de; background: #f8fbff; }
.calendar-day.is-selected { border-color: var(--blue); box-shadow: 0 0 0 2px rgb(23 104 229 / 12%); background: #f8fbff; }
.calendar-day.is-empty { visibility: hidden; pointer-events: none; }
.day-top { display: flex; align-items: center; justify-content: space-between; gap: 4px; }
.day-markers { min-width: 0; display: flex; align-items: center; gap: 5px; }
.day-number { width: 24px; height: 24px; display: inline-grid; place-items: center; border-radius: 50%; font: 700 12px/1 var(--data); }
.calendar-day.is-today .day-number { color: white; background: var(--blue); }
.day-count { color: var(--muted); font-size: 10px; white-space: nowrap; }
.other-currency { width: 6px; height: 6px; flex: 0 0 6px; border-radius: 50%; background: #8b5cf6; }
.day-values { min-width: 0; margin-top: auto; display: grid; gap: 2px; font: 650 11px/1.15 var(--data); font-variant-numeric: tabular-nums; }
.day-value { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.day-income { color: var(--income); }
.day-expense { color: var(--expense); }
.day-profit { margin-top: 2px; padding-top: 4px; border-top: 1px solid var(--border); color: var(--ink); font-weight: 800; }
.day-profit.is-negative { color: var(--expense); }

.daily-panel { min-width: 0; align-self: start; border: 1px solid var(--border); border-radius: 12px; background: #fbfcfe; overflow: hidden; }
.daily-header { min-height: 64px; padding: 12px 14px; display: flex; align-items: center; justify-content: space-between; gap: 10px; border-bottom: 1px solid var(--border); }
.daily-header span { color: var(--muted); font-size: 11px; }
.daily-header h3 { margin: 3px 0 0; font: 700 18px/1.1 var(--data); }
.compact-action { min-height: 36px; padding: 0 12px; font-size: 12px; }
.daily-summary { display: grid; grid-template-columns: repeat(3, 1fr); border-bottom: 1px solid var(--border); background: var(--surface); }
.daily-summary div { min-width: 0; padding: 10px 8px; }
.daily-summary div + div { border-left: 1px solid var(--border); }
.daily-summary span { display: block; margin-bottom: 4px; color: var(--muted); font-size: 10px; }
.daily-summary strong { display: block; overflow: hidden; text-overflow: ellipsis; font: 700 14px/1 var(--data); white-space: nowrap; }
.daily-rows { max-height: 410px; overflow-y: auto; }
.daily-row { min-height: 64px; padding: 10px 10px 10px 12px; display: grid; grid-template-columns: minmax(0, 1fr) auto auto; align-items: center; gap: 8px; border-bottom: 1px solid var(--border); background: var(--surface); }
.daily-row-main { min-width: 0; }
.daily-row-title { display: flex; align-items: center; gap: 7px; font-size: 12px; font-weight: 750; }
.daily-row-title::before { content: ""; width: 6px; height: 6px; flex: 0 0 6px; border-radius: 50%; background: currentColor; }
.daily-row-title.income { color: var(--income); }
.daily-row-title.expense { color: var(--expense); }
.daily-row-note { margin-top: 4px; overflow: hidden; color: var(--muted); font: 500 10px/1.2 var(--mono); text-overflow: ellipsis; white-space: nowrap; }
.daily-row-amount { font: 750 13px/1 var(--data); font-variant-numeric: tabular-nums; white-space: nowrap; }
.daily-row-amount.income { color: var(--income); }
.daily-row-amount.expense { color: var(--expense); }
.daily-row .actions { display: grid; grid-template-columns: repeat(2, 44px); }
.daily-row .row-action { width: 44px; height: 44px; }
.daily-empty { min-height: 130px; padding: 24px; display: grid; place-items: center; color: var(--muted); font-size: 13px; text-align: center; }
.daily-footer { min-height: 38px; padding: 0 12px; display: flex; align-items: center; color: var(--muted); font-size: 11px; }

.modal { width: min(520px, calc(100% - 32px)); padding: 0; overflow: auto; overscroll-behavior: contain; border: 1px solid var(--border); border-radius: 16px; background: var(--surface); color: var(--ink); box-shadow: 0 22px 70px rgb(20 42 72 / 20%); }
.modal::backdrop { background: rgb(17 34 61 / 32%); backdrop-filter: blur(2px); }
.modal form { padding: 22px; }
.modal-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; }
.modal h2 { margin: 0; font: 700 22px/1.15 var(--data); }
.modal p { color: var(--muted); }
.modal-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.modal-grid .full { grid-column: 1 / -1; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }
.confirm-modal { max-width: 420px; }
.toast { position: fixed; z-index: 20; left: 50%; bottom: calc(24px + var(--app-safe-bottom)); transform: translateX(-50%); max-width: min(440px, calc(100% - 32px)); padding: 12px 16px; border-radius: 10px; color: white; background: #172a46; box-shadow: 0 12px 30px rgb(17 34 61 / 24%); font-size: 13px; }

html.telegram-mini-app body { overscroll-behavior-y: none; }
html.telegram-mini-app input::placeholder { color: var(--muted); }
html.telegram-mini-app .summary-strip,
html.telegram-mini-app .entry-panel,
html.telegram-mini-app .operations-panel,
html.telegram-mini-app .modal,
html.telegram-mini-app .daily-row,
html.telegram-mini-app .calendar-day { background: var(--surface); color: var(--ink); }
html.telegram-mini-app .workspace-switch { background: color-mix(in srgb, var(--ink) 6%, var(--surface)); }
html.telegram-mini-app .period-switch,
html.telegram-mini-app .mode-switch,
html.telegram-mini-app .view-switch,
html.telegram-mini-app th,
html.telegram-mini-app .daily-panel { background: color-mix(in srgb, var(--ink) 6%, var(--surface)); }
html.telegram-mini-app .period-switch button,
html.telegram-mini-app .mode-button,
html.telegram-mini-app .view-switch button,
html.telegram-mini-app .field label,
html.telegram-mini-app .icon-button,
html.telegram-mini-app .calendar-arrow { color: var(--muted); }
html.telegram-mini-app .period-switch button.is-active,
html.telegram-mini-app .view-switch button.is-active { color: var(--blue); background: var(--surface); }
html.telegram-mini-app .field input:hover,
html.telegram-mini-app .field select:hover,
html.telegram-mini-app .search-control:hover { border-color: var(--muted); }
html.telegram-mini-app .equation-box { background: color-mix(in srgb, var(--income) 12%, var(--surface)); }
html.telegram-mini-app .net-live-result { background: color-mix(in srgb, var(--net) 12%, var(--surface)); }
html.telegram-mini-app .entry-panel[data-kind="expense"] .equation-box,
html.telegram-mini-app .row-action.delete:hover { background: color-mix(in srgb, var(--expense) 12%, var(--surface)); }
html.telegram-mini-app tbody tr:hover,
html.telegram-mini-app .calendar-day:hover,
html.telegram-mini-app .calendar-day.is-selected { background: color-mix(in srgb, var(--blue) 7%, var(--surface)); }
html.telegram-mini-app .calendar-today { color: var(--blue); background: color-mix(in srgb, var(--blue) 10%, var(--surface)); }
html.telegram-mini-app .modal { max-height: calc(var(--telegram-viewport-height, 100dvh) - var(--app-safe-top) - var(--app-safe-bottom) - 24px); }

@media (max-width: 1320px) {
  #entry-form { grid-template-columns: 1.4fr 1fr 1fr .65fr; }
  .mode-switch { grid-column: 1 / 3; }
  .amount-field { grid-column: 1 / 2; }
  .equation-box { grid-column: 2 / 3; }
  .day-field { grid-column: 1 / 2; }
  .note-field { grid-column: 2 / 4; }
  .primary-action { grid-column: 4 / 5; }
  .calendar-layout { grid-template-columns: minmax(0, 1fr) 300px; gap: 14px; }
  .calendar-day { min-height: 88px; }
  #net-entry-form { grid-template-columns: 1fr 1fr 1.35fr .75fr; }
  .net-live-result { grid-column: 3 / 5; }
  #net-entry-form .day-field { grid-column: 1 / 2; }
  #net-entry-form .currency-field { grid-column: 2 / 3; }
  #net-entry-form .note-field { grid-column: 3 / 4; }
  #net-entry-form .net-primary-action { grid-column: 4 / 5; }
}

@media (max-width: 760px) {
  body { font-size: 14px; }
  .shell { width: calc(100% - 24px); padding: calc(16px + var(--app-safe-top)) var(--app-safe-right) calc(28px + var(--app-safe-bottom)) var(--app-safe-left); }
  .topbar { align-items: flex-start; flex-direction: column; gap: 15px; }
  .brand-lockup { width: 100%; justify-content: space-between; gap: 10px; }
  .brand-lockup h1 { font-size: 34px; }
  .sync-state { font-size: 12px; }
  .period-switch { width: 100%; }
  .period-switch button { min-width: 0; padding: 0 7px; }
  .workspace-switch { width: 100%; }
  .workspace-switch button { min-width: 0; min-height: 46px; padding: 0 9px; }
  .summary-strip { grid-template-columns: repeat(3, 1fr); }
  .summary-stat { min-height: 96px; padding: 16px 12px; }
  .summary-stat strong { font-size: clamp(20px, 6vw, 27px); }
  .summary-stat + .summary-stat { border-left: 1px solid var(--border); }
  .summary-meta { grid-column: 1 / -1; min-height: 48px; padding: 8px 12px; border-left: 0; border-top: 1px solid var(--border); flex-direction: row; align-items: center; justify-content: space-between; }
  .summary-meta label { display: none; }
  .summary-meta select { width: 92px; }
  .entry-panel { padding: 12px; }
  #entry-form { display: grid; grid-template-columns: 1fr 1fr; gap: 13px 10px; }
  .mode-switch, .amount-field, .equation-box, .team-field, .note-field, .primary-action, .form-error { grid-column: 1 / -1; width: 100%; }
  .day-field { grid-column: 1 / 2; }
  .currency-field { grid-column: 2 / 3; }
  .field input, .field select { height: 52px; }
  .equation-box { min-height: 58px; align-items: flex-start; text-align: left; }
  .equation-box span { font-size: 13px; }
  .equation-box strong { font-size: 24px; }
  .primary-action { min-height: 54px; font-size: 16px; }
  .net-panel-heading { align-items: flex-start; flex-direction: column; gap: 6px; }
  .net-panel-heading p { line-height: 1.35; }
  #net-entry-form { grid-template-columns: 1fr 1fr; gap: 13px 10px; }
  #net-entry-form .amount-field, #net-entry-form .net-live-result, #net-entry-form .note-field, #net-entry-form .net-primary-action, #net-entry-form .form-error { grid-column: 1 / -1; width: 100%; }
  #net-entry-form .day-field { grid-column: 1 / 2; }
  #net-entry-form .currency-field { grid-column: 2 / 3; }
  .net-live-result { min-height: 82px; }
  .net-live-result strong { font-size: 23px; }
  .net-operations-toolbar { grid-template-columns: 1fr; }
  .net-operations-toolbar .search-control { justify-self: stretch; max-width: none; }
  .operations-toolbar { padding: 16px 12px 12px; grid-template-columns: 1fr auto; gap: 12px; }
  .operations-toolbar h2 { font-size: 23px; }
  .operations-title { min-width: 0; gap: 10px; }
  .view-switch button { padding: 0 8px; font-size: 11px; }
  .view-switch button { min-height: 44px; }
  .history-controls { grid-column: 1 / -1; grid-row: 2; width: 100%; }
  .select-control { width: 42%; }
  .select-control select { width: 100%; min-width: 0; }
  .search-control { width: 58%; min-width: 0; }
  .operations-panel[data-view="calendar"] .select-control { width: 100%; }
  .undo-button { grid-column: 2; grid-row: 1; }
  .undo-button { font-size: 0; width: 40px; justify-content: center; }
  .undo-button svg { width: 22px; height: 22px; }
  .table-wrap { overflow: visible; }
  table, tbody { display: block; }
  thead { display: none; }
  tbody tr { min-height: 84px; padding: 13px 12px; display: grid; grid-template-columns: 86px minmax(0, 1fr) auto 88px; grid-template-rows: auto auto; gap: 4px 9px; border-bottom: 1px solid var(--border); }
  td { height: auto; min-width: 0; padding: 0; border: 0; display: block; }
  td::before { display: none; }
  td:nth-child(1) { grid-column: 1; grid-row: 1 / 3; color: var(--muted); font-size: 12px; }
  td:nth-child(2) { grid-column: 2; grid-row: 1; color: var(--ink); font-weight: 700; }
  td:nth-child(3) { grid-column: 2; grid-row: 2; }
  td:nth-child(4) { grid-column: 2; grid-row: 3; }
  td:nth-child(5) { grid-column: 3; grid-row: 1 / 3; align-self: center; }
  td:nth-child(6) { grid-column: 4; grid-row: 1 / 3; align-self: center; }
  .type-label { font-size: 12px; }
  .calculation { max-width: 170px; }
  .actions { gap: 0; }
  .row-action { width: 44px; height: 44px; }
  .net-table tbody tr { min-height: 104px; grid-template-columns: 76px minmax(0, 1fr) minmax(0, 1fr) 88px; grid-template-rows: auto auto auto; }
  .net-table td:nth-child(1) { grid-column: 1; grid-row: 1 / 4; }
  .net-table td:nth-child(2) { grid-column: 2; grid-row: 1; color: var(--income); }
  .net-table td:nth-child(3) { grid-column: 2; grid-row: 2; color: #516783; }
  .net-table td:nth-child(4) { grid-column: 3; grid-row: 1; }
  .net-table td:nth-child(5) { grid-column: 3; grid-row: 2; }
  .net-table td:nth-child(6) { grid-column: 2 / 4; grid-row: 3; max-width: none; }
  .net-table td:nth-child(7) { grid-column: 4; grid-row: 1 / 4; align-self: center; }
  .net-table td[data-label]::before { content: attr(data-label); display: block; margin-bottom: 2px; color: var(--muted); font: 600 9px/1 var(--ui); }
  .net-table td:nth-child(6)::before { display: inline; margin: 0 4px 0 0; }
  .net-table .actions { display: grid; grid-template-columns: repeat(2, 44px); }
  .operations-footer { padding: 0 12px; }
  .operations-footer span:last-child { display: none; }
  .calendar-view { padding: 0 12px 12px; }
  .calendar-toolbar { min-height: 58px; flex-wrap: wrap; gap: 6px 12px; }
  .calendar-navigation { width: 100%; }
  .calendar-navigation h3 { min-width: 0; flex: 1; font-size: 18px; }
  .calendar-legend { width: 100%; justify-content: center; gap: 13px; padding-bottom: 5px; }
  .calendar-layout { grid-template-columns: 1fr; gap: 12px; }
  .calendar-weekdays, .calendar-grid { gap: 3px; }
  .calendar-day { min-height: 60px; padding: 4px; gap: 2px; border-radius: 7px; }
  .day-number { width: 21px; height: 21px; font-size: 11px; }
  .day-count { display: none; }
  .day-values { font-size: 10px; }
  .day-income, .day-expense { display: none; }
  .day-profit { margin: 0; padding: 0; border: 0; }
  .daily-rows { max-height: none; }
  .modal form { padding: 18px; }
}

@media (max-width: 390px) {
  .sync-state #sync-label { max-width: 126px; overflow: hidden; text-overflow: ellipsis; }
  .operations-title { gap: 7px; }
  .view-switch button { padding: 0 6px; }
  .calendar-today { padding: 0 8px; }
  tbody tr { grid-template-columns: 72px minmax(0, 1fr) auto 88px; gap: 4px 7px; }
  .signed-amount { font-size: 15px; }
  .net-summary-strip { grid-template-columns: 1fr 1fr; }
  .net-summary-strip .summary-stat { min-height: 88px; }
  .net-summary-strip .summary-stat:nth-child(3) { border-left: 0; border-top: 1px solid var(--border); }
  .net-summary-strip .summary-meta { grid-column: 2; display: grid; grid-template-columns: minmax(76px, 1fr) auto; grid-template-rows: auto auto; gap: 4px 8px; border-left: 1px solid var(--border); }
  .net-summary-strip .summary-meta select { grid-row: 1 / 3; width: 100%; min-width: 0; }
  .net-summary-strip .summary-meta strong { align-self: end; }
  .net-summary-strip .summary-meta span { align-self: start; max-width: 54px; overflow: visible; font-size: 10px; line-height: 1.05; white-space: normal; }
  .net-table tbody tr { grid-template-columns: 68px minmax(0, 1fr) minmax(0, 1fr) 88px; gap: 4px 6px; }
}

@media (max-width: 380px) {
  .operations-panel { margin-inline: -12px; border-right: 0; border-left: 0; border-radius: 0; }
  .calendar-view { padding-inline: 2px; }
  .calendar-weekdays, .calendar-grid { gap: 1px; }
}

@media (prefers-reduced-motion: no-preference) {
  .summary-stat strong, .equation-box strong { transition: color .18s, transform .18s; }
  .entry-panel.is-saving .primary-action { animation: pulse .8s ease-in-out infinite alternate; }
  .toast { animation: toast-in .2s ease-out; }
  @keyframes pulse { to { opacity: .72; } }
  @keyframes toast-in { from { opacity: 0; transform: translate(-50%, 8px); } }
}
