/* =========================================
   ベース設定・変数定義
   ========================================= */
:root {
    --primary-color: #4A90E2;
    --primary-hover: #357ABD;
    --success-color: #2FA572;
    --danger-color: #E74C3C;
    --bg-color: #F5F7FA;
    --card-bg: #FFFFFF;
    --text-main: #333333;
    --text-muted: #7F8C8D;
    --border-color: #E2E8F0;
    --sidebar-bg: #2C3E50;
    --sidebar-text: #ECF0F1;
    --sidebar-hover: #34495E;
    --tooltip-bg: rgba(0, 0, 0, 0.85);
    /* 共通ホバー背景色 */
    --hover-bg: #F8FAFC;
}

/* ダークモード用の配色定義 */
.theme-dark {
    --bg-color: #0F172A;
    --card-bg: #1E293B;
    --text-main: #F1F5F9;
    --text-muted: #94A3B8;
    --border-color: #334155;
    --sidebar-bg: #020617;
    --sidebar-text: #F1F5F9;
    --sidebar-hover: #1E293B;
    --tooltip-bg: rgba(255, 255, 255, 0.95);
    /* ダークモード時のホバー色 */
    --hover-bg: rgba(255, 255, 255, 0.05);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    background-color: var(--bg-color);
    color: var(--text-main);
    line-height: 1.6;
    transition: background-color 0.3s, color 0.3s;
}

/* =========================================
   レイアウト
   ========================================= */
.app-container {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: 250px;
    background-color: var(--sidebar-bg);
    color: var(--sidebar-text);
    display: flex;
    flex-direction: column;
    position: fixed;
    height: 100vh;
    overflow-y: auto;
    z-index: 100;
}

.sidebar-header {
    padding: 20px;
    background-color: rgba(0,0,0,0.1);
    text-align: center;
}

.sidebar-nav {
    flex: 1;
    padding: 20px 0;
}

.sidebar-nav ul {
    list-style: none;
}

.sidebar-nav li a {
    display: flex;
    align-items: center;
    padding: 12px 25px;
    color: var(--sidebar-text);
    text-decoration: none;
    font-size: 15px;
    transition: background-color 0.2s;
}

.sidebar-nav li a:hover,
.sidebar-nav li a.active {
    background-color: var(--sidebar-hover);
    border-left: 4px solid var(--primary-color);
}

.main-content {
    flex: 1;
    margin-left: 250px;
    padding: 40px;
    min-height: 100vh;
}

/* =========================================
   モバイルレスポンシブ対応
   ========================================= */

/* ハンバーガーボタン（PC では非表示） */
.hamburger-btn {
    display: none;
}

/* オーバーレイ（PC では非表示） */
.sidebar-overlay {
    display: none;
}

/* =========================================
   フッター
   ========================================= */
.app-footer {
    margin-left: 250px;
    padding: 16px 40px;
    border-top: 1px solid var(--border-color);
    font-size: 12px;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 16px;
}

.app-footer a {
    color: var(--text-muted);
    text-decoration: none;
}

.app-footer a:hover {
    color: var(--primary-color);
    text-decoration: underline;
}

@media (max-width: 768px) {
    .app-footer {
        margin-left: 0;
        padding: 14px 16px;
        flex-wrap: wrap;
        gap: 10px;
    }
}

/* リスト表示はデフォルトで非表示（PCではグリッドのみ表示） */
.list-view { display: none; }

