/* サロン分析ウィジェット */
.salon-analytics-widget {
    max-width: 100%;
    max-height: calc(100vh - 120px); /* 画面高さからヘッダーとフッター分を引く */
    overflow-y: auto;  /* はみ出したらスクロール */
    margin: 5px 0;
    padding: 5px;
    background: #ffffff;
    border: 1px solid #e1e1e1;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    
    /* モバイルデバイス対応 */
    -webkit-overflow-scrolling: touch; /* iOS のスムーズスクロール */
}

/* モバイルデバイス用の高さ調整 */
@media (max-width: 768px) {
    .salon-analytics-widget {
        /* モバイルブラウザのアドレスバーとツールバーを考慮 */
        max-height: calc(100dvh - 100px); /* Dynamic Viewport Height を使用 */
        margin: 2px 0;
        padding: 3px;
        
        /* セーフエリア対応（iPhone X以降のノッチ対応） */
        padding-bottom: calc(5px + env(safe-area-inset-bottom));
        margin-bottom: calc(2px + env(safe-area-inset-bottom));
    }
}

/* PWA環境での特別対応 */
@media (display-mode: standalone) {
    .salon-analytics-widget {
        max-height: calc(100vh - 80px); /* PWAではツールバーがないため調整 */
        padding-bottom: calc(5px + env(safe-area-inset-bottom));
    }
}

/* iPhone SafariとiOS PWA用の追加対応 */
@supports (height: 100dvh) {
    @media (max-width: 768px) {
        .salon-analytics-widget {
            max-height: calc(100dvh - 100px);
        }
    }
    
    @media (display-mode: standalone) {
        .salon-analytics-widget {
            max-height: calc(100dvh - 60px);
        }
    }
}

/* Android Chrome用の対応 */
@media (max-width: 768px) and (min-resolution: 2dppx) {
    .salon-analytics-widget {
        max-height: calc(100vh - 120px);
        /* Androidの下部ナビゲーションバー対応 */
        margin-bottom: calc(5px + env(safe-area-inset-bottom, 10px));
    }
}

/* ヘッダー */
.salon-analytics-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
    padding-bottom: 5px;
    border-bottom: 2px solid #f0f0f0;
    flex-wrap: wrap;
    gap: 15px;
}
.salon-analytics-title{
    height: 50px;
}

.header-title {
    flex: 1 1 auto;
    min-width: 160px;
    max-width: 50%;
}

.salon-analytics-title {
    margin: 0;
    font-size: 1.2em;
    color: #2c3e50;
    font-weight: 600;
    line-height: 1.3;
    word-break: break-word;
}

.header-controls {
    flex: 0 1 auto;
    min-width: 280px;
    max-width: 50%;
}

/* コントロール */
.salon-analytics-controls {
    display: flex;
    justify-content: flex-start;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.date-selector {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: nowrap;
    justify-content: flex-end;
}

.year-select,
.month-select {
    padding: 6px 10px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 13px;
    background: white;
    min-width: 90px;
    max-width: 110px;
    flex-shrink: 1;
}

.year-select:focus,
.month-select:focus {
    outline: none;
    border-color: #3498db;
    box-shadow: 0 0 0 2px rgba(52, 152, 219, 0.2);
}

.salon-update-btn,
.salon-pdf-btn {
    padding: 6px 12px;
    background: #3498db;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 13px;
    transition: background-color 0.3s ease;
    white-space: nowrap;
    flex-shrink: 0;
    /* iOS対応のタッチ最適化 */
    -webkit-appearance: none;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    user-select: none;
    min-height: 44px; /* iOSタッチ推奨サイズ */
}

/* iOS PWA環境での特別スタイル */
@supports ((-webkit-backdrop-filter: blur(10px)) and (not (-webkit-touch-callout: none))) {
    .salon-pdf-btn {
        background: #27ae60; /* 共有ボタンは緑色 */
    }
}

/* iPad/iPhone での追加対応 */
@media (max-width: 768px) and (-webkit-min-device-pixel-ratio: 2) {
    .salon-pdf-btn {
        font-size: 14px;
        padding: 8px 14px;
        min-width: 100px;
    }
}

.salon-pdf-btn {
    background: #27ae60;
}

.salon-update-btn:hover {
    background: #2980b9;
}

.salon-pdf-btn:hover {
    background: #229954;
}

.salon-update-btn:active,
.salon-pdf-btn:active {
    transform: translateY(1px);
}

.salon-pdf-btn:disabled {
    background: #95a5a6;
    cursor: not-allowed;
    transform: none;
}

/* チャートコンテナ */
.chart-container {
    position: relative;
    margin: 20px 0;
    background: #fafafa;
    border-radius: 6px;
    padding: 15px;
    min-height: 350px;
}

.chart-container canvas {
    max-width: 100%;
    height: auto !important;
    min-height: 300px;
}

/* ローディング */
.loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.9);
    display: flex;
    justify-content: center;
    align-items: center;
    border-radius: 6px;
    z-index: 10;
}

.loading-spinner {
    padding: 20px;
    font-size: 16px;
    color: #666;
}

