:root {
  --ink: #17202a;
  --muted: #657184;
  --soft: #8d98a8;
  --line: #e3e8ef;
  --line-strong: #d3dae4;
  --surface: #ffffff;
  --surface-soft: #f6f8fb;
  --background: #f1f4f8;
  --primary: #2956d7;
  --primary-hover: #1f47ba;
  --primary-soft: #edf2ff;
  --success: #177548;
  --success-soft: #eaf8f0;
  --warning: #8a5b12;
  --warning-soft: #fff7e8;
  --danger: #b32d35;
  --danger-soft: #fff0f1;
  --shadow-sm: 0 1px 2px rgba(18, 32, 51, 0.05);
  --shadow-md: 0 12px 32px rgba(18, 32, 51, 0.08);
  --radius-sm: 9px;
  --radius-md: 14px;
  --radius-lg: 20px;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: var(--background);
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 15% -10%, rgba(104, 139, 235, 0.12), transparent 35%),
    var(--background);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans KR", sans-serif;
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

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

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

a {
  color: inherit;
}

.skip-link {
  position: fixed;
  z-index: 1000;
  top: 10px;
  left: 10px;
  padding: 10px 14px;
  border-radius: 8px;
  color: #fff;
  background: var(--ink);
  transform: translateY(-150%);
}

.skip-link:focus {
  transform: translateY(0);
}

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

.site-header {
  position: sticky;
  z-index: 100;
  top: 0;
  border-bottom: 1px solid rgba(218, 225, 235, 0.9);
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(14px);
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: min(1120px, calc(100% - 40px));
  min-height: 70px;
  margin: 0 auto;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 11px;
  color: var(--ink);
  text-decoration: none;
}

.brand-mark {
  display: grid;
  width: 36px;
  height: 36px;
  place-items: center;
  border-radius: 10px;
  color: #fff;
  background: var(--primary);
  box-shadow: 0 6px 14px rgba(41, 86, 215, 0.24);
  font-size: 16px;
  font-weight: 800;
}

.brand strong,
.brand small {
  display: block;
  line-height: 1.25;
}

.brand strong {
  font-size: 15px;
  letter-spacing: -0.02em;
}

.brand small {
  margin-top: 3px;
  color: var(--soft);
  font-size: 11px;
}

.main-nav {
  display: flex;
  align-items: center;
  gap: 4px;
}

.main-nav a {
  padding: 9px 14px;
  border-radius: 9px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 650;
  text-decoration: none;
  transition: color 140ms ease, background 140ms ease;
}

.main-nav a:hover {
  color: var(--ink);
  background: var(--surface-soft);
}

.main-nav a.active {
  color: var(--primary);
  background: var(--primary-soft);
}

.page-shell {
  width: min(1080px, calc(100% - 40px));
  min-height: calc(100vh - 138px);
  margin: 0 auto;
  padding: 54px 0 64px;
}

.site-footer {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 68px;
  padding: 16px 20px;
  border-top: 1px solid var(--line);
  color: var(--soft);
  background: rgba(255, 255, 255, 0.55);
  font-size: 12px;
  text-align: center;
}

.message-stack {
  position: fixed;
  z-index: 200;
  top: 84px;
  right: 24px;
  display: grid;
  gap: 8px;
  width: min(390px, calc(100% - 48px));
}

.message {
  padding: 13px 16px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--surface);
  box-shadow: var(--shadow-md);
  font-size: 13px;
  font-weight: 600;
}

.message-success {
  border-color: #bfe6d0;
  color: var(--success);
  background: var(--success-soft);
}

.message-info {
  border-color: #cad7fb;
  color: var(--primary-hover);
  background: var(--primary-soft);
}

.button {
  display: inline-flex;
  min-height: 42px;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 9px 17px;
  border: 1px solid transparent;
  border-radius: 10px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 700;
  line-height: 1.2;
  text-decoration: none;
  transition: border-color 140ms ease, background 140ms ease, box-shadow 140ms ease, transform 100ms ease;
}

.button:hover {
  transform: translateY(-1px);
}

.button:active {
  transform: translateY(0);
}

.button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
.document-card:focus-visible,
.file-dropzone:focus-within {
  outline: 3px solid rgba(41, 86, 215, 0.22);
  outline-offset: 2px;
}

.button:disabled {
  cursor: wait;
  opacity: 0.66;
  transform: none;
}

.button-primary {
  color: #fff;
  background: var(--primary);
  box-shadow: 0 6px 14px rgba(41, 86, 215, 0.18);
}

