:root {
  --ink: #161918;
  --muted: #686e6b;
  --line: #dfe3df;
  --surface: #ffffff;
  --canvas: #f4f5f2;
  --soft: #eef1ed;
  --success: #22704a;
  --success-soft: #e8f4ed;
  --danger: #a03333;
  --shadow: 0 18px 48px rgba(27, 31, 29, 0.08);
}

* {
  box-sizing: border-box;
}

html {
  background: var(--canvas);
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI",
    "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background: var(--canvas);
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

[hidden] {
  display: none !important;
}

.auth-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-card {
  width: min(100%, 420px);
  padding: 42px;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: var(--shadow);
}

.brand-mark {
  display: grid;
  grid-template-columns: repeat(2, 9px);
  gap: 4px;
  width: fit-content;
  padding: 10px;
  margin-bottom: 30px;
  border-radius: 10px;
  background: var(--ink);
}

.brand-mark span {
  width: 9px;
  height: 9px;
  background: #fff;
}

.brand-mark span:last-child {
  opacity: 0.45;
}

.eyebrow {
  margin: 0 0 9px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 750;
  letter-spacing: 0.16em;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 10px;
  font-size: clamp(26px, 4vw, 38px);
  line-height: 1.12;
  letter-spacing: -0.035em;
}

.login-copy,
.header-copy,
.table-heading p {
  color: var(--muted);
}

.login-copy {
  margin-bottom: 32px;
  font-size: 15px;
}

label {
  display: block;
  margin-bottom: 8px;
  font-size: 13px;
  font-weight: 700;
}

.password-field {
  position: relative;
}

.password-field input {
  width: 100%;
  height: 50px;
  padding: 0 66px 0 14px;
  border: 1px solid #cfd4d0;
  border-radius: 10px;
  outline: 0;
  background: #fff;
  color: var(--ink);
}

.password-field input:focus,
.cell-input:focus {
  border-color: var(--ink);
  box-shadow: 0 0 0 3px rgba(22, 25, 24, 0.09);
}

.text-button {
  position: absolute;
  top: 0;
  right: 3px;
  height: 50px;
  padding: 0 12px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
}

.form-error {
  min-height: 20px;
  margin: 8px 0 4px;
  color: var(--danger);
  font-size: 13px;
}

.primary-button,
.secondary-button,
.save-button,
.upload-button {
  border-radius: 9px;
  font-weight: 700;
  transition:
    opacity 160ms ease,
    transform 160ms ease,
    background 160ms ease;
}

.primary-button {
  width: 100%;
  height: 50px;
  border: 1px solid var(--ink);
  background: var(--ink);
  color: #fff;
}

.primary-button:hover,
.save-button:hover {
  background: #2d312f;
}

button:active {
  transform: translateY(1px);
}

button:disabled {
  cursor: wait;
  opacity: 0.55;
}

.app-shell {
  width: min(100% - 40px, 1440px);
  margin: 0 auto;
  padding: 48px 0 80px;
}

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

.page-header h1 {
  margin-bottom: 8px;
}

.header-copy {
  max-width: 600px;
  margin-bottom: 0;
  font-size: 15px;
}

.secondary-button {
  min-width: 72px;
  height: 40px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
}

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

.progress-panel,
.table-panel {
  border: 1px solid var(--line);
  background: var(--surface);
  box-shadow: 0 10px 30px rgba(27, 31, 29, 0.045);
}

.progress-panel {
  margin-bottom: 16px;
  padding: 18px 22px;
  border-radius: 14px;
}

.progress-copy {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.progress-copy > div {
  display: flex;
  align-items: baseline;
  gap: 10px;
}

.progress-label,
#progress-percent {
  color: var(--muted);
  font-size: 12px;
}

#progress-number {
  font-size: 14px;
}

.progress-track {
  height: 6px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--soft);
}

#progress-bar {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: var(--success);
  transition: width 280ms ease;
}

.table-panel {
  overflow: hidden;
  border-radius: 16px;
}

.table-heading {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 18px;
  padding: 24px 26px;
  border-bottom: 1px solid var(--line);
}

.table-heading h2 {
  margin-bottom: 5px;
  font-size: 18px;
  letter-spacing: -0.02em;
}

.table-heading p {
  margin-bottom: 0;
  font-size: 13px;
}

.legend {
  display: flex;
  align-items: center;
  flex: 0 0 auto;
  gap: 7px;
  color: var(--muted);
  font-size: 12px;
}

.legend span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--success);
}

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

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

th {
  padding: 12px 12px;
  border-bottom: 1px solid var(--line);
  background: #f8f9f7;
  color: var(--muted);
  font-size: 11px;
  font-weight: 750;
  letter-spacing: 0.04em;
  text-align: left;
  text-transform: uppercase;
}

th:nth-child(1) {
  width: 58px;
  text-align: center;
}

th:nth-child(2) {
  width: 120px;
}

th:nth-child(3) {
  width: 150px;
}

th:nth-child(4) {
  width: 145px;
}

th:nth-child(5) {
  width: 29%;
}

th:nth-child(6) {
  width: 185px;
}

th:nth-child(7) {
  width: 150px;
}

td {
  padding: 12px;
  border-bottom: 1px solid #e7eae7;
  background: #fff;
  font-size: 13px;
  vertical-align: middle;
}

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

tr.is-complete td {
  background: #fbfdfb;
}

.position-cell {
  color: #8a908d;
  text-align: center;
}

.id-cell {
  font-weight: 750;
}

.subaccount-cell {
  color: #373c39;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 12px;
}

