/**
 * 琴行智能管理系统 /tools/music-store
 * 复刻站点工具页观感：本地 CSS 变量 + 站点主题变量，三端自适应（1099 / 760 / 520）。
 */

/* 整屏：解除站点 1280px 中心限宽，保留左侧导航 */
body.page-music-store-full .app { max-width: 100%; }
body.page-music-store-full .main-content { max-width: 100%; width: 100%; border-right: 0; }

.mst-page {
    --mst-line: var(--border-color);
    --mst-tint: color-mix(in srgb, var(--accent) 12%, transparent);
    --mst-ok: #2e9e5b;
    --mst-warn: #d98a00;
    --mst-bad: #d33;
    padding: 14px 2px 48px;
    color: var(--text-primary);
}

/* ---------------- 顶部 ---------------- */
.mst-top {
    display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
    padding: 12px 14px; margin-bottom: 12px;
    border: 1px solid var(--mst-line); border-radius: var(--radius);
    background: var(--bg-secondary);
}
.mst-top-l { display: flex; align-items: center; gap: 10px; min-width: 0; flex: 1 1 260px; }
.mst-logo {
    flex: 0 0 auto; width: 42px; height: 42px; display: flex; align-items: center; justify-content: center;
    font-size: 21px; border-radius: 11px; background: var(--mst-tint);
    border: 1px solid color-mix(in srgb, var(--accent) 26%, transparent);
}
.mst-top-t h1 { font-size: 18px; line-height: 1.25; margin: 0; }
.mst-top-sub { font-size: 12px; color: var(--text-secondary); margin: 2px 0 0; }
.mst-top-sub b { color: var(--accent); font-weight: 600; }
.mst-top-r { display: flex; gap: 6px; flex-wrap: wrap; }

/* ---------------- 通用元件 ---------------- */
.mst-btn {
    height: 32px; padding: 0 12px; font-size: 13px; font-family: inherit;
    color: var(--text-primary); background: var(--bg-primary);
    border: 1px solid var(--mst-line); border-radius: 8px; cursor: pointer;
    transition: background .15s, border-color .15s;
}
.mst-btn:hover { background: var(--mst-tint); border-color: color-mix(in srgb, var(--accent) 34%, transparent); }
.mst-btn:disabled { opacity: .5; cursor: not-allowed; }
.mst-btn-pri { color: #fff; background: var(--accent); border-color: var(--accent); }
.mst-btn-pri:hover { background: color-mix(in srgb, var(--accent) 86%, #000); border-color: color-mix(in srgb, var(--accent) 86%, #000); }
.mst-btn-danger { color: var(--mst-bad); }
.mst-btn-danger:hover { background: rgba(211, 51, 51, .08); border-color: rgba(211, 51, 51, .38); }
.mst-btn-sm { height: 26px; padding: 0 9px; font-size: 12px; border-radius: 6px; }

.mst-input {
    height: 32px; padding: 0 10px; box-sizing: border-box;
    font-family: inherit; font-size: 13.5px; color: var(--text-primary);
    background: var(--bg-primary); border: 1px solid var(--mst-line); border-radius: 8px;
}
.mst-input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--mst-tint); }
select.mst-input { padding-right: 4px; }
.mst-grow { flex: 1 1 220px; min-width: 0; }

.mst-bar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.mst-meta { font-size: 12.5px; color: var(--text-secondary); }
.mst-hint { font-size: 12px; color: var(--text-secondary); }
.mst-note { font-size: 12.5px; line-height: 1.7; color: var(--text-secondary); margin: 8px 0 0; }
.mst-ta-r { text-align: right; }

.mst-card {
    border: 1px solid var(--mst-line); border-radius: var(--radius);
    background: var(--bg-secondary); padding: 14px; margin-bottom: 12px;
}
.mst-card-h { display: flex; align-items: baseline; gap: 8px; margin-bottom: 10px; }
.mst-card-h h3 { font-size: 14.5px; margin: 0; }
.mst-cols { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 12px; }
.mst-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 10px; }

.mst-empty {
    padding: 26px 16px; text-align: center; font-size: 13px; color: var(--text-secondary);
    border: 1px dashed var(--mst-line); border-radius: var(--radius); background: var(--bg-secondary);
}
.mst-empty[hidden] { display: none !important; }

/* ---------------- 主体布局 ---------------- */
.mst-body { display: grid; grid-template-columns: 176px minmax(0, 1fr); gap: 12px; align-items: start; }
.mst-nav { display: flex; flex-direction: column; gap: 4px; position: sticky; top: 8px; }
.mst-navbtn {
    text-align: left; height: 38px; padding: 0 12px; font-size: 13.5px; font-family: inherit;
    color: var(--text-primary); background: transparent;
    border: 1px solid transparent; border-radius: 9px; cursor: pointer;
    transition: background .15s, color .15s;
}
.mst-navbtn:hover { background: var(--bg-secondary); }
.mst-navbtn.is-on { background: var(--mst-tint); color: var(--accent); font-weight: 600; border-color: color-mix(in srgb, var(--accent) 28%, transparent); }
.mst-main { min-width: 0; }
.mst-pane[hidden] { display: none !important; }

