/* Restaurant bill splitter (/tools/restaurant-bill-splitter): mode switch, people list, item cards
   with "who had it" chips, tax/tip fields and the per-person result. Builds on the .nk-* tools block
   in site.css. */

/* Panels and results toggled by the script use [hidden]; inline display: flex must not win. */
[data-bill-splitter] [hidden] {
  display: none !important;
}

/* Visually hidden label text (still read by screen readers). */
.nk-rb-sr {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* Mode switch with the Clear button on the right. */
.nk-rb-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 16px;
}

/* Mode switch: a bit larger than the default segmented control. */
.nk-rb-mode {
  align-self: flex-start;
  max-width: 100%;
}
.nk-rb-mode span {
  min-height: 44px;
  padding: 0 22px;
  font-size: 15px;
}

/* People: two columns of name fields on wide cards, one column on phones. */
.nk-rb-people {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 190px), 1fr));
  gap: 10px;
}
.nk-rb-person {
  display: grid;
  grid-template-columns: 10px minmax(0, 1fr) 36px;
  gap: 8px;
  align-items: center;
}

/* One item = a small parchment card: name, price, remove, then the chips. */
.nk-rb-item {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px;
  border-radius: 18px;
  background: #f7f1e8;
}
.nk-rb-item__top {
  display: grid;
  grid-template-columns: minmax(0, 1fr) clamp(84px, 28%, 120px) 36px;
  gap: 8px;
  align-items: center;
}
.nk-rb-item .nk-input {
  height: 46px;
}

/* Two fields side by side (tax + payer, bill + people). */
.nk-rb-fields {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 170px), 1fr));
  gap: 12px;
}
.nk-rb-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}
.nk-rb-field > span {
  font-size: 13px;
  font-weight: 600;
  color: #7a6a5c;
}
.nk-rb-hint {
  margin: -6px 0 0;
  font-size: 13px;
  line-height: 1.5;
  color: #9a8570;
}
.nk-rb-select {
  padding-right: 36px;
  font-size: 16px;
  appearance: none;
  -webkit-appearance: none;
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5l5 5 5-5' fill='none' stroke='%238b5e3c' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
}

/* Tip: presets + a custom percent field. */
.nk-rb-tip .nk-calc-label {
  margin-bottom: 8px;
}
.nk-rb-tip__row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}
.nk-rb-tip .nk-seg {
  flex-wrap: wrap;
}
.nk-rb-tip .nk-seg span {
  padding: 0 12px;
  font-variant-numeric: tabular-nums;
}
.nk-rb-pct {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 16px;
  font-weight: 600;
  color: #7a6a5c;
}
.nk-rb-pct .nk-input {
  width: 76px;
  height: 44px;
}

/* People count stepper (split evenly). */
.nk-rb-stepper {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) 44px;
  gap: 6px;
  align-items: center;
}
.nk-rb-stepper .nk-input {
  text-align: center;
  font-variant-numeric: tabular-nums;
}
.nk-rb-stepper .nk-icon-btn {
  width: 44px;
  height: 44px;
  background: #f7f1e8;
  color: #8b5e3c;
}

.nk-rb-check {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  font-size: 15px;
  line-height: 1.45;
  color: #3b302b;
  cursor: pointer;
}
.nk-rb-check input {
  width: 20px;
  height: 20px;
  margin: 1px 0 0;
  flex: none;
  accent-color: #7a9970;
}

/* "Who had it" chips. */
.nk-rb-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.nk-rb-chip {
  position: relative;
  cursor: pointer;
  max-width: 100%;
}
.nk-rb-chip input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
  pointer-events: none;
}
.nk-rb-chip span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 36px;
  max-width: 100%;
  box-sizing: border-box;
  padding: 0 14px;
  border-radius: 999px;
  border: 1.5px solid #ddd5c8;
  background: transparent;
  font-size: 14px;
  font-weight: 500;
  color: #9a8570;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  transition:
    background-color 0.15s ease,
    border-color 0.15s ease,
    color 0.15s ease;
}
.nk-rb-chip span::before {
  content: '';
  width: 14px;
  height: 14px;
  flex: none;
  border-radius: 50%;
  border: 1.5px solid #ddd5c8;
  box-sizing: border-box;
}
.nk-rb-chip input:checked + span {
  background: #fffdf9;
  border-color: rgba(59, 48, 43, 0.22);
  color: #2e2018;
}
.nk-rb-chip input:checked + span::before {
  border: 0;
  background: #7a9970
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='8' viewBox='0 0 10 8'%3E%3Cpath d='M1 4l2.6 2.6L9 1.2' fill='none' stroke='%23fffdf9' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E")
    center / 9px 7px no-repeat;
}
.nk-rb-chip input:focus-visible + span {
  outline: 2px solid #8b5e3c;
  outline-offset: 2px;
}
.nk-rb-chip:hover span {
  border-color: #c8bbae;
}
.nk-rb-warn {
  margin: 0;
  font-size: 13px;
  line-height: 1.45;
  color: #8b5e3c;
}

/* Result: one row per person, and the pay-back list. */
.nk-rb-shares,
.nk-rb-transfers {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.nk-rb-shares li,
.nk-rb-transfers li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-radius: 16px;
  background: #f7f1e8;
  font-size: 16px;
  color: #3b302b;
}
.nk-rb-transfers li {
  padding: 10px 16px;
  background: transparent;
  box-shadow: inset 0 0 0 1px #e5ddd2;
  font-size: 15px;
}
.nk-rb-share__who {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 8px;
  min-width: 0;
  overflow-wrap: anywhere;
}
.nk-rb-share__who strong {
  color: #2e2018;
  font-weight: 700;
}
.nk-rb-share__amount {
  flex: none;
  font-weight: 800;
  letter-spacing: -0.02em;
  font-size: 22px;
  color: #2e2018;
  font-variant-numeric: tabular-nums;
}
.nk-rb-transfer__amount {
  flex: none;
  font-weight: 700;
  font-size: 16px;
  color: #2e2018;
  font-variant-numeric: tabular-nums;
}
.nk-rb-none {
  margin: 0;
  font-size: 15px;
  color: #7a6a5c;
}

/* Tables: row headers and the total column. */
.nk-table tbody th.nk-rb-rowhead {
  font-weight: 600;
  color: #2e2018;
  text-align: left;
  padding-left: 0;
  overflow-wrap: anywhere;
}
.nk-table td.nk-rb-strong {
  color: #2e2018;
  font-weight: 700;
}

/* Disabled add/remove buttons (12-person limit, last person). */
[data-bill-splitter] .nk-icon-btn:disabled,
[data-bill-splitter] .nk-text-btn:disabled {
  opacity: 0.35;
  cursor: default;
  text-decoration: none;
}

@media (max-width: 480px) {
  .nk-rb-item {
    padding: 12px;
  }
  .nk-rb-item .nk-input {
    padding: 0 10px;
    font-size: 16px;
  }
  .nk-rb-mode span {
    padding: 0 14px;
  }
  .nk-rb-compact .nk-table {
    font-size: 14px;
  }
  .nk-rb-compact .nk-table th,
  .nk-rb-compact .nk-table td {
    padding: 9px 6px;
  }
  .nk-rb-compact .nk-table thead th {
    font-size: 11px;
    letter-spacing: 0.04em;
  }
  .nk-rb-compact .nk-table tbody th.nk-rb-rowhead {
    min-width: 60px;
    overflow-wrap: normal;
  }
  .nk-rb-shares li {
    padding: 12px 14px;
  }
}
@media (prefers-reduced-motion: reduce) {
  .nk-rb-chip span {
    transition: none;
  }
}