@media (max-width: 768px) {
    /* ============================================
       ハンバーガーメニュー・サイドバー
    ============================================ */
    .hamburger-btn {
        display: flex;
        position: fixed;
        top: 12px;
        left: 12px;
        z-index: 200;
        background-color: var(--sidebar-bg);
        color: var(--sidebar-text);
        border: none;
        border-radius: 8px;
        padding: 8px;
        cursor: pointer;
        align-items: center;
        justify-content: center;
        box-shadow: 0 2px 8px rgba(0,0,0,0.3);
        -webkit-tap-highlight-color: transparent;
    }

    .sidebar {
        position: fixed;
        height: 100vh;
        -webkit-transform: translateX(-260px);
        transform: translateX(-260px);
        -webkit-transition: transform 0.3s ease;
        transition: transform 0.3s ease;
        z-index: 150;
    }

    .sidebar.open {
        -webkit-transform: translateX(0);
        transform: translateX(0);
    }

    .sidebar-overlay {
        display: block;
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background-color: rgba(0, 0, 0, 0.5);
        z-index: 140;
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.3s ease;
    }

    .sidebar-overlay.active {
        opacity: 1;
        pointer-events: auto;
    }

    /* ============================================
       メインレイアウト
    ============================================ */
    .main-content {
        margin-left: 0;
        padding: 60px 12px 32px;
    }

    .app-container {
        flex-direction: row;
    }

    .page-title {
        font-size: 18px;
    }

    .card {
        padding: 12px;
    }

    /* ============================================
       カレンダー：PC用グリッドを非表示、リスト表示ON
    ============================================ */
    .calendar-grid-wrapper {
        display: none;
    }

    .list-view {
        display: block;
    }

    /* ============================================
       リスト表示スタイル
    ============================================ */

    /* 1日分の行（取引あり） */
    .list-day {
        background: var(--card-bg);
        border-radius: 10px;
        padding: 11px 14px;
        margin-bottom: 6px;
        cursor: pointer;
        border-left: 3px solid transparent;
        -webkit-tap-highlight-color: transparent;
        -webkit-transition: background-color 0.15s;
        transition: background-color 0.15s;
    }

    /* 今日 */
    .list-day.today {
        border-left-color: var(--primary-color);
        background: rgba(74, 144, 226, 0.06);
    }

    /* 取引なしの日（コンパクト・やや薄く） */
    .list-day.empty {
        padding: 7px 14px;
        opacity: 0.45;
        background: transparent;
        box-shadow: none;
    }

    /* 取引ありの日（白背景＋影で浮き上がる） */
    .list-day:not(.empty) {
        box-shadow: 0 1px 4px rgba(0,0,0,0.08);
    }

    .list-day:active {
        background-color: var(--hover-bg);
    }

    /* 日付ヘッダー行（日付・曜日・合計） */
    .list-day-header {
        display: flex;
        align-items: center;
        gap: 6px;
    }

    .list-day-label {
        display: flex;
        align-items: baseline;
        gap: 3px;
    }

    .list-day-num {
        font-size: 17px;
        font-weight: bold;
        min-width: 24px;
    }

    .list-day-week {
        font-size: 12px;
    }

    /* 「今日」バッジ */
    .list-today-badge {
        font-size: 11px;
        background: var(--primary-color);
        color: white;
        padding: 1px 7px;
        border-radius: 10px;
    }

    /* 日付右端の収支合計 */
    .list-day-net {
        margin-left: auto;
        font-weight: bold;
        font-size: 14px;
    }

    .list-day-net.income { color: var(--success-color); }
    .list-day-net.expense { color: var(--danger-color); }

    /* 「＋ 追加」ヒント（取引なしの日） */
    .list-add-hint {
        margin-left: auto;
        font-size: 12px;
        color: var(--text-muted);
    }

    /* 取引明細のコンテナ */
    .list-day-txs {
        margin-top: 7px;
        display: flex;
        flex-direction: column;
        gap: 5px;
        padding-left: 2px;
    }

    /* 1件の取引行 */
    .list-tx-item {
        display: flex;
        align-items: center;
        gap: 7px;
        font-size: 13px;
    }

    /* カテゴリバッジ */
    .list-tx-badge {
        font-size: 10px;
        color: white;
        padding: 2px 6px;
        border-radius: 4px;
        white-space: nowrap;
        flex-shrink: 0;
    }

    /* メモ・名称（はみ出したら省略） */
    .list-tx-memo {
        flex: 1;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        color: var(--text-muted);
        font-size: 12px;
    }

    /* 金額 */
    .list-tx-amount {
        font-weight: 600;
        white-space: nowrap;
        font-size: 13px;
        flex-shrink: 0;
    }

    .list-tx-amount.income { color: var(--success-color); }
    .list-tx-amount.expense { color: var(--danger-color); }

    /* ============================================
       モーダル
    ============================================ */
    .modal-content {
        width: 96%;
        max-height: 90vh;
        overflow-y: auto;
        padding: 20px 16px;
        -webkit-overflow-scrolling: touch;
    }

    /* ============================================
       ページヘッダー（タイトル＋Tipsボタン）
    ============================================ */
    .page-header {
        flex-wrap: wrap;
        gap: 8px;
        margin-bottom: 16px;
    }

    /* ============================================
       フォームの横並び → 縦並びに変換
       （モーダル内の「支給日と休日ルール」など）
    ============================================ */
    .flex-row,
    .form-group-row {
        flex-direction: column;
        gap: 0;
    }

    /* ============================================
       リストアイテム（定期収入・固定費など）
    ============================================ */
    .list-item {
        flex-wrap: wrap;
        gap: 6px;
        padding: 12px 10px;
    }

    .item-info {
        flex: 1 1 100%;
    }

    .item-actions {
        width: 100%;
        justify-content: flex-end;
    }

    /* ============================================
       テーブル（月間集計など）横スクロール対応
    ============================================ */
    table {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* ============================================
       Tipsツールチップが画面外にはみ出さないように
    ============================================ */
    .tips-content {
        width: calc(100vw - 40px);
        max-width: 280px;
        left: auto;
        right: 0;
    }

    /* ============================================
       設定カード
    ============================================ */
    .settings-card {
        padding: 16px;
        margin: 0;
    }

    /* ============================================
       iOS Safari / Chrome 共通対応
       ・16px未満のinputはiOSが自動ズームするため16pxに統一
       ・タップハイライトを透明に統一
    ============================================ */
    input[type="text"],
    input[type="number"],
    input[type="email"],
    input[type="password"],
    select,
    textarea {
        font-size: 16px !important;
    }

    * {
        -webkit-tap-highlight-color: transparent;
    }
}

/* =========================================
   認証（ログイン・会員登録）ページ用
   ========================================= */
.auth-container {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    background-color: var(--bg-color);
}

.auth-card {
    width: 100%;
    max-width: 400px;
    background-color: var(--card-bg);
    padding: 40px;
    border-radius: 12px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.1);
}

