/* リセットとベーススタイル */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Helvetica Neue', Arial, 'Hiragino Kaku Gothic ProN', 'Hiragino Sans', Meiryo, sans-serif;
    line-height: 1.6;
    color: #333;
    background-color: #f5f5f5;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 20px;
}

/* ヘッダー */
header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 20px 0;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
    position: relative;
}

header .header-image {
    max-width: 100%;
    height: auto;
    display: block;
    margin: 0 auto 10px;
    max-height: 120px;
    object-fit: contain;
}

/* ユーザー側ページのヘッダー画像（大きく） */
.user-page header .header-image {
    max-height: 180px;
}

/* 管理者ページのヘッダー画像（小さく） */
.admin-page header .header-image {
    max-height: 60px;
}

/* レスポンシブ対応 */
@media (max-width: 768px) {
    .user-page header .header-image {
        max-height: 120px;
    }
    
    .admin-page header .header-image {
        max-height: 40px;
    }
}

@media (max-width: 480px) {
    .user-page header .header-image {
        max-height: 80px;
    }
    
    .admin-page header .header-image {
        max-height: 30px;
    }
}

header h1 {
    font-size: 1.8rem;
    font-weight: 600;
}

header h1 .viewing-limit-info {
    display: block;
    font-size: 0.9rem;
    font-weight: normal;
    margin-top: 5px;
    color: #ffeb3b;
}

/* メイン */
main {
    margin: 40px auto;
    padding: 30px;
    background-color: white;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    min-height: 500px;
}

main h2 {
    color: #2c3e50;
    margin-bottom: 25px;
    padding-bottom: 10px;
    border-bottom: 3px solid #3498db;
    font-size: 1.8rem;
}

main h3 {
    color: #34495e;
    margin: 25px 0 15px 0;
    font-size: 1.4rem;
}

/* ボタン */
.btn {
    display: inline-block;
    padding: 10px 20px;
    margin: 5px;
    border: none;
    border-radius: 5px;
    text-decoration: none;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s ease;
    font-size: 1rem;
}

.btn-primary {
    background-color: #667eea;
    color: white;
}

.btn-primary:hover {
    background-color: #5568d3;
}

.btn-secondary {
    background-color: #95a5a6;
    color: white;
}

.btn-secondary:hover {
    background-color: #7f8c8d;
}

.btn-small {
    padding: 5px 15px;
    font-size: 0.9rem;
}

.btn-search {
    background-color: #27ae60;
    color: white;
}

.btn-search:hover {
    background-color: #229954;
}

/* テーブル */
table {
    width: 100%;
    border-collapse: collapse;
    margin: 20px 0;
}

table thead {
    background-color: #34495e;
    color: white;
}

table th,
table td {
    padding: 12px;
    text-align: left;
    border-bottom: 1px solid #ddd;
}

table tbody tr:hover {
    background-color: #f8f9fa;
}

/* テーブル内リンク */
.link-text {
    color: #3498db;
    text-decoration: none;
    font-weight: 500;
    transition: color 0.2s ease;
}

.link-text:hover {
    color: #2980b9;
    text-decoration: underline;
}

.detail-table th {
    background-color: #ecf0f1;
    color: #2c3e50;
    width: 30%;
    font-weight: 600;
}

/* カード */
.taikai-list,
.feature-list,
.admin-menu {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 20px;
    margin: 30px 0;
}

.taikai-card,
.feature-card,
.menu-card {
    background-color: white;
    border: 1px solid #ddd;
    border-radius: 8px;
    padding: 25px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.taikai-card:hover,
.feature-card:hover,
.menu-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 5px 15px rgba(0,0,0,0.15);
}

.taikai-card h3,
.feature-card h3,
.menu-card h3 {
    color: #2c3e50;
    margin-bottom: 10px;
}

.taikai-card p,
.feature-card p,
.menu-card p {
    color: #7f8c8d;
    margin-bottom: 15px;
}

/* 検索フォーム */
.search-form {
    margin: 20px 0;
    padding: 20px;
    background-color: #f8f9fa;
    border-radius: 5px;
}

.search-input {
    width: 60%;
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 5px;
    font-size: 1rem;
}

/* セクション */
.division-section,
.overall-division-section,
.runner-info,
.record-info,
.checkpoint-info {
    margin: 30px 0;
}

