:root {
  --bg: #eef3f7;
  --surface: #ffffff;
  --surface-soft: #f7f9fc;
  --surface-tint: #edf5f8;
  --text: #15212f;
  --muted: #647386;
  --line: #dbe3ec;
  --line-strong: #c4cfdb;
  --nav: #13202d;
  --nav-soft: #1b2a38;
  --nav-line: rgba(196, 213, 230, 0.18);
  --nav-text: #edf6ff;
  --nav-muted: #9db1c3;
  --primary: #146c83;
  --primary-strong: #0e5265;
  --primary-soft: #e5f3f6;
  --accent: #9f5b12;
  --good: #177c59;
  --warn: #a36510;
  --danger: #b42318;
  --shadow: 0 14px 34px rgba(31, 48, 68, 0.08);
  --shadow-soft: 0 8px 18px rgba(31, 48, 68, 0.05);
}

* {
  box-sizing: border-box;
}

html {
  background: var(--bg);
}

body {
  margin: 0;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.74), rgba(255, 255, 255, 0) 260px),
    var(--bg);
  color: var(--text);
  font-family: "Microsoft YaHei", "PingFang SC", "Segoe UI", Arial, sans-serif;
  font-size: 14px;
  line-height: 1.45;
}

body.auth-required .app-shell {
  filter: blur(2px);
  pointer-events: none;
  user-select: none;
}

body.authenticated .auth-screen {
  display: none;
}

body:not(.is-admin) .admin-only,
body:not(.can-write) #newStudentBtn,
body:not(.can-write) #newFlightBtn,
body:not(.can-write) #newPilotProfileBtn,
body:not(.can-write) #newProficiencyBtn,
body:not(.can-write) [data-edit-flight],
body:not(.can-write) [data-delete-flight],
body:not(.can-write) [data-edit-profile],
body:not(.can-write) [data-delete-profile],
body:not(.can-write) [data-edit-proficiency],
body:not(.can-write) [data-delete-proficiency] {
  display: none !important;
}

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

button,
a.secondary,
label.secondary {
  border: 0;
  cursor: pointer;
  text-decoration: none;
}

.app-shell {
  display: grid;
  grid-template-columns: 282px minmax(0, 1fr);
  min-height: 100vh;
}

.auth-screen {
  position: fixed;
  z-index: 1000;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 18px;
  background:
    linear-gradient(135deg, rgba(19, 32, 45, 0.94), rgba(20, 108, 131, 0.88)),
    var(--bg);
}

.auth-card {
  width: min(420px, 100%);
  padding: 22px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 10px;
  background: #ffffff;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.28);
}

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

.auth-brand h1,
.auth-brand p,
.auth-note,
.sidebar-note {
  margin: 0;
}

.auth-brand h1 {
  font-size: 22px;
  font-weight: 900;
}

.auth-brand p,
.auth-note {
  color: var(--muted);
}

.auth-note {
  margin-top: 12px;
  font-size: 12px;
}

.auth-card label {
  display: grid;
  gap: 7px;
  margin-bottom: 12px;
  color: var(--muted);
  font-weight: 800;
}

.auth-card input {
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  color: var(--text);
}

.auth-error {
  margin: 0 0 12px;
  padding: 10px 12px;
  border: 1px solid #f3b6af;
  border-radius: 8px;
  background: #fff7f6;
  color: var(--danger);
  font-size: 13px;
  font-weight: 800;
  line-height: 1.5;
  word-break: break-word;
}

.hidden {
  display: none !important;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  padding: 18px 14px;
  background:
    linear-gradient(180deg, rgba(35, 54, 72, 0.78), rgba(19, 32, 45, 0) 220px),
    var(--nav);
  color: var(--nav-text);
}

.brand {
  display: flex;
  gap: 11px;
  align-items: center;
  padding: 7px 8px 16px;
  margin-bottom: 6px;
  border-bottom: 1px solid var(--nav-line);
}

.brand-mark {
  display: grid;
  width: 42px;
  height: 42px;
  flex: 0 0 auto;
  place-items: center;
  border: 1px solid rgba(223, 235, 247, 0.28);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.06);
  color: #ffffff;
  font-size: 16px;
  font-weight: 900;
}

.brand h1,
.brand p,
.topbar h2,
.topbar p,
.panel h3,
.dialog-head h3 {
  margin: 0;
}

.brand h1 {
  font-size: 18px;
  line-height: 1.15;
  font-weight: 900;
}

.brand p {
  margin-top: 4px;
  color: var(--nav-muted);
  font-size: 12px;
}

