:root {
  --bg: #f4f1ea;
  --bg-cool: #edf1ed;
  --paper: #fffdf8;
  --paper-strong: #ffffff;
  --paper-muted: #f8f4ec;
  --ink: #201c17;
  --ink-soft: #3c352d;
  --muted: #746c62;
  --muted-2: #948a7d;
  --line: #ddd4c6;
  --line-strong: #c8bdad;
  --accent: #c96542;
  --accent-dark: #9f4a2e;
  --accent-soft: #fff0e7;
  --moss: #587466;
  --moss-soft: #edf4ef;
  --blue: #526d86;
  --red: #b6534b;
  --shadow: 0 18px 48px rgba(52, 43, 31, 0.1);
  --shadow-soft: 0 10px 28px rgba(52, 43, 31, 0.07);
  --focus: 0 0 0 3px rgba(201, 101, 66, 0.16);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background:
    linear-gradient(180deg, rgba(255, 253, 248, 0.74), rgba(237, 241, 237, 0.78)),
    linear-gradient(90deg, rgba(32, 28, 23, 0.035) 1px, transparent 1px),
    linear-gradient(rgba(32, 28, 23, 0.03) 1px, transparent 1px),
    var(--bg);
  background-size: auto, 36px 36px, 36px 36px, auto;
  color: var(--ink);
  font-family: Inter, "Microsoft YaHei", "PingFang SC", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

button,
input,
select {
  font: inherit;
}

a {
  color: inherit;
}

h1,
h2,
p {
  margin: 0;
}

.app-shell {
  width: min(1460px, calc(100% - 40px));
  margin: 0 auto;
  padding: 30px 0 44px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 22px;
  margin-bottom: 18px;
}

.brand {
  display: flex;
  align-items: center;
  min-width: 0;
  gap: 13px;
}

.brand-mark {
  display: grid;
  place-items: center;
  flex: 0 0 52px;
  width: 52px;
  height: 52px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  box-shadow: var(--shadow-soft);
  overflow: hidden;
}

.brand-logo {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

h1 {
  font-size: 26px;
  line-height: 1.12;
  font-weight: 760;
  color: var(--ink);
}

.brand p {
  margin-top: 5px;
  color: var(--muted);
  font-size: 13px;
  overflow-wrap: anywhere;
}

.topbar-tools {
  display: flex;
  align-items: center;
  gap: 10px;
}

.metric-strip {
  display: grid;
  grid-template-columns: repeat(2, minmax(104px, 1fr));
  gap: 8px;
}

.metric-strip > div {
  min-height: 58px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 253, 248, 0.88);
  box-shadow: var(--shadow-soft);
}

.metric-strip span {
  display: block;
  font-size: 19px;
  font-weight: 760;
  line-height: 1.15;
  color: var(--ink);
}

.metric-strip small {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(320px, 0.95fr);
  gap: 16px;
}

.panel {
  position: relative;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 253, 248, 0.92);
  box-shadow: var(--shadow);
}

.upload-panel,
.result-panel,
.records-panel {
  padding: 18px;
}

.records-panel {
  grid-column: 1 / -1;
}

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.section-title h2 {
  font-size: 16px;
  line-height: 1.25;
  font-weight: 720;
  color: var(--ink);
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  max-width: 160px;
  padding: 0 10px;
  border: 1px solid #e5c9b8;
  border-radius: 999px;
  color: var(--accent-dark);
  background: var(--accent-soft);
  font-size: 12px;
  font-weight: 650;
  white-space: nowrap;
}

.status-pill.ready {
  border-color: #c9d8cf;
  color: #3f6657;
  background: var(--moss-soft);
}

.upload-form {
  display: grid;
  gap: 14px;
}

.dropzone {
  display: grid;
  grid-template-columns: 54px minmax(0, 1fr);
  align-items: center;
  min-height: 150px;
  padding: 18px;
  border: 1.5px dashed #ceb9a4;
  border-radius: 8px;
  background: #fbf7ef;
  cursor: pointer;
  transition: border-color 160ms ease, background 160ms ease, transform 160ms ease, box-shadow 160ms ease;
}

.dropzone:hover,
.dropzone.drag-over {
  border-color: var(--accent);
  background: #fffaf3;
  box-shadow: inset 0 0 0 1px rgba(201, 101, 66, 0.08);
}

