:root {
  --color-bg: #191b1f;
  --color-surface: #23262b;
  --color-surface-raised: #292d33;
  --color-surface-soft: #1e2126;
  --color-text: #f3f0e8;
  --color-text-muted: #a8a7a2;
  --color-border: #363a40;
  --color-border-strong: #474c54;
  --color-accent: #f06432;
  --color-accent-hover: #ff7443;
  --color-accent-soft: rgb(240 100 50 / 14%);
  --color-success: #356859;
  --color-success-text: #b8e0d2;
  --color-error: #a94a45;
  --color-error-text: #ffd0cc;
  --color-warning: #b47b35;
  --radius-sm: 10px;
  --radius-md: 14px;
  --radius-lg: 18px;
  --shadow-card: 0 16px 40px rgb(0 0 0 / 18%);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
    "Segoe UI", sans-serif;
  color: var(--color-text);
  background: var(--color-bg);
  color-scheme: dark;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
}

* {
  box-sizing: border-box;
}

html {
  background: var(--color-bg);
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background: var(--color-bg);
}

button,
input {
  font: inherit;
}

button {
  -webkit-tap-highlight-color: transparent;
}

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

input {
  min-width: 0;
}

[hidden] {
  display: none !important;
}

.app-shell {
  width: min(100%, 580px);
  min-height: 100vh;
  margin: 0 auto;
  padding:
    max(18px, env(safe-area-inset-top))
    16px
    max(20px, env(safe-area-inset-bottom));
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 28px;
}

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

.brand-mark {
  display: grid;
  width: 44px;
  height: 44px;
  place-items: center;
  border: 1px solid rgb(240 100 50 / 55%);
  border-radius: 13px;
  color: var(--color-accent);
  background: var(--color-accent-soft);
  font-size: 21px;
  font-weight: 800;
}

.eyebrow,
.card__eyebrow {
  margin: 0;
  color: var(--color-text-muted);
  font-size: 11px;
  font-weight: 750;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

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

h1 {
  margin-bottom: 0;
  font-size: 27px;
  line-height: 1;
  letter-spacing: -0.04em;
}

h2 {
  margin-bottom: 10px;
  font-size: clamp(26px, 7vw, 34px);
  line-height: 1.08;
  letter-spacing: -0.045em;
}

.section-title {
  margin: 0;
  font-size: 24px;
}

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

.screen {
  animation: screen-in 180ms ease-out;
}

.screen--center {
  display: grid;
  min-height: 56vh;
  place-content: center;
  justify-items: center;
  padding: 30px 12px;
  text-align: center;
}

.screen--center .muted {
  max-width: 360px;
}

@keyframes screen-in {
  from {
    opacity: 0;
    transform: translateY(4px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.loader {
  width: 32px;
  height: 32px;
  margin-bottom: 20px;
  border: 3px solid var(--color-border);
  border-top-color: var(--color-accent);
  border-radius: 50%;
  animation: spin 700ms linear infinite;
}

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

.profile-chip {
  display: inline-flex;
  max-width: 48%;
  align-items: center;
  gap: 7px;
  padding: 8px 10px;
  overflow: hidden;
  border: 1px solid var(--color-border);
  border-radius: 999px;
  color: var(--color-text-muted);
  background: var(--color-surface-soft);
  font-size: 12px;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.profile-chip__dot {
  flex: 0 0 auto;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--color-success);
}

.notice {
  margin-bottom: 16px;
  padding: 11px 13px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-surface-soft);
  font-size: 13px;
  line-height: 1.45;
}

.notice--success {
  border-color: rgb(53 104 89 / 70%);
  color: var(--color-success-text);
  background: rgb(53 104 89 / 18%);
}

.notice--error {
  border-color: rgb(169 74 69 / 70%);
  color: var(--color-error-text);
  background: rgb(169 74 69 / 18%);
}

.section-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 20px;
}

.section-heading--row {
  align-items: end;
  margin-top: 30px;
}

.dashboard-intro {
  margin-bottom: 18px;
}

.card {
  margin-bottom: 14px;
  padding: 18px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  background: var(--color-surface);
  box-shadow: var(--shadow-card);
}

.card--flat {
  box-shadow: none;
}

.card__header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 16px;
}

.card__header > div:first-child {
  display: grid;
  gap: 4px;
}

.card__header strong {
  font-size: 16px;
}

.stack {
  display: grid;
  gap: 14px;
}

.field {
  display: grid;
  gap: 7px;
}

.field__label {
  color: var(--color-text-muted);
  font-size: 12px;
  font-weight: 700;
}

.input,
.category-row__name,
.category-row__percent {
  width: 100%;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  outline: none;
  color: var(--color-text);
  background: var(--color-surface-soft);
  transition:
    border-color 120ms ease,
    box-shadow 120ms ease;
}

.input {
  padding: 13px 14px;
}

.input:focus,
.category-row__name:focus,
.category-row__percent:focus,
.amount-input:focus {
  border-color: var(--color-accent);
  box-shadow: 0 0 0 3px rgb(240 100 50 / 14%);
}

.amount-field {
  display: flex;
  align-items: center;
  border-bottom: 1px solid var(--color-border-strong);
}

.amount-input {
  width: 100%;
  padding: 8px 0 12px;
  border: 0;
  outline: none;
  color: var(--color-text);
  background: transparent;
  font-size: clamp(40px, 13vw, 58px);
  font-weight: 720;
  line-height: 1;
  letter-spacing: -0.055em;
}

.amount-input::placeholder {
  color: #666a70;
}

.amount-field__currency {
  padding-bottom: 8px;
  color: var(--color-text-muted);
  font-size: 30px;
  font-weight: 650;
}

.field-hint {
  margin: -4px 0 0;
  font-size: 12px;
  line-height: 1.5;
}

.form-error {
  margin: 0;
  color: var(--color-error-text);
  font-size: 13px;
  line-height: 1.45;
}

.button {
  display: inline-flex;
  min-height: 44px;
  align-items: center;
  justify-content: center;
  padding: 12px 16px;
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  font-weight: 760;
  cursor: pointer;
  transition:
    transform 100ms ease,
    background 120ms ease,
    border-color 120ms ease;
}

.button:active:not(:disabled) {
  transform: translateY(1px);
}

.button:focus-visible {
  outline: 3px solid rgb(240 100 50 / 35%);
  outline-offset: 2px;
}

.button--primary {
  color: #21130d;
  background: var(--color-accent);
}

.button--primary:hover:not(:disabled) {
  background: var(--color-accent-hover);
}

.button--secondary {
  width: 100%;
  border-color: var(--color-border-strong);
  color: var(--color-text);
  background: transparent;
}

.button--ghost {
  min-height: 36px;
  padding: 7px 10px;
  border-color: var(--color-border);
  color: var(--color-text-muted);
  background: transparent;
}

.button--compact {
  flex: 0 0 auto;
  font-size: 12px;
}

.button--large {
  min-height: 52px;
  font-size: 16px;
}

.status-badge {
  display: inline-flex;
  width: fit-content;
  align-items: center;
  padding: 6px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 760;
}

.status-badge--success {
  color: var(--color-success-text);
  background: rgb(53 104 89 / 32%);
}

.status-badge--error {
  margin-bottom: 18px;
  color: var(--color-error-text);
  background: rgb(169 74 69 / 30%);
}

.currency-pill {
  padding: 6px 9px;
  border: 1px solid var(--color-border);
  border-radius: 999px;
  color: var(--color-text-muted);
  background: var(--color-surface-soft);
  font-size: 11px;
  font-weight: 760;
}

.category-editor {
  display: grid;
  gap: 10px;
  margin-bottom: 12px;
}

.category-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 88px 36px;
  gap: 8px;
  align-items: center;
}

