:root {
  --bg: #f8f4ef;
  --panel: #ffffff;
  --text: #1e2224;
  --muted: #756d68;
  --line: #e3d9cf;
  --accent: #551821;
  --accent-dark: #3a1117;
  --accent-soft: #f4eaeb;
  --charcoal: #1e2224;
  --warn: #a46722;
  --danger: #a33c43;
  --sidebar: #eee8df;
  --shadow: 0 16px 42px rgba(49, 33, 34, 0.06);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  display: grid;
  grid-template-columns: 230px 1fr;
  background: var(--bg);
  color: var(--text);
  font-family: "PingFang SC", "Hiragino Sans GB", "Noto Sans SC", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
  font-weight: 400;
  letter-spacing: 0;
  -webkit-font-smoothing: antialiased;
  text-rendering: geometricPrecision;
}

body.locked {
  overflow: hidden;
}

.login-screen {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: none;
  place-items: center;
  padding: 20px;
  background: linear-gradient(115deg, #551821 0%, #351b20 48%, #1e2224 100%);
}

body.locked .login-screen {
  display: grid;
}

.login-box {
  width: min(400px, 100%);
  padding: 40px 38px 38px;
  border: 0;
  border-radius: 17px;
  background: #fff;
  box-shadow: 0 26px 70px rgba(20, 16, 17, 0.38);
}

.login-box h1 {
  font-size: 16px;
  text-align: center;
  font-weight: 400;
  letter-spacing: 0;
  margin-top: 18px;
  color: #675d59;
}

.login-box p {
  color: #928985;
  margin-top: 54px;
  text-align: center;
  font-size: 13px;
}

.login-form {
  margin-top: 30px;
  gap: 14px;
}

.login-brand,
.sidebar-logo-tile {
  display: grid;
  place-items: center;
  overflow: hidden;
}

.login-brand {
  height: 72px;
  background: #fff;
}

.login-brand img {
  width: 250px;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.sidebar-logo-tile img {
  display: block;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.sidebar {
  background: var(--sidebar);
  border-right: 1px solid #ded4c9;
  color: #35282a;
  padding: 30px 18px 20px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.brand {
  display: grid;
  padding: 0 6px 34px;
}

.sidebar-logo-tile {
  height: 44px;
  justify-items: start;
}

.sidebar-logo-tile img {
  width: 158px;
}

nav {
  display: grid;
  gap: 8px;
  flex: 1;
  align-content: start;
  grid-auto-rows: min-content;
}

.sidebar-user {
  display: grid;
  grid-template-columns: 38px 1fr 28px;
  align-items: center;
  gap: 10px;
  padding: 20px 8px 0;
  border-top: 1px solid #d9cfc3;
  color: #2a2221;
}

.user-avatar {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  background: #f1dba3;
  color: #5c4b30;
  font-weight: 400;
}

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

.sidebar-user strong {
  font-size: 13px;
  font-weight: 400;
}

.sidebar-user span {
  margin-top: 3px;
  color: #786f69;
  font-size: 12px;
}

.sidebar-user button {
  padding: 0;
  width: 28px;
  height: 28px;
  background: transparent;
  color: var(--accent);
  font-size: 18px;
  font-weight: 400;
}

.nav-button {
  width: 100%;
  border: 0;
  border-radius: 8px;
  padding: 0 14px;
  height: 44px;
  min-height: 44px;
  display: flex;
  align-items: center;
  text-align: left;
  background: transparent;
  color: #695d59;
  cursor: pointer;
  font-size: 14px;
  font-weight: 400;
  line-height: 1;
}

.nav-button.active,
.nav-button:hover {
  background: var(--accent);
  color: #ffffff;
}

.main {
  min-width: 0;
  padding: 42px;
}

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

.top-actions,
.table-actions,
.form-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

#current-user {
  display: none;
  color: var(--muted);
  font-size: 13px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 28px;
  line-height: 1.25;
  font-weight: 400;
}

h2 {
  font-size: 17px;
  font-weight: 400;
}

.topbar p {
  margin-top: 12px;
  color: var(--muted);
  font-size: 13px;
}

button {
  border: 0;
  border-radius: 8px;
  background: #eef1ef;
  color: #38413e;
  padding: 12px 17px;
  cursor: pointer;
  font: inherit;
  font-weight: 400;
}

button:hover {
  filter: brightness(0.98);
}

.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 400;
}

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

.metrics {
  display: grid;
  grid-template-columns: repeat(7, minmax(120px, 1fr));
  gap: 10px;
  margin-bottom: 24px;
}

.contract-metrics {
  grid-template-columns: repeat(4, minmax(150px, 1fr));
  margin-bottom: 18px;
}

.contract-metrics[hidden] {
  display: none !important;
}

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

.metric-card {
  position: relative;
  min-width: 0;
  min-height: 112px;
  padding: 16px;
  overflow: hidden;
  text-align: left;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: none;
}

.metric-card:hover,
.metric-card:focus-visible {
  color: var(--text);
  background: #fff;
  border-color: #bea8a1;
  transform: translateY(-2px);
  box-shadow: var(--shadow);
}

.metric-card .metric-label {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.metric-card strong {
  display: flex;
  align-items: baseline;
  gap: 4px;
  margin-top: 19px;
  font-size: 25px;
  font-weight: 500;
}

.metric-card small {
  color: var(--muted);
  font-size: 12px;
  font-weight: 400;
}

.metric-card i {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 25px;
  height: 25px;
  display: grid;
  place-items: center;
  color: var(--accent);
  background: var(--accent-soft);
  border-radius: 8px;
  font-size: 11px;
  font-style: normal;
}

.metric-card.attention strong {
  color: var(--danger);
}

.workspace {
  display: grid;
  grid-template-columns: minmax(280px, 330px) 1fr;
  gap: 0;
  align-items: start;
  min-width: 0;
}

.workspace.hide-form {
  grid-template-columns: 1fr;
}

.workspace.hide-form .form-panel {
  display: none;
}

.workspace.hide-form .table-panel {
  border-radius: 14px;
}

.workspace.hide-table {
  grid-template-columns: minmax(320px, 560px);
}

.workspace.hide-table .table-panel {
  display: none;
}

.workspace.hide-table .form-panel {
  border-right: 1px solid var(--line);
  border-radius: 14px;
}

.panel {
  padding: 20px;
  min-width: 0;
}

.form-panel {
  border-radius: 14px 0 0 14px;
  border-right: 0;
}

.table-panel {
  border-radius: 0 14px 14px 0;
}

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

.table-actions {
  flex-wrap: wrap;
  justify-content: flex-end;
}

.table-actions input {
  width: min(240px, 48vw);
}

form {
  display: grid;
  gap: 12px;
  margin-top: 15px;
}

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

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

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

input,
select,
textarea {
  width: 100%;
  border: 1px solid #d9d4ce;
  border-radius: 8px;
  padding: 12px 13px;
  font: inherit;
  background: #fff;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(73, 26, 32, 0.1);
  outline: none;
}

textarea {
  min-height: 78px;
  resize: vertical;
}

.table-wrap {
  overflow: auto;
  max-height: calc(100vh - 250px);
}

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

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

.actions-cell {
  white-space: nowrap;
}

.link-button {
  border: 0;
  background: transparent;
  color: var(--accent-dark);
  padding: 0 8px 0 0;
  font-weight: 400;
}

.student-name-button {
  display: block;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--wine);
  font: inherit;
  font-weight: 700;
  text-align: left;
  cursor: pointer;
}

.student-name-button:hover {
  text-decoration: underline;
}

.student-school {
  display: block;
  margin-top: 4px;
  color: var(--muted);
}

.progress-metric {
  min-width: 150px;
}

.progress-metric > span {
  display: block;
  min-height: 20px;
  margin-bottom: 7px;
  color: var(--muted);
  font-size: 12px;
}

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

.progress-line i {
  display: block;
  width: 105px;
  height: 7px;
  overflow: hidden;
  border-radius: 999px;
  background: #e5e8e6;
}

.progress-line b {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: #16734a;
}

.progress-line strong {
  min-width: 48px;
  color: #173a2b;
  font-size: 17px;
}

.progress-metric.danger .progress-line b {
  background: #c6283d;
}

.progress-metric.danger .progress-line strong {
  color: #a71931;
}

.detail-progress-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(180px, 1fr));
  gap: 18px;
  margin-top: 18px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

th {
  color: var(--muted);
  font-weight: 400;
  background: #fbfaf8;
  position: sticky;
  top: 0;
}

.course-group-row td {
  padding: 11px 9px;
  background: #f3eee8;
  color: var(--accent-dark);
  border-top: 1px solid #ddd2c7;
  border-bottom: 1px solid #ddd2c7;
}

.course-group-row span {
  font-size: 14px;
}

.course-group-row small {
  margin-left: 10px;
  color: var(--muted);
  font-size: 12px;
}

.attendance-statuses {
  display: flex;
  gap: 5px;
  min-width: 310px;
}

.attendance-status-button {
  min-width: 54px;
  height: 34px;
  padding: 0 9px;
  border: 1px solid #ded6ce;
  background: #fff;
  color: #625955;
  border-radius: 7px;
  font-size: 12px;
}

.attendance-status-button.active {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

.attendance-name span,
.attendance-name small {
  display: block;
}

.attendance-name small {
  margin-top: 4px;
  color: var(--muted);
  font-size: 11px;
  white-space: nowrap;
}

.attendance-homework {
  display: flex;
  align-items: center;
  gap: 6px;
  color: #514845;
  white-space: nowrap;
}

.attendance-homework input {
  width: 15px;
  height: 15px;
  margin: 0;
  accent-color: var(--accent);
}

.attendance-remark {
  min-width: 150px;
  padding: 8px 9px;
}

.attendance-form-actions {
  flex-wrap: wrap;
}

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

.pill {
  display: inline-block;
  border-radius: 999px;
  padding: 3px 8px;
  background: var(--accent-soft);
  color: var(--accent-dark);
  font-size: 12px;
  white-space: nowrap;
}

.pill.high {
  background: #fff1dd;
  color: var(--warn);
}

.pill.danger {
  background: #ffe8eb;
  color: var(--danger);
}

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

.permission-check {
  min-height: 34px;
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 8px 9px;
  border: 1px solid #ded6ce;
  border-radius: 8px;
  background: #fff;
  color: #514845;
  font-size: 13px;
}

.permission-check input {
  width: 14px;
  height: 14px;
  margin: 0;
  accent-color: var(--accent);
}

.detail-modal {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(31, 24, 25, 0.42);
}

.detail-modal[hidden] {
  display: none;
}

.detail-card {
  width: min(1080px, 100%);
  max-height: min(82vh, 820px);
  overflow: hidden;
  display: grid;
  grid-template-rows: auto 1fr;
  border-radius: 14px;
  background: #fff;
  border: 1px solid var(--line);
}

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

.detail-head-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.detail-edit-form {
  display: grid;
  grid-template-columns: repeat(2, minmax(220px, 1fr));
  gap: 14px;
}

.detail-edit-form .field:has(textarea),
.detail-edit-form .form-actions {
  grid-column: 1 / -1;
}

.password-card {
  width: min(520px, calc(100vw - 32px));
  max-height: calc(100vh - 40px);
  overflow: hidden;
  border-radius: 14px;
  background: #fff;
  box-shadow: 0 24px 70px rgba(41, 28, 23, 0.2);
}

.password-form {
  display: grid;
  gap: 16px;
}

.detail-head p {
  margin-top: 7px;
  color: var(--muted);
  font-size: 13px;
}

.detail-body {
  overflow: auto;
  padding: 20px 22px 24px;
}

.detail-section {
  margin-bottom: 20px;
}

.detail-section h3 {
  margin: 0 0 11px;
  font-size: 15px;
  font-weight: 400;
}

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

.detail-grid div,
.detail-note {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fbfaf8;
}

.detail-grid span,
.detail-note span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 6px;
}

.detail-grid strong {
  font-weight: 400;
}

.detail-note {
  margin-top: 10px;
}

.detail-note p {
  line-height: 1.7;
}

.mini-table {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.mini-table table {
  min-width: 660px;
}

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

  .sidebar {
    min-height: auto;
  }

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

  .workspace,
  .metrics {
    grid-template-columns: 1fr;
  }

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

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .top-actions,
  .table-actions,
  .form-actions {
    width: 100%;
    justify-content: flex-start;
    flex-wrap: wrap;
  }

  .detail-grid,
  .detail-edit-form,
  .permission-grid {
    grid-template-columns: 1fr;
  }

  .main {
    padding: 26px 16px;
    overflow: hidden;
  }

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