/*
 * Parent portal: Buddy's layer on top of crm5's geex files (vendor/geex/css: crm-ui, crm-filter-bar,
 * crm-mobile, crm-dark, crm-layout, crm-guest). The shell and the x-pt components use crm5's own class
 * names (.sidebar, .s-nav-item, .topbar, .page-content, .card, .crm-badge, .crm-empty, .modal-content,
 * .crm-bottom-nav, .login-*), so their look is crm5's. This file only adds what Buddy needs on top:
 *   - every control at least 44 px (crm5's 32-36 px buttons, bells and icon buttons are raised);
 *   - <details> dropdowns and <dialog> modals (Buddy has no Bootstrap JS);
 *   - the viewing-as banner, the page actions row, the family badge;
 *   - placeholders back on (crm-ui.css hides every placeholder; Buddy's forms use them as hints);
 *   - the dark-mode surfaces crm-dark.css doesn't reach, and the sign-in panel's heading colour;
 *   - the older .pt- classes that page views still use, in the geex look.
 * Colours, radius, shadow and font come only from the tokens in /css/app.css. Class prefix: .pt-
 */

/* ── Base ───────────────────────────────────────────────────────────────── */
/* crm5 keeps Bootstrap's own white for fields, menus and modals; the page grey is only the body's */
.pt-body, .pt-guest { --bs-body-bg: var(--crm-surface); }
.pt-body { min-height: 100vh; margin: 0; }
.pt-skip {
  position: absolute; left: 16px; top: -80px; z-index: 2000;
  display: inline-flex; align-items: center; min-height: 44px; padding: 10px 16px; border-radius: 12px;
  background: var(--crm-primary); color: var(--crm-on-primary); font-weight: 600; text-decoration: none;
}
.pt-skip:focus { top: 16px; color: var(--crm-on-primary); }
.page-content:focus { outline: none; }
.pt-body :focus-visible { outline: 3px solid rgba(var(--crm-primary-rgb), .45); outline-offset: 2px; }

/* crm-ui.css hides every placeholder (a crm5 rule); Buddy's placeholders are hints (code formats, examples). */
.pt-body input::placeholder,
.pt-body textarea::placeholder { opacity: 1 !important; color: var(--crm-muted) !important; }

/* ── Sidebar ────────────────────────────────────────────────────────────── */
.sidebar-brand-full {
  display: flex; flex: 1 1 auto; align-items: center; gap: 10px; min-width: 0; min-height: 44px;
  color: inherit; text-decoration: none;
}
.pt-brand-text { display: flex; flex-direction: column; min-width: 0; }
.sidebar-brand-name, .sidebar-brand-sub { display: block; }
.sidebar .s-nav-item { min-height: 44px; }
.sidebar .s-nav-item:focus-visible { outline-color: var(--crm-sidebar-text); }
.pt-sidebar-close { display: none !important; }

/* ── Top bar ────────────────────────────────────────────────────────────── */
.topbar .page-title { line-height: 1.3; }
.topbar .crm-mobile-toggle,
.topbar-bell {
  width: 44px; height: 44px; flex: none; border-radius: 12px;
  border: 1px solid var(--crm-border); background: transparent; color: var(--crm-body-text);
  font-size: 1.2rem; text-decoration: none;
}
.topbar .crm-mobile-toggle { align-items: center; justify-content: center; }
.topbar .crm-mobile-toggle:hover { border-color: var(--crm-primary); background: var(--crm-primary-soft); color: var(--crm-primary-ink); }
.topbar-bell .notif-count { width: auto; min-width: 18px; height: 18px; padding: 0 4px; border-radius: 9px; border-color: var(--crm-surface); font-size: .62rem; }
.topbar-user { min-height: 44px; list-style: none; background: var(--crm-surface); }
.topbar-user .user-avatar { font-size: .85rem; }
.topbar-user .user-avatar i { font-size: 1rem; }
.topbar-user .user-name { color: var(--crm-heading); }
.topbar-user .pt-caret { font-size: .7rem; color: var(--crm-muted); }
.pt-family-badge {
  display: inline-flex; align-items: center; gap: 4px; min-width: 0; max-width: 150px; padding: 4px 8px;
  border-radius: 8px; background: var(--crm-primary-soft); color: var(--crm-primary-ink);
  font-size: .75rem; font-weight: 600; white-space: nowrap;
}
.pt-family-badge span { overflow: hidden; text-overflow: ellipsis; }

