:root {
  color-scheme: dark;
  --bg: #17191d;
  --surface: #202329;
  --surface-2: #292d34;
  --surface-3: #323741;
  --glass: rgba(38, 42, 49, 0.76);
  --line: rgba(255, 255, 255, 0.09);
  --line-strong: rgba(255, 255, 255, 0.16);
  --text: #f5f5f7;
  --muted: #8e8e93;
  --muted-2: #63666d;
  --green: #30d158;
  --red: #ff453a;
  --yellow: #ffd60a;
  --blue: #64d2ff;
  --shadow: 0 24px 70px rgba(0, 0, 0, 0.48);
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(180deg, #1d2026 0%, #17191d 48%, #202329 100%);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text", Inter, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
  text-rendering: geometricPrecision;
}

body.modal-open {
  overflow: hidden;
}

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

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

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

.topbar,
.top-actions,
.section-head,
.modal-head,
.money-row,
.item-head,
.item-meta,
.card-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.topbar {
  min-height: 48px;
  margin-bottom: 22px;
}

.top-actions,
.split-buttons,
.item-actions {
  display: flex;
  gap: 8px;
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--muted-2);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: 28px;
  font-weight: 750;
  line-height: 1;
}

h2 {
  font-size: 26px;
  font-weight: 760;
}

h3 {
  font-size: 20px;
  font-weight: 740;
}

.icon-button {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.055);
  color: var(--text);
  font-size: 20px;
  font-weight: 750;
  transition: transform 160ms ease, background 160ms ease, border-color 160ms ease;
}

.icon-button:active,
.action-button:active,
.small-button:active,
.text-button:active,
.nav-button:active {
  transform: scale(0.97);
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.hero-card {
  position: relative;
  overflow: hidden;
  min-height: 238px;
  padding: 20px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.075), rgba(255, 255, 255, 0.025)),
    linear-gradient(145deg, #303640 0%, #1d2128 100%);
  box-shadow: var(--shadow);
}

.hero-card::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.11), transparent 22%, transparent 78%, rgba(255, 255, 255, 0.035)),
    linear-gradient(180deg, rgba(255, 255, 255, 0.05), transparent 42%);
  opacity: 0.72;
}

.hero-card > * {
  position: relative;
  z-index: 1;
}

.money-row {
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
}

.money-row strong {
  color: var(--text);
  font-size: 22px;
  font-weight: 760;
}

.limit-block {
  display: grid;
  min-height: 160px;
  align-content: center;
  justify-items: center;
  margin-top: 12px;
  text-align: center;
}

.limit-block p {
  color: var(--muted);
  font-size: 14px;
  font-weight: 720;
}

.limit-block strong {
  display: block;
  margin: 8px 0 6px;
  color: var(--green);
  font-size: clamp(54px, 18vw, 78px);
  font-weight: 780;
  line-height: 0.92;
  letter-spacing: 0;
}

.limit-block span {
  display: inline-flex;
  min-height: 30px;
  align-items: center;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.055);
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.warning-stack {
  display: grid;
  gap: 8px;
  margin: 12px 0 14px;
}

.alert {
  padding: 12px 13px;
  border: 1px solid rgba(255, 214, 10, 0.2);
  border-radius: 8px;
  background: rgba(255, 214, 10, 0.075);
  color: var(--yellow);
  font-size: 13px;
  font-weight: 780;
}

.alert.danger {
  border-color: rgba(255, 69, 58, 0.24);
  background: rgba(255, 69, 58, 0.095);
  color: var(--red);
}

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

.metric-card,
.item-card {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--glass);
  backdrop-filter: blur(20px);
}

.metric-card {
  min-height: 108px;
  padding: 14px;
}

.metric-card span {
  display: block;
  min-height: 34px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 720;
}

.metric-card strong {
  display: block;
  margin-top: 10px;
  overflow-wrap: anywhere;
  color: var(--text);
  font-size: 25px;
  font-weight: 770;
  line-height: 1.04;
}

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

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

.metric-card.warning strong {
  color: var(--yellow);
}

.metric-card.locked strong {
  color: var(--blue);
}

.metric-card.muted strong {
  color: #b4b6bd;
}

.metric-card.wide {
  grid-column: 1 / -1;
  min-height: 88px;
}

.quick-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 16px;
}

.action-button,
.small-button {
  border: 0;
  border-radius: 8px;
  background: var(--text);
  color: #111318;
  font-weight: 780;
  transition: transform 160ms ease, filter 160ms ease, background 160ms ease;
}

.action-button {
  min-height: 54px;
  padding: 12px;
}

.action-button.income {
  background: var(--green);
}

