/* ==========================================================================
   CCB Directory — Style System (Rebuilt, with contrast tweaks)
   Palettes provided by you:
   Light: #FFEBD2 #FFA364 #FC7643 #AF4F41 #273248
   Dark:  #1A2730 #424048 #45586C #B0CEE2 #A63E1B #E95D2C
   Notes:
   - #B0CEE2 corrects the typo "#BOCEE2".
   - Default = dark theme (data-theme unset or "dark") to match existing UX.
   - System theme = blended tokens under :root:not([data-theme]).
   - 2025-08-24 updates:
     • Increased light-theme link contrast for `.linklike` (AA compliant).
     • Made dark-theme expanded cards clearly distinct from collapsed.
     • NEW: Telephone-only hover color for `.badge[href^="tel:"]` without affecting contact-name links.
   ========================================================================== */

/* ===== Base tokens (DARK default) ======================================= */
:root {
  /* Typography & layout */
  --font-family: "Roboto", Arial, sans-serif;
  --radius: 16px;
  --gap: 14px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);

  /* Core colors (Dark) */
  --bg: #1a2730; /* deep blue-charcoal */
  --surface: #223041; /* card/surfaces – derived between #1A2730 and #273248 */
  --surface-2: #273248; /* elevated surface */
  --controls-bg: #06436a; /* controls panel */
  --results-bg: #327eb1; /* banner / results label bg */
  --text: #b0cee2; /* primary text on dark */
  --text-inverse: #1a2730; /* text on light chips */
  --muted: #a9bdcc; /* secondary text on dark */
  --danger: #a63e1b; /* danger (dark palette) */
  --accent: #e95d2c; /* primary accent */
  --accent-2: #a63e1b; /* deep accent */
  --ring: #b0cee2; /* focus ring on dark */
  --clear-x: #b0cee2; /* clear-search hover */

  /* Badges & chips */
  --badge-bg: #1f2a3a;
  --badge-border: #2a3646;
  --badge-text: var(--text);

  /* Cards */
  --card: var(--surface);
  --card-border: rgba(176, 206, 226, 0.1);

  /* CTA buttons */
  --cta-bg: var(--accent);
  --cta-border: rgba(233, 93, 44, 0.35);
  --cta-text: #fff;
  --cta-hover-bg: #af4f41;
  --cta-active-bg: #ff8d5e; /* active/pressed */

  /* Accordions (details.card) */
  --card-collapsed-bg: var(--surface);
  --card-expanded-bg: #32465e; /* clearer distinction on dark */
  --summary-hover-bg: rgba(255, 255, 255, 0.06);

  /* Banners */
  --results-txt: #fff;

  /* Feedback */
  --error-bg: var(--danger);
  --error-txt: #fff;

  /* NEW: Telephone badge hover color (defaults for dark/system-dark) */
  --tel-hover-color: #e95d2c; /* matches dark accent for clear affordance */
}

/* Explicit dark-theme attribute support (same defaults, keep expanded contrast) */
:root[data-theme="dark"] {
  --bg: #1a2730;
  --surface: #223041;
  --surface-2: #273248;
  --controls-bg: #06436a;
  --results-bg: #327eb1;
  --text: #b0cee2;
  --text-inverse: #1a2730;
  --muted: #a9bdcc;
  --danger: #a63e1b;
  --accent: #e95d2c;
  --accent-2: #a63e1b;
  --ring: #b0cee2;
  --clear-x: #b0cee2;

  --badge-bg: #1f2a3a;
  --badge-border: #2a3646;
  --badge-text: var(--text);

  --card: var(--surface);
  --card-border: rgba(176, 206, 226, 0.1);

  --cta-bg: var(--accent);
  --cta-border: rgba(233, 93, 44, 0.35);
  --cta-text: #fff;
  --cta-hover-bg: #af4f41;
  --cta-active-bg: #ff8d5e;

  --card-collapsed-bg: var(--surface);
  --card-expanded-bg: #32465e;
  --summary-hover-bg: rgba(255, 255, 255, 0.06);

  --results-txt: #fff;
  --error-bg: var(--danger);
  --error-txt: #fff;

  /* Telephone hover color remains the same on explicit dark */
  --tel-hover-color: #e95d2c;
}

