@charset "UTF-8";

/* ==========================================================================
   1. ベース・共通設定
   ========================================================================== */
*, *::before, *::after {
    box-sizing: border-box;
}

body {
    margin: 0;
    padding: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans JP", sans-serif;
    background-color: #f1f5f9;
    color: #0f172a;
    line-height: 1.6;
}

.font-numeric {
    font-variant-numeric: tabular-nums;
    font-weight: 600;
}

.font-bold {
    font-weight: 700;
    color: #0f172a;
}

.text-muted {
    color: #64748b;
}

/* ==========================================================================
   2. ヘッダー
   ========================================================================== */
.main-header {
    background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
    color: #ffffff;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 4px 20px rgba(15, 23, 42, 0.15);
    border-bottom: 2px solid #3b82f6;
}

.header-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 20px;
    height: 64px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}

.brand-text {
    font-size: 22px;
    font-weight: 900;
    letter-spacing: 0.8px;
}

.brand-text .accent-color {
    color: #38bdf8;
}

.sub-text {
    font-size: 13px;
    color: #94a3b8;
    margin-left: 12px;
    font-weight: 700;
    letter-spacing: 1px;
    border-left: 1px solid #334155;
    padding-left: 12px;
}

.header-home-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 36px;
    padding: 7px 14px;
    border: 1px solid rgba(148, 163, 184, 0.55);
    border-radius: 4px;
    background: rgba(255, 255, 255, 0.08);
    color: #ffffff;
    font-size: 13px;
    font-weight: 700;
    text-decoration: none;
    white-space: nowrap;
}

.header-home-btn:hover {
    background: #2563eb;
    border-color: #2563eb;
}

/* ==========================================================================
   3. メインレイアウト・検索フォーム
   ========================================================================== */
.main-content {
    max-width: 1200px;
    margin: 32px auto;
    padding: 0 20px;
}

.search-section {
    background-color: #ffffff;
    border-radius: 12px;
    padding: 24px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -1px rgba(0, 0, 0, 0.03);
    margin-bottom: 32px;
}

.form-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    align-items: center;
}

.select-wrapper {
    flex: 1;
    min-width: 180px;
}

.form-select {
    width: 100%;
    height: 46px;
    padding: 0 16px;
    font-size: 14px;
    font-weight: 600;
    color: #334155;
    background-color: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    outline: none;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    cursor: pointer;
}

.form-select:focus {
    border-color: #3b82f6;
    background-color: #ffffff;
    box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.15);
}

