/* Screen-only layout: document and print formatting remain independent. */
input[type="checkbox"], input[type="radio"] { width:16px; height:16px; min-width:16px; min-height:16px; max-width:16px; padding:0; flex:0 0 16px; vertical-align:middle; }
.lesson-report-page label:has(input[type="checkbox"]) { display:flex; align-items:center; gap:7px; min-height:32px; }
.customer-divider-option { display:flex; align-items:center; gap:8px; font-weight:400; }
.customer-divider-option input { width:auto; min-height:0; }
.customer-data-field.customer-column-divider { position:relative; }
.customer-column-divider::before { content:''; position:absolute; z-index:2; top:0; bottom:-15px; left:-8px; width:var(--customer-divider-width,1px); background:var(--customer-divider-color,#d4dde0); pointer-events:none; }
.customer-data-field.customer-row-divider { position:relative; }
.customer-row-divider::after { content:''; position:absolute; z-index:2; left:0; right:0; bottom:-8px; height:var(--customer-divider-width,1px); background:var(--customer-divider-color,#d4dde0); pointer-events:none; }
.customer-divider-settings { display:grid; grid-template-columns:repeat(auto-fit,minmax(160px,1fr)); gap:12px; align-items:end; }
.customer-divider-settings h3, .customer-divider-settings > .hint { grid-column:1/-1; }
.customer-divider-line-add { display:grid; grid-template-columns:minmax(180px,1fr) minmax(160px,220px) auto; gap:10px; align-items:end; margin:12px 0 16px; padding:12px; border:1px solid var(--input-border); border-radius:10px; background:var(--input-background); }
.customer-section-row:last-child .customer-column-divider::before { bottom:0; }
#app { display:block; }
#app > aside { display:flex; flex-direction:row; flex-wrap:wrap; position:sticky; top:0; height:auto; max-height:80dvh; padding:10px max(12px, env(safe-area-inset-right)); gap:8px; z-index:30; overflow:auto; }
#app > aside h2 { display:none; }
#app > aside #menuToggle { display:block; min-width:110px; min-height:44px; margin:0; color:white; border:1px solid #ffffff55; }
#app > aside:not(.menu-open) > :not(#menuToggle):not(.navigation-shortcuts) { display:none !important; }
#app > aside > .navigation-shortcuts { display:flex; flex:0 0 auto; align-items:center; gap:8px; }
#app > aside.menu-open { position:fixed; inset:0 auto 0 0; width:min(320px,90vw); height:100dvh; max-height:100dvh; flex-direction:column; flex-wrap:nowrap; align-items:stretch; box-shadow:12px 0 40px #0005; }
#app > aside.menu-open button[data-page], #app > aside.menu-open #logout { flex:0 0 auto; width:100%; margin:0; padding:10px 12px; min-height:44px; }
.menu-backdrop { position:fixed; inset:0; background:#10282166; z-index:29; border:0; border-radius:0; }
.menu-backdrop:hover, .menu-backdrop:active { background:#10282166; transform:none; }
.template-preview-dialog { width:min(950px,96vw); padding:18px; }
.template-preview-dialog > header { display:flex; align-items:center; justify-content:space-between; gap:12px; }
.template-preview-dialog iframe { display:block; width:100%; height:65dvh; border:1px solid var(--input-border); background:white; }
main { min-width:0; }
#content { max-width:100%; overflow-x:auto; }
.table-scroll, .annual-exam-wrap { max-width:100%; overscroll-behavior-x:contain; }
@media(max-width:1100px) {
  main { padding:20px 14px; }
  main > header { flex-wrap:wrap; }
  #actions, #toolbar { flex-wrap:wrap; }
  #modal { width:calc(100vw - 20px); max-width:calc(100vw - 20px); }
  #modalBody { min-width:0; max-height:70dvh; padding:16px; }
  .fieldrow, .class-field-row, .customer-field-row, .sheet-order-row, .task-column-row, .section-row { min-width:0; grid-template-columns:repeat(2,minmax(0,1fr)); }
  .customer-field-admin .customer-field-row { min-width:1480px; grid-template-columns:minmax(225px,1.2fr) minmax(150px,.9fr) 145px minmax(155px,.9fr) minmax(190px,1fr) minmax(270px,1.25fr) 105px 95px; }
  .price-service-row { grid-template-columns:minmax(0,1fr) minmax(0,1fr); }
  .document-upload-grid, .document-recipient-grid, .customer-folder-add, .customer-folder-create-row, .misc-report-grid, .backup-panel { grid-template-columns:repeat(2,minmax(0,1fr)); }
  .customer-folder-add > div { grid-template-columns:minmax(0,1fr); }
  .contract-create-classes, .contract-create-discounts, .contract-template-choice { max-width:100%; }
  .contract-editor, .template-editor { min-width:0; }
  .rich-text-box { min-width:0; max-width:100%; overflow-x:auto; }
  .rich-text-toolbar { flex-wrap:wrap; }
  #modalForm > footer { flex-wrap:wrap; }
  input, select, textarea { min-width:0; max-width:100%; }
  button, input, select { min-height:44px; }
  .customer-data-field.review-active-layout { --customer-field-height:44px; }
}

/* Kopfwerkzeuge rechts anordnen und exakt auf Buttonhöhe bringen. */
main > header {
  --workspace-control-height:34px;
  column-gap:7px;
}
#toolbar {
  align-items:center;
  justify-content:flex-start;
  gap:7px;
}
#toolbar > :first-child {
  margin-left:auto;
}
#toolbar > input,
#toolbar > select,
#toolbar > button,
#toolbar > label > input:not([type="checkbox"]):not([type="radio"]),
#toolbar > label > select,
#actions > button {
  box-sizing:border-box;
  height:var(--workspace-control-height);
  min-height:var(--workspace-control-height) !important;
  max-height:var(--workspace-control-height);
}
#toolbar > label {
  display:flex;
  align-items:center;
  min-height:var(--workspace-control-height);
  height:var(--workspace-control-height);
  margin:0;
  gap:6px;
  white-space:nowrap;
}
.workspace-header-actions,
#actions {
  align-items:center;
  justify-content:flex-end;
}

@media (pointer:coarse) {
  main > header {
    --workspace-control-height:36px;
  }
}

/* Filter und Werkzeuge stehen in jedem Menü zwischen Titel und Aktionen. */
main > header {
  display:grid;
  grid-template-columns:minmax(180px,auto) minmax(0,1fr) auto;
  grid-template-areas:"title toolbar actions";
  align-items:center;
  column-gap:7px;
}
.workspace-title {
  grid-area:title;
  min-width:0;
}
#toolbar {
  grid-area:toolbar;
  width:100%;
  min-width:0;
  min-height:0;
  margin:0;
  padding:0;
  flex-wrap:nowrap;
  overflow-x:auto;
  overscroll-behavior-x:contain;
  scrollbar-width:thin;
}
#toolbar > input,
#toolbar > select,
#toolbar > label,
#toolbar > button {
  flex:0 0 auto;
}
.workspace-header-actions {
  grid-area:actions;
  justify-self:end;
}

