:root {
  color-scheme: light;
  --bg: #f5f7fb;
  --panel: #ffffff;
  --ink: #172033;
  --muted: #667085;
  --line: #d9e0ea;
  --blue: #2563eb;
  --blue-dark: #1e40af;
  --green: #15803d;
  --red: #b42318;
  --amber: #b45309;
  --shadow: 0 16px 40px rgba(23, 32, 51, 0.09);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, Segoe UI, Arial, sans-serif;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: wait;
  opacity: 0.65;
}

.app-shell {
  display: grid;
  grid-template-columns: 280px 1fr;
  min-height: 100vh;
}

.login-screen {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 20px;
  background: linear-gradient(180deg, #eef4ff 0%, #f8fafc 100%);
}

.login-card {
  display: grid;
  width: min(100%, 420px);
  gap: 14px;
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.login-card label {
  display: grid;
  gap: 8px;
  font-weight: 700;
}

.login-brand {
  margin-bottom: 4px;
}

.login-brand p,
.login-hint {
  color: var(--muted);
}

.login-hint {
  margin: 0;
  font-size: 13px;
}

.app-version {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
}

.app-version code {
  color: inherit;
  font: inherit;
  font-weight: 700;
}

.settings-version {
  margin-top: 18px;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 22px;
  padding: 24px;
  background: #101828;
  color: #fff;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  display: grid;
  width: 44px;
  height: 44px;
  place-items: center;
  border-radius: 8px;
  background: #f8c14a;
  color: #101828;
  font-weight: 800;
}

.brand h1,
.brand p,
.topbar h2,
.topbar p,
.section-head h3,
.form-panel h3,
.modal-form h3 {
  margin: 0;
}

.brand h1 {
  font-size: 20px;
}

.brand p,
.sidebar-note,
.role-badge,
.muted {
  color: #b8c2d6;
}

.user-panel,
.sidebar-note {
  display: grid;
  gap: 8px;
}

.user-panel label {
  color: #d5dbea;
  font-size: 13px;
}

.user-panel select,
.nav-tab,
.sidebar-note {
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 8px;
}

.user-panel select {
  width: 100%;
  padding: 11px;
  background: #182338;
  color: #fff;
}

.role-badge {
  font-size: 13px;
}

.panel-label {
  color: #d5dbea;
  font-size: 13px;
}

.user-panel strong {
  font-size: 16px;
}

.nav-tabs {
  display: grid;
  gap: 8px;
}

.nav-tab {
  padding: 12px;
  background: transparent;
  color: #d5dbea;
  text-align: left;
}

.nav-tab.active {
  background: #fff;
  color: #101828;
}

.dark-button {
  border-color: rgba(255, 255, 255, 0.18);
  background: #182338;
  color: #fff;
}

.sidebar-note {
  margin-top: auto;
  padding: 14px;
  font-size: 13px;
  line-height: 1.45;
}

.sidebar-note strong,
.sidebar-note span {
  display: block;
}

.content {
  min-width: 0;
  padding: 28px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 24px;
}

.eyebrow {
  color: var(--muted);
  font-size: 13px;
}

.topbar h2 {
  font-size: clamp(28px, 4vw, 42px);
}

.stats {
  display: grid;
  grid-template-columns: repeat(3, 96px);
  gap: 10px;
}

.stats div {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  text-align: center;
}

.stats span {
  display: block;
  font-size: 24px;
  font-weight: 800;
}

.stats small {
  color: var(--muted);
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.toolbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}

.toolbar-actions,
.date-row,
.week-switcher {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.week-switcher {
  justify-content: space-between;
  margin-bottom: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.week-schedule-content {
  overflow: clip;
}

#scheduleView {
  overflow-x: clip;
}

.week-label {
  display: grid;
  gap: 3px;
  min-width: 220px;
  text-align: center;
}

.week-label strong {
  font-size: 18px;
}

.week-label span {
  color: var(--muted);
  font-size: 13px;
}

.date-actions {
  display: grid;
  gap: 6px;
}

.date-row input {
  min-width: 180px;
}

.toolbar label,
.modal-form label,
.form-panel label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 11px 12px;
  background: #fff;
  color: var(--ink);
}

textarea {
  resize: vertical;
}

.segmented {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 2px;
}

.segmented button,
.ghost-button,
.primary-button {
  min-height: 42px;
  border-radius: 8px;
  border: 1px solid var(--line);
  padding: 0 14px;
  white-space: nowrap;
}

.segmented button {
  background: #fff;
  color: var(--muted);
}

.segmented button.active {
  background: var(--ink);
  color: #fff;
}

.primary-button {
  border-color: var(--blue);
  background: var(--blue);
  color: #fff;
  font-weight: 700;
}

.primary-button:hover {
  background: var(--blue-dark);
}

.ghost-button {
  background: #fff;
  color: var(--ink);
}

.ghost-button.active {
  border-color: var(--blue);
  background: #eef4ff;
  color: var(--blue-dark);
  font-weight: 800;
}

.ghost-button.photo-schedule-button {
  border-color: #0f766e;
  background: #0f766e;
  color: #fff;
  font-weight: 800;
}

.ghost-button.photo-schedule-button:hover {
  border-color: #0b5f59;
  background: #0b5f59;
}

button:disabled {
  cursor: wait;
  opacity: 0.65;
}

.danger-button {
  border-color: #ffd5d1;
  background: #fff1f0;
  color: var(--red);
}

.schedule-grid,
.item-list,
.timeline {
  display: grid;
  gap: 12px;
}

.lesson-row,
.homework-item,
.request-item,
.history-item,
.form-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.lesson-row {
  display: grid;
  grid-template-columns: 74px 1fr auto;
  gap: 16px;
  align-items: center;
  padding: 16px;
}

.lesson-number {
  display: grid;
  width: 56px;
  height: 56px;
  place-items: center;
  border-radius: 8px;
  background: #eef4ff;
  color: var(--blue-dark);
  font-weight: 800;
}

.lesson-title,
.lesson-main h3,
.homework-item h3,
.request-item h3 {
  display: block;
  margin: 0 0 6px;
  font-size: 18px;
  font-weight: 800;
}

.lesson-meta,
.homework-meta,
.request-meta,
.history-meta {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  color: var(--muted);
  font-size: 13px;
}

.row-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.homework-item,
.request-item,
.history-item,
.form-panel {
  padding: 16px;
}

.homework-text,
.request-text,
.history-text {
  margin: 10px 0 0;
  line-height: 1.55;
}

.homework-section {
  display: grid;
  gap: 12px;
}

.homework-section + .homework-section {
  margin-top: 8px;
}

.compact-head {
  margin-bottom: 0;
}

.done-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  width: fit-content;
  margin-top: 12px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
  font-weight: 700;
}

.done-toggle input {
  width: 18px;
  height: 18px;
  accent-color: var(--green);
}

.homework-progress {
  display: grid;
  gap: 8px;
  margin-top: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
}

.homework-progress h4,
.homework-progress p {
  margin: 0;
}

.progress-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.progress-list span {
  display: inline-flex;
  min-height: 28px;
  align-items: center;
  border-radius: 999px;
  padding: 0 10px;
  background: #ecfdf3;
  color: var(--green);
  font-size: 13px;
  font-weight: 700;
}

.private-comments {
  display: grid;
  gap: 10px;
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.private-comments h4 {
  margin: 0;
  font-size: 15px;
}

.private-comments label {
  display: grid;
  gap: 8px;
  font-weight: 700;
}

.private-comments textarea {
  width: 100%;
  resize: vertical;
}

.private-comment-card {
  display: grid;
  gap: 6px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
}

.private-comment-card p {
  margin: 0;
  line-height: 1.45;
}

.lesson-button {
  width: 100%;
  color: inherit;
  font: inherit;
  text-align: left;
}

.lesson-button:hover {
  border-color: #b9c8df;
  transform: translateY(-1px);
}

.empty-lesson-row {
  border-style: dashed;
  background: #f8fafc;
  box-shadow: none;
  color: var(--muted);
}

.empty-lesson-row .lesson-number {
  background: #eef1f5;
  color: #667085;
}

.empty-lesson-row .lesson-title {
  color: #667085;
}

.lesson-homework-chip {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  border-radius: 999px;
  padding: 0 12px;
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
}

.lesson-statuses {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
  min-width: 0;
}

.lesson-homework-chip.done {
  background: #dcfce7;
  color: #166534;
}

.lesson-homework-chip.missing {
  background: #fef3c7;
  color: #92400e;
}

.lesson-homework-chip.pending {
  background: #fee2e2;
  color: #991b1b;
}

.lesson-new-homework {
  display: flex;
  width: fit-content;
  max-width: 100%;
  min-height: 32px;
  align-items: center;
  margin-top: 10px;
  border-left: 4px solid #2563eb;
  border-radius: 4px;
  padding: 6px 10px;
  background: #dbeafe;
  color: #1e40af;
  font-size: 13px;
  font-weight: 700;
  text-align: left;
}

.muted-chip {
  background: #eef1f5;
  color: #667085;
}

.modal-title-row {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: start;
}

.wide-dialog {
  width: min(980px, calc(100vw - 28px));
}

.lesson-editor-list {
  display: grid;
  gap: 10px;
  max-height: min(58vh, 620px);
  overflow: auto;
  padding-right: 4px;
}

.lesson-editor-row {
  display: grid;
  grid-template-columns: 76px 240px minmax(210px, 1.2fr) minmax(150px, 1fr) 100px auto;
  gap: 10px;
  align-items: end;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #f8fafc;
}

.lesson-editor-row .custom-subject {
  margin-top: 8px;
}

.time-edit {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

.homework-box {
  display: grid;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #f8fafc;
}

.homework-box h4 {
  margin: 0;
}

.request-preview {
  margin-top: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #f8fafc;
  color: #344054;
  line-height: 1.5;
}

.template-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(320px, 0.9fr);
  gap: 16px;
  align-items: start;
}

.template-layout .form-panel:first-child {
  grid-column: 1 / -1;
}

.users-layout .form-panel:first-child {
  grid-column: auto;
}

.compact-form,
.template-list,
.template-preview,
.student-list {
  display: grid;
  gap: 10px;
}

.template-row {
  display: grid;
  gap: 5px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #f8fafc;
}

.template-row span {
  color: var(--muted);
  font-size: 13px;
}

.time-template-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.time-template-grid .primary-button {
  grid-column: 1 / -1;
}

.settings-panel {
  max-width: 560px;
  position: static;
}

.settings-panel .compact-form {
  grid-template-columns: 1fr;
}

.student-card {
  display: grid;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
}

.student-card h4 {
  margin: 0 0 6px;
  font-size: 17px;
}

.student-password-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto;
  gap: 10px;
  align-items: end;
}

.student-password-form label {
  display: grid;
  gap: 8px;
  font-weight: 700;
}

.photo-grid {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 12px;
}

.image-thumbnail-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  padding: 0;
  background: transparent;
  cursor: zoom-in;
}

