/* Owner: package P2 (Customise drawer, snackbar and Theme Library). Clockface Online rebrand overrides, linked last in the index.php head.
   Loads after style.css and cfo.css. Tokens only; legacy !important rules are beaten with #settingsDrawer / #themeLibraryModal specificity. */

/* =====================================================================
   DRAWER SHELL
   ===================================================================== */
/* A closed drawer is off-screen and out of the tab order; visibility flips after the 300ms slide. */
.drawer:not(.open) { visibility: hidden; }
.drawer.open { visibility: visible; transition: right var(--dur-base) var(--ease), visibility 0s linear 0s; }
@media (prefers-reduced-motion: reduce) {
    .drawer, .drawer.open { transition: none !important; }
    .accordion-content, .theme-tab-pane { animation: none !important; }
}

#settingsDrawer { color: var(--text-primary); font-family: var(--font-sans); }
#settingsDrawer .close-drawer:focus-visible { outline-offset: 2px; }

/* Accordion headers get a little inset so the hover well does not touch the text. */
#settingsDrawer .accordion-header {
    width: calc(100% + var(--space-4));
    margin: 0 calc(var(--space-2) * -1);
    padding: 18px var(--space-2);
}

/* =====================================================================
   LABELS, BADGES, DIVIDERS
   ===================================================================== */
#settingsDrawer .drawer-divider { height: 1px; width: 100%; margin: 18px 0; background: var(--border); }
#settingsDrawer .drawer-group-divided { margin-top: 20px; padding-top: 15px; border-top: 1px solid var(--border); }
#settingsDrawer .drawer-label-icon { margin-right: 6px; color: var(--text-secondary); }
#settingsDrawer .drawer-label-icon-gold { color: var(--gold-ink); }
#settingsDrawer .drawer-label-badge { margin-left: 6px; }
#settingsDrawer .drawer-subhead { margin-bottom: var(--space-2); }

/* =====================================================================
   SEGMENTED CONTROLS (Starter / Saved / Community and Time & Date)
   ===================================================================== */
#settingsDrawer .drawer-theme-tabs { margin-bottom: var(--space-4); }
#settingsDrawer .seg-btn { min-height: 36px; font-size: 14px; line-height: 20px; }

/* =====================================================================
   THEME TILES
   ===================================================================== */
#settingsDrawer .preset-grid { margin-bottom: var(--space-4); }
.preset-btn.is-selected,
.preset-btn[aria-pressed="true"] { box-shadow: 0 0 0 2px var(--accent), var(--shadow-sm); }
.preset-btn-locked i { opacity: 0.85; }

/* Saved tiles sit in an overflow-hidden wrapper, so their focus ring is drawn inside. */
.saved-theme-tile .preset-btn:focus-visible,
.saved-theme-delete:focus-visible { outline-offset: -3px; }
#drawerSavedStylesGrid { margin-bottom: var(--space-3); }
.saved-theme-delete {
    position: absolute; top: 50%; right: 0; z-index: 3;
    display: grid; place-items: center; width: 44px; height: 44px;
    padding: 0; border: 0; border-radius: var(--radius-pill); background: none;
    font: inherit; font-size: 14px; opacity: 0.7; cursor: pointer;
    transform: translateY(-50%);
    transition: opacity var(--dur-fast) var(--ease);
}
.saved-theme-delete:hover,
.saved-theme-delete:focus-visible { opacity: 1; }
.drawer-empty { width: 100%; padding: 10px 0; text-align: center; color: var(--text-tertiary); font-size: 12px; line-height: 16px; }
#settingsDrawer .drawer-hint { margin-bottom: var(--space-4); text-align: center; font-size: 12px; line-height: 16px; }
#settingsDrawer .drawer-notice { margin-bottom: var(--space-4); }
#settingsDrawer .upgrade-notice .fa-lock { color: var(--text-secondary); margin-right: 2px; }

