/*
  Tooth menu + chart attribute panels (chart.html, tooth_menu.html).
  Everything is scoped under the cf- prefix so it cannot leak into the rest of the app.
  Sizes are in px on purpose: the chart page body is font-size: 40px (fs-pix-40) and the rest of the app
  uses percentage font classes, so em/rem would inherit that.
  Set --accent on any element to colour its dot, focus ring and checked state (category colours match the chart).
*/

.cf-panel {
  --cf-border: #D9DDE3;
  --cf-border-strong: #B9C0CA;
  --cf-text: #1D1E1F;
  --cf-muted: #6B7280;
  --cf-surface: #FFFFFF;
  --cf-soft: #F5F7FA;
  --cf-primary: #2F81F8;
  background: var(--cf-surface);
  border-radius: 3px;
  box-shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 4px 16px rgba(16, 24, 40, 0.06);
  font-size: 14px;
  line-height: 1.4;
  text-align: left;
  color: var(--cf-text);
}
.cf-panel *,
.cf-panel *::before,
.cf-panel *::after {
  box-sizing: border-box;
  font-family: "Noto Sans", sans-serif;
}

/* ---------- header ---------- */
.cf-head {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--cf-border);
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--cf-surface);
  border-radius: 3px 3px 0 0;
}
.cf-badge {
  min-width: 56px;
  height: 56px;
  padding: 0 10px;
  border-radius: 3px;
  background: var(--cf-primary);
  color: #fff;
  font-size: 22px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  letter-spacing: 0.02em;
  word-break: break-all;
  text-align: center;
  line-height: 1.1;
}
.cf-badge.cf-badge-multi {
  font-size: 13px;
}
.cf-title {
  font-size: 18px;
  font-weight: 700;
  margin: 0;
}
.cf-sub {
  font-size: 12px;
  color: var(--cf-muted);
  margin: 2px 0 0 0;
}
.cf-kbd {
  display: inline-block;
  padding: 0 6px;
  border: 1px solid var(--cf-border-strong);
  border-bottom-width: 2px;
  border-radius: 3px;
  background: var(--cf-soft);
  font-size: 11px;
  font-weight: 600;
  color: var(--cf-text);
}
.cf-body {
  padding: 4px 20px 20px 20px;
}
.cf-panel-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 20px 4px 20px;
}
.cf-panel-head .cf-title {
  font-size: 16px;
}

/* ---------- sections ---------- */
.cf-section {
  margin-top: 18px;
}
.cf-section-title {
  margin: 0 0 8px 0;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--cf-muted);
}
.cf-card {
  border: 1px solid var(--cf-border);
  border-radius: 3px;
  background: var(--cf-surface);
  padding: 4px 14px;
}

/* ---------- rows ---------- */
.cf-field {
  display: grid;
  grid-template-columns: minmax(120px, 38%) 1fr;
  align-items: center;
  gap: 12px;
  padding: 9px 0;
  border-bottom: 1px solid var(--cf-border);
}
.cf-card > .cf-field:last-child,
.cf-card > .cf-block:last-child {
  border-bottom: none;
}
.cf-field.cf-stack {
  grid-template-columns: 1fr;
  gap: 6px;
}
.cf-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 600;
  margin: 0;
  color: var(--cf-text);
}
.cf-dot {
  flex: 0 0 auto;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent, var(--cf-primary));
}
.cf-dot.cf-dot-ring {
  background: transparent;
  border: 2px solid var(--accent, var(--cf-primary));
}
.cf-hint {
  font-weight: 400;
  color: var(--cf-muted);
}