/* アクション */
.actions {
    margin: 30px 0;
    text-align: center;
}

/* その他 */
.no-data {
    text-align: center;
    color: #7f8c8d;
    padding: 40px;
    font-size: 1.1rem;
}

.record-type-links {
    margin: 20px 0;
    padding: 15px;
    background-color: #f8f9fa;
    border-left: 4px solid #667eea;
    border-radius: 4px;
}

.record-type-links a {
    color: #667eea;
    text-decoration: none;
    font-weight: 500;
}

.record-type-links a:hover {
    text-decoration: underline;
}

.runner-refresh-panel {
    margin: 16px 0 24px;
    padding: 14px 16px;
    border: 1px solid #d9e2f0;
    border-radius: 8px;
    background: #f8fbff;
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: center;
    justify-content: space-between;
}

.runner-refresh-controls {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
}

.runner-refresh-button {
    border: 1px solid #4b6cb7;
    background: #4b6cb7;
    color: #fff;
    border-radius: 6px;
    padding: 8px 12px;
    cursor: pointer;
    font-size: 0.95rem;
}

.runner-refresh-button:hover {
    background: #36589a;
}

.runner-refresh-toggle {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    border: none;
    background: transparent;
    padding: 0;
    cursor: pointer;
    font-size: 0.95rem;
    color: #4a5568;
    font-weight: 600;
}

.runner-refresh-toggle-slider {
    position: relative;
    width: 46px;
    height: 26px;
    border-radius: 999px;
    background: #cbd5e1;
    border: 1px solid #cbd5e1;
    transition: background-color 0.2s ease;
    flex-shrink: 0;
    box-shadow: inset 0 1px 2px rgba(15, 23, 42, 0.08);
}

.runner-refresh-toggle-slider::after {
    content: '';
    position: absolute;
    top: 3px;
    left: 3px;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
    transition: transform 0.2s ease;
}

.runner-refresh-toggle.is-on .runner-refresh-toggle-slider {
    background: #34c759;
}

.runner-refresh-toggle.is-on .runner-refresh-toggle-slider::after {
    transform: translateX(20px);
}

.runner-refresh-toggle-label {
    min-width: 2.4em;
    letter-spacing: 0.04em;
}

.runner-refresh-toggle.is-on .runner-refresh-toggle-label {
    color: #157f3b;
}

.runner-refresh-toggle.is-off .runner-refresh-toggle-label {
    color: #64748b;
}

.runner-refresh-status {
    font-size: 0.95rem;
    color: #4a5568;
}

.runner-refresh-help {
    width: 100%;
    font-size: 0.9rem;
    color: #4a5568;
    line-height: 1.5;
    margin: 0 0 8px 0;
}

.back-link {
    margin-top: 30px;
    padding-top: 20px;
    border-top: 1px solid #ddd;
}

.back-link a {
    color: #3498db;
    text-decoration: none;
}

.back-link a:hover {
    text-decoration: underline;
}

.admin-link {
    text-align: center;
    margin-top: 30px;
    padding-top: 20px;
    border-top: 1px solid #ddd;
}

.admin-link a {
    color: #e74c3c;
    text-decoration: none;
    font-weight: 600;
}

.admin-link a:hover {
    text-decoration: underline;
}

/* フッター */
footer {
    background-color: #2c3e50;
    color: white;
    text-align: center;
    padding: 20px 0;
    margin-top: 50px;
}

