/* style.css */

/* 基礎 */
*,
*::before,
*::after {
    box-sizing: border-box;
}

html {
    -webkit-text-size-adjust: 100%;
}

body {
    margin: 0;
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans JP", "Hiragino Kaku Gothic ProN", Meiryo, sans-serif;
    line-height: 1.6;
    color: #333;
    background: #f6f8fb;
    font-size: clamp(14px, 1.6vw, 18px);
}

/* カラートークン */
:root {
    --brand: #5C6BC0;
    --brand-d: #4051a8;
    --brand-l: #e6ebff;
    --accent: #1E90FF;
    --accent-2: #8A2BE2;
    --ok: #16a34a;
    --warn: #f59e0b;
    --error: #e11d48;
    --muted: #556070;
    --border: #e6eaf2;
    --card: #fff;
    --shadow: 0 8px 24px rgba(15, 20, 40, .08);
}

/* コンテナ */
.container {
    max-width: 1100px;
    margin: 0 auto;
    padding: 0 16px;
}

/* race_outputページでは幅制限を解除（ワイド化） */
/* bodyに .page--race を付けることで有効化 */
.page--race .container {
    max-width: none;
    padding-left: 16px;
    padding-right: 16px;
}

/* 画像・iframeは親幅に収める */
img,
video,
canvas,
svg {
    max-width: 100%;
    height: auto;
    display: block;
}

iframe {
    width: 100%;
}

/* ヘッダー */
.site-header {
    background: #fff;
    border-bottom: 1px solid #eee;
    padding: 0;
    /* base.htmlでcontainerを適用したため、ここで調整 */
}

.header-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .75rem;
    padding: .5rem 0;
    flex-wrap: wrap;
}

.brand-title {
    font-weight: 700;
    font-size: clamp(18px, 2.5vw, 22px);
    text-decoration: none;
    /* リンクとして使う場合 */
    color: inherit;
    /* リンク色を継承 */
}

.nav {
    display: flex;
    align-items: center;
    gap: .5rem;
    flex-wrap: wrap;
}

.login-info {
    display: inline-flex;
    align-items: center;
    gap: .5rem;
}

/* 余白ヘルパー */
.ml-10 {
    margin-left: 10px;
}

.ml-20 {
    margin-left: 20px;
}

.mb-15 {
    margin-bottom: 15px;
}

/* 見出し・ページヘッダー */
.page-header {
    margin: 10px 0 16px;
}

.page-header__top {
    display: flex;
    justify-content: flex-start;
}

.page-title {
    margin: 8px 0 0;
    font-weight: 800;
    font-size: clamp(22px, 3vw, 28px);
    color: #1b2a4a;
}

.page-title__date {
    color: var(--accent);
}

