/* ページ切替タブ（共通ヘッダー内） */
.page-tabs {
    display: flex;
    gap: 4px;
    border-bottom: 2px solid #4a90d9;
}
.page-tab {
    padding: 8px 18px;
    font-size: 0.9rem;
    font-weight: bold;
    text-decoration: none;
    border: 1px solid #4a90d9;
    border-bottom: none;
    border-radius: 8px 8px 0 0;
    background: #eef4fb;
    color: #4a90d9;
    white-space: nowrap;
    transition: background 0.12s, color 0.12s;
}
.page-tab-active {
    background: #4a90d9;
    color: #fff;
}
.page-tab:not(.page-tab-active):hover {
    background: #d4e6f7;
}

/* number input のスピナーボタンを非表示 */
input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}
input[type="number"] {
    -moz-appearance: textbox;
    appearance: textbox;
}

/* Dash dcc.Input の増減ボタンを非表示 */
.dash-input-group .input-group-addon {
    display: none !important;
}
.dash-input-group {
    flex-wrap: nowrap;
}
.dash-input-group input {
    border-radius: 4px !important;
}

/* マニュアルモーダル */
.manual-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 9999;
    display: flex;
    justify-content: center;
    align-items: center;
}
.manual-modal-content {
    background: #fff;
    border-radius: 10px;
    padding: 24px;
    width: 90vw;
    max-width: 800px;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
}
.manual-modal-content table {
    border-collapse: collapse;
    width: 100%;
    margin: 8px 0;
}
.manual-modal-content th,
.manual-modal-content td {
    border: 1px solid #ddd;
    padding: 6px 10px;
    text-align: left;
}
.manual-modal-content th {
    background: #f5f5f5;
}

/* ソルバー計算中スピナー */
@keyframes solver-spin {
    to { transform: rotate(360deg); }
}

/* ── dash_daq NumericInput の余白調整 ── */
.numeric-input {
    margin: 0 !important;
}
.numeric-input input {
    font-size: 1rem !important;
}

/* ── PC: 絆入力を7列1行に固定 ── */
.bond-fields {
    display: grid !important;
    grid-template-columns: repeat(7, auto) !important;
    gap: 8px !important;
}

/* ── 贈り物逆引きページ ── */
.gl-columns {
    display: flex;
    gap: 16px;
    align-items: flex-start;
}
.gl-select-col {
    flex: 1;
    min-width: 0;
}
/* 結果カラム: スクロールしても選択部と並んで見えるよう追従させる */
.gl-result-col {
    width: 380px;
    flex-shrink: 0;
    position: sticky;
    top: 16px;
    align-self: flex-start;
    max-height: calc(100vh - 32px);
    overflow-y: auto;
}
.gl-gift-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(92px, 1fr));
    gap: 6px;
}
.gl-gift-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    padding: 6px 4px;
    border: 1px solid #ccc;
    border-radius: 6px;
    cursor: pointer;
    font-family: inherit;
    text-align: center;
    transition: border-color 0.12s, box-shadow 0.12s;
}
.gl-gift-card:hover {
    border-color: #4a90d9;
}
.gl-gift-card.gl-selected {
    border-color: #4a90d9;
    box-shadow: 0 0 0 2px rgba(74, 144, 217, 0.35);
}
.gl-high {
    background: #ede7f6;
}
.gl-normal {
    background: #fafafa;
}
/* アイコンに重ねる製造2次ノード名 */
.gl-icon-wrap {
    position: relative;
    display: flex;
    justify-content: center;
    width: 100%;
}
.gl-node-badge {
    position: absolute;
    top: -3px;
    right: -1px;
    font-size: 0.6rem;
    line-height: 1.3;
    font-weight: bold;
    color: #a0304a;
    background: #fdecef;
    border: 1px solid #f3c4cf;
    border-radius: 8px;
    padding: 0 4px;
    white-space: nowrap;
}
.gl-gift-name {
    font-size: 0.7rem;
    line-height: 1.2;
    color: #333;
    word-break: break-word;
}
.gl-tier-counts {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 2px;
    font-size: 0.66rem;
    color: #555;
    line-height: 1.3;
}
/* 1つの「特大3人」が途中で折り返さないようにし、区切りの / で改行させる */
.gl-tier-count {
    white-space: nowrap;
}
.gl-tier-sep {
    color: #bbb;
}
.gl-legend {
    border: 1px solid #ccc;
    border-radius: 10px;
    padding: 1px 8px;
}
.gl-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-top: 6px;
}
/* 製造の2次ノード名（花の名前）のバッジ */
.gl-node {
    font-weight: bold;
    background: #fdecef;
    border: 1px solid #f3c4cf;
    border-radius: 10px;
    padding: 1px 10px;
}
.gl-chip {
    font-size: 0.8rem;
    background: #f0f4f8;
    border: 1px solid #dde4ea;
    border-radius: 12px;
    padding: 2px 10px;
    white-space: nowrap;
}

