/*
 * Hotfix 2026-04-22
 * Scope: mobile/tablet layout fixes for footer CTA, floating actions,
 * important notice visibility, and YouTube card sizing.
 */

@media (max-width: 1279px) {
  /* ① Footer reservation links: keep side-by-side on phone/tablet. */
  .footer-reservation-banner {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: clamp(0.5rem, 2.8vw, 0.875rem);
    padding: clamp(0.625rem, 3vw, 1rem);
  }

  .footer-reservation-banner__link {
    min-block-size: 2.75rem;
    padding: 0.625rem 0.5rem;
    gap: 0.375rem;
    font-size: clamp(0.75rem, 2.8vw, 0.9rem);
    line-height: 1.3;
    text-align: center;
    white-space: nowrap;
  }

  .footer-reservation-banner__link .material-symbols-outlined {
    font-size: 1.125rem;
  }

  /* ② Avoid overlap with bottom fixed nav by hiding duplicate floating CTAs. */
  .c-fab-ai,
  .c-floating-cta,
  .footer-pagetop,
  .sp-fab {
    display: none !important;
  }

  /* ③ Header notice strip: prevent clipping behind surrounding UI. */
  .c-emergency-banner {
    padding-block: 0.5rem;
    padding-inline: clamp(0.625rem, 2.8vw, 0.9rem);
  }

  .c-emergency-banner__inner {
    grid-template-columns: auto minmax(0, 1fr) auto;
    gap: 0.375rem;
  }

  .c-emergency-banner__title,
  .c-emergency-banner__text {
    overflow: visible;
    text-overflow: clip;
    white-space: normal;
    word-break: break-word;
  }

  .sz-hero-v2__important {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: center;
    column-gap: clamp(0.4rem, 2vw, 0.75rem);
    padding-inline: clamp(0.5rem, 2.5vw, 0.9rem);
  }

  .sz-hero-v2__important-body {
    min-width: 0;
    padding: 0.375rem 0;
  }

  .sz-hero-v2__important-text {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .sz-hero-v2__important-nav {
    margin-inline-end: 0;
  }

  /* ④ YouTube cards: smaller side-by-side cards on phone/tablet. */
  .sz-youtube__grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: clamp(0.625rem, 2.8vw, 0.9rem);
    overflow: visible;
    padding-block-end: 0;
    scroll-snap-type: none;
  }

  .sz-youtube__item {
    flex: initial;
    min-width: 0;
    border-radius: 0.875rem;
  }

  .sz-youtube__caption {
    padding: 0.5rem 0.625rem 0.625rem;
    font-size: clamp(0.75rem, 2.6vw, 0.875rem);
    line-height: 1.4;
  }

  .sz-youtube-modal__dialog {
    width: min(100%, 960px);
    max-height: min(82vh, 700px);
  }
}

@media (max-width: 359px) {
  /* Keep side-by-side intent even on narrow devices by shrinking text. */
  .footer-reservation-banner__link {
    font-size: 0.75rem;
    letter-spacing: -0.01em;
  }

  .sz-youtube__caption {
    font-size: 0.75rem;
  }
}

/* ============================================================
 * Extended fixes (phase 2) — 2026-04-22
 * ============================================================ */

/* A) SP header: keep hospital name on a single line with ellipsis so
 *    the notice / hero stack below never gets compressed. */
@media (max-width: 767px) {
  .sz-header__mobile-inner {
    column-gap: clamp(0.25rem, 1.5vw, 0.5rem);
  }

  .sz-header__mobile-logo {
    min-width: 0;
    flex: 1 1 auto;
  }

  .sz-header__mobile-logo-img {
    flex-shrink: 0;
  }

  .sz-header__mobile-logo-name {
    min-width: 0;
    flex: 1 1 auto;
    font-size: clamp(0.7rem, 3vw, 0.95rem);
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .sz-header__mobile-tel,
  .sz-header__hamburger {
    flex-shrink: 0;
  }
}

/* B) Tablet: let the schedule panel flow below the hero instead of
 *    floating over the important-notice bar. */
@media (min-width: 768px) and (max-width: 1023px) {
  .sz-hero-v2__slider {
    height: auto;
  }

  .sz-hero-v2__schedule {
    position: static;
    inset: auto;
    width: 100%;
    max-width: none;
    margin-block-start: clamp(0.75rem, 2vw, 1.25rem);
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.08);
  }

  .sz-hero-v2__important {
    margin-block-start: clamp(0.5rem, 2vw, 1rem);
  }
}