.user-box {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.user-box strong {
  display: block;
  margin-top: 3px;
  color: #ffffff;
}

.sidebar-note {
  color: var(--nav-muted);
  font-size: 12px;
}

.account-card {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.account-card div {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
}

.account-card span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.account-card strong {
  display: block;
  margin-top: 4px;
}

.inline-check {
  display: flex !important;
  align-items: center;
  gap: 8px;
}

.side-section {
  margin-top: 16px;
}

.side-section.compact {
  padding-top: 14px;
  border-top: 1px solid var(--nav-line);
}

.side-section.first {
  margin-top: 12px;
  padding-top: 0;
  border-top: 0;
}

.side-title {
  margin: 0 8px 8px;
  color: var(--nav-muted);
  font-size: 12px;
  font-weight: 800;
}

.module-nav,
.template-filter {
  display: grid;
  gap: 7px;
}

.module-tab,
.template-chip,
.student-item {
  width: 100%;
  border: 1px solid transparent;
  border-radius: 8px;
  color: var(--nav-text);
  text-align: left;
  transition: background 0.16s ease, border-color 0.16s ease, transform 0.16s ease;
}

.module-tab,
.template-chip {
  min-height: 38px;
  padding: 8px 10px;
  background: transparent;
  font-weight: 800;
}

.module-tab:hover,
.template-chip:hover,
.student-item:hover {
  border-color: rgba(223, 235, 247, 0.2);
  background: rgba(255, 255, 255, 0.06);
}

.module-tab.active,
.template-chip.active,
.student-item.active {
  border-color: rgba(125, 177, 201, 0.72);
  background: #213544;
}

.module-tab.active {
  box-shadow: inset 3px 0 0 #62b3c7;
}

.hidden,
.module-page {
  display: none;
}

.module-page.active {
  display: block;
}

.student-list {
  display: grid;
  gap: 7px;
}

.student-item {
  padding: 10px 11px;
  background: rgba(255, 255, 255, 0.035);
}

.student-name {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-weight: 900;
}

.student-meta {
  margin-top: 5px;
  color: var(--nav-muted);
  font-size: 12px;
}

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

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 64px;
  margin-bottom: 16px;
  padding: 4px 2px;
}

.topbar h2 {
  font-size: 24px;
  line-height: 1.18;
  font-weight: 900;
}

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

.top-actions,
.button-row,
.filters,
.dialog-actions {
  display: flex;
  align-items: center;
  gap: 9px;
}

.primary,
.secondary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  padding: 8px 13px;
  border-radius: 8px;
  font-weight: 800;
  white-space: nowrap;
  transition: background 0.16s ease, border-color 0.16s ease, transform 0.16s ease;
}

.primary {
  background: var(--primary);
  color: white;
}

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

.primary:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

.secondary {
  border: 1px solid var(--line);
  background: #ffffff;
  color: var(--text);
}

.secondary:hover {
  border-color: var(--line-strong);
  background: var(--surface-soft);
}

.sidebar .primary {
  min-height: 40px;
  margin-top: 2px;
  background: #2f758d;
}

.sidebar .secondary {
  border-color: rgba(223, 235, 247, 0.16);
  background: rgba(255, 255, 255, 0.07);
  color: #ffffff;
}

.wide {
  width: 100%;
}

.small {
  min-height: 32px;
  padding: 6px 10px;
  font-size: 13px;
}

.file-button input {
  display: none;
}

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

.metric {
  min-width: 0;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow-soft);
}

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

.metric-value {
  margin-top: 4px;
  font-size: 25px;
  line-height: 1.15;
  font-weight: 900;
}

.metric-sub {
  margin-top: 5px;
  color: var(--muted);
  font-size: 12px;
}

.workspace-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(320px, 0.65fr);
  gap: 12px;
  margin-bottom: 12px;
}

.compact-grid {
  grid-template-columns: minmax(0, 1fr) minmax(360px, 0.9fr);
}

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

.category-card {
  padding: 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
}

.category-title {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-weight: 900;
}

.category-values {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-top: 9px;
}

.category-values span {
  color: var(--muted);
  font-size: 12px;
}

.category-values strong {
  display: block;
  margin-top: 2px;
  color: var(--text);
  font-size: 15px;
}

.delta-positive {
  color: var(--danger) !important;
}

.delta-negative {
  color: var(--warn) !important;
}

.delta-zero {
  color: var(--good) !important;
}

.alert-list {
  display: grid;
  gap: 8px;
  max-height: 214px;
  overflow: auto;
}

.alert-item {
  display: grid;
  grid-template-columns: 52px 1fr auto;
  gap: 10px;
  align-items: start;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
}

.alert-item.over {
  border-color: #e9b6b0;
  background: #fff7f6;
}

.alert-item.short {
  border-color: #ecd094;
  background: #fffaf0;
}

.alert-item.minor {
  border-color: #cfe2ea;
  background: #f4fafc;
}

.alert-code,
.alert-title,
.alert-delta {
  font-weight: 900;
}