/* ── 2次ノード比較ページ ── */
.nc-weight-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 4px 16px;
}
.nc-weight-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    font-size: 0.85rem;
}
.nc-weight-label {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.nc-node {
    border-bottom: 1px solid #eee;
}
.nc-node.nc-top > .nc-summary {
    background: #fff8e1;
}
.nc-summary {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 4px;
    cursor: pointer;
    list-style: none;
}
.nc-summary::-webkit-details-marker {
    display: none;
}
.nc-rank {
    width: 1.6em;
    text-align: right;
    color: #888;
    font-size: 0.85rem;
}
.nc-node-name {
    width: 6.5em;
    white-space: nowrap;
    flex-shrink: 0;
    text-align: center;
}
.nc-category {
    width: 8em;
    flex-shrink: 0;
    white-space: nowrap;
    font-size: 0.85rem;
    color: #555;
}
.nc-bar {
    flex: 1;
    min-width: 40px;
    height: 10px;
    background: #f0f0f0;
    border-radius: 5px;
    overflow: hidden;
}
.nc-bar-fill {
    display: block;
    height: 100%;
    background: #4a90d9;
}
.nc-ev {
    min-width: 5em;
    text-align: right;
    font-variant-numeric: tabular-nums;
}
.nc-gifts {
    padding: 4px 0 8px 2.2em;
}
.nc-gift-row {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.85rem;
    padding: 2px 0;
}
.nc-gift-name {
    flex: 1;
    min-width: 0;
}
.nc-gift-value {
    width: 5em;
    text-align: right;
    font-variant-numeric: tabular-nums;
}
.nc-gift-target {
    width: 12em;
    display: flex;
    align-items: center;
    gap: 4px;
}

/* ── モバイル対応 ── */
@media (max-width: 768px) {
    .nc-category {
        display: none;
    }
    .nc-gift-target {
        width: auto;
    }
    .nc-gift-row {
        flex-wrap: wrap;
    }
    /* 2カラム → 縦積み */
    .main-columns {
        flex-direction: column !important;
        gap: 12px !important;
    }

    /* サイドバーを横幅いっぱいに */
    .sidebar {
        width: 100% !important;
        position: static !important;
    }

    /* メインコンテンツを横幅いっぱいに */
    .main-columns > div:last-child {
        width: 100% !important;
    }

    /* ページ全体のパディングを縮小 */
    .page-container {
        padding: 10px !important;
    }

    /* 共通ヘッダー */
    .site-header-wrap {
        padding: 10px 10px 0 !important;
    }
    .site-header {
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 4px !important;
    }
    .site-header > div {
        margin-left: 0 !important;
    }
    .site-title {
        font-size: 1.2rem !important;
    }

    /* タブバー: はみ出す場合は横スクロール */
    .page-tabs {
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch;
    }
    .page-tab {
        padding: 8px 10px !important;
        font-size: 0.8rem !important;
    }

    /* ヘッダー行: 縦積み中央揃え */
    .page-header {
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 6px !important;
    }
    .page-header h1 {
        font-size: 1.25rem !important;
    }
    .page-header-right {
        width: 100% !important;
        justify-content: space-between !important;
        margin-left: 0 !important;
    }

    /* 衣装カード */
    .student-card {
        padding: 10px !important;
    }
    .student-card-header input[type="text"] {
        font-size: 0.9rem !important;
    }

    /* 衣装カード内の絆入力: 4列固定 → 4+3 の2行 */
    .bond-fields {
        display: grid !important;
        grid-template-columns: repeat(4, 1fr) !important;
        gap: 6px !important;
    }
    .bond-fields > div {
        min-width: 0 !important;
    }
    .bond-fields input {
        font-size: 0.95rem !important;
        padding: 6px 4px !important;
    }

    /* 絆ランク入力行 */
    .bond-rank-row {
        display: grid !important;
        grid-template-columns: repeat(auto-fill, minmax(70px, 1fr)) !important;
        gap: 8px !important;
    }
    .bond-rank-section {
        padding: 10px !important;
    }

    /* 全ボタン: タッチしやすい最小高さ */
    button,
    .dash-dropdown .Select-control {
        min-height: 44px !important;
    }

    /* 衣装追加ボタン */
    .add-student-btn {
        width: 100% !important;
        padding: 10px 16px !important;
        font-size: 1rem !important;
    }

    /* 計算ボタン: 画面下部に固定 */
    .calc-btn-wrapper {
        position: fixed !important;
        bottom: 0 !important;
        left: 0 !important;
        right: 0 !important;
        padding: 10px !important;
        background: rgba(255, 255, 255, 0.95) !important;
        backdrop-filter: blur(8px) !important;
        -webkit-backdrop-filter: blur(8px) !important;
        box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.1) !important;
        z-index: 100 !important;
    }
    .calc-btn-wrapper button {
        border-radius: 8px !important;
    }

    /* 結果エリア: 固定ボタン分の余白 */
    .chart-result-area {
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch;
        padding-bottom: 72px !important;
    }

    /* 結果テーブルの可読性向上 */
    .chart-result-area table {
        font-size: 0.85rem !important;
    }
    .chart-result-area th,
    .chart-result-area td {
        padding: 6px 8px !important;
        white-space: nowrap;
    }

    /* プリセットセクション: ドロップダウンを1行、ボタンを次の行 */
    .preset-section .dash-dropdown {
        width: 100% !important;
    }
    #load-preset-btn {
        padding: 8px 16px !important;
    }

    /* モーダル */
    .manual-modal-content {
        width: 95vw !important;
        max-height: 90vh !important;
        padding: 16px !important;
        border-radius: 8px !important;
    }

    /* 贈り物逆引き: 2カラム → 縦積み、カードを詰める */
    .gl-columns {
        flex-direction: column !important;
        gap: 12px !important;
    }
    .gl-select-col,
    .gl-result-col {
        width: 100% !important;
        position: static !important;
        max-height: none !important;
        overflow-y: visible !important;
    }
    .gl-gift-grid {
        grid-template-columns: repeat(auto-fill, minmax(88px, 1fr)) !important;
    }
    .gl-gift-card {
        min-height: 0 !important;
    }

    /* 削除ボタン: タップしやすく */
    .remove-student-btn {
        width: 32px !important;
        height: 32px !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
    }
}

/* ── 小さいスマホ対応 (360px以下) ── */
@media (max-width: 360px) {
    .page-header h1 {
        font-size: 1.1rem !important;
    }
    .bond-fields {
        grid-template-columns: repeat(4, 1fr) !important;
    }
}