.dropzone.drag-over {
  transform: translateY(-1px);
}

.drop-icon {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border: 1px solid #ead6c8;
  border-radius: 8px;
  color: var(--accent-dark);
  background: var(--paper);
  box-shadow: 0 8px 18px rgba(201, 101, 66, 0.1);
}

.drop-icon svg,
.button svg,
.icon-button svg {
  width: 18px;
  height: 18px;
}

.drop-copy {
  display: grid;
  min-width: 0;
  gap: 5px;
}

.drop-copy strong {
  display: block;
  font-size: 18px;
  line-height: 1.28;
  font-weight: 760;
  color: var(--ink);
  overflow-wrap: anywhere;
}

.drop-copy span {
  color: var(--muted);
  font-size: 13px;
  overflow-wrap: anywhere;
}

.upload-meta-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(0, 0.85fr);
  gap: 10px;
}

.upload-meta-grid.custom-type-visible {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.field-control,
.type-filter {
  position: relative;
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 660;
}

.field-control[hidden] {
  display: none;
}

.field-control select,
.field-control input,
.type-filter select,
.login-form input {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: var(--paper-strong);
  padding: 0 10px;
  outline: 0;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.7);
}

.field-control input:focus,
.field-control select:focus,
.type-filter select:focus,
.login-form input:focus,
.search-box:focus-within {
  border-color: var(--accent);
  box-shadow: var(--focus);
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

.button,
.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 40px;
  border: 1px solid transparent;
  border-radius: 8px;
  text-decoration: none;
  cursor: pointer;
  transition: background 140ms ease, border-color 140ms ease, color 140ms ease, opacity 140ms ease, transform 140ms ease;
}

.button {
  padding: 0 14px;
  font-weight: 700;
}

.button.primary {
  color: #fffdf8;
  border-color: var(--accent-dark);
  background: var(--accent);
  box-shadow: 0 10px 20px rgba(159, 74, 46, 0.18);
}

.button.primary:hover {
  background: var(--accent-dark);
  transform: translateY(-1px);
}

.button.secondary,
.icon-button {
  color: var(--ink-soft);
  border-color: var(--line);
  background: rgba(255, 253, 248, 0.88);
}

.button.secondary:hover,
.icon-button:hover {
  border-color: var(--line-strong);
  background: var(--paper-strong);
}

.button.danger {
  color: var(--red);
}

.button:disabled,
.button.disabled {
  pointer-events: none;
  opacity: 0.46;
}

.icon-button {
  width: 38px;
  height: 38px;
  padding: 0;
}

.loading-spinner {
  width: 22px;
  height: 22px;
  border: 2px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: loading-spin 760ms linear infinite;
}

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

.icon-button.is-loading svg {
  animation: loading-spin 760ms linear infinite;
}

.link-preview {
  display: flex;
  align-items: center;
  min-height: 80px;
  margin-bottom: 12px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbf7ef;
}

.link-preview a {
  color: var(--accent-dark);
  font-weight: 720;
  line-height: 1.4;
  text-decoration: none;
  overflow-wrap: anywhere;
}

.link-preview a:hover {
  text-decoration: underline;
}

.records-title {
  margin-bottom: 8px;
}

.record-tools {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) minmax(150px, 220px);
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
}

.search-box {
  display: grid;
  grid-template-columns: 20px minmax(0, 1fr);
  align-items: center;
  gap: 8px;
  min-height: 42px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper-strong);
  color: var(--muted);
}

.search-box svg {
  width: 18px;
  height: 18px;
}

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

.record-tools .type-filter {
  gap: 0;
}

.record-tools .type-filter span {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}

.type-badge {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 0 9px;
  border: 1px solid #cbd8cf;
  border-radius: 999px;
  color: #3f6657;
  background: var(--moss-soft);
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.table-frame {
  position: relative;
  overflow-x: auto;
  overflow-y: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper-strong);
}

table {
  width: 100%;
  min-width: 1480px;
  border-collapse: collapse;
  table-layout: fixed;
}

th:nth-child(1),
td:nth-child(1) {
  width: 12%;
}

