:root {
  --bg-0: #f2eee8;
  --bg-1: #f8f6f1;
  --surface: #fffdf9;
  --surface-strong: #fff;
  --text: #1d2328;
  --text-soft: #5a666f;
  --border: #d7d8d4;
  --border-strong: #bfc5c9;
  --accent: #0f766e;
  --accent-strong: #0c5e58;
  --accent-soft: #e4f3f1;
  --positive: #1f7a43;
  --negative: #b4233f;
  --warn: #935f10;
  --shadow: 0 22px 54px rgba(17, 24, 28, 0.08);
  --radius-xl: 22px;
  --radius-lg: 14px;
  --radius-md: 10px;
  --radius-sm: 8px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--text);
  font-family: "Space Grotesk", sans-serif;
  background: linear-gradient(160deg, var(--bg-0) 0%, var(--bg-1) 55%, #ecefe9 100%);
}

.bg {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image:
    radial-gradient(circle at 8% 0%, rgba(15, 118, 110, 0.2), transparent 38%),
    radial-gradient(circle at 100% 18%, rgba(185, 110, 44, 0.16), transparent 34%),
    radial-gradient(circle at 42% 100%, rgba(48, 67, 82, 0.1), transparent 32%);
}

.container {
  width: min(1240px, 94vw);
  margin: 1.5rem auto 3.2rem;
  display: grid;
  gap: 1rem;
  position: relative;
  z-index: 1;
}

.hero {
  border-radius: var(--radius-xl);
  background:
    linear-gradient(140deg, rgba(255, 255, 255, 0.09) 0%, rgba(255, 255, 255, 0) 42%),
    linear-gradient(130deg, #10262d 0%, #1d3d44 54%, #365461 100%);
  color: #eef5f8;
  padding: 2.4rem 1.8rem 2rem;
  position: relative;
  overflow: hidden;
  box-shadow: var(--shadow);
}

.hero::before {
  content: "";
  position: absolute;
  right: -6rem;
  top: -7rem;
  width: 20rem;
  height: 20rem;
  border-radius: 999px;
  background: radial-gradient(circle, rgba(255, 196, 133, 0.28) 0%, rgba(255, 196, 133, 0) 72%);
  pointer-events: none;
}

.label {
  margin: 0;
  font-size: 0.74rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: #ffd7a8;
  font-weight: 700;
}

.hero h1 {
  margin: 0.3rem 0 0.6rem;
  font-family: "Fraunces", serif;
  font-size: clamp(2.7rem, 6.2vw, 4.8rem);
  line-height: 0.9;
  letter-spacing: -0.02em;
  color: #fff;
}

.hero p {
  margin: 0;
  max-width: 60ch;
  line-height: 1.55;
  font-size: 0.98rem;
  color: #d6e5eb;
}

.summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 0.75rem;
}

.metric {
  background: linear-gradient(170deg, var(--surface-strong) 0%, var(--surface) 100%);
  border: 1px solid #d6dbde;
  border-radius: var(--radius-lg);
  padding: 0.9rem 1rem;
  box-shadow: 0 8px 24px rgba(14, 22, 28, 0.05);
  opacity: 0;
  transform: translateY(7px);
  animation: card-in 0.35s ease forwards;
}

.summary.summary--no-anim .metric {
  opacity: 1;
  transform: none;
  animation: none;
}

.metric .name {
  display: block;
  font-size: 0.7rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-soft);
  font-weight: 700;
}

.metric .value {
  display: block;
  margin-top: 0.34rem;
  font-size: 1.34rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.metric .value.positive {
  color: var(--positive);
}

.metric .value.negative {
  color: var(--negative);
}

.metric .metric-label {
  display: block;
  margin-top: 0.45rem;
  font-size: 0.68rem;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--text-soft);
  font-weight: 700;
}

.metric-table-wrap {
  margin-top: 0.45rem;
}

.metric-table-grid {
  width: 100%;
  border-collapse: collapse;
  table-layout: auto;
}

.metric-table-grid .metric-col-name {
  width: auto;
}

.metric-table-grid .metric-col-value {
  width: 0.1%;
}

.metric-table-grid th,
.metric-table-grid td {
  padding: 0.12rem 0;
  vertical-align: baseline;
}

.metric-title-row td {
  font-size: 0.7rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-soft);
  font-weight: 700;
  padding-bottom: 0.3rem;
}

.metric-title-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
}

.metric-switch {
  display: inline-flex;
  border: 1px solid #c7d1d6;
  border-radius: 999px;
  overflow: hidden;
  background: #eef3f5;
}

.metric-switch-btn {
  border: none;
  box-shadow: none;
  background: transparent;
  color: #3d4f59;
  padding: 0.2rem 0.46rem;
  font-size: 0.68rem;
  font-weight: 700;
  line-height: 1.2;
}