.action-button.expense {
  background: var(--surface-3);
  color: var(--red);
  border: 1px solid rgba(255, 69, 58, 0.2);
}

.action-button:not(.income):not(.expense) {
  background: rgba(255, 255, 255, 0.09);
  color: var(--text);
  border: 1px solid var(--line);
}

.small-button {
  min-height: 40px;
  padding: 0 14px;
}

.small-button.ghost {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
}

.section-head {
  margin-bottom: 16px;
}

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

.item-card {
  padding: 15px;
}

.item-card h3 {
  overflow-wrap: anywhere;
  font-size: 17px;
}

.item-amount {
  flex: 0 0 auto;
  color: var(--text);
  font-size: 19px;
  font-weight: 780;
}

.item-meta {
  align-items: flex-start;
  margin-top: 10px;
  color: var(--muted);
  font-size: 13px;
}

.card-row {
  margin-top: 8px;
  color: var(--muted);
  font-size: 14px;
}

.card-row strong {
  color: var(--text);
  font-weight: 760;
}

.status {
  display: inline-flex;
  align-items: center;
  height: 28px;
  padding: 0 10px;
  border: 1px solid rgba(255, 69, 58, 0.22);
  border-radius: 999px;
  background: rgba(255, 69, 58, 0.1);
  color: var(--red);
  font-size: 12px;
  font-weight: 780;
  white-space: nowrap;
}

.status.paid {
  border-color: rgba(48, 209, 88, 0.22);
  background: rgba(48, 209, 88, 0.1);
  color: var(--green);
}

.text-button {
  min-height: 34px;
  padding: 0 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.055);
  color: var(--text);
  font-size: 13px;
  font-weight: 740;
}

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

.empty {
  padding: 28px 16px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  text-align: center;
}

.bottom-nav {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 4px;
  width: min(100%, 500px);
  margin: 0 auto;
  padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(28, 31, 36, 0.82);
  backdrop-filter: blur(24px) saturate(1.25);
}

.nav-button {
  min-width: 0;
  min-height: 48px;
  padding: 6px 4px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 11px;
  font-weight: 760;
}

.nav-button.active {
  background: rgba(255, 255, 255, 0.105);
  color: var(--text);
}

.modal {
  width: min(calc(100% - 22px), 460px);
  max-height: min(760px, calc(100dvh - 28px));
  padding: 0;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: rgba(18, 20, 24, 0.96);
  color: var(--text);
  box-shadow: var(--shadow);
  backdrop-filter: blur(24px);
}

.modal[open] {
  position: fixed;
  inset: 50% auto auto 50%;
  z-index: 30;
  transform: translate(-50%, -50%);
}

.modal::backdrop {
  background: rgba(0, 0, 0, 0.72);
}

.modal form {
  padding: 16px;
}

.form-grid {
  display: grid;
  gap: 10px;
  margin: 16px 0;
}

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

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

.field input,
.field select,
.field textarea {
  width: 100%;
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(24, 27, 32, 0.92);
  color: var(--text);
  padding: 10px 12px;
  outline: 0;
}

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

.field input:focus,
.field select:focus,
.field textarea:focus {
  border-color: rgba(100, 210, 255, 0.72);
}

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

@media (min-width: 700px) {
  .app-shell {
    padding-top: 28px;
  }

  .hero-card {
    min-height: 258px;
  }
}

.hidden {
  display: none !important;
}

.login-screen {
  width: min(100%, 500px);
  min-height: 100vh;
  margin: 0 auto;
  display: grid;
  place-items: center;
  padding: max(18px, env(safe-area-inset-top)) 16px calc(24px + env(safe-area-inset-bottom));
}

.login-card {
  width: 100%;
  padding: 24px 20px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--glass);
  box-shadow: var(--shadow);
}

.login-hint {
  margin: 10px 0 18px;
  color: var(--muted);
  font-size: 14px;
}

.login-error {
  margin: 0 0 12px;
  color: var(--red);
  font-size: 13px;
  font-weight: 700;
}

.login-submit {
  width: 100%;
  margin-top: 4px;
}

.offline-banner {
  position: fixed;
  top: 0;
  right: 0;
  left: 0;
  z-index: 40;
  padding: 10px 14px;
  border-bottom: 1px solid rgba(255, 214, 10, 0.24);
  background: rgba(255, 214, 10, 0.12);
  color: var(--yellow);
  font-size: 13px;
  font-weight: 700;
  text-align: center;
}

.app-shell:not(.hidden) {
  padding-top: calc(max(18px, env(safe-area-inset-top)) + 0px);
}

body:has(.offline-banner:not(.hidden)) .app-shell:not(.hidden) {
  padding-top: calc(max(18px, env(safe-area-inset-top)) + 42px);
}
