:root {
    --ey-yellow: #ffe600;
    --ey-dark: #2e2e38;
    --ey-gray: #747480;
    --bg: #f6f6fa;
    --border: #c4c4cd;
    --changed: #e3120b;
}

* {
    box-sizing: border-box;
}

html,
body {
    /* 横方向のはみ出し・横スクロールを防ぐ（特にスマホで指が左右に動くのを防止） */
    overflow-x: hidden;
    max-width: 100%;
}

body {
    margin: 0;
    font-family: "Segoe UI", "Hiragino Kaku Gothic ProN", Meiryo, sans-serif;
    color: var(--ey-dark);
    background: var(--bg);
}

.app-header {
    background: var(--ey-dark);
    color: #fff;
    padding: 12px 20px;
    position: sticky;
    top: 0;
    z-index: 10;
}

.app-header h1 {
    margin: 0 0 8px;
    font-size: 18px;
}

/* --- ログイン / ユーザー表示 --- */
.user-box {
    margin-left: auto;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.user-name {
    color: #fff;
    font-size: 13px;
    opacity: 0.9;
}

.login-overlay {
    position: fixed;
    inset: 0;
    background: rgba(46, 46, 56, 0.92);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
}

.login-card {
    background: #fff;
    border-radius: 8px;
    padding: 32px 28px;
    max-width: 420px;
    width: 90%;
    text-align: center;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.35);
}

.login-card h2 {
    margin: 0 0 12px;
    color: var(--ey-dark);
}

.login-card p {
    color: var(--ey-gray);
    font-size: 14px;
    line-height: 1.6;
}

.login-google {
    display: inline-block;
    margin-top: 12px;
    padding: 12px 22px;
    background: var(--ey-yellow);
    color: var(--ey-dark);
    font-weight: 700;
    border-radius: 6px;
    text-decoration: none;
}

.login-note {
    margin-top: 16px;
    font-size: 12px;
    color: var(--changed);
}

.app-header h1::before {
    content: "";
    display: inline-block;
    width: 10px;
    height: 16px;
    background: var(--ey-yellow);
    margin-right: 8px;
    vertical-align: middle;
}

.header-controls {
    display: flex;
    align-items: center;
    gap: 14px;
    flex-wrap: wrap;
}

.header-controls label,
.header-controls .ctrl-id {
    display: flex;
    flex-direction: column;
    font-size: 12px;
    gap: 3px;
}

.header-controls input {
    padding: 6px 8px;
    border: 1px solid var(--border);
    border-radius: 4px;
    font-size: 14px;
}

.combo {
    position: relative;
    display: inline-flex;
    align-items: stretch;
}

.combo > input {
    padding-right: 30px;
    min-width: 360px;
}

/* 記録セレクタは readonly（選択専用）。編集に見えないよう caret を消しポインタにする */
#speedhive-id[readonly] {
    caret-color: transparent;
    cursor: pointer;
    background: #fff;
}

.combo-toggle {
    position: absolute;
    right: 1px;
    top: 1px;
    bottom: 1px;
    width: 28px;
    border: none;
    border-left: 1px solid var(--border);
    background: #fff;
    color: var(--ey-dark);
    cursor: pointer;
    font-size: 11px;
    border-radius: 0 4px 4px 0;
}

.combo-list {
    position: absolute;
    top: calc(100% + 2px);
    left: 0;
    right: 0;
    margin: 0;
    padding: 4px 0;
    list-style: none;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 4px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.18);
    max-height: 280px;
    overflow-y: auto;
    z-index: 50;
    min-width: 100%;
    width: max-content;
    max-width: 90vw;
}