th:nth-child(2),
td:nth-child(2) {
  width: 20%;
}

th:nth-child(3),
td:nth-child(3) {
  width: 9%;
}

th:nth-child(4),
td:nth-child(4) {
  width: 10%;
}

th:nth-child(5),
td:nth-child(5) {
  width: 7%;
}

th:nth-child(6),
td:nth-child(6) {
  width: 18%;
}

th:nth-child(7),
td:nth-child(7) {
  width: 24%;
}

th,
td {
  padding: 13px 14px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

th {
  color: var(--muted);
  background: #f5efe5;
  font-size: 12px;
  font-weight: 760;
}

td {
  font-size: 14px;
  background: rgba(255, 253, 248, 0.64);
}

tbody tr {
  transition: background 150ms ease;
}

tbody tr:hover td {
  background: #fbf7ef;
}

tr:last-child td {
  border-bottom: 0;
}

.file-stack,
.link-stack,
.description-stack {
  display: grid;
  min-width: 0;
  gap: 3px;
}

.file-stack strong,
.link-stack a,
.description-stack strong {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-stack strong,
.description-stack strong {
  color: var(--ink);
  font-weight: 720;
}

.file-stack span,
.link-stack span,
.description-stack span {
  color: var(--muted);
  font-size: 12px;
}

.description-stack span {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.link-stack a {
  color: var(--accent-dark);
  font-weight: 700;
  text-decoration: none;
}

.link-stack a:hover {
  text-decoration: underline;
}

.row-actions {
  display: flex;
  align-items: center;
  flex-wrap: nowrap;
  gap: 6px;
}

.row-actions .button {
  min-height: 34px;
  padding: 0 9px;
  font-size: 13px;
  flex: 0 0 auto;
}

.empty-state {
  display: none;
  align-items: center;
  justify-content: center;
  min-height: 180px;
  gap: 12px;
  color: var(--muted);
  font-weight: 650;
}

.empty-state.visible {
  display: flex;
}

.records-pagination {
  display: flex;
  justify-content: center;
  margin-top: 14px;
}

.records-pagination .button {
  min-width: 220px;
}

.records-pagination .button[hidden] {
  display: none;
}

.records-loading,
.records-error {
  display: grid;
  min-height: 180px;
  align-content: center;
  justify-items: center;
  gap: 10px;
  padding: 18px;
  color: var(--muted);
  text-align: center;
}

.records-loading[hidden],
.records-error[hidden] {
  display: none;
}

.records-error strong {
  color: var(--ink);
}

.loading-lines {
  display: flex;
  gap: 5px;
}

.loading-lines i {
  width: 28px;
  height: 4px;
  border-radius: 8px;
  background: var(--line-strong);
  animation: loading-pulse 960ms ease-in-out infinite;
}

.loading-lines i:nth-child(2) {
  animation-delay: 120ms;
}

.loading-lines i:nth-child(3) {
  animation-delay: 240ms;
}

@keyframes loading-pulse {
  50% {
    opacity: 0.35;
  }
}

@media (prefers-reduced-motion: reduce) {
  .loading-spinner,
  .icon-button.is-loading svg,
  .loading-lines i {
    animation: none;
  }
}

.empty-state svg {
  width: 42px;
  height: 42px;
}

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  max-width: min(360px, calc(100vw - 32px));
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: var(--paper-strong);
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(10px);
  pointer-events: none;
  transition: opacity 180ms ease, transform 180ms ease;
}

.toast.visible {
  opacity: 1;
  transform: translateY(0);
}

.login-page {
  display: grid;
  place-items: center;
}

.login-shell {
  width: min(100% - 32px, 420px);
}

.login-panel {
  padding: 24px;
}

.login-brand {
  margin-bottom: 22px;
}

.login-form {
  display: grid;
  gap: 14px;
}

.login-form label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
}

.login-error {
  min-height: 20px;
  margin-top: 12px;
  color: var(--red);
  font-size: 13px;
}

@media (max-width: 1160px) {
  .record-tools {
    grid-template-columns: minmax(220px, 1fr) minmax(150px, 210px);
  }
}

@media (max-width: 860px) {
  .app-shell {
    width: min(100% - 20px, 760px);
    padding-top: 18px;
  }

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

  .topbar {
    display: grid;
  }

  .topbar-tools,
  .metric-strip {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .topbar-tools {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 38px;
  }

  .record-tools {
    grid-template-columns: 1fr;
  }

  .workspace {
    display: grid;
  }
}

@media (max-width: 760px) {
  .table-frame {
    overflow: visible;
    border: 0;
    background: transparent;
  }

  .records-loading,
  .records-error {
    min-height: 160px;
    padding: 16px 12px;
  }

  table,
  tbody,
  tr,
  td {
    display: block;
    width: 100%;
  }

  table {
    table-layout: auto;
    min-width: 0;
  }

  thead {
    display: none;
  }

  tbody {
    display: grid;
    gap: 12px;
  }

  tbody tr {
    display: grid;
    gap: 0;
    border: 1px solid var(--line);
    border-radius: 8px;
    overflow: hidden;
    background: var(--paper-strong);
    box-shadow: var(--shadow-soft);
  }

  th:nth-child(n),
  td:nth-child(n) {
    width: 100%;
  }

  td {
    display: grid;
    grid-template-columns: 96px minmax(0, 1fr);
    gap: 10px;
    padding: 12px;
    border-bottom: 1px solid var(--line);
    background: transparent;
  }

  td::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: 12px;
    font-weight: 760;
  }

  td:last-child {
    border-bottom: 0;
  }

  .row-actions {
    justify-content: flex-start;
    flex-wrap: wrap;
  }

  .row-actions .button {
    flex: 1 1 88px;
  }
}

@media (max-width: 560px) {
  .brand-mark {
    flex-basis: 42px;
    width: 42px;
    height: 42px;
  }

  h1 {
    font-size: 21px;
  }

  .upload-panel,
  .result-panel,
  .records-panel {
    padding: 14px;
  }

  .dropzone {
    grid-template-columns: 1fr;
    gap: 12px;
    min-height: 150px;
  }

  .upload-meta-grid,
  .upload-meta-grid.custom-type-visible {
    grid-template-columns: 1fr;
  }

  .button-row {
    display: grid;
    grid-template-columns: 1fr;
  }

  .button {
    width: 100%;
  }
}

.upload-progress {
  display: grid;
  gap: 6px;
}

.upload-progress[hidden] {
  display: none;
}

.upload-progress__label {
  min-height: 18px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.upload-progress__bar {
  display: block;
  width: 100%;
  height: 10px;
  overflow: hidden;
  border: 0;
  border-radius: 8px;
  background: var(--line);
  color: var(--accent);
}

.upload-progress__bar::-webkit-progress-bar {
  background: var(--line);
}

.upload-progress__bar::-webkit-progress-value {
  background: var(--accent);
  transition: width 140ms ease;
}

.upload-progress__bar::-moz-progress-bar {
  background: var(--accent);
}

.upload-progress[data-phase="processing"] .upload-progress__bar {
  animation: processing-sweep 900ms ease-in-out infinite;
  background: repeating-linear-gradient(90deg, var(--accent-soft) 0 14px, var(--accent) 14px 28px);
  background-size: 200% 100%;
}

@keyframes processing-sweep {
  from {
    background-position: 100% 0;
  }

  to {
    background-position: 0 0;
  }
}

.records-skeleton[hidden] {
  display: none;
}

.records-skeleton__block {
  display: block;
  width: 72%;
  height: 14px;
  border-radius: 4px;
  background: linear-gradient(90deg, var(--paper-muted), #ece4d9, var(--paper-muted));
  background-size: 200% 100%;
  animation: skeleton-sweep 900ms ease-in-out infinite;
}

.records-skeleton__block--wide {
  width: 94%;
}

@keyframes skeleton-sweep {
  from {
    background-position: 100% 0;
  }

  to {
    background-position: 0 0;
  }
}

.record-row[data-entering="true"] {
  animation: record-enter 180ms ease-out both;
}

.record-row.record-row--success {
  animation: record-success 900ms ease-out both;
}

@keyframes record-enter {
  from {
    opacity: 0;
    transform: translateY(4px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes record-success {
  0% {
    box-shadow: inset 4px 0 0 var(--accent);
  }

  100% {
    box-shadow: inset 0 0 0 transparent;
  }
}

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