.button-primary:hover {
  background: var(--primary-hover);
  box-shadow: 0 9px 20px rgba(41, 86, 215, 0.22);
}

.button-secondary {
  border-color: var(--line-strong);
  color: #3c4859;
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}

.button-secondary:hover {
  border-color: #b9c3d0;
  background: var(--surface-soft);
}

.button-large {
  width: 100%;
  min-height: 52px;
  border-radius: 11px;
  font-size: 15px;
}

.text-button {
  padding: 0;
  border: 0;
  color: var(--primary);
  background: none;
  cursor: pointer;
  font-weight: 700;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--primary);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.12em;
}

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

.page-heading h1,
.form-intro h1 {
  margin: 0;
  color: #111a25;
  font-size: clamp(28px, 4vw, 38px);
  font-weight: 760;
  letter-spacing: -0.045em;
  line-height: 1.2;
}

.page-heading p:not(.eyebrow),
.form-intro > p:not(.eyebrow) {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 15px;
}

.library-panel {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}

.search-toolbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 150px;
  gap: 10px;
  padding: 20px;
  border-bottom: 1px solid var(--line);
}

.search-field {
  position: relative;
  display: block;
}

.search-icon {
  position: absolute;
  top: 50%;
  left: 16px;
  width: 14px;
  height: 14px;
  border: 2px solid #8793a4;
  border-radius: 50%;
  transform: translateY(-58%);
  pointer-events: none;
}

.search-icon::after {
  position: absolute;
  right: -5px;
  bottom: -4px;
  width: 6px;
  height: 2px;
  border-radius: 2px;
  background: #8793a4;
  content: "";
  transform: rotate(45deg);
}

.search-field input,
.sort-field select,
.field-group input[type="text"],
.field-group textarea {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  color: var(--ink);
  background: var(--surface);
  outline: none;
  transition: border-color 140ms ease, box-shadow 140ms ease;
}

.search-field input,
.sort-field select {
  height: 46px;
}

.search-field input {
  padding: 0 16px 0 43px;
}

.sort-field select {
  padding: 0 36px 0 14px;
  cursor: pointer;
}

.search-field input:focus,
.sort-field select:focus,
.field-group input[type="text"]:focus,
.field-group textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(41, 86, 215, 0.09);
}

.result-summary {
  display: flex;
  min-height: 46px;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 22px;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  background: #fbfcfe;
  font-size: 12px;
}

#result-count {
  color: #475366;
  font-weight: 700;
}

.document-list {
  display: grid;
}

.document-card {
  display: flex;
  min-width: 0;
  align-items: center;
  justify-content: space-between;
  gap: 22px;
  padding: 24px 25px;
  border-bottom: 1px solid var(--line);
  color: inherit;
  text-decoration: none;
  transition: background 140ms ease;
}

.document-card:hover {
  background: #f8faff;
}

.document-card:hover .card-arrow {
  color: var(--primary);
  transform: translateX(3px);
}

.document-card-content {
  min-width: 0;
}

