:root {
  color-scheme: light;
  --bg: #f5f5f7;
  --surface: rgba(255, 255, 255, 0.86);
  --surface-solid: #ffffff;
  --surface-2: #f2f2f7;
  --ink: #1d1d1f;
  --muted: #6e6e73;
  --line: #d2d2d7;
  --accent: #007aff;
  --accent-soft: #e8f2ff;
  --forest: #0a84ff;
  --terracotta: #ff9f0a;
  --gold: #ffd60a;
  --teal: #30b0c7;
  --green: #34c759;
  --purple: #5856d6;
  --rose: #ff2d55;
  --danger: #b42318;
  --nav: rgba(255, 255, 255, 0.72);
  --chip: #e8f2ff;
  --shadow: 0 22px 70px rgba(0, 0, 0, 0.09);
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display", Inter, "Segoe UI", system-ui, sans-serif;
  background: linear-gradient(180deg, #ffffff 0%, var(--bg) 42%, #eef3f8 100%);
  color: var(--ink);
  overflow-x: hidden;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.shell {
  min-height: 100vh;
  min-height: 100dvh;
  padding: 0;
}

.phone {
  position: relative;
  width: 100%;
  min-height: 100vh;
  min-height: 100dvh;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  overflow: hidden;
}

.app-view,
.screen {
  min-height: 100vh;
  min-height: 100dvh;
}

.app-view {
  display: grid;
  grid-template-columns: 244px minmax(0, 1fr);
}

.screen {
  display: none;
  overflow-y: auto;
  padding: 46px clamp(28px, 5vw, 76px);
  grid-column: 2;
}

.screen.active {
  display: block;
}

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

h1 {
  margin-bottom: 8px;
  font-size: clamp(36px, 4vw, 56px);
  line-height: 1.03;
  letter-spacing: 0;
  font-weight: 800;
}

h2 {
  margin-bottom: 12px;
  font-size: 22px;
  line-height: 1.12;
  font-weight: 760;
}

h3 {
  margin-bottom: 6px;
  font-size: 18px;
}

.lead {
  margin-bottom: 0;
  color: var(--muted);
  font-size: clamp(17px, 1.6vw, 22px);
  line-height: 1.35;
}

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

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

.hero-card {
  margin: 0;
  padding: 30px;
  border: 1px solid rgba(255, 255, 255, 0.72);
  border-radius: 28px;
  background: linear-gradient(145deg, rgba(255, 255, 255, 0.94), rgba(241, 247, 255, 0.9));
  color: var(--ink);
  box-shadow: var(--shadow);
}

.hero-topline {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.hero-topline em {
  color: var(--muted);
  font-size: 13px;
  font-style: normal;
  font-weight: 800;
}

.hero-card span,
.summary-tile span {
  display: block;
  color: var(--muted);
  font-weight: 700;
}

.hero-card strong {
  display: block;
  margin: 14px 0 12px;
  color: var(--ink);
  font-size: clamp(44px, 5vw, 70px);
  line-height: 1;
  letter-spacing: 0;
}

.hero-card p {
  margin: 0 0 18px;
  color: var(--muted);
  font-size: 18px;
  font-weight: 760;
}

.section-title {
  margin: 24px 0 12px;
  font-size: 28px;
  font-weight: 900;
}

.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 30px;
}

.header-actions,
.form-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: minmax(360px, 1.15fr) minmax(230px, 0.7fr) minmax(330px, 0.95fr);
  gap: 18px;
  align-items: start;
}

.cards-dashboard,
.debts-dashboard {
  grid-template-columns: repeat(2, minmax(260px, 1fr));
}

.distribution-panel {
  grid-column: 1 / 3;
}

.insights-panel {
  grid-column: 1 / 3;
}

.recent-panel {
  grid-column: 3;
  grid-row: 1 / span 2;
}

.panel,
.metric-card {
  border: 1px solid rgba(255, 255, 255, 0.7);
  border-radius: 22px;
  background: var(--surface);
  box-shadow: 0 14px 44px rgba(0, 0, 0, 0.06);
  backdrop-filter: blur(18px);
}

.panel {
  padding: 22px;
}

.metric-card {
  min-height: 152px;
  padding: 22px;
}

.metric-card span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
  text-transform: uppercase;
}

