:root {
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --text: #172033;
  --muted: #6b7280;
  --line: #e5e7eb;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --danger-bg: #fef2f2;
  --danger: #b91c1c;
  --info-bg: #eff6ff;
  --info: #1d4ed8;
  --shadow: 0 18px 50px rgba(31, 41, 55, 0.08);
  --radius: 18px;
}

* {
  box-sizing: border-box;
}

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

button,
input {
  font: inherit;
}

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

.page-shell {
  width: min(1040px, calc(100% - 32px));
  margin: 0 auto;
  padding: 72px 0;
}

.hero {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 24px;
  margin-bottom: 26px;
}

.hero-branding {
  display: flex;
  align-items: center;
  gap: 20px;
}

.brand-mark {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: 112px;
  height: 112px;
  padding: 8px;
  border-radius: 24px;
  background: linear-gradient(180deg, #ffffff 0%, #f7fafc 100%);
  border: 1px solid rgba(229, 231, 235, 0.95);
  box-shadow: 0 18px 40px rgba(15, 23, 42, 0.08);
}

.brand-mark img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.hero-copy {
  min-width: 0;
}

.eyebrow {
  display: inline-block;
  margin-bottom: 10px;
  color: var(--primary);
  font-weight: 700;
  font-size: 0.82rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.hero h1 {
  margin: 0;
  max-width: 720px;
  font-size: clamp(2rem, 5vw, 3.4rem);
  line-height: 1.04;
  letter-spacing: -0.045em;
}

.hero p {
  margin: 14px 0 0;
  max-width: 680px;
  color: var(--muted);
  font-size: 1rem;
}

.panel {
  padding: 28px;
  background: var(--surface);
  border: 1px solid rgba(229, 231, 235, 0.9);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.search-panel {
  padding-bottom: 22px;
  border-bottom: 1px solid var(--line);
}

.search-main {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: end;
  gap: 12px;
}

.date-filters {
  display: grid;
  grid-template-columns: 140px 160px 170px 170px auto;
  align-items: end;
  gap: 10px;
  margin-top: 16px;
}

.compact-field select,
.compact-field input {
  width: 100%;
  height: 44px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 11px;
  outline: none;
  background: var(--surface-soft);
  color: var(--text);
}

.compact-field select:focus,
.compact-field input:focus {
  border-color: #93c5fd;
  box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.1);
  background: #fff;
}

.secondary-button {
  height: 44px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: #fff;
  color: var(--text);
  font-weight: 700;
  cursor: pointer;
}

.secondary-button:hover {
  background: var(--surface-soft);
}

.filter-hint {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 0.8rem;
}

.field label {
  display: block;
  margin-bottom: 8px;
  font-size: 0.88rem;
  font-weight: 600;
}

.input-wrap {
  position: relative;
}

.input-wrap svg {
  position: absolute;
  left: 14px;
  top: 50%;
  width: 20px;
  height: 20px;
  transform: translateY(-50%);
  fill: none;
  stroke: #94a3b8;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  pointer-events: none;
}

.input-wrap input {
  width: 100%;
  height: 48px;
  padding: 0 16px 0 44px;
  border: 1px solid var(--line);
  border-radius: 12px;
  outline: none;
  background: var(--surface-soft);
  color: var(--text);
  transition: border-color .2s ease, box-shadow .2s ease, background .2s ease;
}

.input-wrap input:focus {
  border-color: #93c5fd;
  box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.1);
  background: #fff;
}

.primary-button,
.download-button,
.preview-button {
  border: 0;
  border-radius: 12px;
  background: var(--primary);
  color: #fff;
  font-weight: 700;
  cursor: pointer;
  transition: background .2s ease, transform .2s ease;
}

.primary-button {
  height: 48px;
  padding: 0 22px;
}

.primary-button:hover,
.download-button:hover {
  background: var(--primary-hover);
}

.preview-button {
  border: 1px solid #bfdbfe;
  background: #eff6ff;
  color: var(--primary);
}

.preview-button:hover {
  background: #dbeafe;
}

.primary-button:active,
.download-button:active,
.preview-button:active {
  transform: translateY(1px);
}

.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 24px 0 14px;
}

.toolbar strong {
  display: block;
  font-size: 1rem;
}

.toolbar span {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.86rem;
}

.text-button {
  border: 0;
  background: transparent;
  color: var(--primary);
  font-weight: 700;
  cursor: pointer;
}

.feedback {
  margin: 8px 0 14px;
  padding: 14px 16px;
  border-radius: 12px;
  font-size: 0.9rem;
}

.feedback.info {
  color: var(--info);
  background: var(--info-bg);
}

.feedback.error {
  color: var(--danger);
  background: var(--danger-bg);
}

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

.document-card {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 16px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fff;
  transition: transform .2s ease, box-shadow .2s ease, border-color .2s ease;
}