/* ---------- inputs ---------- */
.cf-select,
.cf-input,
.cf-textarea {
  width: 100%;
  min-height: 36px;
  padding: 7px 10px;
  border: 1px solid var(--cf-border-strong);
  border-radius: 3px;
  background-color: var(--cf-surface);
  color: var(--cf-text);
  font-size: 14px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.cf-select {
  appearance: none;
  -webkit-appearance: none;
  padding-right: 32px;
  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='%236B7280' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 11px center;
}
.cf-textarea {
  min-height: 84px;
  resize: vertical;
}
.cf-select:hover,
.cf-input:hover,
.cf-textarea:hover {
  border-color: var(--accent, var(--cf-primary));
}
.cf-select:focus,
.cf-input:focus,
.cf-textarea:focus {
  outline: none;
  border-color: var(--accent, var(--cf-primary));
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent, #2F81F8) 28%, transparent);
}
.cf-input::placeholder {
  color: #A0A7B2;
}

/* periodontal probing sites */
.cf-probe {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}
.cf-probe label {
  display: block;
  margin: 0 0 3px 0;
  font-size: 11px;
  font-weight: 700;
  color: var(--cf-muted);
  text-align: center;
}
.cf-probe .cf-input {
  text-align: center;
  padding: 7px 4px;
}

/* ---------- chips (checkbox pills) ----------
   th:field on a checkbox emits a hidden "_field" input right after it, so the state selectors below use the
   general sibling combinator (~) rather than the adjacent one (+). */
.cf-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.cf-chip {
  position: relative;
  display: inline-flex;
  cursor: pointer;
  margin: 0;
}
.cf-chip input {
  position: absolute;
  opacity: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  cursor: pointer;
}
.cf-chip span {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 7px 12px;
  border: 1px solid var(--cf-border-strong);
  border-radius: 3px;
  background: var(--cf-surface);
  font-size: 13px;
  font-weight: 500;
  color: var(--cf-text);
  transition: background 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
  user-select: none;
}
.cf-chip span::before {
  content: "";
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 2px solid var(--accent, var(--cf-primary));
  background: transparent;
  transition: background 0.15s ease;
}
.cf-chip:hover span {
  border-color: var(--accent, var(--cf-primary));
}
.cf-chip input:checked ~ span {
  border-color: var(--accent, var(--cf-primary));
  background: color-mix(in srgb, var(--accent, #2F81F8) 16%, #fff);
  font-weight: 600;
}
.cf-chip input:checked ~ span::before {
  background: var(--accent, var(--cf-primary));
}
.cf-chip input:focus-visible ~ span {
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent, #2F81F8) 30%, transparent);
}

/* ---------- switch rows (master toggles that reveal chips) ---------- */
.cf-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--cf-border);
}
.cf-switch {
  position: relative;
  flex: 0 0 auto;
  width: 40px;
  height: 22px;
  margin: 0;
  cursor: pointer;
}
.cf-switch input {
  position: absolute;
  opacity: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  cursor: pointer;
}
.cf-switch .cf-slider {
  position: absolute;
  inset: 0;
  border-radius: 3px;
  background: #C9CFD8;
  transition: background 0.2s ease;
}
.cf-switch .cf-slider::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 16px;
  height: 16px;
  border-radius: 2px;
  background: #fff;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
  transition: transform 0.2s ease;
}
.cf-switch input:checked ~ .cf-slider {
  background: var(--accent, var(--cf-primary));
}
.cf-switch input:checked ~ .cf-slider::after {
  transform: translateX(18px);
}
.cf-switch input:focus-visible ~ .cf-slider {
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent, #2F81F8) 30%, transparent);
}
.cf-subchips {
  padding: 4px 0 12px 0;
  border-bottom: 1px solid var(--cf-border);
}
.cf-card > .cf-subchips:last-child {
  border-bottom: none;
}

/* ---------- segmented radio control (chart severity) ---------- */
.cf-seg {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 3px;
  background: var(--cf-soft);
  border: 1px solid var(--cf-border);
  border-radius: 3px;
}
.cf-seg label {
  position: relative;
  flex: 1 1 auto;
  margin: 0;
  cursor: pointer;
}
.cf-seg input {
  position: absolute;
  opacity: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  cursor: pointer;
}
.cf-seg span {
  display: block;
  padding: 6px 10px;
  border-radius: 3px;
  text-align: center;
  font-size: 13px;
  font-weight: 500;
  color: var(--cf-muted);
  transition: background 0.15s ease, color 0.15s ease;
  user-select: none;
  white-space: nowrap;
}
.cf-seg label:hover span {
  color: var(--cf-text);
}
.cf-seg input:checked ~ span {
  background: var(--cf-surface);
  color: var(--cf-text);
  font-weight: 700;
  box-shadow: 0 1px 3px rgba(16, 24, 40, 0.18);
}
.cf-seg input:focus-visible ~ span {
  box-shadow: 0 0 0 3px rgba(47, 129, 248, 0.35);
}