@media (max-width:700px),
       (max-width:1000px) and (pointer:coarse),
       (max-height:650px) and (pointer:coarse) {
  main > header {
    grid-template-columns:minmax(0,1fr);
    grid-template-areas:
      "title"
      "toolbar"
      "actions";
  }
  #toolbar {
    justify-content:flex-start;
  }
  .workspace-header-actions {
    justify-self:stretch;
  }
}
@media (min-width:601px) and (max-width:1100px),
       (min-width:601px) and (max-width:1366px) and (pointer:coarse) {
  #modalBody .customer-section-row {
    grid-template-columns:minmax(0,1fr) !important;
  }
  #modalBody .customer-data-field {
    width:100%;
    min-width:0;
  }
  #modalBody .customer-data-field > .aligned-field-label {
    grid-template-columns:clamp(140px,22vw,220px) minmax(0,1fr);
  }
  #modalBody .customer-data-field.review-active-layout {
    grid-template-columns:minmax(0,1fr) 233px;
    column-gap:10px;
  }
  #modalBody .review-settings {
    grid-column:2;
    grid-row:1;
    grid-template-columns:38px;
    width:38px;
    justify-self:end;
  }
  #modalBody .review-settings.review-enabled {
    grid-template-columns:38px 145px 38px;
    width:233px;
  }
  #modalBody .review-settings.review-done {
    grid-template-columns:38px;
    width:38px;
  }
}
@media(max-width:600px) {
  .customer-divider-line-add { grid-template-columns:minmax(0,1fr); }
  .customer-section-filter { flex-direction:column; gap:6px; }
  .customer-section-filter > strong { min-width:0; padding-top:0; }
  .customer-section-filter details { width:100%; min-width:0; }
  #app > aside.menu-open button[data-page], #app > aside.menu-open #logout { flex-basis:auto; }
  #modalBody, .customer-section-row, .two-col, .document-format-controls,
  .document-upload-grid, .document-recipient-grid, .customer-folder-add, .customer-folder-create-row,
  .misc-report-grid, .backup-panel, .contract-discount-row, .contract-service-row,
  .price-service-row, .fieldrow, .class-field-row, .customer-field-row,
  .sheet-order-row, .task-column-row, .section-row { grid-template-columns:minmax(0,1fr); }
  .customer-field-admin .customer-field-row { min-width:1480px; grid-template-columns:minmax(225px,1.2fr) minmax(150px,.9fr) 145px minmax(155px,.9fr) minmax(190px,1fr) minmax(270px,1.25fr) 105px 95px; }
  .customer-field-single { grid-column:1 / -1 !important; }
  #modalBody .customer-fixed-row { grid-template-columns:minmax(0,1fr) !important; }
  #modalBody .customer-data-field.review-active-layout {
    grid-template-columns:minmax(0,1fr) 245px;
    column-gap:8px;
  }
  #modalBody .review-settings {
    grid-column:2;
    grid-row:1;
    width:44px;
    justify-self:end;
  }
  #modalBody .review-settings.review-enabled { width:245px; }
  #modalBody .review-settings.review-done { width:44px; }
  .template-heading, .contract-block-card > header { flex-direction:column; align-items:stretch; }
  .contract-block-card { padding:10px; }
  .contract-block-add, .contract-placeholder-insert { align-items:stretch; }
  .contract-block-add > *, .contract-placeholder-insert > * { width:100%; min-width:0; }
  .output-options { grid-template-columns:1fr; padding:14px; }
  #login form { padding:24px; }
  #modalForm > header, #modalForm > footer { padding:12px; }
  #modalForm > footer > button { flex:1 1 auto; }
}