.cell-input {
  width: 100%;
  min-width: 0;
  height: 39px;
  padding: 0 10px;
  border: 1px solid #d5dad6;
  border-radius: 8px;
  outline: 0;
  background: #fff;
  color: var(--ink);
  font-size: 13px;
}

.txid-input {
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 12px;
}

.image-control {
  display: flex;
  align-items: center;
  gap: 9px;
}

.image-preview {
  display: block;
  width: 44px;
  height: 44px;
  flex: 0 0 44px;
  padding: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--soft);
  appearance: none;
  cursor: zoom-in;
}

.image-preview:disabled {
  cursor: default;
  opacity: 1;
}

.image-preview:not(:disabled):focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 2px;
}

.image-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.image-placeholder {
  display: grid;
  width: 100%;
  height: 100%;
  place-items: center;
  color: #929895;
  font-size: 18px;
}

.file-input {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
}

.upload-button {
  display: inline-grid;
  min-width: 82px;
  min-height: 36px;
  place-items: center;
  padding: 7px 10px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  font-size: 12px;
  text-align: center;
}

.status-control {
  display: grid;
  gap: 7px;
}

.status-line {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 11px;
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #b8beba;
}

.is-complete .status-dot {
  background: var(--success);
}

.is-complete .status-line {
  color: var(--success);
}

.save-button {
  height: 35px;
  border: 1px solid var(--ink);
  background: var(--ink);
  color: #fff;
  font-size: 12px;
}

.save-button.is-saved {
  border-color: #cfe3d6;
  background: var(--success-soft);
  color: var(--success);
}

.loading-state {
  padding: 70px 20px;
  color: var(--muted);
  font-size: 14px;
  text-align: center;
}

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 20;
  max-width: min(360px, calc(100vw - 44px));
  padding: 12px 16px;
  border-radius: 10px;
  background: var(--ink);
  box-shadow: 0 12px 32px rgba(22, 25, 24, 0.22);
  color: #fff;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition:
    opacity 180ms ease,
    transform 180ms ease;
}

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

.toast.is-error {
  background: var(--danger);
}

.viewer-open {
  overflow: hidden;
}

.image-viewer {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  grid-template-rows: 58px minmax(0, 1fr) 42px;
  background: rgba(12, 14, 13, 0.94);
  color: #fff;
}

.viewer-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 max(18px, env(safe-area-inset-right)) 0
    max(18px, env(safe-area-inset-left));
  border-bottom: 1px solid rgba(255, 255, 255, 0.16);
}

#image-viewer-title {
  overflow: hidden;
  font-size: 13px;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.viewer-close {
  min-width: 70px;
  height: 36px;
  padding: 0 12px;
  border: 1px solid rgba(255, 255, 255, 0.24);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
}

.viewer-stage {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  min-height: 0;
  overflow: auto;
  padding: 18px;
  overscroll-behavior: contain;
  touch-action: pinch-zoom;
  -webkit-overflow-scrolling: touch;
}

#viewer-image {
  display: block;
  max-width: min(94vw, 1500px);
  max-height: calc(100vh - 136px);
  object-fit: contain;
  cursor: zoom-in;
  touch-action: pinch-zoom;
  user-select: none;
  -webkit-user-drag: none;
}

#viewer-image.is-zoomed {
  max-width: none;
  max-height: none;
  cursor: zoom-out;
}

.viewer-hint {
  align-self: center;
  margin: 0;
  padding: 0 18px max(4px, env(safe-area-inset-bottom));
  color: rgba(255, 255, 255, 0.68);
  font-size: 11px;
  text-align: center;
}

@media (max-width: 820px) {
  body {
    background: var(--canvas);
  }

  .app-shell {
    width: min(100% - 24px, 720px);
    padding: 28px 0 60px;
  }

  .page-header {
    align-items: center;
  }

  .header-copy {
    font-size: 13px;
  }

  .table-heading {
    padding: 20px;
  }

  .legend {
    display: none;
  }

  .table-wrap {
    overflow: visible;
    padding: 12px;
    background: #eef0ed;
  }

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

  thead {
    display: none;
  }

  tr {
    margin-bottom: 12px;
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: #fff;
  }

  tr:last-child {
    margin-bottom: 0;
  }

  td {
    display: grid;
    grid-template-columns: 92px minmax(0, 1fr);
    align-items: center;
    gap: 10px;
    min-height: 48px;
    padding: 10px 12px;
  }

  td::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.02em;
  }

  .position-cell {
    text-align: left;
  }

  .status-control {
    grid-template-columns: 1fr 96px;
    align-items: center;
  }

  .image-preview {
    width: 58px;
    height: 58px;
    flex-basis: 58px;
  }

  .upload-button {
    min-height: 40px;
  }

  .image-viewer {
    grid-template-rows: 56px minmax(0, 1fr) 46px;
  }

  .viewer-stage {
    padding: 10px;
  }

  #viewer-image {
    max-width: 96vw;
    max-height: calc(100vh - 122px);
  }
}

@media (max-width: 480px) {
  .auth-shell {
    align-items: start;
    padding: 42px 16px;
  }

  .login-card {
    padding: 32px 24px;
    border-radius: 18px;
  }

  .page-header h1 {
    font-size: 28px;
  }

  .header-copy {
    max-width: 250px;
  }

  .progress-panel {
    padding: 16px;
  }

  .table-heading {
    display: block;
  }

  .table-heading p {
    line-height: 1.6;
  }

  td {
    grid-template-columns: 78px minmax(0, 1fr);
  }
}

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