/* ============================================================
   校园跑步数据生成器 — 全局样式
   风格：专业工作台（浅色）— 浅灰工作区 × 白面板 × 靛蓝 accent
   数据字体 JetBrains Mono，正文 Noto Sans SC
   ============================================================ */
:root {
    --bg:      #F4F5F7;    /* 工作区底 */
    --surface: #FFFFFF;    /* 面板 */
    --surface-2:#F0F2F5;   /* hover 面 / 槽 */
    --field:   #FFFFFF;    /* 输入框底 */
    --border:  #E2E5EA;
    --border-2:#CBD1D9;    /* 强边框 */
    --text:    #1B1F27;
    --text-2:  #5B6472;
    --text-3:  #98A0AC;
    --accent:      #3B5BD7;
    --accent-hover:#2F4CC4;
    --accent-dim:  rgba(59,91,215,.09);
    --danger:  #D64545;
    --danger-dim: rgba(214,69,69,.08);
    --success: #217A4B;
    --success-dim: rgba(33,122,75,.08);

    --sans: 'Noto Sans SC', -apple-system, 'Segoe UI', 'Microsoft YaHei', sans-serif;
    --mono: 'JetBrains Mono', 'Courier New', monospace;
    --radius: 6px;
    --radius-sm: 4px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: var(--sans);
    background: var(--bg);
    color: var(--text);
    font-size: 13.5px;
    line-height: 1.6;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

::selection { background: var(--accent); color: #fff; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #C6CCD4; border-radius: 5px; border: 2px solid var(--bg); }
::-webkit-scrollbar-thumb:hover { background: #AEB6C0; }

a { color: var(--accent); text-decoration: none; }
button { font-family: inherit; }

/* 等宽小标签 */
.mono-tag {
    font-family: var(--mono);
    font-size: 10.5px;
    letter-spacing: .06em;
    color: var(--text-3);
}

/* 分组标签（01/02/03 步骤编号 + 大写说明） */
.group-label {
    font-family: var(--mono);
    font-size: 10px; font-weight: 600;
    letter-spacing: .1em; text-transform: uppercase;
    color: var(--text-3);
    margin-bottom: 9px;
    display: flex; align-items: center; gap: 8px;
}
.group-label .step-no {
    color: var(--accent);
    background: var(--accent-dim);
    padding: 1px 6px;
    border-radius: 3px;
    font-size: 9.5px;
}

/* 提示小字 */
.hint { font-size: 11.5px; color: var(--text-2); margin-top: 8px; line-height: 1.6; }
.hint code {
    font-family: var(--mono); font-size: 10.5px;
    color: var(--accent); background: var(--accent-dim);
    padding: 1px 5px; border-radius: 3px;
}

.hidden { display: none; }

/* ============================================================
   面板
   ============================================================ */
.panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}
.section-head {
    display: flex; align-items: center; gap: 10px;
    padding: 10px 14px;
    border-bottom: 1px solid var(--border);
}
.section-head h2 { font-size: 12.5px; font-weight: 700; }
.section-head .mono-tag { margin-left: auto; }
.section-body { padding: 14px; }

/* ============================================================
   应用顶栏（生成器页）
   ============================================================ */
.topbar {
    position: sticky; top: 0; z-index: 900;
    display: flex; align-items: center; gap: 12px;
    padding: 0 20px;
    height: 48px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}
.app-icon-link {
    flex: none;
    display: block;
    line-height: 0;
}
.app-icon {
    width: 22px; height: 22px; flex: none;
    border-radius: 5px;
    border: 1px solid var(--border);
    object-fit: cover;
    display: block;
}
.app-icon-link .app-icon { cursor: pointer; }
.app-icon-link:hover .app-icon {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-dim);
}
.topbar h1 { font-size: 13.5px; font-weight: 700; }
.topbar .mono-tag { margin-left: 2px; }
.topbar .topbar-side { margin-left: auto; display: flex; align-items: center; gap: 8px; }

.link-btn {
    font-size: 12px;
    color: var(--text-2);
    padding: 5px 11px;
    background: var(--surface);
    border: 1px solid var(--border-2);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all .12s;
}
.link-btn:hover { color: var(--accent); border-color: var(--accent); }

/* ============================================================
   生成器：工作台布局
   ============================================================ */
.gen-frame { max-width: 1720px; margin: 0 auto; padding: 18px 20px 8px; }

.workbench {
    display: grid;
    grid-template-columns: 280px 1fr;
    gap: 14px;
    align-items: stretch;
}

/* 左配置栏 */
.cfg-side { display: flex; flex-direction: column; gap: 14px; }
.cfg-side .panel-sec { padding: 14px; }

.setting-item { display: flex; flex-direction: column; gap: 5px; margin-bottom: 12px; }
.setting-item:last-child { margin-bottom: 0; }
.setting-item label { font-size: 12px; font-weight: 500; color: var(--text-2); }
.setting-item select {
    padding: 8px 10px;
    background: var(--field);
    border: 1px solid var(--border-2);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-family: var(--mono); font-size: 12.5px;
    cursor: pointer;
    transition: border-color .12s, box-shadow .12s;
    width: 100%;
}
.setting-item select:hover { border-color: #B4BCC7; }
.setting-item select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-dim); }