/* リンク/ボタン */
a {
    color: #0b5ed7;
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

.btn {
    padding: .6rem 1rem;
    font: inherit;
    border-radius: 10px;
    border: 1px solid var(--brand);
    background: var(--brand);
    color: #fff;
    cursor: pointer;
    transition: all .15s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: .4rem;
}

.btn:hover {
    background: var(--brand-d);
    border-color: var(--brand-d);
}

.btn--sm {
    padding: .45rem .75rem;
    font-size: .95em;
    border-radius: 8px;
}

.btn-primary {
    background: var(--brand);
    border-color: var(--brand);
}

.btn-secondary {
    background: #eef2f7;
    border-color: #d8e0ee;
    color: #111;
}

.btn-secondary:hover {
    background: #e5ebf5;
}

.btn-accent {
    background: var(--accent);
    border-color: var(--accent);
}

.btn-link {
    color: #0b5ed7;
    background: transparent;
    border: none;
    padding: 0;
    text-decoration: underline;
    text-underline-offset: 2px;
}

.w-100 {
    width: 100%;
}

/* トグルボタン（競馬場/レース番号） */
.button-group {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.button-group--wrap {
    flex-wrap: wrap;
}

.btn-toggle {
    background: #fff;
    color: #1b2a4a;
    border-color: #d7dff0;
    box-shadow: 0 1px 3px rgba(15, 23, 42, .04);
    /* デフォルトのボタンの影を少し抑える */
}

.btn-toggle:hover {
    background: #f6f9ff;
    border-color: #c7d5f5;
    box-shadow: 0 2px 6px rgba(15, 23, 42, .08);
    /* ホバー時の影を少し強調 */
}

.btn-toggle.is-active {
    background: linear-gradient(180deg, #e8f1ff, #d8e8ff);
    border-color: #a7c4ff;
    box-shadow: inset 0 0 0 2px rgba(30, 144, 255, .15), 0 4px 8px rgba(30, 144, 255, .1);
    /* 強めのシャドウ */
    color: #114a8b;
    font-weight: 700;
    position: relative;
    /* アイコン配置のため */
    z-index: 2;
    /* 隣接ボタンより手前に表示 */
}

/* アクティブなボタンに表示するアイコンのスタイル */
.btn.is-active .active-icon {
    display: inline-block;
    /* アイコンを表示 */
    margin-right: 5px;
    /* テキストとの間にスペース */
    color: inherit;
    /* 親要素の文字色を継承 */
}

.btn .active-icon {
    display: none;
    /* デフォルトでは非表示 */
}


/* 過去戦績の表示モード切替 (segmented group) */
.button-group--segmented {
    border: 1px solid #E5EAF3;
    /* グループ全体の境界線は維持 */
    border-radius: 12px;
    overflow: hidden;
    /* 角丸を維持するため */
    background: #fff;
    box-shadow: inset 0 1px 0 rgba(15, 23, 42, .03);
    display: flex;
    /* Flexboxで配置 */
    flex-wrap: wrap;
    /* 必要に応じて折り返し */
}

.button-group--segmented .btn {
    border-radius: 0;
    /* 個々のボタンの角丸は削除 */
    border: none;
    /* 個々のボタンの境界線は削除 */
    border-right: 1px solid #E5EAF3;
    /* 右側に境界線を追加 */
    background: #fff;
    color: #334155;
    font-weight: 700;
    padding: 10px 14px;
    min-width: 92px;
    position: relative;
    /* for active indicator/icon */
    box-shadow: none;
    /* 個々のボタンの影は削除 */
}

.button-group--segmented .btn:last-child {
    border-right: 0;
    /* 最後のボタンの右境界線は削除 */
}

.button-group--segmented .btn.is-active {
    background: #0ea5e9;
    /* アクティブなボタンの背景色を強調 */
    color: #fff;
    box-shadow: inset 0 0 0 1px #0ea5e9;
    /* アクティブなボタンの内部に境界線 */
    position: relative;
    z-index: 1;
    /* 重なり順を調整 */
}

/* カード */
.card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 14px;
    box-shadow: var(--shadow);
    margin: 16px 0;
    overflow: hidden;
}

.card-header {
    position: relative;
    padding: 14px 18px 12px 18px;
    background: linear-gradient(180deg, #fafcff 0%, #f2f6ff 100%);
    border-bottom: 1px solid var(--border);
}

.card-header-accent {
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 6px;
    background: linear-gradient(180deg, var(--accent) 0%, var(--accent-2) 100%);
}

.card-title {
    margin: 0;
    font-size: 20px;
    font-weight: 800;
    letter-spacing: .02em;
    color: #1b2a4a;
    display: flex;
    align-items: center;
    gap: 10px;
}

.card-body {
    padding: 16px 18px 18px;
}

.icon {
    font-size: 1.1em;
}

/* 通知/アラート */
.notice {
    padding: 10px 12px;
    border-radius: 10px;
    border: 1px solid #dfe7f5;
    background: #f7fbff;
    color: #0c3a6b;
    margin: 0 0 12px;
}

.notice-info strong {
    color: #0c3a6b;
}

.alerts {
    margin: 10px 0;
    display: grid;
    gap: 8px;
}

.alert {
    padding: 10px 12px;
    border-radius: 10px;
    font-weight: 700;
    border: 1px solid #e5e7eb;
    background: #f8fafc;
    color: #111;
}

.alert.success {
    border-color: #c7f9cc;
    background: #eefff0;
    color: #066a12;
}

.alert.error {
    border-color: #ffd6dd;
    background: #fff1f3;
    color: #b3133a;
}

.alert.info {
    border-color: #dbeafe;
    background: #eff6ff;
    color: #1e40af;
}

/* グリッド（ログイン/登録2カラム） */
.grid {
    display: grid;
    gap: 16px;
}

.grid--2col {
    grid-template-columns: 1fr;
}

@media (min-width: 900px) {
    .grid--2col {
        grid-template-columns: 1fr 1fr;
    }
}

/* フォーム（ログイン/登録） */
.auth-card .card-body {
    padding-top: 14px;
}

.auth-form {
    display: grid;
    gap: 12px;
}

.input-label {
    display: grid;
    gap: 6px;
    font-weight: 700;
    color: #334155;
}

input[type="text"],
input[type="password"] {
    padding: 10px 12px;
    border-radius: 10px;
    border: 1px solid #d8dfed;
    background: #fff;
    font: inherit;
}

input[type="text"]:focus,
input[type="password"]:focus {
    outline: none;
    border-color: #9bb8ff;
    box-shadow: 0 0 0 3px rgba(30, 144, 255, .15);
}

/* ===== カレンダー(index) ===== */
.year-month-selector {
    margin: 1rem 0;
    display: flex;
    align-items: center;
    gap: .5rem;
    flex-wrap: wrap;
}

.calendar-container {
    background: #fff;
    border-radius: 10px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, .08);
    padding: 1rem;
    width: 100%;
    max-width: 700px;
}

.calendar {
    table-layout: fixed;
    width: 100%;
    border-collapse: collapse;
}

.calendar th,
.calendar td {
    border: 1px solid #ddd;
    text-align: center;
    padding: clamp(6px, 1.2vw, 14px);
    vertical-align: middle;
    background: #fff;
    color: #111;
}

td.weekday {
    background: #eaeaea;
    color: #111;
}

td.saturday {
    background: #e0f0ff;
    color: #FF7043;
}

td.sunday {
    background: #ffeaea;
    color: #FF5252;
}

.calendar td.holiday {
    background: #ffeaea !important;
    color: #FF5252 !important;
}

td.empty {
    background: #f7f7f7;
}

td.selected {
    background: #4CAF50;
    color: #111;
    border-radius: 5px;
}

.day-button {
    display: block;
    width: 100%;
    background: transparent;
    border: none;
    color: inherit !important;
    font-weight: bold;
    font-size: clamp(14px, 4vw, 18px);
    padding: .45rem 0;
    cursor: pointer;
}

@media (max-width:480px) {
    .calendar-container {
        padding: .75rem;
    }

    .calendar th,
    .calendar td {
        padding: 6px;
    }

    .day-button {
        font-size: clamp(13px, 3.6vw, 16px);
        padding: .4rem 0;
    }
}

@media (min-width:1024px) {
    .calendar-container {
        max-width: 960px;
        padding: 1.25rem 1.5rem;
    }

    .calendar th,
    .calendar td {
        padding: 12px 14px;
        font-size: 16px;
    }

    .day-button {
        font-size: 20px;
    }
}

/* 最終優先の祝日スタイル（PCでも確実に反映） */
.calendar td.holiday {
    background-color: #ffeaea !important;
    color: #FF5252 !important;
}

.calendar td.holiday.selected {
    background-color: #4CAF50 !important;
    color: #111 !important;
}

@media (min-width:1024px) {
    .calendar td.holiday {
        background-color: #ffeaea !important;
        color: #FF5252 !important;
    }

    .calendar td.holiday.selected {
        background-color: #4CAF50 !important;
        color: #111 !important;
    }
}

/* ===== paddockテーブル(race_output) ===== */

/* 縦横ともにスクロール許可（ここを x のみ から修正） */
.table-wrapper {
    overflow: auto;
    -webkit-overflow-scrolling: touch;
}

/* 既定は max-content（横に長い場合は横スクロール） */
#raceTable,
.race-table {
    width: max-content;
    border-collapse: collapse;
}

#raceTable th,
#raceTable td,
.race-table th,
.race-table td {
    padding: 8px 10px;
    font-size: 14px;
    text-align: center;
    vertical-align: middle;
    white-space: nowrap;
    border: 1px solid #e3e7f2;
}

#raceTable thead th {
    position: sticky;
    top: 0;
    z-index: 3;
    background: linear-gradient(180deg, #f8faff 0%, #eef3ff 100%);
    color: #334155;
    font-weight: 800;
    letter-spacing: .02em;
    border-bottom: 2px solid #d5dff1;
}

/* DataTables のスタイル微調整（テーマに寄せる） */
.dataTables_wrapper .dataTables_paginate .paginate_button {
    border: 1px solid #d8dfed !important;
    border-radius: 8px !important;
    padding: .2rem .5rem !important;
    margin: 0 .15rem !important;
    background: #fff !important;
    color: #1b2a4a !important;
}

.dataTables_wrapper .dataTables_paginate .paginate_button.current {
    background: #eaf2ff !important;
    border-color: #a7c4ff !important;
    color: #114a8b !important;
}

.dataTables_wrapper .dataTables_length select,
.dataTables_wrapper .dataTables_filter input {
    border: 1px solid #d8dfed;
    border-radius: 8px;
    padding: 6px 8px;
}

/* スマホでの列制限（不要列だけ非表示） */
@media (max-width: 768px) {
    #raceTable {
        table-layout: fixed;
    }

    #raceTable th,
    #raceTable td {
        white-space: normal !important;
        word-break: break-word;
        line-height: 1.35;
        padding: 6px 6px !important;
        font-size: 12px !important;
    }

    .select-note {
        display: block;
        margin-top: 4px;
        font-size: 11px;
        line-height: 1.2;
        color: #333;
    }

    #paddock-form select {
        margin-bottom: 2px;
        width: 100%;
        max-width: 100%;
        font-size: 12px !important;
        padding: 4px !important;
    }

    button {
        width: 100%;
    }
}

