:root {
  color-scheme: dark;
  --bg: #101418;
  --panel: #171d22;
  --panel-2: #1e262d;
  --line: #2b343c;
  --text: #f4f7f8;
  --muted: #93a1aa;
  --ice: #dce9ee;
  --green: #18c37e;
  --red: #ff5f57;
  --amber: #f2b84b;
  --blue: #74a7ff;
}

* {
  box-sizing: border-box;
}

html,
body,
#app {
  min-height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select {
  font: inherit;
}

button {
  color: inherit;
}

.app-shell {
  min-height: 100vh;
  padding: env(safe-area-inset-top) 16px calc(88px + env(safe-area-inset-bottom));
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 0 12px;
}

.top-actions {
  display: flex;
  gap: 8px;
}

.budget-title-button {
  min-height: 34px;
  padding: 0;
  background: transparent;
  border: 0;
  color: var(--text);
  font-size: 28px;
  font-weight: 800;
  text-align: left;
}

.eyebrow {
  margin: 0 0 2px;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: 28px;
}

h2 {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
}

h3 {
  margin: 12px 0 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.content {
  display: grid;
  gap: 16px;
}

.summary-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.summary-grid.single {
  grid-template-columns: 1fr;
}

.metric,
.group {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
}

.metric {
  min-height: 104px;
  width: 100%;
  padding: 14px;
  text-align: left;
}

.available-metric {
  min-height: 142px;
  padding: 18px;
  background: var(--panel);
  text-align: center;
}

.available-metric.success {
  border-color: rgba(24, 195, 126, 0.5);
  background: linear-gradient(180deg, rgba(24, 195, 126, 0.12), var(--panel));
}

.available-metric.complete {
  border-color: rgba(24, 195, 126, 0.35);
  background: linear-gradient(180deg, rgba(24, 195, 126, 0.08), var(--panel));
}

.available-metric.danger {
  border-color: rgba(255, 95, 87, 0.5);
  background: linear-gradient(180deg, rgba(255, 95, 87, 0.12), var(--panel));
}

.metric span,
label span {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 13px;
}

.metric strong {
  display: block;
  font-size: 20px;
  line-height: 1.15;
}

.available-metric strong {
  font-size: clamp(34px, 10vw, 52px);
}

.available-metric.complete strong {
  color: var(--green);
}

.metric.success strong {
  color: var(--green);
}

.metric.positive strong,
.group-footer-total.positive {
  color: var(--green);
}

.metric.danger strong,
.metric.bad strong {
  color: var(--red);
}

.metric.negative strong,
.group-footer-total.negative {
  color: var(--red);
}

.metric.neutral strong,
.metric.good strong {
  color: var(--ice);
}

.metric.zero strong,
.group-footer-total.zero {
  color: var(--muted);
}

.budget-overall-total {
  min-height: 62px;
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  column-gap: 12px;
  padding: 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  text-align: left;
}

.budget-overall-total span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.budget-overall-total strong {
  font-size: 18px;
  text-align: right;
  white-space: nowrap;
}

.budget-overall-total strong.positive {
  color: var(--green);
}

.budget-overall-total strong.negative {
  color: var(--red);
}

.budget-overall-total strong.zero {
  color: var(--muted);
}

.group {
  overflow: hidden;
  padding: 14px;
}

.backup-box {
  border-color: rgba(116, 167, 255, 0.35);
  background: linear-gradient(180deg, rgba(116, 167, 255, 0.08), var(--panel));
}

.stats-category {
  display: grid;
  gap: 8px;
}

.stats-category-head {
  display: grid;
  gap: 6px;
}

.stats-category-title {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
}

.group-header {
  min-height: 40px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 4px;
}

.group-title {
  min-width: 0;
  display: grid;
  gap: 2px;
}

.group-title h2 {
  margin: 0;
}

.group-footer {
  min-height: 46px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 8px;
  margin-right: -6px;
  margin-left: -6px;
  padding: 8px 6px;
  border-top: 1px solid var(--line);
  background: var(--panel-2);
  border-radius: 12px;
}

.group-footer .budget-details {
  margin-top: 4px;
}

.group-footer-label {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.group-footer-amount {
  display: grid;
  justify-items: end;
  gap: 2px;
}

.group-footer-total {
  white-space: nowrap;
  font-size: 15px;
  font-weight: 800;
}

.section-action {
  min-height: 44px;
  width: 100%;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 14px;
  color: var(--text);
  font-weight: 800;
}

.section-action.compact-action {
  justify-self: start;
  width: auto;
  min-height: 38px;
  padding: 0 14px;
  color: var(--muted);
  font-size: 13px;
}

.section-action.compact-action.active {
  border-color: var(--blue);
  color: var(--blue);
}

.month-bar {
  min-height: 64px;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 10px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  text-align: center;
}

.month-center {
  min-height: 44px;
  background: transparent;
  border: 0;
  border-radius: 12px;
  color: var(--text);
}

.month-center:active {
  background: var(--panel-2);
}

.month-bar span,
.month-center span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.month-bar strong,
.month-center strong {
  display: block;
  margin-top: 2px;
  font-size: 18px;
}

.row,
.activity-row {
  width: 100%;
  min-height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 0;
  background: transparent;
  border: 0;
  border-top: 1px solid var(--line);
  text-align: left;
}

.row:first-of-type,
.activity-row:first-of-type {
  border-top: 0;
}

.row strong,
.activity-row strong {
  white-space: nowrap;
}

.row.negative strong,
.activity-row.negative strong,
.activity-row.deleted strong {
  color: var(--red);
}

.row.zero strong,
.activity-row.neutral strong,
.amount-display.neutral strong {
  color: var(--muted);
}

.row.positive strong,
.activity-row.positive strong {
  color: var(--green);
}

.activity-row.move strong {
  color: var(--blue);
}

.row.warning strong {
  color: var(--amber);
}

.row.derived strong {
  color: var(--blue);
}

.row.reorder-row {
  position: relative;
  cursor: grab;
}

.row.reorder-row::before {
  content: "⇅";
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  color: var(--muted);
  font-weight: 800;
  pointer-events: none;
}

.row.reorder-row.drag-over {
  border-top-color: var(--blue);
  box-shadow: inset 0 2px 0 var(--blue);
}

.row.reorder-row.dragging {
  opacity: 0.55;
}

.activity-main {
  flex: 1;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0;
  background: transparent;
  border: 0;
  text-align: left;
}

.amount-stack {
  display: grid;
  justify-items: end;
  gap: 3px;
}

.planned-value {
  color: var(--blue);
  font-weight: 800;
}

.bar-percent {
  color: var(--muted);
  font-weight: 700;
}

.stats-bar {
  display: block;
  height: 6px;
  margin-top: 6px;
  background: rgba(147, 161, 170, 0.2);
  border-radius: 999px;
  overflow: hidden;
}

.stats-bar::after {
  content: "";
  display: block;
  height: 100%;
  width: var(--bar, 0%);
  background: var(--blue);
  border-radius: inherit;
}

.row.negative .stats-bar::after {
  background: var(--red);
}

.row.positive .stats-bar::after {
  background: var(--green);
}

small {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.budget-details {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 4px;
}

.budget-detail {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding: 0 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
}

.budget-detail.allocated {
  background: rgba(116, 167, 255, 0.14);
  color: var(--blue);
}

.budget-detail.future {
  background: rgba(242, 184, 75, 0.14);
  color: var(--amber);
}

.budget-detail.negative {
  background: rgba(255, 107, 107, 0.13);
  color: var(--red);
}

.budget-detail.zero {
  background: rgba(147, 161, 170, 0.08);
  color: var(--muted);
}

.tabs {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
  padding: 8px 12px calc(8px + env(safe-area-inset-bottom));
  background: rgba(16, 20, 24, 0.92);
  border-top: 1px solid var(--line);
  backdrop-filter: blur(16px);
}

.tab {
  min-height: 48px;
  background: transparent;
  border: 0;
  border-radius: 14px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.tab.active {
  background: var(--panel-2);
  color: var(--text);
}

.fab {
  position: fixed;
  right: 20px;
  bottom: calc(78px + env(safe-area-inset-bottom));
  width: 62px;
  height: 62px;
  background: var(--green);
  border: 0;
  border-radius: 50%;
  color: #07120d;
  font-size: 34px;
  font-weight: 700;
  box-shadow: 0 18px 44px rgba(0, 0, 0, 0.35);
}

.icon-button,
.primary,
.mini,
.chip,
.option {
  min-height: 40px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel-2);
  color: var(--text);
  font-weight: 700;
}

.primary {
  background: var(--green);
  border-color: var(--green);
  color: #07120d;
}

.icon-button.attention {
  border-color: rgba(242, 184, 75, 0.65);
  color: var(--amber);
}

.mini {
  min-height: 32px;
  padding: 0 10px;
  color: var(--muted);
  font-size: 12px;
}

.mini.primary {
  color: #07120d;
}

.mini.happy-action {
  border-color: rgba(116, 167, 255, 0.55);
  background: rgba(116, 167, 255, 0.18);
  color: #b9d2ff;
}

.row-actions {
  display: flex;
  gap: 6px;
}

.danger-text {
  color: var(--red);
}

.count-pill {
  min-width: 28px;
  min-height: 28px;
  display: inline-grid;
  place-items: center;
  padding: 0 8px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.safety-strip {
  min-height: 48px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.safety-strip span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.safety-strip strong {
  color: var(--green);
  font-size: 13px;
  white-space: nowrap;
}

.safety-strip.warning strong {
  color: var(--amber);
}

.settings-actions {
  justify-content: flex-end;
  margin-top: 10px;
}

.activity-tools {
  display: grid;
  gap: 10px;
}

.activity-tools-top {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: center;
}

.period-inline {
  display: grid;
  grid-template-columns: auto auto auto auto;
  gap: 6px;
  align-items: center;
}

.period-inline input {
  min-height: 40px;
  padding: 0 10px;
  border-radius: 10px;
}

.search,
input,
select {
  width: 100%;
  min-height: 48px;
  padding: 0 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  color: var(--text);
}

.chips {
  display: flex;
  gap: 8px;
  overflow-x: auto;
}

.period-filter {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 8px;
  align-items: end;
  padding: 8px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
}

@media (max-width: 760px) {
  .activity-tools-top {
    grid-template-columns: 1fr;
  }

  .period-inline {
    grid-template-columns: 1fr 1fr;
  }
}

.chip.active {
  border-color: var(--green);
  color: var(--green);
}

.chip.active.move {
  border-color: var(--blue);
  color: var(--blue);
}

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

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.helper {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.panel {
  position: fixed;
  inset: 0;
  z-index: 8;
  display: flex;
  align-items: flex-end;
  padding: 16px;
  background: rgba(5, 8, 10, 0.72);
  backdrop-filter: blur(12px);
}

.panel-card {
  width: 100%;
  max-height: calc(100vh - 40px);
  display: grid;
  gap: 14px;
  overflow: auto;
  padding: 16px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 22px 22px 16px 16px;
}

.panel-titlebar {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 10px;
}

.panel-titlebar strong {
  text-align: center;
}

.quick-action {
  display: grid;
  gap: 12px;
  padding: 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
}

.inline-form {
  grid-template-columns: 1fr auto;
  align-items: end;
}

.move-form {
  grid-template-columns: 1fr 1fr;
}

.move-value {
  grid-column: span 2;
  text-align: center;
}

.move-value input {
  height: 58px;
  font-size: 32px;
  font-weight: 800;
  text-align: center;
}

.route-choice {
  min-height: 64px;
  padding: 10px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 14px;
}

.route-choice select {
  min-height: 34px;
  padding: 0;
  background: transparent;
  border: 0;
  font-weight: 800;
}

.move-form .primary {
  grid-column: span 2;
}

.move-action {
  background: var(--blue);
  border-color: var(--blue);
  color: #07101c;
}

.panel-bottom-actions {
  position: sticky;
  bottom: -16px;
  display: grid;
  grid-template-columns: auto 1fr 1fr 1fr auto;
  align-items: end;
  gap: 10px;
  padding: 12px 0 0;
  background: var(--bg);
  border-top: 1px solid var(--line);
}

.panel-bottom-actions.single {
  grid-template-columns: 1fr;
}

.panel-bottom-actions label {
  display: grid;
  gap: 4px;
}

.two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.check-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.check-row input {
  width: auto;
  min-height: auto;
}

.check-row span {
  margin: 0;
}

.embedded {
  background: transparent;
}

.budget-switch-list {
  display: grid;
  gap: 10px;
}

.budget-switch-row {
  display: grid;
  gap: 8px;
  padding: 10px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
}

.budget-switch-row.active {
  border-color: var(--blue);
  box-shadow: inset 4px 0 0 var(--blue);
}

.budget-switch-main {
  display: grid;
  gap: 4px;
  padding: 0;
  background: transparent;
  border: 0;
  text-align: left;
}

.budget-switch-main strong {
  font-size: 18px;
}

.budget-switch-main span {
  color: var(--muted);
  font-size: 12px;
}

.budget-switch-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.budget-reset-action {
  margin-left: auto;
}

.compact {
  min-height: 48px;
}

.panel-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.composer {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow: auto;
  padding: calc(16px + env(safe-area-inset-top)) 16px calc(24px + env(safe-area-inset-bottom));
  background: var(--bg);
}

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

.hidden {
  display: none;
}

.amount-display {
  display: grid;
  gap: 10px;
  margin-top: 8px;
  padding: 20px 18px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 20px;
  text-align: center;
}

.amount-display input {
  width: 100%;
  height: 44px;
  padding: 0 12px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 14px;
  color: var(--text);
  font-size: 22px;
  font-weight: 700;
  text-align: center;
  outline: none;
}

.amount-display input::placeholder {
  color: var(--muted);
  opacity: 0.75;
}

.amount-display span {
  color: var(--muted);
  font-size: 13px;
}

.amount-display strong {
  color: var(--ice);
  font-size: clamp(42px, 12vw, 62px);
  line-height: 1;
  word-break: break-word;
}

.amount-display small {
  min-height: 16px;
  font-size: 13px;
}

.amount-display.inflow strong {
  color: var(--green);
}

.amount-display.outflow strong {
  color: var(--red);
}

.amount-display.loan strong {
  color: var(--amber);
}

.amount-display.invalid small {
  color: var(--red);
}

.split-button {
  min-height: 48px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 14px;
  color: var(--text);
  font-weight: 800;
}

.choice-list {
  display: grid;
  gap: 8px;
}

.loan-flow {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.choice {
  min-height: 52px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 12px;
  text-align: left;
}

.category-row.reorder-row {
  position: relative;
  cursor: grab;
}

.category-row.reorder-row::before {
  content: "⇅";
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  color: var(--muted);
  font-weight: 800;
  pointer-events: none;
}

.category-row.drag-over {
  border-color: var(--blue);
  box-shadow: inset 4px 0 0 var(--blue);
}

.category-row.dragging {
  opacity: 0.6;
}

.category-block {
  display: grid;
  gap: 8px;
}

.category-envelope-tabs {
  width: 100%;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 8px;
  border: 1px dashed var(--line);
  border-radius: 12px;
}

.category-envelope-tabs.drag-over {
  border-color: var(--blue);
  box-shadow: inset 0 0 0 1px var(--blue);
}

.category-envelope-tab {
  min-height: 36px;
  padding: 0 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--text);
  font-weight: 700;
  cursor: grab;
}

.category-envelope-tab.drag-over {
  border-color: var(--blue);
  box-shadow: inset 0 0 0 1px var(--blue);
}

.category-envelope-tab.dragging {
  opacity: 0.5;
}

.category-create-form {
  margin-top: 14px;
}

.choice.selected {
  border-color: var(--green);
  box-shadow: inset 4px 0 0 var(--green);
}

.choice span {
  font-weight: 800;
}

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

.selector-button {
  min-height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  text-align: left;
}

.selector-button span {
  color: var(--muted);
  font-size: 13px;
}

.selector-button strong {
  font-size: 18px;
}

.picker-panel {
  position: fixed;
  inset: 0;
  z-index: 12;
  display: flex;
  align-items: flex-end;
  padding: 16px;
  background: rgba(5, 8, 10, 0.72);
  backdrop-filter: blur(12px);
}

.picker-card {
  width: 100%;
  max-height: min(78vh, 680px);
  display: grid;
  gap: 12px;
  overflow: auto;
  padding: 16px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 22px 22px 16px 16px;
}

.composer label {
  display: grid;
  gap: 4px;
}

.preview {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.split-panel {
  display: grid;
  gap: 10px;
  padding: 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
}

.split-header,
.split-line {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 8px;
}

.split-header span.ok {
  color: var(--green);
}

.split-header span.warn {
  color: var(--amber);
}

.split-line {
  grid-template-columns: 1fr 112px auto;
}

.split-line input,
.split-line select {
  min-height: 42px;
}

.impact {
  padding: 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  color: var(--green);
  font-weight: 800;
}

.impact.negative {
  color: var(--red);
}

@media (min-width: 760px) {
  .app-shell {
    max-width: 760px;
    margin: 0 auto;
  }
}

@media (max-width: 680px) {
  .panel-bottom-actions {
    grid-template-columns: 1fr 1fr;
  }

  .panel-bottom-actions label,
  .panel-bottom-actions .primary {
    grid-column: span 2;
  }
}