/* 模式选择：垂直选项列表 */
.mode-list { display: flex; flex-direction: column; gap: 6px; }
.tab-button {
    display: block; width: 100%;
    text-align: left;
    padding: 10px 12px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-left: 2px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-2);
    font-family: var(--sans);
    font-size: 12.5px; font-weight: 500;
    cursor: pointer;
    transition: all .12s;
}
.tab-button .mode-name { display: flex; align-items: center; gap: 8px; font-weight: 500; color: inherit; }
.tab-button .mode-name .idx {
    font-family: var(--mono); font-size: 9.5px; font-weight: 600;
    color: var(--text-3);
    border: 1px solid var(--border);
    border-radius: 3px;
    padding: 0 5px;
    line-height: 1.7;
}
.tab-button .mode-desc {
    display: block;
    font-size: 11px; font-weight: 400;
    color: var(--text-3);
    margin-top: 3px;
    padding-left: 27px;
}
.tab-button:hover { border-color: var(--border-2); color: var(--text); background: var(--surface-2); }
.tab-button.active {
    background: var(--accent-dim);
    border-color: rgba(59,91,215,.35);
    border-left: 2px solid var(--accent);
    color: var(--accent);
}
.tab-button.active .mode-name .idx { color: var(--accent); border-color: rgba(59,91,215,.35); }
.tab-button.active .mode-desc { color: var(--text-2); }

/* 模式内容显隐（JS 切 .active） */
.mode-content { display: none; }
.mode-content.active { display: block; }

/* 主区：参数 */
.param-main { display: flex; flex-direction: column; min-width: 0; }
.param-main > .section-head,
.param-main > .mode-content,
.param-main > .message-slot { flex-shrink: 0; }
.param-main .section-body { padding: 16px; }
/* 反馈消失后仍保留一行空间，结果区边界不随提示显隐跳动。 */
.message-slot { min-height: 54px; }

.form-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px 14px; }
.form-group { display: flex; flex-direction: column; gap: 5px; }
.form-group.full-width { grid-column: 1 / -1; }
.form-group label { font-size: 12px; font-weight: 500; color: var(--text-2); }
.form-group input, .form-group select {
    padding: 7px 10px;
    background: var(--field);
    border: 1px solid var(--border-2);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-family: var(--mono);
    font-size: 12.5px;
    transition: border-color .12s, box-shadow .12s;
    width: 100%;
    /* 移动端 time/date input 有原生 min-width，会撑破卡片 (#11) */
    min-width: 0;
}
.form-group input::placeholder { color: var(--text-3); }
.form-group input:hover, .form-group select:hover { border-color: #B4BCC7; }
.form-group input:focus, .form-group select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-dim);
}
.form-group input::-webkit-calendar-picker-indicator { opacity: .55; cursor: pointer; }

/* 执行条 */
.run-bar {
    display: flex; gap: 8px; margin-top: 16px;
    padding-top: 14px;
    border-top: 1px solid var(--border);
}
.run-bar .btn { flex: none; min-width: 130px; }
.run-bar .btn-primary { flex: 1; }

/* ============================================================
   按钮
   ============================================================ */
