:root {
  color-scheme: light;
  --bg: #f6f8fb;
  --surface: #ffffff;
  --surface-soft: #f9fbfd;
  --border: #dce4ee;
  --border-strong: #c8d4e3;
  --text: #162033;
  --muted: #66758a;
  --blue: #2563eb;
  --blue-soft: #eaf1ff;
  --green-soft: #e9f8ef;
  --green: #168348;
  --orange-soft: #fff3e3;
  --orange: #b35a00;
  --purple-soft: #f2edff;
  --purple: #6d42c5;
  --shadow: 0 18px 48px rgba(22, 32, 51, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 15px;
}

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

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 34px max(32px, calc((100vw - 1120px) / 2)) 26px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 28px;
  font-weight: 750;
}

.topbar p,
.section-head p,
.dialog-head p,
.viewer-head p {
  margin-top: 8px;
  color: var(--muted);
}

.admin-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.admin-status {
  color: var(--muted);
  font-size: 14px;
}

.hidden {
  display: none;
}

.page-shell {
  width: min(1120px, calc(100vw - 48px));
  margin: 28px auto 56px;
}

.toolbar {
  display: grid;
  grid-template-columns: minmax(280px, 1fr) auto;
  gap: 16px;
  align-items: center;
  margin-bottom: 28px;
}

.search-box {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 46px;
  padding: 0 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
}

.search-box span {
  color: var(--muted);
}

.search-box input {
  width: 100%;
  border: 0;
  outline: 0;
  color: var(--text);
  background: transparent;
}

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

.tab,
.ghost-button,
.primary-button,
.icon-button {
  border: 0;
  border-radius: 8px;
  cursor: pointer;
}

.tab {
  min-height: 38px;
  padding: 0 14px;
  color: var(--muted);
  background: transparent;
}

.tab.active {
  color: var(--blue);
  background: var(--blue-soft);
  font-weight: 650;
}

.primary-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  padding: 0 18px;
  color: #fff;
  background: var(--blue);
  font-weight: 650;
}

.tool-link {
  text-decoration: none;
}

.ghost-button {
  min-height: 38px;
  padding: 0 14px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
}

.icon-button {
  width: 36px;
  height: 36px;
  color: var(--muted);
  background: transparent;
  font-size: 24px;
  line-height: 1;
}

.section-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}

.section-head h2,
.archive h2,
.dialog-head h2,
.viewer-head h2 {
  font-size: 20px;
  font-weight: 720;
}

.report-list {
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
}

.report-row {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) 120px 128px 88px;
  gap: 16px;
  align-items: center;
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
}

.report-row:last-child {
  border-bottom: 0;
}

.report-title {
  display: block;
  margin-bottom: 6px;
  color: var(--text);
  font-size: 16px;
  font-weight: 680;
}

.report-meta,
.report-date {
  color: var(--muted);
}

.badge {
  justify-self: start;
  padding: 5px 10px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 650;
}

.badge.attendance {
  color: var(--green);
  background: var(--green-soft);
}

.badge.enrollment {
  color: var(--orange);
  background: var(--orange-soft);
}

.badge.monthly {
  color: var(--blue);
  background: var(--blue-soft);
}

.badge.other {
  color: var(--purple);
  background: var(--purple-soft);
}

.open-report {
  text-decoration: none;
  color: var(--blue);
  background: transparent;
  border: 0;
  cursor: pointer;
  font-weight: 650;
}

.row-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  justify-content: flex-end;
  flex-wrap: wrap;
}

.delete-report {
  color: #b42318;
  background: transparent;
  border: 0;
  cursor: pointer;
  font-weight: 650;
}

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

.archive {
  margin-top: 30px;
}

.archive-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 14px;
}

.archive-chip {
  padding: 8px 13px;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
}

dialog {
  border: 0;
  border-radius: 12px;
  box-shadow: var(--shadow);
}

dialog::backdrop {
  background: rgba(22, 32, 51, 0.34);
}

.login-dialog {
  width: min(430px, calc(100vw - 40px));
  padding: 0;
}

.login-dialog form {
  padding: 24px;
}

.publish-dialog {
  width: min(860px, calc(100vw - 40px));
  padding: 0;
}

.publish-dialog form {
  padding: 24px;
}

.dialog-head,
.viewer-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 170px 180px;
  gap: 14px;
  margin-top: 22px;
}

label {
  color: var(--text);
  font-weight: 650;
}

.login-fields {
  display: grid;
  gap: 14px;
  margin-top: 22px;
}

.form-grid input,
.form-grid select,
.login-fields input,
.source-field input,
.html-field textarea {
  display: block;
  width: 100%;
  margin-top: 8px;
  color: var(--text);
  background: var(--surface-soft);
  border: 1px solid var(--border);
  border-radius: 8px;
  outline: 0;
}

.form-grid input,
.form-grid select,
.login-fields input,
.source-field input {
  height: 42px;
  padding: 0 12px;
}

.form-error {
  min-height: 20px;
  margin-top: 12px;
  color: #b42318;
  font-size: 14px;
}

.source-field,
.html-field {
  display: block;
  margin-top: 18px;
}

.html-field textarea {
  min-height: 260px;
  padding: 12px;
  resize: vertical;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
  line-height: 1.5;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 18px;
}

.viewer-dialog {
  width: min(1180px, calc(100vw - 32px));
  height: min(860px, calc(100vh - 32px));
  padding: 0;
}

.viewer-head {
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
}

#reportFrame {
  width: 100%;
  height: calc(100% - 82px);
  border: 0;
  background: #fff;
}

.report-page {
  height: 100vh;
  overflow: hidden;
  background: var(--surface);
}

.report-topbar {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 18px;
  align-items: center;
  min-height: 86px;
  padding: 16px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.report-topbar h1 {
  font-size: 20px;
}

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

.back-link,
.primary-link {
  color: var(--blue);
  text-decoration: none;
  font-weight: 650;
}

.report-frame-shell {
  height: calc(100vh - 86px);
  background: #fff;
}

.report-frame-shell #reportFrame {
  width: 100%;
  height: 100%;
  border: 0;
}

.report-missing {
  max-width: 520px;
  margin: 80px auto;
  padding: 24px;
  text-align: center;
}

.report-missing p {
  margin: 10px 0 18px;
  color: var(--muted);
}

@media (max-width: 820px) {
  .topbar,
  .section-head,
  .dialog-head,
  .viewer-head {
    align-items: stretch;
    flex-direction: column;
  }

  .admin-actions {
    justify-content: flex-start;
  }

  .toolbar,
  .form-grid,
  .report-row {
    grid-template-columns: 1fr;
  }

  .report-row {
    gap: 8px;
  }

  .report-topbar {
    grid-template-columns: 1fr;
  }

  .page-shell {
    width: min(100% - 28px, 1120px);
  }
}