/* <details> dropdowns in crm5's .user-dropdown-menu look */
details.pt-dd { position: relative; }
details.pt-dd > summary { list-style: none; cursor: pointer; }
details.pt-dd > summary::-webkit-details-marker { display: none; }
details.pt-dd > summary:focus-visible { outline: 3px solid rgba(var(--crm-primary-rgb), .45); outline-offset: 2px; }
details.pt-dd > .dropdown-menu {
  position: absolute; top: calc(100% + 6px); right: 0; left: auto; z-index: 1060;
  display: block; max-width: calc(100vw - 24px); margin: 0;
}
details.pt-dd:not([open]) > .dropdown-menu { display: none; }
.user-dropdown-menu .dropdown-item { min-height: 44px; width: 100%; border: 0; background: transparent; text-align: start; }
.user-dropdown-menu .dropdown-item i { font-size: 1.05rem; }
.user-dropdown-menu .dropdown-header { padding: 8px 12px 4px; font-size: .72rem; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; }
.user-dropdown-menu form { margin: 0; }
.user-dropdown-menu .pt-user-email { font-size: .75rem; overflow-wrap: anywhere; }
.pt-theme-row { cursor: pointer; }
.pt-theme-row > span:first-child { display: inline-flex; align-items: center; gap: 9px; }
.pt-theme-row .form-check-input { width: 2.4em; height: 1.3em; margin: 0; cursor: pointer; }
.pt-kids .avatar-circle-sm { flex: none; }

/* The kid you're viewing (crm5's impersonation bar) */
.pt-viewing {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; margin: 0 0 6px; padding: 8px 20px;
  border-radius: 16px; background: var(--crm-primary); color: var(--crm-on-primary); font-size: .9rem;
}
.pt-viewing > span { flex: 1 1 220px; min-width: 0; }
.pt-viewing form { margin: 0; }
.btn.pt-viewing-btn {
  min-height: 44px; padding: 6px 14px; border: 1px solid rgba(var(--crm-sidebar-text-rgb), .35);
  background: rgba(var(--crm-sidebar-text-rgb), .2); color: var(--crm-on-primary); font-size: .82rem;
}
.btn.pt-viewing-btn:hover { background: rgba(var(--crm-sidebar-text-rgb), .3); color: var(--crm-on-primary); }

/* ── Page content ───────────────────────────────────────────────────────── */
.page-content { min-width: 0; }
/* The page heading with its actions, as on crm5's list pages ("Assignments" and its + button) */
.pt-page-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px 16px; margin: 2px 0 18px; }
.pt-page-title { flex: 1 1 260px; min-width: 0; margin: 0; color: var(--crm-heading); font-size: 1.55rem; font-weight: 600; line-height: 1.25; overflow-wrap: anywhere; }
.pt-page-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; align-items: center; gap: 8px; margin-left: auto; }
.pt-flash { display: flex; align-items: center; gap: 8px; border-radius: 12px; font-weight: 600; text-align: start; }
.pt-flash i { flex: none; font-size: 1.2rem; }
.page-content > .pt-flash { margin-bottom: 16px; font-size: .9rem; }

