/*
 * ClassFlow viewport fitting
 * --------------------------
 * Ab Tablet-/Notebook-Grösse (>= 900 px Breite und >= 600 px Höhe) bleibt
 * die Anwendung vollständig innerhalb des Browserfensters. Die eigentlichen
 * Arbeitsflächen skalieren in den verfügbaren Raum; Browser-Scrolling ist nur
 * auf kleineren/mobile Viewports vorgesehen.
 */

:root {
  --compact-header-h: 48px;
  --compact-footer-h: 32px;
  --compact-page-gap: 7px;
}

/* Header und Footer generell kompakter. */
.site-header {
  height: var(--compact-header-h);
}
.site-header__inner {
  width: min(1720px, calc(100% - 20px));
  gap: 12px;
}
.brand__logo {
  height: 31px;
  max-width: 180px;
}
.main-navigation {
  gap: 4px;
}
.main-navigation__link {
  padding: 5px 9px;
  border-radius: 8px;
  font-size: 12px;
}
.site-header__account {
  gap: 6px;
}
.account-chip {
  gap: 6px;
}
.account-chip__avatar {
  width: 27px;
  height: 27px;
  border-radius: 8px;
  font-size: 12px;
}
.account-chip__name {
  font-size: 11px;
}
.account-chip__name small {
  font-size: 8px;
}
.site-header .button--small {
  min-height: 29px;
  padding: 4px 8px;
  font-size: 10px;
}
.site-footer__inner {
  width: min(1720px, calc(100% - 20px));
  min-height: var(--compact-footer-h);
  gap: 16px;
}
.site-footer__logo {
  height: 22px;
  max-width: 150px;
}
.site-footer__meta {
  gap: 12px;
  font-size: 9px;
}
.site-footer {
  border-top-width: 2px;
}

/* Kompaktere Grundelemente auf Arbeitsseiten. */
.app-body .button {
  min-height: 34px;
  padding: 6px 10px;
  border-radius: 9px;
  font-size: 12px;
}
.app-body .button--small {
  min-height: 28px;
  padding: 4px 8px;
  font-size: 10px;
}
.app-body input,
.app-body select {
  min-height: 36px;
  padding: 6px 9px;
  border-radius: 9px;
  font-size: 12px;
}
.app-body .eyebrow {
  margin-bottom: 3px;
  font-size: 9px;
}
.app-body .flash-stack {
  gap: 4px;
  margin: 0 0 5px;
}
.app-body .flash {
  padding: 6px 10px;
  border-radius: 8px;
  font-size: 11px;
}

/*
 * Desktop / Notebook / Tablet:
 * kein Browser-Scrollen. Der Main-Bereich ist die flexible mittlere Grid-Zeile.
 */