/* Drawer community tiles are real buttons now: reset the button look, keep the card look. */
#drawer-community .community-card {
    -webkit-appearance: none; appearance: none;
    padding: 0; font: inherit; color: inherit; text-align: center; box-sizing: border-box;
}
#drawer-community .community-card:hover .community-card-info,
#drawer-community .community-card:focus-within .community-card-info { opacity: 1; }
#drawer-community .drawer-community-user { margin-top: 2px; font-family: var(--font-sans); font-size: 10px; line-height: 14px; opacity: 0.9; }

#openLibraryBtn { margin-top: var(--space-1); }

/* =====================================================================
   SAVE CURRENT LOOK CARD
   ===================================================================== */
#settingsDrawer .save-theme-box,
body.dark-mode #settingsDrawer .save-theme-box {
    margin-bottom: var(--space-4);
    padding: var(--space-3) var(--space-4);
    border: 1px solid var(--border) !important;
    border-radius: var(--radius-lg);
    background: var(--surface-subtle) !important;
}
#settingsDrawer .save-theme-head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-2); margin-bottom: var(--space-2); }
#settingsDrawer .save-theme-title i { margin-right: 4px; color: var(--accent-ink); }
#settingsDrawer .settings-group label.publish-label,
body.dark-mode #settingsDrawer .settings-group label.publish-label {
    display: inline-flex; align-items: center; gap: 6px; min-height: 44px; margin: 0;
    font-size: 12px; line-height: 16px; font-weight: 500; text-transform: none; letter-spacing: 0;
    color: var(--text-secondary) !important; cursor: pointer;
}
#publishCheckbox { width: 16px; height: 16px; margin: 0; accent-color: var(--accent-ink); cursor: pointer; }
#settingsDrawer .save-theme-row { display: grid; gap: var(--space-2); }
#customStyleName { width: 100%; min-width: 0; margin: 0; box-sizing: border-box; }
/* The field sits on a subtle well, so it takes the paper colour to stay visible. */
#settingsDrawer .save-theme-box .custom-input,
body.dark-mode #settingsDrawer .save-theme-box .custom-input {
    background: var(--surface) !important;
    border-color: var(--border-control) !important;
    color: var(--text-primary) !important;
}
#saveThemeBtn,
body.dark-mode #saveThemeBtn,
#saveThemeBtn.is-private,
#saveThemeBtn.is-saved {
    height: 44px; padding: 0 var(--space-5); border: 0;
    background: var(--primary); color: var(--on-primary);
    font-size: 15px; line-height: 22px;
}
#saveFeedbackMsg.save-feedback { margin-top: var(--space-2); padding: var(--space-2) var(--space-3); font-size: 12px; line-height: 16px; text-align: left; }
.cfo-notice-neutral { --notice: var(--text-secondary); --notice-ink: var(--text-secondary); --notice-bg: var(--surface); --notice-line: var(--border); }

/* =====================================================================
   SWATCHES AND CUSTOM PICKERS
   ===================================================================== */
/* 36px visible swatch, 44px hit area. */
#settingsDrawer .swatch::after { content: ""; position: absolute; inset: -4px; border-radius: var(--radius-md); }
#settingsDrawer .swatch:focus-visible { outline-offset: 3px; }
/* The custom picker is a <label> round the colour input: undo the overline label style. */
#settingsDrawer .settings-group label.custom-picker {
    display: flex; margin: 0; font-size: 14px; line-height: 1; letter-spacing: 0; text-transform: none;
    color: var(--text-secondary);
}
#settingsDrawer .custom-picker:focus-within { outline: 2px solid var(--focus); outline-offset: 3px; }
#settingsDrawer .custom-picker:has(input:focus:not(:focus-visible)) { outline: none; }
#settingsDrawer .swatch-lock { color: var(--text-secondary); font-size: 10px; }
#settingsDrawer .custom-picker .swatch-lock { font-size: 14px; }
#settingsDrawer .swatch.disabled-swatch:hover { border-color: var(--border); }

