:root {
  color-scheme: light;
  --paper: #F6F1E7;
  --paper-2: #EFE8DA;
  --sheet: #FFFDF8;
  --ink: #2B2620;
  --ink-2: #5C5348;
  --ink-3: #8F8577;
  --rule: #E2D9C8;
  --rule-2: #D6CBB6;
  --seal: #B8392B;
  --seal-deep: #9E2F24;
  --seal-ink: #FFF8F0;
  --seal-soft: rgba(184, 57, 43, .09);
  --focus: rgba(184, 57, 43, .38);
  --mark: rgba(230, 170, 60, .35);
  --ok: #5B8A72;
  --ok-soft: rgba(91, 138, 114, .10);
  --err: #A33D4F;
  --err-soft: rgba(163, 61, 79, .09);
  --shadow: 0 1px 2px rgba(60, 40, 20, .06), 0 8px 28px rgba(60, 40, 20, .08);
  --shadow-lg: 0 2px 6px rgba(60, 40, 20, .08), 0 24px 60px rgba(60, 40, 20, .18);
  --serif: "Songti SC", "STSong", "Noto Serif CJK SC", "Noto Serif SC", "Source Han Serif SC", "Source Han Serif CN", "SimSun", Georgia, serif;
  --sans: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC", "Noto Sans SC", system-ui, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --paper: #1B1916;
  --paper-2: #221F1B;
  --sheet: #23201C;
  --ink: #ECE4D6;
  --ink-2: #BDB3A3;
  --ink-3: #8B8273;
  --rule: #34302A;
  --rule-2: #433D35;
  --seal: #D4553F;
  --seal-deep: #E06A55;
  --seal-ink: #1B1916;
  --seal-soft: rgba(212, 85, 63, .14);
  --focus: rgba(212, 85, 63, .45);
  --mark: rgba(220, 160, 60, .32);
  --ok: #7FB197;
  --ok-soft: rgba(127, 177, 151, .12);
  --err: #D16A7C;
  --err-soft: rgba(209, 106, 124, .12);
  --shadow: 0 1px 2px rgba(8, 6, 4, .24), 0 10px 30px rgba(8, 6, 4, .28);
  --shadow-lg: 0 2px 8px rgba(8, 6, 4, .30), 0 28px 70px rgba(8, 6, 4, .46);
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: var(--paper);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.6;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}

::selection { color: var(--ink); background: var(--mark); }

a { color: var(--seal); }

button, input { font: inherit; }

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

.icon-sprite {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}