.metric-card strong {
  display: block;
  margin: 12px 0 8px;
  font-size: clamp(28px, 3.2vw, 44px);
  line-height: 1.02;
}

.metric-card p {
  color: var(--muted);
  font-size: 15px;
  line-height: 1.4;
}

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

.panel-heading h2 {
  margin: 0;
}

.panel-heading span {
  color: var(--muted);
  font-weight: 800;
}

.distribution-card,
.settings-card,
.expense-card,
.entity-card,
.form-panel,
.auth-card,
.setup-card {
  border: 1px solid rgba(210, 210, 215, 0.72);
  border-radius: 8px;
  background: var(--surface);
}

.distribution-card,
.settings-card {
  padding: 22px 20px;
  background: rgba(242, 242, 247, 0.78);
}

.bar-row {
  display: grid;
  gap: 8px;
  margin-bottom: 18px;
}

.bar-row:last-child {
  margin-bottom: 0;
}

.bar-label {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 18px;
}

.bar-label strong {
  white-space: nowrap;
}

.bar-track {
  height: 10px;
  border-radius: 20px;
  background: rgba(210, 210, 215, 0.7);
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  border-radius: inherit;
}

.expense-list {
  display: grid;
  gap: 14px;
}

.expense-list.wide {
  grid-template-columns: repeat(auto-fit, minmax(360px, 1fr));
}

.entity-panel {
  grid-column: 1 / -1;
}

.entity-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 14px;
}

.entity-card {
  display: grid;
  gap: 16px;
  padding: 18px;
}

.entity-card.is-muted {
  opacity: 0.66;
}

.entity-topline {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.entity-topline h3 {
  margin: 0 0 6px;
}

.entity-topline p,
.entity-note {
  margin: 0;
  color: var(--muted);
}

.meta-grid {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 7px 14px;
  padding: 12px;
  border-radius: 8px;
  background: rgba(242, 242, 247, 0.72);
}

.meta-grid span {
  color: var(--muted);
  font-weight: 800;
}

.meta-grid strong {
  min-width: 0;
  word-break: break-word;
}

.expense-card {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 14px;
  align-items: center;
  min-height: 124px;
  padding: 18px 16px;
}

.category-badge {
  display: grid;
  place-items: center;
  width: 52px;
  height: 68px;
  border-radius: 16px;
  color: #fff;
  font-size: 22px;
  font-weight: 900;
}

.expense-main {
  min-width: 0;
}

.expense-title {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.expense-title h3 {
  margin: 0;
  word-break: break-word;
}

.expense-amount {
  flex: 0 0 auto;
  font-size: 20px;
  font-weight: 900;
  white-space: nowrap;
}

.expense-meta {
  margin: 6px 0 12px;
  color: var(--muted);
  font-size: 15px;
}

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

.chip-btn,
.icon-btn,
.link-btn,
.secondary-btn,
.primary-btn,
.danger-btn {
  min-height: 42px;
  border: 0;
  border-radius: 999px;
  font-weight: 800;
}

.chip-btn {
  min-width: 104px;
  padding: 0 16px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.74);
  color: var(--ink);
}

.icon-btn {
  min-width: 44px;
  padding: 0 12px;
  background: var(--surface-2);
  color: var(--ink);
}

.primary-btn {
  width: 100%;
  padding: 0 20px;
  color: #fff;
  background: var(--accent);
  box-shadow: 0 10px 26px rgba(0, 122, 255, 0.22);
}

.primary-btn.compact,
.secondary-btn.compact {
  width: auto;
}

.secondary-btn {
  padding: 0 18px;
  color: var(--accent);
  background: var(--accent-soft);
}

.link-btn {
  width: fit-content;
  padding: 0;
  color: var(--accent);
  background: transparent;
}

.danger-btn {
  padding: 0 18px;
  color: var(--danger);
  background: #fff1f0;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 10px;
  border-radius: 999px;
  background: #fff8d6;
  color: #7a5900;
  font-size: 12px;
  font-weight: 800;
}

.form-panel {
  display: grid;
  gap: 16px;
  padding: 18px;
}

.form-layout {
  display: grid;
  grid-template-columns: minmax(360px, 640px) minmax(280px, 420px);
  gap: 24px;
  align-items: start;
}

.help-panel {
  padding: 24px;
  border-radius: 18px;
  background: var(--surface-2);
}

.help-panel p {
  color: var(--muted);
  font-size: 18px;
  line-height: 1.45;
}

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

.check-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 10px 0 4px;
  color: var(--ink);
  font-size: 14px;
  font-weight: 800;
}