.alert-meta {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.alert-delta {
  white-space: nowrap;
}

.panel {
  padding: 15px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow-soft);
  margin-bottom: 12px;
}

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

.panel-head h3 {
  font-size: 16px;
  font-weight: 900;
}

.panel-head span {
  color: var(--muted);
  font-size: 12px;
}

.stage-grid {
  display: grid;
  gap: 9px;
}

.stage-row {
  display: grid;
  grid-template-columns: 150px 1fr 82px;
  align-items: center;
  gap: 12px;
}

.stage-name {
  font-weight: 800;
}

.stage-hours {
  color: var(--muted);
  font-size: 12px;
  text-align: right;
}

.check-summary-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}

.check-summary-grid .metric {
  padding: 12px;
  box-shadow: none;
}

.check-summary-grid .metric-value {
  font-size: 22px;
}

.bar {
  height: 9px;
  overflow: hidden;
  border-radius: 999px;
  background: #e5ebf1;
}

.bar > i {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--primary);
}

.next-course {
  min-height: 116px;
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-tint);
}

.next-course strong {
  display: block;
  margin-bottom: 7px;
  font-size: 17px;
}

.next-course p {
  margin: 5px 0;
  color: var(--muted);
}

.empty-state {
  display: grid;
  place-items: center;
  color: var(--muted);
  text-align: center;
}

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

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 980px;
  background: #ffffff;
}

.proficiency-table {
  min-width: 920px;
}

.profile-table {
  min-width: 1080px;
}

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

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #f5f8fb;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}

td {
  color: var(--text);
}

tbody tr:last-child td {
  border-bottom: 0;
}

.course-title {
  max-width: 320px;
  font-weight: 800;
}

.course-times {
  min-width: 142px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.55;
  white-space: nowrap;
}

.course-times strong {
  color: var(--text);
}

.course-times span {
  color: var(--muted);
}

.course-times-total {
  margin-top: 2px;
  color: var(--text);
  font-weight: 900;
}

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

.file-link {
  display: inline-flex;
  max-width: 180px;
  margin-top: 4px;
  color: var(--primary);
  font-size: 12px;
  font-weight: 800;
  text-decoration: none;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

.upload-current {
  display: block;
  min-height: 18px;
  margin-top: 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.upload-current .file-link {
  margin-top: 0;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 23px;
  padding: 3px 8px;
  border-radius: 999px;
  background: #eef2f6;
  color: #344054;
  font-size: 12px;
  font-weight: 800;
}

.badge.done {
  background: #e7f6ef;
  color: var(--good);
}

.badge.running {
  background: #fff4df;
  color: var(--warn);
}

.badge.over {
  background: #fff0ee;
  color: var(--danger);
}

.badge.short {
  background: #fff4df;
  color: var(--warn);
}

.badge.idle {
  background: #eef2f6;
  color: #536170;
}

.progress-cell {
  min-width: 130px;
}

select,
input,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  color: var(--text);
  outline: none;
}

select:focus,
input:focus,
textarea:focus {
  border-color: #6baabe;
  box-shadow: 0 0 0 3px rgba(20, 108, 131, 0.12);
}

select,
input {
  height: 36px;
  padding: 7px 10px;
}

textarea {
  padding: 9px 10px;
  resize: vertical;
}

dialog {
  width: min(760px, calc(100vw - 28px));
  max-height: calc(100vh - 12px);
  padding: 0;
  border: 0;
  border-radius: 8px;
  box-shadow: 0 28px 80px rgba(15, 23, 42, 0.28);
  overflow: hidden;
}

dialog::backdrop {
  background: rgba(16, 24, 40, 0.45);
}

.dialog-card {
  padding: 18px;
  max-height: calc(100vh - 12px);
  overflow: auto;
  background: var(--surface);
}

.dialog-card.large {
  width: 100%;
}

#flightDialog {
  width: min(1180px, calc(100vw - 12px));
}

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

.dialog-head.sticky {
  position: sticky;
  top: -18px;
  z-index: 2;
  margin: -18px -18px 14px;
  padding: 16px 18px 12px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.dialog-head p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.icon-button {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border-radius: 8px;
  background: #eef2f6;
  color: var(--text);
  font-size: 22px;
  line-height: 1;
}

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

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

.course-editor-grid,
.checklist-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.course-editor-grid textarea {
  min-height: 160px;
  line-height: 1.55;
}

.course-editor-grid label:nth-child(2) textarea {
  min-height: 230px;
}

.check-section {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
  overflow: hidden;
}

.check-section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  background: #ffffff;
}

.check-section-head h4 {
  margin: 0;
  font-size: 14px;
}

.check-list {
  display: grid;
  gap: 6px;
  padding: 10px;
}

.check-row {
  display: grid;
  grid-template-columns: 24px minmax(0, 1fr) 78px 32px;
  gap: 8px;
  align-items: center;
}