.icon {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ---------- seal / brand ---------- */

.seal {
  position: relative;
  display: inline-grid;
  flex: 0 0 auto;
  place-items: center;
  color: var(--seal);
  background: var(--seal-soft);
  border: 1px solid var(--seal);
  border-radius: 9px;
  font-family: var(--serif);
  font-weight: 600;
  line-height: 1;
}

.seal::after {
  content: "";
  position: absolute;
  inset: 4px;
  border: 1px solid var(--seal);
  border-radius: 5px;
  opacity: .55;
  pointer-events: none;
}

.seal-sm {
  width: 30px;
  height: 30px;
  border-radius: 7px;
  font-size: 17px;
}
.seal-sm::after { inset: 3px; border-radius: 4px; }

.seal-lg {
  width: 60px;
  height: 60px;
  border-radius: 10px;
  font-size: 34px;
  transform: rotate(-4deg);
}
.seal-lg::after { inset: 5px; border-radius: 6px; }

.seal-empty {
  width: 48px;
  height: 48px;
  border-radius: 10px;
  color: var(--ink-3);
  background: transparent;
  border-color: var(--rule-2);
  font-size: 18px;
}
.seal-empty::after { border-color: var(--rule-2); }

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

.brand-text { display: grid; gap: 1px; line-height: 1.15; }
.brand-text strong {
  font-family: var(--serif);
  font-size: 18px;
  font-weight: 600;
  letter-spacing: .12em;
}
.brand-text small {
  color: var(--ink-3);
  font-size: 10.5px;
  letter-spacing: .14em;
  text-transform: lowercase;
}

/* ---------- app frame ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--paper);
  border-bottom: 1px solid var(--rule);
}

.topbar-inner {
  width: min(1120px, 100%);
  min-height: 68px;
  margin: 0 auto;
  padding: 0 32px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.account { display: flex; align-items: center; gap: 10px; }
.account-name {
  max-width: 160px;
  overflow: hidden;
  color: var(--ink-3);
  font-family: var(--sans);
  font-size: 11.5px;
  letter-spacing: .08em;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.logout-form { margin: 0; }

.page {
  width: min(1120px, 100%);
  margin: 0 auto;
  padding: 44px 32px 64px;
}

/* ---------- masthead ---------- */

.masthead {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 36px;
  padding-bottom: 28px;
  border-bottom: 1px solid var(--rule);
}

.masthead-main { min-width: 0; }

.masthead h1 {
  margin: 0;
  font-family: var(--serif);
  font-size: clamp(40px, 5.2vw, 54px);
  font-weight: 600;
  letter-spacing: .12em;
  line-height: 1.15;
}

.lede {
  max-width: 42ch;
  margin: 14px 0 0;
  color: var(--ink-2);
  font-family: var(--serif);
  font-size: 17.5px;
  line-height: 34px;
}

.catalog-meta {
  flex: 0 0 auto;
  margin: 0;
  color: var(--ink-3);
  font-family: var(--serif);
  font-size: 14px;
  letter-spacing: .06em;
  text-align: right;
  white-space: nowrap;
}
.catalog-meta strong {
  color: var(--ink);
  font-size: 22px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.catalog-meta span {
  display: block;
  margin-top: 5px;
  font-size: 11.5px;
  letter-spacing: .08em;
}

/* ---------- buttons ---------- */

.btn {
  min-height: 42px;
  padding: 0 20px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border: 1px solid transparent;
  border-radius: 999px;
  color: var(--ink);
  background: transparent;
  font-family: var(--sans);
  font-size: 13.5px;
  font-weight: 600;
  letter-spacing: .04em;
  line-height: 1;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
  transition: background-color .15s ease, border-color .15s ease, color .15s ease, transform .15s ease;
}

.btn:active { transform: translateY(1px); }
.btn:disabled { cursor: not-allowed; opacity: .55; transform: none; }

.btn-primary {
  color: var(--seal-ink);
  background: var(--seal);
  box-shadow: 0 6px 18px rgba(184, 57, 43, .18);
}
.btn-primary:hover { background: var(--seal-deep); }

.btn-ghost {
  color: var(--ink-2);
  background: transparent;
  border-color: var(--rule-2);
}
.btn-ghost:hover { color: var(--ink); background: var(--paper-2); }

.btn-small { min-height: 34px; padding: 0 13px; font-size: 12.5px; }
.btn-block { width: 100%; min-height: 46px; }

.icon-btn {
  width: 36px;
  height: 36px;
  display: inline-grid;
  place-items: center;
  border: 1px solid transparent;
  border-radius: 999px;
  color: var(--ink-3);
  background: transparent;
  cursor: pointer;
  transition: color .15s ease, background-color .15s ease, border-color .15s ease;
}
.icon-btn:hover { color: var(--seal); background: var(--seal-soft); }
.icon-btn.is-copied { color: var(--ok); background: var(--ok-soft); }

.btn:focus-visible,
.icon-btn:focus-visible,
.dropzone:focus-visible,
input:focus-visible,
a:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.theme-toggle { flex: 0 0 auto; }
.icon-sun { display: none; }
:root[data-theme="dark"] .icon-sun { display: block; }
:root[data-theme="dark"] .icon-moon { display: none; }

/* ---------- dispatch ---------- */

.dispatch {
  margin-top: 30px;
  padding: 26px 30px 22px;
  border: 1px solid var(--rule);
  border-radius: 18px;
  background: var(--sheet);
  box-shadow: var(--shadow);
}

.dispatch-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 18px;
}

.dispatch-copy h2,
.archive-head h2,
.note-sheet h2 {
  margin: 0;
  font-family: var(--serif);
  font-size: 24px;
  font-weight: 600;
  letter-spacing: .12em;
}

.dispatch-copy p,
.note-sheet p {
  margin: 7px 0 0;
  color: var(--ink-2);
  font-family: var(--serif);
  font-size: 15.5px;
  line-height: 30px;
}

.dispatch-note {
  flex: 0 0 auto;
  color: var(--ink-3);
  font-family: var(--sans);
  font-size: 11px;
  letter-spacing: .06em;
  line-height: 1.7;
  text-align: right;
}

.dropzone {
  min-height: 118px;
  padding: 18px 22px;
  display: flex;
  align-items: center;
  gap: 16px;
  border: 1px dashed var(--rule-2);
  border-radius: 12px;
  background: var(--paper-2);
  cursor: pointer;
  transition: border-color .18s ease, background-color .18s ease, box-shadow .18s ease;
}
.dropzone:hover,
.dropzone.dragging {
  border-color: var(--seal);
  background: var(--seal-soft);
  box-shadow: inset 0 0 0 1px rgba(184, 57, 43, .06);
}

.drop-icon {
  width: 44px;
  height: 44px;
  display: inline-grid;
  flex: 0 0 auto;
  place-items: center;
  color: var(--seal);
  border: 1px solid var(--rule-2);
  border-radius: 12px;
  background: var(--sheet);
}
.drop-icon .icon { width: 21px; height: 21px; }

.drop-text { display: grid; gap: 2px; margin-right: auto; }
.drop-text strong { font-family: var(--serif); font-size: 16px; font-weight: 600; letter-spacing: .04em; }
.drop-text span { color: var(--ink-3); font-size: 11.5px; letter-spacing: .04em; }

.upload-status {
  min-height: 22px;
  margin: 14px 0 0;
  color: var(--ink-2);
  font-family: var(--serif);
  font-size: 13.5px;
}
.upload-status.error { color: var(--err); }
.upload-status.success { color: var(--ok); }

.progress {
  height: 4px;
  margin-top: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--rule);
}
.progress-bar {
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: var(--seal);
  transition: width .2s ease;
}