/* ===== Light theme overrides =========================================== */
:root[data-theme="light"] {
  --bg: #ffebd2; /* warm peach */
  --surface: #ffffff; /* clean paper */
  --surface-2: #ffebd2; /* subtle elevation */
  --controls-bg: #ffa364; /* warm control band */
  --results-bg: #fc7643; /* strong label background */
  --text: #273248; /* navy text */
  --text-inverse: #ffffff; /* on saturated chips */
  --muted: #4a556e; /* supportive copy */
  --danger: #af4f41; /* light-palette danger */
  --accent: #fc7643; /* primary accent */
  --accent-2: #af4f41; /* deep accent */
  --ring: #273248; /* strong focus for accessibility */
  --clear-x: #af4f41;

  --badge-bg: #fff4e8; /* soft chip */
  --badge-border: #ffd6b8;

  --card: var(--surface);
  --card-border: rgba(39, 50, 72, 0.1);

  --cta-bg: var(--accent);
  --cta-border: rgba(252, 118, 67, 0.35);
  --cta-text: #ffffff;
  --cta-hover-bg: #af4f41; /* lighter hover */
  --cta-active-bg: #ffb589; /* pressed */

  --card-collapsed-bg: var(--surface);
  --card-expanded-bg: #ffe0c3; /* distinct from collapsed on light */
  --summary-hover-bg: rgba(0, 0, 0, 0.04);

  --results-txt: #ffffff;
  --error-bg: var(--danger);
  --error-txt: #ffffff;

  /* NEW: stronger, AA-friendly telephone hover color on light */
  --tel-hover-color: #af4f41;
}

/* ===== System (follow user preference, with blended accents) ============ */
@media (prefers-color-scheme: light) {
  :root:not([data-theme]) {
    /* Start from light tokens and blend accents with dark’s vibrancy */
    --bg: #fff1e1; /* blend of #FFEBD2 + white */
    --surface: #ffffff;
    --surface-2: #ffe5cc;
    --controls-bg: #ffaa75; /* in-between #FFA364 and white */
    --results-bg: #ff8856; /* blend of #FC7643 and #E95D2C */
    --text: #273248;
    --text-inverse: #ffffff;
    --muted: #56627a;
    --danger: #b24c33; /* between #AF4F41 and #A63E1B */
    --accent: #f1703e; /* blend of #FC7643 + #E95D2C */
    --accent-2: #af4f41;
    --ring: #273248;
    --clear-x: #af4f41;

    --badge-bg: #fff4e8;
    --badge-border: #ffd8bd;

    --cta-bg: var(--accent);
    --cta-border: rgba(241, 112, 62, 0.35);
    --cta-text: #ffffff;
    --cta-hover-bg: #af4f41;
    --cta-active-bg: #ffb089;

    --card-collapsed-bg: var(--surface);
    --card-expanded-bg: #ffe3c9; /* system-light expanded */
    --summary-hover-bg: rgba(0, 0, 0, 0.04);

    --results-txt: #ffffff;
    --error-bg: var(--danger);
    --error-txt: #ffffff;

    /* System-light telephone hover */
    --tel-hover-color: #af4f41;
  }
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    /* Start from dark tokens with slightly softer text */
    --bg: #1a2730;
    --surface: #223041;
    --surface-2: #273248;
    --controls-bg: #06436a; /* slightly softer than #424048 */
    --results-bg: #327eb1;
    --text: #c8d9e6; /* softening of #B0CEE2 */
    --text-inverse: #0f1a22;
    --muted: #a9bdcc;
    --danger: #a63e1b;
    --accent: #e95d2c;
    --accent-2: #a63e1b;
    --ring: #b0cee2;
    --clear-x: #c8d9e6;

    --badge-bg: #203046;
    --badge-border: #2a3a50;

    --cta-bg: var(--accent);
    --cta-border: rgba(233, 93, 44, 0.35);
    --cta-text: #ffffff;
    --cta-hover-bg: #ff7a42;
    --cta-active-bg: #ff8d5e;

    --card-collapsed-bg: var(--surface);
    --card-expanded-bg: #32465e; /* clearer than collapsed */
    --summary-hover-bg: rgba(255, 255, 255, 0.06);

    --results-txt: #ffffff;
    --error-bg: var(--danger);
    --error-txt: #ffffff;

    /* System-dark telephone hover */
    --tel-hover-color: #e95d2c;
  }
}

/* ===== Resets & structural ================================================== */
* {
  box-sizing: border-box;
}
html {
  -webkit-text-size-adjust: 100%;
}
html,
body {
  font-family: var(--font-family);
  height: 100%;
}

