/* --- ベーススタイル --- */
body {
    font-family: 'Helvetica Neue', Arial, sans-serif;
    padding: 15px;
    margin: 0;
    background-color: #f0f4f8;
    background-image:
        radial-gradient(circle at 12% 18%, rgba(37, 99, 235, 0.14) 0%, rgba(37, 99, 235, 0) 42%),
        radial-gradient(circle at 88% 12%, rgba(14, 165, 233, 0.12) 0%, rgba(14, 165, 233, 0) 38%),
        linear-gradient(145deg, #f8fbff 0%, #eef3f8 100%);
    background-attachment: fixed;
    color: #333;
}

h2, h3 {
    color: #2c3e50;
    text-align: center;
    margin-top: 0;
}

.card {
    background: #fff;
    padding: 20px;
    border-radius: 10px;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
    margin-bottom: 20px;
}

.form-group { margin-bottom: 15px; }
label { display: block; font-weight: bold; margin-bottom: 5px; font-size: 14px; }
select { width: 100%; padding: 10px; font-size: 16px; border: 1px solid #cbd5e1; border-radius: 8px; background-color: #f8fafc; box-sizing: border-box; }

.rank-group { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 8px; }
.rank-group label {
    min-width: 0; text-align: center; background: #e2e8f0;
    padding: 10px 0; border-radius: 8px; cursor: pointer; font-weight: bold; font-size: 16px; transition: 0.2s;
}
.rank-group input[type="radio"] { display: none; }
.rank-group input[type="radio"]:checked + label { background: #f59e0b; color: #fff; box-shadow: 0 2px 4px rgba(245, 158, 11, 0.4); }

button { width: 100%; padding: 12px; font-size: 16px; font-weight: bold; color: white; border: none; border-radius: 8px; cursor: pointer; transition: 0.2s; margin-bottom: 5px; text-shadow: 0 1px 2px rgba(0, 0, 0, 0.62), 0 0 1px rgba(0, 0, 0, 0.72); }
.btn-nav-link {
    display: block;
    width: 100%;
    box-sizing: border-box;
    text-align: center;
    padding: 12px;
    font-size: 16px;
    font-weight: bold;
    color: white;
    background-color: #0f766e;
    border-radius: 8px;
    text-decoration: none;
    margin-bottom: 10px;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.62), 0 0 1px rgba(0, 0, 0, 0.72);
}
.btn-nav-link:hover { background-color: #0d6660; }
.btn-nav-link.btn-compact {
    padding: 8px;
    font-size: 14px;
    margin-bottom: 8px;
}
.btn-nav-link.disabled {
    background-color: #94a3b8;
    cursor: not-allowed;
    pointer-events: none;
    opacity: 0.6;
}
#btnToGlobal {
    background-color: #7c3aed;
}
#btnToGlobal:hover {
    background-color: #6d28d9;
}
.mode-links-row {
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
    margin-top: -2px;
    margin-bottom: 8px;
}
.mode-links-row .btn-nav-link {
    margin-bottom: 0;
}
.btn-mode-sub {
    background-color: #475569;
}
.btn-mode-sub:hover {
    background-color: #334155;
}
.btn-mode-sub.btn-mode-air {
    background-color: #dc2626;
}
.btn-mode-sub.btn-mode-air:hover {
    background-color: #b91c1c;
}
.btn-mode-sub.btn-mode-top {
    background-color: #d97706;
}
.btn-mode-sub.btn-mode-top:hover {
    background-color: #b45309;
}
.btn-mode-sub.btn-mode-city {
    background-color: #16a34a;
}
.btn-mode-sub.btn-mode-city:hover {
    background-color: #15803d;
}
.global-hint {
    text-align: center;
    font-size: 12px;
    background-color: #6366f1;
    margin-top: -5px;
    margin-bottom: 10px;
    font-weight: 600;
}
.btn-submit {
    background-color: #2563eb;
    font-size: 18px;
    padding: 14px;
    margin-top: 8px;
    box-shadow: 0 6px 14px rgba(37, 99, 235, 0.35);
    border: 2px solid #1d4ed8;
}
.btn-submit:hover { background-color: #1d4ed8; transform: translateY(-1px); }
.btn-submit:active { background-color: #1e40af; transform: translateY(0); }
.btn-submit:disabled { background-color: #94a3b8; cursor: not-allowed; }
.btn-csv { background-color: #10b981; }
.btn-delete { background-color: #ef4444; margin-top: 10px; display: none; }
.btn-sync { background-color: #0ea5e9; }
.overall-summary-grid--5 {
    grid-template-columns: repeat(5, minmax(0, 1fr));
}
.btn-compact {
    padding: 8px 10px;
    font-size: 14px;
}
.mode-toggle-btn {
    font-size: 14px;
}

#modePageTitle .title-main {
    display: block;
}

#modePageTitle .title-mode {
    display: block;
    margin-top: 4px;
    font-size: 18px;
    font-weight: 800;
}

#modePageTitle .title-mode.theme-airRide {
    color: #dc2626;
}

#modePageTitle .title-mode.theme-topRide {
    color: #d97706;
}

/* --- 認証用・管理者用スタイル --- */
.btn-login { background-color: #ef4444; }
.btn-link { background-color: #4285F4; }
.btn-guest { background-color: #0ea5e9; }
.btn-logout { background-color: #64748b; margin-top: 10px; }
#authSection { text-align: center; margin-bottom: 15px; padding: 15px; }
#userInfo { font-weight: bold; color: #3b82f6; margin-bottom: 5px; font-size: 15px; }
#authSubMessage { font-size: 12px; color: #64748b; margin-bottom: 15px; }
#appContent { display: none; }

#message { text-align: center; font-weight: bold; color: #10b981; min-height: 24px; margin-bottom: 10px; }
#syncStatus { text-align: center; font-size: 12px; color: #64748b; margin-bottom: 10px; font-weight: bold; }

/* --- グラフ・レイアウト関連 --- */
.section-header { text-align: center; font-size: 18px; color: #1e293b; border-bottom: 2px solid #cbd5e1; padding-bottom: 8px; margin-bottom: 15px; font-weight: bold; }
.chart-title { text-align: center; font-size: 14px; font-weight: bold; color: #475569; margin-bottom: 5px; }
.chart-note { text-align: center; font-size: 11px; color: #64748b; margin-bottom: 5px; }
.overall-summary-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
}
.overall-summary-grid--4 {
    grid-template-columns: repeat(4, minmax(0, 1fr));
}
.overall-stat {
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    padding: 12px 10px;
    text-align: center;
}
.overall-stat-label {
    font-size: 12px;
    color: #64748b;
    margin-bottom: 6px;
    font-weight: 700;
}
.overall-stat-value {
    font-size: 22px;
    color: #0f172a;
    font-weight: 800;
    line-height: 1.2;
}

.chart-container { position: relative; height: 300px; width: 100%; min-width: 0; overflow-x: auto; overflow-y: hidden; -webkit-overflow-scrolling: touch; }
.chart-container canvas { display: block; }
.chart-box { min-width: 0; width: 100%; margin-bottom: 0; }

/* --- モバイルファースト: 992px未満は常に1カラム --- */
body { overflow-x: hidden; }
.main-layout {
    display: grid;
    grid-template-columns: 1fr;
    gap: 20px;
    width: 100%;
    max-width: 100%;
    margin: 0 auto;
}
.left-col,
.right-col {
    width: 100%;
    min-width: 0;
    max-width: 100%;
}
.card {
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    overflow-x: hidden;
}
.chart-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 20px;
    width: 100%;
    min-width: 0;
}
.chart-grid > * {
    min-width: 0;
    width: 100%;
}
body.layout-mobile .overall-summary-grid {
    grid-template-columns: 1fr;
}
body.layout-mobile .overall-stat-value {
    font-size: 20px;
}

/* --- デスクトップ: 共通閾値より広い時に2カラム表示 --- */
body.layout-desktop { box-sizing: border-box; padding: 15px 20px; overflow-y: auto; }
body.layout-desktop .main-layout {
    display: grid;
    grid-template-columns: 320px minmax(0, 1fr);
    gap: 20px;
    align-items: start;
}
body.layout-desktop .left-col {
    display: flex;
    flex-direction: column;
    gap: 0;
    min-height: 0;
    overflow: visible;
}
body.layout-desktop .left-col > .card { margin-bottom: 0; min-width: 0; }
body.layout-desktop .left-col > #appContent { flex: 0 0 auto; display: flex; flex-direction: column; min-height: 0; }
body.layout-desktop #appContent {
    min-height: 0;
    overflow: visible;
}
body.layout-desktop #appContent > .card {
    margin-bottom: 0;
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
}
body.layout-desktop #authSection {
    border-top-left-radius: 0;
    border-top-right-radius: 0;
    border-top: 1px solid #e2e8f0;
}

body.layout-desktop .right-col {
    display: flex;
    flex-direction: column;
    gap: 15px;
    min-width: 0;
    overflow: visible;
}
body.layout-desktop .right-col > .card {
    display: flex;
    flex-direction: column;
    margin-bottom: 0;
    padding: 12px 20px;
    min-width: 0;
    min-height: 0;
    flex-shrink: 0;
}

body.layout-desktop .chart-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}
body.layout-desktop #headerRiderStats + .chart-grid,
body.layout-desktop #headerCourseStats + .chart-grid,
body.layout-desktop #headerMachineStats + .chart-grid,
body.layout-desktop #headerCourseMachineStats + .chart-grid {
    grid-template-columns: 1fr;
    gap: 24px;
}
body.layout-desktop #headerRiderStats + .chart-grid .chart-container,
body.layout-desktop #headerCourseStats + .chart-grid .chart-container,
body.layout-desktop #headerMachineStats + .chart-grid .chart-container,
body.layout-desktop #headerCourseMachineStats + .chart-grid .chart-container {
    height: 300px;
    min-height: 300px;
}
body.layout-desktop .chart-box {
    display: flex;
    flex-direction: column;
    min-height: 0;
    min-width: 0;
}
body.layout-desktop .chart-container {
    flex: 1;
    height: auto;
    min-height: 0;
    width: 100%;
}
.chart-grid::-webkit-scrollbar { height: 8px; }
.chart-grid::-webkit-scrollbar-track { background: #f1f5f9; border-radius: 4px; }
.chart-grid::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 4px; }

@media (max-width: 480px) {
    .rank-group {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }

    .rank-group label {
        font-size: 15px;
        padding: 10px 0;
    }
}