/* C) PWA install banner: guarantee clearance above the bottom nav bar
 *    even on devices with large safe-area insets. */
@media (max-width: 1023px) {
  .c-pwa-banner:not(.c-pwa-banner--update) {
    bottom: calc(env(safe-area-inset-bottom, 0px) + 3.75rem);
  }
}

/* D) YouTube modal: larger touch target for the close button and
 *    prevent iOS rubber-band from scrolling the page behind. */
.sz-youtube-modal {
  overscroll-behavior: contain;
}

.sz-youtube-modal__close {
  min-inline-size: 44px;
  min-block-size: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.sz-youtube__thumb {
  min-block-size: 44px;
}

/* E) Body bottom padding: zero-out on desktop where the mobile bottom
 *    bar is hidden, and keep safe-area inclusive spacing on mobile. */
@media (max-width: 1023px) {
  body {
    padding-block-end: calc(3.5rem + env(safe-area-inset-bottom, 0px));
  }
}

@media (min-width: 1024px) {
  body {
    padding-block-end: 0;
  }
}

/* F) Header logo image: ensure non-square custom logos are not stretched. */
.sz-header__mobile-logo-img,
.sz-header__logo-img {
  object-fit: contain;
  object-position: center;
}

/* G) Stacking: keep bottom bar above the install banner so the user can
 *    always access primary navigation. */
.c-bottom-bar {
  z-index: 1001;
}

.c-pwa-banner {
  z-index: 1000;
}

/* H) Emergency banner sits BEFORE <main> in the DOM so the fixed header
 *    overlaps it. Push it below the header height to keep the whole
 *    notice visible on every viewport. */
.c-emergency-banner-container {
  margin-block-start: 3.5rem !important;
  position: relative;
  z-index: 40;
}

@media (min-width: 1280px) {
  .c-emergency-banner-container {
    margin-block-start: 6.125rem !important;
  }
}

/* I) 全ページ共通: 自動生成ページ内アンカー */
.c-page-anchor-nav {
  margin: clamp(0.6rem, 2.6vw, 1rem) auto clamp(0.8rem, 3vw, 1.2rem);
  max-width: min(1100px, calc(100% - 1.5rem));
  padding: 0.2rem;
  border: 1px solid #e2e8f0;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.9);
  box-shadow: 0 4px 14px rgba(15, 23, 42, 0.06);
}

.c-page-anchor-nav__list {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  overflow-x: auto;
  scrollbar-width: thin;
  padding: 0.2rem;
}

.c-page-anchor-nav__link {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.4rem 0.85rem;
  border-radius: 999px;
  background: #eff6ff;
  color: #0f3f8a;
  text-decoration: none;
  font-size: clamp(0.73rem, 2.2vw, 0.86rem);
  font-weight: 700;
  line-height: 1.2;
  transition: transform 0.18s ease, box-shadow 0.18s ease, background 0.18s ease;
}

.c-page-anchor-nav__link:hover,
.c-page-anchor-nav__link:focus-visible {
  background: #dbeafe;
  transform: translateY(-1px);
  box-shadow: 0 3px 10px rgba(30, 64, 175, 0.18);
}

@media (max-width: 767px) {
  .c-page-anchor-nav {
    max-width: calc(100% - 1rem);
    border-radius: 14px;
    margin-block: 0.65rem 0.95rem;
  }

  .c-page-anchor-nav__link {
    padding: 0.38rem 0.7rem;
    font-size: 0.76rem;
  }
}

/* J) フッター崩れ修正: 全サイズで情報ブロックを安全配置 */
@media (max-width: 1023px) {
  .footer-main__in {
    display: grid;
    grid-template-columns: 1fr;
    gap: clamp(1rem, 4vw, 1.4rem);
    justify-items: stretch;
  }

  .footer-info {
    inline-size: 100%;
    align-items: center;
    text-align: center;
  }

  .footer-logo,
  .footer-logo-text {
    inline-size: 100%;
    justify-content: center;
  }

  .footer-logo-text__ja {
    white-space: normal;
    text-wrap: balance;
    line-height: 1.35;
  }

  .footer-logo-text__en {
    max-inline-size: 44ch;
    text-wrap: balance;
    word-break: break-word;
  }

  .footer-tel__number {
    font-size: clamp(1.25rem, 6vw, 1.8rem);
    line-height: 1.1;
  }

  .footer-address {
    justify-content: center;
  }

  .footer-side {
    inline-size: 100%;
    align-items: stretch;
  }

  .footer-sns {
    justify-content: center;
    flex-wrap: wrap;
  }

  .footer-banner--recruit,
  .footer-reservation-banner {
    inline-size: 100%;
    max-inline-size: 100%;
  }

  .footer-reservation-banner__link {
    white-space: normal;
    line-height: 1.35;
    text-align: center;
  }
}

@media (max-width: 479px) {
  .footer-reservation-banner {
    grid-template-columns: 1fr;
  }

  .footer-address {
    flex-direction: column;
    align-items: center;
    text-align: center;
  }

  .footer-address__icon {
    margin-top: 0;
  }
}

/* K) FAB文言はみ出し修正（デスクトップ表示時） */
@media (min-width: 1280px) {
  .c-fab-ai {
    width: 64px;
    height: 64px;
    gap: 1px;
  }

  .c-fab-ai__icon {
    font-size: 1.4rem;
  }

  .c-fab-ai__label {
    font-size: 0.55rem;
    line-height: 1.05;
    letter-spacing: -0.02em;
    max-inline-size: 100%;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
}

/* L) 表組みの左寄せ統一（見出し・本文・caption） */
#main-content table caption,
#main-content table th,
#main-content table td,
#main-content .sakura-table caption,
#main-content .sakura-table th,
#main-content .sakura-table td,
#main-content .schedule-table th,
#main-content .schedule-table td,
#main-content .schedule-table--specialized th,
#main-content .schedule-table--specialized td,
#main-content .sz-hours-table th,
#main-content .sz-hours-table td,
#main-content .sz-simple-table th,
#main-content .sz-simple-table td,
#main-content .sz-schedule-table th,
#main-content .sz-schedule-table td,
#main-content .sz-fee-table th,
#main-content .sz-fee-table td,
#main-content .sz-dept-schedule__table th,
#main-content .sz-dept-schedule__table td,
#main-content .gobyou-schedule__table th,
#main-content .gobyou-schedule__table td,
#main-content .dept-table-modern th,
#main-content .dept-table-modern td,
#main-content .access-hours-table th,
#main-content .access-hours-table td {
  text-align: left !important;
  vertical-align: top;
}

#main-content table caption,
#main-content .sakura-table caption {
  color: var(--color-text-sub);
  font-weight: 600;
  padding-bottom: 0.5rem;
}