/* Cards: crm5's section card. Buddy's cards hold menus and pop-ups, so nothing is clipped. */
.pt-card { min-width: 0; margin-bottom: 16px; overflow: visible; }
.pt-card > .card-header { border-radius: var(--crm-card-radius) var(--crm-card-radius) 0 0; }
.pt-card > .card-header:last-child { border-bottom: 0; border-radius: var(--crm-card-radius); }
.pt-card .crm-card-title { font-size: 1rem; }
.pt-card-body { min-width: 0; }
.pt-card-foot { padding: 10px 20px 12px; border-top: 1px solid var(--crm-border); background: transparent; border-radius: 0 0 var(--crm-card-radius) var(--crm-card-radius); }
.pt-card-foot a:not(.btn), .crm-card-header a:not(.btn), .pt-card-actions a:not(.btn) {
  display: inline-flex; align-items: center; min-height: 44px; font-weight: 600; text-decoration: none;
}
.pt-card-foot a:not(.btn):hover, .crm-card-header a:not(.btn):hover, .pt-card-actions a:not(.btn):hover { text-decoration: underline; }
/* crm-layout.css paints every link in .page-content with --crm-link through a very specific selector
   (a:not(.btn):not(.nav-link)…). Buddy's link-shaped components keep their own text colour. */
.page-content a.pt-rw-tab.is-active,
.page-content a.pt-sd-chip.is-active,
.page-content a.pt-chip.is-active { color: var(--crm-on-primary) !important; }
.page-content a.pt-rw-alert:not(:hover) { color: var(--rb-almost) !important; }
.page-content a.pt-badge.pt-badge-almost { color: var(--s-warning) !important; text-decoration: none; }
.page-content a.pt-nt-item-title,
.page-content a.pt-rv-q-title:not(:hover) { color: var(--crm-heading) !important; }
.page-content a.pt-hw-row { color: var(--crm-body-text) !important; }
/* Plain links inside a sentence: a 44 px tap area without moving the text (an inline box's
   vertical padding doesn't change the line height; the side padding is given back by the margin). */
.page-content :is(p, span, small, dd, td, .form-text) > a:not([class]),
.login-form-inner :is(p, span, small) > a:not([class]) {
  padding: 12px 8px; margin: 0 -8px;
  -webkit-box-decoration-break: clone; box-decoration-break: clone;
}

/* ── Buttons: crm5's look, 44 px tall ───────────────────────────────────── */
.pt-body .btn, .pt-guest .btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px; }
.pt-body .btn-sm, .pt-guest .btn-sm, .pt-btn-sm { height: auto; min-height: 44px; padding: 6px 14px; }
.pt-body .btn-icon-sq, .pt-body .crm-icon-btn { min-width: 44px; min-height: 44px; }
.pt-btn i { font-size: 1.1rem; }
.pt-btn-ghost { color: var(--crm-link); text-decoration: none; }
.pt-btn-ghost:hover { background: var(--crm-primary-soft); color: var(--crm-primary-ink); }
.pt-btn-block { width: 100%; }
.pt-icon-btn {
  position: relative; display: inline-flex; flex: none; align-items: center; justify-content: center;
  width: 44px; height: 44px; border: 0; border-radius: 12px; background: transparent; color: inherit;
  font-size: 1.3rem; text-decoration: none; cursor: pointer;
}
.pt-icon-btn:hover { background: var(--crm-primary-soft); color: var(--crm-primary-ink); }
.pt-dot {
  position: absolute; top: 4px; right: 2px; min-width: 18px; padding: 0 5px; border-radius: 999px;
  background: var(--rb-miss); color: var(--crm-surface); font-size: .68rem; font-weight: 700; line-height: 18px; text-align: center;
}
/* FullCalendar's toolbar buttons */
.pt-body .fc .fc-button { min-width: 44px; min-height: 44px; }