.btn-group { display: flex; gap: 8px; margin-top: 14px; }
.btn {
    flex: 1;
    padding: 8px 18px;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    font-family: var(--sans);
    font-size: 13px; font-weight: 500;
    cursor: pointer;
    transition: background .12s, border-color .12s, color .12s;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn-primary:disabled { opacity: .4; cursor: not-allowed; }
.btn-secondary { background: var(--surface); color: var(--text-2); border-color: var(--border-2); }
.btn-secondary:hover:not(:disabled) { color: var(--accent); border-color: var(--accent); }
.btn-sm { flex: none; padding: 5px 13px; font-size: 12px; }

/* ============================================================
   输出区（右栏内嵌卡片，按钮正下方；超限内部滚动 #49）
   ============================================================ */
/* 明确的 200px 基准阻断表格的内容高度贡献；双栏填满工作台剩余空间。
   工作台高度只由左栏、当前表单与这一基准决定，不由结果行数决定。 */
.results-area {
    display: flex;
    align-items: flex-end;
    flex: 1 0 200px;
    height: 200px;
    min-height: 200px;
    min-width: 0;
}
.results-section {
    display: none;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px;
    flex: 1;
    min-height: 0;
    min-width: 0;
    flex-direction: column;
    height: 100%;
    /* 矮窗口可把整张结果卡滚入顶栏下方，卡片底边仍固定在结果槽底部。 */
    max-height: calc(100vh - 56px);
    /* scrollIntoView 时避让 sticky 顶栏（48px + 余量） */
    scroll-margin-top: 56px;
}
.results-section.show { display: flex; }

.results-head {
    display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
    flex: none;
    margin-bottom: 10px;
}
.results-head .mono-tag { margin-left: auto; }

/* 固定卡片内只让表格内容滚动，短结果也保留同一个下边界。 */
.results-scroll {
    flex: 1;
    min-height: 0;
    overflow: auto;
    overscroll-behavior: contain;
    scrollbar-gutter: stable;
}

.results-table { width: 100%; border-collapse: collapse; white-space: nowrap; }
.results-table th {
    position: sticky; top: 0; z-index: 1;
    background: var(--surface);
    font-family: var(--mono); font-size: 10px; font-weight: 600;
    letter-spacing: .08em; text-transform: uppercase;
    color: var(--text-3);
    text-align: left;
    padding: 6px 10px;
    border-bottom: 1px solid var(--border);
}
.results-table td {
    font-family: var(--mono); font-size: 12px;
    padding: 7px 10px;
    border-bottom: 1px solid var(--border);
}
.results-table tbody tr { transition: background .1s; }
.results-table tbody tr:hover { background: var(--surface-2); }
.results-table td:first-child { color: var(--text-2); }

/* ============================================================
   消息条（JS 会整体覆盖 className 为 `message ${type} show`）
   ============================================================ */
.message {
    display: none;
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    font-family: var(--mono);
    font-size: 12px;
    border: 1px solid transparent;
}
.message.show { display: flex; align-items: center; gap: 9px; }
.message.success { background: var(--success-dim); border-color: rgba(33,122,75,.25); color: var(--success); }
.message.error   { background: var(--danger-dim); border-color: rgba(214,69,69,.3); color: var(--danger); }
.message.loading { background: var(--accent-dim); border-color: rgba(59,91,215,.25); color: var(--accent); }
.message.loading::before {
    content: '';
    width: 12px; height: 12px; flex: none;
    border: 2px solid rgba(59,91,215,.25);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ============================================================
   模态框
   .modal       默认隐藏，JS 设 style.display='flex' 显示（export-modal）
   .modal-mask  默认 flex，JS 用内联 display 控制显隐（编辑器 settings-modal）
   ============================================================ */
.modal {
    display: none;
    position: fixed; inset: 0;
    background: rgba(24,28,36,.4);
    z-index: 1000;
    align-items: center; justify-content: center;
}
.modal-content {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 22px;
    max-width: 420px; width: 90%;
    position: relative;
    box-shadow: 0 16px 48px rgba(20,26,40,.18);
}
.modal-close { position: absolute; top: 10px; right: 13px; font-size: 19px; cursor: pointer; color: var(--text-3); background: none; border: none; }
.modal-close:hover { color: var(--text); }
.modal h3 { font-size: 13.5px; font-weight: 700; margin-bottom: 14px; }
.modal .form-group { margin-bottom: 12px; }
.modal .btn-group { margin-top: 16px; }

/* ============================================================
   状态条
   ============================================================ */
.statusbar {
    display: flex; align-items: center; gap: 18px;
    padding: 6px 14px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-family: var(--mono); font-size: 10.5px;
    color: var(--text-3);
    margin-top: 14px;
}
.statusbar .st-item { display: flex; align-items: center; gap: 6px; }
.statusbar .st-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--success); }

/* ============================================================
   日历选择器
   ============================================================ */
