/* Baby cost calculator — modern UI on top of shared/style.css.
 *
 * Design tokens + patterns follow docs/baby/SCOPE.md and the UX research in
 * the redesign: ghost inputs (borderless until focus), sticky header, hover
 * rows, pill toggles (role=switch), Okabe-Ito chart palette, progressive
 * chart entrance, animated row add/remove, responsive table→card, and a
 * global prefers-reduced-motion override.
 */

:root {
  --fn-ease: cubic-bezier(0.16, 1, 0.3, 1); /* Linear/Vercel feel */
  --fn-dur: 0.2s;
}

.fn-window-hint {
  font-size: 12px;
  color: var(--fn-light);
  margin: -12px 0 16px;
}

.fn-section {
  margin-top: 24px;
}
.fn-section h3 {
  margin: 0 0 12px;
  font-size: 16px;
}

/* ---------------- items table ---------------- */
.fn-items-table {
  border-collapse: collapse;
  width: 100%;
}
.fn-items-table thead th {
  position: sticky;
  top: 0;
  background: var(--fn-white);
  z-index: 1;
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--fn-muted);
  text-align: left;
  border-bottom: 1px solid var(--fn-border);
  padding: 8px;
  white-space: nowrap;
}
.fn-items-table th,
.fn-items-table td {
  font-size: 13px;
  padding: 4px 6px;
  vertical-align: middle;
  border-bottom: 1px solid var(--fn-border);
}
.fn-items-table tbody tr {
  transition: background var(--fn-dur) var(--fn-ease),
    opacity var(--fn-dur) var(--fn-ease),
    transform var(--fn-dur) var(--fn-ease);
}
.fn-items-table tbody tr:hover {
  background: var(--fn-teal-soft);
}
.fn-disabled-row {
  opacity: 0.45;
}
.fn-disabled-row input,
.fn-disabled-row select {
  cursor: not-allowed;
}

/* ghost inputs: borderless until focus, underline reveals via :focus-within */
.fn-items-table input[type="number"],
.fn-items-table input[type="text"],
.fn-items-table select {
  width: 72px;
  padding: 6px 8px;
  border: 1px solid transparent;
  background: transparent;
  border-radius: 6px;
  font-size: 13px;
  font-family: inherit;
  outline: none;
  transition: border-color var(--fn-dur) var(--fn-ease),
    background var(--fn-dur) var(--fn-ease);
}
.fn-items-table input[type="text"].fn-item-label {
  width: 150px;
}
.fn-items-table select {
  width: auto;
  padding: 6px 4px;
  margin-left: 2px;
}
.fn-items-table .fn-rate input {
  width: 52px;
}
.fn-items-table input[type="number"]:hover,
.fn-items-table input[type="text"]:hover,
.fn-items-table select:hover {
  background: rgba(0, 0, 0, 0.03);
}
.fn-items-table input[type="number"]:focus,
.fn-items-table input[type="text"]:focus,
.fn-items-table select:focus {
  border-color: var(--fn-teal);
  background: #fff;
  box-shadow: 0 0 0 3px rgba(42, 157, 143, 0.12);
}
.fn-items-table td:focus-within {
  background: rgba(42, 157, 143, 0.04);
}

/* hide number spinners (cross-browser) — they read as dated */
.fn-items-table input[type="number"]::-webkit-outer-spin-button,
.fn-items-table input[type="number"]::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
.fn-items-table input[type="number"] {
  -moz-appearance: textfield;
}

/* ---------------- pill toggle (role=switch) ---------------- */
.fn-toggle-cell {
  text-align: center;
  width: 44px;
}
.fn-switch {
  position: relative;
  display: inline-block;
  width: 34px;
  height: 20px;
  cursor: pointer;
}
.fn-switch input {
  position: absolute;
  opacity: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  cursor: pointer;
}
.fn-switch .fn-track {
  position: absolute;
  inset: 0;
  border-radius: 9999px;
  background: var(--fn-border);
  transition: background var(--fn-dur) var(--fn-ease);
}
.fn-switch .fn-knob {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
  transition: transform var(--fn-dur) var(--fn-ease);
}
.fn-switch input:checked ~ .fn-track {
  background: var(--fn-teal);
}
.fn-switch input:checked ~ .fn-knob {
  transform: translateX(14px);
}
.fn-switch input:focus-visible ~ .fn-track {
  outline: 2px solid var(--fn-teal);
  outline-offset: 2px;
}