/* ── Forms: crm5's fields, 44 px tall ───────────────────────────────────── */
.pt-body .form-control, .pt-body .form-select { min-height: 44px; }
.pt-body textarea.form-control { min-height: 110px; }
/* Bootstrap check rows as 44 px rows: the box and its label line up and the whole row is the target */
.page-content .form-check { display: flex; align-items: center; gap: .6em; min-height: 44px; margin-bottom: 0; padding-left: 0; }
.page-content .form-check .form-check-input { float: none; flex: none; margin: 0; }
.page-content .form-check-label { display: inline-flex; align-items: center; min-height: 44px; cursor: pointer; }
.page-content label.form-check { min-width: 44px; cursor: pointer; }
.pt-nt-item-title { display: flex; align-items: center; min-height: 44px; }
.page-content td > label[for] { display: inline-flex; align-items: center; min-height: 44px; cursor: pointer; }
.pt-field { min-width: 0; margin-bottom: 16px; }
.pt-label { display: block; }
.pt-hint { font-size: .78rem; color: var(--crm-muted); }
.pt-error { font-size: .8rem; font-weight: 600; }
.pt-input.is-invalid { border-color: var(--rb-miss); }

/* ── Badges: crm5's .crm-badge (x-pt.status-badge); bare .pt-badge spans get the same shape ── */
.pt-badge {
  display: inline-flex; align-items: center; justify-content: center; padding: 3px 10px;
  border: 1px solid transparent; border-radius: 999px; font-size: .72rem; font-weight: 600; line-height: 1.5; white-space: nowrap;
}
/* crm5's status palette (the --s-* tokens of crm-ui.css), as on .crm-b-success / warning / danger / primary / neutral */
.pt-badge:not(.crm-badge).pt-badge-ok { background: var(--s-bg-success); color: var(--s-success); border-color: var(--s-br-success); }
.pt-badge:not(.crm-badge).pt-badge-almost { background: var(--s-bg-warning); color: var(--s-warning); border-color: var(--s-br-warning); }
.pt-badge:not(.crm-badge).pt-badge-miss { background: var(--s-bg-danger); color: var(--s-danger); border-color: var(--s-br-danger); }
.pt-badge:not(.crm-badge).pt-badge-new { background: var(--s-bg-purple); color: var(--s-purple); border-color: var(--s-br-purple); }
.pt-badge:not(.crm-badge).pt-badge-neutral { background: var(--s-bg-neutral); color: var(--s-neutral); border-color: var(--s-br-neutral); }
.crm-badge.pt-badge { min-width: 0; }

/* ── Stat tiles: crm5's .stat-card (x-pt.stat) ──────────────────────────── */
.pt-stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 170px), 1fr)); gap: 12px; }
.pt-stat-card { min-width: 0; padding: 14px 16px; }
.pt-stat-card .stat-icon { width: 44px; height: 44px; border-radius: 12px; font-size: 1.3rem; }
.pt-stat-card .stat-value { color: var(--crm-heading); }
.pt-stat-card .stat-label { color: var(--crm-muted); overflow-wrap: anywhere; }
.pt-stat-body { min-width: 0; }
.pt-tone-primary .stat-icon { background: var(--crm-primary-soft); color: var(--crm-primary-ink); }
.pt-tone-ok .stat-icon { background: var(--rb-ok-bg); color: var(--rb-ok); }
.pt-tone-almost .stat-icon { background: var(--rb-almost-bg); color: var(--rb-almost); }
.pt-tone-miss .stat-icon { background: var(--rb-miss-bg); color: var(--rb-miss); }
.pt-tone-sun .stat-icon { background: var(--rb-sun); color: var(--rb-sun-ink); }
.card .pt-stat-card { box-shadow: none; }

/* ── Avatars ────────────────────────────────────────────────────────────── */
.pt-avatar {
  display: inline-flex; flex-shrink: 0; align-items: center; justify-content: center; width: 36px; height: 36px;
  border-radius: 50%; background: linear-gradient(135deg, var(--crm-primary), var(--crm-primary-light));
  color: var(--crm-on-primary); font-weight: 700; text-transform: uppercase;
}
.pt-avatar-sm { width: 28px; height: 28px; font-size: .8rem; }

