/* ============================================
   CALENDAR.CSS - カレンダーグリッド、セル、サマリー
   ============================================ */

/* カレンダーヘッダー行（ナビ + サマリー） */
.calendar-header-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
    flex-wrap: wrap;
    gap: 16px;
    padding: 0;
}

/* ナビゲーション */
.calendar-nav {
    display: flex;
    align-items: center;
    gap: 20px;
}

.summary-inline {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 2px;
}

.summary-totals {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 0;
}

.summary-grid {
    display: grid;
    grid-template-columns: repeat(3, auto);
    gap: 0;
}

.summary-cell {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    padding: 4px 16px;
    border-left: 1px solid var(--border);
    white-space: nowrap;
}

.summary-cell:first-child {
    border-left: none;
}

.summary-label {
    font-size: 12px;
    font-weight: 500;
    color: var(--text-light);
    margin-bottom: 2px;
}

.summary-value {
    font-size: 20px;
    font-weight: 700;
    font-family: 'Saira', 'Zen Kaku Gothic New', sans-serif;
    white-space: nowrap;
}

.summary-value.profit {
    color: #dc2626;
}

.summary-value.loss {
    color: #16a34a;
}

body[data-theme="dark"] .summary-value.profit {
    color: #ef4444;
}

body[data-theme="dark"] .summary-value.loss {
    color: #22c55e;
}

.summary-percent {
    font-size: 12px;
    font-weight: 500;
    color: var(--text-light);
    margin-top: 1px;
}

.summary-categories-inline {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 8px;
    margin-bottom: 16px;
}

.cat-badge {
    padding: 5px 12px;
    border-radius: 6px;
    font-size: 16px;
    font-weight: 500;
    width: 100%;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    justify-content: space-between
}

.cat-name {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
    min-width: 0;
    font-weight: 600;
}

.cat-amount {
    white-space: nowrap;
    flex-shrink: 0;
    font-weight: 600
}

.calendar-nav h2 {
    font-size: 40px;
    font-weight: 600;
    margin: 0;
    white-space: nowrap;
}

