/* ==========================================================================
   Rachel's Place — Children register (Director & Owner tool)
   Builds on kpi.css; same tokens, table shell, locks and status pills.
   ========================================================================== */

body[data-page="children"] {
  background: var(--color-bg);
}

body[data-page="children"] .site-footer {
  margin-top: var(--space-16);
}

/* Filters row inside the shared toolbar */
.chd-filters {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
  flex: 1 1 24rem;
}

.chd-search {
  flex: 1 1 14rem;
  min-width: 11rem;
}

.chd-search,
.chd-filters select {
  width: auto;
  max-width: 100%;
  padding: 0.45rem 0.7rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  color: var(--color-text);
  font: inherit;
  font-size: var(--text-sm);
}

.chd-search:focus,
.chd-filters select:focus {
  outline: 2px solid var(--color-primary);
  outline-offset: 1px;
}

/* Insight cards */
.chd-insights {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(18rem, 1fr));
  gap: var(--space-4);
  margin: 0 0 var(--space-6);
}

.chd-insight-card h2 {
  font-size: var(--text-md);
  margin-bottom: var(--space-3);
}

.chd-birthdays,
.chd-flags {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.45rem;
  font-size: var(--text-sm);
}

.chd-birthdays li,
.chd-flags li {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-3);
  padding-bottom: 0.45rem;
  border-bottom: 1px dashed var(--color-border);
}

.chd-birthdays li:last-child,
.chd-flags li:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

.chd-birthdays .when,
.chd-flags .what {
  color: var(--color-text-muted);
  white-space: nowrap;
}

.chd-empty-note {
  color: var(--color-text-faint);
}

/* Table tweaks on top of .kpi-table */
.chd-table td {
  vertical-align: middle;
}

.chd-table .chd-name-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  border: 0;
  background: none;
  padding: 0;
  font: inherit;
  font-weight: 700;
  color: var(--color-text);
  cursor: pointer;
  text-align: left;
}

.chd-table .chd-name-btn .chd-caret {
  transition: transform 0.15s ease;
  color: var(--color-text-faint);
  flex: none;
}

.chd-table tr.is-open .chd-name-btn .chd-caret {
  transform: rotate(90deg);
}

.chd-table .chd-name-sub {
  display: block;
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--color-text-faint);
  margin-top: 0.1rem;
}

.chd-table input[type="text"],
.chd-table input[type="date"],
.chd-table select {
  width: 100%;
  min-width: 6.5rem;
  padding: 0.35rem 0.45rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: #fff8e1;
  color: var(--color-text);
  font: inherit;
  font-size: var(--text-sm);
}

.chd-table input:disabled,
.chd-table select:disabled {
  background: transparent;
  border-color: transparent;
  color: var(--color-text);
  opacity: 1;
  cursor: default;
  padding-left: 0;
}

.chd-table input[type="date"]:disabled {
  min-width: 5.5rem;
}

.chd-table .chd-name-cell {
  min-width: 13rem;
}

.chd-table .chd-name-inputs {
  display: grid;
  gap: 0.25rem;
}

/* Booked-day checkboxes */
.chd-days {
  display: inline-flex;
  gap: 0.25rem;
}

.chd-day {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.65rem;
  height: 1.65rem;
  border-radius: var(--radius-sm);
  font-family: var(--font-body);
  font-size: 0.68rem;
  font-weight: 700;
  line-height: 1;
  letter-spacing: 0.02em;
  border: 1px solid var(--color-border);
  color: var(--color-text);
  background: var(--color-surface-2);
  cursor: pointer;
  user-select: none;
}

.chd-day.is-on {
  background: #dfe8de;
  border-color: #2f6b4f;
  color: #1e4634;
}

.chd-day.is-locked {
  cursor: default;
}

.chd-day.is-locked:not(.is-on) {
  opacity: 1;
}

/* Alert badge */
.chd-alert {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.5rem;
  padding: 0.15rem 0.45rem;
  border-radius: var(--radius-pill);
  font-size: 0.7rem;
  font-weight: 700;
  background: #f6e3d7;
  color: #8d3f1d;
  white-space: nowrap;
}

.chd-alert-none {
  background: transparent;
  color: var(--color-text-faint);
  font-weight: 500;
}