body {
  background: radial-gradient(
      1200px 600px at 80% -20%,
      rgba(69, 88, 108, 0.25) 0%,
      transparent 60%
    ),
    var(--bg);
  color: var(--text);
}
:root[data-theme="light"] body,
:root:not([data-theme]) body {
  background: var(--bg); /* remove dark radial on light/system light */
}

/* ===== Header & theme toggle ============================================== */
.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 24px;
}

.header {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 20px;
  align-items: center;
  margin-bottom: 15px;
}

.logo-image {
  width: 100px;
  height: 100px;
  object-fit: cover;
  image-rendering: optimizeQuality;
}

.header-title {
  margin: 0;
}
.ccb {
  font-size: 2rem;
  color: var(--muted);
}
.heading {
  font-size: 3.4rem;
  font-weight: 700;
}

.theme-toggle {
  margin-left: auto;
  border: 1px solid var(--card-border);
  background: var(--surface-2);
  color: var(--text);
  border-radius: 999px;
  padding: 8px 12px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  box-shadow: var(--shadow);
  min-width: 92px;
}
.theme-toggle:hover,
.theme-toggle:focus-visible {
  outline: none;
  filter: brightness(1.05);
}
.theme-toggle-icon {
  font-size: 18px;
}
.theme-toggle-text {
  font-size: 14px;
}

/* ===== Filters & controls ================================================== */
.controls {
  background: var(--controls-bg);
  padding: 16px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.filters-grid {
  display: grid;
  grid-template-columns: 1fr 220px 220px;
  gap: var(--gap);
}
@media (max-width: 840px) {
  .filters-grid {
    grid-template-columns: 1fr;
  }
}

#filters-title {
  font-size: 1.75rem;
  margin-top: 10px;
}

.label {
  display: block;
  font-size: 1.2rem;
  margin-bottom: 5px;
  color: var(--text);
  opacity: 0.85;
}

.input-wrapper {
  position: relative;
}

#search {
  width: 100%;
  padding: 12px 40px 12px 12px;
  border-radius: 12px;
  border: 1px solid var(--card-border);
  background: var(--surface);
  color: var(--text);
  font-size: 1.1rem;
}
#search::placeholder {
  color: var(--muted);
}

#clear-search {
  position: absolute;
  right: 8px;
  top: 70%;
  transform: translateY(-50%);
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 25px;
  cursor: pointer;
}
#clear-search:hover {
  color: var(--clear-x);
}

/* Selects (custom chevron) */
.select-wrapper {
  position: relative;
  color: var(--muted);
}
.select-wrapper select {
  width: 100%;
  padding: 12px;
  height: 48px;
  border-radius: 12px;
  border: 1px solid var(--card-border);
  background: var(--surface);
  color: var(--text);
  font-size: 16px;
  line-height: 1.5;
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  padding-right: 44px;
}
.select-wrapper::after {
  content: "";
  position: absolute;
  right: 12px;
  top: 70%;
  transform: translateY(-50%);
  width: 20px;
  height: 20px;
  pointer-events: none;
  background-color: currentColor;
  -webkit-mask-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><polyline points="6 9 12 15 18 9" fill="none" stroke="%23000" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></svg>');
  mask-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><polyline points="6 9 12 15 18 9" fill="none" stroke="%23000" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></svg>');
  -webkit-mask-repeat: no-repeat;
  mask-repeat: no-repeat;
  -webkit-mask-size: contain;
  mask-size: contain;
}
.select-wrapper:hover,
.select-wrapper:focus-within {
  color: var(--accent);
}
.select-wrapper select:focus-visible {
  outline: 2px solid var(--ring);
  outline-offset: 2px;
}

/* Meta row */
.meta-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 6px 8px;
  align-items: center;
  margin-top: 18px;
  color: var(--badge-text);
}
.linklike {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--accent);
  text-decoration: underline;
  font-size: 1rem;
  padding: 0;
  font-family: var(--font-family);
}

/* ===== Results banner ====================================================== */
.results {
  margin-top: 24px;
}
#results-title {
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--results-txt);
  background-color: var(--results-bg);
  border-radius: 10px;
  padding: 8px 12px;
}