.auth-header {
    text-align: center;
    margin-bottom: 30px;
}

/* =========================================
   共通コンポーネント
   ========================================= */
.page-header {
    display: flex;
    align-items: center;
    gap: 15px;
    margin-bottom: 30px;
}

.page-title {
    font-size: 24px;
    color: var(--text-main);
    display: flex;
    align-items: center;
    margin: 0;
}

.card {
    background-color: var(--card-bg);
    border-radius: 12px;
    padding: 25px;
    box-shadow: 0 4px 6px rgba(0,0,0,0.03);
    margin-bottom: 25px;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 10px 20px;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
}

.btn-primary { background-color: var(--primary-color); color: white; }
.btn-primary:hover { background-color: var(--primary-hover); }

.form-group { margin-bottom: 15px; }
.form-group label {
    display: block;
    margin-bottom: 5px;
    font-size: 13px;
    font-weight: bold;
    color: var(--text-muted);
}

.form-control {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 14px;
    background-color: var(--card-bg);
    color: var(--text-main);
    outline: none;
}
.form-control:focus { 
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(74, 144, 226, 0.2); /* フォーカスを分かりやすく */
}

/* =========================================
   🚀 Tips（ツールチップ）下展開設定
   ========================================= */
.tips-container {
    position: relative;
    display: inline-flex;
    align-items: center;
    cursor: help;
    color: var(--text-muted);
    transition: color 0.2s;
}

.tips-container:hover {
    color: var(--primary-color);
}

.tips-icon {
    font-size: 20px !important;
}

.tips-content {
    visibility: hidden;
    width: 280px;
    background-color: var(--tooltip-bg);
    color: var(--card-bg);
    text-align: left;
    border-radius: 8px;
    padding: 15px;
    position: absolute;
    z-index: 1000;
    top: 130%; /* 🚀 アイコンの下に展開 */
    left: 0;
    opacity: 0;
    transition: opacity 0.3s, transform 0.3s;
    transform: translateY(-10px); /* 🚀 下展開アニメーションの起点 */
    font-size: 13px;
    line-height: 1.6;
    box-shadow: 0 4px 15px rgba(0,0,0,0.2);
    pointer-events: none;
    word-wrap: break-word;
}

