/* Clinic Calendar Frontend Styles */

.clinic-calendar-container {
    font-family: -apple-system, BlinkMacSystemFont, 'Hiragino Sans', 'Yu Gothic', sans-serif;
    max-width: 100%;
    padding: 0;
    box-sizing: border-box;
    --cc-border-color: #dde1ea;
    container-type: inline-size;
}

.clinic-calendar-title {
    font-size: 1.4em;
    font-weight: 700;
    color: #1d2327;
    margin-bottom: 12px;
}

.clinic-calendar-months {
    display: flex;
    gap: 10px;
    /* PC・タブレット：2列固定、折り返しなし */
    flex-wrap: nowrap;
    align-items: flex-start;
}

.clinic-calendar-nav {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
    border: 1px solid #c3c4c7;
    border-radius: 50%;
    background: #fff;
    color: #1d2327;
    font-size: 21px;
    font-weight: 700;
    line-height: 1;
    text-decoration: none;
    box-shadow: 0 1px 2px rgba(0,0,0,0.08);
    box-sizing: border-box;
    flex: 0 0 26px;
}

.clinic-calendar-nav:hover,
.clinic-calendar-nav:focus {
    border-color: #2271b1;
    color: #2271b1;
    text-decoration: none;
    outline: none;
}

.clinic-calendar-month-header {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 0;
    padding: 8px 10px;
    background: #fff;
    border: 1px solid var(--cc-border-color);
    border-bottom: none;
    border-radius: 0;
}

.clinic-calendar-nav-spacer {
    flex: 0 0 26px;
    width: 26px;
    height: 26px;
}

.clinic-calendar-month-title {
    flex: 1 1 auto;
    font-size: 1.1em;
    font-weight: 700;
    text-align: center;
    margin-bottom: 0;
    color: #1d2327;
    padding: 0;
    background: transparent;
    border-radius: 0;
}

.clinic-calendar-month {
    /* 等幅2列 */
    flex: 1 1 0;
    min-width: 0;
    background: #fff;
    border: none;
}

.clinic-cal-table {
    width: 100%;
    border-collapse: collapse;
    table-layout: fixed;
    background: #fff;
    border: none;
}

.clinic-cal-table th {
    text-align: center;
    padding: 6px 2px;
    font-size: 0.8em;
    font-weight: 700;
    background: #f6f7f7;
    border: 1px solid var(--cc-border-color);
    color: #333;
}