@media (min-width: 900px) and (min-height: 600px) {
  html,
  body {
    width: 100%;
    height: 100%;
    overflow: hidden;
  }

  .app-body {
    height: 100dvh;
    min-height: 0;
    display: grid;
    grid-template-rows: var(--compact-header-h) minmax(0, 1fr) var(--compact-footer-h);
    overflow: hidden;
  }

  .app-body .site-header {
    position: relative;
    top: auto;
  }

  .app-body .page-shell {
    width: min(1720px, calc(100% - 16px));
    height: 100%;
    min-height: 0;
    margin: 0 auto;
    padding: var(--compact-page-gap) 0;
    overflow: hidden;
  }

  /* ---------- Klassenspiegel ---------- */
  .original-workspace-page .page-shell {
    width: min(1880px, calc(100% - 12px));
    display: flex;
    flex-direction: column;
    gap: 5px;
  }

  .desktop-toolbar {
    flex: 0 0 auto;
    display: grid;
    grid-template-columns:
      minmax(82px, .72fr)
      minmax(210px, 1.75fr)
      minmax(78px, .68fr)
      minmax(118px, 1fr)
      minmax(118px, 1fr)
      minmax(136px, 1.14fr)
      minmax(112px, .95fr);
    gap: 5px;
    margin: 0;
  }

  .desktop-toolbar__group,
  .desktop-toolbar__group:nth-child(n) {
    min-width: 0;
    min-height: 52px;
    max-height: 58px;
    padding: 5px 6px;
    gap: 3px;
    border-radius: 10px;
  }

  .desktop-toolbar__title {
    font-size: 8.5px;
    line-height: 1;
  }

  .desktop-toolbar label {
    gap: 2px;
    font-size: 8.5px;
    line-height: 1.05;
  }

  .desktop-toolbar select,
  .desktop-toolbar .button {
    min-height: 27px;
    height: 27px;
    padding: 3px 5px;
    border-radius: 7px;
    font-size: clamp(8px, .66vw, 10px);
    line-height: 1.05;
  }

  .desktop-toolbar .button {
    white-space: normal;
  }

  .desktop-toolbar__layout,
  .desktop-toolbar__export,
  .desktop-toolbar__groups,
  .desktop-toolbar__row {
    gap: 3px;
  }

  .desktop-toolbar__layout {
    grid-template-columns: minmax(72px, 1fr) minmax(72px, 1fr) minmax(64px, .78fr);
  }

  .classroom-canvas-card {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
    border-radius: 13px;
  }

  .classroom-canvas-card__meta {
    flex: 0 0 auto;
    min-height: 39px;
    padding: 5px 10px;
  }

  .classroom-canvas-card__meta h1 {
    font-size: clamp(15px, 1.35vw, 21px);
  }

  .classroom-canvas-card__meta p {
    margin-top: 0;
    font-size: 9px;
    line-height: 1.15;
  }

  .view-mode-badge {
    padding: 4px 7px;
    font-size: 9px;
  }

  .desk-board {
    flex: 1 1 auto;
    min-height: 0;
    height: auto;
    aspect-ratio: auto;
    border-radius: 0 0 12px 12px;
  }

  /* 1000x680 Original-Geometrie wird per JS proportional skaliert. */
  .desk-board-stage {
    inset: auto;
    left: 50%;
    top: 50%;
    width: 1000px;
    height: 680px;
    transform-origin: center;
    transform: translate(-50%, -50%) scale(var(--desk-stage-scale, 1));
  }

  .desk-board.student-view .desk-board-stage {
    transform: translate(-50%, -50%) scale(var(--desk-stage-scale, 1)) rotate(180deg);
  }

  .drag-help {
    left: 7px;
    bottom: 6px;
    padding: 4px 6px;
    font-size: 8px;
  }

  .overflow-note-original {
    flex: 0 0 auto;
    max-height: 28px;
    margin: 0;
    padding: 4px 8px;
    overflow: hidden;
    font-size: 9px;
    line-height: 1.15;
  }

  /* Klassenverwaltung bleibt ebenfalls innerhalb des Viewports. */
  .desktop-dialog {
    width: min(860px, calc(100% - 24px));
    height: min(610px, calc(100dvh - 30px));
    max-height: calc(100dvh - 30px);
    overflow: hidden;
  }

  .desktop-dialog__header {
    min-height: 42px;
    padding: 7px 11px;
  }

  .desktop-dialog__header h2 {
    font-size: 17px;
  }

  .desktop-dialog__close {
    width: 30px;
    height: 30px;
    font-size: 18px;
  }

  .class-manager {
    height: calc(100% - 42px);
    min-height: 0;
    grid-template-columns: 220px minmax(0, 1fr);
  }

  .class-manager__classes,
  .class-manager__students {
    min-height: 0;
    padding: 10px;
  }

  .class-manager__students {
    overflow: hidden;
  }

  .class-manager__class-list {
    gap: 2px;
    margin: 6px 0 8px;
    max-height: 145px;
    overflow: auto;
  }

  .class-manager__class {
    padding: 4px 6px;
    font-size: 10px;
  }

  .class-manager__actions {
    gap: 4px;
    margin-top: 6px;
  }

  .student-manage-list {
    height: clamp(145px, 31dvh, 230px);
  }

  .student-manage-selector {
    padding: 4px 7px;
    font-size: 10px;
  }

  .student-editor {
    gap: 5px;
    margin-top: 7px;
  }

  .student-editor input {
    min-height: 30px;
  }

  .student-editor label {
    font-size: 10px;
  }

  .student-delete-actions {
    gap: 5px;
    margin-top: 5px;
  }

  /* ---------- Gruppen ---------- */
  .group-workbench-page .page-shell,
  .random-workbench-page .page-shell {
    width: min(1740px, calc(100% - 16px));
    height: 100%;
    margin: 0 auto;
    padding: var(--compact-page-gap) 0;
  }

  .subwindow-shell {
    height: 100%;
    min-height: 0;
    display: flex;
    flex-direction: column;
    border-radius: 13px;
  }

  .subwindow-toolbar {
    flex: 0 0 auto;
    min-height: 46px;
    padding: 5px 8px;
    gap: 8px;
  }

  .subwindow-toolbar__title {
    gap: 6px;
  }

  .subwindow-toolbar__title h1 {
    font-size: clamp(14px, 1.25vw, 19px);
    line-height: 1;
  }

  .subwindow-toolbar__actions,
  .group-settings {
    gap: 4px;
  }

  .group-settings label {
    gap: 1px;
    font-size: 8px;
  }

  .group-settings input,
  .group-settings select {
    width: 86px;
    min-height: 27px;
    height: 27px;
    padding: 3px 5px;
    font-size: 9px;
  }

  .group-board {
    position: relative;
    flex: 1 1 auto;
    min-height: 0;
    padding: 8px;
    overflow: hidden;
  }

  .group-card-grid-original {
    gap: clamp(6px, .7vw, 12px);
    transform-origin: top left;
  }

  .group-card-original h2 {
    padding: 6px 7px 3px;
    font-size: clamp(11px, 1vw, 15px);
    line-height: 1.05;
  }

  .group-dropzone {
    min-height: 40px;
    padding: 3px 6px 6px;
  }

  .group-student {
    padding: 2px 4px;
    font-size: clamp(8px, .8vw, 11px);
    line-height: 1.15;
  }

  .group-board > .muted {
    display: none;
  }

  .group-board .empty-state {
    height: 100%;
    min-height: 0;
    padding: 14px;
  }

  /* ---------- Glücksrad ---------- */
  .random-window {
    flex: 1 1 auto;
    min-height: 0;
    grid-template-columns: minmax(380px, 1.55fr) minmax(280px, .82fr);
  }

  .wheel-panel,
  .random-side {
    min-height: 0;
  }

  .wheel-panel {
    padding: 8px;
    display: flex;
    flex-direction: column;
  }

  .wheel-heading {
    flex: 0 0 auto;
    margin-bottom: 3px;
    font-size: 10px;
  }

  .wheel-wrap {
    flex: 0 0 auto;
    width: 320px;
    height: 320px;
    max-width: 100%;
    margin: auto;
  }

  .wheel-canvas {
    width: 94%;
    height: 94%;
  }

  .wheel-pointer {
    top: 1%;
    border-left-width: 13px;
    border-right-width: 13px;
    border-bottom-width: 30px;
  }

  .wheel-center {
    width: 31%;
    padding: 8px;
    border-width: 3px;
    font-size: clamp(14px, 2vw, 26px);
  }

  .wheel-status-line {
    flex: 0 0 auto;
    margin: 3px 0 0;
    font-size: 10px;
  }

  .random-side {
    padding: 8px 10px;
    overflow: hidden;
  }

  .random-side h2 {
    margin: 0 0 4px;
    font-size: 12px;
  }

  .draw-mode {
    gap: 3px;
    padding: 6px;
    margin-bottom: 5px;
  }

  .draw-mode label {
    font-size: 10px;
  }

  .random-side__buttons {
    gap: 4px;
  }

  .winner-panel,
  .random-status-box,
  .random-history-original {
    margin-top: 6px;
  }

  .winner-panel {
    padding: 6px;
  }

  .winner-display {
    min-height: clamp(54px, 10dvh, 82px);
    padding: 6px;
    font-size: clamp(17px, 2vw, 28px);
  }

  .winner-meta {
    margin-top: 3px;
    font-size: 9px;
  }

  .random-status-box {
    padding: 5px;
    font-size: 9px;
    line-height: 1.2;
  }

  .random-history-original ol {
    min-height: 55px;
    max-height: clamp(55px, 13dvh, 110px);
    padding: 5px 5px 5px 24px;
    font-size: 9px;
  }

  /* ---------- Dashboard ---------- */
  .dashboard-page .page-shell {
    display: grid;
    grid-template-rows: minmax(78px, 14%) 24px minmax(104px, 22%) 24px minmax(0, 1fr);
    gap: 4px;
  }

  .dashboard-page .dashboard-hero {
    min-height: 0;
    height: 100%;
    padding: 9px 16px;
    border-radius: 13px;
  }

  .dashboard-page .dashboard-hero h1 {
    font-size: clamp(20px, 2.55vw, 38px);
    line-height: .96;
  }

  .dashboard-page .dashboard-hero__content > p:not(.eyebrow) {
    max-width: 720px;
    margin: 5px 0 7px;
    font-size: 10px;
  }

  .dashboard-page .dashboard-hero__facts {
    gap: 15px;
  }

  .dashboard-page .dashboard-hero__facts strong {
    font-size: 15px;
  }

  .dashboard-page .dashboard-hero__facts span {
    font-size: 8px;
  }

  .dashboard-page .dashboard-hero__icon {
    right: 24px;
    bottom: -45px;
    width: 145px;
    height: 145px;
  }

  .dashboard-page .section-heading {
    height: 24px;
    min-height: 0;
    margin: 0;
    align-items: center;
  }

  .dashboard-page .section-heading h2 {
    font-size: 14px;
  }

  .dashboard-page .section-heading__hint,
  .dashboard-page .section-badge {
    font-size: 8px;
  }

  .dashboard-page .section-badge {
    padding: 2px 6px;
  }

  .dashboard-page .action-grid {
    min-height: 0;
    gap: 6px;
  }

  .dashboard-page .action-card {
    min-height: 0;
    height: 100%;
    padding: 7px 9px;
    border-radius: 11px;
    gap: 4px;
  }

  .dashboard-page .action-card__number {
    width: 24px;
    height: 18px;
    font-size: 8px;
  }

  .dashboard-page .action-card h3 {
    margin-bottom: 0;
    font-size: 12px;
  }

  .dashboard-page .action-card p {
    font-size: 8.5px;
    line-height: 1.15;
  }

  .dashboard-page .stack-form {
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 4px;
    margin-top: auto;
  }

  .dashboard-page .stack-form input {
    min-height: 28px;
    height: 28px;
    padding: 3px 6px;
    font-size: 9px;
  }

  .dashboard-page .stack-form .button {
    min-height: 28px;
    height: 28px;
    padding: 3px 7px;
    font-size: 9px;
  }

  .dashboard-page .class-card-grid {
    min-height: 0;
    height: 100%;
    grid-template-columns: repeat(auto-fit, minmax(145px, 1fr));
    grid-auto-rows: minmax(62px, 1fr);
    gap: 5px;
    overflow: hidden;
  }

  .dashboard-page .class-card {
    min-height: 0;
    height: 100%;
    padding: 6px 8px;
    border-radius: 10px;
  }

  .dashboard-page .layout-badge {
    padding: 2px 5px;
    font-size: 7px;
  }

  .dashboard-page .class-card h3 {
    margin: 0;
    font-size: clamp(15px, 1.4vw, 22px);
  }

  .dashboard-page .class-card p {
    font-size: 8px;
  }

  .dashboard-page .class-card__seatline span {
    width: 15px;
    height: 7px;
  }

  .dashboard-page .empty-state {
    min-height: 0;
    height: 100%;
    padding: 12px;
  }

  .dashboard-page .empty-state img {
    width: 38px;
    height: 38px;
  }

  /* ---------- Login / Registrierung ---------- */
  .auth-body,
  .auth-body .auth-shell {
    width: 100%;
    height: 100dvh;
    min-height: 0;
    overflow: hidden;
  }

  .auth-body .auth-layout {
    height: 100%;
    min-height: 0;
  }

  .auth-body .auth-brand-panel__content,
  .auth-body .auth-form-panel {
    padding-top: clamp(20px, 4dvh, 46px);
    padding-bottom: clamp(20px, 4dvh, 46px);
  }

  .auth-body .auth-form-card {
    padding-top: clamp(16px, 3dvh, 32px);
    padding-bottom: clamp(16px, 3dvh, 32px);
  }
}

