:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --text: #1c2430;
  --muted: #667085;
  --line: #d9dee7;
  --primary: #146c94;
  --primary-dark: #0d506f;
  --green: #0f7b52;
  --yellow: #9a6700;
  --orange: #b54708;
  --red: #b42318;
  --gray: #475467;
}

* {
  box-sizing: border-box;
}

html,
body {
  max-width: 100%;
  overflow-x: hidden;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Arial, Helvetica, sans-serif;
  line-height: 1.5;
}

a {
  color: inherit;
  text-decoration: none;
}

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

.sidebar {
  background: #102331;
  color: #f7fbff;
  padding: 24px;
}

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

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

.brand strong,
.brand small {
  display: block;
}

.brand small {
  color: #b9c6d1;
  font-size: 12px;
}

.user-card {
  border: 1px solid rgba(255,255,255,.12);
  border-radius: 8px;
  margin-bottom: 18px;
  padding: 12px;
}

.user-card strong,
.user-card small {
  display: block;
}

.user-card small {
  color: #b9c6d1;
  font-size: 12px;
  margin-top: 2px;
}

.account-link {
  border-top: 1px solid rgba(255,255,255,.12);
  color: #f2b84b;
  display: block;
  font-size: 13px;
  font-weight: 800;
  margin-top: 10px;
  padding-top: 10px;
}

.account-link:hover {
  color: #ffd47a;
}

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

.nav a {
  border-radius: 8px;
  color: #d9e4ec;
  padding: 10px 12px;
}

.nav a:hover {
  background: rgba(255,255,255,.08);
  color: #fff;
}

.logout-form {
  margin-top: 18px;
}

.logout-form button {
  background: transparent;
  border: 1px solid rgba(255,255,255,.2);
  border-radius: 8px;
  color: #f7fbff;
  cursor: pointer;
  font: inherit;
  font-weight: 700;
  padding: 10px 12px;
  width: 100%;
}

.main {
  padding: 28px;
  max-width: 1400px;
  min-width: 0;
  width: 100%;
}

.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 20px;
}

.page-header h1 {
  margin: 0;
  font-size: 30px;
}

.page-header p {
  margin: 6px 0 0;
  color: var(--muted);
}

.eyebrow {
  color: var(--primary);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

.actions,
.form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  min-width: 0;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  font-weight: 700;
  padding: 9px 14px;
}

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

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

.danger-button {
  border-color: var(--red);
  color: var(--red);
}

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

.stat,
.panel,
.form-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  min-width: 0;
}

.stat {
  padding: 18px;
}

.stat span {
  color: var(--muted);
  display: block;
  font-size: 13px;
}

.stat strong {
  display: block;
  font-size: 26px;
  margin-top: 6px;
}

.stat.danger {
  border-color: #f3b8b2;
  background: #fff4f2;
}

.content-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(320px, .8fr);
  gap: 18px;
  margin-bottom: 20px;
  min-width: 0;
}

.panel,
.form-panel {
  margin-bottom: 20px;
  padding: 18px;
}

.danger-panel {
  border-color: #f3b8b2;
  background: #fffafa;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
  min-width: 0;
}

.panel-header h2 {
  font-size: 18px;
  margin: 0;
}

.panel-header a,
.link {
  color: var(--primary);
  font-weight: 700;
}