/* ---------- chart attributes grid ---------- */
.cf-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 14px;
  padding: 12px 20px 20px 20px;
}
.cf-tile {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 14px;
  border: 1px solid var(--cf-border);
  border-radius: 3px;
  background: var(--cf-surface);
}
.cf-tile .cf-textarea {
  flex: 1;
  min-height: 64px;
}
.cf-tile-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.cf-tile-wide {
  grid-column: span 2;
}
@media (max-width: 640px) {
  .cf-tile-wide {
    grid-column: span 1;
  }
}

/* save feedback line returned by htmx */
.cf-save {
  min-height: 0;
  padding: 0 20px;
}

/* ---------- chart Options dropdown (chart.html header) ---------- */
.cf-options {
  position: relative;
  display: inline-block;
}
.cf-options-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border: 1px solid #B9C0CA;
  border-radius: 3px;
  background: #FFFFFF;
  color: #1D1E1F;
  font-family: "Noto Sans", sans-serif;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.cf-options-btn::after {
  content: "";
  width: 7px;
  height: 7px;
  border-right: 2px solid #6B7280;
  border-bottom: 2px solid #6B7280;
  transform: translateY(-2px) rotate(45deg);
}
.cf-options-btn:hover,
.cf-options-btn[aria-expanded="true"] {
  border-color: #2F81F8;
}
.cf-options-btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px rgba(47, 129, 248, 0.3);
}
.cf-options-menu {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  z-index: 20;
  min-width: 170px;
  padding: 6px;
  border: 1px solid #D9DDE3;
  border-radius: 3px;
  background: #FFFFFF;
  box-shadow: 0 4px 16px rgba(16, 24, 40, 0.16);
}
.cf-options-menu[hidden] {
  display: none;
}
.cf-options-item {
  display: block;
  width: 100%;
  padding: 8px 10px;
  border: none;
  border-radius: 3px;
  background: transparent;
  font-family: "Noto Sans", sans-serif;
  font-size: 14px;
  text-align: left;
  cursor: pointer;
}
.cf-options-item:hover,
.cf-options-item:focus-visible {
  outline: none;
  background: #F5F7FA;
}
.cf-options-danger,
.cf-options-danger:hover {
  color: #EF5245;
}
.cf-options-danger:hover {
  background: #FDECEA;
}

/* ---------- chart page header (title left, Options right) ---------- */
.cf-pagehead {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin: 12px 0 16px 0;
  padding: 0 0 14px 0;
  border-bottom: 1px solid #C9CFD8;
  text-align: left;
}
.cf-pagetitle {
  margin: 0;
  font-family: "Noto Sans", sans-serif;
  font-size: 28px;
  font-weight: 700;
  line-height: 1.15;
  color: #1D1E1F;
}
.cf-pagesub {
  margin: 2px 0 0 0;
  font-family: "Noto Sans", sans-serif;
  font-size: 13px;
  color: #6B7280;
}
.cf-pagehead .cf-options-menu {
  left: auto;
  right: 0;
}

/* ---------- tooth menu: fixed height, attributes scroll inside the panel ---------- */
.cf-tooth {
  display: flex;
  flex-direction: column;
  max-height: 82.5vh;
  overflow: hidden;
}
.cf-tooth > form {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
}
.cf-tooth .cf-head {
  flex: 0 0 auto;
}
.cf-tooth .cf-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: #B9C0CA transparent;
}
.cf-tooth .cf-body::-webkit-scrollbar {
  width: 8px;
}
.cf-tooth .cf-body::-webkit-scrollbar-thumb {
  background: #B9C0CA;
  border-radius: 3px;
}