.theme-dark .tips-content {
    color: var(--bg-color);
}

.tips-content::after {
    content: "";
    position: absolute;
    bottom: 100%; /* 🚀 ツールチップの真上（アイコンとの間）に配置 */
    left: 10px;
    border-width: 6px;
    border-style: solid;
    /* 🚀 上向きの三角形を描画 */
    border-color: transparent transparent var(--tooltip-bg) transparent; 
}

.tips-container:hover .tips-content {
    visibility: visible;
    opacity: 1;
    transform: translateY(0);
}

/* =========================================
   カレンダーセル
   ========================================= */
.calendar-grid { 
    display: grid; 
    grid-template-columns: repeat(7, 1fr); 
    gap: 8px; 
}

.cal-day-header {
    text-align: center;
    font-weight: bold;
    padding-bottom: 8px;
    font-size: 14px;
    border-bottom: 2px solid var(--border-color);
    margin-bottom: 5px;
    color: var(--text-main);
}

.cal-cell {
    background-color: var(--card-bg);
    border-radius: 8px;
    height: 125px; /* 高さを固定にする */
    padding: 8px;
    border: 1px solid var(--border-color);
    cursor: pointer;
    display: flex;
    flex-direction: column;
    overflow: hidden; /* 枠からはみ出した分は表示しない */
    transition: border-color 0.2s, box-shadow 0.2s;
}

.cal-cell:hover {
    border-color: var(--primary-color);
    box-shadow: 0 2px 8px rgba(0,0,0,0.05);
}

.cal-cell.empty {
    background-color: transparent;
    border: none;
    cursor: default;
}

.cal-cell.today {
    border: 2px solid var(--primary-color);
    background-color: rgba(74, 144, 226, 0.05);
}

.cal-date {
    font-size: 13px;
    font-weight: bold;
    margin-bottom: 4px;
}

/* ラベル潰れ防止のスタイル */
.tx-label {
    font-size: 10px;
    color: white;
    padding: 2px 5px;
    border-radius: 4px;
    margin-bottom: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.2;
    min-height: 16px;
    display: block;
    flex-shrink: 0;
}

/* 「+n件」のスタイル */
.more-label {
    font-size: 10px;
    color: var(--text-muted);
    text-align: center;
    margin-top: 2px;
    font-weight: bold;
}

/* =========================================
   モーダル（ポップアップ）共通
   ========================================= */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0,0,0,0.5);
    z-index: 9999;
    justify-content: center;
    align-items: center;
}

.modal.active {
    display: flex;
}

.modal-content {
    background-color: var(--card-bg);
    width: 90%;
    max-width: 500px;
    border-radius: 12px;
    padding: 30px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.2);
    animation: modalFadeIn 0.2s ease-out;
}

@keyframes modalFadeIn {
    from { opacity: 0; transform: translateY(-20px); }
    to { opacity: 1; transform: translateY(0); }
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 10px;
}

.close-btn {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: var(--text-muted);
}

/* =========================================
   サブスクリプション管理（サービス一覧）
   ========================================= */
.service-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.service-item {
    background-color: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 12px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    transition: background-color 0.2s;
    font-size: 15px;
}

.service-item:hover {
    background-color: var(--hover-bg);
}

/* サービスアイコンのサイズ制限 */
.service-item img, 
.service-item i {
    width: 32px !important;
    height: 32px !important;
    font-size: 24px !important;
    margin-right: 12px;
}

/* サービス情報エリア（名前など） */
.service-info {
    display: flex;
    align-items: center;
    flex: 1;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

/* 右側のボタン・金額エリア */
.service-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* 編集ボタンのスタイル（小さく、目立ちすぎないように） */
.btn-edit {
    padding: 2px 8px;
    font-size: 11px;
    background-color: transparent;
    border: 1px solid var(--primary-color);
    color: var(--primary-color);
    border-radius: 4px;
}
.btn-edit:hover {
    background-color: var(--primary-color);
    color: white;
}