.document-card:hover {
  transform: translateY(-1px);
  border-color: #dbe3ee;
  box-shadow: 0 12px 30px rgba(15, 23, 42, 0.06);
}

.document-icon {
  display: grid;
  width: 46px;
  height: 46px;
  place-items: center;
  border-radius: 12px;
  background: #eff6ff;
  color: var(--primary);
}

.document-icon svg {
  width: 23px;
  height: 23px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.document-info {
  min-width: 0;
}

.document-name {
  margin: 0;
  overflow: hidden;
  font-size: 0.98rem;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.document-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 7px;
  color: var(--muted);
  font-size: 0.82rem;
}

.dot {
  color: #cbd5e1;
}

.document-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.download-button,
.preview-button {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  padding: 0 14px;
  text-decoration: none;
  font-size: 0.88rem;
}

.download-button svg,
.preview-button svg {
  width: 17px;
  height: 17px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.empty-state {
  padding: 46px 18px;
  border: 1px dashed #d8dee8;
  border-radius: 14px;
  background: var(--surface-soft);
  text-align: center;
}

.empty-state strong {
  display: block;
  margin-bottom: 6px;
}

.empty-state p {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.skeleton {
  height: 78px;
  border-radius: 14px;
  background: linear-gradient(90deg, #f1f5f9 25%, #e8edf3 37%, #f1f5f9 63%);
  background-size: 400% 100%;
  animation: shimmer 1.25s infinite;
}

@keyframes shimmer {
  0% { background-position: 100% 0; }
  100% { background-position: 0 0; }
}

@media (max-width: 700px) {
  .page-shell {
    width: min(100% - 20px, 1040px);
    padding: 34px 0;
  }

  .panel {
    padding: 18px;
  }

  .search-main {
    grid-template-columns: 1fr;
  }

  .date-filters {
    grid-template-columns: 1fr 1fr;
  }

  .filter-clear {
    grid-column: 1 / -1;
  }

  .primary-button {
    width: 100%;
  }

  .document-card {
    grid-template-columns: auto 1fr;
  }

  .document-actions {
    grid-column: 1 / -1;
    width: 100%;
  }

  .download-button,
  .preview-button {
    flex: 1;
    justify-content: center;
  }
}

.login-panel {
  max-width: 640px;
  margin: 0 auto;
}

.login-copy {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 16px;
  align-items: center;
  margin-bottom: 24px;
}

.login-copy .eyebrow {
  margin-bottom: 6px;
}

.login-copy h2 {
  margin: 0;
  font-size: 1.35rem;
  letter-spacing: -0.025em;
}

.login-copy p {
  margin: 7px 0 0;
  color: var(--muted);
  font-size: 0.92rem;
}

.lock-icon {
  display: grid;
  width: 50px;
  height: 50px;
  place-items: center;
  border-radius: 14px;
  color: var(--primary);
  background: var(--info-bg);
}

.lock-icon svg {
  width: 24px;
  height: 24px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.login-form {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: end;
  gap: 12px;
}

.login-form input {
  width: 100%;
  height: 48px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  outline: none;
  background: var(--surface-soft);
}

.login-form input:focus {
  border-color: #93c5fd;
  box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.1);
  background: #fff;
}

.logout-button {
  padding: 10px 0;
}

.primary-button:disabled,
.download-button:disabled,
.preview-button:disabled {
  cursor: wait;
  opacity: .65;
}

[hidden] {
  display: none !important;
}

@media (max-width: 700px) {
  .hero {
    align-items: flex-start;
  }

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

  .brand-mark {
    width: 88px;
    height: 88px;
    border-radius: 20px;
  }

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

  .login-form .primary-button {
    width: 100%;
  }
}


body.modal-open {
  overflow: hidden;
}

.preview-modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  padding: 24px;
}

.preview-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.68);
  backdrop-filter: blur(4px);
}

.preview-dialog {
  position: relative;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  width: min(1100px, 96vw);
  height: min(860px, 92vh);
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 18px;
  background: #fff;
  box-shadow: 0 30px 80px rgba(15, 23, 42, 0.35);
}

.preview-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--line);
}

.preview-header .eyebrow {
  margin-bottom: 4px;
}

.preview-header h2 {
  max-width: min(760px, 70vw);
  margin: 0;
  overflow: hidden;
  font-size: 1rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.preview-close {
  display: grid;
  width: 40px;
  height: 40px;
  flex: 0 0 auto;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  color: var(--text);
  cursor: pointer;
}

.preview-close:hover {
  background: var(--surface-soft);
}

.preview-close svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
}

.preview-body {
  position: relative;
  min-height: 0;
  background: #e5e7eb;
}

.preview-frame,
#previewFrame {
  width: 100%;
  height: 100%;
  border: 0;
  background: #fff;
}

.preview-loading {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 0.92rem;
}

.preview-footer {
  display: flex;
  justify-content: flex-end;
  padding: 12px 18px;
  border-top: 1px solid var(--line);
  background: #fff;
}

