:root {
  --bg: #e8efe8;
  --bg-deep: #d5e0d6;
  --ink: #14201a;
  --muted: #5a6b60;
  --line: #b7c5b9;
  --surface: #f7faf7;
  --accent: #1f6b4a;
  --accent-ink: #ffffff;
  --danger: #9b2c2c;
  --warn: #8a6a12;
  --sticky-w: 240px;
  --row-h: 36px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(1200px 600px at 10% -10%, #cfe0d3 0%, transparent 55%),
    linear-gradient(180deg, var(--bg) 0%, var(--bg-deep) 100%);
  color: var(--ink);
  font-family: 'IBM Plex Sans', system-ui, sans-serif;
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.top {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 1.5rem;
  padding: 1.25rem 1.5rem 1rem;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(8px);
  position: sticky;
  top: 0;
  z-index: 20;
}

.eyebrow {
  margin: 0;
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

h1 {
  margin: 0.15rem 0 0;
  font-family: 'IBM Plex Serif', Georgia, serif;
  font-weight: 600;
  font-size: 1.75rem;
  letter-spacing: -0.02em;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  align-items: center;
  justify-content: flex-end;
}

.status {
  font-size: 0.85rem;
  color: var(--muted);
  margin-right: 0.4rem;
}

.status.ok {
  color: var(--accent);
}

.status.err {
  color: var(--danger);
}

.status.busy {
  color: var(--warn);
}

.btn {
  appearance: none;
  border: 0;
  background: var(--accent);
  color: var(--accent-ink);
  font: inherit;
  font-weight: 500;
  font-size: 0.9rem;
  padding: 0.55rem 0.9rem;
  border-radius: 6px;
  cursor: pointer;
}

.btn:hover {
  filter: brightness(1.05);
}

.btn:disabled {
  opacity: 0.55;
  cursor: wait;
}

.btn-secondary {
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--line);
}

.btn-danger {
  background: var(--danger);
  color: #fff;
}

.confirm-message {
  margin: 0;
  color: var(--muted);
  line-height: 1.45;
  font-size: 0.95rem;
}

.btn-ghost {
  background: transparent;
  color: var(--muted);
  border: 0;
  padding: 0.2rem 0.4rem;
  font-size: 0.8rem;
}

.btn-ghost:hover {
  color: var(--danger);
}

.btn-tiny {
  background: transparent;
  color: var(--accent);
  border: 1px dashed color-mix(in srgb, var(--accent) 40%, var(--line));
  font-size: 0.78rem;
  padding: 0.25rem 0.5rem;
}

main {
  padding: 1rem 1.5rem 2rem;
  flex: 1;
}

.table-wrap {
  overflow: auto;
  max-height: calc(100vh - 7rem);
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
}

table {
  border-collapse: separate;
  border-spacing: 0;
  width: max-content;
  min-width: 100%;
  font-size: 0.88rem;
}

thead th {
  position: sticky;
  top: 0;
  z-index: 5;
  background: #eef4ef;
  border-bottom: 1px solid var(--line);
  padding: 0.65rem 0.55rem;
  font-weight: 600;
  text-align: right;
  white-space: nowrap;
}

thead th.sticky-col,
tbody th.sticky-col,
tfoot th.sticky-col {
  position: sticky;
  left: 0;
  text-align: left;
  min-width: var(--sticky-w);
  max-width: var(--sticky-w);
  z-index: 6;
  background: #eef4ef;
}

tbody th.sticky-col {
  z-index: 4;
  background: var(--surface);
}

tfoot th.sticky-col {
  background: #e3ece4;
}

tfoot .totals-income th.sticky-col,
tfoot .totals-income td {
  background: #dceee1;
}

tfoot .totals-rest th.sticky-col,
tfoot .totals-rest td {
  background: #d4e4d7;
}

th.group-row {
  position: static;
  background: #dfeadf !important;
  font-family: 'IBM Plex Serif', Georgia, serif;
  font-weight: 600;
  font-size: 0.95rem;
  padding: 0.55rem 0.75rem;
  border-top: 1px solid var(--line);
  min-width: 0;
  max-width: none;
  text-align: left;
}

td,
tbody th,
tfoot td,
tfoot th {
  border-bottom: 1px solid color-mix(in srgb, var(--line) 70%, transparent);
  height: var(--row-h);
  padding: 0;
}

td {
  text-align: right;
  min-width: 92px;
}

td input {
  position: relative;
  z-index: 1;
  width: 100%;
  height: var(--row-h);
  border: 0;
  background: #fff;
  text-align: right;
  font: inherit;
  padding: 0 0.55rem;
  color: var(--ink);
  cursor: text;
  caret-color: var(--accent);
}

td input:focus {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
  background: #fff;
}

td input:disabled {
  color: var(--muted);
  cursor: default;
}

.name-cell {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0 0.55rem;
  height: var(--row-h);
}

.name-cell input {
  flex: 1;
  border: 0;
  background: transparent;
  font: inherit;
  min-width: 0;
}

.name-cell input:focus {
  outline: none;
  background: #fff;
  box-shadow: inset 0 0 0 1px var(--line);
}

tr.income td,
tr.income th.sticky-col {
  background: #eef6f0;
}

.totals td,
.totals th {
  font-weight: 600;
  background: #e3ece4;
}

.totals-income td,
.totals-income th {
  background: #dceee1;
}

.totals-rest td,
.totals-rest th {
  background: #d4e4d7;
}

.group-actions {
  display: flex;
  gap: 0.35rem;
  align-items: center;
  justify-content: space-between;
}

dialog {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0;
  background: var(--surface);
  color: var(--ink);
  width: min(420px, 92vw);
}

dialog::backdrop {
  background: rgb(20 32 26 / 45%);
}

#dialog-form {
  display: grid;
  gap: 0.9rem;
  padding: 1.2rem;
}

#dialog-form h2 {
  margin: 0;
  font-family: 'IBM Plex Serif', Georgia, serif;
  font-size: 1.2rem;
}

#dialog-form label {
  display: grid;
  gap: 0.35rem;
  font-size: 0.85rem;
  color: var(--muted);
}

#dialog-form input,
#dialog-form select {
  font: inherit;
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0.55rem 0.65rem;
  background: #fff;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
}

@media (max-width: 720px) {
  .top {
    flex-direction: column;
    align-items: start;
  }

  :root {
    --sticky-w: 170px;
  }
}