.loading-spinner::after {
    content: '';
    width: 20px;
    height: 20px;
    border: 2px solid #f3f3f3;
    border-top: 2px solid #3498db;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    display: inline-block;
    margin-left: 10px;
    vertical-align: middle;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* エラーメッセージ */
.error-message {
    background: #ffebee;
    border: 1px solid #f8bbd9;
    border-radius: 4px;
    padding: 15px;
    margin: 15px 0;
    color: #c62828;
}

.error-text {
    margin: 0;
    font-weight: 500;
}

/* サクセスメッセージ */
.success-message {
    background: #e8f5e8;
    border: 1px solid #c3e6c3;
    border-radius: 4px;
    padding: 15px;
    margin: 15px 0;
    color: #2e7d32;
}

.success-text {
    margin: 0;
    font-weight: 500;
}

/* サマリー */
.summary-container {
    margin-top: 20px;
    padding: 15px;
    background: #f8f9fa;
    border-radius: 6px;
    border-left: 4px solid #3498db;
    max-width: 100%;
    overflow-x: auto;
}

.summary-title {
    margin: 0 0 15px 0;
    font-size: 1.2em;
    color: #2c3e50;
    font-weight: 600;
}

.summary-placeholder {
    margin: 0;
    color: #7f8c8d;
    font-style: italic;
}

.summary-stats {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 15px;
    max-width: 100%;
    overflow-x: auto;
}

.stat-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px;
    background: white;
    border-radius: 4px;
    border: 1px solid #e9ecef;
    min-width: 180px;
    white-space: nowrap;
}

.stat-label {
    font-weight: 500;
    color: #495057;
}

.stat-value {
    font-weight: 600;
    color: #2c3e50;
}

/* レスポンシブ対応 */
@media (max-width: 800px) {
    .salon-analytics-header {
        flex-direction: column;
        align-items: stretch;
        text-align: center;
        gap: 10px;
    }
    
    .header-title {
        min-width: auto;
        max-width: none;
        margin-bottom: 10px;
    }
    
    .header-controls {
        min-width: auto;
        max-width: none;
        width: 100%;
    }
    
    .date-selector {
        justify-content: center;
        flex-wrap: nowrap;
        gap: 6px;
    }
    
    .year-select,
    .month-select {
        min-width: 80px;
        max-width: 100px;
    }
    
    .chart-container {
        min-height: 320px;
        padding: 10px;
        /* モバイルでのマージン調整 */
        margin: 10px 0;
    }
    
    .chart-container canvas {
        min-height: 280px;
    }
    
    /* サマリーセクションのモバイル対応 */
    .summary-container {
        margin-top: 10px;
        margin-bottom: calc(10px + env(safe-area-inset-bottom, 0px));
        padding: 10px;
    }
    
    .summary-stats {
        grid-template-columns: 1fr; /* モバイルでは1列表示 */
        gap: 8px;
    }
}

@media (max-width: 600px) {
    .salon-analytics-widget {
        padding: 8px;
        margin: 8px 0;
        /* モバイルでの下部マージン強化 */
        margin-bottom: calc(15px + env(safe-area-inset-bottom, 0px));
    }
    
    .salon-analytics-title {
        font-size: 1.1em;
    }
    
    .date-selector {
        flex-direction: column;
        align-items: stretch;
        gap: 5px;
    }
    
    .year-select,
    .month-select,
    .salon-update-btn {
        width: 100%;
        margin-bottom: 3px;
        min-width: auto;
        max-width: none;
    }
    
    .summary-stats {
        grid-template-columns: 1fr;
        gap: 10px;
    }
    
    .stat-item {
        flex-direction: column;
        align-items: flex-start;
        gap: 5px;
        min-width: auto;
        white-space: normal;
    }
}


@media (max-width: 480px) {
    .salon-analytics-widget {
        padding: 6px;
        margin: 5px 0;
        margin-bottom: calc(20px + env(safe-area-inset-bottom, 0px));
        max-height: calc(100vh - 140px);
    }
    
    .chart-container {
        padding: 8px;
        min-height: 300px;
        margin: 8px 0;
    }
    
    .chart-container canvas {
        min-height: 250px;
    }
    
    .summary-container {
        margin-bottom: calc(15px + env(safe-area-inset-bottom, 0px));
    }
}

/* 特殊なモバイル環境への対応 */
/* iOS Safari のアドレスバー隠し機能対応 */
@media screen and (max-device-width: 480px) and (orientation: portrait) {
    .salon-analytics-widget {
        max-height: calc(100vh - 100px);
        min-height: calc(100vh - 180px);
    }
}

@media screen and (max-device-width: 850px) and (orientation: landscape) {
    .salon-analytics-widget {
        max-height: calc(100vh - 80px);
    }
}

/* Android Chrome のアドレスバー対応 */
@supports (-webkit-appearance: none) {
    @media (max-width: 768px) {
        .salon-analytics-widget {
            max-height: calc(100vh - 110px);
            margin-bottom: calc(10px + env(safe-area-inset-bottom, 15px));
        }
    }
}

/* フルスクリーンモード対応 */
@media (display-mode: fullscreen) {
    .salon-analytics-widget {
        max-height: calc(100vh - 40px);
        margin-bottom: calc(10px + env(safe-area-inset-bottom, 0px));
    }
}