.button-group {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.btn {
    height: 46px;
    padding: 0 24px;
    font-size: 14px;
    font-weight: 700;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    white-space: nowrap;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

.btn-primary {
    background-color: #3b82f6;
    color: #ffffff;
}

.btn-primary:hover {
    background-color: #2563eb;
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
}

.btn-secondary {
    background-color: #f1f5f9;
    color: #475569;
}

.btn-secondary:hover {
    background-color: #e2e8f0;
    color: #1e293b;
}

.sort-action-btn.is-active {
    background-color: #2563eb;
    color: #ffffff;
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.3);
}

.sort-action-btn.is-active:hover {
    background-color: #1d4ed8;
    color: #ffffff;
}

.sort-action-btn:disabled {
    background-color: #e2e8f0;
    color: #94a3b8;
    cursor: not-allowed;
    opacity: 0.72;
    box-shadow: none;
}

/* 💡 SAJ連携ボタン（スタイリッシュ最適化版） */
.btn-saj {
    background-color: #10b981 !important;
    color: #ffffff !important;
    box-shadow: 0 2px 4px rgba(16, 185, 129, 0.1);
}

.btn-saj:hover:not(:disabled) {
    background-color: #059669 !important;
    box-shadow: 0 4px 12px rgba(16, 185, 129, 0.3) !important;
}

.btn-saj:disabled {
    background-color: #cbd5e1 !important;
    color: #94a3b8 !important;
    cursor: not-allowed !important;
    opacity: 0.7;
    box-shadow: none !important;
}

/* ==========================================================================
   4. リザルトテーブルセクション
   ========================================================================== */
.result-section {
    background-color: #ffffff;
    border-radius: 12px;
    padding: 32px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
}

.section-header-container {
    display: block;
    margin-bottom: 24px;
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 2px solid #f1f5f9;
    padding-bottom: 18px;
}

.section-header h2 {
    margin: 0;
    font-size: 22px;
    color: #0f172a;
    font-weight: 800;
}

.live-badge {
    font-size: 11px;
    background-color: #ecfdf5;
    color: #065f46;
    padding: 6px 14px;
    border-radius: 9999px;
    font-weight: 700;
    letter-spacing: 0.5px;
    border: 1px solid #a7f3d0;
    animation: pulse 2.5s infinite;
}

@keyframes pulse {
    0% { opacity: 0.7; transform: scale(1); }
    50% { opacity: 1; transform: scale(1.02); }
    100% { opacity: 0.7; transform: scale(1); }
}

.table-responsive-wrapper {
    width: 100%;
    overflow-x: auto;
}

.result-table {
    width: 100%;
    table-layout: fixed;
    border-collapse: collapse;
    text-align: left;
    font-size: 14px;
}

.result-table th {
    background-color: #f8fafc;
    color: #64748b;
    font-weight: 700;
    padding: 16px 14px;
    border-bottom: 2px solid #e2e8f0;
    white-space: nowrap;
}

.sort-btn {
    cursor: pointer;
    user-select: none;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    color: #3b82f6;
    transition: color 0.15s;
}

.sort-btn:hover {
    color: #1d4ed8;
}

.result-table td {
    padding: 16px 14px;
    border-bottom: 1px solid #f1f5f9;
    vertical-align: middle;
}

.result-table tbody tr.zebra-bg,
.result-table tbody tr.is-zebra {
    background-color: #e8eef6 !important;
}

.result-table tbody tr.athlete-main-row:hover {
    background-color: #dbeafe !important;
}

.col-rank { width: 75px; text-align: center; }
.col-bib { width: 75px; text-align: center; color: #64748b; }
.col-name-block { width: auto; }
.col-time { width: 130px; text-align: right; color: #334155; }
.col-total { width: 130px; text-align: right; color: #0f172a; font-size: 16px; font-weight: 700; }

.rank-badge {
    display: inline-block;
    width: 28px;
    height: 28px;
    line-height: 28px;
    border-radius: 50%;
    background-color: #3b82f6;
    color: #ffffff;
    font-weight: 700;
    font-size: 12px;
    text-align: center;
}

.time-diff-text {
    font-size: 11px;
    color: #ef4444;
    font-weight: 600;
    margin-left: 6px;
    display: inline-block;
}

.total-sp {
    display: none;
}

.time-diff {
    font-size: 12px;
    font-weight: 600;
    color: #64748b;
}

.sp-row-toggle,
.sp-accordion-row {
    display: none;
}

.sp-row-toggle {
    border: 0;
    cursor: pointer;
    line-height: 1;
}

.main-footer {
    text-align: center;
    padding: 48px 20px;
    font-size: 13px;
    color: #94a3b8;
}

/* ==========================================================================
   5. スマートフォン用レイアウト (レスポンシブファインチューニング)
   ========================================================================== */
@media (max-width: 992px) {
    .main-content {
        margin: 16px auto;
        padding: 0 8px;
    }

    .search-section {
        padding: 16px;
        border-radius: 10px;
    }

    .result-section {
        padding: 16px;
        border-radius: 10px;
    }

    .pc-only-btn, .pc-only-cell, .col-bib {
        display: none !important;
    }

    .table-responsive-wrapper {
        overflow-x: hidden;
    }

    .result-table,
    .result-table thead,
    .result-table tbody {
        display: block;
        width: 100%;
    }

    .result-table thead tr,
    .result-table tbody tr.athlete-main-row {
        display: grid;
        grid-template-columns: 55px minmax(0, 1fr) 128px;
        align-items: center;
        width: 100%;
    }

    .result-table tbody tr.athlete-main-row {
        border-bottom: 1px solid #f1f5f9;
    }

    .result-table tbody tr.athlete-main-row.is-zebra,
    .result-table tbody tr.sp-accordion-row.is-zebra.is-open {
        background-color: #e8eef6 !important;
    }

    .result-table tbody tr.athlete-main-row td {
        border-bottom: none;
    }

    .result-table {
        table-layout: fixed !important;
        width: 100% !important;
    }

    .col-rank { width: 55px !important; }
    .col-name-block { width: auto !important; min-width: 0; }
    .col-total { width: 124px !important; }

    .result-table th,
    .result-table td {
        padding: 12px 8px;
    }

    .sp-first-line {
        display: flex;
        align-items: center;
        gap: 6px;
        min-width: 0;
    }

    .sp-first-line .col-bib-sp {
        flex: 0 0 auto;
        color: #475569;
        background-color: #e2e8f0;
        padding: 2px 6px;
        border-radius: 4px;
        font-size: 11px;
        font-weight: 700;
    }

    .col-name-sp {
        flex: 1 1 auto;
        min-width: 0;
        font-weight: 700;
        font-size: 14px;
        overflow-wrap: anywhere;
    }

    .sp-second-line {
        display: block;
        margin-top: 2px;
        font-size: 12px;
        color: #64748b;
    }

    .total-cell-content {
        display: flex;
        align-items: center;
        justify-content: flex-end;
        gap: 6px;
        white-space: nowrap;
    }

    .total-pc {
        display: none;
    }

    .total-sp {
        display: inline;
    }

    .total-sp .time-diff {
        font-size: 13px;
    }

    .total-cell-content .sp-row-toggle {
        display: inline-flex !important;
        font-size: 10px;
        color: #3b82f6;
        background-color: #eff6ff;
        width: 18px;
        height: 18px;
        align-items: center;
        justify-content: center;
        border-radius: 4px;
        font-weight: bold;
    }

    .sp-accordion-row.is-open {
        display: block;
        width: 100%;
    }

    /* アコーディオン部分の質感向上 */
    .sp-accordion-td-fixed {
        display: block;
        width: 100%;
        padding: 4px 8px 12px 8px !important;
        border-bottom: 1px solid #e2e8f0 !important;
    }

    .sp-accordion-container {
        background-color: #f8fafc;
        border-radius: 8px;
        padding: 10px 14px;
        border-left: 4px solid #3b82f6;
        box-shadow: inset 0 1px 2px rgba(0,0,0,0.02);
    }

    .sp-accordion-row.is-zebra .sp-accordion-container {
        background-color: #dfe8f3;
    }

    .sp-detail-line {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 4px 0;
        border-bottom: 1px dashed #e2e8f0;
    }
    
    .sp-detail-line:last-child {
        border-bottom: none;
    }

    .sp-label-left {
        color: #64748b;
        font-weight: 700;
        font-size: 12px;
    }

    .sp-value-right {
        color: #1e293b;
        font-size: 13px;
        font-weight: 600;
        min-width: 90px;
        text-align: right;
    }

    .section-header-container {
        display: flex !important;
        flex-direction: column;
        gap: 12px;
        padding: 0 0 16px 0;
    }

    .btn-sp-sort {
        flex: 1;
        height: 40px;
        font-size: 13px;
        font-weight: 700;
        color: #475569;
        background-color: #f1f5f9;
        border: 1px solid #e2e8f0;
        border-radius: 8px;
    }

    .btn-sp-sort:active {
        background-color: #e2e8f0;
    }
}
/* ========================================================================== 
   追記：sokuho.php 完成版との接続調整
   ========================================================================== 
   既存 style.css は .main-header / .main-content / .result-table を前提にしています。
   下記は、完成版HTMLで追加した label やステータス表示などの不足分を補うCSSです。
============================================================================= */

.form-label {
    display: block;
    margin-bottom: 6px;
    font-size: 12px;
    font-weight: 800;
    color: #475569;
}

.select-wrapper-wide {
    flex: 3 1 520px;
    min-width: 420px;
}

.taikai-select {
    min-width: 100%;
}

.search-button-group {
    align-self: end;
}

.status-message {
    min-height: 22px;
    margin-top: 14px;
    font-size: 13px;
    color: #64748b;
    font-weight: 600;
}

.status-message.is-error {
    color: #dc2626;
}

.center {
    text-align: center !important;
}

.error {
    color: #dc2626;
    font-weight: 700;
}

.col-bib-sp {
    display: none;
}

@media (max-width: 992px) {
    .form-grid {
        display: flex;
        flex-direction: column;
        align-items: stretch;
    }

    .select-wrapper,
    .select-wrapper-wide {
        flex: 1 1 auto;
        width: 100%;
        min-width: 0;
    }

    .form-select {
        height: 48px;
        padding-left: 12px;
        padding-right: 12px;
        font-size: 16px;
    }

    .search-button-group {
        align-self: stretch;
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 8px;
    }

    .search-button-group .btn {
        width: 100%;
        min-width: 0;
        padding-left: 10px;
        padding-right: 10px;
        white-space: nowrap;
    }

    .col-bib-sp {
        display: inline-block;
    }
}