/* Locked live backgrounds: the whole tile (swatch plus label) is one button. */
#settingsDrawer .swatch-wrapper-locked {
    min-width: 44px; min-height: 44px; padding: 0; border: 0; border-radius: var(--radius-md);
    background: none; color: inherit; font: inherit; cursor: pointer;
}
#settingsDrawer .swatch-wrapper-locked .swatch { cursor: pointer; }
#settingsDrawer .swatch-wrapper-locked:hover .swatch { box-shadow: var(--shadow-sm); }

/* =====================================================================
   UNSPLASH SEARCH, RESULTS, HISTORY AND UPLOAD
   ===================================================================== */
#settingsDrawer .unsplash-search-row { display: flex; align-items: center; gap: var(--space-2); margin-bottom: var(--space-3); }
#unsplashInput { flex: 1; min-width: 0; margin: 0; }
#unsplashGrid { margin-bottom: var(--space-4); }
#settingsDrawer .unsplash-message { grid-column: 1 / -1; padding: 6px 0; text-align: center; color: var(--text-tertiary); font-size: 12px; line-height: 16px; }
#settingsDrawer .unsplash-message.is-error { color: var(--danger); }
#settingsDrawer .unsplash-thumb {
    display: block; width: 100%; min-height: 44px; padding: 0; border: 0; border-radius: var(--radius-sm);
    background: var(--surface-subtle); overflow: hidden; cursor: pointer;
}
#settingsDrawer .unsplash-thumb .image { display: block; height: 50px; border-radius: 0; }
#settingsDrawer .unsplash-history { margin-bottom: var(--space-4); padding-top: var(--space-3); border-top: 1px solid var(--border); }
#settingsDrawer .unsplash-history-title { margin-bottom: var(--space-2); }
#settingsDrawer .unsplash-history-grid { display: flex; gap: var(--space-2); padding-bottom: 5px; overflow-x: auto; scrollbar-width: thin; }
#settingsDrawer .unsplash-history-card {
    position: relative; flex-shrink: 0; width: 100px; min-width: 100px; overflow: hidden;
    border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface-subtle);
}
#settingsDrawer .unsplash-history-apply { display: block; width: 100%; padding: 0; border: 0; background: none; cursor: pointer; }
#settingsDrawer .unsplash-history-apply:focus-visible { outline-offset: -3px; }
#settingsDrawer .unsplash-history-apply img { display: block; width: 100%; height: 50px; object-fit: cover; transition: opacity var(--dur-fast) var(--ease); }
#settingsDrawer .unsplash-history-apply:hover img { opacity: 0.85; }
#settingsDrawer .unsplash-history-credit { display: flex; flex-direction: column; gap: 2px; padding: 5px 4px; text-align: center; font-size: 10px; line-height: 14px; }
#settingsDrawer .unsplash-history-author { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; color: var(--text-secondary); }
#settingsDrawer .unsplash-history-author a { color: var(--text-primary); text-decoration: underline; }
#settingsDrawer .unsplash-history-source { color: var(--accent-ink); font-weight: 600; text-decoration: none; }
#settingsDrawer .unsplash-history-source i { font-size: 10px; }
#settingsDrawer .unsplash-upload { margin-top: var(--space-4); }

/* =====================================================================
   SIZE SLIDER
   ===================================================================== */
#settingsDrawer .slider-container i { color: var(--text-secondary); }
#settingsDrawer .slider-container .small-btn { min-width: 44px; justify-content: center; }

/* =====================================================================
   FONT CONTROLS AND GRID
   ===================================================================== */
#settingsDrawer .flex-actions .action-btn { min-width: 44px; justify-content: center; }
/* The on state of Bold / Italic was invisible in light mode: tan fill, navy glyph. */
#settingsDrawer .toggle-btn.active,
body.dark-mode #settingsDrawer .toggle-btn.active { background: var(--accent) !important; color: var(--on-primary) !important; }
#settingsDrawer .font-btn.is-selected,
body.dark-mode #settingsDrawer .font-btn.is-selected {
    border-color: var(--accent-ink) !important;
    box-shadow: inset 0 0 0 1px var(--accent-ink);
    background: var(--accent-tint) !important;
}
#customGoogleFontName { min-width: 0; margin: 0; }
#settingsDrawer .custom-font-apply,
body.dark-mode #settingsDrawer .custom-font-apply { flex-shrink: 0; background: var(--primary); color: var(--on-primary); }
#settingsDrawer .custom-font-error { padding: var(--space-2) var(--space-3); font-size: 12px; line-height: 16px; text-align: left; }
#settingsDrawer .cfo-btn .cfo-badge { margin-left: var(--space-1); }

