:root {
  color-scheme: light;
  --bg: #f5f7f6;
  --surface: #ffffff;
  --surface-muted: #eef4f1;
  --ink: #15211f;
  --muted: #63706d;
  --line: #d9e3df;
  --teal: #0f766e;
  --teal-deep: #0b5f59;
  --blue: #2563eb;
  --amber: #b45309;
  --rose: #be123c;
  --green: #15803d;
  --shadow: 0 18px 50px rgba(18, 34, 31, 0.08);
  --radius: 8px;
  --tap: 44px;
  font-family: "Segoe UI", Tahoma, Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  min-height: 100%;
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(180deg, rgba(15, 118, 110, 0.08), rgba(15, 118, 110, 0) 260px),
    var(--bg);
}

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  width: min(1180px, 100%);
  margin: 0 auto;
  padding: 18px 18px 48px;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 16px;
  min-height: 72px;
  padding: 6px 0 18px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-mark {
  width: 52px;
  height: 52px;
  border-radius: 8px;
  box-shadow: 0 10px 24px rgba(15, 118, 110, 0.18);
}

.eyebrow,
.brand h1,
.stat-card p,
.section-heading h2,
.empty-state h3,
.empty-state p {
  margin: 0;
}

.eyebrow {
  color: var(--muted);
  font-size: 0.84rem;
}

.brand h1 {
  font-size: 1.9rem;
  line-height: 1.05;
}

.owner-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 40px;
  padding: 0 14px;
  border: 1px solid rgba(15, 118, 110, 0.22);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.72);
  color: var(--teal-deep);
  box-shadow: 0 12px 28px rgba(15, 118, 110, 0.1);
  font-weight: 800;
  letter-spacing: 0;
  white-space: nowrap;
}

.owner-dot {
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border-radius: 7px;
  background: var(--teal);
  color: #ffffff;
  font-size: 0.92rem;
  line-height: 1;
}

.header-actions,
.section-heading,
.toolbar,
.filter-buttons {
  display: flex;
  align-items: center;
  gap: 8px;
}

.header-actions {
  flex-shrink: 0;
}

.icon-button,
.ghost-button,
.primary-button,
.filter-button {
  min-height: var(--tap);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
}

.icon-button {
  display: inline-grid;
  place-items: center;
  width: var(--tap);
  padding: 0;
}

.icon-button input {
  display: none;
}

.ghost-button,
.primary-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 14px;
  white-space: nowrap;
}

.primary-button {
  width: 100%;
  border-color: var(--teal);
  color: #ffffff;
  background: var(--teal);
  font-weight: 700;
}

.primary-button:hover,
.primary-button:focus-visible {
  background: var(--teal-deep);
}

.ghost-button:hover,
.icon-button:hover,
.filter-button:hover,
.ghost-button:focus-visible,
.icon-button:focus-visible,
.filter-button:focus-visible {
  border-color: var(--teal);
  outline: none;
}

[data-icon] svg {
  display: block;
  width: 20px;
  height: 20px;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  fill: none;
}

.workspace {
  display: grid;
  gap: 18px;
}

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

.stat-card {
  display: grid;
  grid-template-columns: 42px 1fr;
  align-items: center;
  gap: 10px;
  min-height: 96px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.stat-icon {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 8px;
  color: #ffffff;
}

.stat-card p {
  color: var(--muted);
  font-size: 0.86rem;
}

.stat-card strong {
  display: block;
  margin-top: 4px;
  font-size: 1.24rem;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.stat-positive .stat-icon {
  background: var(--green);
}

.stat-negative .stat-icon {
  background: var(--rose);
}

.stat-net .stat-icon {
  background: var(--blue);
}

.stat-people .stat-icon {
  background: var(--amber);
}

.stat-overdue .stat-icon {
  background: #7c3aed;
}

.control-grid {
  display: grid;
  grid-template-columns: minmax(320px, 420px) minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.framed-tool,
.ledger-section {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.9);
  box-shadow: var(--shadow);
}

.entry-form,
.people-panel {
  display: grid;
  gap: 16px;
  padding: 16px;
}

.section-heading {
  justify-content: space-between;
}

.section-heading h2 {
  font-size: 1.08rem;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin: 0;
  padding: 0;
  border: 0;
}

.segmented label {
  min-width: 0;
}

.segmented input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.segmented span {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: var(--tap);
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-muted);
  color: var(--muted);
  font-weight: 700;
  white-space: nowrap;
}

.segmented input:checked + span {
  border-color: var(--teal);
  background: #e5f4ef;
  color: var(--teal-deep);
}

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

.field {
  display: grid;
  gap: 7px;
  min-width: 0;
}

.field span {
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 700;
}

.field input,
.field textarea,
.search-box input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  outline: none;
}

.field input,
.search-box input {
  min-height: var(--tap);
  padding: 0 12px;
}

.field textarea {
  resize: vertical;
  min-height: 86px;
  padding: 10px 12px;
}

.field input:focus,
.field textarea:focus,
.search-box input:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.12);
}

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

.person-card {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: center;
  min-height: 72px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.person-card h3,
.person-card p {
  margin: 0;
}

.person-card h3 {
  font-size: 1rem;
}

.person-card p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.84rem;
}

.person-overdue {
  color: var(--rose) !important;
  font-weight: 800;
}

.person-side {
  display: grid;
  justify-items: end;
  gap: 8px;
}

.balance-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 98px;
  min-height: 36px;
  padding: 0 10px;
  border-radius: 999px;
  font-weight: 800;
  white-space: nowrap;
}

.settle-button {
  min-height: 34px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-muted);
  color: var(--teal-deep);
  font-weight: 800;
}