/* Kompakter Kopfbereich auf Handy und Tablet, damit Listen früher beginnen. */
@media (max-width:1100px),
       (max-width:1366px) and (pointer:coarse) {
  #app > aside {
    padding:6px max(10px, env(safe-area-inset-right));
  }
  #app > aside #menuToggle {
    min-height:38px;
    padding:6px 10px;
  }
  main {
    padding:10px 12px 18px;
  }
  main > header {
    min-height:0;
    gap:8px;
    padding-bottom:8px;
  }
  main > header h1 {
    margin:0;
    font-size:clamp(1.35rem,3vw,1.75rem);
    line-height:1.08;
  }
  main > header small {
    font-size:.62rem;
  }
  #actions {
    gap:6px;
  }
  #actions > button {
    min-height:36px;
    padding:5px 10px;
  }
  #toolbar {
    min-height:0;
    gap:6px;
    margin:8px 0 10px;
    padding:3px 0;
  }
  #toolbar > input,
  #toolbar > select,
  #toolbar > label,
  #toolbar > button {
    min-height:38px;
  }
}

@media (max-width:600px) {
  main {
    padding:8px 10px 14px;
  }
  main > header {
    gap:6px;
    padding-bottom:6px;
  }
  main > header h1 {
    font-size:1.35rem;
  }
  #toolbar {
    margin:6px 0 8px;
    padding:2px 0;
  }
}