/* ── Tables: crm5's header in the sidebar colour (crm-layout styles .table; this adds .pt-table) ── */
.pt-table thead th {
  background: var(--crm-sidebar); color: var(--crm-sidebar-text);
  border-bottom: 2px solid rgba(var(--crm-sidebar-text-rgb), .2); font-size: .77rem; font-weight: 600; white-space: nowrap;
}
.pt-table thead th:first-child { border-top-left-radius: 10px; }
.pt-table thead th:last-child { border-top-right-radius: 10px; }
.pt-table tbody tr:hover, .page-content .table tbody tr:hover { background: var(--crm-primary-soft); }
.page-content .table { --bs-table-bg: transparent; --bs-table-color: var(--crm-body-text); }
.page-content .table thead tr:first-child th:first-child { border-top-left-radius: 10px; }
.page-content .table thead tr:first-child th:last-child { border-top-right-radius: 10px; }

/* ── Modal: a <dialog> in crm5's .modal-content with the gradient .crm-modal-header ── */
.pt-modal {
  width: min(600px, calc(100vw - 24px)); max-height: calc(100dvh - 28px); padding: 0; overflow: visible;
  border: 0; border-radius: 18px; background: transparent; color: var(--crm-body-text);
}
.pt-modal::backdrop { background: rgba(0, 0, 0, .5); }
.pt-modal .modal-content { max-height: calc(100dvh - 28px); overflow: hidden; background: var(--crm-surface); }
.pt-modal .crm-modal-header { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.pt-modal .modal-title { margin: 0; color: var(--crm-on-primary); font-size: 1rem; font-weight: 700; }
.pt-modal .pt-modal-close { color: var(--crm-on-primary); }
.pt-modal .pt-modal-close:hover { background: rgba(var(--crm-sidebar-text-rgb), .18); color: var(--crm-on-primary); }
.pt-modal .modal-body { overflow-y: auto; }
.pt-modal .modal-footer { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; }

/* ── Empty state: crm5's .crm-empty ─────────────────────────────────────── */
.crm-empty.pt-empty { padding: 32px 16px; }
.crm-empty__icon i { line-height: 1; }
.pt-empty-title, .pt-empty-text { margin: 0; }
.pt-body .crm-empty__title { color: var(--crm-heading); }
.pt-body .crm-empty__text { color: var(--crm-muted); }
.pt-empty-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }

/* ── Bottom nav (crm-mobile.css shows it at 768 px and below) ───────────── */
.crm-bottom-nav__item { min-width: 0; min-height: 44px; }
.crm-bottom-nav__item span { max-width: 100%; padding: 0 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ── Narrow screens: crm5's drawer (900 px and below) and phone tweaks ──── */
@media (max-width: 900px) {
  /* The open drawer and its shade sit above the bottom nav (crm-mobile.css gives that 1030) */
  .sidebar { z-index: 1045; }
  .crm-mobile-overlay { z-index: 1040; }
  .pt-sidebar-close { display: flex !important; width: 44px; height: 44px; margin-left: auto; font-size: 1.1rem; }
  .sidebar:target { left: 20px; }
  .sidebar:target ~ .crm-mobile-overlay, .crm-mobile-overlay:target { display: block; }
}
@media (max-width: 768px) {
  /* One row, as a native app bar: the title gives way (ellipsis), the buttons keep their size */
  .topbar { flex-wrap: nowrap; min-height: 60px; padding: 6px 10px !important; border-radius: 0 0 16px 16px; }
  .topbar > .d-flex:first-child { min-width: 0; }
  .topbar .page-title { min-width: 0; }
  .topbar-right { flex: none; }
  .pt-page-title { font-size: 1.3rem; }
  .topbar-user { padding: 4px 6px; }
  .topbar-user .pt-caret { display: none; }
  .topbar-bell { width: 44px !important; height: 44px !important; }
  .page-content { padding: 12px 10px !important; }
  .pt-page-actions { justify-content: flex-start; }
  .pt-family-badge { display: none; }
  details.pt-dd > .dropdown-menu { position: fixed; top: 66px; right: 10px; left: auto; }
  .pt-viewing { margin: 0 10px 6px; }
  .pt-body .form-control, .pt-body .form-select { font-size: 16px !important; }
}
@media (max-width: 420px) {
  .topbar .pt-kids .user-name { display: none; }
}

/* ── Dark mode: Buddy's surfaces and crm5's that crm-dark.css doesn't reach ── */
html[data-bs-theme="dark"] .crm-card-title,
html[data-bs-theme="dark"] .pt-body .crm-empty__title { color: var(--crm-heading); }
html[data-bs-theme="dark"] .topbar .crm-mobile-toggle,
html[data-bs-theme="dark"] .topbar-bell { border-color: var(--crm-border); color: var(--crm-body-text); }
html[data-bs-theme="dark"] .pt-card-foot { border-color: var(--crm-border); }
html[data-bs-theme="dark"] .crm-empty__icon { background: var(--crm-primary-soft); color: var(--crm-primary-ink); }
html[data-bs-theme="dark"] .pt-table td, html[data-bs-theme="dark"] .pt-table th { border-color: var(--crm-border); }
html[data-bs-theme="dark"] .btn-outline-primary { color: var(--crm-primary-ink); border-color: rgba(var(--rb-ink-rgb), .55); }
html[data-bs-theme="dark"] .crm-card-title > i,
html[data-bs-theme="dark"] .pt-card-title > i { color: var(--crm-primary-ink); }
html[data-bs-theme="dark"] .crm-bottom-nav__item { color: var(--crm-muted); }
html[data-bs-theme="dark"] .crm-bottom-nav__item.active { color: var(--crm-primary-ink); }

/* ── Sign-in pages (crm5's guest shell, vendor/geex/css/crm-guest.css) ──── */
.pt-guest .login-brand-wrap { align-items: center; }
.pt-login-logo {
  display: inline-flex; flex: none; align-items: center; justify-content: center; width: 42px; height: 42px;
  border-radius: 12px; background: linear-gradient(135deg, var(--crm-primary), var(--crm-primary-light));
  color: var(--crm-on-primary); font-size: 1.35rem;
}
/* app.css colours every heading; on the purple panel they stay white, as in crm5 */
.login-bg-text h2, .login-bg-text p { color: var(--crm-on-primary); }
.login-form-inner .auth-title { font-size: 1.3rem; line-height: 1.25; }
.login-form-inner .pt-auth-sub, .login-form-inner .auth-subtitle { font-size: .9rem; }
/* crm5's light greys for these are under 4.5:1 on white; the muted token reads */
.login-tagline, .login-form-inner .auth-subtitle, .login-form-inner .pt-auth-note { color: var(--crm-muted); }
.login-form-inner .pt-auth-sub, .login-form-inner .pt-auth-note { opacity: 1; }
.btn.btn-login { min-height: 48px; border: 0; color: var(--crm-on-primary); }
.btn.btn-login:hover, .btn.btn-login:focus { color: var(--crm-on-primary); }
.login-form-inner .form-control { min-height: 46px; }
.login-footer-text { color: var(--crm-muted); }
/* Short screens (a landscape phone, a tablet at 150%): the features and heading stack instead of overlapping */
@media (max-height: 720px) {
  .login-bg-panel { flex-direction: column; align-items: stretch; justify-content: space-between; gap: 20px; }
  .login-bg-features { position: relative; top: auto; left: auto; right: auto; transform: none; gap: 14px; }
  .login-bg-text h2 { font-size: 1.7rem; }
}
@media (max-width: 768px) {
  .pt-guest .form-control { font-size: 16px; }
}

@media (prefers-reduced-motion: reduce) {
  .sidebar, .main-wrapper { transition: none; }
}

@media print {
  .sidebar, .topbar, .crm-bottom-nav, .pt-page-actions, .crm-mobile-overlay, .login-bg-panel, .login-footer { display: none !important; }
  .main-wrapper { margin: 0 !important; padding: 0 !important; }
}