/* Kleine Notebook-Höhen: nochmals etwas dichter, weiterhin ohne Seiten-Scroll. */
@media (min-width: 900px) and (min-height: 600px) and (max-height: 760px) {
  :root {
    --compact-header-h: 44px;
    --compact-footer-h: 28px;
    --compact-page-gap: 5px;
  }

  .brand__logo { height: 28px; }
  .site-footer__logo { height: 18px; }
  .site-footer__meta { font-size: 8px; }

  .desktop-toolbar__group,
  .desktop-toolbar__group:nth-child(n) {
    min-height: 48px;
    max-height: 50px;
    padding: 4px 5px;
  }

  .desktop-toolbar select,
  .desktop-toolbar .button {
    min-height: 24px;
    height: 24px;
  }

  .classroom-canvas-card__meta {
    min-height: 34px;
    padding: 3px 8px;
  }

  .classroom-canvas-card__meta p {
    display: none;
  }

  .subwindow-toolbar {
    min-height: 40px;
    padding: 3px 6px;
  }

  .dashboard-page .page-shell {
    grid-template-rows: minmax(68px, 13%) 21px minmax(92px, 21%) 21px minmax(0, 1fr);
  }

  .dashboard-page .section-heading {
    height: 21px;
  }
}

/* Unterhalb Tablet-/Notebook-Grösse ist bewusst normales Scrollen erlaubt. */
@media (max-width: 899px), (max-height: 599px) {
  html,
  body {
    height: auto;
    min-height: 100%;
    overflow-x: hidden;
    overflow-y: auto;
  }

  .site-header {
    height: 54px;
  }

  .site-header__inner {
    width: calc(100% - 18px);
  }

  .brand__logo {
    height: 31px;
  }

  .site-footer__inner {
    min-height: 54px;
    width: calc(100% - 18px);
  }

  .page-shell,
  .original-workspace-page .page-shell,
  .group-workbench-page .page-shell,
  .random-workbench-page .page-shell {
    width: calc(100% - 18px);
    margin: 10px auto 24px;
  }

  .desktop-toolbar {
    margin-bottom: 8px;
  }

  .desk-board {
    min-height: 420px;
  }

  .group-board {
    overflow: visible;
  }

  .random-side {
    overflow: visible;
  }
}

@media (max-width: 620px) {
  .site-header__inner {
    grid-template-columns: auto 1fr;
  }

  .main-navigation {
    display: none;
  }

  .account-chip__name {
    display: none;
  }

  .site-footer__meta span:first-child {
    display: none;
  }

  .site-footer__inner {
    justify-content: space-between;
  }
}