.check-row input {
  width: 18px;
  min-height: 18px;
  accent-color: var(--accent);
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 800;
}

input,
select {
  width: 100%;
  min-height: 50px;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0 14px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.9);
}

input:focus,
select:focus {
  outline: 4px solid rgba(0, 122, 255, 0.14);
  border-color: var(--accent);
}

.category-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.category-option {
  min-height: 38px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.78);
  font-weight: 800;
}

.category-option.active {
  border-color: rgba(0, 122, 255, 0.42);
  background: var(--chip);
  color: var(--accent);
}

.settings-card {
  display: grid;
  gap: 14px;
  margin-bottom: 18px;
}

.settings-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 20px;
}

.tools-card {
  align-content: start;
}

.settings-card p {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 18px;
  line-height: 1.45;
}

.settings-card .compact-note {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

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

.insight-list div {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid rgba(210, 210, 215, 0.78);
}

.insight-list div:last-child {
  border-bottom: 0;
}

.insight-list span,
.budget-item span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.insight-list strong {
  text-align: right;
}

.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.filters-panel {
  display: grid;
  grid-template-columns: minmax(220px, 1.4fr) repeat(3, minmax(160px, 1fr)) auto;
  gap: 12px;
  align-items: end;
  margin-bottom: 18px;
}

.filter-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

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

.budget-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.7);
}

.budget-item span {
  display: block;
  margin-top: 4px;
}

.budget-item.is-muted {
  opacity: 0.62;
}

.inline-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.mini-progress {
  height: 8px;
  border-radius: 999px;
  background: rgba(0, 122, 255, 0.13);
  overflow: hidden;
}

.mini-progress span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
}

.mini-progress.is-over span {
  background: var(--danger);
}

.compact-details summary {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  cursor: pointer;
  font-size: 20px;
  font-weight: 900;
}

.compact-details summary::marker {
  color: var(--accent);
}

.compact-details[open] summary {
  margin-bottom: 14px;
}

.bottom-nav {
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  z-index: 4;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 244px;
  padding: 30px 16px;
  background: var(--nav);
  border-right: 1px solid rgba(210, 210, 215, 0.64);
  backdrop-filter: blur(22px);
}

.nav-item {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 8px;
  min-height: 50px;
  border: 0;
  border-radius: 14px;
  background: transparent;
  color: var(--muted);
  font-size: 15px;
  font-weight: 800;
  padding: 0 12px;
}

.nav-icon {
  display: grid;
  place-items: center;
  width: 44px;
  height: 34px;
  border-radius: 999px;
  font-size: 22px;
  line-height: 1;
}

.nav-item.active {
  color: var(--accent);
  background: rgba(0, 122, 255, 0.08);
}

.nav-item.active .nav-icon {
  background: var(--accent-soft);
  color: var(--accent);
}

.nav-signout {
  margin-top: auto;
  color: var(--danger);
}

.nav-signout .nav-icon {
  background: #fff1f0;
}

.auth-card,
.setup-card {
  margin: 32px 22px;
  padding: 24px;
}

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  padding: 4px;
  border-radius: 999px;
  background: rgba(242, 242, 247, 0.92);
  margin-bottom: 18px;
}

.segment {
  min-height: 42px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font-weight: 900;
}

.segment.active {
  background: var(--surface-solid);
  color: var(--ink);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.06);
}

.modal {
  width: min(92vw, 390px);
  border: 0;
  border-radius: 22px;
  padding: 22px;
  background: var(--surface);
}