.metric-switch-btn.is-active {
  background: #0f766e;
  color: #fff;
}

.metric-table-grid tbody td:nth-child(2),
.metric-table-grid tbody td:nth-child(3) {
  width: 1%;
  min-width: 0;
  white-space: nowrap;
}

.metric-section-row td {
  padding-top: 0.4rem;
  padding-bottom: 0.16rem;
  font-size: 0.68rem;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--text-soft);
  font-weight: 700;
}

.metric-section-row--with-cols td:nth-child(2),
.metric-section-row--with-cols td:nth-child(3) {
  text-align: right;
}

.metric-cell-name {
  font-size: 0.82rem;
  color: #3d4b55;
  font-weight: 600;
  padding-right: 0.45rem;
}

.metric-cell-value {
  text-align: right;
  white-space: nowrap;
}

.metric-table-grid td:nth-child(3),
.metric-section-row td:nth-child(3) {
  padding-left: 0.75rem;
}

.metric-cell-value .value {
  font-size: 0.85rem;
  margin-top: 0;
  font-variant-numeric: tabular-nums;
}

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

.card {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.93) 0%, rgba(255, 253, 249, 0.93) 100%);
  backdrop-filter: blur(2px);
  padding: 1.05rem;
  box-shadow: 0 7px 22px rgba(17, 24, 28, 0.04);
}

.card h2 {
  margin: 0 0 0.8rem;
  font-size: 1.06rem;
  letter-spacing: -0.01em;
}

.card h3 {
  margin: 0;
  font-size: 0.94rem;
}

.stack {
  display: grid;
  gap: 0.68rem;
}

.header-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.62rem;
}

label {
  display: grid;
  gap: 0.3rem;
  font-size: 0.88rem;
  font-weight: 600;
  color: #273037;
}

input,
select {
  width: 100%;
  font: inherit;
  font-weight: 500;
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 0.6rem 0.66rem;
  background: #fff;
  transition: border-color 0.14s ease, box-shadow 0.14s ease;
}

input::placeholder {
  color: #8f99a3;
}

input:focus,
select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.18);
}

button,
.import-label {
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 0.58rem 0.9rem;
  font: inherit;
  font-size: 0.88rem;
  font-weight: 700;
  cursor: pointer;
  text-align: center;
  color: #fff;
  background: linear-gradient(145deg, var(--accent) 0%, #0d6a62 100%);
  transition: transform 0.12s ease, filter 0.15s ease, box-shadow 0.15s ease;
  box-shadow: 0 6px 16px rgba(15, 118, 110, 0.24);
}

button:hover,
.import-label:hover {
  filter: brightness(1.03);
}

button:active,
.import-label:active {
  transform: translateY(1px);
}

button.danger {
  background: linear-gradient(145deg, #bd2f4c 0%, #a01f3f 100%);
  box-shadow: 0 6px 16px rgba(160, 31, 63, 0.24);
}

button.danger:hover {
  filter: brightness(1.04);
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}

.table {
  width: 100%;
  min-width: 700px;
  border-collapse: collapse;
  background: #fff;
}

.table th,
.table td {
  border-bottom: 1px solid #e7ecef;
  padding: 0.62rem 0.54rem;
  text-align: left;
  font-size: 0.88rem;
}

.table th {
  position: sticky;
  top: 0;
  background: #edf5f6;
  color: #3d4d57;
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
}

.table tbody tr:hover {
  background: #f7fbfc;
}

.table th.num,
.table td.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.table td.editable-num,
.table td.editable-text,
.table td.editable-select,
.table td.editable-shares {
  cursor: pointer;
  position: relative;
}

.table td.editable-num:hover,
.table td.editable-text:hover,
.table td.editable-select:hover,
.table td.editable-shares:hover {
  background: #ecf6f8;
}

.table td.editable-num::after,
.table td.editable-text::after,
.table td.editable-select::after,
.table td.editable-shares::after {
  content: "";
  position: absolute;
  top: 3px;
  right: 3px;
  width: 0;
  height: 0;
  border-top: 7px solid #9db7bc;
  border-left: 7px solid transparent;
  opacity: 0.9;
  pointer-events: none;
}

.inline-num-input {
  width: 100%;
  max-width: 8rem;
  margin-left: auto;
  display: block;
  text-align: right;
  font: inherit;
  color: var(--text);
  border: 1px solid var(--accent);
  border-radius: 5px;
  padding: 0.2rem 0.36rem;
  background: #fff;
}

.inline-text-input,
.inline-select-input {
  width: 100%;
  font: inherit;
  color: var(--text);
  border: 1px solid var(--accent);
  border-radius: 5px;
  padding: 0.22rem 0.36rem;
  background: #fff;
}

.add-row td {
  background: #f8fbfc;
}

.table-input {
  width: 100%;
  font: inherit;
  color: var(--text);
  border: 1px solid #b9c5cb;
  border-radius: 5px;
  padding: 0.26rem 0.34rem;
  background: #fff;
}

.table-input--num {
  text-align: right;
}

.table-add-btn {
  padding: 0.3rem 0.52rem;
  font-size: 0.78rem;
  border-radius: 5px;
  box-shadow: none;
}

.table-add-btn--secondary {
  background: #e9eff2;
  color: #2f414d;
}

.card-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 0.7rem;
}

.add-panel {
  margin-top: 0.62rem;
  border: 1px solid #d3dde1;
  border-radius: 8px;
  background: #f8fbfc;
  padding: 0.62rem;
}

.add-grid {
  display: grid;
  gap: 0.5rem;
}

.add-grid label {
  font-size: 0.8rem;
  font-weight: 600;
}

.add-grid--income {
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
}

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

.add-shares {
  border: 1px solid #d8e2e6;
  border-radius: 7px;
  padding: 0.5rem;
  background: #fff;
}

.shares-editor {
  display: grid;
  gap: 0.45rem;
  min-width: 210px;
}

.shares-editor-rows {
  display: grid;
  gap: 0.3rem;
}

.shares-editor-row {
  display: grid;
  grid-template-columns: auto 1fr 74px;
  align-items: center;
  gap: 0.36rem;
  font-size: 0.78rem;
}

.shares-editor-toggle {
  margin: 0;
}

.shares-editor-name {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.shares-editor-input {
  width: 100%;
  font: inherit;
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: 5px;
  padding: 0.18rem 0.3rem;
}

.shares-editor-input:disabled {
  background: #f0f3f4;
  color: #97a2aa;
}

.shares-editor-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.28rem;
}

.shares-editor-btn {
  padding: 0.22rem 0.48rem;
  font-size: 0.74rem;
  border-radius: 5px;
  box-shadow: none;
}

.shares-editor-btn--secondary {
  background: #e9eff2;
  color: #2f414d;
}

.group {
  border: 1px solid #d5dcde;
  border-radius: var(--radius-md);
  background: linear-gradient(180deg, #ffffff 0%, #fbfdfd 100%);
  padding: 0.75rem;
  margin-bottom: 0.8rem;
}

.group-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.5rem;
  margin-bottom: 0.56rem;
}

.group-head h3 {
  margin: 0;
  font-size: 0.96rem;
}

.group-head p {
  margin: 0;
  color: var(--text-soft);
  font-size: 0.8rem;
  font-variant-numeric: tabular-nums;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.58rem;
}

.split-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.7rem;
}