.combo-list li {
    padding: 10px 12px;
    font-size: 13px;
    color: var(--ey-dark);
    cursor: pointer;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.combo-list li:hover {
    background: var(--ey-yellow);
}

/* ゲスト用サンプル項目 */
.combo-list li.combo-sample {
    font-weight: 700;
    color: var(--ey-dark);
    white-space: normal;
}

.combo-empty {
    color: #888;
    cursor: default !important;
}

.combo-empty:hover {
    background: transparent !important;
}

.icon-btn {
    background: #fff;
    color: var(--ey-dark);
    border: 1px solid var(--border);
    width: 38px;
    height: 38px;
    border-radius: 4px;
    cursor: pointer;
    align-self: flex-end;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    transition: background 0.15s, color 0.15s;
}

.icon-btn:hover {
    background: var(--ey-yellow);
    color: var(--ey-dark);
}

.icon-btn svg {
    width: 22px;
    height: 22px;
    flex: none;
}

.icon-btn:disabled {
    opacity: 0.5;
    cursor: progress;
}

.icon-btn-danger:hover {
    background: #ff5252;
    color: #fff;
    border-color: #ff5252;
}

.icon-btn-primary {
    background: var(--ey-yellow);
    color: var(--ey-dark);
    border-color: var(--ey-yellow);
}

.icon-btn-primary:hover {
    background: var(--ey-yellow);
    color: var(--ey-dark);
    filter: brightness(0.95);
}

/* ヘッダーのテキストボタン（取り込み / 更新） */
.text-btn {
    background: #fff;
    color: var(--ey-dark);
    border: 1px solid var(--border);
    height: 38px;
    padding: 0 14px;
    font-size: 13px;
    font-weight: 700;
    border-radius: 4px;
    cursor: pointer;
    align-self: flex-end;
    transition: background 0.15s, color 0.15s;
}

.text-btn:hover {
    background: #f0f0f5;
}

.text-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.text-btn-primary {
    background: var(--ey-yellow);
    color: var(--ey-dark);
    border-color: var(--ey-yellow);
}

.text-btn-primary:hover {
    background: var(--ey-yellow);
    filter: brightness(0.95);
}

/* 取り込みチューザ */
.im-source {
    display: flex;
    gap: 16px;
    margin-bottom: 12px;
    font-weight: 600;
}

.im-source label {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
}

.im-field {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-bottom: 10px;
    font-size: 13px;
    font-weight: 600;
}

.im-field input {
    padding: 7px 9px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 14px;
}

.status {
    font-size: 12px;
    align-self: flex-end;
    color: var(--ey-yellow);
}

.status.error {
    color: #ff8a80;
}

.secondary-btn {
    background: #fff;
    color: var(--ey-dark);
    border: 1px solid var(--border);
    padding: 6px 12px;
    font-size: 13px;
    border-radius: 4px;
    cursor: pointer;
}

.secondary-btn:hover {
    background: #f0f0f5;
}

.app-header .secondary-btn {
    align-self: flex-end;
}

.header-controls select {
    padding: 6px 8px;
    border: 1px solid var(--border);
    border-radius: 4px;
    font-size: 14px;
    min-width: 130px;
}

.copy-paste-group {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 6px;
}

.back-to-boxplot {
    color: #747480;
    font-size: 12px;
    text-decoration: none;
    white-space: nowrap;
    padding: 4px 6px;
    border-radius: 4px;
}

.back-to-boxplot:hover {
    color: #2e2e38;
    background: #f3f3f5;
    text-decoration: underline;
}

main {
    padding: 20px;
    max-width: 1100px;
    margin: 0 auto;
}

.hidden {
    display: none;
}

#boxplot-section {
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 14px;
    margin-bottom: 20px;
}

#tire-usage-section {
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 14px;
    margin-bottom: 20px;
}

#tire-usage-section h2 {
    font-size: 15px;
    margin: 0 0 10px;
}

.tire-usage-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

.tire-usage-table th,
.tire-usage-table td {
    border: 1px solid var(--border);
    padding: 6px 10px;
    text-align: left;
}

.tire-usage-table th {
    background: #f0f0f5;
    font-size: 12px;
}

.tire-usage-table .num {
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.tire-usage-table .total {
    font-weight: 700;
}

/* --- 管理者（マスターアカウント）メニュー --- */
.admin-guard {
    padding: 16px;
    color: var(--ey-gray);
    font-size: 14px;
}

.admin-section {
    border: 1px solid var(--border);
    border-left: 4px solid var(--ey-yellow);
    border-radius: 6px;
    padding: 12px 16px;
    margin-bottom: 16px;
    background: #fbfbf3;
}

.admin-total {
    font-size: 13px;
    color: var(--ey-dark);
    margin-bottom: 10px;
}

.admin-users-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
    margin-bottom: 12px;
}

.admin-users-table th,
.admin-users-table td {
    border: 1px solid var(--border);
    padding: 6px 10px;
    text-align: left;
    word-break: break-all;
}

.admin-users-table th {
    background: #f0f0f5;
    font-size: 12px;
}

.admin-users-table .num {
    text-align: right;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.admin-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
}

.admin-upload {
    display: inline-flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
}

.session-meta {
    font-size: 12px;
    color: var(--ey-gray);
    margin: -4px 0 10px;
}

.hint {
    font-size: 11px;
    font-weight: 400;
    color: var(--ey-gray);
    margin-left: 8px;
}

