:root {
  --bg: #f6f5f1;
  --surface: #ffffff;
  --surface-strong: #fdfaf4;
  --ink: #202124;
  --muted: #686d72;
  --line: #dedbd2;
  --teal: #187f78;
  --teal-dark: #0f5d58;
  --coral: #c85d4f;
  --gold: #b8860b;
  --green: #3f7f42;
  --blue: #416f9f;
  --shadow: 0 18px 48px rgba(32, 33, 36, 0.1);
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
}

body {
  margin: 0;
  background:
    linear-gradient(180deg, rgba(24, 127, 120, 0.1), transparent 260px),
    var(--bg);
  color: var(--ink);
  font-family: Inter, "Segoe UI", Arial, sans-serif;
  line-height: 1.5;
  letter-spacing: 0;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

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

.topbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(240px, 320px);
  gap: 16px;
  align-items: stretch;
  margin-bottom: 16px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--teal-dark);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  overflow-wrap: anywhere;
}

h1 {
  margin: 0;
  font-size: 3rem;
  line-height: 1.06;
}

.student-panel {
  display: grid;
  align-content: center;
  gap: 6px;
  padding: 18px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.student-panel span {
  color: var(--muted);
  font-size: 0.88rem;
}

.student-panel strong {
  font-size: 1.35rem;
}

.student-panel small {
  color: var(--teal-dark);
  font-weight: 700;
}

.metrics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.connection-state {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(280px, 0.9fr);
  gap: 22px;
  align-items: start;
  margin-bottom: 18px;
  padding: 22px;
  background: var(--surface);
  border: 1px solid rgba(24, 127, 120, 0.24);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.connection-state h2 {
  margin: 0;
  font-size: 1.7rem;
}

.connection-state p {
  max-width: 720px;
  margin: 10px 0 0;
  color: var(--muted);
}

.connection-state ol {
  display: grid;
  gap: 10px;
  margin: 0;
  padding: 0 0 0 20px;
  color: var(--ink);
}

.connection-state code {
  padding: 2px 6px;
  background: rgba(24, 127, 120, 0.1);
  border-radius: 5px;
  color: var(--teal-dark);
  font-weight: 800;
}

.metric {
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.metric span {
  display: block;
  color: var(--muted);
  font-size: 0.86rem;
}

.metric strong {
  display: block;
  margin-top: 6px;
  font-size: 2rem;
  line-height: 1;
}

.metric.attention {
  border-color: rgba(200, 93, 79, 0.35);
}

.workspace {
  display: grid;
  grid-template-columns: minmax(248px, 286px) minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}

.filters,
.content-area {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.filters {
  position: sticky;
  top: 16px;
  display: grid;
  gap: 14px;
  padding: 16px;
}

.field {
  display: grid;
  gap: 6px;
}

.field span {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

.field input,
.field select {
  width: 100%;
  min-height: 42px;
  padding: 9px 11px;
  color: var(--ink);
  background: var(--surface-strong);
  border: 1px solid var(--line);
  border-radius: 6px;
}

.field input:focus,
.field select:focus {
  outline: 3px solid rgba(24, 127, 120, 0.18);
  border-color: var(--teal);
}

.view-switch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  padding: 3px;
  background: #ebe8df;
  border-radius: 8px;
}

.segmented,
.reset-button {
  min-height: 40px;
  border: 0;
  border-radius: 6px;
  font-weight: 800;
}

.segmented {
  color: var(--muted);
  background: transparent;
}

.segmented.active {
  color: var(--surface);
  background: var(--teal);
}

.reset-button {
  color: var(--teal-dark);
  background: rgba(24, 127, 120, 0.1);
}

.content-area {
  min-width: 0;
  overflow: hidden;
}

.content-toolbar {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: center;
  padding: 18px 18px 14px;
  border-bottom: 1px solid var(--line);
}

.content-toolbar h2 {
  margin: 0;
  font-size: 1.45rem;
}

.sort-mobile {
  display: none;
  width: min(260px, 100%);
}

.field.compact select {
  min-height: 38px;
}

.table-wrap {
  overflow-x: auto;
}

.pinned-panel {
  display: grid;
  grid-template-columns: minmax(220px, 0.55fr) minmax(0, 1fr);
  gap: 14px;
  padding: 16px 18px;
  background: #fff7f4;
  border-bottom: 1px solid rgba(200, 93, 79, 0.24);
}

.pinned-panel h3 {
  margin: 0;
  font-size: 1.08rem;
}

.pinned-panel p {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.pinned-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 10px;
}

.pinned-item {
  display: grid;
  gap: 2px;
  padding: 10px 12px;
  background: var(--surface);
  border: 1px solid rgba(200, 93, 79, 0.24);
  border-radius: 8px;
}

.pinned-item span,
.pinned-item small {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.pinned-item strong {
  line-height: 1.25;
}

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

th,
td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #f0eee7;
  font-size: 0.82rem;
}

th button {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 0;
  color: var(--muted);
  background: transparent;
  border: 0;
  font-weight: 900;
}

th button.active-sort {
  color: var(--teal-dark);
}

th button.active-sort::after {
  content: "↑";
  font-size: 0.85rem;
}

th button.active-sort[data-direction="desc"]::after {
  content: "↓";
}

td {
  font-size: 0.95rem;
}

tbody tr:hover {
  background: rgba(24, 127, 120, 0.06);
}

tbody tr.pinned-row {
  background: rgba(200, 93, 79, 0.06);
}

.discipline-cell {
  width: 42%;
  font-weight: 700;
}

.grade-badge {
  display: inline-flex;
  max-width: 100%;
  min-height: 28px;
  align-items: center;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 900;
  white-space: nowrap;
}

.grade-excellent {
  color: #ffffff;
  background: var(--green);
}

.grade-good {
  color: #ffffff;
  background: var(--blue);
}

.grade-ok {
  color: #3d2b00;
  background: #f1c96b;
}

.grade-pass {
  color: #063f3b;
  background: rgba(24, 127, 120, 0.16);
}

.grade-empty {
  color: #ffffff;
  background: var(--coral);
}

.cards-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 12px;
  padding: 16px;
}

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

.record-card.pinned-card {
  border-color: rgba(200, 93, 79, 0.3);
  background: #fff7f4;
}

.record-card-head {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 800;
}

.record-card h3 {
  margin: 0;
  font-size: 1rem;
  line-height: 1.35;
}

.record-card dl {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin: 0;
}

.record-card dt {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
}

.record-card dd {
  margin: 2px 0 0;
  font-weight: 800;
}

.empty-state {
  margin: 0;
  padding: 28px;
  color: var(--muted);
  text-align: center;
}

.hidden {
  display: none !important;
}

@media (max-width: 1180px) {
  .topbar,
  .workspace,
  .connection-state {
    grid-template-columns: 1fr;
  }

  .student-panel,
  .filters {
    position: static;
  }

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

  .view-switch,
  .reset-button {
    align-self: end;
  }
}

@media (max-width: 760px) {
  .app-shell {
    width: min(100% - 20px, 720px);
    padding: 18px 0;
  }

  h1 {
    font-size: 2.1rem;
  }

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

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

  .metric strong {
    margin: 0;
    font-size: 1.7rem;
  }

  .content-toolbar {
    display: grid;
  }

  .pinned-panel {
    grid-template-columns: 1fr;
    padding: 14px 12px;
  }

  .sort-mobile {
    display: block;
  }

  .cards-list {
    grid-template-columns: 1fr;
    padding: 12px;
  }

  .record-card dl {
    grid-template-columns: 1fr 74px 54px;
  }
}

@media (max-width: 560px) {
  .app-shell {
    width: min(100% - 14px, 420px);
    padding: 10px 0;
  }

  .topbar {
    gap: 10px;
  }

  .filters {
    grid-template-columns: 1fr;
    gap: 10px;
    padding: 12px;
  }

  .content-toolbar {
    padding: 14px 12px 12px;
  }

  .metric {
    padding: 12px;
  }

  .record-card-head {
    align-items: flex-start;
    flex-direction: column;
  }

  .record-card dl {
    grid-template-columns: 1fr;
  }
}