.image-thumbnail-button:focus-visible {
  outline: 3px solid rgba(37, 99, 235, 0.35);
  outline-offset: 3px;
}

.photo-grid .image-thumbnail-button img,
.preview-strip .image-thumbnail-button img {
  width: 132px;
  height: 96px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--line);
  transition: border-color 160ms ease, transform 160ms ease;
}

.image-thumbnail-button:hover img {
  border-color: var(--blue);
  transform: translateY(-1px);
}

.image-preview-dialog {
  width: calc(100vw - 28px);
  max-width: 1200px;
  height: calc(100vh - 28px);
  max-height: calc(100vh - 28px);
  background: #101828;
}

.image-preview-shell {
  position: relative;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  align-items: center;
  justify-items: center;
  width: 100%;
  height: 100%;
  padding: 18px;
}

.image-preview-shell img {
  display: block;
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  object-fit: contain;
}

.image-preview-shell p {
  max-width: 100%;
  margin: 12px 54px 0;
  overflow-wrap: anywhere;
  color: #fff;
  text-align: center;
}

.ghost-button.image-preview-close {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 2;
  width: 42px;
  min-width: 42px;
  height: 42px;
  padding: 0;
}

.permission-toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  width: fit-content;
  color: #344054;
  font-weight: 700;
}

