:root {
  --bg: #f3f5f7;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --ink: #17202a;
  --muted: #687382;
  --line: #d9e0e7;
  --blue: #2563eb;
  --blue-dark: #1d4ed8;
  --green: #0f9f7a;
  --green-soft: #e8f7f2;
  --orange: #f97316;
  --red: #d92d20;
  --shadow: 0 16px 42px rgba(31, 41, 55, .10);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  min-height: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    linear-gradient(180deg, rgba(37, 99, 235, .08), transparent 340px),
    var(--bg);
  font-family: "Segoe UI", Arial, sans-serif;
  letter-spacing: 0;
}

body.modal-open {
  overflow: hidden;
}

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

button {
  cursor: pointer;
}

button:disabled {
  cursor: wait;
  opacity: .65;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: 28px;
  line-height: 1.15;
}

h2 {
  font-size: 20px;
  line-height: 1.2;
}

h3 {
  font-size: 15px;
  line-height: 1.25;
}

.app-header {
  width: min(1360px, calc(100% - 32px));
  margin: 0 auto;
  padding: 20px 0 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 18px;
}

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

.brand-mark {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--ink);
  color: #fff;
  font-weight: 800;
}

.brand-title {
  font-weight: 800;
  font-size: 20px;
}

.brand-subtitle,
.panel-head p,
.admin-hero p,
.history-item small,
.teacher-item small,
.request-item small,
.request-item p,
.subtitle {
  color: var(--muted);
}

.user-label {
  color: var(--muted);
  font-size: 14px;
}

.role-pill,
.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 0 10px;
  border-radius: 8px;
  background: var(--green-soft);
  color: #087259;
  font-weight: 700;
  font-size: 13px;
  white-space: nowrap;
}

.status-pill[data-mode="busy"] {
  background: #fff7ed;
  color: #c2410c;
}

.status-pill[data-mode="error"] {
  background: #fff1f2;
  color: var(--red);
}

.app-shell {
  width: min(1360px, calc(100% - 32px));
  margin: 0 auto 42px;
}

.teacher-view {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 330px;
  gap: 18px;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.check-panel,
.result-panel,
.admin-hero,
.admin-grid .panel {
  padding: 22px;
}

.history-panel {
  padding: 18px;
}

.result-panel {
  grid-column: 1 / -1;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 18px;
  margin-bottom: 18px;
}

.panel-head.compact {
  align-items: center;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

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

.field {
  display: grid;
  gap: 7px;
  color: #334155;
  font-size: 13px;
  font-weight: 750;
}

.field-wide {
  margin-top: 14px;
}

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

input:focus,
select:focus,
textarea:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, .13);
}

textarea {
  min-height: 230px;
  resize: vertical;
  line-height: 1.5;
}

.textarea-small {
  min-height: 92px;
}

.action-row {
  margin-top: 14px;
  display: grid;
  grid-template-columns: 150px minmax(190px, 280px);
  justify-content: end;
  align-items: end;
  gap: 12px;
}

.result-actions {
  grid-template-columns: 170px minmax(170px, 240px);
}

.button {
  min-height: 44px;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 0 16px;
  font-weight: 800;
  letter-spacing: 0;
}

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

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

.button-secondary {
  background: var(--green);
  color: #fff;
}

.button-ghost {
  background: var(--surface);
  border-color: var(--line);
  color: var(--ink);
}

.button-small {
  min-height: 34px;
  padding: 0 12px;
}

.history-list,
.teacher-list,
.request-list {
  display: grid;
  gap: 10px;
}

.history-item,
.teacher-item {
  width: 100%;
  text-align: left;
  display: grid;
  gap: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
  padding: 11px;
  color: var(--ink);
}

.teacher-row {
  grid-template-columns: 24px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
}

.teacher-item.is-selected {
  border-color: var(--blue);
  background: #f5f8ff;
}

.teacher-export-checkbox {
  width: 18px;
  height: 18px;
  margin: 0;
}

.teacher-pick {
  display: grid;
  gap: 4px;
  min-width: 0;
  padding: 0;
  border: 0;
  background: transparent;
  text-align: left;
  color: var(--ink);
}

.history-item:hover,
.teacher-item:hover {
  border-color: var(--blue);
  background: #f5f8ff;
}

.history-item span,
.teacher-item span {
  color: var(--muted);
  font-size: 12px;
}

.history-item strong,
.teacher-item strong {
  font-size: 14px;
}

.mark-badge {
  width: 64px;
  min-width: 64px;
  height: 64px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--blue);
  color: #fff;
  font-size: 32px;
  font-weight: 900;
}