.table-wrap {
  max-width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

table {
  border-collapse: collapse;
  min-width: 720px;
  width: 100%;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 11px 10px;
  text-align: left;
  vertical-align: top;
}

th {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

.detail-row td {
  background: #fafbfc;
  color: var(--muted);
  font-size: 13px;
}

.empty {
  color: var(--muted);
  padding: 16px 10px;
  text-align: center;
}

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

.badge {
  display: inline-flex;
  align-items: center;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 800;
  padding: 5px 8px;
  white-space: nowrap;
}

.badge.green { background: #e7f6ee; color: var(--green); }
.badge.yellow { background: #fff3c4; color: var(--yellow); }
.badge.orange { background: #ffead5; color: var(--orange); }
.badge.red { background: #fee4e2; color: var(--red); }
.badge.gray { background: #eef1f5; color: var(--gray); }

.table-action {
  color: var(--primary);
  font-size: 13px;
  font-weight: 800;
}

.table-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.stack-list {
  display: grid;
  gap: 10px;
}

.student-row {
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 12px;
  min-width: 0;
}

.student-row small {
  color: var(--muted);
  display: block;
}

.filter-bar,
.form-grid {
  display: grid;
  gap: 12px;
}

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

.filter-actions {
  align-items: end;
  display: flex;
  gap: 10px;
}

.filter-bar {
  grid-template-columns: minmax(260px, 1fr) 180px 180px auto;
  margin-bottom: 18px;
}

.filter-bar.compact {
  grid-template-columns: minmax(260px, 1fr) 180px auto;
}

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

label {
  color: var(--text);
  display: grid;
  font-weight: 700;
  gap: 6px;
}

.field-hint {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.field-hint a {
  color: var(--primary);
}

.readonly-field {
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 4px;
  min-height: 40px;
  padding: 9px 11px;
}

.readonly-field span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.student-picker {
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 12px;
  margin-bottom: 14px;
  padding: 14px;
}

.student-picker.has-selection label {
  display: none;
}

.student-search-results {
  display: grid;
  gap: 8px;
}

.student-result-card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  cursor: pointer;
  display: grid;
  gap: 2px;
  min-height: 62px;
  padding: 12px;
  text-align: left;
}

.student-result-card:hover {
  border-color: var(--primary);
}

.student-result-card span,
.student-result-card small,
.selected-student-card small,
.selected-student-card span,
.student-search-message {
  color: var(--muted);
}

.selected-student-card {
  align-items: center;
  background: #f7fbff;
  border: 1px solid #cce3ef;
  border-radius: 8px;
  display: flex;
  gap: 12px;
  justify-content: space-between;
  padding: 12px;
  min-width: 0;
}

.selected-student-card strong,
.selected-student-card small,
.selected-student-card span {
  display: block;
  overflow-wrap: anywhere;
}

.summary-list {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin: 0 0 18px;
}

.summary-list div {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
}

.summary-list .wide {
  grid-column: 1 / -1;
}

.summary-list dt {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  margin-bottom: 4px;
}

.summary-list dd {
  margin: 0;
}

input,
select,
textarea {
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  font: inherit;
  min-height: 40px;
  padding: 9px 11px;
  width: 100%;
}

.password-field {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  position: relative;
}

.password-field input {
  border-radius: 8px 0 0 8px;
}

.password-toggle {
  background: #eef5f8;
  border: 1px solid var(--line);
  border-left: 0;
  border-radius: 0 8px 8px 0;
  color: var(--primary);
  cursor: pointer;
  font: inherit;
  font-size: 13px;
  font-weight: 800;
  min-height: 40px;
  min-width: 66px;
  padding: 0 10px;
}

.password-toggle:hover {
  background: #dcecf2;
}

textarea {
  resize: vertical;
}

.form-actions {
  justify-content: flex-end;
  margin-top: 16px;
}

.alert {
  border-radius: 8px;
  font-weight: 700;
  margin-bottom: 16px;
  padding: 12px 14px;
}

.alert-success {
  background: #e7f6ee;
  color: var(--green);
}

.alert-error {
  background: #fee4e2;
  color: var(--red);
}

.login-wrap {
  align-items: center;
  display: flex;
  min-height: calc(100vh - 56px);
  justify-content: center;
}

.login-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 16px;
  max-width: 420px;
  padding: 24px;
  width: 100%;
}

.login-panel h1 {
  margin: 0;
}

.teacher-hero {
  align-items: flex-start;
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: flex;
  gap: 16px;
  justify-content: space-between;
  margin-bottom: 16px;
  padding: 18px;
}

.teacher-hero h1 {
  font-size: 28px;
  margin: 0;
}

.teacher-hero p {
  color: var(--muted);
  margin: 6px 0 0;
}

.teacher-search {
  display: grid;
  gap: 10px;
  grid-template-columns: minmax(0, 1fr) auto;
  margin-bottom: 16px;
}

.teacher-student-card {
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: flex;
  gap: 14px;
  justify-content: space-between;
  padding: 14px;
}

.teacher-student-card small {
  color: var(--muted);
  display: block;
  margin: 2px 0 8px;
}

.teacher-history-card {
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: flex;
  gap: 12px;
  justify-content: space-between;
  padding: 12px;
}

.teacher-history-card small {
  color: var(--muted);
  display: block;
}

.teacher-card-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

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

  .sidebar {
    position: static;
  }

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

  .stats-grid,
  .content-grid,
  .filter-bar,
  .filter-panel,
  .form-grid {
    grid-template-columns: 1fr;
  }

  .page-header {
    display: grid;
    gap: 12px;
  }

  .page-header .actions {
    justify-content: flex-start;
  }

  .panel-header {
    align-items: flex-start;
    flex-wrap: wrap;
  }

  .teacher-hero,
  .teacher-student-card {
    display: grid;
  }

  .teacher-search {
    grid-template-columns: 1fr;
  }

  .teacher-card-actions .button {
    width: 100%;
  }

  .summary-list {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  body {
    font-size: 15px;
  }

  .sidebar {
    padding: 14px;
  }

  .brand {
    margin-bottom: 12px;
  }

  .brand-mark {
    height: 36px;
    width: 36px;
  }

  .user-card {
    margin-bottom: 12px;
    padding: 10px;
  }

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

  .nav a {
    min-height: 40px;
    overflow-wrap: anywhere;
    padding: 9px 10px;
    text-align: center;
  }

  .logout-form {
    margin-top: 10px;
  }

  .main {
    padding: 14px;
  }

  .page-header h1,
  .teacher-hero h1 {
    font-size: 24px;
    overflow-wrap: anywhere;
  }

  .page-header .actions {
    display: grid;
    width: 100%;
  }

  .page-header .actions .button,
  .page-header > .button {
    width: 100%;
  }

  .teacher-hero {
    padding: 14px;
  }

  .teacher-hero .button,
  .teacher-search .button,
  .form-actions .button,
  .form-actions button {
    width: 100%;
  }

  .panel,
  .form-panel {
    padding: 14px;
  }

  .panel-header {
    display: grid;
  }

  .panel-header .actions {
    display: grid;
    width: 100%;
  }

  .student-picker {
    padding: 12px;
  }

  .student-result-card {
    min-height: 72px;
    padding: 14px;
  }

  .selected-student-card,
  .student-row,
  .teacher-history-card {
    align-items: stretch;
    display: grid;
  }

  .selected-student-card .button,
  .student-row .button {
    width: 100%;
  }

  .form-actions,
  .filter-actions {
    display: grid;
  }

  input,
  select,
  textarea,
  .button,
  .password-toggle {
    min-height: 44px;
  }

  .password-field {
    grid-template-columns: minmax(0, 1fr) minmax(76px, auto);
  }

  .table-actions {
    display: grid;
  }

  .table-wrap {
    margin-left: -14px;
    margin-right: -14px;
    padding-left: 14px;
    padding-right: 14px;
    width: calc(100% + 28px);
  }

  th,
  td {
    padding: 10px 9px;
  }
}