.calendar-nav .nav-buttons {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.btn-nav {
    text-decoration: none;
    color: var(--text);
    font-size: 20px;
    transition: all 0.2s ease;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 4px 12px;
}

.btn-nav:hover {
    background: var(--hover-bg, #f1f5f9);
    border-color: var(--primary);
    color: var(--primary);
}

.btn-nav.disabled {
    opacity: 0.3;
    cursor: not-allowed;
    pointer-events: none;
}

/* カレンダー */
.calendar-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 0;
    border: 1px solid var(--border);
    border-radius: 12px;
    overflow: hidden;
}

.calendar {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 1px;
    background: linear-gradient(135deg, #c0c8d4 0%, #b0bac8 100%);
    border: 1px solid #a8b2c0;
    border-radius: 0;
    overflow: hidden;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.08);
}

.weekday-header {
    background: linear-gradient(180deg, #f8fafc 0%, #f1f5f9 100%);
    padding: 14px 8px;
    text-align: center;
    font-weight: 600;
    font-size: 14px;
    color: #475569;
    border-bottom: 1px solid #e2e8f0;
}

.weekday-header.sun {
    color: var(--sun);
}

.weekday-header.sat {
    color: var(--sat);
}

.day-header {
    background: linear-gradient(180deg, #f8fafc 0%, #f1f5f9 100%);
    padding: 14px 8px;
    text-align: center;
    font-weight: 600;
    font-size: 14px;
    color: #475569;
    border-bottom: 1px solid #e2e8f0;
}

.day-header.sun {
    color: #ef4444;
}

.day-header.sat {
    color: #3b82f6;
}

.day-cell {
    background: #ffffff;
    min-height: 100px;
    min-width: 0;
    padding: 4px 6px 6px 6px;
    cursor: pointer;
    transition: all 0.2s ease;
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 2px;
    border-right: 1px solid rgba(0, 0, 0, 0.1);
    border-bottom: 1px solid rgba(0, 0, 0, 0.1);
}

.cell-header {
    display: flex;
    flex-direction: column;
    padding: 0 2px;
    margin-bottom: 0;
}

.cell-top-row {
    display: flex;
    align-items: center;
    gap: 4px;
    width: 100%;
    overflow: hidden;
}

.cell-total-row {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    margin-top: -4px;
    margin-bottom: 2px;
    min-height: 20px;
}


.day-cell:hover {
    background: linear-gradient(180deg, #fefefe 0%, #f8fafc 100%);
    box-shadow: inset 0 0 0 2px #3b82f6;
    z-index: 10;
}

.day-cell.today {
    background: linear-gradient(180deg, #fefefe 0%, #f8fafc 100%);
    box-shadow: inset 0 0 0 2px #3b82f6;
    z-index: 10;
}

.day-cell.today .day-number {
    font-weight: 500;
}

.day-cell.empty {
    background: #f8fafc;
    cursor: default;
}

.day-cell.empty:hover {
    background: #f8fafc;
    box-shadow: none;
}

.day-number {
    font-family: 'Saira', 'Zen Kaku Gothic New', sans-serif;
    font-size: 20px;
    font-weight: 500;
    line-height: 1;
    color: #1e293b;
    flex-shrink: 0;
    margin-bottom: -1px;
}

/* 祝日の日番号 */
.day-cell.holiday .day-number {
    color: #dc2626;
}

/* 土曜日の日番号 */
.day-cell.saturday .day-number {
    color: #2563eb;
}

/* 日曜日の日番号 */
.day-cell.sunday .day-number {
    color: #dc2626;
}

.cell-right {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    flex: 1;
    min-width: 0;
    max-width: 75%;
    overflow: visible;
    height: 100%;
    padding-top: 0;
}

.comment-line {
    font-size: 12px;
    color: #1e293b;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
    min-width: 0;
    line-height: 1;
    margin-bottom: 1px;
    cursor: default;
}



@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(-90%);
    }

    to {
        opacity: 1;
        transform: translateY(-100%);
    }
}

.total {
    font-family: 'Saira', 'Zen Kaku Gothic New', sans-serif;
    font-weight: 600;
    font-size: clamp(16px, 2.2vw, 32px);
    line-height: 1;
    text-align: center;
    white-space: nowrap;
    letter-spacing: -0.03em;
    overflow: visible;
}

.total.profit {
    color: #dc2626;
    text-shadow: 0 1px 2px rgba(220, 38, 38, 0.1);
}

.total.loss {
    color: #16a34a;
    text-shadow: 0 1px 2px rgba(22, 163, 74, 0.1);
}

/* ダークモード用 */
body[data-theme="dark"] .total.profit {
    color: #ef4444;
}

body[data-theme="dark"] .total.loss {
    color: #22c55e;
}

.total-placeholder {
    font-family: 'Saira', 'Zen Kaku Gothic New', sans-serif;
    font-weight: 600;
    font-size: 20px;
    line-height: 1;
    text-align: center;
    white-space: nowrap;
    letter-spacing: -0.03em;
    overflow: visible;
}

/* Summary Section */
.summary {
    margin-top: 24px;
    padding: 24px 32px;
    background: linear-gradient(135deg, var(--card-bg) 0%, rgba(248, 250, 252, 0.8) 100%);
    border-radius: 16px;
    border: 1px solid var(--border);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.06);
    text-align: center;
}

.details-container {
    display: flex;
    flex-direction: column;
    gap: 1px;
    margin-top: 0;
    flex: 1;
}

.category-block {
    display: flex;
    flex-direction: column;
    padding: 3px 8px;
    justify-content: center;
    border-radius: 4px;
    margin: 0 2px;
    transition: transform 0.15s ease;
    overflow: hidden;
    min-width: 0;
    min-height: 24px;
    flex: 1;
}

.category-block:hover {
    transform: scale(1.02);
}

.category-placeholder {
    background-color: transparent !important;
}

.category-name-line {
    font-size: 12px;
    color: #475569;
    line-height: 1;
    font-weight: 500;
    margin-bottom: 2px;
    letter-spacing: 0.02em
}

.category-value-line {
    font-family: 'Saira', 'Zen Kaku Gothic New', sans-serif;
    font-size: 14px;
    color: #1e293b;
    line-height: 1;
    font-weight: 500;
    text-align: center;
    letter-spacing: -0.02em
}

/* 表示のみアイコン */
.display-only-icon {
    font-size: 12px;
    margin-right: 2px;
    opacity: 0.7;
}

/* カレンダーセル内のみでellipsis適用 */
.day-cell .category-name-line,
.day-cell .category-value-line {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis
}

.detail {
    font-size: 12px;
    color: var(--text-light);
    line-height: 1.4;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    padding: 3px 6px;
    border-radius: 3px;
}

/* レスポンシブ */
@media (max-width: 768px) {
    .calendar {
        font-size: 14px;
        --font-scale: 1.5;
        /* デフォルト1.5倍 */
    }

    .day-cell {
        min-height: 90px;
        padding: 4px;
    }

    .day-number {
        font-size: calc(16px * var(--font-scale, 1)) !important;
    }

    .total {
        font-size: calc(16px * var(--font-scale, 1)) !important;
    }

    .category-value-line {
        font-size: calc(10px * var(--font-scale, 1)) !important;
    }

    .category-name-line {
        font-size: calc(8px * var(--font-scale, 1)) !important;
    }

    .comment-line {
        font-size: calc(8px * var(--font-scale, 1)) !important;
    }
}

/* カレンダーラッパー（背景カード） */
.calendar-wrapper {
    background: var(--card-bg);
    border-radius: var(--card-radius);
    padding: 24px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);
}

/* ビュー切替ボタン */
.view-switch {
    display: flex;
    gap: 8px;
    margin-left: 16px;
}

.view-switch a {
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 14px;
    text-decoration: none;
    color: var(--text);
    background: var(--card-bg);
    border: 1px solid var(--border);
    transition: all 0.2s ease;
}

.view-switch a:hover {
    background: var(--hover-bg);
}

.view-switch a.active {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

/* カテゴリヘッダーバッジ（カレンダー曜日行） */
.weekday-badge-category {
    font-weight: 800;
    font-size: 18px;
    background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
    color: white;
    padding: 4px 10px;
    border-radius: 6px;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}

/* 週合計ヘッダーバッジ（カレンダー曜日行） */
.weekday-badge-total {
    font-weight: 800;
    font-size: 18px;
    background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
    color: white;
    padding: 4px 18px;
    border-radius: 6px;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}

/* 年月選択トリガー */
.date-picker-trigger {
    cursor: pointer;
}

/* 年月選択モーダル */
#datePickerModal {
    align-items: center;
    justify-content: center;
}

#datePickerModal .modal-content {
    max-width: 320px;
    margin: 0;
    padding: 24px;
}