.circuit-name {
    font-size: 18px;
    font-weight: 700;
    color: var(--ey-dark);
    margin: 0 0 6px;
    padding: 6px 10px;
    border-left: 4px solid var(--ey-yellow);
    background: #faf9f5;
}

.box-tooltip {
    position: fixed;
    z-index: 1000;
    max-width: 320px;
    background: #2e2e38;
    color: #fff;
    border: 1px solid #ffe600;
    border-radius: 6px;
    padding: 8px 10px;
    font-size: 12px;
    line-height: 1.5;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.3);
    pointer-events: none;
}

.box-tooltip .bt-title {
    font-weight: 700;
    color: #ffe600;
    margin-bottom: 4px;
}

.box-tooltip .bt-empty {
    color: #c9c9d1;
}

.box-tooltip ul {
    margin: 0;
    padding-left: 16px;
}

.box-tooltip li {
    margin: 2px 0;
}

.box-tooltip .bt-key {
    color: #c9c9d1;
}

.session-card.flash {
    animation: flash-highlight 1.2s ease-out;
}

#boxplot-section.flash {
    animation: flash-highlight 1.2s ease-out;
    border-radius: 8px;
}

@keyframes flash-highlight {
    0% {
        box-shadow: 0 0 0 3px var(--ey-yellow);
        background: #fffbe0;
    }
    100% {
        box-shadow: none;
        background: #fff;
    }
}

.sugg-dropdown {
    position: absolute;
    z-index: 100;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 4px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    max-height: 220px;
    overflow-y: auto;
}

.sugg-item {
    padding: 6px 10px;
    font-size: 14px;
    cursor: pointer;
    white-space: nowrap;
}

.sugg-item:hover {
    background: var(--ey-yellow);
}

#boxplot-section h2,
.session-card h2 {
    font-size: 15px;
    margin: 0 0 10px;
}

.session-card {
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 16px;
    margin-bottom: 18px;
}

.session-card .session-title {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
    border-bottom: 2px solid var(--ey-yellow);
    padding-bottom: 6px;
    margin-bottom: 12px;
}

.session-card .session-title h2 {
    margin: 0;
}

.badge {
    font-size: 11px;
    background: var(--ey-gray);
    color: #fff;
    padding: 2px 8px;
    border-radius: 10px;
}

.badge.next {
    background: var(--ey-yellow);
    color: var(--ey-dark);
}

.subsection-label {
    font-size: 12px;
    font-weight: 700;
    color: var(--ey-gray);
    margin: 12px 0 6px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.vehicle-select {
    display: flex;
    align-items: center;
    gap: 6px;
}

.vehicle-select label {
    font-size: 12px;
    font-weight: 700;
    color: var(--ey-gray);
}

.vehicle-select select {
    padding: 4px 8px;
    border: 1px solid var(--border);
    border-radius: 4px;
    font-size: 13px;
    background: #fff;
}

.field-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
    gap: 10px;
}

.fr-grid {
    display: grid;
    grid-template-columns: 160px 1fr 1fr;
    gap: 8px 10px;
    align-items: center;
}

.fr-grid .fr-head {
    font-size: 12px;
    font-weight: 700;
    color: var(--ey-gray);
    text-align: center;
}

.fr-grid .fr-row-label {
    font-size: 13px;
}