/* Expanded detail row */
.chd-detail-row > td {
  background: var(--color-surface-2);
  padding: var(--space-4) var(--space-5);
  text-align: left;
}

.chd-detail {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(17rem, 1fr));
  gap: var(--space-5);
  max-width: 70rem;
}

.chd-detail h4 {
  margin: 0 0 var(--space-2);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--color-text-muted);
}

.chd-contact-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.5rem;
  font-size: var(--text-sm);
}

.chd-contact-list li {
  line-height: 1.45;
}

.chd-contact-list .tags {
  margin-left: 0.35rem;
}

.chd-contact-list .tag {
  display: inline-block;
  padding: 0.05rem 0.45rem;
  margin-right: 0.25rem;
  border-radius: var(--radius-pill);
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  background: #dfe8de;
  color: #1e4634;
}

.chd-contact-list .tag.emergency {
  background: #f6e9c8;
  color: #7a5a12;
}

.chd-contact-list a {
  color: var(--color-primary);
  text-decoration: none;
}

.chd-contact-list a:hover {
  text-decoration: underline;
}

.chd-detail textarea {
  width: 100%;
  min-height: 6.5rem;
  padding: 0.5rem 0.6rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: #fff8e1;
  color: var(--color-text);
  font: inherit;
  font-size: var(--text-sm);
  line-height: 1.5;
  resize: vertical;
}

.chd-detail textarea:disabled {
  background: transparent;
  border-color: var(--color-border);
  opacity: 1;
  cursor: default;
}

.chd-detail .hint {
  display: block;
  margin-top: 0.35rem;
  font-size: 0.72rem;
  color: var(--color-text-faint);
}

.chd-medical-text {
  white-space: pre-wrap;
  font-size: var(--text-sm);
  line-height: 1.5;
  margin: 0;
}

.chd-remove {
  margin-top: var(--space-3);
}

/* Upload feedback + row count */
.chd-upload-note {
  margin: 0 0 var(--space-4);
  padding: 0.6rem 0.9rem;
  border-radius: var(--radius-md);
  background: #dfe8de;
  color: #1e4634;
  font-size: var(--text-sm);
  font-weight: 600;
}

.chd-upload-note.is-error {
  background: #f6e3d7;
  color: #8d3f1d;
}

.chd-count {
  margin-left: auto;
  font-size: var(--text-sm);
  color: var(--color-text-faint);
}

/* Status editing (select + optional start date) */
.chd-status-edit {
  display: inline-flex;
  flex-direction: column;
  gap: 0.3rem;
  align-items: stretch;
}

/* "+ n more" toggle in Worth a look */
.chd-flags-more {
  background: none;
  border: 0;
  padding: 0;
  font: inherit;
  color: var(--color-accent, #2f6b4f);
  text-decoration: underline;
  cursor: pointer;
}

/* Add child form */
.chd-add-card {
  margin-top: var(--space-4);
}

.chd-add-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: var(--space-3) var(--space-4);
  margin-top: var(--space-3);
}

.chd-add-grid label {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--color-text-muted);
}

.chd-add-grid input,
.chd-add-grid select {
  width: 100%;
  max-width: 100%;
  padding: 0.45rem 0.55rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  color: var(--color-text);
  font: inherit;
  font-weight: 400;
}

.chd-add-grid .req {
  color: #a33b1c;
}

.chd-add-days {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.chd-add-days-label {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--color-text-muted);
}

.chd-add-error {
  margin-top: var(--space-3);
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius-sm);
  background: #f6e3d7;
  color: #8d3f1d;
  font-size: var(--text-sm);
}

.chd-add-actions {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  flex-wrap: wrap;
  margin-top: var(--space-4);
}

.chd-add-hint {
  font-size: var(--text-sm);
  color: var(--color-text-faint);
}

/* Structured contact editor */
.chd-ct-editor {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.chd-ct-row {
  position: relative;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.45rem 0.5rem;
  align-items: center;
  padding: 0.6rem;
  padding-right: 2.4rem; /* space for the remove button */
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface);
}

.chd-ct-row input[data-ct-field="name"] {
  grid-column: 1 / -1;
}