.dates-cal-row {
    display: flex; gap: 14px;
    margin-bottom: 14px;
    align-items: stretch;
}
.calendar-container {
    flex: 1; min-width: 0;
    background: var(--field);
    border: 1px solid var(--border-2);
    border-radius: var(--radius);
    padding: 10px 12px;
    user-select: none;
}
.dates-side {
    /* 220px：保证中屏一行至少容纳 2 个标签（200px 时差 1px 只剩 1 个/行） */
    width: 220px; flex: none;
    display: flex; flex-direction: column; gap: 6px;
}
.dates-side label {
    font-size: 12px; font-weight: 500; color: var(--text-2);
}

.calendar-header {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 6px;
}
.cal-title {
    font-family: var(--mono);
    font-size: 12px; font-weight: 600;
    color: var(--text);
}
.cal-nav-btn {
    width: 24px; height: 24px;
    display: flex; align-items: center; justify-content: center;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-2);
    font-size: 14px;
    cursor: pointer;
    transition: all .12s;
}
.cal-nav-btn:hover { border-color: var(--accent); color: var(--accent); }

.calendar-weekdays {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 1px;
    margin-bottom: 2px;
}
.calendar-weekdays span {
    font-family: var(--mono);
    font-size: 9.5px; font-weight: 600;
    color: var(--text-3);
    text-align: center;
    padding: 2px 0;
    letter-spacing: .05em;
}

.calendar-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 1px;
}
.cal-day {
    height: 26px;
    display: flex; align-items: center; justify-content: center;
    font-family: var(--mono);
    font-size: 11px; font-weight: 500;
    color: var(--text);
    background: var(--surface);
    border: 1px solid transparent;
    border-radius: 3px;
    cursor: pointer;
    transition: all .1s;
    position: relative;
}
.cal-day:hover:not(.cal-empty):not(.cal-selected) {
    border-color: var(--accent);
    background: var(--accent-dim);
}
.cal-day.cal-empty {
    cursor: default;
    background: transparent;
}
.cal-day.cal-today {
    border-color: var(--border-2);
    font-weight: 700;
}
.cal-day.cal-today::after {
    content: '';
    position: absolute;
    bottom: 2px;
    width: 3px; height: 3px;
    border-radius: 50%;
    background: var(--accent);
}
.cal-day.cal-selected {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
    font-weight: 600;
}
.cal-day.cal-selected:hover {
    background: var(--accent-hover);
}
.cal-day.cal-weekend {
    color: var(--danger);
}
.cal-day.cal-weekend.cal-selected {
    color: #fff;
}
.cal-day.cal-other-month {
    color: var(--text-3);
    opacity: .45;
}

.calendar-actions {
    display: flex; gap: 4px;
    margin-top: 6px;
    padding-top: 6px;
    border-top: 1px solid var(--border);
}
.cal-action-btn {
    flex: 1;
    padding: 3px 6px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: var(--sans);
    font-size: 10.5px;
    color: var(--text-2);
    cursor: pointer;
    transition: all .12s;
}
.cal-action-btn:hover { border-color: var(--accent); color: var(--accent); }

/* 已选日期标签 */
.selected-dates-tags {
    flex: 1;
    display: flex; flex-wrap: wrap; align-content: flex-start; gap: 5px;
    min-height: 0;
    /* 展开态高度封顶，超出滚动，避免大量日期把整页撑高 */
    max-height: 200px;
    padding: 8px;
    background: var(--field);
    border: 1px solid var(--border-2);
    border-radius: var(--radius-sm);
    overflow-y: auto;
}
.dates-placeholder {
    font-size: 11px;
    color: var(--text-3);
    line-height: 1.6;
}
.date-tag {
    display: inline-flex; align-items: center; gap: 3px;
    padding: 2px 6px;
    background: var(--accent-dim);
    border: 1px solid rgba(59,91,215,.25);
    border-radius: 3px;
    font-family: var(--mono);
    font-size: 10.5px;
    color: var(--accent);
    animation: tag-in .15s ease-out;
}
.date-tag .tag-remove {
    width: 13px; height: 13px;
    display: flex; align-items: center; justify-content: center;
    font-size: 11px;
    color: var(--text-3);
    cursor: pointer;
    border-radius: 2px;
    transition: all .1s;
    line-height: 1;
}
.date-tag .tag-remove:hover { color: var(--danger); background: var(--danger-dim); }