.document-card h3 {
  overflow: hidden;
  margin: 0;
  font-size: 17px;
  font-weight: 720;
  letter-spacing: -0.025em;
  line-height: 1.35;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.document-card-content > p {
  display: -webkit-box;
  overflow: hidden;
  max-width: 760px;
  margin: 7px 0 13px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.55;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.document-card-meta,
.document-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 7px;
  color: var(--soft);
  font-size: 11px;
}

.document-card-meta strong,
.document-meta strong {
  color: #596578;
  font-weight: 700;
}

.publisher-avatar {
  display: inline-grid;
  flex: 0 0 auto;
  width: 28px;
  height: 28px;
  place-items: center;
  border-radius: 50%;
  color: var(--primary);
  background: var(--primary-soft);
  font-size: 12px;
  font-weight: 800;
}

.publisher-avatar-small {
  width: 22px;
  height: 22px;
  font-size: 10px;
}

.card-arrow {
  flex: 0 0 auto;
  color: #a8b1be;
  font-size: 20px;
  transition: color 140ms ease, transform 140ms ease;
}

.loading-card {
  position: relative;
  overflow: hidden;
  height: 124px;
  border-bottom: 1px solid var(--line);
  background:
    linear-gradient(#e9edf3 0 0) 24px 25px / 40% 18px no-repeat,
    linear-gradient(#f0f3f7 0 0) 24px 54px / 72% 12px no-repeat,
    linear-gradient(#f0f3f7 0 0) 24px 76px / 50% 12px no-repeat;
}

.loading-card::after {
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.72), transparent);
  content: "";
  animation: shimmer 1.3s infinite;
  transform: translateX(-100%);
}

@keyframes shimmer {
  100% { transform: translateX(100%); }
}

.empty-state,
.inline-error {
  padding: 56px 24px;
  text-align: center;
}

.empty-state strong,
.inline-error strong {
  display: block;
  margin-bottom: 5px;
  font-size: 16px;
}

.empty-state p {
  margin: 0 0 18px;
  color: var(--muted);
  font-size: 13px;
}

.inline-error {
  color: var(--danger);
  background: var(--danger-soft);
}

.load-more-wrap {
  padding: 18px;
  text-align: center;
}

.load-more-wrap:empty {
  display: none;
}

.mobile-action {
  display: none;
}

.form-layout {
  display: grid;
  grid-template-columns: minmax(260px, 0.75fr) minmax(500px, 1.25fr);
  gap: 58px;
  align-items: start;
}

.form-intro {
  position: sticky;
  top: 120px;
  padding: 18px 0;
}

.back-link {
  display: inline-flex;
  align-items: center;
  margin-bottom: 30px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
  text-decoration: none;
}

.back-link::before {
  margin-right: 7px;
  content: "←";
}

.back-link:hover {
  color: var(--primary);
}

.notice-card {
  display: grid;
  gap: 3px;
  margin-top: 30px;
  padding: 17px 18px;
  border: 1px solid #d8e1fa;
  border-radius: 12px;
  color: #596578;
  background: var(--primary-soft);
  font-size: 12px;
}

.notice-card strong {
  margin-bottom: 3px;
  color: var(--primary-hover);
}

.upload-form {
  padding: 34px;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow-md);
}

.field-group {
  margin-bottom: 25px;
}

.field-group > label:first-child {
  display: block;
  margin-bottom: 8px;
  color: #2a3544;
  font-size: 13px;
  font-weight: 720;
}

.field-group > label:first-child span {
  margin-left: 4px;
  color: var(--primary);
  font-size: 10px;
}

.field-group input[type="text"],
.field-group textarea {
  padding: 12px 13px;
}

.field-group input[type="text"] {
  height: 46px;
}

.field-group textarea {
  min-height: 130px;
  resize: vertical;
  line-height: 1.55;
}

.field-group.has-error input,
.field-group.has-error textarea,
.field-group.has-error .file-dropzone {
  border-color: #e3989d;
}

.field-help,
.field-error,
.field-meta {
  margin: 7px 1px 0;
  font-size: 11px;
}

.field-help {
  color: var(--soft);
}

.field-error {
  color: var(--danger);
  font-weight: 650;
}

.field-meta {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: var(--soft);
}

.field-meta .field-help {
  margin: 0;
}

.form-error-summary {
  margin-bottom: 20px;
  padding: 13px 15px;
  border: 1px solid #f0c3c6;
  border-radius: 10px;
  color: var(--danger);
  background: var(--danger-soft);
  font-size: 12px;
}

.file-dropzone {
  display: flex !important;
  min-height: 176px;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 25px;
  border: 1.5px dashed #bdc7d4;
  border-radius: 13px;
  cursor: pointer;
  background: #fafbfd;
  text-align: center;
  transition: border-color 140ms ease, background 140ms ease;
}

.file-dropzone:hover,
.file-dropzone.dragover {
  border-color: var(--primary);
  background: var(--primary-soft);
}

.file-dropzone.has-file {
  border-style: solid;
  border-color: #91bca7;
  background: var(--success-soft);
}

.file-dropzone input[type="file"] {
  position: absolute;
  overflow: hidden;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.file-badge {
  display: inline-grid;
  width: 48px;
  height: 48px;
  place-items: center;
  margin-bottom: 3px;
  border-radius: 12px;
  color: var(--primary);
  background: #e4ebff;
  font-size: 10px;
  font-weight: 850;
  letter-spacing: 0.04em;
}

.file-dropzone.has-file .file-badge {
  color: var(--success);
  background: #d7f1e2;
}

.file-dropzone strong {
  max-width: 100%;
  overflow: hidden;
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-dropzone > span:last-of-type {
  color: var(--soft);
  font-size: 11px;
}

.viewer-page {
  width: min(1440px, calc(100% - 32px));
  padding-top: 30px;
}

.document-viewer {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow-md);
}

.viewer-header {
  padding: 26px 28px 24px;
  border-bottom: 1px solid var(--line);
}

.viewer-heading-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 28px;
}

.viewer-header .back-link {
  margin-bottom: 14px;
}

.viewer-header h1 {
  margin: 0 0 12px;
  font-size: clamp(24px, 3vw, 32px);
  font-weight: 760;
  letter-spacing: -0.04em;
  line-height: 1.28;
}

.document-meta {
  font-size: 12px;
}

.viewer-actions {
  display: flex;
  flex: 0 0 auto;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 7px;
}

.document-description {
  max-width: 900px;
  margin: 22px 0 0;
  padding-top: 20px;
  border-top: 1px solid var(--line);
  color: #4f5b6d;
  font-size: 13px;
  line-height: 1.75;
}

.html-frame-wrap {
  position: relative;
  min-height: 680px;
  background: #fff;
}

.html-frame-wrap iframe {
  display: block;
  width: 100%;
  height: min(76vh, 980px);
  min-height: 680px;
  border: 0;
  background: #fff;
}

.frame-loading {
  position: absolute;
  z-index: 1;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  color: var(--muted);
  background: #fff;
  font-size: 13px;
}

.frame-loading[hidden] {
  display: none;
}

.spinner {
  width: 18px;
  height: 18px;
  border: 2px solid #dde3ec;
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 700ms linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.error-page {
  max-width: 560px;
  margin: 60px auto;
  padding: 58px 40px;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow-md);
  text-align: center;
}

.error-page > span {
  display: inline-block;
  margin-bottom: 15px;
  padding: 5px 10px;
  border-radius: 7px;
  color: var(--primary);
  background: var(--primary-soft);
  font-size: 11px;
  font-weight: 800;
}

.error-page h1 {
  margin: 0;
  font-size: 25px;
  letter-spacing: -0.035em;
}

.error-page p {
  margin: 13px 0 25px;
  color: var(--muted);
  font-size: 13px;
}

@media (max-width: 900px) {
  .form-layout {
    grid-template-columns: 1fr;
    gap: 24px;
  }

  .form-intro {
    position: static;
    padding: 0;
  }

  .form-intro .back-link {
    margin-bottom: 22px;
  }

  .notice-card {
    margin-top: 20px;
  }

  .viewer-heading-row {
    display: block;
  }

  .viewer-actions {
    justify-content: flex-start;
    margin-top: 22px;
  }
}

@media (max-width: 680px) {
  .header-inner {
    width: min(100% - 24px, 1120px);
    min-height: 62px;
  }

  .brand small {
    display: none;
  }

  .brand-mark {
    width: 32px;
    height: 32px;
    border-radius: 9px;
  }

  .main-nav a {
    padding: 8px 9px;
    font-size: 12px;
  }

  .page-shell {
    width: min(100% - 24px, 1080px);
    padding: 35px 0 48px;
  }

  .page-heading {
    margin-bottom: 20px;
  }

  .page-heading h1,
  .form-intro h1 {
    font-size: 28px;
  }

  .desktop-action {
    display: none;
  }

  .mobile-action {
    display: flex;
    position: sticky;
    bottom: 14px;
    z-index: 50;
    width: calc(100% - 28px);
    margin: 18px auto 0;
    box-shadow: 0 12px 30px rgba(41, 86, 215, 0.28);
  }

  .library-panel {
    border-radius: 15px;
  }

  .search-toolbar {
    grid-template-columns: 1fr;
    padding: 14px;
  }

  .sort-field select {
    width: 100%;
  }

  .result-summary {
    align-items: flex-start;
    flex-direction: column;
    gap: 2px;
    padding: 10px 16px;
  }

  .document-card {
    gap: 10px;
    padding: 19px 17px;
  }

  .document-card h3 {
    font-size: 15px;
  }

  .document-card-content > p {
    font-size: 12px;
  }

  .document-card-meta {
    gap: 5px;
  }

  .card-arrow {
    font-size: 17px;
  }

  .upload-form {
    padding: 23px 18px;
    border-radius: 15px;
  }

  .field-meta {
    display: block;
  }

  #description-count {
    display: block;
    margin-top: 3px;
    text-align: right;
  }

  .viewer-page {
    width: 100%;
    padding: 0;
  }

  .document-viewer {
    border-right: 0;
    border-left: 0;
    border-radius: 0;
  }

  .viewer-header {
    padding: 22px 18px;
  }

  .viewer-header h1 {
    font-size: 24px;
  }

  .viewer-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .viewer-actions .button:last-child {
    grid-column: 1 / -1;
  }

  .html-frame-wrap,
  .html-frame-wrap iframe {
    min-height: 70vh;
  }

  .message-stack {
    top: 72px;
    right: 12px;
    width: calc(100% - 24px);
  }

  .error-page {
    margin: 20px auto;
    padding: 40px 22px;
  }
}

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