/* Picasso Themes (Story 5656) -- color themes any page can wear.

   A theme is a set of CSS custom properties on <html data-pt-theme="...">, chosen with
   PicassoThemes.openPicker (picasso-themes.js) and remembered in the database per SCOPE (a
   page family: 'health' is every Health Records II page). A page adopts themes by reading the
   variables WITH its own colors as the fallback, so with no theme chosen it looks exactly as it
   always did:

       .my-head { background: var(--pt-head-bg, #0F766E); color: var(--pt-head-ink, #fff); }

   The variables:
       --pt-head-bg      the header's background (a color, or a gradient for the metallic ones)
       --pt-head-ink     text on the header
       --pt-head-soft    quieter text on the header (a crumb, a line of facts)
       --pt-head-shadow  a text shadow that keeps header text readable on a sheen ('none' if not needed)
       --pt-accent       buttons, the chosen tab, links, fold titles
       --pt-accent-ink   text on an accent background
       --pt-accent-dark  an accent button under the finger / pointer
       --pt-accent-wash  a light tint of the accent (hover, chips, counts)
       --pt-accent-line  a border in the accent's family (outlined buttons)
       --pt-edge         the colored left edge of a card or row
       --pt-page         the page behind the cards

   The themes themselves are rows of data in picasso-themes.js, which writes their rules into the
   page (one line per theme there; the colors are worked out from one to three base colors). Each
   theme also answers to [data-pt-preview="..."], so a swatch in the picker can wear it on its own.

   This file holds two things: the common chrome every themed page shares, and the picker. */

/* ---- the common chrome: a page that joins a scope gets these for free ----
   Only while a theme is chosen (:root[data-pt-theme]), so a page with no theme is untouched. A
   page's own parts read the --pt-* variables with their usual color as the fallback. */
:root[data-pt-theme] body { background: var(--pt-page); }
:root[data-pt-theme] .ct-header,
:root[data-pt-theme] .ed-header,
:root[data-pt-theme] .picasso-header { background: var(--pt-head-bg); color: var(--pt-head-ink); text-shadow: var(--pt-head-shadow); }
:root[data-pt-theme] .ct-header h1, :root[data-pt-theme] .ed-header h1, :root[data-pt-theme] .picasso-header h1 { color: var(--pt-head-ink); }
:root[data-pt-theme] .ed-header a { color: var(--pt-head-soft); border-color: currentColor; }
:root[data-pt-theme] .ed-header a:hover { background: rgba(255, 255, 255, .2); color: var(--pt-head-ink); }
:root[data-pt-theme] .ed-tabs { background: var(--pt-accent-dark); }
:root[data-pt-theme] .ed-tab:hover { background: var(--pt-accent); }
:root[data-pt-theme] .ed-tab.active { border-bottom-color: var(--pt-edge); }
:root[data-pt-theme] .ed-btn.primary,
:root[data-pt-theme] .btn-primary { background: var(--pt-accent); border-color: var(--pt-accent); color: var(--pt-accent-ink); }
:root[data-pt-theme] .ed-btn.primary:hover,
:root[data-pt-theme] .btn-primary:hover { background: var(--pt-accent-dark); border-color: var(--pt-accent-dark); }
/* the Theme button PicassoThemes.buttonHtml() draws when a page has no button style of its own */
.pt-open { background: #fff; color: var(--pt-accent, #1B1B1F); border: 1px solid var(--pt-accent-line, #C9CED8); border-radius: 6px;
           padding: 6px 12px; font: inherit; font-size: 13px; font-weight: 600; cursor: pointer; white-space: nowrap; }

/* ---- the picker: a sheet of swatches. It closes only by its own buttons or Escape. ---- */
.pt-bg {
    position: fixed; inset: 0; z-index: 2000; background: rgba(15, 23, 42, .45);
    display: flex; align-items: flex-start; justify-content: center; padding: 24px 12px; overflow: auto;
}
.pt-sheet {
    background: #fff; border-radius: 12px; width: 100%; max-width: 640px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, .25); font-family: inherit;
    /* the swatches scroll; the family tabs and Save / Cancel stay in sight */
    display: flex; flex-direction: column; max-height: calc(100dvh - 48px);
}
.pt-fams { display: flex; gap: 6px; padding: 6px 16px 8px; overflow-x: auto; flex: 0 0 auto; border-bottom: 1px solid #E1E4EB; scrollbar-width: none; }
.pt-fams::-webkit-scrollbar { display: none; }
.pt-fam { flex: 0 0 auto; background: #fff; color: #1B1B1F; border: 1px solid #C9CED8; border-radius: 16px; padding: 5px 12px; font: inherit; font-size: 13px; cursor: pointer; white-space: nowrap; }
.pt-fam span { color: #6B7280; font-size: 11.5px; margin-left: 2px; }
.pt-fam.on { background: #1B1B1F; border-color: #1B1B1F; color: #fff; }
.pt-fam.on span { color: #D1D5DB; }
.pt-grid[hidden] { display: none; }
.pt-chosen { flex: 1 1 auto; align-self: center; font-size: 13px; color: #5B6472; }
.pt-head { display: flex; align-items: center; padding: 14px 16px 6px; }
.pt-head h2 { margin: 0; font-size: 17px; flex: 1 1 auto; color: #1B1B1F; }
.pt-body { padding: 12px 16px 12px; overflow: auto; flex: 1 1 auto; }
.pt-group { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: #5B6472; margin: 12px 0 8px; }
.pt-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 10px; }
.pt-swatch {
    display: flex; flex-direction: column; align-items: stretch; gap: 6px; padding: 6px; cursor: pointer;
    background: #fff; border: 2px solid #E1E4EB; border-radius: 10px; font: inherit; font-size: 13px; color: #1B1B1F; text-align: left;
}
.pt-swatch:hover { border-color: #9AA3AE; }
.pt-swatch.on { border-color: #1B1B1F; box-shadow: 0 0 0 2px rgba(27, 27, 31, .15); }
.pt-chipbar { height: 30px; border-radius: 6px; display: flex; align-items: flex-end; padding: 4px; gap: 4px; }
.pt-chipbar i { display: block; width: 18px; height: 8px; border-radius: 4px; }
.pt-name { display: flex; align-items: center; gap: 6px; font-weight: 600; }
.pt-swatch.on .pt-name::before { content: '\2713'; }
.pt-foot { flex: 0 0 auto; display: flex; justify-content: flex-end; gap: 8px; padding: 12px 16px; border-top: 1px solid #E1E4EB; }
.pt-btn { background: #fff; color: #1B1B1F; border: 1px solid #C9CED8; border-radius: 6px; padding: 7px 14px; font: inherit; font-size: 14px; cursor: pointer; }
.pt-btn.primary { background: #1B1B1F; color: #fff; border-color: #1B1B1F; }