/* Handy: Kopfzeilen bleiben einzeilig und dürfen horizontal scrollen statt umzubrechen. */
@media (max-width:700px),
       (max-width:1000px) and (pointer:coarse),
       (max-height:650px) and (pointer:coarse) {
  #app > aside {
    min-height:0;
    padding:4px 8px;
  }
  #app > aside #menuToggle {
    min-width:96px;
    min-height:34px;
    padding:4px 8px;
    font-size:.92rem;
  }
  main {
    padding:6px 8px 12px;
  }
  main > header {
    display:grid;
    grid-template-columns:minmax(0,1fr);
    gap:4px;
    min-height:0;
    padding-bottom:4px;
  }
  main > header small {
    display:none;
  }
  main > header h1 {
    margin:0;
    font-size:1.2rem;
    line-height:1.05;
  }
  .workspace-header-actions {
    display:flex;
    width:100%;
    max-width:100%;
    flex-wrap:nowrap;
    gap:5px;
    overflow-x:auto;
    overscroll-behavior-x:contain;
    scrollbar-width:thin;
  }
  #actions {
    display:flex;
    flex:0 0 auto;
    width:max-content;
    flex-wrap:nowrap;
    gap:5px;
  }
  #actions > button {
    flex:0 0 auto;
    min-height:32px;
    padding:4px 8px;
    font-size:.85rem;
    white-space:nowrap;
  }
  #toolbar {
    display:flex;
    max-width:100%;
    min-height:0;
    flex-wrap:nowrap;
    align-items:center;
    gap:5px;
    margin:4px 0 6px;
    padding:0;
    overflow-x:auto;
    overscroll-behavior-x:contain;
    scrollbar-width:thin;
  }
  #toolbar > input,
  #toolbar > select,
  #toolbar > label,
  #toolbar > button {
    flex:0 0 auto;
    min-width:120px;
    min-height:34px;
    padding:4px 8px;
    font-size:.88rem;
  }
  #toolbar > label {
    display:flex;
    align-items:center;
    gap:5px;
    width:auto;
    white-space:nowrap;
  }
  #content {
    min-height:0;
  }
}

/* Die Administrationsbereiche werden kompakt über eine Auswahl geöffnet. */
#toolbar.admin-menu-select {
  display:flex;
  justify-content:flex-end;
  overflow:visible;
}
#toolbar.admin-menu-select > label {
  width:min(100%,360px);
  height:auto;
  margin-left:auto;
}
#toolbar.admin-menu-select select {
  width:100%;
  min-width:220px;
}

/* Erklärende Hilfetexte werden programmweit ausgeblendet. */
.hint,
.field-help,
.placeholder-help,
.output-help,
.output-field-hint,
.annual-sheet-help {
  display:none !important;
}