#datePickerModal h3 {
    margin-bottom: 16px;
    padding-bottom: 8px;
}

.date-picker-row {
    display: flex;
    gap: 12px;
    margin-bottom: 16px;
}

.date-picker-field {
    flex: 1;
}

.date-picker-field label {
    display: block;
    margin-bottom: 4px;
    font-weight: 500;
}

#datePickerModal .btn-save {
    width: 100%;
}

/* 週合計フォントウェイト */
.week-total-value {
    font-weight: 900;
}

/* ========================================
   カレンダーチャートセクション
   ======================================== */
.calendar-chart-section {
    margin-top: 24px;
    background: var(--card-bg);
    border-radius: var(--card-radius);
    padding: 20px 24px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);
}

.chart-section-title {
    font-size: 18px;
    font-weight: 600;
    margin: 0 0 16px 0;
    color: var(--text);
}

/* ========================================
   マーカー（カレンダー連携）
   ======================================== */
.day-marker {
    position: absolute;
    top: 1px;
    right: 1px;
    font-size: 12px;
    text-decoration: none;
    opacity: 0.8;
    transition: all 0.2s ease;
    cursor: pointer;
    line-height: 1;
    z-index: 1;
}

.day-marker + .day-marker {
    right: 18px;
}

.day-marker:hover {
    opacity: 1;
    transform: scale(1.2);
}

/* ========================================
   カレンダー右上インポートボタン
   ======================================== */
.calendar-wrapper {
    position: relative;
}

.calendar-import-btn {
    position: absolute;
    top: 6px;
    right: 20px;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 0 10px;
    font-size: 12px;
    font-weight: 600;
    color: #fff;
    background: #f59e0b;
    border: 1px solid #d97706;
    border-radius: 6px;
    text-decoration: none;
    transition: all 0.2s ease;
    z-index: 10;
    box-shadow: 0 2px 4px rgba(217, 119, 6, 0.3);
}

.calendar-import-btn:hover {
    background: #fbbf24;
    border-color: #f59e0b;
    box-shadow: 0 4px 8px rgba(217, 119, 6, 0.4);
    transform: translateY(-1px);
    color: #fff;
}

body[data-theme="dark"] .calendar-import-btn {
    background: #f59e0b;
    border-color: #d97706;
    color: #fff;
}

body[data-theme="dark"] .calendar-import-btn:hover {
    background: #fbbf24;
    border-color: #f59e0b;
    color: #fff;
}

/* モバイル表示では非表示 */
@media (max-width: 768px) {
    .calendar-import-btn {
        display: none;
    }
}