.chd-ct-row input[type="text"],
.chd-ct-row input[type="tel"] {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  text-align: left;
  padding: 0.35rem 0.5rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  color: var(--color-text);
  font: inherit;
  font-size: var(--text-sm);
}

.chd-ct-check {
  display: inline-flex;
  align-items: center;
  justify-self: start;
  gap: 0.35rem;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--color-text-muted);
  white-space: nowrap;
  cursor: pointer;
}

.chd-ct-check input {
  accent-color: #2f6b4f;
}

.chd-ct-remove {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  border: 1px solid var(--color-border);
  background: var(--color-surface-2);
  color: var(--color-text-muted);
  border-radius: var(--radius-sm);
  width: 1.5rem;
  height: 1.5rem;
  padding: 0;
  line-height: 1;
  font-size: 0.95rem;
  cursor: pointer;
}

.chd-ct-remove:hover {
  color: #a33b1c;
  border-color: #a33b1c;
}

.chd-ct-addbtn {
  align-self: flex-start;
}

@media (max-width: 700px) {
  .chd-count {
    margin-left: 0;
  }
}

/* Dark theme */
[data-theme='dark'] .chd-table input[type="text"],
[data-theme='dark'] .chd-table input[type="date"],
[data-theme='dark'] .chd-table select,
[data-theme='dark'] .chd-detail textarea {
  background: rgba(255, 241, 184, 0.08);
  border-color: rgba(247, 243, 236, 0.25);
  color: var(--color-text);
}

[data-theme='dark'] .chd-table input:disabled,
[data-theme='dark'] .chd-table select:disabled {
  background: transparent;
  border-color: transparent;
}

[data-theme='dark'] .chd-detail textarea:disabled {
  background: transparent;
  border-color: var(--color-border);
}

[data-theme='dark'] .chd-day.is-on {
  background: rgba(47, 107, 79, 0.45);
  border-color: #7fb99b;
  color: #d9ead9;
}

[data-theme='dark'] .chd-alert {
  background: rgba(180, 85, 46, 0.3);
  color: #f0b795;
}

[data-theme='dark'] .chd-upload-note {
  background: rgba(47, 107, 79, 0.35);
  color: #d9ead9;
}

[data-theme='dark'] .chd-upload-note.is-error {
  background: rgba(180, 85, 46, 0.3);
  color: #f0b795;
}

[data-theme='dark'] .chd-add-error {
  background: rgba(180, 85, 46, 0.3);
  color: #f0b795;
}

[data-theme='dark'] .chd-add-grid input,
[data-theme='dark'] .chd-add-grid select,
[data-theme='dark'] .chd-ct-row input[type="text"],
[data-theme='dark'] .chd-ct-row input[type="tel"] {
  background: var(--color-surface);
  color: var(--color-text);
  border-color: var(--color-border);
}

[data-theme='dark'] .chd-flags-more {
  color: #9fd3b4;
}

[data-theme='dark'] .chd-contact-list .tag {
  background: rgba(47, 107, 79, 0.45);
  color: #d9ead9;
}

[data-theme='dark'] .chd-contact-list .tag.emergency {
  background: rgba(196, 146, 42, 0.3);
  color: #ecd9a8;
}

/* Mobile */
@media (max-width: 640px) {
  .chd-filters {
    flex: 1 1 100%;
  }

  .chd-filters select {
    flex: 1 1 8rem;
  }

  .chd-detail {
    grid-template-columns: 1fr;
  }

  /* The register still relies on .kpi-table's horizontal-scroll layout here
     (kept intentionally — see report), but the padlock and name-toggle tap
     targets are enlarged so scrolling to reach a control isn't required just
     to press it accurately. */
  .chd-table .kpi-row-lock {
    width: 2.5rem;
    height: 2.5rem;
  }

  .chd-table .chd-name-btn {
    min-height: 2.5rem;
    padding-block: 0.25rem;
  }

  .chd-table th,
  .chd-table td {
    padding: 0.6rem 0.5rem;
  }
}

/* ---------- Mobile (stacked cards) ----------
   Below 860px the register becomes one card per child: the header row is hidden
   and each cell carries its own label, so there is no sideways scrolling. The
   padlock cell becomes the card header alongside the child's name. */