/* =====================================================================
   TIME ZONE SEARCH AND DROPDOWN
   ===================================================================== */
#settingsDrawer .tz-search { position: relative; width: 100%; }
#settingsDrawer .tz-search-icon {
    position: absolute; top: 50%; left: 12px; z-index: 2;
    color: var(--text-tertiary); font-size: 12px; pointer-events: none;
    transform: translateY(-50%);
}
#tzSearchInput { position: relative; z-index: 1; width: 100%; margin: 0; padding: 8px 44px 8px 34px; box-sizing: border-box; }
#settingsDrawer .tz-clear-btn {
    position: absolute; top: 50%; right: 0; z-index: 3;
    width: 44px; height: 44px; padding: 0; border: 0; border-radius: var(--radius-pill); background: none;
    color: var(--text-tertiary); font: inherit; font-size: 14px; line-height: 44px; text-align: center; cursor: pointer;
    transform: translateY(-50%);
    transition: color var(--dur-fast) var(--ease);
}
#settingsDrawer .tz-clear-btn:hover { color: var(--danger); }
#settingsDrawer .tz-dropdown {
    position: absolute; top: calc(100% + 4px); left: 0; z-index: 100;
    width: 100%; max-height: 240px; overflow-y: auto; scrollbar-width: thin;
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md);
    box-shadow: var(--shadow-float);
}
#settingsDrawer .tz-option {
    display: flex; align-items: center; gap: var(--space-2); width: 100%; min-height: 44px; padding: 10px 12px;
    border: 0; border-bottom: 1px solid var(--border); background: transparent;
    color: var(--text-primary); font: inherit; font-size: 13px; line-height: 18px; text-align: left; cursor: pointer;
    transition: background-color var(--dur-fast) var(--ease);
}
#settingsDrawer .tz-option:last-child { border-bottom: 0; }
#settingsDrawer .tz-option:hover { background: var(--surface-hover); }
#settingsDrawer .tz-option.is-selected { background: var(--primary-tint); font-weight: 600; }
#settingsDrawer .tz-option-local { font-weight: 600; }
#settingsDrawer .tz-option i { color: var(--text-secondary); }
#settingsDrawer .tz-option:focus-visible { outline-offset: -2px; }
#settingsDrawer .tz-empty { padding: 15px; text-align: center; color: var(--text-tertiary); font-size: 12px; line-height: 16px; }

/* =====================================================================
   DRAWER FOOTER AND AD SLOT
   ===================================================================== */
#settingsDrawer .drawer-footer-actions { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--space-2); }
#settingsDrawer .drawer-footer .cfo-btn {
    height: auto; min-height: 44px; padding: var(--space-1) var(--space-2);
    font-size: 13px; line-height: 18px; gap: 6px; white-space: normal; text-align: center;
}
/* The footer is a subtle well, so its secondary buttons sit on paper with a hairline. */
#settingsDrawer .drawer-footer .cfo-btn-secondary,
body.dark-mode #settingsDrawer .drawer-footer .cfo-btn-secondary { background: var(--surface) !important; border: 1px solid var(--border) !important; }
#settingsDrawer .drawer-footer .cfo-btn-secondary:hover,
body.dark-mode #settingsDrawer .drawer-footer .cfo-btn-secondary:hover { background: var(--surface-hover) !important; }
#settingsDrawer .drawer-footer a.cfo-btn,
#settingsDrawer .drawer-footer a.cfo-btn:hover { color: var(--text-primary); }
#settingsDrawer .drawer-footer .drawer-coffee-btn,
body.dark-mode #settingsDrawer .drawer-footer .drawer-coffee-btn {
    margin-bottom: var(--space-2);
    background: var(--gold) !important; color: var(--on-primary) !important; border: 0 !important; box-shadow: none;
}
#settingsDrawer .drawer-footer .drawer-coffee-btn:hover { box-shadow: var(--shadow-sm); }

