:root {
  --bg: #f6f7f4;
  --surface: #ffffff;
  --ink: #17211c;
  --muted: #66736d;
  --line: #dfe5df;
  --nav: #1d2a26;
  --accent: #0f766e;
  --accent-dark: #115e59;
  --amber: #b45309;
  --red: #b42318;
  --red-bg: #fee2e2;
  --green-bg: #dcfce7;
  --shadow: 0 12px 32px rgba(23, 33, 28, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.45;
}

a {
  color: var(--accent-dark);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 24px;
  align-items: center;
  min-height: 64px;
  padding: 0 28px;
  background: var(--nav);
  color: #f8faf9;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.08);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: #f8faf9;
  font-weight: 700;
}

.brand:hover {
  text-decoration: none;
}

.brand-mark {
  display: inline-grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: #f4c95d;
  color: #1d2a26;
  font-size: 13px;
  letter-spacing: 0;
}

.nav {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

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

.nav a:hover {
  background: rgba(255, 255, 255, 0.08);
  text-decoration: none;
}

.user-menu {
  display: flex;
  align-items: center;
  gap: 12px;
  color: #d7dfdb;
}

.app-main {
  width: min(1280px, calc(100% - 32px));
  margin: 0 auto;
  padding: 32px 0 48px;
}

.login-main {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(90deg, rgba(29, 42, 38, 0.92), rgba(29, 42, 38, 0.78)),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='1200' height='800' viewBox='0 0 1200 800'%3E%3Crect width='1200' height='800' fill='%23f6f7f4'/%3E%3Cg fill='none' stroke='%23d7dfdb' stroke-width='2'%3E%3Cpath d='M80 120h1040M80 240h1040M80 360h1040M80 480h1040M80 600h1040M180 80v640M380 80v640M580 80v640M780 80v640M980 80v640'/%3E%3C/g%3E%3C/svg%3E");
  background-size: cover;
}

.login-shell {
  width: min(980px, 100%);
}

.login-panel {
  display: grid;
  grid-template-columns: 1.1fr 420px;
  min-height: 520px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.96);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.login-copy {
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  padding: 48px;
  background: #1d2a26;
  color: #f8faf9;
}

.login-copy p {
  max-width: 540px;
  margin: 0;
  color: #d7dfdb;
  font-size: 17px;
}

.login-copy h1 {
  margin: 10px 0 16px;
  font-size: 42px;
  line-height: 1.08;
  letter-spacing: 0;
}

.login-card {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 18px;
  padding: 42px;
}

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

h1 {
  margin: 0;
  font-size: 30px;
  line-height: 1.18;
  letter-spacing: 0;
}

h2 {
  margin: 0;
  font-size: 18px;
  line-height: 1.25;
  letter-spacing: 0;
}

.eyebrow {
  display: inline-block;
  color: var(--accent-dark);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.login-copy .eyebrow {
  color: #f4c95d;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #ffffff;
  color: var(--ink);
  font: inherit;
  padding: 10px 12px;
}

textarea {
  resize: vertical;
}

input:focus, select:focus, textarea:focus {
  outline: 2px solid rgba(15, 118, 110, 0.25);
  border-color: var(--accent);
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  gap: 8px;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 8px 13px;
  font-weight: 800;
  cursor: pointer;
  text-decoration: none;
  font-size: 14px;
  line-height: 1.1;
}

.button:hover {
  text-decoration: none;
}

.text-link {
  color: var(--accent-dark);
  font-weight: 800;
  text-align: center;
  text-decoration: none;
}

.text-link:hover {
  text-decoration: underline;
}

.button-primary {
  background: var(--accent);
  color: #ffffff;
}

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

.button-secondary {
  background: #eef5f2;
  color: var(--accent-dark);
  border-color: #cfe3dc;
}

.button-ghost {
  color: #f8faf9;
  border-color: rgba(255, 255, 255, 0.18);
}

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

.button-row, .heading-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.page-heading {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 18px;
  margin-bottom: 22px;
}

.panel, .metric, .template-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 1px 2px rgba(23, 33, 28, 0.04);
}

.panel {
  padding: 20px;
  margin-bottom: 22px;
}

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

.student-history-heading {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 16px;
  margin: 4px 0 18px;
}

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

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

.metric {
  padding: 18px;
}

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

.metric strong {
  display: block;
  margin-top: 8px;
  font-size: 28px;
}

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

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

.template-card {
  padding: 20px;
}

.template-card h2 {
  margin-bottom: 16px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  margin-bottom: 16px;
}

.form-grid.tight {
  gap: 10px;
  margin-bottom: 0;
}

.log-filter-grid {
  grid-template-columns: minmax(180px, 1.2fr) minmax(140px, 0.8fr) minmax(180px, 1.2fr) minmax(96px, 0.45fr);
}

.narrow-panel {
  max-width: 560px;
}

.inline-form {
  display: flex;
  align-items: end;
  gap: 10px;
}

.option-add-form {
  margin-bottom: 16px;
}

.option-edit-form {
  align-items: center;
}

.option-edit-form label {
  min-width: 220px;
}

.user-list {
  display: grid;
  gap: 12px;
}

.user-list-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: end;
  border-top: 1px solid var(--line);
  padding-top: 12px;
}

.user-list-row:first-child {
  border-top: 0;
  padding-top: 0;
}

.user-form {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: end;
}

.user-form label {
  flex: 1 1 150px;
  min-width: 130px;
}

.user-form .button,
.user-delete-form .button {
  min-height: 38px;
}

.user-delete-form {
  display: flex;
  align-items: end;
}

.form-panel {
  display: grid;
  gap: 14px;
}

.form-guidance {
  background: #f4f8f6;
  border-left: 3px solid var(--accent);
  border-radius: 6px;
  color: #31423a;
  padding: 12px 14px;
}

.form-guidance strong {
  display: block;
  margin-bottom: 6px;
}

.form-guidance ul {
  margin: 0;
  padding-left: 18px;
}

.form-guidance li {
  margin: 5px 0;
}

.workload-notes {
  border-left: 4px solid var(--accent);
  background: #f4f8f6;
}

.workload-notes ul {
  margin: 0;
  padding-left: 18px;
}

.workload-notes li {
  margin: 7px 0;
}

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

fieldset {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
}

legend {
  padding: 0 6px;
  color: #4b5a54;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.status-form {
  display: grid;
  grid-template-columns: minmax(96px, 1fr) auto;
  gap: 8px;
  align-items: center;
}

.status-form select {
  min-width: 96px;
  padding: 7px 9px;
}

.status-form .button {
  min-height: 34px;
}

.profile-form {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: end;
  min-width: 0;
}

.profile-form label {
  flex: 1 1 140px;
  min-width: 120px;
}

.profile-form input,
.profile-form select {
  padding: 8px 10px;
}

.profile-form .button {
  flex: 0 0 auto;
  min-height: 36px;
}

table {
  width: 100%;
  border-collapse: collapse;
  table-layout: auto;
}

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

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

th {
  color: #4b5a54;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0;
  background: #f4f7f5;
}

td {
  font-size: 14px;
}

.num {
  text-align: right;
  white-space: nowrap;
}

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

.empty-state {
  display: grid;
  place-items: center;
  gap: 8px;
  min-height: 180px;
  padding: 28px;
  text-align: center;
  color: var(--muted);
}

.empty-state h2 {
  color: var(--ink);
}

.tag, .status {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 6px;
  padding: 3px 8px;
  font-size: 12px;
  font-weight: 800;
}

.tag {
  background: #eef5f2;
  color: var(--accent-dark);
}

.status-active, .status-approved {
  background: var(--green-bg);
  color: #166534;
}

.status-inactive, .status-rejected {
  background: #f1f3f2;
  color: #5d6863;
}

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

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

.alert-success {
  background: var(--green-bg);
  color: #166534;
  border: 1px solid #bbf7d0;
}

.alert-error {
  background: var(--red-bg);
  color: var(--red);
  border: 1px solid #fecaca;
}

.low-row, .row-error {
  background: #fff7ed;
}

.row-ignored {
  background: #f8faf9;
  color: var(--muted);
}

.message-error {
  color: var(--red);
  font-weight: 700;
}

.message-warning {
  color: var(--amber);
  font-weight: 700;
}

.log-details {
  min-width: 240px;
  max-width: 520px;
  white-space: normal;
  overflow-wrap: anywhere;
}

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

code {
  display: inline-block;
  max-width: 420px;
  white-space: normal;
  overflow-wrap: anywhere;
  color: #374151;
  background: #f4f7f5;
  border-radius: 6px;
  padding: 3px 5px;
  font-size: 12px;
}

.review-form {
  display: grid;
  grid-template-columns: 90px minmax(130px, 1fr);
  gap: 8px;
}

.review-form .button {
  min-height: 34px;
}

.actions {
  width: 1%;
  white-space: nowrap;
}

.actions form {
  display: inline-block;
  margin-left: 6px;
}

.error-panel {
  max-width: 760px;
  margin: 60px auto;
}

.error-panel pre {
  max-height: 360px;
  overflow: auto;
  padding: 14px;
  background: #1f2937;
  color: #f8fafc;
  border-radius: 8px;
}

@media (max-width: 880px) {
  .topbar {
    grid-template-columns: 1fr;
    gap: 10px;
    padding: 12px 16px;
  }

  .user-menu {
    justify-content: space-between;
  }

  .login-panel,
  .two-column,
  .template-grid,
  .workload-sections,
  .metric-grid,
  .metric-grid.three,
  .form-grid {
    grid-template-columns: 1fr;
  }

  .login-copy {
    padding: 32px;
  }

  .login-copy h1 {
    font-size: 34px;
  }

  .login-card {
    padding: 28px;
  }

  .page-heading {
    align-items: stretch;
    flex-direction: column;
  }

  .student-history-heading {
    align-items: stretch;
    flex-direction: column;
  }

  .inline-form {
    align-items: stretch;
    flex-direction: column;
  }

  .profile-form {
    grid-template-columns: 1fr;
    min-width: 0;
  }

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

  .user-delete-form {
    justify-content: flex-start;
  }

  table {
    display: block;
    overflow-x: auto;
    white-space: nowrap;
  }
}
