:root {
  --bg: #f3f4f1;
  --panel: #ffffff;
  --ink: #1f2528;
  --muted: #657078;
  --line: #d8ddd9;
  --accent: #bf2f2f;
  --accent-dark: #8e2222;
  --blue: #245c7a;
  --green: #387457;
  --amber: #a36512;
  --shadow: 0 10px 30px rgba(31, 37, 40, 0.08);
}

* {
  box-sizing: border-box;
}

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

.auth-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(31, 37, 40, 0.78);
}

.auth-card {
  width: min(420px, 100%);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.3);
  padding: 18px;
}

.auth-card h1 {
  margin-bottom: 6px;
}

.auth-card p {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
  margin-bottom: 14px;
}

.auth-form {
  display: grid;
  gap: 12px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 18px 22px;
  border-bottom: 1px solid var(--line);
  background: #ffffff;
  position: sticky;
  top: 0;
  z-index: 10;
}

.mobile-tabs {
  display: none;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: 20px;
}

h2 {
  font-size: 15px;
}

h3 {
  font-size: 13px;
  margin-top: 18px;
  margin-bottom: 8px;
}

.topbar p,
.empty {
  color: var(--muted);
  font-size: 13px;
  margin-top: 4px;
}

.layout {
  display: grid;
  grid-template-columns: minmax(300px, 390px) minmax(250px, 330px) minmax(420px, 1fr);
  gap: 14px;
  padding: 14px;
  align-items: start;
}

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

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 14px;
  min-width: 0;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}

.tag {
  border: 1px solid var(--line);
  background: #f8f9f7;
  color: var(--muted);
  border-radius: 999px;
  padding: 3px 8px;
  font-size: 12px;
  white-space: nowrap;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

label {
  display: grid;
  gap: 5px;
  font-size: 12px;
  color: var(--muted);
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 9px 10px;
  font: inherit;
  color: var(--ink);
  background: #ffffff;
}

input:focus,
select:focus,
textarea:focus {
  outline: 2px solid rgba(36, 92, 122, 0.22);
  border-color: var(--blue);
}

.wide {
  grid-column: 1 / -1;
}

.graded-fields {
  display: none;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #fafafa;
}

.graded-fields.visible,
.edit-graded-fields.visible {
  display: grid;
}

.edit-graded-fields {
  display: none;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #fafafa;
}

button,
.button-link,
.upload-button {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #ffffff;
  color: var(--ink);
  min-height: 36px;
  padding: 8px 11px;
  font: inherit;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

button:hover,
.button-link:hover,
.upload-button:hover {
  border-color: var(--blue);
}

.primary {
  background: var(--accent);
  color: #ffffff;
  border-color: var(--accent);
}

.primary:hover {
  background: var(--accent-dark);
  border-color: var(--accent-dark);
}

.danger {
  color: #ffffff;
  background: #822323;
  border-color: #822323;
}

.danger:hover {
  background: #5d1717;
  border-color: #5d1717;
}

.listing-list {
  display: grid;
  gap: 8px;
}

.listing-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  cursor: pointer;
  background: #ffffff;
}

.listing-card:hover,
.listing-card.active {
  border-color: var(--blue);
  background: #f6fafb;
}

.listing-card strong {
  display: block;
  font-size: 13px;
  margin-bottom: 3px;
}

.listing-card span {
  color: var(--muted);
  font-size: 12px;
}

.packet-preview {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #fbfcfa;
}

.readiness-list,
.status-panel {
  display: grid;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #fbfcfa;
}

.check-row,
.status-row {
  display: grid;
  grid-template-columns: 22px 1fr;
  gap: 8px;
  align-items: start;
  font-size: 13px;
}

.check-dot {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #ffffff;
  font-size: 12px;
  margin-top: 1px;
}

.check-dot.ok {
  background: var(--green);
}

.check-dot.warn {
  background: var(--amber);
}

.check-dot.blocked {
  background: #822323;
}

.helper-text {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
  margin-bottom: 10px;
}

.settings-block + .settings-block {
  margin-top: 18px;
}

.settings-actions {
  margin: 12px 0;
}

.device-list {
  display: grid;
  gap: 8px;
}

.device-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #fbfcfa;
  font-size: 13px;
}

.device-row span {
  color: var(--muted);
  display: block;
  font-size: 12px;
  margin-top: 2px;
}

.packet-preview div {
  min-width: 0;
}

.packet-preview dt {
  color: var(--muted);
  font-size: 11px;
  margin-bottom: 2px;
}

.packet-preview dd {
  margin: 0;
  font-size: 13px;
  overflow-wrap: anywhere;
}

.edit-form {
  margin-top: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fbfcfa;
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.upload-button input {
  display: none;
}

.photo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 10px;
}

.photo-tile {
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: #ffffff;
  position: relative;
}

