:root {
  color-scheme: light;
  --bg: #f5f8f7;
  --surface: #ffffff;
  --surface-soft: #eef7f5;
  --text: #172322;
  --muted: #687a78;
  --line: #dbe6e4;
  --line-strong: #c6d8d5;
  --teal: #0f9a94;
  --teal-dark: #08746f;
  --teal-soft: #dff5f2;
  --coral: #ff6b5f;
  --coral-soft: #ffe9e6;
  --gold: #f5aa33;
  --green: #3fae72;
  --red: #df5757;
  --shadow: 0 18px 40px rgba(21, 48, 45, 0.12);
  --radius: 8px;
  --radius-lg: 14px;
  --nav-height: 76px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  background:
    radial-gradient(circle at top left, rgba(15, 154, 148, 0.08), transparent 30rem),
    var(--bg);
  color: var(--text);
  font-size: 16px;
  letter-spacing: 0;
}

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

button {
  cursor: pointer;
}

.app-shell {
  width: min(100%, 520px);
  min-height: 100dvh;
  margin: 0 auto;
  background: rgba(255, 255, 255, 0.62);
  border-left: 1px solid rgba(219, 230, 228, 0.7);
  border-right: 1px solid rgba(219, 230, 228, 0.7);
  position: relative;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: max(12px, env(safe-area-inset-top)) 16px 12px;
  background: rgba(247, 250, 249, 0.9);
  backdrop-filter: blur(18px);
  border-bottom: 1px solid rgba(219, 230, 228, 0.78);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand-mark {
  width: 38px;
  height: 38px;
  flex: 0 0 auto;
  border-radius: 10px;
  display: inline-grid;
  place-items: center;
  background: linear-gradient(135deg, var(--teal-dark), var(--teal));
  color: #fff;
  font-size: 22px;
  font-weight: 900;
  line-height: 1;
  box-shadow: 0 8px 18px rgba(15, 154, 148, 0.2);
}

.brand strong,
.brand small {
  display: block;
}

.brand strong {
  font-size: 17px;
  line-height: 1.15;
}

.brand small {
  color: var(--muted);
  font-size: 12px;
  margin-top: 2px;
}

.icon-button,
.shield-button,
.ghost-button,
.text-button,
.danger-button,
.primary-button {
  min-height: 42px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  transition: transform 0.16s ease, background 0.16s ease, border-color 0.16s ease, color 0.16s ease;
}

.icon-button {
  width: 42px;
  display: inline-grid;
  place-content: center;
  gap: 4px;
}

.icon-button span {
  display: block;
  width: 17px;
  height: 2px;
  border-radius: 2px;
  background: var(--text);
}

.shield-button {
  padding: 0 12px;
  font-size: 13px;
  font-weight: 700;
  color: var(--teal-dark);
  background: var(--teal-soft);
  border-color: rgba(15, 154, 148, 0.22);
}

.view {
  min-height: calc(100dvh - 68px - var(--nav-height));
  padding: 16px 16px calc(var(--nav-height) + 24px);
}

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

.screen-header {
  display: grid;
  gap: 4px;
  margin: 6px 0 2px;
}

.screen-header h1,
.screen-header h2 {
  margin: 0;
  font-size: 26px;
  line-height: 1.12;
}

.screen-header p {
  margin: 0;
  color: var(--muted);
  line-height: 1.55;
  font-size: 14px;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: 0 10px 28px rgba(20, 52, 49, 0.06);
  padding: 16px;
}

.panel.tight {
  padding: 12px;
}

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

.panel-title h2,
.panel-title h3 {
  margin: 0;
  font-size: 16px;
  line-height: 1.2;
}

.panel-title small {
  color: var(--muted);
  font-size: 12px;
}

.form-grid {
  display: grid;
  gap: 12px;
}

.field {
  display: grid;
  gap: 7px;
  min-width: 0;
}

.field label {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.field input,
.field select,
.field textarea {
  width: 100%;
  min-width: 0;
  max-width: 100%;
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fbfdfc;
  color: var(--text);
  padding: 10px 12px;
  outline: none;
}

.field input[type="date"],
.field input[type="month"] {
  display: block;
  -webkit-appearance: none;
  appearance: none;
  line-height: 1.25;
}

.field textarea {
  min-height: 78px;
  resize: vertical;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(15, 154, 148, 0.14);
}

.amount-row {
  display: grid;
  grid-template-columns: 36px 1fr;
  align-items: center;
  min-height: 58px;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: #fbfdfc;
  overflow: hidden;
}

.amount-row span {
  display: grid;
  place-items: center;
  height: 100%;
  color: var(--teal-dark);
  font-weight: 900;
  font-size: 21px;
}

.amount-row input {
  border: 0;
  min-height: 58px;
  padding: 10px 14px 10px 4px;
  background: transparent;
  font-size: 30px;
  font-weight: 850;
  color: var(--text);
}

.amount-row input[readonly] {
  caret-color: transparent;
}

.amount-row:focus-within {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(15, 154, 148, 0.14);
}

.keypad {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.keypad button {
  min-height: 54px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font-size: 21px;
  font-weight: 900;
  touch-action: manipulation;
}

.keypad button:active {
  transform: translateY(1px);
  background: var(--teal-soft);
}

.keypad button.utility {
  color: var(--muted);
}

.segmented {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
  padding: 4px;
  border-radius: var(--radius);
  background: #edf4f3;
}

.segmented button {
  border: 0;
  border-radius: 6px;
  min-height: 38px;
  color: var(--muted);
  background: transparent;
  font-weight: 800;
}

.segmented button.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 3px 12px rgba(26, 56, 53, 0.08);
}

.chip-grid {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 3px;
  scrollbar-width: none;
}

.chip-grid::-webkit-scrollbar {
  display: none;
}

.chip {
  flex: 0 0 auto;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  padding: 0 13px;
  color: var(--text);
  font-size: 14px;
  font-weight: 750;
}

.chip.active {
  color: var(--teal-dark);
  background: var(--teal-soft);
  border-color: rgba(15, 154, 148, 0.28);
}

.primary-button,
.danger-button,
.ghost-button,
.text-button {
  width: 100%;
  padding: 0 14px;
  font-weight: 850;
}

.primary-button {
  background: var(--teal);
  border-color: var(--teal);
  color: #fff;
  box-shadow: 0 12px 26px rgba(15, 154, 148, 0.22);
}

.danger-button {
  background: var(--coral-soft);
  border-color: rgba(255, 107, 95, 0.28);
  color: #af3129;
}

.ghost-button {
  background: var(--surface);
}

.text-button {
  background: transparent;
  border-color: transparent;
  color: var(--teal-dark);
  width: auto;
  min-height: 34px;
  padding: 0 4px;
}

.button-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.bottom-nav {
  position: fixed;
  left: 50%;
  bottom: 0;
  transform: translateX(-50%);
  width: min(100%, 520px);
  z-index: 30;
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 6px;
  padding: 8px 10px max(8px, env(safe-area-inset-bottom));
  background: rgba(247, 250, 249, 0.94);
  border-top: 1px solid rgba(219, 230, 228, 0.9);
  backdrop-filter: blur(18px);
}

.bottom-nav button {
  min-height: 52px;
  border: 0;
  border-radius: var(--radius);
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 850;
}

.bottom-nav button.active {
  background: var(--surface);
  color: var(--teal-dark);
  box-shadow: 0 5px 18px rgba(20, 52, 49, 0.08);
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.metric {
  min-height: 96px;
  display: grid;
  align-content: space-between;
  gap: 8px;
  padding: 14px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: #fbfdfc;
}

.metric.wide {
  grid-column: 1 / -1;
  background: linear-gradient(135deg, #083f3c, #0f9a94);
  color: #fff;
  border-color: transparent;
}

.metric span {
  color: inherit;
  opacity: 0.72;
  font-size: 12px;
  font-weight: 800;
}

.metric strong {
  display: block;
  font-size: 22px;
  line-height: 1.1;
}

.metric small {
  color: inherit;
  opacity: 0.72;
}

.progress {
  height: 10px;
  border-radius: 999px;
  background: #e6efed;
  overflow: hidden;
}

.progress > span {
  display: block;
  height: 100%;
  width: 0;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--teal), var(--gold));
}

.chart {
  width: 100%;
  height: 178px;
  display: block;
}

.bars {
  display: grid;
  gap: 11px;
}

.bar-row {
  display: grid;
  gap: 6px;
}

.bar-meta {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-size: 13px;
}

.bar-meta strong {
  font-weight: 850;
}

.bar-track {
  height: 9px;
  background: #e8f0ee;
  border-radius: 999px;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  border-radius: 999px;
  background: var(--teal);
}

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

.row-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fbfdfc;
}

.row-item strong {
  display: block;
  margin-bottom: 3px;
  font-size: 15px;
}

.row-item small {
  color: var(--muted);
  line-height: 1.35;
}

.row-amount {
  text-align: right;
  font-weight: 900;
}

.row-amount.expense {
  color: var(--coral);
}

.row-amount.income {
  color: var(--green);
}

.row-actions {
  display: flex;
  gap: 6px;
  justify-content: flex-end;
  margin-top: 8px;
}

.mini-button {
  min-height: 31px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface);
  padding: 0 10px;
  color: var(--text);
  font-size: 12px;
  font-weight: 800;
}

