* {
  box-sizing: border-box;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: #1a1a1a;
  background: #fafafa;
  margin: 0;
  padding: 24px;
}

main {
  max-width: 720px;
  margin: 0 auto;
}

h1 {
  font-size: 22px;
  margin: 0;
}

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

.icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  padding: 0;
  border-radius: 50%;
  color: #444;
}

.icon-btn:disabled {
  opacity: 0.4;
  cursor: default;
}

h2 {
  font-size: 16px;
  margin-bottom: 8px;
}

section {
  background: #fff;
  border: 1px solid #e0e0e0;
  border-radius: 10px;
  padding: 16px 20px;
  margin-bottom: 16px;
}

label {
  display: block;
  font-size: 12px;
  color: #666;
  margin-bottom: 4px;
}

input[type="text"],
input[type="number"],
textarea {
  width: 100%;
  font-size: 14px;
  padding: 8px 10px;
  border: 1px solid #ccc;
  border-radius: 6px;
  font-family: inherit;
}

textarea {
  resize: vertical;
  font-family: ui-monospace, monospace;
  font-size: 13px;
  margin-bottom: 8px;
}

button {
  font-size: 13px;
  padding: 8px 14px;
  border: 1px solid #ccc;
  border-radius: 6px;
  background: #f5f5f5;
  cursor: pointer;
}

button:hover {
  background: #eee;
}

.roster-chips {
  margin-top: 10px;
  font-size: 13px;
  color: #444;
}

.ledger-table-wrap {
  overflow-x: auto;
}

#ledger-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 16px;
  margin-bottom: 10px;
}

#ledger-table th,
#ledger-table td {
  padding: 6px 6px;
  text-align: left;
  border-bottom: 1px solid #eee;
  font-size: 13px;
}

#ledger-table th {
  color: #888;
  font-weight: 500;
  font-size: 12px;
}

#ledger-table select {
  width: 100%;
  font-size: 16px;
  padding: 6px;
  border: 1px solid #ccc;
  border-radius: 6px;
}

#ledger-table input[type="text"],
#ledger-table input[type="number"] {
  font-size: 16px;
}

#ledger-table input[type="number"] {
  text-align: right;
  width: 90px;
}

.row-summary {
  display: none;
}

tr.row-warning {
  background: #fff6e5;
}

.amount-negative {
  color: #b3261e;
}

#ledger-table input[type="number"].amount-negative {
  color: #b3261e;
}

.split-toggle-btn {
  font-size: 12px;
  padding: 6px 10px;
}

.split-toggle-btn.split-custom {
  border-color: #1a6b3c;
  background: #2a6f4b;
  color: #fff;
  font-weight: 600;
}

.split-toggle-btn.split-custom::before {
  content: "●";
  font-size: 8px;
  margin-right: 5px;
  vertical-align: 1px;
}

.split-toggle-btn.split-custom:hover {
  background: #235c3d;
}

tr.split-row {
  background: #f7f7f7;
}

.split-editor {
  padding: 10px 6px !important;
}

.split-editor-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
}

.split-editor-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: #444;
}

.split-editor-item input[type="number"] {
  width: 60px;
  font-size: 16px;
  padding: 4px 6px;
  text-align: right;
}

.split-apply-all-btn {
  margin-top: 10px;
  margin-right: 8px;
  font-size: 12px;
  padding: 6px 10px;
  color: #1a5fb4;
  border-color: #b6d0ec;
  background: #fff;
}

.split-apply-all-btn:hover {
  background: #eaf2fb;
}

.split-clear-btn {
  margin-top: 10px;
  font-size: 12px;
  padding: 6px 10px;
  color: #b3261e;
  border-color: #e0b4af;
  background: #fff;
}

.split-clear-btn:hover {
  background: #fbebe9;
}

#ledger-table tfoot td {
  border-bottom: none;
  border-top: 2px solid #ddd;
  padding-top: 8px;
}

.total-label {
  font-weight: 600;
}

.total-amount {
  font-weight: 600;
  text-align: right;
}

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

@media (max-width: 599.98px) {
  #ledger-table thead {
    display: none;
  }

  #ledger-table,
  #ledger-table tbody {
    display: block;
    width: 100%;
  }

  #ledger-table tbody tr {
    display: block;
    border: 1px solid #eee;
    border-radius: 8px;
    padding: 4px 10px;
    margin-bottom: 8px;
  }

  #ledger-table tbody tr.row-warning {
    border-color: #f0d38a;
  }

  #ledger-table tbody td {
    display: block;
    width: 100%;
    border-bottom: none;
    padding: 8px 0;
  }

  #ledger-table tbody tr:not(.row-expanded) td:not(.row-summary) {
    display: none;
  }

  #ledger-table tbody td[data-label]::before {
    content: attr(data-label);
    display: block;
    font-size: 11px;
    color: #888;
    margin-bottom: 3px;
  }

  .row-summary {
    display: block;
    padding: 0 !important;
  }

  .row-summary-toggle {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 10px;
    width: 100%;
    padding: 10px 0;
    border: none;
    background: none;
    text-align: left;
    font: inherit;
    cursor: pointer;
  }

  .row-summary-text {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: #1a1a1a;
  }

  .row-summary-amount {
    flex-shrink: 0;
    font-weight: 600;
  }

  .row-summary-chevron {
    flex-shrink: 0;
    color: #999;
    transition: transform 0.15s ease;
  }

  tr.row-expanded .row-summary-chevron {
    transform: rotate(90deg);
  }

  tr.row-expanded .row-summary-toggle {
    border-bottom: 1px solid #eee;
  }

  #ledger-table tbody tr.split-row {
    border-top: none;
    margin-top: -8px;
    padding-top: 0;
  }

  #ledger-table tbody tr.split-row:not(.row-expanded) {
    display: none;
  }

  .split-editor-list {
    flex-direction: column;
    gap: 8px;
  }

  #ledger-table tfoot,
  #ledger-table tfoot tr {
    display: flex;
  }

  #ledger-table tfoot tr {
    width: 100%;
    justify-content: space-between;
    align-items: baseline;
    border: none;
    border-top: 2px solid #ddd;
    padding-top: 8px;
  }

  #ledger-table tfoot td {
    display: inline;
    width: auto;
    padding: 0;
    border-top: none;
  }

  #ledger-table tfoot .total-spacer {
    display: none;
  }
}

.excluded-count {
  font-size: 12px;
  color: #9a6a00;
  margin-top: 6px;
}

.load-error {
  font-size: 13px;
  color: #7a1f1f;
  background: #fdecec;
  border: 1px solid #f3c6c6;
  border-radius: 8px;
  padding: 10px 14px;
  margin-bottom: 16px;
}

.share-status {
  font-size: 12px;
  color: #1a6b3c;
  margin-top: 8px;
}

.share-fallback {
  margin-top: 8px;
}

.share-fallback input[type="text"] {
  font-family: ui-monospace, monospace;
  font-size: 12px;
}

#results {
  font-size: 14px;
  line-height: 1.7;
}

#results .payments {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid #eee;
}

#results .payments div {
  font-weight: 600;
}