/* PCでは select-note を表示しない */
@media (min-width: 769px) {
    .select-note {
        display: none;
    }
}

@media (max-width: 420px) {

    #raceTable th,
    #raceTable td {
        padding: 4px !important;
        font-size: 11px !important;
    }
}

/* 広告ラッパ */
.adsense-header,
.adsense-footer {
    width: 100%;
    overflow: hidden;
}

/* 旧フラッシュメッセージ互換（必要なら） */
.success {
    color: green;
    font-weight: bold;
    margin-top: 20px;
}

.error {
    color: red;
    font-weight: bold;
    margin-top: 20px;
}

/* 任意: やや狭いコンテナ（他ページとトーンを合わせる用） */
.container--narrow {
    max-width: 960px;
}

/* login 専用: スマホ時は横幅を絞って中央寄せ、PC時は制限解除して2カラム維持 */
.auth-wrap {
    width: 100%;
    margin-inline: auto;
}

@media (max-width: 899px) {
    .auth-wrap {
        max-width: min(520px, 92vw);
    }
}

@media (min-width: 900px) {
    .auth-wrap {
        max-width: none;
    }
}

/* スマホでの入力サイズ・余白を微調整（他ページに合わせる） */
@media (max-width: 600px) {

    .auth-form input[type="text"],
    .auth-form input[type="password"] {
        padding: 9px 10px;
        font-size: 15px;
    }

    .auth-card .card-body {
        padding: 12px;
    }
}

