/**
 * Canarsie Custom Component & Utility Styles
 * Material Design 3 Expressive Specification:
 * - Pure Tonal Elevation (Zero shadows, Zero borders)
 * - Expressive Shape Scale (Generous corner radii & pill forms)
 * - Spring-Based Motion Physics
 */

/* ==================================================================
   Pull to Refresh Indicator (<ct-pull-to-refresh>)
   ================================================================== */
.ct-ptr-indicator {
  position: fixed;
  top: calc(var(--toolbar-height, 56px) + 8px);
  left: 50%;
  margin-left: -20px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--md-sys-color-surface-container-highest);
  color: var(--md-sys-color-primary);
  border: none;
  box-shadow: none;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  opacity: 0;
  pointer-events: none;
  user-select: none;
  transform: translateY(-8px) scale(0.65);
  transition: opacity 0.2s ease, transform 0.25s var(--md-sys-motion-easing-spring, cubic-bezier(0.34, 1.56, 0.64, 1));
  will-change: transform, opacity;
}

.ct-ptr-spinner {
  width: 22px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.ct-ptr-svg {
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
}

.ct-ptr-circle {
  fill: none;
  stroke: var(--md-sys-color-primary);
  stroke-width: 3;
  stroke-linecap: round;
  stroke-dasharray: 56;
  stroke-dashoffset: 50;
  transition: stroke-dashoffset 0.1s ease;
}

.ct-ptr-indicator.ready .ct-ptr-circle {
  stroke-dashoffset: 14;
}

.ct-ptr-indicator.refreshing .ct-ptr-spinner {
  animation: ct-ptr-rotate 0.8s linear infinite;
}

@keyframes ct-ptr-rotate {
  100% { transform: rotate(360deg); }
}

/* ==================================================================
   <ct-toolset> Component (Expressive Segmented Pill Action Bar)
   ================================================================== */
ct-toolset {
  display: flex;
  box-sizing: border-box;
  width: 100%;
  max-width: 100%;
  position: sticky;
  top: 0;
  z-index: 8;
  background: inherit;
  align-items: center;
  padding: var(--toolset-padding, var(--toolset-padding-y, 12px) var(--toolset-padding-x, 16px));
  gap: var(--toolset-gap, 8px);
}

ct-toolset.padding {
  padding: var(--toolset-padding, var(--toolset-padding-y, 12px) var(--toolset-padding-x, 16px));
}

.ct-toolset_group {
  display: flex;
  flex-wrap: nowrap;
  border: none;
  border-radius: var(--toolset-radius, 9999px);
  overflow: hidden;
  height: var(--toolset-height, 42px);
  background: var(--md-sys-color-surface-container);
  flex-shrink: 0;
  padding: 3px;
  gap: 3px;
}

button.ct-toolset_button {
  padding: 0 14px 0 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  white-space: nowrap;
  gap: 6px;
  font-family: var(--md-ref-typeface-brand, 'Plus Jakarta Sans', system-ui, sans-serif);
  font-size: 13px;
  font-weight: 500;
  border: none;
  border-radius: 9999px;
  background: transparent;
  color: var(--md-sys-color-on-surface-variant);
  position: relative;
  cursor: pointer;
  height: 100%;
  transition: background-color 0.2s ease, color 0.2s ease, transform 0.2s var(--md-sys-motion-easing-spring, cubic-bezier(0.34, 1.56, 0.64, 1));
}

button.ct-toolset_button:hover {
  background-color: var(--md-sys-color-surface-container-high);
  color: var(--md-sys-color-on-surface);
}

button.ct-toolset_button:active {
  transform: scale(0.95);
}

button.ct-toolset_button.active {
  background-color: var(--md-sys-color-secondary-container);
  color: var(--md-sys-color-on-secondary-container);
  font-weight: 600;
}

button.ct-toolset_button.overflow {
  padding: 0;
  width: 36px;
  min-width: 36px;
  justify-content: center;
}

button.ct-toolset_button.overflow .label {
  display: none !important;
}

button.ct-toolset_button:not(.overflow) .label {
  display: inline-block;
}

button.ct-toolset_button md-icon {
  font-size: 20px;
  width: 20px;
  height: 20px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.ct-toolset_dot {
  display: none;
}

/* Floating badge for icon-only (overflow) buttons */
button.ct-toolset_button.overflow .ct-toolset_dot.visible {
  position: absolute;
  top: 2px;
  right: 2px;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  font-size: 10px;
  font-weight: 700;
  line-height: 16px;
  border-radius: 9999px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--md-sys-color-tertiary);
  color: var(--md-sys-color-on-tertiary);
  box-sizing: border-box;
  z-index: 2;
  pointer-events: none;
  animation: ct-pop 0.2s var(--md-sys-motion-easing-spring);
}

button.ct-toolset_button.overflow .ct-toolset_dot.visible:empty {
  min-width: 8px;
  width: 8px;
  height: 8px;
  top: 6px;
  right: 6px;
  padding: 0;
}

/* Inline pill count for buttons with labels */
button.ct-toolset_button:not(.overflow) .ct-toolset_dot.visible {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 9999px;
  font-size: 11px;
  font-weight: 700;
  line-height: 20px;
  background: var(--md-sys-color-tertiary);
  color: var(--md-sys-color-on-tertiary);
  margin-left: 2px;
  box-sizing: border-box;
  z-index: 2;
  animation: ct-pop 0.2s var(--md-sys-motion-easing-spring);
}

button.ct-toolset_button:not(.overflow) .ct-toolset_dot.visible:empty {
  min-width: 8px;
  width: 8px;
  height: 8px;
  padding: 0;
  margin-left: 4px;
}

ct-spacer {
  display: inline-block;
  height: 24px;
}

/* ==================================================================
   <ct-gallery> Component (M3 Expressive Carousel & Morphing Dots)
   ================================================================== */
ct-gallery, .ct-gallery_container {
  display: block;
  overflow: hidden;
  position: relative;
  width: 100%;
  border-radius: var(--gallery-radius, 24px);
  border: none;
  box-shadow: none;
  background: var(--md-sys-color-surface-container);
  transition: background-color 0.4s ease;
  touch-action: pan-y;
  user-select: none;
  -webkit-user-select: none;
}

.ct-gallery_track {
  display: flex;
  will-change: transform;
  width: 100%;
  align-items: center;
  touch-action: pan-y;
  user-select: none;
  -webkit-user-select: none;
}

.ct-gallery_track.transition {
  transition: transform 0.4s var(--md-sys-motion-easing-standard, cubic-bezier(0.2, 0, 0, 1));
}

.ct-gallery_track img {
  width: 100%;
  flex-shrink: 0;
  object-fit: cover;
  opacity: 0;
  transition: opacity 0.3s ease;
  user-select: none;
  -webkit-user-select: none;
  -webkit-user-drag: none;
  pointer-events: none;
  touch-action: pan-y;
}

.ct-gallery_track img.loaded {
  opacity: 1;
}

.ct-gallery_track img.square { aspect-ratio: 1 / 1; }
.ct-gallery_track img.classic { aspect-ratio: 4 / 3; }
.ct-gallery_track img.wide { aspect-ratio: 16 / 9; }

.ct-gallery_dots {
  position: absolute;
  bottom: 14px;
  left: 0;
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  z-index: 2;
}

/* M3 Expressive Morphing Dot Indicators: active expands into a pill */
.ct-gallery_dots .dot {
  width: 8px;
  height: 8px;
  border-radius: 9999px;
  background: rgba(255, 255, 255, 0.4);
  cursor: pointer;
  border: none;
  transition: width 0.35s var(--md-sys-motion-easing-spring, cubic-bezier(0.34, 1.56, 0.64, 1)),
              background-color 0.25s ease,
              transform 0.2s ease;
}

.ct-gallery_dots .dot:hover {
  background: rgba(255, 255, 255, 0.7);
  transform: scale(1.15);
}

.ct-gallery_dots .dot.active {
  width: 24px;
  background: #ffffff;
}

/* ==================================================================
   <ct-search> Component (M3 Expressive Pill Search Bar)
   ================================================================== */
ct-search {
  display: inline-flex;
  align-items: center;
  position: relative;
}

.ct-search_inner {
  display: flex;
  align-items: center;
  border-radius: var(--search-radius, 9999px);
  background: var(--md-sys-color-surface-container-high);
  border: none;
  box-shadow: none;
  padding: 0 4px;
  height: 48px;
  width: 280px;
  max-width: 100%;
  box-sizing: border-box;
  transition: width 0.35s var(--md-sys-motion-easing-spring, cubic-bezier(0.34, 1.56, 0.64, 1)),
              background-color 0.2s ease;
}

.ct-search_inner:focus-within {
  background: var(--md-sys-color-surface-container-highest);
  width: 330px;
}

.ct-search_toggle {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  --md-icon-button-icon-size: 20px;
  --md-icon-button-state-layer-width: 36px;
  --md-icon-button-state-layer-height: 36px;
  color: var(--md-sys-color-on-surface-variant);
  transition: color 0.2s ease;
}

.ct-search_inner:focus-within .ct-search_toggle {
  color: var(--md-sys-color-primary);
}

.ct-search_inner input {
  border: 0;
  background: transparent;
  outline: none;
  font-family: var(--md-ref-typeface-brand, 'Plus Jakarta Sans', sans-serif);
  font-size: 15px;
  font-weight: 400;
  color: var(--md-sys-color-on-surface);
  width: 100%;
  flex: 1;
  min-width: 0;
  height: 100%;
  padding: 0 4px;
  box-sizing: border-box;
}

.ct-search_inner input::placeholder {
  color: var(--md-sys-color-outline);
  opacity: 1;
}

.ct-search_clear {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  --md-icon-button-icon-size: 18px;
  --md-icon-button-state-layer-width: 36px;
  --md-icon-button-state-layer-height: 36px;
  color: var(--md-sys-color-on-surface-variant);
  display: none !important;
}

.ct-search_clear.enabled {
  display: inline-flex !important;
  animation: ct-pop 0.2s var(--md-sys-motion-easing-spring);
}

@container (max-width: 480px) {
  ct-search {
    width: 100%;
  }
  .ct-search_inner {
    width: 100%;
  }
  .ct-search_inner:focus-within {
    width: 100%;
  }
}

@media (max-width: 600px) {
  ct-search {
    width: 100%;
  }
  .ct-search_inner {
    width: 100%;
  }
  .ct-search_inner:focus-within {
    width: 100%;
  }
}

@keyframes ct-pop {
  0% { transform: scale(0.6); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

/* ==================================================================
   <ct-tooltip> Component
   ================================================================== */
ct-tooltip {
  display: none;
}

.ct-tooltip_placeholder {
  position: fixed;
  background: var(--md-sys-color-surface-container-highest);
  color: var(--md-sys-color-on-surface);
  border-radius: 12px;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 500;
  font-family: var(--md-ref-typeface-plain);
  z-index: 9999;
  pointer-events: none;
  border: none;
  box-shadow: none;
  max-width: 280px;
  animation: ct-tooltip-pop 0.2s var(--md-sys-motion-easing-spring, cubic-bezier(0.34, 1.56, 0.64, 1));
}

@keyframes ct-tooltip-pop {
  0% { transform: scale(0.9); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

.ct-tooltip_placeholder.rich {
  padding: 14px 18px;
  border-radius: 16px;
}

/* ==================================================================
   <ct-grid> Component (Responsive Masonry / Tile Grid)
   ================================================================== */
ct-grid {
  --grid-gap: 12px;
  display: block;
  position: relative;
  box-sizing: border-box;
  margin: calc(-1 * var(--grid-gap, 12px) / 2);
  width: calc(100% + var(--grid-gap, 12px));
}

ct-grid .item {
  display: block;
  position: absolute;
  top: 0;
  left: 0;
  z-index: 1;
  box-sizing: border-box;
  padding: calc(var(--grid-gap, 12px) / 2);
}

ct-grid .item-content {
  position: relative;
  width: 100%;
  height: 100%;
}

/* ==================================================================
   <card> & Tonal Surface Containers (Zero Shadows, Zero Borders)
   ================================================================== */
card {
  display: block;
  background: var(--md-sys-color-surface-container-high);
  color: var(--md-sys-color-on-surface);
  border-radius: var(--card-radius, 20px);
  position: relative;
  overflow: hidden;
  border: none;
  box-shadow: none;
  transition: background-color 0.2s ease,
              transform 0.25s var(--md-sys-motion-easing-spring, cubic-bezier(0.34, 1.56, 0.64, 1));
}

card:hover {
  background: var(--md-sys-color-surface-container-highest);
  transform: translateY(-2px);
}

card:active {
  transform: scale(0.985);
}

card:focus-visible {
  outline: 2px solid var(--md-sys-color-primary);
  outline-offset: 2px;
}

card[aria-selected="true"],
card.selected {
  background: var(--md-sys-color-surface-container-highest);
}

/* Card Tonal Variants */
card.tonal-low {
  background: var(--md-sys-color-surface-container);
}

card.tonal-low:hover {
  background: var(--md-sys-color-surface-container-high);
}

card.tonal-highest {
  background: var(--md-sys-color-surface-container-highest);
}

/* ==================================================================
   Material 3 Dropdown & Menu Components (<md-menu>, <md-menu-item>)
   Elevated surface container styling with crisp tonal contrast & subtle shadow
   ================================================================== */
md-menu {
  --md-menu-container-color: var(--md-sys-color-surface-container-highest);
  --md-menu-container-shape: var(--md-sys-shape-corner-md, 12px);
  --md-menu-container-elevation: 2;
  --md-menu-container-shadow-color: var(--ct-dropdown-shadow-color, rgba(0, 0, 0, 0.25));
}

md-menu::part(elevation) {
  box-shadow: var(--ct-dropdown-shadow, 0 8px 24px -4px rgba(0, 0, 0, 0.25), 0 2px 6px -1px rgba(0, 0, 0, 0.12));
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--md-menu-container-shape, 12px);
}

md-menu::part(items),
md-menu .items {
  background-color: var(--md-menu-container-color, var(--md-sys-color-surface-container-highest));
  border-radius: inherit;
}

md-menu-item,
md-select-option {
  --md-menu-item-container-color: transparent;
  --md-menu-item-hover-state-layer-color: var(--md-sys-color-on-surface);
  --md-menu-item-hover-state-layer-opacity: 0.08;
  --md-menu-item-selected-container-color: var(--md-sys-color-secondary-container);
  --md-menu-item-selected-label-text-color: var(--md-sys-color-on-secondary-container);
  border-radius: var(--md-sys-shape-corner-sm, 8px);
  margin: 2px 6px;
  box-sizing: border-box;
}

md-menu-item:first-of-type,
md-select-option:first-of-type {
  margin-top: 4px;
}

md-menu-item:last-of-type,
md-select-option:last-of-type {
  margin-bottom: 4px;
}

/* ==================================================================
   Dropdown Menu Search Field (<md-menu> search bar)
   M3 Expressive Pill with leading search icon, clear button, & focus states
   ================================================================== */
.ct-menu-search-wrapper {
  position: sticky;
  top: 0;
  z-index: 10;
  background-color: var(--md-menu-container-color, var(--md-sys-color-surface-container-highest));
  padding: 8px 10px 8px 10px;
  border-bottom: 1px solid var(--md-sys-color-outline-variant);
  box-sizing: border-box;
}

.ct-menu-search-inner {
  display: flex;
  align-items: center;
  position: relative;
  width: 100%;
  height: 36px;
  box-sizing: border-box;
  border-radius: var(--search-radius, 9999px);
  background-color: var(--md-sys-color-surface-container-high);
  border: 1px solid var(--md-sys-color-outline-variant);
  padding: 0 6px 0 10px;
  transition: border-color 0.2s ease, background-color 0.2s ease, box-shadow 0.2s ease;
}

.ct-menu-search-inner:focus-within {
  background-color: var(--md-sys-color-surface-container-highest);
  border-color: var(--md-sys-color-primary);
  box-shadow: 0 0 0 1px var(--md-sys-color-primary);
}

.ct-menu-search-icon {
  flex-shrink: 0;
  font-size: 18px;
  width: 18px;
  height: 18px;
  margin-right: 6px;
  color: var(--md-sys-color-on-surface-variant);
  pointer-events: none;
  user-select: none;
  transition: color 0.2s ease;
}

.ct-menu-search-inner:focus-within .ct-menu-search-icon {
  color: var(--md-sys-color-primary);
}

.ct-menu-search-input {
  flex: 1;
  min-width: 0;
  border: none;
  background: transparent;
  outline: none;
  font-family: var(--md-ref-typeface-brand, 'Plus Jakarta Sans', system-ui, sans-serif);
  font-size: 13px;
  font-weight: 400;
  color: var(--md-sys-color-on-surface);
  line-height: 20px;
  padding: 0;
  box-sizing: border-box;
}

.ct-menu-search-input::placeholder {
  color: var(--md-sys-color-outline);
  opacity: 1;
}

.ct-menu-search-clear {
  flex-shrink: 0;
  display: none;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--md-sys-color-on-surface-variant);
  cursor: pointer;
  padding: 0;
  margin-left: 4px;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.ct-menu-search-clear:hover {
  background-color: rgba(128, 128, 128, 0.15);
  color: var(--md-sys-color-on-surface);
}

.ct-menu-search-clear md-icon {
  font-size: 16px;
  width: 16px;
  height: 16px;
  pointer-events: none;
}

.ct-menu-search-clear.visible {
  display: inline-flex;
}

.ct-menu-empty-message {
  padding: 12px 16px;
  font-size: 13px;
  color: var(--md-sys-color-outline);
  text-align: center;
  font-style: italic;
  user-select: none;
}

/* ==================================================================
   Padding & Spacing Utility Classes
   ================================================================== */
.padding { padding: var(--card-padding, 16px); }
.padding-top { padding-top: var(--card-padding, 16px); }
.padding-bottom { padding-bottom: var(--card-padding, 16px); }
.padding-left { padding-left: var(--card-padding, 16px); }
.padding-right { padding-right: var(--card-padding, 16px); }

.margin { margin: var(--card-padding, 16px); }
.margin-top { margin-top: var(--card-padding, 16px); }
.margin-bottom { margin-bottom: var(--card-padding, 16px); }
.margin-left { margin-left: var(--card-padding, 16px); }
.margin-right { margin-right: var(--card-padding, 16px); }

.grid-container {
  display: flex;
  flex-wrap: wrap;
  gap: var(--pane-gap, 16px);
  box-sizing: border-box;
}

.grid-item {
  box-sizing: border-box;
}

.width-100 { width: 100%; }
.width-90 { width: calc(90% - 6px); }
.width-80 { width: calc(80% - 6px); }
.width-75 { width: calc(75% - 6px); }
.width-70 { width: calc(70% - 6px); }
.width-66 { width: calc(66.666% - 6px); }
.width-60 { width: calc(60% - 6px); }
.width-50 { width: calc(50% - 8px); }
.width-40 { width: calc(40% - 6px); }
.width-33 { width: calc(33.333% - 8px); }
.width-25 { width: calc(25% - 9px); }
.width-20 { width: calc(20% - 10px); }

@media screen and (max-width: 1024px) {
  .width-33, .width-25 {
    width: calc(50% - 8px);
  }
}

@media screen and (max-width: 599px) {
  .width-90, .width-80, .width-75, .width-70,
  .width-66, .width-60, .width-50, .width-40,
  .width-33, .width-25, .width-20 {
    width: 100% !important;
  }
}