.field {
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.field label {
    font-size: 12px;
    color: var(--ey-gray);
}

.field input {
    padding: 6px 8px;
    border: 1px solid var(--border);
    border-radius: 4px;
    font-size: 14px;
    width: 100%;
}

.field input.auto {
    background: #f0f0f5;
    font-weight: 700;
}

.field input.changed,
.fr-grid input.changed {
    border: 2px solid var(--changed);
    box-shadow: 0 0 0 2px rgba(227, 18, 11, 0.15);
}

.fr-grid input {
    padding: 6px 8px;
    border: 1px solid var(--border);
    border-radius: 4px;
    font-size: 14px;
    width: 100%;
}

.memo-field {
    margin-top: 12px;
}

.memo-field label {
    display: block;
    font-size: 12px;
    color: var(--ey-gray);
    margin-bottom: 4px;
}

.memo-field textarea {
    width: 100%;
    min-height: 56px;
    padding: 8px;
    border: 1px solid var(--border);
    border-radius: 4px;
    font-size: 14px;
    font-family: inherit;
    resize: vertical;
}

.stats-box {
    display: flex;
    gap: 18px;
    flex-wrap: wrap;
    background: #fafafe;
    border: 1px solid var(--border);
    border-left: 4px solid var(--ey-yellow);
    border-radius: 6px;
    padding: 10px 14px;
    margin-top: 14px;
}

.stat {
    display: flex;
    flex-direction: column;
}

.stat .stat-label {
    font-size: 11px;
    color: var(--ey-gray);
}

.stat .stat-value {
    font-size: 18px;
    font-weight: 700;
}

.low-sample {
    color: var(--changed);
    font-size: 12px;
    align-self: center;
}

/* 高速ラップ手動除外の操作パネル */
.fast-exclude {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 8px;
}

.fast-exclude .fe-label {
    font-size: 12px;
    color: var(--ey-gray);
}

.fast-exclude .secondary-btn {
    padding: 4px 10px;
    font-size: 12px;
}

.fast-exclude .secondary-btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.no-data-note {
    font-size: 12px;
    color: var(--ey-gray);
    margin-top: 12px;
    font-style: italic;
}

/* 記録未選択のプレースホルダ（取り込み前） */
.empty-note {
    margin: 32px 8px;
    padding: 24px;
    border: 2px dashed var(--border);
    border-radius: 8px;
    text-align: center;
    color: var(--ey-dark);
    font-size: 14px;
    line-height: 1.7;
}

/* ゲストのセッションカードに表示するログイン促し（セッティング欄の代わり） */
.guest-login-hint {
    margin-top: 14px;
    padding: 12px 14px;
    border: 2px solid var(--ey-yellow);
    border-radius: 6px;
    background: #fffbe5;
    color: var(--ey-dark);
    font-size: 13px;
    font-weight: 700;
    text-align: center;
}

/* 箱ひげ図直下のセッション番号トラック（各箱に対応。タップで変更点を表示） */
.boxplot-changes {
    display: flex;
    gap: 8px;
    margin-top: 6px;
    /* Plotly の左右マージン(l:50, r:10)に合わせ、各番号を箱の位置へ近づける */
    padding-left: 50px;
    padding-right: 10px;
    align-items: stretch;
}

.boxplot-changes.hidden {
    display: none;
}

.bpc-col {
    flex: 1 1 0;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

/* 箱の上に常時表示するセッション統計（ベスト/TOP5平均/連続3/有効ラップ） */
.bpc-stats {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 4px 3px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: #fff;
}

.bpc-stat {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 4px;
    font-size: 10px;
    line-height: 1.2;
    white-space: nowrap;
}

.bpc-stat span {
    color: var(--ey-gray);
}

.bpc-stat b {
    color: var(--ey-dark);
    font-size: 11px;
    font-variant-numeric: tabular-nums;
}

.bpc-col.hidden-session .bpc-stats {
    opacity: 0.5;
}

.bpc-no-btn {
    flex: 1 1 auto;
    background: #fafafe;
    border: 1px solid var(--border);
    border-top: 3px solid var(--ey-yellow);
    border-radius: 6px;
    padding: 8px 4px;
    font-size: 13px;
    font-weight: 700;
    color: var(--ey-dark);
    cursor: pointer;
    text-align: center;
}

.bpc-no-btn:hover {
    background: #fffbe0;
}

.bpc-no-btn:active {
    transform: translateY(1px);
}

.bpc-toggle-btn {
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 4px 2px;
    font-size: 11px;
    color: var(--ey-gray);
    cursor: pointer;
    text-align: center;
}

.bpc-toggle-btn:hover {
    background: #f2f2f7;
}

.bpc-toggle-btn:active {
    transform: translateY(1px);
}

/* 箱を非表示にしたセッションの列（番号ボタン等は残しつつ淡色化） */
.bpc-col.hidden-session .bpc-no-btn {
    opacity: 0.5;
    border-top-color: var(--border);
}

.bpc-col.hidden-session .bpc-toggle-btn {
    background: var(--ey-yellow);
    color: var(--ey-dark);
    font-weight: 700;
}

/* 変更点ポップアップ（モーダル） */
.change-modal {
    position: fixed;
    inset: 0;
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
}

.change-modal.hidden {
    display: none;
}

.change-modal .cm-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(46, 46, 56, 0.55);
}

.change-modal .cm-card {
    position: relative;
    z-index: 1;
    width: 100%;
    max-width: 420px;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    background: #fff;
    border-radius: 10px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
    overflow: hidden;
}

.change-modal .cm-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 12px 14px;
    background: var(--ey-dark);
    color: #fff;
    border-bottom: 3px solid var(--ey-yellow);
}