.mini-button.danger {
  color: #b73b34;
  border-color: rgba(255, 107, 95, 0.32);
  background: var(--coral-soft);
}

.empty-state {
  padding: 20px 12px;
  text-align: center;
  color: var(--muted);
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
  background: #fbfdfc;
}

.forecast-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.forecast-card {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fbfdfc;
}

.forecast-card span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  margin-bottom: 6px;
}

.forecast-card strong {
  font-size: 17px;
}

.filters {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.filters select,
.filters input {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 0 10px;
}

.modal-root {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: end center;
  padding: 16px;
  background: rgba(16, 31, 30, 0.44);
}

.modal-root[hidden] {
  display: none;
}

.modal {
  width: min(100%, 500px);
  max-height: calc(100dvh - 32px);
  overflow: auto;
  overflow-x: hidden;
  border-radius: 18px;
  background: var(--surface);
  box-shadow: var(--shadow);
  padding: 18px;
}

.modal .form-grid,
.modal .button-row {
  min-width: 0;
}

.modal h2 {
  margin: 0 0 8px;
  font-size: 22px;
}

.modal p {
  margin: 0 0 14px;
  color: var(--muted);
  line-height: 1.5;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--nav-height) + 18px);
  z-index: 120;
  transform: translate(-50%, 16px);
  width: min(calc(100% - 32px), 460px);
  padding: 12px 14px;
  border-radius: var(--radius);
  background: #102120;
  color: #fff;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.22);
  font-size: 14px;
}

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

.drawer {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 80;
  width: min(84vw, 340px);
  background: var(--surface);
  box-shadow: 20px 0 45px rgba(16, 31, 30, 0.2);
  padding: max(18px, env(safe-area-inset-top)) 16px 18px;
  transform: translateX(-105%);
  transition: transform 0.18s ease;
}

.drawer.open {
  transform: translateX(0);
}

.drawer h2 {
  margin: 0 0 16px;
}

.drawer button {
  width: 100%;
  margin-bottom: 8px;
}

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

.hidden {
  display: none !important;
}

@media (min-width: 700px) {
  .app-shell {
    margin-top: 24px;
    margin-bottom: 24px;
    min-height: calc(100dvh - 48px);
    border-radius: 24px;
    overflow: hidden;
    box-shadow: 0 24px 70px rgba(20, 52, 49, 0.14);
  }

  .bottom-nav {
    border-radius: 0 0 24px 24px;
  }

  .modal-root {
    place-items: center;
  }
}

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