:root {
  --bg: #f6f4ef;
  --surface: #ffffff;
  --surface-2: #f1f5f2;
  --ink: #1f2520;
  --muted: #677067;
  --line: #d9ded7;
  --green: #19714d;
  --green-soft: #dff3e9;
  --red: #b24038;
  --red-soft: #fae8e5;
  --blue: #2d5d86;
  --blue-soft: #e1edf7;
  --gold: #8b671a;
  --gold-soft: #fff0c8;
  --shadow: 0 18px 45px rgba(34, 39, 35, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-card {
  width: min(420px, 100%);
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.login-brand {
  margin-bottom: 22px;
}

.alert {
  margin-bottom: 14px;
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 14px;
}

.alert.error {
  background: var(--red-soft);
  color: var(--red);
}

.account-bar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  padding: 10px 18px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.account-bar > div:first-child {
  margin-right: auto;
}

.account-message {
  margin-left: 10px;
  color: var(--green);
  font-size: 13px;
  font-weight: 700;
}

.account-panel {
  position: relative;
}

.account-panel summary {
  cursor: pointer;
  color: var(--green);
  font-weight: 700;
  list-style: none;
}

.account-panel summary::-webkit-details-marker {
  display: none;
}

.account-form {
  position: absolute;
  z-index: 10;
  right: 0;
  top: calc(100% + 10px);
  width: min(360px, calc(100vw - 36px));
  display: grid;
  gap: 10px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 22px;
  background: #17231d;
  color: #f8fbf7;
  display: flex;
  flex-direction: column;
  gap: 28px;
}

.brand {
  display: grid;
  grid-template-columns: 48px 1fr;
  gap: 12px;
  align-items: center;
}

.brand-mark {
  width: 48px;
  height: 48px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: #e8b54f;
  color: #142019;
  font-weight: 800;
}

.brand h1,
.brand p,
.topbar h2,
.topbar p,
.panel h3,
.schema-block h4 {
  margin: 0;
}

.brand h1 {
  font-size: 19px;
}

.brand p,
.sync-panel p,
.eyebrow,
.muted {
  color: var(--muted);
  font-size: 13px;
}

.brand p,
.sync-panel p {
  color: #b8c3ba;
}

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

.nav-item {
  min-height: 42px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: #dfe8e0;
  text-align: left;
  padding: 0 14px;
}

.nav-item:hover,
.nav-item.active {
  background: #24352c;
  border-color: #385244;
}

.sync-panel {
  margin-top: auto;
  display: grid;
  grid-template-columns: 10px 1fr;
  gap: 10px;
  padding: 14px;
  border: 1px solid #32493d;
  border-radius: 8px;
  background: #1d2c24;
}

.status-dot {
  width: 10px;
  height: 10px;
  margin-top: 4px;
  border-radius: 50%;
  background: #e8b54f;
}

.status-dot.online {
  background: #54c081;
}

.workspace {
  min-width: 0;
  padding: 28px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
}

.topbar h2 {
  font-size: 30px;
}

.topbar-actions,
.button-row,
.dialog-actions,
.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.primary-button,
.ghost-button,
.text-button,
.icon-button {
  border-radius: 8px;
  min-height: 40px;
  border: 1px solid transparent;
}

.primary-button {
  background: var(--green);
  color: #fff;
  padding: 0 16px;
  font-weight: 700;
}

.ghost-button {
  background: var(--surface);
  color: var(--ink);
  border-color: var(--line);
  padding: 0 14px;
}

.ghost-button:disabled,
.primary-button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.text-button {
  min-height: auto;
  color: var(--green);
  background: transparent;
  padding: 0;
  font-weight: 700;
}

.icon-button {
  width: 36px;
  background: var(--surface-2);
  color: var(--ink);
  font-size: 22px;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(180px, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.metric,
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.metric {
  padding: 18px;
}

.metric span,
th,
label {
  color: var(--muted);
  font-size: 13px;
}

.metric strong {
  display: block;
  margin-top: 8px;
  font-size: 28px;
}

.metric p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.metric.receive {
  background: var(--green-soft);
}

.metric.pay {
  background: var(--red-soft);
}

.metric.neutral {
  background: var(--blue-soft);
}

.metric.partial {
  background: var(--gold-soft);
}

.content-grid,
.settings-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(320px, 0.65fr);
  gap: 18px;
}

.panel {
  padding: 18px;
}

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

.toolbar {
  justify-content: space-between;
  margin-bottom: 14px;
}

.search-box {
  display: grid;
  gap: 6px;
}

.search-box input,
.search-box select,
select,
input {
  height: 40px;
  min-width: 180px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 11px;
  background: var(--surface);
  color: var(--ink);
}

.table-wrap {
  overflow: auto;
}

.table-wrap.large {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 760px;
}

th,
td {
  padding: 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

tbody tr:last-child td {
  border-bottom: 0;
}

.num {
  text-align: right;
  white-space: nowrap;
}

.pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 26px;
  border-radius: 999px;
  padding: 0 10px;
  font-size: 12px;
  font-weight: 800;
}

.pill.receive {
  color: var(--green);
  background: var(--green-soft);
}

.pill.pay {
  color: var(--red);
  background: var(--red-soft);
}

.pill.paid {
  color: var(--blue);
  background: var(--blue-soft);
}

.pill.partial {
  color: var(--gold);
  background: var(--gold-soft);
}

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

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

.person-line,
.ledger-entry {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: var(--surface-2);
}

.person-line {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

.person-line strong,
.ledger-entry strong {
  display: block;
}

.person-line span,
.ledger-entry span {
  color: var(--muted);
  font-size: 13px;
}

.ledger-stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(140px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.ledger-stat {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: var(--surface);
}

.ledger-list {
  display: grid;
  gap: 12px;
}

.ledger-payments {
  margin-top: 10px;
  display: grid;
  gap: 6px;
}

.entry-summary {
  margin-bottom: 14px;
}

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

.entry-summary-grid > div,
.payment-history {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: var(--surface-2);
}

.entry-summary-grid span,
.payment-history span,
.balance-note {
  color: var(--muted);
  font-size: 13px;
}

.entry-summary-grid strong,
.payment-history strong {
  display: block;
  margin-top: 4px;
}

.payment-history {
  display: grid;
  gap: 6px;
  margin-top: 10px;
}

.balance-note {
  align-self: end;
  min-height: 40px;
  display: flex;
  align-items: center;
}

.schema-block {
  margin-top: 14px;
  padding: 12px;
  border-radius: 8px;
  background: var(--surface-2);
}

.schema-block p {
  margin: 6px 0 0;
  color: var(--muted);
  line-height: 1.5;
}

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

.form-stack label,
.form-grid label {
  display: grid;
  gap: 6px;
}

.form-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.form-grid .wide {
  grid-column: 1 / -1;
}

dialog {
  width: min(720px, calc(100vw - 30px));
  border: 0;
  border-radius: 8px;
  padding: 0;
  box-shadow: 0 24px 80px rgba(22, 31, 26, 0.28);
}

dialog::backdrop {
  background: rgba(15, 20, 17, 0.45);
}

.dialog-form {
  padding: 18px;
}

.dialog-heading {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.dialog-heading h3 {
  margin: 0;
  font-size: 22px;
}

.dialog-actions {
  justify-content: flex-end;
  margin-top: 18px;
}

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  max-width: 340px;
  padding: 12px 14px;
  border-radius: 8px;
  background: #17231d;
  color: #fff;
  box-shadow: var(--shadow);
  transform: translateY(16px);
  opacity: 0;
  pointer-events: none;
  transition: 160ms ease;
}

.toast.show {
  transform: translateY(0);
  opacity: 1;
}

.empty {
  padding: 20px;
  color: var(--muted);
  text-align: center;
}

@media (max-width: 960px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
  }

  .nav {
    grid-template-columns: repeat(6, minmax(110px, 1fr));
    overflow: auto;
  }

  .metric-grid,
  .content-grid,
  .settings-grid,
  .ledger-stats {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 640px) {
  .account-bar {
    align-items: flex-start;
    flex-direction: column;
  }

  .account-bar > div:first-child {
    margin-right: 0;
  }

  .account-form {
    left: 0;
    right: auto;
  }

  .workspace {
    padding: 18px;
  }

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

  .metric-grid,
  .content-grid,
  .settings-grid,
  .ledger-stats,
  .entry-summary-grid,
  .form-grid {
    grid-template-columns: 1fr;
  }

  .topbar-actions,
  .toolbar {
    width: 100%;
  }

  .topbar-actions > *,
  .toolbar > *,
  .search-box,
  .search-box input,
  .search-box select,
  select {
    width: 100%;
  }
}