.permission-toggle input {
  width: 18px;
  height: 18px;
  margin: 0;
  accent-color: var(--blue);
}

.ocr-photo-trigger {
  width: 100%;
}

.ocr-photo-trigger img {
  width: 100%;
}

.two-column {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 18px;
  align-items: start;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.section-head span {
  color: var(--muted);
  font-size: 13px;
}

.form-panel {
  display: grid;
  gap: 14px;
  position: sticky;
  top: 20px;
}

.status {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  border-radius: 999px;
  padding: 0 10px;
  font-size: 13px;
  font-weight: 700;
}

.status.pending {
  background: #fff7ed;
  color: var(--amber);
}

.status.approved {
  background: #ecfdf3;
  color: var(--green);
}

.status.rejected {
  background: #fff1f0;
  color: var(--red);
}

.history-item {
  display: grid;
  gap: 8px;
}

.history-diff {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.history-diff pre {
  overflow: auto;
  max-height: 180px;
  margin: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #f8fafc;
  color: #344054;
  font-size: 12px;
}

dialog {
  width: min(560px, calc(100vw - 28px));
  max-height: calc(100vh - 28px);
  overflow: hidden;
  border: 0;
  border-radius: 8px;
  padding: 0;
  box-shadow: var(--shadow);
}

dialog::backdrop {
  background: rgba(16, 24, 40, 0.48);
}

.modal-form {
  display: grid;
  gap: 14px;
  max-height: calc(100vh - 28px);
  overflow-y: auto;
  padding: 20px;
}

.ghost-button.dialog-close {
  position: sticky;
  z-index: 30;
  top: 0;
  justify-self: end;
  width: 42px;
  min-width: 42px;
  height: 42px;
  padding: 0;
  border-color: #c9d2df;
  background: #fff;
  box-shadow: 0 4px 12px rgba(23, 32, 51, 0.12);
  font-size: 25px;
  line-height: 1;
}

.ghost-button.dialog-close:hover {
  border-color: #98a6ba;
  background: #f8fafc;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.ocr-dialog {
  width: min(1180px, calc(100vw - 28px));
  max-height: calc(100vh - 28px);
}

.ocr-dialog > .modal-form {
  overflow: auto;
}

.ocr-upload-form,
.ocr-review,
.ocr-result-panel,
.ocr-rows {
  display: grid;
  gap: 12px;
}

.ocr-crop-stage {
  display: grid;
  gap: 10px;
}

.ocr-crop-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.ocr-crop-canvas {
  height: min(56vh, 520px);
  min-height: 280px;
  overflow: hidden;
  border: 1px solid var(--line);
  background: #111827;
}

.ocr-crop-canvas img {
  display: block;
  max-width: 100%;
}

.ocr-crop-canvas .cropper-point {
  width: 14px;
  height: 14px;
  opacity: 0.9;
}

.icon-actions {
  display: flex;
  gap: 8px;
  flex: 0 0 auto;
}

.setup-notice,
.ocr-warnings {
  border: 1px solid #f6d39b;
  border-radius: 8px;
  padding: 12px;
  background: #fff8eb;
  color: #7a4700;
  line-height: 1.45;
}

.ocr-warnings ul {
  margin: 8px 0 0;
  padding-left: 20px;
}

.ocr-progress {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}

.progress-track {
  height: 8px;
  overflow: hidden;
  border-radius: 8px;
  background: #e5eaf1;
}

.progress-track span {
  display: block;
  width: 0;
  height: 100%;
  background: var(--blue);
  transition: width 0.2s ease;
}

.ocr-review-layout {
  display: grid;
  grid-template-columns: minmax(240px, 0.7fr) minmax(0, 1.8fr);
  gap: 16px;
  align-items: start;
}

.ocr-photo-panel {
  display: grid;
  gap: 10px;
  position: sticky;
  top: 0;
}

.ocr-photo-panel img {
  width: 100%;
  max-height: 68vh;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
  object-fit: contain;
}

.ocr-target-row,
.ocr-table-head {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 12px;
}

.ocr-detection-fields {
  display: grid;
  grid-template-columns: repeat(2, minmax(150px, 1fr)) repeat(2, minmax(120px, 0.65fr));
  gap: 10px;
  align-items: end;
}

.ocr-detected-columns {
  margin: 0;
}

.ocr-class-result {
  min-height: 42px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f8fafc;
}

.ocr-class-result span,
.field-hint {
  color: var(--muted);
  font-size: 12px;
}

.ocr-target-row label {
  min-width: 230px;
}

.ocr-row {
  display: grid;
  grid-template-columns: 145px 64px minmax(170px, 1.2fr) 150px minmax(150px, 1fr) 100px 42px;
  gap: 8px;
  align-items: end;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #f8fafc;
}

.ocr-row label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
}

.icon-button {
  width: 42px;
  padding: 0;
  font-size: 22px;
}

.ocr-raw-text {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
}

.ocr-raw-text summary {
  cursor: pointer;
  font-weight: 700;
}

.ocr-raw-text pre {
  overflow: auto;
  max-height: 240px;
  margin: 12px 0 0;
  white-space: pre-wrap;
  color: #344054;
  font-size: 12px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%) translateY(20px);
  max-width: min(480px, calc(100vw - 32px));
  border-radius: 8px;
  padding: 12px 16px;
  background: #101828;
  color: #fff;
  opacity: 0;
  pointer-events: none;
  transition: 0.2s ease;
}