.photo-tile img {
  width: 100%;
  aspect-ratio: 4 / 5;
  object-fit: cover;
  display: block;
  background: #e5e8e4;
}

.photo-tile div {
  padding: 8px;
  font-size: 12px;
  color: var(--muted);
}

.photo-delete {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 30px;
  min-height: 30px;
  padding: 0;
  border-color: rgba(0, 0, 0, 0.35);
  background: rgba(130, 35, 35, 0.95);
  color: #ffffff;
  font-size: 18px;
  line-height: 1;
}

.thumbnail-preview {
  position: fixed;
  width: 180px;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: #ffffff;
  box-shadow: 0 18px 42px rgba(31, 37, 40, 0.22);
  z-index: 100;
  pointer-events: none;
}

.thumbnail-preview img {
  width: 100%;
  aspect-ratio: 4 / 5;
  object-fit: cover;
  display: block;
}

.thumbnail-preview div {
  padding: 7px 8px;
  font-size: 12px;
  color: var(--ink);
}

.ebay-progress {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  padding: 12px;
  margin-bottom: 10px;
}

.ebay-progress-header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
  margin-bottom: 10px;
}

.ebay-progress-header strong {
  display: block;
  font-size: 14px;
}

.ebay-progress-header span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-top: 2px;
}

.progress-track {
  height: 12px;
  border-radius: 999px;
  background: #eef1ed;
  border: 1px solid var(--line);
  overflow: hidden;
  margin-bottom: 12px;
}

.progress-fill {
  height: 100%;
  width: var(--progress, 0%);
  background: #2d8a57;
  transition: width 180ms ease, background-color 180ms ease;
}

.ebay-progress.working .progress-fill,
.ebay-progress.partial .progress-fill {
  background: #c68a1c;
}

.ebay-progress.failed .progress-fill {
  background: #b8463d;
}

.progress-fill.pulse {
  background-image: linear-gradient(90deg, rgba(255,255,255,0), rgba(255,255,255,0.42), rgba(255,255,255,0));
  background-size: 160px 100%;
  animation: progress-pulse 1s linear infinite;
}

@keyframes progress-pulse {
  from {
    background-position: -160px 0;
  }
  to {
    background-position: 160px 0;
  }
}

.submit-step-list {
  display: grid;
  gap: 8px;
}

.submit-step {
  display: grid;
  grid-template-columns: 18px 1fr;
  gap: 9px;
  align-items: start;
}

.submit-light {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  margin-top: 2px;
  background: #c9d0cb;
  border: 1px solid rgba(31, 37, 40, 0.2);
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.45);
}

.submit-light.success {
  background: #2d8a57;
}

.submit-light.working,
.submit-light.partial {
  background: #d69a20;
}

.submit-light.failed {
  background: #b8463d;
}

.submit-step strong {
  font-size: 13px;
}

.submit-step span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-top: 1px;
}

.raw-output {
  margin-top: 8px;
}

.raw-output summary {
  cursor: pointer;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 6px;
}

pre {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  background: #f8f9f7;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  max-height: 280px;
  overflow: auto;
  font-size: 12px;
}

.description-preview {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  font-size: 13px;
  line-height: 1.45;
  background: #ffffff;
  max-height: 300px;
  overflow: auto;
}

.hidden {
  display: none;
}

@media (max-width: 1100px) {
  .layout {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  body {
    background: #ffffff;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
    gap: 10px;
    padding: 12px 14px;
  }

  .topbar h1 {
    font-size: 18px;
  }

  .topbar p {
    display: none;
  }

  .topbar button {
    width: 100%;
  }

  .mobile-tabs {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 6px;
    padding: 8px;
    position: sticky;
    top: 0;
    z-index: 9;
    background: #ffffff;
    border-bottom: 1px solid var(--line);
  }

  .mobile-tab {
    min-height: 38px;
    padding: 8px 4px;
    font-size: 12px;
  }

  .mobile-tab.active {
    color: #ffffff;
    background: var(--blue);
    border-color: var(--blue);
  }

  .form-grid,
  .graded-fields,
  .edit-graded-fields {
    grid-template-columns: 1fr;
  }

  .layout {
    display: block;
    padding: 0;
  }

  .panel {
    display: none;
    border: 0;
    border-radius: 0;
    box-shadow: none;
    padding: 14px;
    min-height: calc(100vh - 104px);
  }

  .panel.mobile-active {
    display: block;
  }

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

  .button-row > * {
    width: 100%;
  }

  input,
  select,
  textarea,
  button,
  .button-link,
  .upload-button {
    min-height: 44px;
    font-size: 16px;
  }

  label {
    font-size: 13px;
  }

  .photo-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .packet-preview {
    grid-template-columns: 1fr;
  }

  .thumbnail-preview {
    left: 50% !important;
    top: 50% !important;
    transform: translate(-50%, -50%);
    width: min(72vw, 260px);
  }

  pre,
  .description-preview {
    max-height: none;
  }
}