/* Ad slot (drawer and Theme Library only; other slots keep the shared .ad-slot rules). Display stays with the JS. */
#drawerAdSlot .ad-label,
#themeLibraryModalAdSlot .ad-label,
body.dark-mode #drawerAdSlot .ad-label,
body.dark-mode #themeLibraryModalAdSlot .ad-label { font-size: 10px; line-height: 14px; letter-spacing: 0.5px; color: var(--text-tertiary); }
#drawerAdSlot .ad-dismiss,
#themeLibraryModalAdSlot .ad-dismiss,
body.dark-mode #drawerAdSlot .ad-dismiss,
body.dark-mode #themeLibraryModalAdSlot .ad-dismiss {
    display: inline-grid; place-items: center; width: 44px; height: 44px; margin: -15px -12px -15px -8px;
    padding: 0; border: 0; border-radius: var(--radius-pill); background: none;
    color: var(--text-tertiary); opacity: 1; font: inherit; font-size: 12px; cursor: pointer;
    transition: background-color var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
#drawerAdSlot .ad-dismiss:hover,
#themeLibraryModalAdSlot .ad-dismiss:hover { background: var(--surface-hover); color: var(--text-primary); }
#drawerAdSlot .ad-upgrade-cta,
#themeLibraryModalAdSlot .ad-upgrade-cta {
    border: 1px solid var(--gold-line); border-radius: var(--radius-md); background: var(--gold-tint);
    color: var(--gold-ink); font-size: 12px; line-height: 16px;
}
#drawerAdSlot .ad-upgrade-cta:hover,
#themeLibraryModalAdSlot .ad-upgrade-cta:hover { border-color: var(--gold); background: var(--gold-tint); color: var(--gold-ink); }
#drawerAdSlot ins.adsbygoogle,
#themeLibraryModalAdSlot ins.adsbygoogle { background: var(--surface-hover); }

/* =====================================================================
   SNACKBAR (inverse toast)
   ===================================================================== */
#snackbar .cfo-toast-text { flex: 1; min-width: 0; }
#snackbar .cfo-toast-text i { margin-right: 4px; }
#snackbar .snackbar-link {
    padding: 0; border: 0; background: none; cursor: pointer;
    font: inherit; font-weight: 600; color: inherit; text-decoration: underline; text-underline-offset: 2px;
}
#snackbar .closeSmall {
    display: inline-grid; place-items: center; flex-shrink: 0; width: 44px; height: 44px; padding: 0;
    border: 0; border-radius: var(--radius-pill); background: var(--surface-14);
    color: var(--surface); opacity: 1; font: inherit; font-size: 16px;
}
#snackbar .closeSmall:hover { background: var(--surface-24); }
@media (max-width: 600px) {
    #snackbar { left: 16px !important; right: 16px !important; border-radius: var(--radius-lg); }
}

/* =====================================================================
   THEME LIBRARY MODAL
   ===================================================================== */
#themeLibraryModal .community-header { margin-bottom: var(--space-3); padding-bottom: var(--space-3); }
#themeLibraryTitle { margin: 0; color: var(--ink); font-size: 22px; line-height: 30px; font-weight: 700; }
#themeLibraryTitle i { margin-right: 6px; color: var(--accent-ink); }
#themeLibraryModal .theme-tab-btn { min-height: 44px; }

