:root {
  color-scheme: light;
  --paper: #fbf8f1;
  --surface: #fffdf8;
  --surface-soft: #f7f3eb;
  --ink: #071d3b;
  --text: #172033;
  --muted: #6d7280;
  --line: #d9d5cc;
  --blue: #075bbd;
  --green: #339f48;
  --orange: #d86b1f;
  --purple: #8a3ba6;
  --shadow: 0 24px 60px rgba(20, 31, 50, 0.16);
}

* {
  box-sizing: border-box;
}

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

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

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

button,
a,
select,
input {
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible,
a:focus-visible,
select:focus-visible,
input:focus-visible,
textarea:focus-visible {
  outline: 3px solid rgba(7, 91, 189, 0.24);
  outline-offset: 3px;
}

h1,
h2,
p {
  margin: 0;
}

.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;
}

.hidden {
  display: none !important;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  width: min(100%, 760px);
  margin: 0 auto;
  padding: calc(34px + env(safe-area-inset-top)) 24px 18px;
}

.brand-block {
  display: flex;
  min-width: 0;
  gap: 14px;
}

.brand-rule {
  flex: 0 0 4px;
  align-self: stretch;
  min-height: 66px;
  background: var(--blue);
}

.brand-block h1 {
  color: var(--ink);
  font-family: "Songti SC", STSong, SimSun, serif;
  font-size: clamp(32px, 9.6vw, 44px);
  font-weight: 700;
  line-height: 1.08;
  letter-spacing: 0.015em;
  white-space: nowrap;
}

.brand-block p {
  margin-top: 12px;
  color: var(--muted);
  font-family: "Songti SC", STSong, SimSun, serif;
  font-size: 16px;
  letter-spacing: 0.08em;
}

.admin-actions {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  min-height: 44px;
}

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

.publish-button {
  min-height: 44px;
  padding: 0 4px;
  color: var(--ink);
  background: transparent;
  border: 0;
  border-bottom: 2px solid var(--blue);
  border-radius: 0;
  cursor: pointer;
  font-family: "Songti SC", STSong, SimSun, serif;
  font-size: 18px;
}

.home-link {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  color: var(--ink);
  text-decoration: none;
  font-family: "Songti SC", STSong, SimSun, serif;
  font-size: 16px;
  white-space: nowrap;
}

.home-link:hover {
  color: var(--blue);
}

.page-shell {
  width: min(100%, 760px);
  margin: 0 auto;
  padding: 10px 24px calc(64px + env(safe-area-inset-bottom));
}

.toolbar {
  margin-bottom: 14px;
}

.search-box {
  display: flex;
  align-items: center;
  min-height: 58px;
  padding: 0 18px;
  background: rgba(255, 255, 255, 0.42);
  border: 1px solid #cfccc5;
  border-radius: 12px;
}

.search-mark {
  display: none;
}

.search-box input {
  width: 100%;
  min-width: 0;
  color: var(--ink);
  background: transparent;
  border: 0;
  outline: 0;
  font-family: "Songti SC", STSong, SimSun, serif;
  font-size: 17px;
}

.search-box input::placeholder {
  color: #8d8e91;
}

.tabs {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin-top: 22px;
  border-bottom: 1px solid #c7c4bd;
}

.tab {
  position: relative;
  min-height: 52px;
  padding: 0 2px;
  color: #282b32;
  background: transparent;
  border: 0;
  cursor: pointer;
  font-family: "Songti SC", STSong, SimSun, serif;
  font-size: 18px;
}

.tab::after {
  position: absolute;
  right: 8px;
  bottom: -1px;
  left: 8px;
  height: 0;
  background: var(--blue);
  content: "";
  transition: height 160ms ease;
}

.tab.active {
  color: var(--blue);
  font-weight: 700;
}

.tab.active::after {
  height: 3px;
}

.archive-summary {
  display: flex;
  align-items: center;
  gap: 14px;
  min-height: 72px;
  color: #555b66;
  font-family: "Songti SC", STSong, SimSun, serif;
  font-size: 17px;
}

.month-select-label {
  position: relative;
}

.month-select-label select {
  min-height: 44px;
  padding: 0 30px 0 0;
  color: #1f2733;
  background: transparent;
  border: 0;
  cursor: pointer;
  font-family: "Songti SC", STSong, SimSun, serif;
  font-size: 22px;
  font-weight: 600;
}

.summary-divider,
.detail-divider {
  display: inline-block;
  width: 1px;
  background: #c9c5bc;
}

.summary-divider {
  height: 28px;
}

.report-list {
  position: relative;
}

.report-row {
  display: grid;
  grid-template-columns: 58px 14px minmax(0, 1fr) 44px;
  align-items: stretch;
  min-height: 136px;
}

.report-day {
  padding-top: 25px;
  color: var(--ink);
  text-align: left;
  font-family: "Songti SC", STSong, SimSun, serif;
}

.report-day span {
  display: block;
  font-size: 20px;
  line-height: 1;
  white-space: nowrap;
}

.report-day small {
  display: block;
  margin-top: 8px;
  color: #555d69;
  font-size: 13px;
}

.timeline-dot {
  position: relative;
  display: block;
}

.timeline-dot::before {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 6px;
  width: 1px;
  background: #d8d5cd;
  content: "";
}

.timeline-dot::after {
  position: absolute;
  top: 31px;
  left: 2px;
  width: 9px;
  height: 9px;
  background: var(--blue);
  border: 2px solid var(--paper);
  border-radius: 50%;
  content: "";
}