/* ---------- patient page (patient/patient.html) ---------- */
.cf-split {
  display: grid;
  grid-template-columns: minmax(300px, 2fr) minmax(300px, 3fr);
  gap: 16px;
  align-items: start;
}
@media (max-width: 900px) {
  .cf-split {
    grid-template-columns: 1fr;
  }
}
.cf-pair {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.cf-form-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  padding: 14px 0 4px 0;
}

/* buttons (same look as the Options button, with a filled primary variant) */
.cf-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 9px 16px;
  border: 1px solid #B9C0CA;
  border-radius: 3px;
  background: #FFFFFF;
  color: #1D1E1F;
  font-family: "Noto Sans", sans-serif;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease, box-shadow 0.15s ease;
}
.cf-btn:hover {
  border-color: #2F81F8;
}
.cf-btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px rgba(47, 129, 248, 0.3);
}
.cf-btn-primary {
  background: #2F81F8;
  border-color: #2F81F8;
  color: #FFFFFF;
}
.cf-btn-primary:hover {
  background: #1F6FE5;
  border-color: #1F6FE5;
}

/* chart list */
.cf-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 4px 20px 8px 20px;
}
.cf-list-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border: 1px solid #D9DDE3;
  border-radius: 3px;
  background: #FFFFFF;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.cf-list-row:hover {
  border-color: #2F81F8;
  background: #F5F7FA;
}
.cf-list-row::after {
  content: "";
  flex: 0 0 auto;
  width: 7px;
  height: 7px;
  border-right: 2px solid #6B7280;
  border-top: 2px solid #6B7280;
  transform: rotate(45deg);
}
.cf-list-title {
  margin: 0;
  font-family: "Noto Sans", sans-serif;
  font-size: 14px;
  font-weight: 600;
  color: #1D1E1F;
}
.cf-empty {
  margin: 0;
  padding: 18px 14px;
  border: 1px dashed #B9C0CA;
  border-radius: 3px;
  font-family: "Noto Sans", sans-serif;
  font-size: 13px;
  text-align: center;
  color: #6B7280;
}
.cf-panel-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 8px 20px 20px 20px;
}

/* ---------- public demo page (demo/demo_chart.html) ---------- */
.cf-demo-stack {
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.cf-demo-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
}
.cf-demo-actions form {
  margin: 0;
}

/* dog / cat switch: same look as the segmented control, but the options are links to separate pages */
.cf-seg-links a {
  display: block;
  min-width: 64px;
  padding: 6px 14px;
  border-radius: 3px;
  text-align: center;
  font-family: "Noto Sans", sans-serif;
  font-size: 13px;
  font-weight: 500;
  text-decoration: none;
  color: #6B7280;
  transition: background 0.15s ease, color 0.15s ease;
}
.cf-seg-links a:hover {
  color: #1D1E1F;
}
.cf-seg-links a.cf-active {
  background: #FFFFFF;
  color: #1D1E1F;
  font-weight: 700;
  box-shadow: 0 1px 3px rgba(16, 24, 40, 0.18);
}

/* locked sample values */
.cf-readonly {
  margin: 0;
  padding: 8px 10px;
  border: 1px solid #D9DDE3;
  border-radius: 3px;
  background: #F5F7FA;
  font-family: "Noto Sans", sans-serif;
  font-size: 14px;
  font-weight: 600;
  color: #1D1E1F;
}

/* sign-up note shown where the PDF download would be */
.cf-demo-cta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 16px;
  padding: 16px 20px;
  border: 1px solid #D9DDE3;
  border-radius: 3px;
  background: #FFFFFF;
}
.cf-demo-cta .cf-title,
.cf-demo-cta .cf-sub {
  margin: 0;
}
.cf-demo-cta .cf-sub {
  margin-top: 2px;
}

/* the global a:hover rule recolours links; keep .cf-btn text readable when it is an <a> */
a.cf-btn {
  text-decoration: none;
}
a.cf-btn:hover {
  color: #1D1E1F;
}
a.cf-btn-primary,
a.cf-btn-primary:hover {
  color: #FFFFFF;
}