/* ---------------- KPI ---------------- */
.mst-kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin-bottom: 12px; }
.mst-kpi {
    border: 1px solid var(--mst-line); border-radius: var(--radius);
    background: var(--bg-secondary); padding: 12px 14px;
}
.mst-kpi-t { font-size: 12px; color: var(--text-secondary); }
.mst-kpi-v { font-size: 21px; font-weight: 700; line-height: 1.3; margin-top: 4px; }
.mst-kpi-s { font-size: 11.5px; color: var(--text-secondary); margin-top: 2px; }
.mst-kpi.is-warn .mst-kpi-v { color: var(--mst-warn); }
.mst-kpi.is-bad .mst-kpi-v { color: var(--mst-bad); }
.mst-kpi.is-ok .mst-kpi-v { color: var(--mst-ok); }

/* ---------------- 图表 ---------------- */
/* ★柱状图曾整块不显示：图例 flex-basis:100% 与 6 根柱子同处一行（无 wrap），
   把所有柱子列压成宽度 0。改为 flex-wrap 让图例独占第二行，柱子列均分第一行。 */
.mst-chart { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 6px 10px; padding-top: 6px; }
.mst-chart-col { flex: 1 1 0; min-width: 0; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: 4px; height: 158px; }
/* ★柱状图容器必须 flex:1 占满剩余高度：height:100% 会与上方的数值、下方的月份
   叠加超出 158px，被 flex 压缩为 0 —— 柱子永远显示不出来（历史 bug）。 */
.mst-chart-bars { flex: 1 1 auto; min-height: 0; display: flex; align-items: flex-end; gap: 3px; width: 100%; justify-content: center; }
.mst-bar-in, .mst-bar-out { width: 12px; border-radius: 3px 3px 0 0; min-height: 2px; flex: 0 0 auto; }
.mst-bar-in { background: var(--accent); }
.mst-bar-out { background: color-mix(in srgb, var(--mst-bad) 62%, transparent); }
.mst-chart-x { font-size: 11px; color: var(--text-secondary); white-space: nowrap; flex: 0 0 auto; }
.mst-chart-v { font-size: 10.5px; color: var(--text-secondary); flex: 0 0 auto; }
.mst-chart-legend { display: flex; gap: 12px; font-size: 11.5px; color: var(--text-secondary); margin-top: 2px; flex: 1 1 100%; }
.mst-chart-legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 4px; vertical-align: middle; }

/* ---------------- 今日课表 / 待办 ---------------- */
.mst-today, .mst-todo { display: flex; flex-direction: column; gap: 6px; max-height: 260px; overflow: auto; }
.mst-row {
    display: flex; align-items: center; gap: 8px; padding: 7px 10px;
    border: 1px solid var(--mst-line); border-radius: 9px; background: var(--bg-primary);
}
.mst-row-t { font-weight: 600; font-size: 13px; }
.mst-row-s { font-size: 12px; color: var(--text-secondary); }
.mst-row-r { margin-left: auto; display: flex; gap: 6px; }

/* ---------------- 表格 ---------------- */
.mst-table-wrap { border: 1px solid var(--mst-line); border-radius: var(--radius); background: var(--bg-secondary); overflow: auto; }
.mst-table { width: 100%; border-collapse: collapse; font-size: 13px; min-width: 720px; }
.mst-table th, .mst-table td { padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--mst-line); vertical-align: middle; }
.mst-table th { font-size: 12px; font-weight: 600; color: var(--text-secondary); background: color-mix(in srgb, var(--text-primary) 4%, transparent); position: sticky; top: 0; }
.mst-table tbody tr:last-child td { border-bottom: 0; }
.mst-table tbody tr:hover { background: var(--mst-tint); }
.mst-table .mst-ops { display: flex; gap: 6px; justify-content: flex-end; flex-wrap: wrap; }
.mst-sub { display: block; font-size: 11.5px; color: var(--text-secondary); }