/* レスポンシブ対応（ユーザー側ページ） */
@media (max-width: 768px) {
    /* 基本レイアウト */
    .container {
        padding: 0 10px;
    }
    
    .user-page main {
        margin: 20px auto;
        padding: 15px;
    }
    
    .user-page header h1 {
        font-size: 1.4rem;
    }
    
    /* 検索フォーム */
    .search-form form {
        display: flex;
        flex-direction: column;
        gap: 10px;
    }
    
    .search-input {
        width: 100%;
        box-sizing: border-box;
        margin: 0;
    }
    
    .btn {
        width: 100%;
        margin: 0;
        box-sizing: border-box;
    }
    
    /* テーブルをスクロール可能に */
    .table-wrapper {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    table {
        font-size: 0.85rem;
        width: 100%;
        table-layout: fixed;
    }
    
    table th,
    table td {
        padding: 8px 6px;
        word-wrap: break-word;
    }
    
    /* カードレイアウト */
    .taikai-list,
    .feature-list {
        grid-template-columns: 1fr;
        gap: 15px;
    }
    
    .taikai-card,
    .feature-card {
        padding: 20px;
    }
    
    /* タブ */
    .tab-button {
        padding: 10px 16px;
        font-size: 14px;
    }
    
    /* 詳細テーブル */
    .detail-table th,
    .detail-table td {
        display: block;
        width: 100%;
    }
    
    .detail-table th {
        border-bottom: none;
        padding-bottom: 5px;
    }
    
    .detail-table td {
        padding-top: 5px;
        padding-bottom: 15px;
        border-bottom: 1px solid #ddd;
    }
}

@media (max-width: 480px) {
    .user-page header h1 {
        font-size: 1.2rem;
    }
    
    .user-page main h2 {
        font-size: 1.4rem;
    }
    
    .user-page main h3 {
        font-size: 1.1rem;
    }
    
    table {
        font-size: 0.75rem;
        width: 100%;
        table-layout: fixed;
    }
    
    table th,
    table td {
        padding: 6px 4px;
        word-wrap: break-word;
    }
    
    .tab-button {
        padding: 8px 12px;
        font-size: 13px;
    }
    
    .taikai-card h3,
    .feature-card h3 {
        font-size: 1.2rem;
    }
}

/* iPhone SE など小画面対応（320px〜375px） */
@media (max-width: 375px) {
    .user-page .container {
        padding: 0 8px;
    }
    
    .user-page main {
        margin: 15px auto;
        padding: 12px;
    }
    
    .user-page header h1 {
        font-size: 1rem;
    }
    
    .user-page main h2 {
        font-size: 1.2rem;
    }
    
    .user-page main h3 {
        font-size: 1rem;
    }
    
    /* 検索フォーム */
    .search-form {
        padding: 15px;
    }
    
    .search-form h3 {
        font-size: 1rem;
    }
    
    .search-input {
        font-size: 14px;
        padding: 10px;
    }
    
    .btn {
        padding: 10px 15px;
        font-size: 14px;
    }
    
    .btn-small {
        padding: 6px 10px;
        font-size: 12px;
    }
    
    /* タブ */
    .tabs-header {
        display: flex;
        gap: 5px;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        margin-bottom: 15px;
    }
    
    .tab-button {
        padding: 8px 12px;
        font-size: 12px;
        white-space: nowrap;
        flex-shrink: 0;
        min-width: auto;
    }
    
    /* テーブル */
    .table-wrapper {
        width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        margin: 10px 0;
    }
    
    table {
        font-size: 0.7rem;
        width: 100%;
        table-layout: fixed;
    }
    
    table th,
    table td {
        padding: 6px 4px;
        word-wrap: break-word;
        overflow-wrap: break-word;
    }
    
    /* 部門一覧テーブル */
    .division-table th:first-child,
    .division-table td:first-child {
        width: 25%;
        text-align: center;
    }
    
    .division-table th:last-child,
    .division-table td:last-child {
        width: 75%;
    }
    
    /* 記録一覧テーブル（5列：順位、ゼッケン、氏名、記録、上位との差） */
    .records-table th:nth-child(1),
    .records-table td:nth-child(1) {
        width: 12%;
        text-align: center;
    }
    
    .records-table th:nth-child(2),
    .records-table td:nth-child(2) {
        width: 15%;
        text-align: center;
    }
    
    .records-table th:nth-child(3),
    .records-table td:nth-child(3) {
        width: 35%;
    }
    
    .records-table th:nth-child(4),
    .records-table td:nth-child(4) {
        width: 19%;
        text-align: center;
        font-size: 0.65rem;
    }
    
    .records-table th:nth-child(5),
    .records-table td:nth-child(5) {
        width: 19%;
        text-align: center;
        font-size: 0.65rem;
    }
    
    /* 検索結果テーブル */
    .results-table th:nth-child(1),
    .results-table td:nth-child(1) {
        width: 13%;
        text-align: center;
    }
    
    .results-table th:nth-child(2),
    .results-table td:nth-child(2) {
        width: 27%;
    }
    
    .results-table th:nth-child(3),
    .results-table td:nth-child(3) {
        display: none;
    }
    
    .results-table th:nth-child(4),
    .results-table td:nth-child(4) {
        width: 10%;
        text-align: center;
    }
    
    .results-table th:nth-child(5),
    .results-table td:nth-child(5) {
        width: 15%;
        font-size: 0.6rem;
    }
    
    .results-table th:nth-child(6),
    .results-table td:nth-child(6) {
        width: 20%;
        text-align: center;
        font-size: 0.6rem;
    }
    
    .results-table th:nth-child(7),
    .results-table td:nth-child(7) {
        width: 15%;
        text-align: center;
    }
    
    /* カード */
    .taikai-card,
    .feature-card {
        padding: 15px;
    }
    
    .taikai-card h3,
    .feature-card h3 {
        font-size: 1.1rem;
    }
    
    .taikai-card p,
    .feature-card p {
        font-size: 0.85rem;
    }
    
    /* 詳細情報 */
    .detail-table {
        font-size: 0.85rem;
    }
    
    .detail-table th,
    .detail-table td {
        padding: 8px;
    }
    
    /* 検索ヘルプ */
    .search-help {
        font-size: 11px;
    }
}

/* 超小画面対応（iPhone SE第1世代: 320px） */
@media (max-width: 320px) {
    .user-page header h1 {
        font-size: 0.9rem;
    }
    
    .user-page main h2 {
        font-size: 1.1rem;
    }
    
    .tab-button {
        font-size: 11px;
        padding: 6px 8px;
    }
    
    table {
        font-size: 0.65rem;
    }
    
    table th,
    table td {
        padding: 5px 3px;
    }
    
    .btn {
        font-size: 13px;
        padding: 8px 12px;
    }
    
    .btn-small {
        font-size: 11px;
        padding: 5px 8px;
    }
}

/* 追加スタイル - 大会ロゴ・カスタムバナー */
.taikai-logo {
    max-width: 200px;
    margin: 10px 0;
}

.custom-banner {
    background-color: #f0f4ff;
    border-left: 4px solid #667eea;
    padding: 15px;
    margin: 20px 0;
    border-radius: 4px;
}

.custom-banner h3 {
    color: #667eea;
    margin-top: 0;
}

/* フラッシュメッセージ */
.flash-messages {
    margin: 20px 0;
}

.flash-message {
    padding: 15px;
    margin: 10px 0;
    border-radius: 5px;
    border-left: 4px solid;
}

.flash-success {
    background-color: #d4edda;
    border-color: #28a745;
    color: #155724;
}

.flash-error {
    background-color: #f8d7da;
    border-color: #dc3545;
    color: #721c24;
}

.flash-warning {
    background-color: #fff3cd;
    border-color: #ffc107;
    color: #856404;
}

.flash-info {
    background-color: #d1ecf1;
    border-color: #17a2b8;
    color: #0c5460;
}

/* ==========================================================
   タブナビゲーション（共通）
   ========================================================== */
.laps-tabs {
    display: flex;
    gap: 8px;
    margin-bottom: 20px;
    border-bottom: 2px solid #e0e0e0;
    overflow-x: auto;
}

.tab-button {
    padding: 12px 24px;
    background: #f5f5f5;
    border: none;
    border-bottom: 3px solid transparent;
    cursor: pointer;
    font-size: 16px;
    font-weight: 500;
    transition: all 0.3s;
    white-space: nowrap;
}

.tab-button:hover {
    background: #e8f4f8;
}

.tab-button.active {
    background: white;
    border-bottom-color: #2196F3;
    color: #2196F3;
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

/* ==========================================================
   ページネーション（共通）
   ========================================================== */
.pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 20px;
    margin-top: 20px;
    padding: 20px;
}

.page-btn {
    padding: 8px 16px;
    background: #2196F3;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    transition: background 0.3s;
}

.page-btn:hover:not(:disabled) {
    background: #1976D2;
}

.page-btn:disabled {
    background: #ccc;
    cursor: not-allowed;
}

.page-info {
    font-size: 16px;
    font-weight: 500;
}

.current-page {
    color: #2196F3;
    font-weight: bold;
}

/* レスポンシブ対応 */
@media (max-width: 768px) {
    .laps-tabs {
        gap: 4px;
    }
    
    .tab-button {
        padding: 10px 16px;
        font-size: 14px;
    }
    
    .pagination {
        gap: 10px;
        padding: 15px;
    }
    
    .page-btn {
        padding: 6px 12px;
        font-size: 13px;
    }
    
    .page-info {
        font-size: 14px;
    }
}

/* 記録証プレビュー */
.certificate-preview {
    margin: 30px 0;
    padding: 20px;
    background: #f9f9f9;
    border-radius: 8px;
    border: 1px solid #e0e0e0;
}

.certificate-preview h3 {
    margin-bottom: 15px;
    color: #2c3e50;
    font-size: 18px;
}

.preview-image-container {
    text-align: center;
    background: white;
    padding: 20px;
    border-radius: 4px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.certificate-preview-image {
    max-width: 100%;
    height: auto;
    border: 1px solid #ddd;
    border-radius: 4px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

@media (max-width: 768px) {
    .certificate-preview {
        padding: 15px;
    }
    
    .certificate-preview h3 {
        font-size: 16px;
    }
    
    .preview-image-container {
        padding: 10px;
    }
}

/* 順位変動矢印 */
.rank-arrow {
    margin-left: 5px;
    font-weight: bold;
    font-size: 16px;
}

.rank-up {
    color: #d32f2f; /* 赤 */
}

.rank-down {
    color: #1976d2; /* 青 */
}

.rank-same {
    color: #388e3c; /* 緑 */
}

/* オリジナル画像アップロード */
.custom-image-upload {
    margin: 30px 0;
    padding: 20px;
    background: #f9f9f9;
    border-radius: 8px;
    border: 1px solid #e0e0e0;
}

.custom-image-upload h3 {
    margin-bottom: 10px;
    color: #2c3e50;
    font-size: 18px;
}

.upload-hint {
    font-size: 14px;
    color: #666;
    margin-bottom: 15px;
}

.upload-area {
    background: white;
    padding: 20px;
    border-radius: 4px;
    border: 2px dashed #ddd;
}

.file-input-wrapper {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.file-input-label {
    display: inline-block;
    padding: 10px 20px;
    background: #667eea;
    color: white;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    transition: background 0.3s;
}

.file-input-label:hover {
    background: #5568d3;
}

.selected-file-name {
    font-size: 14px;
    color: #333;
    flex: 1;
    min-width: 200px;
}

.upload-status {
    margin-top: 10px;
    padding: 10px;
    border-radius: 4px;
    font-size: 14px;
}

.upload-status.uploading {
    background: #fff3cd;
    color: #856404;
}

.upload-status.success {
    background: #d4edda;
    color: #155724;
}

.upload-status.error {
    background: #f8d7da;
    color: #721c24;
}

@media (max-width: 768px) {
    .custom-image-upload {
        padding: 15px;
    }
    
    .custom-image-upload h3 {
        font-size: 16px;
    }
    
    .file-input-wrapper {
        flex-direction: column;
        align-items: stretch;
    }
    
    .file-input-label {
        text-align: center;
    }
}

/* 記録推移グラフ */
.performance-graph {
    background: white;
    padding: 30px;
    margin: 30px 0;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.performance-graph h3 {
    color: #333;
    margin-bottom: 20px;
    font-size: 20px;
    font-weight: 600;
    padding-bottom: 10px;
    border-bottom: 2px solid #667eea;
}

.graph-container {
    position: relative;
    height: 400px;
    margin: 20px 0;
    width: 100%;
}

.graph-container canvas {
    max-width: 100%;
}

@media (max-width: 768px) {
    .performance-graph {
        padding: 15px 10px;
        margin: 20px 0;
    }
    
    .performance-graph h3 {
        font-size: 16px;
        margin-bottom: 15px;
    }
    
    .graph-container {
        height: 350px;
        margin: 15px 0;
    }
}

@media (max-width: 480px) {
    .performance-graph {
        padding: 12px 8px;
        margin: 15px -10px;
        border-radius: 0;
    }
    
    .performance-graph h3 {
        font-size: 15px;
        margin-bottom: 12px;
    }
    
    .graph-container {
        height: 320px;
        margin: 10px 0;
    }
}