.change-modal .cm-title {
    font-size: 15px;
    font-weight: 700;
}

.change-modal .cm-close {
    background: transparent;
    border: none;
    color: #fff;
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
    padding: 0 4px;
}

.change-modal .cm-body {
    padding: 14px;
    overflow-y: auto;
}

.change-modal .cm-note {
    margin: 0;
    font-size: 14px;
    color: var(--ey-gray);
}

.change-modal .cm-count {
    font-size: 12px;
    font-weight: 700;
    color: var(--ey-gray);
    margin-bottom: 10px;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.change-modal .cm-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.change-modal .cm-item {
    border: 1px solid var(--border);
    border-left: 4px solid var(--ey-yellow);
    border-radius: 6px;
    padding: 8px 10px;
    background: #fafafe;
}

.change-modal .cm-key {
    font-size: 13px;
    font-weight: 700;
    color: var(--ey-dark);
    margin-bottom: 4px;
}

.change-modal .cm-change {
    font-size: 14px;
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
}

/* --- A4 集約印刷（箱ひげ図＋変更点＋ラップ情報を1枚に） --- */

/* 画面上では印刷シートを隠す */
#print-sheet {
    display: none;
}

.print-head {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    border-bottom: 2px solid var(--ey-dark);
    padding-bottom: 3mm;
    margin-bottom: 3mm;
    gap: 6mm;
}

.print-title {
    font-size: 14pt;
    font-weight: 700;
    color: var(--ey-dark);
    white-space: nowrap;
}

.print-meta {
    font-size: 9.5pt;
    color: var(--ey-dark);
    text-align: right;
}

.print-box {
    text-align: center;
    margin-bottom: 3mm;
    /* 箱ひげ図は段・ページで分割させない */
    break-inside: avoid;
    page-break-inside: avoid;
    -webkit-column-break-inside: avoid;
}

.print-box-img {
    max-width: 100%;
    max-height: 70mm;
    height: auto;
    break-inside: avoid;
    page-break-inside: avoid;
}

/* セッションブロックを2段組で敷き詰めて余白を減らす。
   段組は印刷シート全体（#print-sheet）側に持たせ、ヘッダー/箱ひげ図/
   フッターを全段ぶち抜きにすることで、1ページ目の箱ひげ図直下から
   2段組が始まる。 */
.ps-sessions {
    margin: 0;
}

.ps-session {
    break-inside: avoid;
    -webkit-column-break-inside: avoid;
    border: 1px solid #b5b5be;
    border-radius: 4px;
    padding: 2mm 2.4mm 2.6mm;
    margin: 0 0 3mm;
    background: #fff;
}

/* 項目数が多い車種（F1 等）で全設定を出すセッションは、段/ページの高さを
   超えても分割できるようにして、はみ出し（表示崩れ）を防ぐ。見出し・各設定
   グループ・統計表は下位ルールで途中分割を禁止し、まとまりは保つ。 */
.ps-session.ps-tall {
    break-inside: auto;
    -webkit-column-break-inside: auto;
}

/* 見出し・各設定グループ・統計表は途中で割らない */
.ps-shead,
.ps-group,
.ps-stats {
    break-inside: avoid;
    -webkit-column-break-inside: avoid;
}

.ps-shead {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 3mm;
    border-bottom: 1.5px solid var(--ey-dark);
    padding-bottom: 1mm;
    margin-bottom: 1.6mm;
}

.ps-sno {
    font-size: 10.5pt;
    font-weight: 700;
    color: var(--ey-dark);
    white-space: nowrap;
}

.ps-stime {
    font-size: 8pt;
    color: var(--ey-gray);
    text-align: right;
}

.ps-sect-label {
    font-size: 8pt;
    font-weight: 700;
    color: #fff;
    background: var(--ey-gray);
    border-radius: 2px;
    padding: 0.6mm 1.6mm;
    margin-bottom: 1.4mm;
    display: inline-block;
}

/* 全設定表示: セクションごとにラベル/値グリッド */
.ps-group {
    margin-bottom: 1.6mm;
}

.ps-gtitle {
    font-size: 8pt;
    font-weight: 700;
    color: var(--ey-dark);
    border-left: 2.5px solid var(--ey-yellow);
    padding-left: 1.4mm;
    margin-bottom: 1mm;
}

.ps-kv-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.6mm 2.4mm;
}

.ps-kv {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 1.6mm;
    font-size: 8pt;
    border-bottom: 1px dotted #d3d3da;
    padding: 0.3mm 0;
}

.ps-k {
    color: #555;
}