/* ---------------- color dot + misc cells ---------------- */
.fn-dot-cell {
  width: 20px;
  padding-right: 0 !important;
}
.fn-color-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  vertical-align: middle;
}
.fn-muted {
  color: var(--fn-light);
  text-align: center;
}
/* ---------------- item label + help tooltip ---------------- */
.fn-item-name {
  vertical-align: middle;
}
.fn-help {
  position: relative;
  display: inline-flex;
  align-items: center;
  margin-left: 5px;
  vertical-align: middle;
  cursor: help;
}
.fn-help-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 15px;
  height: 15px;
  font-size: 11px;
  color: var(--fn-light);
  background: var(--fn-bg);
  border: 1px solid var(--fn-border);
  border-radius: 50%;
  transition: color var(--fn-dur) var(--fn-ease), background var(--fn-dur) var(--fn-ease),
    border-color var(--fn-dur) var(--fn-ease);
  user-select: none;
}
.fn-help:hover .fn-help-icon,
.fn-help:focus-visible .fn-help-icon {
  color: var(--fn-teal);
  background: var(--fn-teal-soft);
  border-color: var(--fn-teal);
}
.fn-help:focus-visible {
  outline: 2px solid var(--fn-teal);
  outline-offset: 2px;
  border-radius: 50%;
}
.fn-help-tip {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%) translateY(4px);
  width: 260px;
  max-width: 80vw;
  padding: 10px 12px;
  background: #1a1a1a;
  color: #fff;
  font-size: 12px;
  line-height: 1.45;
  font-weight: 400;
  text-align: left;
  border-radius: 8px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity var(--fn-dur) var(--fn-ease), transform var(--fn-dur) var(--fn-ease),
    visibility 0s linear var(--fn-dur);
  z-index: 30;
}
.fn-help-tip::after {
  content: '';
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 6px solid transparent;
  border-top-color: #1a1a1a;
}
.fn-help:hover .fn-help-tip,
.fn-help:focus-visible .fn-help-tip {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: translateX(-50%) translateY(0);
  transition: opacity var(--fn-dur) var(--fn-ease), transform var(--fn-dur) var(--fn-ease),
    visibility 0s;
}

.fn-remove-btn {
  background: none;
  border: none;
  color: var(--fn-light);
  cursor: pointer;
  font-size: 15px;
  padding: 2px 6px;
  border-radius: 4px;
  transition: color var(--fn-dur) var(--fn-ease), background var(--fn-dur) var(--fn-ease);
}
.fn-remove-btn:hover {
  color: #b91c1c;
  background: #fef2f2;
}

/* ---------------- row animations ---------------- */
@keyframes fn-row-in {
  from {
    opacity: 0;
    transform: translateY(-4px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}
.fn-items-table tbody tr.is-new {
  animation: fn-row-in var(--fn-dur) var(--fn-ease);
}
.fn-items-table tbody tr.is-leaving {
  opacity: 0;
  transform: translateX(8px);
}

/* ---------------- add-row buttons ---------------- */
.fn-add-row {
  display: flex;
  gap: 10px;
  margin-top: 12px;
}
.fn-btn-secondary {
  background: var(--fn-white);
  color: var(--fn-teal-dark);
  border: 1px solid var(--fn-teal);
  font-weight: 500;
  transition: background var(--fn-dur) var(--fn-ease), transform var(--fn-dur) var(--fn-ease);
}
.fn-btn-secondary:hover {
  background: var(--fn-teal-soft);
}
.fn-btn-secondary:active {
  transform: scale(0.97);
}

/* ---------------- grand total + chart ---------------- */
.fn-baby-total {
  margin-top: 24px;
  text-align: center;
  transition: background var(--fn-dur) var(--fn-ease);
}
.fn-baby-total .fn-stat-value {
  font-size: 36px;
}
.fn-baby-chart-wrap {
  height: 380px;
  margin-top: 20px;
}

/* ---------------- responsive: table → card at 700px ---------------- */
@media (max-width: 700px) {
  .fn-items-table thead {
    display: none;
  }
  .fn-items-table,
  .fn-items-table tbody,
  .fn-items-table tr,
  .fn-items-table td {
    display: block;
    width: 100%;
  }
  .fn-items-table tr {
    margin-bottom: 12px;
    border: 1px solid var(--fn-border);
    border-radius: 10px;
    padding: 8px 12px;
    background: var(--fn-white);
  }
  .fn-items-table td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 0;
    border-bottom: none;
  }
  .fn-items-table td::before {
    content: attr(data-label);
    color: var(--fn-light);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.03em;
  }
  /* hide cells with empty data-label (toggle, dot, remove) */
  .fn-items-table td[data-label=""] {
    padding: 0;
  }
  .fn-items-table td[data-label=""]::before {
    content: none;
  }
  .fn-toggle-cell {
    width: auto;
  }
  .fn-dot-cell {
    display: none !important;
  }
  .fn-items-table input[type="number"],
  .fn-items-table input[type="text"],
  .fn-items-table input[type="text"].fn-item-label,
  .fn-items-table .fn-rate input {
    width: 90px;
  }
  .fn-baby-chart-wrap {
    height: 300px;
  }
}

/* ---------------- reduced motion: WCAG 2.2 C39 ---------------- */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