@media (max-width: 860px) {
  body[data-page="children"] .kpi-mobile-hint {
    display: none !important;
  }

  .chd-table {
    width: 100%;
    min-width: 0;
  }

  .chd-table thead {
    display: none;
  }

  .chd-table,
  .chd-table tbody,
  .chd-table td {
    display: block;
    width: 100%;
  }

  .chd-table tr {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: var(--space-3) var(--space-4);
    margin-bottom: var(--space-3);
  }

  .chd-table tr.is-open {
    border-color: var(--color-primary);
    margin-bottom: 0;
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
  }

  /* Padlock + name become the card header */
  .chd-table td.chd-lock-cell {
    order: 2;
    width: auto;
    flex: none;
    padding: 0 0 var(--space-2);
    margin-bottom: var(--space-2);
    border: 0;
    border-bottom: 1px solid var(--color-divider);
    align-self: stretch;
    display: flex;
    align-items: center;
  }

  .chd-table td.chd-name-cell {
    order: 1;
    flex: 1 1 60%;
    width: auto;
    border: 0;
    padding: 0 var(--space-2) var(--space-2) 0;
    margin-bottom: var(--space-2);
    border-bottom: 1px solid var(--color-divider);
    font-size: var(--text-base);
    display: block;
    text-align: left;
  }

  .chd-table td.chd-name-cell > * {
    max-width: 100%;
  }

  .chd-table td.chd-name-cell::before {
    display: none;
  }

  .chd-table td {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
    order: 3;
    flex: 1 1 100%;
    width: 100%;
    border: 0;
    border-top: 1px solid var(--color-divider);
    padding-block: var(--space-2);
    padding-inline: 0;
    text-align: right;
    white-space: normal;
    position: static;
  }

  .chd-table td[data-label='Status'] {
    border-top: 0;
  }

  /* Striping and hover tints read as noise once rows are cards */
  .chd-table tbody tr:nth-child(even) td,
  .chd-table tbody tr:hover td {
    background: transparent;
  }

  .chd-table td::before {
    content: attr(data-label);
    flex: 1 1 auto;
    text-align: left;
    font-size: var(--text-xs);
    font-weight: 600;
    color: var(--color-text-muted);
  }

  .chd-table td > * {
    flex: 0 1 auto;
    max-width: 62%;
    min-width: 0;
    overflow-wrap: anywhere;
  }

  .chd-table td input,
  .chd-table td select {
    width: auto;
    min-width: 7rem;
    min-height: 2.5rem;
    text-align: right;
  }

  .chd-table .chd-name-btn {
    max-width: 100%;
    text-align: left;
  }

  .chd-table .chd-days {
    justify-content: flex-end;
    flex-wrap: wrap;
  }

  /* The expanded contacts / notes panel sits under its card */
  .chd-table tr.chd-detail-row {
    border-top: 0;
    border-color: var(--color-primary);
    border-top-left-radius: 0;
    border-top-right-radius: 0;
    margin-bottom: var(--space-3);
    padding-top: 0;
  }

  .chd-table tr.chd-detail-row td {
    border: 0;
    padding: 0;
    text-align: left;
    display: block;
  }

  .chd-table tr.chd-detail-row td::before {
    display: none;
  }

  /* Keep the detail panel inside the card: textareas and contact inputs have
     wide intrinsic widths that would otherwise stretch the whole table. */
  .chd-table tr.chd-detail-row td,
  .chd-table .chd-detail,
  .chd-table .chd-detail > * {
    min-width: 0;
    max-width: 100%;
  }

  .chd-table .chd-detail {
    grid-template-columns: 1fr;
    gap: var(--space-4);
  }

  .chd-table .chd-detail textarea,
  .chd-table .chd-ct-row input {
    width: 100%;
    min-width: 0;
    max-width: 100%;
  }

  .chd-table .chd-ct-row {
    grid-template-columns: 1fr;
  }

  /* Name inputs in edit mode must not slide under the padlock */
  .chd-table .chd-name-cell {
    min-width: 0;
  }

  .chd-table .chd-name-inputs input {
    width: 100%;
    min-width: 0;
    max-width: 100%;
  }
}