.ps-v {
    font-weight: 700;
    color: var(--ey-dark);
    font-variant-numeric: tabular-nums;
    white-space: normal;
    text-align: right;
}

/* 変更点表示: チップ */
.ps-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 1.4mm;
}

.ps-chip {
    display: inline-flex;
    align-items: baseline;
    gap: 1mm;
    font-size: 8pt;
    background: #fbfbe8;
    border: 1px solid #e6e6a8;
    border-radius: 3px;
    padding: 0.6mm 1.6mm;
}

.ps-ck {
    font-weight: 700;
    color: var(--ey-dark);
}

.ps-cf {
    color: var(--ey-gray);
    text-decoration: line-through;
}

.ps-arrow {
    color: var(--changed);
    font-weight: 700;
}

.ps-ct {
    font-weight: 700;
    color: var(--changed);
}

.ps-nochange {
    font-size: 8pt;
    color: var(--ey-gray);
    font-style: italic;
}

.ps-memo,
.ps-outcome {
    font-size: 8pt;
    color: #333;
    margin-top: 1.2mm;
    line-height: 1.35;
}

/* ラップ情報テーブル（横並び1行） */
.ps-stats {
    width: 100%;
    border-collapse: collapse;
    margin-top: 1.8mm;
    font-size: 8pt;
    table-layout: fixed;
}

.ps-stats th,
.ps-stats td {
    border: 1px solid #c4c4cd;
    padding: 0.8mm 1mm;
    text-align: center;
}

.ps-stats th {
    background: var(--ey-yellow);
    color: var(--ey-dark);
    font-weight: 700;
    width: 11%;
}

.ps-stats td {
    font-weight: 700;
    color: var(--ey-dark);
    font-variant-numeric: tabular-nums;
    width: 9%;
}

.ps-empty {
    font-size: 9pt;
    color: var(--ey-gray);
    text-align: center;
    padding: 6mm 0;
}

.print-footer {
    margin-top: 3mm;
    font-size: 7.5pt;
    color: var(--ey-gray);
    text-align: right;
}

@page {
    size: A4 portrait;
    margin: 10mm;
}

@media print {
    /* 印刷時は画面UIをすべて隠し、集約シートのみを出す */
    body > *:not(#print-sheet) {
        display: none !important;
    }

    html,
    body {
        overflow: visible;
        background: #fff;
    }

    #print-sheet {
        display: block !important;
        position: static;
        width: 100%;
        color: #000;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
        /* シート全体を2段組にし、1ページ目から段組を効かせる */
        column-count: 2;
        column-gap: 6mm;
    }

    /* ヘッダー・箱ひげ図・フッターは全段ぶち抜き（段の上に配置）。
       箱ひげ図は break-inside: avoid で段・ページ跨ぎを防止する。 */
    .print-head,
    .print-box,
    .print-footer {
        column-span: all;
        -webkit-column-span: all;
    }
}



.change-modal .cm-from {
    color: var(--ey-gray);
}

.change-modal .cm-arrow {
    color: var(--ey-gray);
}

.change-modal .cm-to {
    font-weight: 700;
    color: var(--changed);
}

.change-modal .cm-foot {
    padding: 10px 14px;
    border-top: 1px solid var(--border);
    text-align: right;
}

/* Mini-Z 手動ラップ入力ボタン（各セッション） */
.lap-input-btn {
    background: var(--ey-yellow);
    color: var(--ey-dark);
    border-color: var(--ey-yellow);
    font-weight: 700;
}

.lap-input-btn:hover {
    filter: brightness(0.95);
    background: var(--ey-yellow);
}

/* Mini-Z モードで無効化された Speedhive 取得ボタン */
.icon-btn.mode-disabled,
.icon-btn.mode-disabled:hover {
    opacity: 0.4;
    cursor: not-allowed;
    filter: grayscale(1);
}

/* ラップ入力モーダルの貼り付け欄とフッター */
.lm-textarea {
    width: 100%;
    min-height: 220px;
    box-sizing: border-box;
    margin-top: 10px;
    padding: 8px 10px;
    font-family: "Consolas", "Courier New", monospace;
    font-size: 13px;
    line-height: 1.5;
    border: 1px solid var(--border);
    border-radius: 6px;
    resize: vertical;
    white-space: pre;
    overflow: auto;
}