/* ===== PCでテーブルを縦いっぱいに表示（race_output） ===== */
@media (min-width: 1024px) {

    /* テーブルカードを画面高にフィットさせる（ヘッダ/ツールバー分を差し引き） */
    .page--race .table-card {
        height: calc(100vh - 220px);
        display: flex;
        flex-direction: column;
        margin: 0 0 16px;
        min-height: 0;
        /* 子のoverflow有効化 */
    }

    .page--race .table-card .card-body {
        flex: 1;
        display: flex;
        flex-direction: column;
        padding: 8px 12px 12px;
        min-height: 0;
        /* 子のoverflow有効化 */
    }

    .page--race .table-card .notice {
        margin: 0 0 10px;
    }

    /* 生成HTML内の table-wrapper を縦に伸ばしスクロールさせる（縦横ともに） */
    .page--race .table-card .table-wrapper {
        flex: 1;
        min-height: 0;
        overflow: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* PCでもテーブルは内容幅優先（横に長いときは横スクロール） */
    .page--race .table-card #raceTable,
    .page--race .table-card .race-table {
        width: max-content !important;
    }
}

/* 横スクロールのみ許可（縦はページ全体に任せる） */
.table-wrapper {
    overflow-x: auto !important;
    overflow-y: visible !important;
    -webkit-overflow-scrolling: touch;
}

/* PC向けの「内側で縦スクロールさせる」レイアウトを解除して通常フローに戻す */
@media (min-width: 1024px) {
    .page--race .table-card {
        height: auto !important;
        display: block !important;
        margin: 16px 0 !important;
        min-height: 0 !important;
    }

    .page--race .table-card .card-body {
        flex: initial !important;
        display: block !important;
        padding: 16px 18px 18px !important;
        min-height: 0 !important;
    }

    /* 内側のコンテナで縦スクロールさせない（横だけ） */
    .page--race .table-card .table-wrapper {
        flex: initial !important;
        min-height: 0 !important;
        overflow-x: auto !important;
        overflow-y: visible !important;
    }
}

/* 参考: テーブルは内容幅に合わせて横スクロール */
#raceTable,
.race-table {
    width: max-content;
}

#raceTable th,
#raceTable td,
.race-table th,
.race-table td {
    white-space: nowrap;
}

/* thead をページスクロールに追従（Sticky は親で overflow hidden/auto にしないこと） */
#raceTable thead th {
    position: sticky;
    top: 0;
    z-index: 3;
}

/* スマホ時の segmented ボタンの調整 */
@media (max-width: 768px) {
    .button-group--segmented .btn {
        min-width: 76px;
        padding: 8px 10px;
        border-right: 1px solid #E5EAF3;
        /* スマホでも境界線を維持 */
    }

    .button-group--segmented .btn:last-child {
        border-right: 0;
    }
}