/* Interne Dokumentvorschau ohne Browser-Download. */
.file-preview-dialog {
  width:min(1200px,96vw);
  max-width:none;
  height:94dvh;
  max-height:94dvh;
  padding:0;
  border:0;
  border-radius:14px;
  overflow:hidden;
  background:#e9efee;
}
.file-preview-dialog::backdrop {
  background:rgba(7,25,22,.72);
}
.file-preview-window {
  display:grid;
  grid-template-rows:auto auto minmax(0,1fr);
  width:100%;
  height:100%;
}
.file-preview-window > header {
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:12px;
  padding:10px 14px;
  background:var(--content-bg,#fff);
  border-bottom:1px solid var(--line,#d4dde0);
}
.file-preview-window h2 {
  min-width:0;
  margin:0;
  overflow:hidden;
  text-overflow:ellipsis;
  white-space:nowrap;
}
.file-preview-actions {
  display:flex;
  flex:0 0 auto;
  gap:7px;
}
.file-preview-status {
  margin:0;
  padding:12px 16px;
  background:var(--content-bg,#fff);
  text-align:center;
}
.file-preview-content {
  min-height:0;
  padding:16px;
  overflow:auto;
  overscroll-behavior:contain;
}
.file-preview-page {
  width:min(100%,900px);
  margin:0 auto 16px;
  background:white;
  box-shadow:0 4px 18px rgba(0,0,0,.18);
}
.file-preview-page canvas,
.file-preview-image {
  display:block;
  width:100%;
  height:auto;
}
.file-preview-image {
  max-width:100%;
  width:auto;
  margin:0 auto;
  background:white;
}
.file-preview-text {
  box-sizing:border-box;
  width:min(100%,900px);
  min-height:100%;
  margin:0 auto;
  padding:20px;
  overflow-wrap:anywhere;
  white-space:pre-wrap;
  background:white;
}
@media (max-width:700px) {
  #toolbar.admin-menu-select > label {
    width:100%;
  }
  #toolbar.admin-menu-select select {
    min-width:0;
  }
  .file-preview-dialog {
    width:100vw;
    height:100dvh;
    max-height:100dvh;
    margin:0;
    border-radius:0;
  }
  .file-preview-window > header {
    padding:7px 8px;
  }
  .file-preview-window h2 {
    font-size:1rem;
  }
  .file-preview-actions button {
    padding-inline:7px !important;
  }
  .file-preview-content {
    padding:8px;
  }
  .file-preview-page {
    margin-bottom:8px;
  }
}

/* Nachrichtenfilter erhalten eine eigene Zeile statt einer scrollenden Kopfspalte. */
main > header:has(#toolbar.submission-toolbar) {
  grid-template-columns:minmax(0,1fr) auto;
  grid-template-areas:"title actions" "toolbar toolbar";
  row-gap:8px;
}
#toolbar.submission-toolbar {
  flex-wrap:wrap;
  overflow-x:visible;
  gap:7px;
}
#toolbar.submission-toolbar > :first-child { margin-left:0; }
#toolbar.submission-toolbar > select,
#toolbar.submission-toolbar > input,
#toolbar.submission-toolbar > label,
#toolbar.submission-toolbar > button {
  flex:0 1 auto;
  min-width:0;
  max-width:100%;
  padding-inline:8px;
}
#toolbar.submission-toolbar #submissionFormFilter { flex-basis:155px; }
#toolbar.submission-toolbar #submissionStatusFilter { flex-basis:150px; }
#toolbar.submission-toolbar .submission-date-filter { flex-basis:185px; padding:0; }
#toolbar.submission-toolbar .submission-date-filter input { width:135px; min-width:0; }
#toolbar.submission-toolbar #submissionSearch { flex:1 1 180px; width:180px; }
#toolbar.submission-toolbar #openSubmissionFieldPicker { white-space:nowrap; }
@media (max-width:700px),
       (max-width:1000px) and (pointer:coarse),
       (max-height:650px) and (pointer:coarse) {
  main > header:has(#toolbar.submission-toolbar) {
    grid-template-columns:minmax(0,1fr);
    grid-template-areas:"title" "toolbar" "actions";
  }
  #toolbar.submission-toolbar > select,
  #toolbar.submission-toolbar > input,
  #toolbar.submission-toolbar > label,
  #toolbar.submission-toolbar > button { flex:1 1 145px; }
  #toolbar.submission-toolbar .submission-date-filter input { flex:1; width:100%; }
}

/* Jahresplaner: Aktionen zuerst, Planungsjahr und Filter darunter. */
main > header:has(#examPlanningYear) {
  grid-template-columns:minmax(0,1fr) auto;
  grid-template-areas:"title actions" "toolbar toolbar";
  row-gap:8px;
}
#toolbar:has(#examPlanningYear) {
  justify-content:flex-end;
  flex-wrap:nowrap;
  overflow-x:visible;
  gap:7px;
}
#toolbar:has(#examPlanningYear) > :first-child { margin-left:0; }
@media (max-width:700px),
       (max-width:1000px) and (pointer:coarse),
       (max-height:650px) and (pointer:coarse) {
  main > header:has(#examPlanningYear) {
    grid-template-columns:minmax(0,1fr);
    grid-template-areas:"title" "actions" "toolbar";
  }
  #toolbar:has(#examPlanningYear) { flex-wrap:wrap; }
  #toolbar:has(#examPlanningYear) > button { min-width:0; }
}