.check-row input[type="checkbox"] {
  width: 18px;
  height: 18px;
}

.check-row input[type="text"] {
  height: 34px;
}

.check-row select {
  height: 34px;
  padding: 5px 7px;
}

.remove-item {
  display: grid;
  width: 32px;
  height: 32px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  color: var(--danger);
}

.course-template-block {
  margin-top: 12px;
}

.clickable-row {
  cursor: pointer;
}

.clickable-row:hover {
  background: #f8fafc;
}

#flightForm .form-grid.three {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px 12px;
}

#flightForm .span-3 {
  grid-column: 1 / -1;
}

label {
  display: grid;
  gap: 6px;
  color: #344054;
  font-weight: 800;
}

.span-2 {
  grid-column: span 2;
}

.span-3 {
  grid-column: span 3;
}

.dialog-actions {
  position: sticky;
  bottom: -18px;
  justify-content: flex-end;
  margin: 16px -18px -18px;
  padding: 12px 18px 16px;
  border-top: 1px solid var(--line);
  background: var(--surface);
}

.danger-link {
  border: 0;
  background: transparent;
  color: var(--danger);
  cursor: pointer;
  font-weight: 800;
}

.table-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
}

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 10;
  max-width: 360px;
  padding: 12px 14px;
  border-radius: 8px;
  background: #101828;
  color: #ffffff;
  box-shadow: var(--shadow);
  transform: translateY(18px);
  opacity: 0;
  pointer-events: none;
  transition: 0.18s ease;
}

.toast.show {
  transform: translateY(0);
  opacity: 1;
}

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

  .sidebar {
    position: static;
    height: auto;
    padding: 14px;
  }

  .brand {
    margin-bottom: 12px;
  }

  .module-nav,
  .template-filter,
  .student-list {
    grid-template-columns: repeat(auto-fit, minmax(132px, 1fr));
  }

  .side-section {
    margin-top: 14px;
  }

  .button-row {
    flex-wrap: wrap;
  }

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

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

@media (max-width: 760px) {
  body {
    font-size: 13px;
  }

  .sidebar {
    padding: 12px;
  }

  .brand {
    padding: 4px 2px 12px;
  }

  .brand-mark {
    width: 38px;
    height: 38px;
    font-size: 15px;
  }

  .brand h1 {
    font-size: 17px;
  }

  .module-nav,
  .template-filter,
  .student-list {
    grid-template-columns: 1fr 1fr;
  }

  .sidebar [data-module-panel="training"] {
    display: grid;
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .sidebar [data-module-panel="training"] > .primary {
    margin-top: 0;
  }

  .sidebar .button-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .module-tab,
  .template-chip,
  .student-item {
    min-height: 34px;
    padding: 8px 9px;
  }

  .sidebar .primary {
    min-height: 38px;
  }

  .main {
    padding: 14px;
  }

  .topbar,
  .panel-head,
  .top-actions,
  .filters {
    align-items: stretch;
    flex-direction: column;
  }

  .topbar {
    gap: 10px;
  }

  .topbar h2 {
    font-size: 21px;
  }

  .metric-grid,
  .check-summary-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
  }

  .metric {
    padding: 12px;
  }

  .metric-value {
    font-size: 22px;
  }

  .category-grid,
  .form-grid,
  .form-grid.three,
  .course-editor-grid,
  .checklist-grid,
  .account-card {
    grid-template-columns: 1fr;
  }

  .stage-row {
    grid-template-columns: 1fr;
    gap: 6px;
  }

  .stage-hours {
    text-align: left;
  }

  .span-2,
  .span-3 {
    grid-column: span 1;
  }
}

@media (max-width: 460px) {
  .module-nav,
  .template-filter,
  .student-list,
  .metric-grid,
  .check-summary-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 680px) {
  #flightForm.dialog-card {
    padding: 12px;
  }

  #flightForm .dialog-head.sticky {
    top: -12px;
    margin: -12px -12px 10px;
    padding: 12px;
  }

  #flightForm .form-grid.three {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 9px;
  }

  #flightForm .span-3 {
    grid-column: 1 / -1;
  }

  #flightForm label {
    gap: 4px;
    font-size: 13px;
  }

  #flightForm input,
  #flightForm select {
    height: 34px;
    padding: 5px 8px;
  }

  #flightForm textarea {
    min-height: 72px;
  }

  #flightForm .dialog-actions {
    bottom: -12px;
    margin: 12px -12px -12px;
    padding: 10px 12px 12px;
  }
}

@media print {
  .sidebar,
  .top-actions,
  dialog,
  .filters,
  .danger-link {
    display: none !important;
  }

  .app-shell {
    display: block;
  }

  .main {
    padding: 0;
  }

  .panel,
  .metric {
    box-shadow: none;
  }
}