.toast.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.empty {
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 28px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.7);
  text-align: center;
}

.hidden {
  display: none !important;
}

@media (max-width: 920px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    padding: 18px;
  }

  .nav-tabs {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .nav-tab {
    text-align: center;
    padding: 10px 8px;
  }

  .content {
    padding: 18px;
  }

  .topbar,
  .lesson-row {
    align-items: stretch;
  }

  .topbar,
  .two-column,
  .template-layout,
  .history-diff {
    display: grid;
    grid-template-columns: 1fr;
  }

  .stats {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .lesson-row {
    grid-template-columns: 56px 1fr;
  }

  .lesson-statuses {
    grid-column: 1 / -1;
    justify-content: center;
  }

  .lesson-editor-row {
    grid-template-columns: 1fr 1fr;
  }

  .student-password-form {
    grid-template-columns: 1fr;
  }

  .lesson-editor-row .danger-button {
    grid-column: 1 / -1;
  }

  .row-actions {
    grid-column: 1 / -1;
    justify-content: flex-start;
  }

  .ocr-review-layout {
    grid-template-columns: 1fr;
  }

  .ocr-photo-panel {
    position: static;
  }

  .ocr-photo-panel img {
    max-height: 360px;
  }

  .ocr-row {
    grid-template-columns: 1fr 84px 1fr;
  }

  .ocr-row label:nth-of-type(3),
  .ocr-row label:nth-of-type(5) {
    grid-column: span 2;
  }
}

@media (max-width: 560px) {
  body {
    min-width: 0;
  }

  .sidebar,
  .content {
    padding: 14px;
  }

  .nav-tabs {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .topbar h2 {
    font-size: 24px;
    line-height: 1.15;
  }

  .stats {
    grid-template-columns: 1fr;
  }

  .toolbar,
  .toolbar-actions,
  .date-row,
  .week-switcher,
  .modal-title-row,
  .modal-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .toolbar > *,
  .toolbar-actions,
  .segmented {
    width: 100%;
    min-width: 0;
    max-width: 100%;
  }

  .week-label {
    min-width: 0;
    width: 100%;
  }

  .lesson-row {
    grid-template-columns: 48px 1fr;
    gap: 12px;
    padding: 12px;
  }

  .lesson-statuses {
    width: 100%;
  }

  .lesson-new-homework {
    width: 100%;
  }

  .lesson-homework-chip {
    max-width: 100%;
    white-space: normal;
    text-align: center;
  }

  .lesson-number {
    width: 48px;
    height: 48px;
  }

  .lesson-title,
  .lesson-main h3,
  .homework-item h3,
  .request-item h3 {
    font-size: 16px;
  }

  .lesson-meta,
  .homework-meta,
  .request-meta,
  .history-meta {
    gap: 6px;
    font-size: 12px;
  }

  .lesson-editor-row {
    grid-template-columns: 1fr;
  }

  .time-edit {
    grid-template-columns: 1fr;
  }

  .time-template-grid {
    grid-template-columns: 1fr;
  }

  .primary-button,
  .ghost-button,
  .danger-button {
    width: 100%;
  }

  .image-preview-dialog {
    width: 100dvw;
    max-width: none;
    height: 100dvh;
    max-height: none;
    margin: 0;
    border-radius: 0;
  }

  .image-preview-shell {
    width: 100dvw;
    height: 100dvh;
    overflow: hidden;
    padding: max(10px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
  }

  .image-preview-shell img {
    max-width: 100%;
    max-height: 100%;
  }

  .image-preview-shell p {
    max-height: 24dvh;
    margin: 8px 48px 0;
    overflow-y: auto;
  }

  .ghost-button.image-preview-close {
    top: max(10px, env(safe-area-inset-top));
    right: max(10px, env(safe-area-inset-right));
    width: 42px;
    min-width: 42px;
    height: 42px;
    padding: 0;
  }

  .permission-toggle {
    width: 100%;
  }

  .ocr-target-row,
  .ocr-table-head {
    align-items: stretch;
    flex-direction: column;
  }

  .ocr-crop-toolbar {
    align-items: flex-start;
  }

  .ocr-crop-toolbar strong {
    max-width: calc(100% - 100px);
  }

  .ocr-crop-canvas {
    height: 48dvh;
    min-height: 240px;
  }

  .ocr-crop-canvas .cropper-point {
    width: 20px;
    height: 20px;
  }

  .ocr-detection-fields {
    grid-template-columns: 1fr;
  }

  .ocr-target-row label {
    min-width: 0;
  }

  .ocr-row {
    grid-template-columns: 1fr 84px;
  }

  .ocr-row label:nth-of-type(3),
  .ocr-row label:nth-of-type(4),
  .ocr-row label:nth-of-type(5),
  .ocr-row label:nth-of-type(6),
  .ocr-row .icon-button {
    grid-column: 1 / -1;
  }

  .homework-item,
  .request-item,
  .history-item,
  .form-panel {
    padding: 12px;
  }

  .private-comments {
    gap: 8px;
  }

}