/* ===== Cards / Accordion =================================================== */
.cards {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

.card {
  background: var(--card-collapsed-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  border: 1px solid var(--card-border);
}
.card[open] {
  background: var(--card-expanded-bg); /* distinct expanded state */
  border-color: rgba(233, 93, 44, 0.35); /* accent-tinted rim */
}

.card summary {
  list-style: none;
  cursor: pointer;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  border-radius: var(--radius) var(--radius) 0 0;
  transition:
    background-color 0.2s ease,
    color 0.2s ease;
}
.card summary:hover,
.card summary:focus-visible {
  background-color: var(--summary-hover-bg);
}
.card summary:hover .title,
.card summary:focus-visible .title {
  color: var(--accent);
}

.summary-main {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.summary-sub {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  font-size: 14px;
}

.card summary::-webkit-details-marker {
  display: none;
}

.card summary .title {
  font-weight: 700;
  font-size: 28px;
  margin-bottom: 8px;
  color: var(--text);
}

.card summary .chev {
  display: flex;
  align-items: center;
  justify-content: center;
  transition:
    transform 0.2s ease,
    color 0.2s ease;
  color: var(--muted);
}
.card[open] summary .chev {
  transform: rotate(180deg);
  color: var(--accent);
}

.chev-icon {
  width: 24px;
  height: 24px;
}

.card .body {
  padding: 0 16px 16px 16px;
  color: var(--text);
  opacity: 0.92;
}

.card .card-footer-ts {
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px solid var(--card-border);
  font-size: 12px;
  color: var(--muted);
  opacity: 0.9;
}

/* Badges */
.meta {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}
.badge {
  display: inline-flex;
  align-items: center;
  line-height: 1.2;
  vertical-align: middle;
  background: var(--badge-bg);
  color: var(--badge-text);
  padding: 4px 8px;
  border-radius: 999px;
  font-size: 1rem;
  border: 1px solid var(--badge-border);
  text-decoration: none;
  white-space: nowrap;
}
.badge:hover {
  filter: brightness(1.06);
}
.badge .emoji {
  display: inline-block;
  line-height: 1;
  margin: 0 5px;
  vertical-align: middle;
}

/* Make the address take a full row in the .meta flex container */
.badge-address {
  min-width: 0;
  /* Force line break for following badges (category, city) */
  flex: 0 0 100%;
  width: 100%;

  /* Remove the pill styling from the outer shell to avoid a stretched capsule */
  background: transparent;
  border: 0;
  padding: 0;

  /* Align the inner chip to the start of the row */
  display: flex;
  align-items: center;
  justify-content: flex-start;
}

/* The actual pill, sized to its content */
.badge-address .badge-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 4px 8px;
  border-radius: 999px;

  /* Reapply the standard badge visuals to the chip */
  background: var(--badge-bg);
  color: var(--badge-text);
  border: 1px solid var(--badge-border);
  width: max-content; /* your request */
  max-width: 100%;
  white-space: normal; /* was: nowrap */
  overflow-wrap: anywhere; /* break long tokens without spaces */
  word-break: break-word; /* legacy fallback */
}

a.badge-address:hover .badge-chip,
a.badge-address:focus-visible .badge-chip {
  filter: brightness(1.06);
  color: var(--tel-hover-color);
  border: 3px solid var(--accent);
  text-decoration: underline;
}

/* Sponsor medal emoji next to title */
.sponsor-medal {
  margin-left: 6px;
  font-size: 0.95em;
  line-height: 1;
  vertical-align: middle;
}

/* ===== CTA Buttons (actions) ============================================== */
.actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 8px;
}
.actions-left {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 8px;
}
.actions-right {
  margin-left: auto;
  font-size: 12px;
  color: var(--muted);
  opacity: 0.9;
  padding-top: 8px;
}

/* Primary CTA */
.actions-left a,
.actions-left button {
  display: inline-block;
  margin-top: 8px;
  text-decoration: none;
  padding: 10px 14px;
  border-radius: 12px;
  border: 1px solid var(--cta-border);
  background: var(--cta-bg);
  color: var(--cta-text);
  font-weight: 600;
  transition:
    transform 0.04s ease,
    filter 0.15s ease,
    background-color 0.15s ease;
  will-change: transform, filter, background-color;
}
.actions-left a:hover,
.actions-left button:hover {
  background: var(--cta-hover-bg);
  filter: brightness(1.05);
  text-decoration: underline;
}
.actions-left a:active,
.actions-left button:active {
  background: var(--cta-active-bg);
  transform: translateY(1px);
}

/* Ghost-style secondary action (when needed) */
.actions-left .ghost,
.ghost {
  background: transparent;
  color: var(--text);
  border: 1px dashed var(--card-border);
}
.actions-left .ghost:hover,
.ghost:hover {
  background: rgba(0, 0, 0, 0.04);
}
:root[data-theme="dark"] .ghost:hover,
:root:not([data-theme]) .ghost:hover {
  background: rgba(255, 255, 255, 0.06);
}

/* ===== Empty & error states =============================================== */
.empty,
.error {
  margin-top: 16px;
  padding: 12px;
  border-radius: 12px;
  color: var(--error-txt);
}
.empty {
  background-color: var(--error-bg);
}
.error {
  background-color: #bd0b0b;
}

/* ===== Footer ============================================================= */
.footer {
  margin-top: 32px;
  color: var(--muted);
}
.footer-disclaimer {
  width: 100%;
  font-size: 1rem;
  line-height: 1.5;
  margin-bottom: 1em;
  color: var(--muted);
}
.footer-disclaimer p {
  text-align: justify;
  margin: 0;
}

.footer-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}
.footer-left,
.footer-right {
  font-size: 14px;
}
.footer-left {
  text-align: left;
}
.footer-right {
  text-align: right;
}
.footer-left small,
.footer-right small {
  display: block;
  text-align: right;
  margin-top: 4px;
  font-size: 12px;
  color: var(--muted);
}