/* ---------- archive / table ---------- */

.archive {
  margin-top: 30px;
  border: 1px solid var(--rule);
  border-radius: 18px;
  background: var(--sheet);
  overflow: hidden;
}

.archive-head {
  padding: 22px 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  border-bottom: 1px solid var(--rule);
}

.search {
  position: relative;
  display: flex;
  align-items: center;
  width: min(230px, 100%);
}
.search .icon {
  position: absolute;
  left: 12px;
  width: 15px;
  height: 15px;
  color: var(--ink-3);
  pointer-events: none;
}
.search input {
  width: 100%;
  height: 38px;
  padding: 0 12px 0 34px;
  border: 1px solid var(--rule-2);
  border-radius: 10px;
  color: var(--ink);
  background: var(--paper);
  font-family: var(--sans);
  font-size: 12.5px;
  letter-spacing: .02em;
  outline: none;
}
.search input::placeholder { color: var(--ink-3); }
.search input:focus { border-color: var(--seal); background: var(--sheet); }

.table-wrap { width: 100%; overflow-x: auto; }

.file-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}
.file-table th {
  padding: 12px 28px;
  color: var(--ink-3);
  font-family: var(--sans);
  font-size: 10.5px;
  font-weight: 500;
  letter-spacing: .18em;
  text-align: left;
  white-space: nowrap;
}
.file-table th:nth-child(1) { width: auto; }
.file-table th:nth-child(2) { width: 108px; }
.file-table th:nth-child(3) { width: 172px; }
.file-table th.th-actions { width: 150px; text-align: right; }

.file-row { border-top: 1px solid var(--rule); transition: background-color .12s ease; }
.file-row:hover { background: var(--paper-2); }
.file-table td {
  padding: 13px 28px;
  vertical-align: middle;
  font-size: 13.5px;
}
.cell-name { min-width: 0; }
.name-wrap { display: flex; align-items: center; gap: 12px; min-width: 0; }

.file-icon {
  width: 36px;
  height: 36px;
  display: inline-grid;
  flex: 0 0 auto;
  place-items: center;
  color: var(--ink-2);
  border: 1px solid var(--rule);
  border-radius: 10px;
  background: var(--paper);
}
.file-icon .icon { width: 17px; height: 17px; }