.feedback-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 22px;
  margin-top: 18px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.feedback-card {
  display: grid;
  gap: 12px;
}

.rating-options,
.check-options {
  display: grid;
  gap: 10px;
}

.rating-options label,
.check-options label {
  display: flex;
  align-items: center;
  gap: 9px;
  color: #334155;
}

.rating-options input,
.check-options input {
  width: 17px;
  height: 17px;
  padding: 0;
}

.admin-view {
  display: grid;
  gap: 18px;
}

.admin-hero {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 18px;
}

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

.stat-card {
  min-height: 108px;
  display: grid;
  align-content: center;
  gap: 8px;
  padding: 20px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.stat-card span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 750;
}

.stat-card strong {
  font-size: 34px;
}

.admin-grid {
  display: grid;
  grid-template-columns: 340px minmax(0, 1fr);
  gap: 18px;
}

.filter-field {
  width: 260px;
}

.admin-tools {
  display: grid;
  justify-items: end;
  gap: 8px;
}

.export-tools {
  display: flex;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 8px;
}

.admin-export-note {
  color: var(--muted);
  font-weight: 650;
}

.request-item {
  display: grid;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
  padding: 14px;
}

.request-top {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: start;
}

.request-main {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.request-main strong {
  font-size: 15px;
}

.request-main span {
  color: #334155;
  font-weight: 700;
}

.request-item p {
  line-height: 1.45;
}

.request-meta-list {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin: 0;
}

.request-meta-list div,
.detail-grid div {
  display: grid;
  gap: 3px;
  min-width: 0;
}

.request-meta-list dt,
.detail-grid dt {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

.request-meta-list dd,
.detail-grid dd {
  margin: 0;
  color: #334155;
  font-size: 13px;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.admin-comment {
  border-left: 3px solid var(--green);
  padding: 8px 10px;
  background: #f4fbf8;
  color: #334155;
  line-height: 1.45;
}

.muted-comment {
  border-left-color: var(--line);
  background: #f8fafc;
  color: var(--muted);
}

.empty-state {
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 16px;
  color: var(--muted);
  background: var(--surface-soft);
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(15, 23, 42, .38);
}

.modal-panel {
  width: min(980px, 100%);
  max-height: min(860px, calc(100vh - 48px));
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 24px 70px rgba(15, 23, 42, .24);
  overflow: hidden;
}

.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: start;
  gap: 16px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--line);
}

.modal-head p {
  margin-top: 4px;
  color: var(--muted);
  line-height: 1.35;
}

.detail-content {
  display: grid;
  gap: 14px;
  padding: 18px 20px 22px;
  overflow: auto;
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin: 0;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
}

.detail-section {
  display: grid;
  gap: 8px;
}

.detail-text {
  min-height: 44px;
  max-height: 260px;
  overflow: auto;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: var(--surface-soft);
  color: #334155;
  line-height: 1.5;
}

.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-card {
  width: min(440px, 100%);
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.app-title {
  font-size: 28px;
  font-weight: 900;
}

.login-badge {
  display: inline-flex;
  margin-bottom: 14px;
  min-height: 30px;
  align-items: center;
  border-radius: 8px;
  padding: 0 10px;
  background: #fff7ed;
  color: #c2410c;
  font-weight: 800;
  font-size: 13px;
}

.subtitle {
  margin: 8px 0 22px;
  line-height: 1.45;
}

.stack {
  display: grid;
  gap: 15px;
}

.error {
  min-height: 22px;
  color: var(--red);
  font-weight: 800;
}

@media (max-width: 980px) {
  .app-header,
  .session,
  .admin-hero,
  .panel-head {
    align-items: stretch;
    flex-direction: column;
  }

  .teacher-view,
  .admin-grid,
  .feedback-grid,
  .form-grid,
  .form-grid-4,
  .stats-grid,
  .action-row,
  .result-actions {
    grid-template-columns: 1fr;
  }

  .filter-field {
    width: 100%;
  }

  .admin-tools {
    justify-items: stretch;
  }

  .export-tools {
    justify-content: stretch;
  }

  .export-tools .button {
    flex: 1 1 120px;
  }

  .request-top,
  .request-meta-list,
  .detail-grid {
    grid-template-columns: 1fr;
  }

  .request-detail {
    width: 100%;
  }

  .modal-backdrop {
    padding: 12px;
  }

  .modal-head {
    flex-direction: column;
  }

  .modal-head .button {
    width: 100%;
  }

  .app-header {
    gap: 14px;
  }
}