.change-modal .cm-foot.lm-foot {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

.lm-import {
    background: var(--ey-yellow);
    color: var(--ey-dark);
    border-color: var(--ey-yellow);
    font-weight: 700;
}

.lm-import:hover {
    filter: brightness(0.95);
    background: var(--ey-yellow);
}

/* まとめて入力モーダルの区切り時間入力 */
.blm-split-label {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-top: 10px;
    font-size: 13px;
    font-weight: 600;
}

.blm-split,
.lm-split {
    width: 90px;
    padding: 6px 8px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 13px;
}

.blm-import {
    background: var(--ey-yellow);
    color: var(--ey-dark);
    border-color: var(--ey-yellow);
    font-weight: 700;
}

.blm-import:hover {
    filter: brightness(0.95);
    background: var(--ey-yellow);
}


/* ===== モバイル（iPhone 等）向けレイアウト ===== */
@media (max-width: 640px) {
    /* 縦スクロールとピンチズームは許可しつつ、横方向のパンを抑止 */
    body {
        touch-action: pan-y pinch-zoom;
    }

    /* ヘッダーを小さくして上部の占有を抑える */
    .app-header {
        padding: 8px 12px;
    }
    .app-header h1 {
        font-size: 14px;
        margin: 0 0 6px;
    }
    .app-header h1::before {
        width: 8px;
        height: 13px;
        margin-right: 6px;
    }
    .header-controls {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 6px 8px;
        align-items: end;
    }
    .header-controls label,
    .header-controls .ctrl-id {
        font-size: 11px;
        gap: 2px;
    }
    .header-controls .ctrl-id {
        grid-column: 1 / -1;
    }
    .header-controls .combo {
        width: 100%;
    }
    .combo > input {
        min-width: 0;
    }
    .header-controls input,
    .header-controls select {
        padding: 6px;
        font-size: 16px; /* iOS で入力時に自動ズームしない最小サイズ */
        min-width: 0;
        width: 100%;
    }
    #save-btn {
        grid-column: 1 / 2;
        width: 100%;
        align-self: stretch;
        height: 44px;
        padding: 0;
    }
    #delete-btn {
        grid-column: 2 / 3;
        width: 100%;
        align-self: stretch;
        height: 44px;
        padding: 0;
    }
    #import-btn,
    #update-btn {
        grid-column: 1 / -1;
        width: 100%;
        align-self: stretch;
        height: 44px;
        padding: 0;
    }
    #status {
        grid-column: 1 / -1;
        align-self: start;
    }

    /* 本文の余白を詰める */
    main {
        padding: 12px;
    }
    .session-card {
        padding: 12px;
    }

    /* 共通項目は2列、フロント/リアはラベル＋2列で詰める */
    .field-grid {
        grid-template-columns: 1fr 1fr;
        gap: 8px;
    }
    .fr-grid {
        grid-template-columns: 96px 1fr 1fr;
        gap: 6px;
    }
    .fr-grid .fr-row-label {
        font-size: 12px;
    }

    /* タッチで誤拡大しないよう、箱ひげ図のタッチ操作を抑制 */
    #boxplot {
        touch-action: pan-y;
    }

    /* 箱の下の番号トラックを詰める（箱の位置に合わせて左余白は維持） */
    .boxplot-changes {
        gap: 4px;
        padding-left: 50px;
        padding-right: 10px;
    }
    .bpc-no-btn {
        padding: 8px 2px;
        font-size: 12px;
    }
}

/* ============================================================
   走行軌跡ビューア (trajectory.html)
   ============================================================ */
.traj-body {
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
}

.traj-sub {
    font-size: 12px;
    font-weight: 400;
    opacity: 0.7;
    margin-left: 6px;
}

.traj-file-btn {
    position: relative;
    cursor: pointer;
}

.traj-main {
    flex: 1;
    display: flex;
    min-height: 0;
    width: 100%;
    max-width: none;
    margin: 0;
    padding: 0;
}

.traj-map-pane {
    flex: 1;
    position: relative;
    min-width: 0;
}

#map {
    position: absolute;
    inset: 0;
    background: #d5d5db;
}

/* タイル背景なしのグレー地。Leaflet コンテナ自体もグレーに */
.leaflet-container {
    background: #d5d5db;
}

.traj-map-pane.drag-over::after {
    content: "";
    position: absolute;
    inset: 0;
    border: 3px dashed var(--ey-yellow);
    background: rgba(255, 230, 0, 0.08);
    pointer-events: none;
    z-index: 500;
}

/* leaflet divIcon の既定枠を消す */
.car-glyph {
    background: none;
    border: none;
}

/* ドロップ案内 */
.drop-hint {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
    z-index: 450;
}