.report-row:first-child .timeline-dot::before {
  top: 31px;
}

.report-row:last-child .timeline-dot::before {
  bottom: calc(100% - 38px);
}

.report-content {
  position: relative;
  min-width: 0;
  padding: 22px 6px 20px 14px;
  border-bottom: 1px solid #d7d3ca;
}

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

.report-title {
  display: -webkit-box;
  overflow: hidden;
  color: var(--ink);
  text-decoration: none;
  font-family: "Songti SC", STSong, SimSun, serif;
  font-size: clamp(20px, 5.8vw, 27px);
  font-weight: 700;
  line-height: 1.32;
  letter-spacing: 0.01em;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.report-details {
  display: flex;
  align-items: center;
  gap: 11px;
  margin-top: 13px;
}

.report-date {
  color: #70737a;
  font-family: "Songti SC", STSong, SimSun, serif;
  font-size: 14px;
}

.detail-divider {
  height: 18px;
}

.badge {
  font-family: "Songti SC", STSong, SimSun, serif;
  font-size: 14px;
}

.badge.attendance { color: var(--green); }
.badge.enrollment { color: var(--orange); }
.badge.special { color: var(--purple); }
.badge.other { color: #6d42c5; }

.open-report {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  min-height: 44px;
  align-self: center;
  color: var(--blue);
  text-decoration: none;
  font-size: 14px;
  font-weight: 650;
}

.delete-report {
  margin-top: 10px;
  padding: 0;
  color: #b42318;
  background: transparent;
  border: 0;
  cursor: pointer;
  font-size: 13px;
}

.empty-state {
  margin-top: 12px;
  padding: 52px 18px;
  color: var(--muted);
  text-align: center;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

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

.ghost-button {
  min-height: 38px;
  padding: 0 10px;
  color: var(--text);
  background: transparent;
  border: 1px solid var(--line);
  font-size: 13px;
}

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

.primary-button:disabled {
  cursor: wait;
  opacity: 0.62;
}

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

dialog {
  max-height: calc(100dvh - 28px);
  padding: 0;
  color: var(--text);
  background: var(--surface);
  border: 0;
  border-radius: 14px;
  box-shadow: var(--shadow);
}

dialog::backdrop {
  background: rgba(7, 29, 59, 0.38);
  backdrop-filter: blur(2px);
}

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

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

.login-dialog form,
.publish-dialog form {
  max-height: calc(100dvh - 28px);
  padding: 24px;
  overflow-y: auto;
}

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

.dialog-head h2,
.viewer-head h2 {
  color: var(--ink);
  font-family: "Songti SC", STSong, SimSun, serif;
  font-size: 24px;
}

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

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

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

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

.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(--line);
  border-radius: 8px;
  outline: 0;
}

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

.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;
}

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

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

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

.report-topbar {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 16px;
  align-items: center;
  min-height: 82px;
  padding: calc(13px + env(safe-area-inset-top)) 20px 13px;
  background: var(--paper);
  border-bottom: 1px solid var(--line);
}

.report-topbar h1 {
  overflow: hidden;
  color: var(--ink);
  font-family: "Songti SC", STSong, SimSun, serif;
  font-size: 19px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.report-topbar p {
  margin-top: 5px;
  overflow: hidden;
  color: var(--muted);
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

.report-frame-shell {
  height: calc(100dvh - 82px - env(safe-area-inset-top));
  background: #fff;
}

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

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

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

@media (min-width: 700px) {
  .topbar {
    padding-top: 54px;
  }

  .brand-block h1 {
    font-size: 48px;
  }

  .page-shell {
    padding-bottom: 90px;
  }

  .report-row {
    grid-template-columns: 72px 18px minmax(0, 1fr) 60px;
  }

  .report-title {
    font-size: 27px;
  }
}

@media (max-width: 520px) {
  .topbar {
    padding-right: 18px;
    padding-left: 18px;
  }

  .page-shell {
    padding-right: 18px;
    padding-left: 18px;
  }

  .brand-rule {
    min-height: 58px;
  }

  .brand-block h1 {
    font-size: clamp(29px, 9.1vw, 38px);
  }

  .brand-block p {
    font-size: 14px;
  }

  .publish-button {
    font-size: 17px;
  }

  .home-link {
    font-size: 14px;
  }

  .admin-status,
  .admin-actions .ghost-button {
    display: none;
  }

  .report-row {
    grid-template-columns: 54px 13px minmax(0, 1fr) 38px;
  }

  .report-content {
    padding-left: 10px;
  }

  .report-title {
    font-size: clamp(19px, 5.8vw, 24px);
  }

  .open-report {
    font-size: 13px;
  }

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

  .publish-dialog {
    width: calc(100vw - 16px);
    max-height: calc(100dvh - 16px);
  }

  .publish-dialog form {
    max-height: calc(100dvh - 16px);
    padding: 20px;
  }
}

@media (max-width: 360px) {
  .brand-block {
    gap: 10px;
  }

  .brand-block h1 {
    font-size: 28px;
  }

  .brand-block p {
    font-size: 13px;
  }

  .tab {
    font-size: 16px;
  }

  .archive-summary {
    gap: 9px;
  }

  .month-select-label select {
    font-size: 19px;
  }

  .report-row {
    grid-template-columns: 50px 12px minmax(0, 1fr) 36px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}