@media (max-width: 700px) {
  .preview-modal {
    padding: 0;
  }

  .preview-dialog {
    width: 100vw;
    height: 100dvh;
    border: 0;
    border-radius: 0;
  }

  .preview-header {
    padding: 14px;
  }

  .preview-footer {
    padding: 10px 14px calc(10px + env(safe-area-inset-bottom));
  }

  .preview-footer .download-button {
    width: 100%;
    justify-content: center;
  }
}

.grade-tabs {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 16px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.72);
  box-shadow: 0 10px 28px rgba(15, 23, 42, 0.04);
}

.grade-tab {
  min-height: 48px;
  padding: 0 18px;
  border: 0;
  border-radius: 11px;
  background: transparent;
  color: var(--muted);
  font-weight: 700;
  cursor: pointer;
  transition: background .2s ease, color .2s ease, box-shadow .2s ease;
}

.grade-tab:hover {
  color: var(--text);
  background: #f8fafc;
}

.grade-tab.active {
  color: #fff;
  background: var(--primary);
  box-shadow: 0 8px 22px rgba(37, 99, 235, 0.2);
}

.area-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding-bottom: 20px;
}

.area-heading .eyebrow {
  margin-bottom: 5px;
}

.area-heading h2 {
  margin: 0;
  font-size: 1.35rem;
  letter-spacing: -0.025em;
}

@media (max-width: 700px) {
  .grade-tabs {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 900px) and (min-width: 701px) {
  .date-filters {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .filter-clear {
    justify-self: start;
  }
}


/* Sanity-first date filters */
.date-filter-card {
  margin-top: 18px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: linear-gradient(180deg, #fbfdff 0%, #f8fafc 100%);
}

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

.date-filter-title {
  display: flex;
  align-items: center;
  gap: 11px;
  min-width: 0;
}

.calendar-badge {
  display: grid;
  width: 38px;
  height: 38px;
  flex: 0 0 auto;
  place-items: center;
  border-radius: 11px;
  background: #eff6ff;
  color: var(--primary);
}

.calendar-badge svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.date-filter-title strong,
.date-filter-title span {
  display: block;
}

.date-filter-title strong {
  font-size: .9rem;
}

.date-filter-title > div > span {
  margin-top: 3px;
  color: var(--muted);
  font-size: .8rem;
}

.filter-reset {
  min-height: 36px;
  padding: 0 12px;
  border: 1px solid #bfdbfe;
  border-radius: 10px;
  background: #eff6ff;
  color: var(--primary);
  font-weight: 700;
  font-size: .82rem;
  cursor: pointer;
}

.filter-reset:hover {
  background: #dbeafe;
}

.date-pickers {
  display: grid;
  grid-template-columns: minmax(110px, .7fr) minmax(190px, 1.3fr) minmax(130px, .8fr);
  gap: 10px;
}

.date-select-control {
  display: block;
  min-width: 0;
}

.date-select-control > span {
  display: block;
  margin: 0 0 6px 2px;
  color: var(--muted);
  font-size: .74rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .045em;
}

.date-select-control select,
.date-select-control input {
  width: 100%;
  height: 44px;
  padding: 0 38px 0 12px;
  border: 1px solid var(--line);
  border-radius: 11px;
  outline: none;
  background-color: #fff;
  color: var(--text);
  font: inherit;
  font-weight: 600;
  transition: border-color .2s ease, box-shadow .2s ease;
}

.date-select-control select {
  appearance: none;
  background-image:
    linear-gradient(45deg, transparent 50%, #64748b 50%),
    linear-gradient(135deg, #64748b 50%, transparent 50%);
  background-position:
    calc(100% - 17px) 19px,
    calc(100% - 12px) 19px;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}

.date-select-control input {
  padding-right: 12px;
}

.date-select-control select:focus,
.date-select-control input:focus {
  border-color: #93c5fd;
  box-shadow: 0 0 0 4px rgba(37, 99, 235, .1);
}

.period-filter {
  margin-top: 12px;
  border-top: 1px solid var(--line);
  padding-top: 10px;
}

.period-filter summary {
  width: fit-content;
  color: var(--primary);
  font-size: .82rem;
  font-weight: 700;
  cursor: pointer;
  list-style: none;
}

.period-filter summary::-webkit-details-marker { display: none; }
.period-filter summary::before { content: "+"; margin-right: 7px; }
.period-filter[open] summary::before { content: "−"; }

.period-fields {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: end;
  gap: 12px;
  max-width: 560px;
  margin-top: 12px;
}

.period-arrow {
  display: grid;
  height: 44px;
  place-items: center;
  color: var(--muted);
}

@media (max-width: 700px) {
  .date-filter-card { padding: 14px; }
  .date-pickers { grid-template-columns: 1fr 1fr; }
  .month-control { grid-column: 1 / -1; grid-row: 1; }
  .period-fields { grid-template-columns: 1fr; }
  .period-arrow { display: none; }
}
