/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 40px; padding: 0 16px; border-radius: var(--r);
  font: 600 .92rem var(--font-body); white-space: nowrap;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  cursor: pointer; text-decoration: none; transition: background .12s, border-color .12s;
}
.btn:hover { text-decoration: none; background: var(--grey-tint); color: var(--ink); }
.btn-primary { background: var(--teal); border-color: var(--teal); color: #fff; }
.btn-primary:hover { background: var(--teal-deep); border-color: var(--teal-deep); color: #fff; }
.btn-dark { background: var(--night); border-color: var(--night); color: #fff; }
.btn-dark:hover { background: var(--night-2); color: #fff; }
.btn-danger { color: #a93a3a; border-color: #efc9c9; }
.btn-danger:hover { background: var(--rose-tint); color: #8e2c2c; }
.btn-ghost { border-color: transparent; background: transparent; color: var(--teal-deep); }
.btn-ghost:hover { background: var(--teal-tint); color: var(--teal-deep); }
.btn-sm { height: 32px; padding: 0 11px; font-size: .84rem; border-radius: var(--r-sm); }
.btn-lg { height: 48px; padding: 0 22px; font-size: 1rem; }
.btn-block { width: 100%; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }
/* Busy (submitting) state: spinner replaces the icon */
.btn.is-busy { opacity: .8; cursor: progress; }
.btn.is-busy svg.lucide { display: none; }
.btn.is-busy::before {
  content: ""; width: 15px; height: 15px; border-radius: 50%; flex-shrink: 0;
  border: 2px solid currentColor; border-right-color: transparent; animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Forms ---------- */
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px 18px; }
.form-grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.form-grid .full { grid-column: 1 / -1; }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > label, .label { font-size: .86rem; font-weight: 600; color: var(--ink-soft); }
.req::after { content: " *"; color: var(--rose); }
.input, select.input, textarea.input {
  width: 100%; height: 42px; padding: 0 12px;
  font: 400 .95rem var(--font-body); color: var(--ink);
  background: var(--surface); border: 1px solid #cfdcd9; border-radius: var(--r);
  transition: border-color .12s, box-shadow .12s;
}
textarea.input { height: auto; min-height: 84px; padding: 10px 12px; resize: vertical; line-height: 1.5; }
.input:focus { outline: none; border-color: var(--teal); box-shadow: 0 0 0 3px rgba(14, 124, 123, .14); }
.input::placeholder { color: #9bb0b3; }
.field.has-error .input { border-color: #d58b8b; background: #fffafa; }
.field-error { font-size: .8rem; color: #b13d3d; }
.field-hint { font-size: .8rem; color: var(--muted); }
.input-wrap { position: relative; }
.input-wrap .input { padding-right: 44px; }
.input-wrap .icon-btn { position: absolute; right: 3px; top: 3px; }
.check { display: flex; align-items: center; gap: 9px; font-size: .92rem; cursor: pointer; padding: 6px 0; }
.check input { width: 17px; height: 17px; accent-color: var(--teal); }
.check-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 2px 16px; }
.pill-check { display: inline-flex; }
.pill-check input { position: absolute; opacity: 0; }
.pill-check span {
  padding: 7px 13px; border: 1px solid var(--line); border-radius: 999px; font-size: .86rem; cursor: pointer; background: #fff;
}
.pill-check input:checked + span { background: var(--teal); border-color: var(--teal); color: #fff; }
.pill-check input:focus-visible + span { outline: 3px solid rgba(14, 124, 123, .35); }
.form-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 22px; flex-wrap: wrap; }
.section-title { display: flex; align-items: center; gap: 8px; margin: 26px 0 14px; padding-bottom: 8px; border-bottom: 1px solid var(--line-soft); }
.section-title:first-child { margin-top: 0; }
.strength { height: 4px; border-radius: 4px; background: var(--line-soft); overflow: hidden; }
.strength i { display: block; height: 100%; width: 0; background: var(--rose); transition: width .2s, background .2s; }

/* ---------- Cards ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); box-shadow: var(--shadow); }
.card-pad { padding: 22px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 22px; border-bottom: 1px solid var(--line-soft); }
.card-body { padding: 18px 22px; }
.card-foot { padding: 14px 22px; border-top: 1px solid var(--line-soft); background: #fbfdfc; border-radius: 0 0 var(--r-lg) var(--r-lg); }

/* ---------- Stat tiles ---------- */
.stat { padding: 18px 20px; display: flex; flex-direction: column; gap: 4px; }
.stat-label { font-size: .86rem; color: var(--muted); display: flex; align-items: center; gap: 7px; }
.stat-value { font-family: var(--font-display); font-size: 1.75rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.stat-note { font-size: .8rem; color: var(--muted); }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: .92rem; }
.table th {
  text-align: left; font-weight: 600; font-size: .8rem; color: var(--muted);
  padding: 11px 14px; border-bottom: 1px solid var(--line); background: #fafcfb; white-space: nowrap;
}
.table td { padding: 12px 14px; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: #f9fbfb; }
.table .actions { text-align: right; white-space: nowrap; }
.who { display: flex; align-items: center; gap: 11px; }
.who .avatar { background: var(--teal-tint); color: var(--teal-deep); }
.who b { font-weight: 600; display: block; line-height: 1.25; }
.who small { color: var(--muted); }

/* ---------- Badges ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px; padding: 3px 9px; border-radius: 999px;
  font-size: .76rem; font-weight: 600; white-space: nowrap; background: var(--grey-tint); color: var(--ink-soft);
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .8; }
.badge.plain::before { display: none; }
.b-scheduled, .b-proposed { background: var(--blue-tint); color: var(--blue); }
.b-confirmed, .b-accepted, .b-active { background: var(--teal-tint); color: var(--teal-deep); }
.b-checked-in, .b-partially-paid { background: var(--amber-tint); color: var(--amber); }
.b-in-progress { background: var(--violet-tint); color: var(--violet); }
.b-completed, .b-paid { background: var(--green-tint); color: var(--green); }
.b-cancelled { background: var(--grey-tint); color: #66757a; }
.b-no-show, .b-unpaid { background: var(--rose-tint); color: #b13d3d; }
/* Subscription status (super admin) */
.b-trial, .b-returning { background: var(--blue-tint); color: var(--blue); }
.b-new { background: var(--green-tint); color: var(--green); }
.b-expired { background: var(--amber-tint); color: #8a5a0b; }
.b-disabled { background: var(--rose-tint); color: #a93a3a; }

/* ---------- Flash / alerts ---------- */
.flash-stack { position: fixed; right: 20px; top: 84px; z-index: 80; display: flex; flex-direction: column; gap: 10px; max-width: 420px; }
.flash {
  display: flex; gap: 10px; align-items: flex-start; padding: 13px 14px; border-radius: var(--r);
  background: var(--night); color: #e8f4f2; box-shadow: var(--shadow-pop); font-size: .92rem;
  animation: flash-in .25s ease-out;
}
.flash.error { background: #6e2028; color: #fde8e9; }
.flash button { margin-left: auto; color: inherit; opacity: .7; background: none; border: 0; cursor: pointer; }
@keyframes flash-in { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }
.alert { display: flex; gap: 10px; padding: 12px 14px; border-radius: var(--r); font-size: .92rem; margin-bottom: 16px; }
.alert-error { background: var(--rose-tint); color: #8e2c2c; border: 1px solid #f2cfd1; }
.alert-warn { background: var(--amber-tint); color: #7b5208; border: 1px solid #f1dcb0; }
.alert-info { background: var(--teal-tint); color: var(--teal-deep); border: 1px solid #c4e3dd; }
.medical-alert {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 11px 16px; border-radius: var(--r);
  background: #fff1f1; border: 1px solid #f0c4c6; color: #9c2f36; font-size: .9rem; margin-bottom: 18px;
}
.medical-alert b { margin-right: 4px; }
.medical-alert .tag { background: #fff; border: 1px solid #f0c4c6; padding: 2px 9px; border-radius: 999px; font-weight: 600; }

/* ---------- Tabs ---------- */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 20px; overflow-x: auto; scrollbar-width: none; }
.tabs a {
  padding: 11px 15px; color: var(--muted); font-weight: 600; font-size: .92rem; white-space: nowrap;
  border-bottom: 2px solid transparent; margin-bottom: -1px; text-decoration: none;
}
.tabs a:hover { color: var(--ink); text-decoration: none; }
.tabs a.active { color: var(--teal-deep); border-bottom-color: var(--teal); }
.tabs .count { margin-left: 6px; font-size: .74rem; background: var(--grey-tint); padding: 1px 7px; border-radius: 999px; color: var(--muted); }

/* ---------- Empty states ---------- */
.empty { text-align: center; padding: 40px 20px; color: var(--muted); }
.empty svg.lucide { width: 34px; height: 34px; color: #a9bfbd; margin-bottom: 10px; }
.empty h3 { color: var(--ink); margin-bottom: 6px; }
.empty .btn { margin-top: 12px; }

/* ---------- Timeline (visit history) ---------- */
.timeline { position: relative; padding-left: 28px; }
.timeline::before { content: ""; position: absolute; left: 8px; top: 6px; bottom: 6px; width: 2px; background: var(--line); }
.tl-item { position: relative; margin-bottom: 18px; }
.tl-item::before {
  content: ""; position: absolute; left: -26px; top: 18px; width: 14px; height: 14px; border-radius: 50%;
  background: var(--surface); border: 3px solid var(--teal);
}
.tl-date { font-family: var(--font-display); font-weight: 600; font-size: .95rem; }
.kv { display: grid; grid-template-columns: 150px 1fr; gap: 6px 16px; font-size: .92rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; white-space: pre-line; }
.proc-list { list-style: none; padding: 0; margin: 6px 0 0; display: flex; flex-direction: column; gap: 6px; }
.proc-list li { display: flex; gap: 10px; align-items: center; padding: 8px 12px; background: var(--enamel); border-radius: var(--r-sm); font-size: .9rem; }
.tooth-tag {
  display: inline-grid; place-items: center; min-width: 30px; height: 24px; padding: 0 6px; border-radius: 6px;
  background: #fff; border: 1px solid var(--line); font-weight: 700; font-size: .8rem; color: var(--teal-deep);
  font-variant-numeric: tabular-nums;
}

/* ---------- Modal ---------- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(13, 43, 48, .45); z-index: 90; display: grid; place-items: center; padding: 18px; }
.modal { background: var(--surface); border-radius: var(--r-lg); width: min(520px, 100%); max-height: 90vh; overflow: auto; box-shadow: var(--shadow-pop); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--line-soft); }
.modal-body { padding: 18px 20px; }
.modal-foot { padding: 14px 20px; display: flex; justify-content: flex-end; gap: 10px; border-top: 1px solid var(--line-soft); }

/* ---------- Repeating row editors (procedures, items, medicines) ---------- */
.rows-table td { padding: 8px 6px; border-bottom: 1px solid var(--line-soft); vertical-align: top; }
.rows-table th { padding: 8px 6px; }
.rows-table .input { height: 38px; font-size: .9rem; }
.rows-table .w-tooth { width: 84px; }
.rows-table .w-num { width: 110px; }
.rows-table .w-qty { width: 76px; }
.add-row { margin-top: 10px; }

/* ---------- Pagination ---------- */
.pager { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; font-size: .88rem; color: var(--muted); }
.pager .row { gap: 6px; }

/* ---------- Patient picker ---------- */
.picker { position: relative; }
.picker-results {
  position: absolute; z-index: 30; left: 0; right: 0; top: calc(100% + 4px);
  background: #fff; border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--shadow-pop); overflow: hidden;
}
.picker-results button {
  display: flex; width: 100%; gap: 10px; align-items: center; padding: 10px 12px; text-align: left;
  border: 0; background: none; cursor: pointer; font: inherit; color: inherit;
}
.picker-results button:hover, .picker-results button.active { background: var(--teal-tint); }
.picked { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border: 1px solid #bfe0da; background: var(--teal-tint); border-radius: var(--r); }

/* ---------- Slot picker ---------- */
.slots { display: grid; grid-template-columns: repeat(auto-fill, minmax(86px, 1fr)); gap: 6px; }
.slot { height: 34px; border: 1px solid var(--line); border-radius: var(--r-sm); background: #fff; font: 600 .82rem var(--font-body); cursor: pointer; color: var(--ink); }
.slot:hover { border-color: var(--teal); }
.slot.on { background: var(--teal); color: #fff; border-color: var(--teal); }
.slot:disabled { background: var(--grey-tint); color: #a6b2b5; cursor: not-allowed; text-decoration: line-through; border-color: transparent; }

/* ---------- Totals ---------- */
.totals { margin-left: auto; width: min(360px, 100%); font-size: .95rem; }
.totals div { display: flex; justify-content: space-between; padding: 6px 0; }
.totals .grand { border-top: 2px solid var(--ink); margin-top: 6px; padding-top: 10px; font-family: var(--font-display); font-weight: 600; font-size: 1.15rem; }

/* ---------- Patient header ---------- */
.patient-hero { display: flex; gap: 18px; align-items: center; padding: 20px 22px; flex-wrap: wrap; }
.patient-hero .avatar { width: 58px; height: 58px; font-size: 1.15rem; background: var(--teal); }
.patient-hero h1 { font-size: 1.45rem; }
.facts { display: flex; flex-wrap: wrap; gap: 6px 18px; font-size: .9rem; color: var(--ink-soft); margin-top: 4px; }
.facts span { display: inline-flex; align-items: center; gap: 6px; }
.facts svg.lucide { width: 15px; height: 15px; color: var(--muted); }

/* ---------- "Select or type" combobox (DF.combo) ---------- */
.combo { position: relative; }
.combo .input {
  padding-right: 34px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%235b7279' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 11px center;
}
.rows-table .combo .input { padding-right: 28px; background-position: right 8px center; }
.combo-list {
  position: fixed; z-index: 120; margin: 0; padding: 4px; list-style: none; max-height: 260px; overflow-y: auto;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--shadow-pop);
}
.combo-list li {
  display: flex; align-items: baseline; justify-content: space-between; gap: 12px;
  padding: 8px 10px; border-radius: var(--r-sm); cursor: pointer; font-size: .92rem;
}
.combo-list li small { color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.combo-list li:hover, .combo-list li.active { background: var(--teal-tint); }
.combo-list mark { background: none; color: var(--teal-deep); font-weight: 700; }

/* ---------- Quick-pick chips ---------- */
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.chip {
  display: inline-flex; align-items: center; gap: 5px; height: 30px; padding: 0 11px;
  border: 1px solid var(--line); border-radius: 999px; background: var(--surface); color: var(--ink-soft);
  font: 500 .82rem var(--font-body); cursor: pointer; transition: background .12s, border-color .12s, color .12s;
}
.chip:hover { border-color: var(--teal); color: var(--teal-deep); }
.chip.on { background: var(--teal-tint); border-color: var(--teal); color: var(--teal-deep); font-weight: 600; }
.chip.on::before { content: "✓"; font-size: .78rem; }
.chip svg.lucide { width: 14px; height: 14px; }
.chips-label { font-size: .78rem; color: var(--muted); margin-right: 2px; align-self: center; }

/* ---------- Optional / tucked-away sections ---------- */
details.more { margin-top: 22px; border: 1px dashed var(--line); border-radius: var(--r); padding: 0 16px; }
details.more > summary {
  display: flex; align-items: center; gap: 8px; padding: 13px 0; cursor: pointer; list-style: none;
  font-weight: 600; color: var(--ink-soft);
}
details.more > summary::-webkit-details-marker { display: none; }
details.more > summary::after { content: "+"; margin-left: auto; font-size: 1.2rem; color: var(--muted); }
details.more[open] > summary::after { content: "−"; }
details.more[open] { padding-bottom: 16px; border-style: solid; }
.optional { font-weight: 400; color: var(--muted); font-size: .8rem; }

/* ---------- Age + date-of-birth tile picker (patient form) ---------- */
.dob-field { position: relative; }
.dob-field .input[readonly] { cursor: pointer; background: var(--surface); }
.dob-field .input-wrap svg.lucide { position: absolute; right: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.dob-pop {
  position: absolute; z-index: 60; top: calc(100% + 6px); left: 0; width: 300px; max-width: calc(100vw - 32px);
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); box-shadow: var(--shadow-pop); padding: 12px;
}
.dob-head { display: flex; align-items: center; gap: 6px; margin-bottom: 10px; }
.dob-title {
  flex: 1; height: 34px; border: 0; border-radius: var(--r-sm); background: none; cursor: pointer;
  font: 600 .95rem var(--font-display); color: var(--ink);
}
.dob-title:hover:not(:disabled) { background: var(--teal-tint); color: var(--teal-deep); }
.dob-title:disabled { cursor: default; }
.dob-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.dob-grid.days { grid-template-columns: repeat(7, 1fr); gap: 3px; }
.dob-grid .dow { font-size: .7rem; font-weight: 600; color: var(--muted); text-align: center; padding: 2px 0; }
.dob-tile {
  height: 40px; border: 1px solid transparent; border-radius: var(--r-sm); background: var(--enamel);
  font: 500 .88rem var(--font-body); color: var(--ink); cursor: pointer; font-variant-numeric: tabular-nums;
}
.dob-grid.days .dob-tile { height: 34px; background: none; }
.dob-tile:hover:not(:disabled) { border-color: var(--teal); background: var(--teal-tint); }
.dob-tile.on { background: var(--teal); color: #fff; border-color: var(--teal); }
.dob-tile.today { border-color: var(--teal); }
.dob-tile:disabled { color: #b4c2c4; cursor: not-allowed; background: none; }
.dob-foot { display: flex; justify-content: space-between; margin-top: 10px; padding-top: 8px; border-top: 1px solid var(--line-soft); }

/* ---------- Trial / subscription banner ---------- */
.plan-banner {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 18px; padding: 10px 16px;
  border-radius: var(--r); background: var(--blue-tint); border: 1px solid #c9dcf0; color: #24507a; font-size: .9rem;
}
.plan-banner.urgent { background: var(--amber-tint); border-color: #f1dcb0; color: #7b5208; }
.plan-banner .btn { margin-left: auto; }

@media (max-width: 1100px) and (min-width: 861px) {
  .form-grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 860px) {
  .form-grid, .form-grid-3, .check-grid { grid-template-columns: 1fr; }
  .kv { grid-template-columns: 1fr; }
  .flash-stack { left: 14px; right: 14px; }
}