.modal::backdrop {
  background: rgba(29, 29, 31, 0.42);
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 0;
  margin: 6px 0 0;
}

.status {
  position: fixed;
  right: 22px;
  bottom: 22px;
  left: 266px;
  z-index: 5;
  min-height: 0;
  margin: 0;
  color: var(--muted);
  pointer-events: none;
}

.empty-state {
  padding: 24px;
  border-radius: 8px;
  background: var(--surface);
  color: var(--muted);
}

.hidden {
  display: none !important;
}

@media (max-width: 820px) {
  .app-view {
    display: block;
  }

  .screen {
    grid-column: auto;
    width: 100%;
    padding: max(22px, env(safe-area-inset-top)) 18px calc(94px + env(safe-area-inset-bottom));
  }

  h1 {
    font-size: 36px;
    line-height: 1.06;
  }

  h2 {
    font-size: 22px;
  }

  .lead {
    font-size: 17px;
  }

  .page-header,
  .header-actions,
  .form-actions {
    display: grid;
    align-items: stretch;
    gap: 12px;
  }

  .dashboard-grid,
  .form-layout,
  .filters-panel {
    display: grid;
    grid-template-columns: 1fr;
    gap: 16px;
  }

  .distribution-panel,
  .insights-panel,
  .recent-panel {
    grid-column: auto;
    grid-row: auto;
  }

  .hero-card {
    padding: 24px;
    border-radius: 24px;
  }

  .hero-card strong {
    font-size: clamp(42px, 14vw, 58px);
  }

  .metric-card {
    min-height: 128px;
  }

  .form-panel,
  .panel,
  .help-panel {
    padding: 16px;
  }

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

  input,
  select {
    min-height: 46px;
  }

  .category-picker {
    gap: 7px;
  }

  .category-option {
    min-height: 36px;
    padding: 0 12px;
    font-size: 14px;
  }

  .expense-list.wide,
  .entity-grid,
  .settings-grid,
  .cards-dashboard,
  .debts-dashboard {
    grid-template-columns: 1fr;
  }

  .filter-actions,
  .budget-item {
    align-items: stretch;
  }

  .filter-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .bottom-nav {
    position: fixed;
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    height: 78px;
    max-height: 84px;
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: flex-start;
    overflow-x: auto;
    overflow-y: hidden;
    overscroll-behavior-x: contain;
    gap: 6px;
    padding: 9px 10px max(9px, env(safe-area-inset-bottom));
    border-top: 1px solid rgba(210, 210, 215, 0.8);
    border-right: 0;
    box-shadow: 0 -12px 30px rgba(0, 0, 0, 0.08);
    scrollbar-width: none;
  }

  .bottom-nav::-webkit-scrollbar {
    display: none;
  }

  .nav-item {
    flex: 0 0 62px;
    display: grid;
    place-items: center;
    gap: 3px;
    min-height: 52px;
    padding: 0;
    border-radius: 16px;
    font-size: 10px;
  }

  .nav-item span:last-child {
    display: none;
  }

  .nav-item.active span:last-child {
    display: block;
  }

  .nav-signout {
    display: none;
  }

  .nav-icon {
    width: 40px;
    height: 28px;
    font-size: 20px;
  }

  .status {
    right: 16px;
    left: 16px;
    bottom: calc(74px + env(safe-area-inset-bottom));
    padding: 0 4px;
  }
}

@media (max-width: 1100px) and (min-width: 821px) {
  .app-view {
    grid-template-columns: 216px minmax(0, 1fr);
  }

  .bottom-nav {
    width: 216px;
  }

  .dashboard-grid,
  .form-layout {
    grid-template-columns: 1fr;
  }

  .distribution-panel,
  .recent-panel {
    grid-column: auto;
    grid-row: auto;
  }

  .status {
    left: 238px;
  }
}

@media (max-width: 380px) {
  h1 {
    font-size: 30px;
  }

  .hero-card strong {
    font-size: 40px;
  }

  .expense-card {
    grid-template-columns: 1fr;
  }

  .category-badge {
    width: 46px;
    height: 52px;
  }

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