.mst-tag {
    display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 11.5px;
    border: 1px solid color-mix(in srgb, var(--accent) 34%, transparent);
    background: var(--mst-tint); color: var(--accent); white-space: nowrap;
}
.mst-tag.ok { border-color: color-mix(in srgb, var(--mst-ok) 38%, transparent); background: color-mix(in srgb, var(--mst-ok) 12%, transparent); color: var(--mst-ok); }
.mst-tag.warn { border-color: color-mix(in srgb, var(--mst-warn) 38%, transparent); background: color-mix(in srgb, var(--mst-warn) 14%, transparent); color: var(--mst-warn); }
.mst-tag.bad { border-color: color-mix(in srgb, var(--mst-bad) 38%, transparent); background: color-mix(in srgb, var(--mst-bad) 12%, transparent); color: var(--mst-bad); }
.mst-tag.gray { border-color: var(--mst-line); background: transparent; color: var(--text-secondary); }

/* ---------------- 子页签 ---------------- */
.mst-subtabs { display: flex; gap: 6px; margin-bottom: 10px; border-bottom: 1px solid var(--mst-line); }
.mst-subtab {
    height: 34px; padding: 0 14px; font-size: 13px; font-family: inherit; cursor: pointer;
    color: var(--text-secondary); background: transparent;
    border: 0; border-bottom: 2px solid transparent; border-radius: 6px 6px 0 0;
}
.mst-subtab.is-on { color: var(--accent); font-weight: 600; border-bottom-color: var(--accent); }
.mst-subpane[hidden] { display: none !important; }

/* ---------------- 周课表 ---------------- */
.mst-week { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 8px; }
.mst-day { border: 1px solid var(--mst-line); border-radius: var(--radius); background: var(--bg-secondary); display: flex; flex-direction: column; min-height: 120px; }
.mst-day.today { border-color: color-mix(in srgb, var(--accent) 55%, transparent); }
.mst-day-h { font-size: 12px; font-weight: 600; padding: 8px 10px; border-bottom: 1px solid var(--mst-line); color: var(--text-secondary); }
.mst-day.today .mst-day-h { color: var(--accent); }
.mst-day-b { padding: 8px; display: flex; flex-direction: column; gap: 6px; }
.mst-lesson {
    border: 1px solid var(--mst-line); border-radius: 9px; background: var(--bg-primary);
    padding: 7px 8px; font-size: 12px; cursor: pointer; text-align: left;
    display: flex; flex-direction: column; gap: 3px;
}
.mst-lesson:hover { border-color: color-mix(in srgb, var(--accent) 45%, transparent); }
.mst-lesson-t { font-weight: 600; font-size: 12.5px; }
.mst-lesson-s { color: var(--text-secondary); font-size: 11.5px; }
.mst-lesson.is-done { opacity: .72; }
.mst-lesson.is-done .mst-lesson-t { text-decoration: line-through; }
.mst-lesson.is-cancel { opacity: .55; }
.mst-lesson.is-conflict { border-color: var(--mst-bad); }

/* ---------------- 琴房卡片 ---------------- */
.mst-room { border: 1px solid var(--mst-line); border-radius: var(--radius); background: var(--bg-secondary); padding: 12px; }
.mst-room-h { display: flex; align-items: center; gap: 6px; font-weight: 600; font-size: 13.5px; }
.mst-room-m { font-size: 12px; color: var(--text-secondary); margin-top: 4px; }
.mst-room-f { display: flex; gap: 6px; margin-top: 10px; }

/* ---------------- 表单 / 弹窗 ---------------- */
.mst-form { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 10px; }
.mst-f { display: flex; flex-direction: column; gap: 4px; font-size: 12.5px; color: var(--text-secondary); }
.mst-f input, .mst-f select, .mst-f textarea {
    font-family: inherit; font-size: 13.5px; color: var(--text-primary);
    background: var(--bg-primary); border: 1px solid var(--mst-line); border-radius: 8px;
    padding: 7px 9px; box-sizing: border-box; width: 100%;
}
.mst-f textarea { min-height: 76px; resize: vertical; }
.mst-f input:focus, .mst-f select:focus, .mst-f textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--mst-tint); }
.mst-f-full { grid-column: 1 / -1; }
.mst-checks {
    display: flex; flex-wrap: wrap; gap: 6px;
    padding: 7px 8px; border: 1px solid var(--mst-line); border-radius: 8px; background: var(--bg-primary);
    max-height: 148px; overflow: auto;
}
.mst-chk {
    display: inline-flex; align-items: center; gap: 4px; padding: 3px 8px;
    font-size: 12.5px; color: var(--text-primary);
    border: 1px solid var(--mst-line); border-radius: 999px; background: var(--bg-secondary); cursor: pointer;
}
.mst-chk input { margin: 0; }

