/* Responsive workbench layouts. */
.page, .page > *, .score-layout > *, .set-layout > *, .grid2 > *, .grid3 > *, .row2 > *, .row3 > * { min-width: 0; }
.score-layout { grid-template-columns: 260px minmax(0, 1fr); }
.set-layout { grid-template-columns: 180px minmax(0, 1fr); }
.grid2, .row2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid3, .row3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.tbl-wrap, .book-wrap { max-width: 100%; overscroll-behavior-x: contain; }
.table-scroll { width: 100%; max-width: 100%; overflow-x: auto; overscroll-behavior-x: contain; }
.chart, .sm-cell { min-width: 0; }
.chart > svg { max-width: 100%; height: auto; }
.page-head > .seg { max-width: 100%; flex-wrap: wrap; border-radius: 15px; }
.filterbar > *, .pro-toolbar > * { max-width: 100%; }
.modal, .drawer { max-height: 100dvh; }
.pop { max-width: calc(100vw - 20px); max-height: calc(100dvh - 20px); overflow-y: auto; }
.modal { max-height: calc(100dvh - 32px); }
.modal-body, .drawer-body { min-height: 0; overscroll-behavior: contain; }
.modal-head, .modal-foot { flex-shrink: 0; }
.tabs { overflow-x: auto; flex-shrink: 0; scrollbar-width: thin; }
.tabs button { flex-shrink: 0; }
.toast { max-width: calc(100vw - 32px); white-space: normal; text-align: center; }
.pro-model-catalog { grid-template-columns: repeat(auto-fit, minmax(min(100%, 240px), 1fr)); }
.pro-model-row .chk { min-width: 0; }
.pro-model-row .chk input { flex-shrink: 0; }
.pro-account-head h2, .pro-account-head .muted { overflow-wrap: anywhere; }
.pro-account-head > div:first-child { min-width: 0; }
.pro-account-head > div:first-child > div { min-width: 0; }
.pro-between { flex-wrap: wrap; }
.pro-page .tbl td { max-width: 440px; }
.pro-page .tbl-wrap { position: relative; }
@media (max-width: 1280px) {
  .rail-close { display: flex; position: sticky; top: -46px; margin: -42px 0 14px auto; align-items: center; gap: 6px; padding: 7px 10px; background: #fff; border: 1px solid var(--line2); border-radius: 9px; color: var(--ink); z-index: 2; }
  .app.with-rail .rail { width: min(320px, calc(100vw - 32px)); padding: 60px 18px 20px; z-index: 60; }
  .app.rail-open .rail { border-left: 1px solid var(--line2); }
}
@media (max-width: 1080px) {
  .score-layout, .set-layout { grid-template-columns: minmax(0, 1fr); }
  .grid2 { grid-template-columns: minmax(0, 1fr); }
  .nav a, .nav button { min-height: 38px; }
  .me { justify-content: center; padding: 8px 0; }
  .side-foot { flex-shrink: 0; }
  .set-nav { gap: 5px; }
  .set-nav button { flex-shrink: 0; }
  .dev-mail { flex-wrap: wrap; }
  .dev-mail a { overflow-wrap: anywhere; max-width: 100%; }
  .page-head { gap: 10px; }
}
@media (max-width: 760px) {
  :root { --side-w: 56px; }
  .side { padding: 14px 6px 8px; }
  .brand { padding: 2px 0 12px; }
  .page { padding: 54px 16px 28px; overflow-x: hidden; }
  .page-head { padding-right: 0; margin-bottom: 16px; align-items: flex-start; }
  .page-head > .grow { flex-basis: 100%; height: 0; }
  .page-head .page-title { font-size: 20px; }
  .pro-page > .page-head { padding-top: 0; }
  .page-head .sel { max-width: 100%; }
  .grid3 { grid-template-columns: minmax(0, 1fr); }
  .panel, .pro-paper, .pro-communication { padding: 16px; }
  .pro-topup { padding: 18px 16px; }
  .pro-account-stats .panel { padding: 20px; }
  .pro-account-head { padding: 18px 16px; }
  .pro-account-stats { gap: 12px; }
  .pro-account-head .pro-actions { width: 100%; }
  .pro-account-head .pro-actions .btn { flex: 1; }
  .pro-toolbar { align-items: stretch; }
  .pro-toolbar label { flex-wrap: wrap; width: 100%; }
  .pro-toolbar .inp, .pro-toolbar .sel, .filterbar .inp { width: 100%; min-width: 0; }
  .pro-paper-foot { flex-wrap: wrap; }
  .pro-payment { align-items: center; gap: 14px; }
  .pro-qr { width: min(210px, 100%); }
  .pro-communication > .pro-between { gap: 12px; }
  .pro-communication .tag { margin-left: 0; }
  .pro-thumbnails { max-width: 100%; }
  .an-scope { grid-template-columns: minmax(0, 1fr); }
  .an-scope button { padding: 12px; }
  .an-cls.seg { display: flex; flex-wrap: wrap; border-radius: 14px; }
  #scTabs { display: flex; flex-wrap: wrap; border-radius: 14px; }
  .small-mult { grid-template-columns: minmax(0, 1fr); }
  .pg-cards { grid-template-columns: repeat(auto-fill, minmax(min(100%, 250px), 1fr)); }
  .score-layout .exam-list { display: grid; grid-template-columns: minmax(0, 1fr); }
  .paste-hint { align-items: flex-start; flex-wrap: wrap; }
  .set-sec .tbl:has([data-inp="per-field"]) thead { display: none; }
  .set-sec .tbl:has([data-inp="per-field"]) tr { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 6px 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
  .set-sec .tbl:has([data-inp="per-field"]) td { padding: 0; border: 0; }
  .set-sec .tbl:has([data-inp="per-field"]) td:first-child { grid-column: 1; grid-row: 1; }
  .set-sec .tbl:has([data-inp="per-field"]) td:last-child { grid-column: 2; grid-row: 1; align-self: center; }
  .set-sec .tbl:has([data-inp="per-field"]) td:nth-child(2)::before { content: "开始"; }
  .set-sec .tbl:has([data-inp="per-field"]) td:nth-child(3)::before { content: "结束"; }
  .set-sec .tbl:has([data-inp="per-field"]) td::before { display: block; color: var(--ink2); font-size: 12px; margin-bottom: 4px; }
  .set-sec .tbl:has([data-inp="per-field"]) input { min-width: 0; width: 100% !important; }
  .reason-add { flex-wrap: wrap; }
  .reason-add #newRs { width: 100% !important; }
  .ai-home { padding: 58px 16px 24px; }
  .ai-hello { align-items: flex-start; gap: 10px; }
  .ai-hello h1 { font-size: 21px; }
  .ai-hello p { flex-wrap: wrap; font-size: 13px; }
  .ai-thread { padding: 16px; }
  .ai-foot { padding: 10px 16px 18px; }
  .thread-head { flex-wrap: wrap; padding: 48px 16px 0 !important; }
  .thread-head .t { min-width: 0; overflow-wrap: anywhere; }
  .composer-foot { flex-wrap: wrap; }
  .tpl-grid { grid-template-columns: minmax(0, 1fr); }
  .tpl-tabs { max-width: 100%; overflow-x: auto; }
  .tpl-tabs button { flex-shrink: 0; }
  .class-page .cls-bar { left: 10px; right: 10px; top: 48px; max-width: none !important; flex-wrap: wrap; gap: 6px; }
  .cls-bar .cls-seg { flex-basis: 100%; min-width: 0; }
  .cls-bar .cls-seg button { padding: 0 10px; }
  .cls-bar .cls-status { display: none; }
  .class-page .top-tools { left: 10px; right: 10px; top: 126px; flex-wrap: wrap; gap: 6px; }
  .top-tools > .btn { padding: 0 10px; height: 32px; font-size: 12px; }
  .top-tools .btn-icon { width: 32px; padding: 0; }
  .top-tools .zoom { margin-left: auto; }
  .class-page .stage { top: 168px; bottom: 190px; }
  .dock { width: calc(100% - 20px); max-width: none; bottom: 12px; gap: 8px; max-height: 40dvh; overflow-y: auto; overflow-x: hidden; padding: 2px; overscroll-behavior: contain; scrollbar-width: thin; }
  .dock > .seg { display: flex; flex-wrap: wrap; justify-content: center; width: 100%; border-radius: 16px; }
  .dock .seg button { height: 34px; padding: 0 9px; }
  .dock .subbar { flex-wrap: wrap; justify-content: center; width: 100%; max-height: none; overflow: visible; padding: 10px; gap: 8px; }
  .dock .subbar .sel, .dock .subbar .inp { min-width: 0; max-width: 100%; }
  .dock .subbar b { max-width: 100%; }
  .dock .subbar .btn { white-space: nowrap; }
  .dock .legend-ramp { flex-wrap: wrap; }
  .pick-card { max-width: calc(100% - 24px); }
  .dr-hero { padding: 20px 16px 18px; gap: 12px; }
  .dr-name { font-size: 22px; }
  .drawer-body { padding: 0 16px 24px; }
  .drawer .tabs { margin: 0 16px; gap: 20px; }
  .modal-head { padding: 16px 16px 10px; }
  .modal-body { padding: 14px 16px 6px; }
  .modal-foot { padding: 12px 16px 16px; }
  .modal-foot .btn { min-height: 36px; }
  .row3 { grid-template-columns: minmax(0, 1fr); }
  .info-grid { grid-template-columns: 76px minmax(0, 1fr); gap: 9px; }
  .welcome { display: block; padding: 28px 18px; }
  .welcome-in { margin: 0 auto; }
  .welcome .w-mode { flex-wrap: wrap; }
  .welcome .w-mode button { width: 100%; }
}
@media (max-width: 420px) {
  .row2, .w-form { grid-template-columns: minmax(0, 1fr); }
  .page { padding-left: 12px; padding-right: 12px; }
  .pro-model-row { align-items: flex-start; flex-wrap: wrap; }
  .pro-model-tags { justify-content: flex-start; }
  .pro-auth-shell { width: calc(100% - 24px); padding: 32px 0 24px; }
  .pro-auth-shell .pro-login { padding: 22px 18px; }
  .pro-auth-brand { font-size: 19px; }
  .pro-auth-title { font-size: 22px; }
  .class-page .stage { top: 202px; bottom: 210px; }
  .top-tools .zoom { margin-left: 0; }
  .gender-pick { gap: 10px; flex-wrap: wrap; }
  .dev-info .info-grid { grid-template-columns: minmax(0, 1fr); }
  .dev-info .info-grid > div { overflow-wrap: anywhere; min-width: 0; }
  .dev-info .info-grid .v { display: flex; flex-wrap: wrap; gap: 8px; }
  .set-sec .tbl:has([data-inp="per-field"]) td:nth-child(2),
  .set-sec .tbl:has([data-inp="per-field"]) td:nth-child(3) { grid-column: 1 / -1; }
  .gender-pick button { padding: 10px; }
  .modal { width: calc(100vw - 20px); }
  .kpis { gap: 8px; }
  .kpi { padding: 12px 10px; }
}
@media (max-height: 560px) {
  .drawer { overflow-y: auto; }
  .drawer-body { flex: 0 0 auto; overflow-y: visible; }
}
/* Short landscape windows need a scrollable classroom instead of fixed insets
   that consume the entire canvas height. All classroom actions remain reachable. */
@media (max-height: 620px) {
  .app .side { overflow-y: auto; overscroll-behavior: contain; }
  .app .side > .nav { flex: none; }
}
@media (max-width: 760px) and (max-height: 600px) {
  .class-page { display: flex; flex-direction: column; overflow-y: auto; overscroll-behavior: contain; }
  .class-page .cls-bar { order: 1; position: relative; top: auto; left: auto; right: auto; margin: 48px 10px 0; flex-shrink: 0; }
  .class-page .top-tools { order: 2; position: relative; top: auto; left: auto; right: auto; margin: 8px 10px; flex-shrink: 0; }
  .class-page .stage { order: 3; position: relative; inset: auto; width: 100%; height: 300px; min-height: 300px; flex-shrink: 0; }
  .class-page .dock { order: 4; position: relative; inset: auto; transform: none; margin: 10px auto 16px; max-height: none; overflow: visible; flex-shrink: 0; }
}

/* Validation retains the last saved value and marks the rejected edit. */
.inp[aria-invalid="true"], .sub-item input[aria-invalid="true"] {
  border-color: var(--red); background: var(--red-soft);
  box-shadow: 0 0 0 1px var(--red);
}