/* 「+N 天 / 收起」切换按钮：置于标签盒下方、滚动容器之外，始终可见且键盘可达 */
.tag-toggle-btn {
    align-self: flex-start;
    padding: 2px 8px;
    background: var(--field);
    border: 1px solid var(--border-2);
    border-radius: 3px;
    font-family: var(--mono);
    font-size: 10.5px;
    color: var(--text-2);
    cursor: pointer;
    transition: all .1s;
}
.tag-toggle-btn:hover { border-color: var(--accent); color: var(--accent); }

@keyframes tag-in {
    from { opacity: 0; transform: scale(.9); }
    to   { opacity: 1; transform: scale(1); }
}

.dates-count {
    font-family: var(--mono);
    font-size: 10.5px;
    color: var(--text-3);
    margin-left: 4px;
}

/* ============================================================
   轨迹预览卡片（左栏内嵌迷你地图，点击进入轨迹编辑器）
   ============================================================ */
.track-preview-card {
    display: block;
    border: 1px solid var(--border-2);
    border-radius: var(--radius-sm);
    background: var(--field);
    overflow: hidden;
    cursor: pointer;
    text-decoration: none;
    transition: border-color .12s, box-shadow .12s;
}
.track-preview-card:hover,
.track-preview-card:focus-visible {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-dim);  /* 与 select:focus 同一强调语言 */
}
.track-preview-card:focus-visible { outline: none; }

.preview-head {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 9px;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
}
.preview-name {
    flex: 1;
    min-width: 0;
    font-size: 12px;
    font-weight: 500;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
/* 右上读数槽：默认显示圈程，hover 原地换字「编辑 ↗」编码点击行为（同槽换字，无布局跳动） */
.preview-lap,
.preview-edit {
    flex: none;
    font-family: var(--mono);
    font-size: 10.5px;
    color: var(--accent);
}
.preview-edit { display: none; }
.track-preview-card:hover .preview-lap,
.track-preview-card:focus-visible .preview-lap { display: none; }
.track-preview-card:hover .preview-edit,
.track-preview-card:focus-visible .preview-edit { display: inline; }

/* 地图舞台：绝对定位保证 Leaflet 初始化即有确定高度（同编辑器 #map-leaflet 模式） */
.preview-map-wrap { position: relative; height: 176px; background: #E8EAEE; }
#preview-map { position: absolute; inset: 0; background: #E8EAEE; }

/* 空 / 加载中 / 失败 三态覆盖层（[hidden] 切换；display:flex 会压过 UA 的 hidden，需显式关闭）。
   z-index 1100：盖过 Leaflet 瓦片窗格(400)与控件(1000)——地图初始化后切换轨迹时
   加载/失败/空态必须显示在活地图之上 */
.preview-overlay {
    position: absolute;
    inset: 0;
    z-index: 1100;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--surface);
    font-family: var(--mono);
    font-size: 11px;
    color: var(--text-3);
}
.preview-overlay[hidden] { display: none; }

/* 迷你图覆盖：整卡可点 + 紧凑 attribution */
.track-preview-card .leaflet-container { cursor: pointer; font: inherit; background: #E8EAEE; }
.track-preview-card .leaflet-control-attribution {
    font-size: 9px;
    padding: 0 4px;
    background: rgba(255,255,255,.75);
}

/* 响应式 */
@media (max-width: 960px) {
    .workbench { grid-template-columns: 1fr; }
    .form-grid { grid-template-columns: 1fr 1fr; }
    .dates-cal-row { flex-direction: column; }
    .dates-side { width: 100%; }
    /* 单列没有同排左栏可对齐，保留独立、有限的结果槽；矮窗口仍能看到表头和行。 */
    .results-area { flex: none; height: clamp(200px, 40vh, 360px); min-height: 0; }
}
@media (max-width: 640px) {
    .form-grid { grid-template-columns: 1fr; }
    .run-bar { flex-direction: column; }
    .run-bar .btn { min-width: 0; }
    .statusbar { flex-wrap: wrap; gap: 10px; }
    .results-head .mono-tag { display: none; }
}

/* 宽屏（≥1440px）：加宽左栏 / 表单 4 列 / 收窄会被拉伸的元素 */
@media (min-width: 1440px) {
    .workbench { grid-template-columns: 300px 1fr; }
    .form-grid { grid-template-columns: repeat(4, 1fr); gap: 12px 16px; }
    .calendar-container { max-width: 620px; }
    .dates-side { width: 260px; }
    .run-bar .btn-primary { flex: none; min-width: 200px; }
}