/* ===== Mobile polish ====================================================== */
@media (max-width: 480px) {
  .header {
    display: grid;
    grid-template-columns: 1fr;
    grid-auto-rows: auto;
    gap: 10px;
    width: 100%;
    text-align: center;
  }
  .header .logo-image {
    justify-self: center;
    max-width: 160px;
    height: auto;
  }
  .header .header-title {
    margin: 0;
    justify-self: center;
  }
  .header .header-title .ccb {
    font-size: 1.4rem;
  }
  .header .header-title .heading {
    font-size: 1.8rem;
  }
  .footer-content {
    flex-direction: column;
  }
  .footer-content .footer-left,
  .footer-content .footer-right {
    text-align: center;
  }
  .header .theme-toggle {
    margin: 0 auto;
  }
  .label {
    font-size: 1rem;
  }
  .card summary .title {
    font-weight: 600;
    font-size: 22px;
  }
  .badge,
  .meta-row,
  .linklike {
    font-size: 0.9rem;
  }
  #search {
    font-size: 1rem;
  }
  .badge-address .badge-chip {
    /* keep padding/radius; just ensure no horizontal scroll */
    display: inline-block;
  }
}

/* ===== Accessibility & motion ============================================ */
:focus-visible {
  outline: 2px solid var(--ring);
  outline-offset: 2px;
}
@media (prefers-reduced-motion: reduce) {
  * {
    animation: none !important;
    transition: none !important;
  }
}

/* ===== Touch selects: prefer native ====================================== */
@media (hover: none) and (pointer: coarse) {
  .select-wrapper select {
    appearance: auto;
    -webkit-appearance: menulist;
    -moz-appearance: menulist;
    padding-right: 12px;
    font-size: 16px;
  }
  .select-wrapper::after {
    display: none;
  }
}

/* ===== CONTRAST TUNING (Light) =========================================== */
/* Ensure .linklike meets AA on light backgrounds without altering global --accent */
:root[data-theme="light"] .linklike {
  color: #af4f41; /* darker accent from light palette */
  text-decoration: underline;
}
:root[data-theme="light"] .linklike:hover {
  color: #fc7643; /* lighter orange on hover for affordance */
}

/* System light (no explicit data-theme) */
@media (prefers-color-scheme: light) {
  :root:not([data-theme]) .linklike {
    color: #af4f41;
    text-decoration: underline;
  }
  :root:not([data-theme]) .linklike:hover {
    color: #f1703e; /* blended accent hover */
  }
}

/* ===== TELEPHONE BADGE HOVER (DO NOT AFFECT CONTACT NAME LINKS) ========= */
/* Targets only anchors that are .badge and link to phone numbers */
a.badge[href^="tel:"]:hover,
a.badge[href^="tel:"]:focus-visible {
  color: var(--cta-text);
  filter: brightness(1.1);
  background-color: var(--tel-hover-color);
}