.mst-mask {
    position: fixed; inset: 0; z-index: 100000; display: flex; align-items: center; justify-content: center;
    background: rgba(0, 0, 0, .45); padding: 18px;
}
.mst-mask[hidden] { display: none !important; }
.mst-modal {
    width: 100%; max-width: 620px; max-height: 88vh; display: flex; flex-direction: column;
    background: var(--bg-primary); border: 1px solid var(--mst-line); border-radius: 14px;
    box-shadow: 0 18px 48px rgba(0, 0, 0, .28);
}
.mst-modal-h { display: flex; align-items: center; gap: 8px; padding: 12px 14px; border-bottom: 1px solid var(--mst-line); }
.mst-modal-h h2 { font-size: 15px; margin: 0; flex: 1 1 auto; }
.mst-x { width: 30px; height: 30px; border: 0; background: transparent; color: var(--text-secondary); font-size: 15px; cursor: pointer; border-radius: 7px; }
.mst-x:hover { background: var(--bg-secondary); color: var(--text-primary); }
.mst-modal-b { padding: 14px; overflow: auto; }
.mst-modal-f { display: flex; gap: 8px; justify-content: flex-end; padding: 12px 14px; border-top: 1px solid var(--mst-line); }

.mst-detail { font-size: 13px; }
.mst-detail h4 { font-size: 13px; margin: 14px 0 6px; color: var(--text-secondary); font-weight: 600; }
.mst-kv { display: grid; grid-template-columns: 88px minmax(0, 1fr); gap: 6px 10px; line-height: 1.7; }
.mst-kv span { color: var(--text-secondary); }
.mst-log { display: flex; flex-direction: column; gap: 6px; }
.mst-log-i { border: 1px solid var(--mst-line); border-radius: 8px; padding: 7px 9px; background: var(--bg-secondary); font-size: 12.5px; }
.mst-log-i b { font-weight: 600; }
.mst-log-i .mst-log-t { color: var(--text-secondary); font-size: 11.5px; }

/* ---------------- Toast ---------------- */
.mst-toast {
    position: fixed; left: 50%; bottom: 34px; transform: translateX(-50%);
    z-index: 120000; max-width: 84vw;
    padding: 9px 16px; border-radius: 10px; font-size: 13px;
    background: var(--text-primary); color: var(--bg-primary);
    box-shadow: 0 10px 30px rgba(0, 0, 0, .25);
}
.mst-toast[hidden] { display: none !important; }

/* ---------------- 响应式 ---------------- */
@media (max-width: 1099px) {
    .mst-cols { grid-template-columns: minmax(0, 1fr); }
    .mst-week { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}
@media (max-width: 900px) {
    .mst-body { grid-template-columns: minmax(0, 1fr); }
    .mst-nav {
        position: static; flex-direction: row; overflow-x: auto; gap: 6px;
        padding-bottom: 4px; -webkit-overflow-scrolling: touch;
    }
    .mst-navbtn { flex: 0 0 auto; height: 34px; white-space: nowrap; border-color: var(--mst-line); }
}
@media (max-width: 760px) {
    .mst-week { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .mst-top-l { flex: 1 1 100%; }
    .mst-top-r { flex: 1 1 100%; }
    .mst-top-r .mst-btn { flex: 1 1 auto; }
    .mst-kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .mst-input, .mst-f input, .mst-f select, .mst-f textarea { font-size: 16px; }
    .mst-btn { height: 36px; }
    .mst-modal { max-height: 92vh; }
    .mst-mask { padding: 0; align-items: flex-end; }
    .mst-modal { border-radius: 16px 16px 0 0; max-width: none; }
}
@media (max-width: 520px) {
    .mst-week { grid-template-columns: minmax(0, 1fr); }
    .mst-cards { grid-template-columns: minmax(0, 1fr); }
    .mst-kv { grid-template-columns: 74px minmax(0, 1fr); }
}

@media print {
    .mst-nav, .mst-top-r, .mst-bar, .mst-toast, .mst-mask { display: none !important; }
}

/* ================= 渲染性能（2026-10-17 优化轮） =================
   表格行 / 卡片数量可能很大（几百学员、上千条流水），
   用 contain 把重排范围限制在各自容器内，离屏面板跳过首次布局与绘制。
   注意：不能加在 .mst-table-wrap 上（它自身要横向滚动）。 */
.mst-table tbody tr { contain: layout style; }
.mst-cards > * { contain: layout style; }
.mst-day { contain: layout style; }
.mst-kpis > * { contain: layout style; }

/* 未激活的面板跳过首绘；给一个经验高度避免滚动条跳动 */
@media (min-width: 901px) {
    .mst-pane[hidden] {
        content-visibility: auto;
        contain-intrinsic-size: auto 420px;
    }
}

/* 横向溢出兜底（表格 min-width 720px + 窄屏最容易踩） */
.mst-pane { min-width: 0; }
.mst-week { min-width: 0; }

/* 流水被截断时的提示行 */
.mst-more-tip {
    font-size: 12px; color: var(--text-secondary); text-align: center;
    background: color-mix(in srgb, var(--accent) 6%, transparent);
}