.settle-button:hover,
.settle-button:focus-visible {
  border-color: var(--teal);
  background: #e5f4ef;
  outline: none;
}

.balance-positive {
  color: #116237;
  background: #dcfce7;
}

.balance-negative {
  color: #9f1239;
  background: #ffe4e6;
}

.balance-zero {
  color: var(--muted);
  background: var(--surface-muted);
}

.ledger-section {
  display: grid;
  gap: 0;
  overflow: hidden;
}

.toolbar {
  justify-content: space-between;
  flex-wrap: wrap;
  padding: 14px;
  border-bottom: 1px solid var(--line);
}

.search-box {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1 1 240px;
  min-width: 210px;
  padding-inline-start: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.search-box input {
  border: 0;
  box-shadow: none;
  padding-inline-start: 0;
}

.filter-buttons {
  flex-wrap: wrap;
}

.filter-button {
  min-width: 64px;
  padding: 0 12px;
  font-weight: 700;
}

.filter-button.active {
  border-color: var(--teal);
  background: var(--teal);
  color: #ffffff;
}

.ledger-list {
  display: grid;
}

.ledger-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
  min-height: 78px;
  padding: 14px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.ledger-item:last-child {
  border-bottom: 0;
}

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

.ledger-title {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0 0 5px;
}

.ledger-title strong {
  overflow-wrap: anywhere;
}

.kind-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 28px;
  padding: 0 9px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 800;
  white-space: nowrap;
}

.chip-positive {
  color: #116237;
  background: #dcfce7;
}

.chip-negative {
  color: #9f1239;
  background: #ffe4e6;
}

.chip-neutral {
  color: #1d4ed8;
  background: #dbeafe;
}

.chip-overdue {
  color: #991b1b;
  background: #fee2e2;
}

.ledger-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  color: var(--muted);
  font-size: 0.84rem;
}

.ledger-amount {
  text-align: left;
  font-weight: 900;
  white-space: nowrap;
}

.ledger-actions {
  display: flex;
  justify-content: flex-end;
  gap: 6px;
  margin-top: 8px;
}

.mini-button {
  display: inline-grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--muted);
}

.mini-button:hover,
.mini-button:focus-visible {
  border-color: var(--teal);
  color: var(--teal);
  outline: none;
}

.empty-state {
  display: grid;
  justify-items: center;
  gap: 8px;
  min-height: 210px;
  padding: 34px 18px;
  color: var(--muted);
  text-align: center;
}

.empty-state [data-icon] {
  display: grid;
  place-items: center;
  width: 56px;
  height: 56px;
  border-radius: 8px;
  color: var(--teal);
  background: #e5f4ef;
}

.empty-state h3 {
  color: var(--ink);
  font-size: 1.05rem;
}

.toast {
  position: fixed;
  inset-inline: 18px;
  bottom: 18px;
  z-index: 20;
  display: none;
  width: min(420px, calc(100% - 36px));
  margin-inline: auto;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #12221f;
  color: #ffffff;
  box-shadow: var(--shadow);
  text-align: center;
}

.toast.visible {
  display: block;
}

.modal-backdrop,
.lock-screen {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(18, 34, 31, 0.38);
  backdrop-filter: blur(8px);
}

.modal-backdrop[hidden],
.lock-screen[hidden] {
  display: none;
}

.modal-panel,
.lock-card {
  width: min(720px, 100%);
  max-height: calc(100dvh - 36px);
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: 0 28px 80px rgba(18, 34, 31, 0.22);
}

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

.settings-grid {
  display: grid;
  gap: 12px;
}

.settings-block {
  display: grid;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-muted);
}

.settings-block p,
.lock-card p {
  margin: 0;
  color: var(--muted);
  line-height: 1.7;
}

.settings-block-title {
  display: flex;
  align-items: center;
  gap: 8px;
}

.settings-block-title h3,
.lock-card h2 {
  margin: 0;
}

.settings-block-title [data-icon] {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  color: #ffffff;
  background: var(--teal);
}

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

.settings-actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.settings-actions .primary-button,
.settings-actions .ghost-button {
  width: 100%;
  padding: 0 10px;
}

.settings-actions button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.lock-card {
  display: grid;
  gap: 14px;
  justify-items: stretch;
  max-width: 420px;
  padding: 22px;
}

.lock-mark {
  width: 64px;
  height: 64px;
  border-radius: var(--radius);
}

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

@media (max-width: 560px) {
  .app-shell {
    padding: 12px 12px 34px;
  }

  .app-header {
    align-items: flex-start;
  }

  .brand-mark {
    width: 46px;
    height: 46px;
  }

  .brand h1 {
    font-size: 1.55rem;
  }

  .owner-mark {
    order: 3;
    width: 100%;
  }

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

  .stat-card {
    min-height: 84px;
  }

  .toolbar {
    align-items: stretch;
  }

  .search-box,
  .filter-buttons,
  .toolbar .ghost-button {
    width: 100%;
  }

  .filter-button {
    min-width: 0;
    padding: 0 6px;
  }

  .ledger-item {
    grid-template-columns: 1fr;
  }

  .ledger-amount {
    text-align: right;
  }

  .person-card,
  .settings-actions {
    grid-template-columns: 1fr;
  }

  .person-side {
    justify-items: stretch;
  }
}

@media print {
  body {
    background: #ffffff;
  }

  .header-actions,
  .entry-form,
  .toolbar,
  .ledger-actions,
  .toast {
    display: none !important;
  }

  .app-shell {
    width: 100%;
    padding: 0;
  }

  .framed-tool,
  .ledger-section,
  .stat-card {
    box-shadow: none;
  }
}