.drop-hint.hidden {
    display: none;
}

.drop-hint-card {
    background: rgba(46, 46, 56, 0.85);
    color: #fff;
    padding: 24px 32px;
    border-radius: 10px;
    text-align: center;
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.4);
}

.drop-hint-title {
    font-size: 18px;
    font-weight: 600;
}

.drop-hint-sub {
    margin-top: 6px;
    opacity: 0.9;
}

.drop-hint-note {
    margin-top: 10px;
    font-size: 11px;
    opacity: 0.7;
}

/* 凡例 */
.legend {
    position: absolute;
    left: 12px;
    bottom: 12px;
    z-index: 450;
    background: rgba(255, 255, 255, 0.94);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 8px 12px;
    font-size: 12px;
    color: var(--ey-dark);
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.25);
}

.legend.hidden {
    display: none;
}

.legend-row {
    display: flex;
    align-items: center;
    gap: 6px;
    margin: 3px 0;
}

.legend-label {
    display: inline-block;
    width: 62px;
    font-weight: 600;
}

.legend-tick {
    font-variant-numeric: tabular-nums;
}

.legend-unit {
    color: var(--ey-gray);
}

#speed-bar {
    border: 1px solid var(--border);
    border-radius: 2px;
    vertical-align: middle;
}

.legend-throttle .sw,
.legend-steer .sw {
    display: inline-block;
    width: 12px;
    height: 12px;
    border-radius: 2px;
    vertical-align: middle;
    margin: 0 2px 0 6px;
}

/* サイドバー */
.traj-side {
    width: 340px;
    flex-shrink: 0;
    overflow-y: auto;
    background: #fff;
    border-left: 1px solid var(--border);
    padding: 10px 12px;
}

.side-block {
    margin-bottom: 16px;
}

.side-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
}

.side-block h2 {
    font-size: 15px;
    margin: 4px 0 8px;
}

.circuit-meta {
    font-size: 11px;
    color: var(--ey-gray);
}

.filters {
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: 12px;
    margin-bottom: 8px;
}

.filter-chk {
    display: flex;
    align-items: center;
    gap: 6px;
}

.sec-input {
    width: 48px;
    padding: 1px 4px;
}

.filter-sort {
    display: flex;
    align-items: center;
    gap: 6px;
}

.lap-table-wrap {
    max-height: 320px;
    overflow-y: auto;
    border: 1px solid var(--border);
    border-radius: 6px;
}

.lap-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
}

.lap-table thead th {
    position: sticky;
    top: 0;
    background: var(--ey-dark);
    color: #fff;
    padding: 5px 4px;
    font-weight: 600;
    text-align: center;
    z-index: 1;
}

.lap-table td {
    padding: 4px 4px;
    text-align: center;
    border-bottom: 1px solid #eee;
}

.lap-table .mono {
    font-variant-numeric: tabular-nums;
}

.lap-table .delta {
    color: var(--ey-gray);
}

.lap-table tbody tr:hover {
    background: #f0f4ff;
    cursor: pointer;
}

.lap-table tr.sel-row {
    background: #e3f2fd;
}

.lap-table tr.best-row td {
    background: #fff8dc;
    font-weight: 700;
}

.lap-table tr.best-row.sel-row td {
    background: #fdeecb;
}

.crown {
    filter: saturate(1.2);
}

/* 詳細パネル */
.detail-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
}

.detail-cell {
    display: flex;
    flex-direction: column;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 6px 8px;
}

.detail-cell .dk {
    font-size: 10px;
    color: var(--ey-gray);
}

.detail-cell .dv {
    font-size: 14px;
    font-variant-numeric: tabular-nums;
}

/* 下部コントロールバー */
.traj-controls {
    display: flex;
    align-items: center;
    gap: 24px;
    padding: 8px 16px;
    background: var(--ey-dark);
    color: #fff;
    flex-wrap: wrap;
}

.traj-controls label {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
}

.traj-controls select {
    padding: 2px 4px;
}

.ctrl-group {
    display: flex;
    align-items: center;
    gap: 14px;
}

.ctrl-group.player {
    flex: 1;
    min-width: 260px;
}

.seek {
    flex: 1;
    min-width: 120px;
}

.seek-time {
    font-variant-numeric: tabular-nums;
    min-width: 52px;
    text-align: right;
}

@media (max-width: 760px) {
    .traj-main {
        flex-direction: column;
    }
    .traj-side {
        width: 100%;
        max-height: 40vh;
        border-left: none;
        border-top: 1px solid var(--border);
    }
}