.clinic-cal-table th.sun { color: #c62828; }
.clinic-cal-table th.sat { color: #1565c0; }

.clinic-cal-table td {
    border: 1px solid var(--cc-border-color);
    padding: 0;
    vertical-align: top;
    /* テーブルセルにaspect-ratioが効かないブラウザ対策:
       widthは table-layout:fixed で自動均等分割される。
       セルの高さは .cc-cell の padding-top:100% で正方形を実現する */
}

.clinic-cal-table td.other-month {
    background: #f9f9f9;
    opacity: 0.4;
}

/* ======= セル基本 ======= */
.cc-cell {
    /* padding-top:100% で「幅＝高さ」の正方形を実現（table-cellでも確実に動作） */
    position: relative;
    width: 100%;
    padding-top: 100%;
    box-sizing: border-box;
    overflow: hidden;
}

/* 日付・テキストを内包するインナー（absoluteで正方形の中に配置） */
.cc-cell-inner {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

/* 単色セル */
.cc-cell.status-open {
    background-color: var(--cc-color-open, #eaf6eb);
}

.cc-cell.status-closed {
    background-color: var(--cc-color-closed, #ffebee);
}

/* ======= 斜め分割セル =======
   clip-path+absolute方式はtd内で高さ0になるバグあり。
   linear-gradientをcc-cell自体に直接かける方式に変更。
   斜め線はグラデーションの色変化点で表現。
*/

/* am_closed：左上=午前休診色 / 右下=午後診療色 */
.cc-cell.status-am_closed {
    background-image: linear-gradient(
        to bottom right,
        var(--cc-color-am-top,    #ffebee) calc(50% - 1px),
        rgba(255,255,255,0.9)      calc(50% - 1px),
        rgba(255,255,255,0.9)      calc(50% + 1px),
        var(--cc-color-am-bottom, #eaf6eb) calc(50% + 1px)
    );
}

/* pm_closed：左上=午前診療色 / 右下=午後休診色 */
.cc-cell.status-pm_closed {
    background-image: linear-gradient(
        to bottom right,
        var(--cc-color-pm-top,    #eaf6eb) calc(50% - 1px),
        rgba(255,255,255,0.9)      calc(50% - 1px),
        rgba(255,255,255,0.9)      calc(50% + 1px),
        var(--cc-color-pm-bottom, #ffebee) calc(50% + 1px)
    );
}

/* ======= 日付数字・テキスト ======= */
.cc-day-num {
    font-size: 0.9em;
    font-weight: 700;
    line-height: 1;
    z-index: 1;
    color: #1d2327;
    /* 親のflexによって上下左右中央に配置される */
}

.cc-day-text {
    text-align: center;
    font-size: 0.65em;
    font-weight: 600;
    z-index: 1;
    padding: 0 2px;
    margin-top: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
    color: #333;
}

/* ======= 凡例 ======= */
.clinic-calendar-legend {
    display: flex;
    gap: 10px 12px;
    flex-wrap: wrap;
    margin-top: 10px;
    padding: 10px;
    background: #fff;
    border: 1px solid var(--cc-border-color);
    border-radius: 0;
}

.cc-legend-item {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 0.75em;
    line-height: 1.2;
}

/* 単色スウォッチ */
.cc-legend-swatch {
    width: 18px;
    height: 18px;
    border-radius: 3px;
    border: 1px solid rgba(0,0,0,0.1);
    flex-shrink: 0;
}

/* 斜め分割スウォッチ（同じlinear-gradient方式） */
.cc-legend-swatch.diagonal {
    background-color: transparent;
}

/* ======= Skin: borderless minimal ======= */
.clinic-calendar-container.cc-skin-borderless .clinic-calendar-months {
    gap: 10px;
}

.clinic-calendar-container.cc-skin-borderless .clinic-calendar-month-header {
    padding: 8px 10px;
    margin-bottom: 0;
    background: #fff;
    border: none;
    border-bottom: 1px solid var(--cc-border-color);
    border-radius: 0;
}

.clinic-calendar-container.cc-skin-borderless .clinic-calendar-month {
    background: #fff;
    border: 1px solid var(--cc-border-color);
}

.clinic-calendar-container.cc-skin-borderless .clinic-calendar-nav {
    width: 30px;
    height: 30px;
    flex-basis: 30px;
    border-color: #e5e7eb;
    border-radius: 4px;
    color: #374151;
    font-size: 20px;
    box-shadow: 0 2px 7px rgba(0,0,0,0.08);
}

.clinic-calendar-container.cc-skin-borderless .clinic-calendar-nav-spacer {
    width: 30px;
    height: 30px;
    flex-basis: 30px;
}

.clinic-calendar-container.cc-skin-borderless .clinic-calendar-month-title {
    font-size: 1em;
}

.clinic-calendar-container.cc-skin-borderless .clinic-cal-table {
    border-collapse: separate;
    border-spacing: 4px;
}

.clinic-calendar-container.cc-skin-borderless .clinic-cal-table th {
    padding: 5px 2px 8px;
    border: none;
    background: transparent;
    color: #6b7280;
    font-size: 0.72em;
    font-weight: 600;
}

.clinic-calendar-container.cc-skin-borderless .clinic-cal-table th.sun {
    color: #c62828;
}

.clinic-calendar-container.cc-skin-borderless .clinic-cal-table th.sat {
    color: #1565c0;
}

.clinic-calendar-container.cc-skin-borderless .clinic-cal-table td {
    border: none;
    background: transparent;
}

.clinic-calendar-container.cc-skin-borderless .clinic-cal-table td.other-month {
    background: transparent;
    opacity: 1;
}

.clinic-calendar-container.cc-skin-borderless .cc-cell {
    border-radius: 8px;
}

.clinic-calendar-container.cc-skin-borderless .cc-day-num {
    font-size: 0.82em;
    font-weight: 600;
}

.clinic-calendar-container.cc-skin-borderless .clinic-calendar-legend {
    background: #fff;
    border: 1px solid var(--cc-border-color);
    padding: 10px;
    margin-top: 10px;
}

.clinic-calendar-container.is-loading {
    opacity: 0.65;
    pointer-events: none;
}

/* ======= レスポンシブ ======= */

/* タブレット（768px以下）：2列横並び維持・折り返しなし */
@media (max-width: 768px) {
    .clinic-calendar-months {
        flex-wrap: nowrap;
    }
    .clinic-calendar-month {
        flex: 1 1 0;
        min-width: 0;
    }
}

@container (max-width: 480px) {
    .clinic-calendar-months {
        flex-direction: column;
        flex-wrap: nowrap;
        min-width: 0;
    }

    .clinic-calendar-month {
        flex: 0 0 auto;
        width: 100%;
        min-width: 0;
    }
}

/* 狭いウィジェット・スマホ：2ヶ月表示は1列に折り返す */
@media (max-width: 480px) {
    .clinic-calendar-container {
        overflow-x: visible;
        padding: 0;
    }
    .clinic-calendar-nav {
        width: 22px;
        height: 22px;
        font-size: 18px;
        flex-basis: 22px;
    }
    .clinic-calendar-nav-spacer {
        flex-basis: 22px;
        width: 22px;
        height: 22px;
    }
    .clinic-calendar-container.cc-skin-borderless .clinic-calendar-nav,
    .clinic-calendar-container.cc-skin-borderless .clinic-calendar-nav-spacer {
        width: 24px;
        height: 24px;
        flex-basis: 24px;
    }
    .clinic-calendar-months {
        flex-direction: column;
        flex-wrap: nowrap;
        min-width: 0;
    }
    .clinic-calendar-month {
        flex: 0 0 auto;
        width: 100%;
        min-width: 0;
    }

    .clinic-calendar-month-header {
        gap: 4px;
        padding: 3px 4px;
    }

    .clinic-calendar-legend {
        gap: 8px 10px;
        padding: 8px;
    }

    .cc-legend-item {
        font-size: 0.7em;
    }

    .cc-legend-swatch {
        width: 16px;
        height: 16px;
    }

    .cc-cell-text-icon {
        right: 1px;
        bottom: 1px;
        width: 10px;
        height: 10px;
        font-size: 8px;
        box-shadow: none;
    }

}

/* ======= 任意テキスト アイコン（フロント） ======= */
.cc-cell-text-icon {
    position: absolute;
    right: 2px;
    bottom: 2px;
    z-index: 3;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--cc-text-icon-color, #2271b1);
    color: #fff;
    font-size: 9px;
    font-weight: 700;
    line-height: 1;
    letter-spacing: 0;
    box-sizing: border-box;
    pointer-events: none;
    box-shadow: 0 1px 2px rgba(0,0,0,0.18);
}

.cc-cell-text-icon::before {
    content: attr(data-icon);
}

.cc-cell.has-text {
    z-index: 2;
    cursor: pointer;
    outline: none;
}

.cc-cell.has-text:focus-visible {
    box-shadow: inset 0 0 0 2px #2271b1;
}

/* テキスト表示モーダル */
.cc-text-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 99999;
    display: flex;
    align-items: center;
    justify-content: center;
}
.cc-text-modal {
    background: #fff;
    border-radius: 8px;
    padding: 24px 28px;
    max-width: 320px;
    width: 90%;
    box-shadow: 0 8px 32px rgba(0,0,0,0.2);
    text-align: center;
    position: relative;
}
.cc-text-modal-date {
    font-size: 0.85em;
    color: #888;
    margin-bottom: 8px;
}
.cc-text-modal-body {
    font-size: 1.1em;
    font-weight: 700;
    color: #1d2327;
    margin-bottom: 16px;
    word-break: break-all;
}
.cc-text-modal-close {
    background: #f0f0f1;
    border: none;
    border-radius: 4px;
    padding: 6px 20px;
    cursor: pointer;
    font-size: 0.9em;
    color: #50575e;
}
.cc-text-modal-close:hover { background: #ddd; }