.file-meta { min-width: 0; display: flex; align-items: baseline; gap: 8px; }
.file-name {
  max-width: 100%;
  overflow: hidden;
  color: var(--ink);
  font-family: var(--serif);
  font-size: 16px;
  font-weight: 500;
  letter-spacing: .01em;
  text-decoration: none;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.file-name:hover { color: var(--seal); text-decoration: underline; text-underline-offset: 4px; }
.file-ext {
  flex: 0 0 auto;
  padding: 1px 7px;
  color: var(--ink-3);
  border: 1px solid var(--rule);
  border-radius: 999px;
  background: var(--paper);
  font-family: var(--sans);
  font-size: 9.5px;
  letter-spacing: .05em;
  white-space: nowrap;
}

.cell-size,
.cell-date {
  color: var(--ink-2);
  font-family: var(--serif);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.cell-date time { color: var(--ink-2); }
.cell-actions { text-align: right; white-space: nowrap; }
.row-actions { display: flex; align-items: center; justify-content: flex-end; gap: 4px; }

.empty-state {
  padding: 54px 24px 58px;
  text-align: center;
}
.empty-state .seal { margin: 0 auto 16px; }
.empty-state h2 {
  margin: 0;
  font-family: var(--serif);
  font-size: 22px;
  font-weight: 600;
  letter-spacing: .12em;
}
.empty-state p {
  margin: 7px 0 0;
  color: var(--ink-3);
  font-family: var(--serif);
  font-size: 14px;
}

.no-results {
  margin: 0;
  padding: 36px 24px;
  color: var(--ink-3);
  font-family: var(--serif);
  font-size: 14px;
  text-align: center;
}

/* ---------- note ---------- */

.note-sheet {
  margin-top: 30px;
  padding: 24px 28px;
  border: 1px dashed var(--rule-2);
  border-radius: 16px;
}
.note-sheet pre {
  margin: 14px 0 0;
  padding: 14px 16px;
  overflow-x: auto;
  border: 1px solid var(--rule);
  border-radius: 12px;
  background: var(--paper-2);
}
.note-sheet code {
  color: var(--ink-2);
  font-family: var(--mono);
  font-size: 11.5px;
  line-height: 1.8;
}

.footer {
  width: min(1120px, 100%);
  margin: 0 auto;
  padding: 18px 32px 30px;
  display: flex;
  justify-content: space-between;
  gap: 16px;
  color: var(--ink-3);
  border-top: 1px dashed var(--rule);
  font-family: var(--sans);
  font-size: 10.5px;
  letter-spacing: .12em;
}

/* ---------- login ---------- */

.login-body {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 32px 16px;
  background: var(--paper);
}

.login-wrap {
  position: relative;
  width: min(410px, 100%);
}

.login-theme {
  position: fixed;
  top: 18px;
  right: 18px;
  z-index: 30;
}

.login-sheet {
  position: relative;
  overflow: hidden;
  padding: 36px 34px 30px 56px;
  border: 1px solid var(--rule);
  border-radius: 18px;
  background-color: var(--sheet);
  background-image: repeating-linear-gradient(180deg, transparent 0 33px, var(--rule) 33px 34px);
  background-attachment: local;
  box-shadow: var(--shadow-lg);
}
.login-sheet::before {
  content: "";
  position: absolute;
  top: 20px;
  bottom: 20px;
  left: 22px;
  width: 1px;
  background: var(--seal);
  opacity: .25;
  pointer-events: none;
}

.login-brand { display: flex; align-items: center; gap: 13px; margin-bottom: 28px; }
.login-wordmark {
  font-family: var(--serif);
  font-size: 24px;
  font-weight: 600;
  letter-spacing: .14em;
}

.login-sheet h1 {
  margin: 0;
  font-family: var(--serif);
  font-size: 32px;
  font-weight: 600;
  letter-spacing: .14em;
  line-height: 1.2;
}

.login-intro {
  margin: 10px 0 22px;
  color: var(--ink-2);
  font-family: var(--serif);
  font-size: 15.5px;
  line-height: 34px;
}

.login-form { display: grid; gap: 14px; }
.field { display: grid; gap: 5px; }
.field span {
  color: var(--ink-2);
  font-family: var(--sans);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: .12em;
}
.field input {
  height: 44px;
  padding: 0 12px;
  border: 1px solid var(--rule-2);
  border-radius: 10px;
  color: var(--ink);
  background: var(--sheet);
  font-family: var(--sans);
  font-size: 14px;
  outline: none;
}
.field input:focus { border-color: var(--seal); box-shadow: 0 0 0 3px var(--focus); }

.form-error {
  margin: 0 0 16px;
  padding: 10px 12px;
  border: 1px solid var(--err);
  border-radius: 10px;
  color: var(--err);
  background: var(--err-soft);
  font-family: var(--sans);
  font-size: 12px;
}

.login-note {
  margin: 18px 0 0;
  color: var(--ink-3);
  font-family: var(--sans);
  font-size: 10.5px;
  letter-spacing: .04em;
  line-height: 1.8;
}

.login-foot {
  margin: 18px 0 0;
  color: var(--ink-3);
  font-family: var(--sans);
  font-size: 10.5px;
  letter-spacing: .18em;
  text-align: center;
}

/* ---------- error ---------- */

.error-body { display: grid; min-height: 100vh; place-items: center; padding: 24px; }
.error-wrap { width: min(480px, 100%); }
.error-sheet {
  padding: 44px 40px;
  border: 1px solid var(--rule);
  border-radius: 18px;
  background: var(--sheet);
  box-shadow: var(--shadow-lg);
  text-align: center;
}
.error-code {
  margin: 18px 0 0;
  color: var(--seal);
  font-family: var(--serif);
  font-size: 14px;
  letter-spacing: .2em;
}
.error-sheet h1 {
  margin: 6px 0 22px;
  font-family: var(--serif);
  font-size: 26px;
  font-weight: 600;
  letter-spacing: .1em;
}

/* ---------- helpers ---------- */

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

/* ---------- responsive ---------- */

@media (max-width: 860px) {
  .masthead { align-items: flex-start; flex-direction: column; gap: 16px; }
  .catalog-meta { text-align: left; }
  .dispatch-head { flex-direction: column; gap: 8px; }
  .dispatch-note { text-align: left; }
  .dropzone { flex-wrap: wrap; }
  .drop-text { min-width: 0; }
  .dropzone .btn { margin-left: 60px; }
}

@media (max-width: 720px) {
  .topbar-inner, .page, .footer { padding-left: 18px; padding-right: 18px; }
  .page { padding-top: 30px; padding-bottom: 46px; }
  .account-name { display: none; }
  .masthead-main { min-width: 0; }

.masthead h1 { font-size: 40px; }
  .lede { font-size: 16px; line-height: 32px; }
  .dispatch { padding: 20px 18px 18px; }
  .dropzone { padding: 16px; }
  .dropzone .btn { width: 100%; margin-left: 0; }
  .archive-head { align-items: stretch; flex-direction: column; padding: 18px; }
  .search { width: 100%; }
  .file-table thead { display: none; }
  .file-table, .file-table tbody, .file-row, .file-table td { display: block; width: 100%; }
  .file-row { padding: 14px 18px; }
  .file-table td { padding: 0; }
  .file-table td.cell-name { margin-bottom: 8px; }
  .file-table td.cell-size, .file-table td.cell-date {
    display: inline-flex;
    gap: 6px;
    margin-right: 12px;
    color: var(--ink-3);
    font-family: var(--sans);
    font-size: 11px;
  }
  .file-table td.cell-size::before { content: attr(data-label) " "; }
  .file-table td.cell-date::before { content: attr(data-label) " "; }
  .file-table td.cell-actions { margin-top: 11px; text-align: left; }
  .cell-actions .row-actions { justify-content: flex-start; }
  .file-name { white-space: normal; overflow-wrap: anywhere; }
  .note-sheet { padding: 20px 18px; }
  .footer { flex-direction: column; gap: 3px; }
  .icon-btn { width: 40px; height: 40px; }
  .login-sheet { padding: 30px 24px 26px 46px; }
  .login-sheet::before { left: 17px; }
}

@media (max-width: 380px) {
  .brand-text small { display: none; }
  .masthead-main { min-width: 0; }

.masthead h1 { font-size: 34px; }
  .dispatch-copy h2, .archive-head h2, .note-sheet h2 { font-size: 21px; }
  .file-icon { width: 32px; height: 32px; }
  .login-sheet { padding-left: 40px; }
}

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