.category-row__name,
.category-row__percent {
  height: 44px;
  padding: 0 11px;
}

.category-row__percent-wrap {
  position: relative;
}

.category-row__percent {
  padding-right: 27px;
  text-align: right;
}

.category-row__percent-sign {
  position: absolute;
  top: 50%;
  right: 10px;
  color: var(--color-text-muted);
  font-size: 12px;
  transform: translateY(-50%);
  pointer-events: none;
}

.category-row__remove {
  display: grid;
  width: 36px;
  height: 36px;
  place-items: center;
  border: 0;
  border-radius: 10px;
  color: var(--color-text-muted);
  background: transparent;
  font-size: 20px;
  cursor: pointer;
}

.category-row__remove:hover:not(:disabled) {
  color: var(--color-error-text);
  background: rgb(169 74 69 / 14%);
}

.percent-total {
  padding: 6px 9px;
  border-radius: 999px;
  color: var(--color-error-text);
  background: rgb(169 74 69 / 18%);
  font-size: 12px;
  font-weight: 800;
}

.percent-total--valid {
  color: var(--color-success-text);
  background: rgb(53 104 89 / 25%);
}

.template-summary,
.result-list {
  display: grid;
  gap: 9px;
}

.template-summary__row,
.result-list__row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 14px;
  padding-top: 9px;
  border-top: 1px solid var(--color-border);
}

.template-summary__row:first-child,
.result-list__row:first-child {
  padding-top: 0;
  border-top: 0;
}

.template-summary__meta,
.result-list__meta {
  color: var(--color-text-muted);
  font-size: 12px;
}

.result-list__amount {
  flex: 0 0 auto;
  font-size: 16px;
  font-weight: 780;
}

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

.history-item {
  padding: 15px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface-soft);
}

.history-item__top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.history-item__amount {
  font-size: 20px;
  font-weight: 780;
  letter-spacing: -0.03em;
}

.history-item__date {
  color: var(--color-text-muted);
  font-size: 11px;
  white-space: nowrap;
}

.history-item__summary {
  margin: 9px 0 0;
  color: var(--color-text-muted);
  font-size: 12px;
  line-height: 1.5;
}

.history-item__actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 10px;
}

.empty-state {
  padding: 22px 16px;
  border: 1px dashed var(--color-border-strong);
  border-radius: var(--radius-md);
  text-align: center;
}

.empty-state p {
  margin: 6px 0 0;
  font-size: 13px;
}

.footer {
  padding: 22px 4px 0;
  font-size: 11px;
  line-height: 1.5;
  text-align: center;
}

.footer p {
  margin-bottom: 0;
}

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

@media (max-width: 380px) {
  .app-shell {
    padding-inline: 12px;
  }

  .card {
    padding: 15px;
  }

  .category-row {
    grid-template-columns: minmax(0, 1fr) 80px 32px;
    gap: 6px;
  }
}

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