/* M) 全体トーン微調整（木古内町サイト準拠の落ち着いた質感） */
:root {
  --kiko-calm-border: #d8d6d1;
  --kiko-calm-shadow: 0 2px 10px rgba(26, 43, 63, 0.06);
  --kiko-calm-shadow-hover: 0 6px 18px rgba(26, 43, 63, 0.1);
  --kiko-calm-tint: #f3f6fa;
}

#main-content .sakura-content-box,
#main-content .sakura-contact-box,
#main-content .sakura-info-box,
#main-content .sakura-intro-box,
#main-content .sakura-note-box,
#main-content .sakura-related-card,
#main-content .c-card,
#main-content .dept-table-modern,
#main-content .sakura-table-wrapper,
#main-content .access-map-section,
#main-content .sakura-section {
  border-color: var(--kiko-calm-border);
}

#main-content .sakura-content-box,
#main-content .sakura-contact-box,
#main-content .sakura-related-card,
#main-content .c-card,
#main-content .dept-table-modern,
#main-content .sakura-table-wrapper {
  box-shadow: var(--kiko-calm-shadow);
}

#main-content .sakura-related-card,
#main-content .c-card,
#main-content .sakura-table-wrapper {
  background: var(--color-surface);
}

#main-content .c-button,
#main-content .sakura-btn {
  border-radius: 10px;
  letter-spacing: 0.01em;
  box-shadow: 0 1px 3px rgba(26, 43, 63, 0.08);
}

#main-content .c-button:hover,
#main-content .sakura-btn:hover {
  box-shadow: var(--kiko-calm-shadow-hover);
}

#main-content .c-button--secondary,
#main-content .sakura-btn--white,
#main-content .sakura-btn--ghost {
  background: var(--kiko-calm-tint);
}