.person-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.7rem;
  align-items: end;
}

.person-name {
  margin: 0;
}

.split-panel {
  border: 1px solid #d8dedd;
  border-radius: var(--radius-md);
  background: linear-gradient(180deg, #f4fbfa 0%, #f8fbfb 100%);
  padding: 0.78rem;
  display: grid;
  gap: 0.66rem;
}

#import-input {
  display: none;
}

.help,
.empty {
  margin: 0.64rem 0 0;
  color: var(--text-soft);
  font-size: 0.84rem;
}

.no-margin {
  margin-top: 0;
}

.sync-status {
  margin: 0 0 0.8rem;
  border-radius: var(--radius-sm);
  padding: 0.52rem 0.68rem;
  font-size: 0.8rem;
  font-weight: 700;
  border: 1px solid transparent;
}

.sync-status--idle {
  background: #ebefef;
  color: #5a666f;
}

.sync-status--saving {
  background: #fff4dc;
  color: var(--warn);
  border-color: #f2ddb7;
}

.sync-status--ok {
  background: #e7f7ef;
  color: var(--positive);
  border-color: #cce9da;
}

.sync-status--warn {
  background: #fff4df;
  color: var(--warn);
  border-color: #f0ddba;
}

.sync-status--error {
  background: #fdecef;
  color: #8f1d36;
  border-color: #f3c9d3;
}

.delete {
  background: none;
  border: 1px solid #d2d7da;
  box-shadow: none;
  color: #53606b;
  padding: 0.36rem 0.52rem;
  font-size: 0.82rem;
  font-weight: 600;
}

.delete:hover {
  background: #f6f8f9;
  color: #1f2b34;
}

.split-cell {
  color: #4f5f69;
  font-size: 0.8rem;
}

@keyframes card-in {
  from {
    opacity: 0;
    transform: translateY(7px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 980px) {
  .forms {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 720px) {
  .container {
    width: min(1240px, 95vw);
    margin-top: 1rem;
  }

  .hero {
    border-radius: 18px;
    padding: 1.9rem 1.2rem 1.6rem;
  }

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

  .split-grid,
  .person-row {
    grid-template-columns: 1fr;
  }

  .group-head {
    flex-direction: column;
    align-items: flex-start;
  }
}