/* Cards: the hover state is a dark scrim, so its actions use glass (on-glass icons) or solid fills with navy text. */
.library-corner-badge { position: absolute; top: var(--space-2); right: var(--space-2); z-index: 5; }
.community-hover-state .apply-comm-btn {
    position: relative; display: inline-flex; align-items: center; justify-content: center; gap: 4px;
    min-height: 32px; line-height: 16px;
    transition: background-color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
}
/* Rows of icon actions wrap rather than spill out of narrow cards. */
.community-hover-state .hover-actions > div { flex-wrap: wrap; row-gap: var(--space-1); padding: 0 var(--space-1); }
/* Hit area reaches 44px tall without crowding the neighbours. */
.community-hover-state .apply-comm-btn::after { content: ""; position: absolute; inset: -6px 0; }
button.apply-comm-btn.is-icon { width: 32px; min-width: 32px; padding: 0 !important; }
button.apply-comm-btn.is-like { padding: 0 10px !important; }
button.apply-comm-btn.is-wide { padding: 5px 20px !important; }
button.apply-comm-btn.is-glass { background: var(--glass); color: var(--on-glass); box-shadow: inset 0 0 0 1px var(--glass-border); }
button.apply-comm-btn.is-glass:hover { background: var(--glass-border); }
button.apply-comm-btn.is-locked { opacity: var(--disabled); }
button.apply-comm-btn.is-plus,
button.apply-comm-btn.is-plus:hover { background: var(--gold); color: var(--on-primary); box-shadow: none; }
button.apply-comm-btn.is-danger,
button.apply-comm-btn.is-danger:hover { background: var(--danger); color: var(--on-glass); box-shadow: none; }
/* Liked state: P4 toggles .is-liked in toggleThemeLike; the server renders it on first paint. */
button.apply-comm-btn.is-liked,
button.apply-comm-btn.is-liked:hover { background: var(--danger); color: var(--on-glass); box-shadow: none; }
button.apply-comm-btn.is-saved,
button.apply-comm-btn.is-saved:hover { background: var(--primary); color: var(--on-primary); box-shadow: none; }

.library-empty { grid-column: 1 / -1; width: 100%; padding: 20px 0; text-align: center; color: var(--text-tertiary); font-size: 12px; line-height: 16px; }
.library-locked { padding: 40px 20px; text-align: center; }
.library-locked-icon { margin-bottom: 15px; color: var(--text-tertiary); font-size: 40px; }
#themeLibraryModal .library-locked-title,
body.dark-mode #themeLibraryModal .library-locked-title { margin: 0; color: var(--ink) !important; font-size: 18px; line-height: 26px; font-weight: 600; }
.library-locked-text { margin-top: 10px; color: var(--text-secondary); font-size: 14px; line-height: 20px; }
#themeLibraryModal .library-locked-btn,
body.dark-mode #themeLibraryModal .library-locked-btn { margin-top: 20px; background: var(--primary); color: var(--on-primary); text-decoration: none; }
.library-message {
    grid-column: 1 / -1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
    width: 100%; min-height: 220px; text-align: center; color: var(--text-secondary); font-size: 13px; line-height: 18px; font-weight: 500;
}
.library-message i { margin-bottom: 8px; font-size: 28px; }
.library-message.is-error { color: var(--danger); }
.library-message-hint { color: var(--text-tertiary); font-size: 12px; line-height: 16px; font-weight: 400; }

#themeLibraryModal .community-sort-row { display: flex; justify-content: flex-end; margin-bottom: var(--space-4); }
#themeLibraryModal .community-sort { width: auto; max-width: 100%; overflow-x: auto; }
#themeLibraryModal .community-sort .seg-btn { flex: 0 0 auto; min-height: 36px; padding: 6px 15px; font-size: 12px; line-height: 16px; white-space: nowrap; }

/* Lines below the grid (Load more and the coffee button) are owned elsewhere; restyled here only. */
#themeLibraryModal .modal-divider { border-top-color: var(--border) !important; }
#loadMoreCommunityBtn { border: 1px solid var(--border-control) !important; background: transparent !important; color: var(--text-primary) !important; }
#loadMoreCommunityBtn:hover { background: var(--surface-hover) !important; }
#themeLibraryModal .modal-divider .action-btn[onclick^="openCoffeeModal"],
body.dark-mode #themeLibraryModal .modal-divider .action-btn[onclick^="openCoffeeModal"] {
    background: var(--gold) !important; color: var(--on-primary) !important; box-shadow: none !important;
}
