:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-soft: #f9fafc;
  --line: #dde3ee;
  --line-strong: #c8d1df;
  --text: #172033;
  --muted: #667085;
  --primary: #2563eb;
  --primary-soft: #eaf1ff;
  --success: #0f9f6e;
  --success-soft: #e7f8f0;
  --warning: #d97706;
  --warning-soft: #fff4df;
  --danger: #dc2626;
  --danger-soft: #fff0f0;
  --shadow: 0 14px 42px rgba(26, 38, 67, 0.12);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(180deg, #f8fafc 0, var(--bg) 280px);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

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

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

i[data-lucide],
svg.lucide {
  width: 16px;
  height: 16px;
  display: inline-flex;
  flex: 0 0 auto;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 236px minmax(0, 1fr);
}

.app-shell.logged-out {
  grid-template-columns: 1fr;
}

.app-shell.logged-out .side-nav,
.app-shell.logged-out .topbar {
  display: none;
}

.side-nav {
  position: sticky;
  top: 0;
  height: 100vh;
  background: rgba(255, 255, 255, 0.92);
  border-right: 1px solid var(--line);
  padding: 18px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  backdrop-filter: blur(12px);
}

.brand {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr);
  align-items: center;
  gap: 12px;
  padding: 4px 4px 18px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 10px;
}

.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: #111827;
  color: #ffffff;
  font-weight: 900;
}

.brand strong,
.brand small {
  display: block;
  white-space: nowrap;
}

.brand strong {
  font-size: 16px;
}

.brand small {
  margin-top: 3px;
  color: var(--success);
  font-size: 12px;
  font-weight: 700;
}

.nav-btn {
  width: 100%;
  border: 0;
  border-radius: var(--radius);
  padding: 12px 13px;
  display: flex;
  align-items: center;
  gap: 10px;
  text-align: left;
  background: transparent;
  color: #48566f;
  cursor: pointer;
  font-weight: 700;
  white-space: nowrap;
}

.nav-btn:hover {
  background: #f1f4f9;
}

.nav-btn.active {
  background: var(--primary-soft);
  color: var(--primary);
  box-shadow: inset 3px 0 0 var(--primary);
}

.workspace {
  min-width: 0;
  padding: 24px;
}

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

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

h1 {
  font-size: 26px;
  line-height: 1.2;
  letter-spacing: 0;
}

h2,
h3,
.login-form h2 {
  display: flex;
  align-items: center;
  gap: 9px;
  letter-spacing: 0;
}

h2 {
  font-size: 18px;
}

h3 {
  font-size: 15px;
}

.topbar p,
.muted {
  color: var(--muted);
  margin-top: 7px;
}

.top-actions,
.toolbar,
.search-box,
.modal-actions,
.block-head {
  display: flex;
  align-items: center;
  gap: 10px;
}

.top-actions {
  flex-wrap: wrap;
  justify-content: flex-end;
}

.toolbar {
  justify-content: space-between;
  margin-bottom: 14px;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.login-panel {
  display: none;
  min-height: 62vh;
  align-items: center;
  justify-content: center;
}

.login-panel.active {
  display: flex;
}

.login-form,
.panel-block,
.table-wrap,
.upload-zone {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 1px 2px rgba(16, 24, 40, 0.04);
}

.login-form {
  width: min(400px, 100%);
  padding: 26px;
  display: grid;
  gap: 16px;
}

label {
  display: grid;
  gap: 7px;
  color: #344054;
  font-size: 13px;
  font-weight: 750;
  white-space: nowrap;
}

.inline-field {
  width: min(520px, 100%);
  grid-template-columns: auto minmax(220px, 1fr);
  align-items: center;
  gap: 10px;
}

input,
select,
textarea {
  width: 100%;
  min-height: 40px;
  border: 1px solid #cfd6e2;
  border-radius: 6px;
  padding: 9px 11px;
  background: #ffffff;
  color: var(--text);
  outline: none;
}

textarea {
  min-height: 96px;
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

.search-box {
  flex: 1;
  max-width: 560px;
}

.search-box input {
  min-width: 260px;
}

.btn,
.icon-btn {
  border: 1px solid transparent;
  border-radius: 6px;
  cursor: pointer;
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  white-space: nowrap;
}

.btn {
  padding: 9px 13px;
  background: #eef2f7;
  color: var(--text);
  font-weight: 800;
}

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

.btn.success {
  background: var(--success);
  color: #ffffff;
}

.btn.ghost {
  background: #ffffff;
  border-color: var(--line-strong);
}

.btn.danger {
  color: var(--danger);
}

.btn.small {
  min-height: 32px;
  padding: 6px 10px;
  font-size: 13px;
}

.btn:hover,
.icon-btn:hover {
  filter: brightness(0.98);
}

.btn:disabled,
.btn[disabled] {
  background: #eef2f7;
  border-color: var(--line);
  color: #98a2b3;
  cursor: not-allowed;
  filter: none;
}

.icon-btn {
  width: 36px;
  height: 36px;
  padding: 0;
  background: #ffffff;
  border-color: var(--line-strong);
  color: var(--muted);
}

.pill,
.status {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 13px;
  font-weight: 800;
  white-space: nowrap;
}

.pill {
  background: #eef2f7;
  color: #344054;
}

.status.uploading {
  background: var(--warning-soft);
  color: var(--warning);
}

.status.selecting {
  background: var(--primary-soft);
  color: var(--primary);
}

.status.confirmed {
  background: var(--success-soft);
  color: var(--success);
}

.status.completed {
  background: #ecfdf3;
  color: #027a48;
}

.status.failed {
  background: var(--danger-soft);
  color: var(--danger);
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  min-width: 900px;
  border-collapse: separate;
  border-spacing: 0;
}

.compact table {
  min-width: 780px;
}

th,
td {
  padding: 13px 14px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
  font-size: 14px;
  white-space: nowrap;
}

th {
  color: #667085;
  background: var(--surface-soft);
  font-weight: 900;
}

tbody tr:hover {
  background: #fbfcff;
}

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

td .row-actions {
  display: flex;
  gap: 8px;
  flex-wrap: nowrap;
}

.code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  color: var(--primary);
  font-weight: 900;
}

.product-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  max-width: 360px;
  white-space: normal;
}

.tag {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 4px 8px;
  background: #f1f5f9;
  color: #334155;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

tr.draggable-row {
  cursor: grab;
}

tr.draggable-row.dragging {
  opacity: 0.48;
}

tr.draggable-row.drop-target {
  box-shadow: inset 0 2px 0 var(--primary);
}

.drag-handle {
  width: 34px;
  height: 30px;
  display: inline-grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #ffffff;
  color: var(--muted);
  cursor: grab;
}

.upload-zone {
  min-height: 176px;
  display: grid;
  place-items: center;
  gap: 7px;
  margin-bottom: 14px;
  border-style: dashed;
  color: var(--muted);
  cursor: pointer;
  text-align: center;
}

.upload-zone > i,
.upload-zone > svg {
  width: 34px;
  height: 34px;
  color: var(--primary);
}

.upload-zone.dragging {
  border-color: var(--primary);
  background: var(--primary-soft);
}

.upload-zone strong {
  color: var(--text);
}

.settings-panel {
  padding: 18px;
  display: grid;
  gap: 18px;
}

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

.check-row {
  min-height: 42px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-soft);
  color: var(--text);
  cursor: pointer;
}

.check-row input {
  width: 18px;
  min-height: 18px;
  height: 18px;
  margin: 0;
  accent-color: var(--primary);
}

.watermark-preview-box {
  display: grid;
  gap: 8px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background:
    linear-gradient(135deg, rgba(15, 23, 42, 0.72), rgba(15, 23, 42, 0.54)),
    linear-gradient(90deg, #d7e4f4, #f5d2a4);
}

.watermark-preview-box span {
  color: rgba(255, 255, 255, 0.72);
  font-size: 12px;
  font-weight: 800;
}

.watermark-preview-box strong {
  width: fit-content;
  max-width: 100%;
  color: rgba(255, 255, 255, 0.82);
  font-size: 15px;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.72);
  overflow: hidden;
  text-overflow: ellipsis;
}

.photo-stats {
  margin: 8px 0 12px;
  color: var(--muted);
}

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

.photo-tile {
  position: relative;
  aspect-ratio: 2 / 3;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  background: #eef2f7;
  cursor: zoom-in;
}

.photo-tile img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
}

.photo-tile span {
  position: absolute;
  left: 6px;
  bottom: 6px;
  right: 6px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  border-radius: 4px;
  padding: 3px 5px;
  background: rgba(17, 24, 39, 0.72);
  color: #ffffff;
  font-size: 12px;
}

.photo-delete {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 28px;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  border: 0;
  padding: 0;
  cursor: pointer;
  background: rgba(220, 38, 38, 0.92);
  color: #ffffff;
  z-index: 2;
  opacity: 0;
  transition: opacity 0.15s ease, background 0.15s ease;
}

.photo-tile:hover .photo-delete,
.photo-delete:focus-visible {
  opacity: 1;
}

.photo-delete:hover {
  background: rgba(185, 28, 28, 1);
}

.photo-preview-modal {
  width: min(920px, calc(100vw - 28px));
}

.photo-preview-stage {
  position: relative;
  min-height: 320px;
  max-height: min(72vh, 760px);
  display: grid;
  place-items: center;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #101828;
}

.photo-preview-stage img {
  max-width: 100%;
  max-height: min(70vh, 720px);
  display: block;
  object-fit: contain;
}

.photo-preview-nav {
  position: absolute;
  top: 50%;
  z-index: 3;
  width: 46px;
  height: 46px;
  border: 1px solid rgba(255, 255, 255, 0.28);
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.56);
  color: #ffffff;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transform: translateY(-50%) scale(0.96);
  transition: opacity 0.16s ease, transform 0.16s ease, background 0.16s ease;
}

.photo-preview-stage:hover .photo-preview-nav,
.photo-preview-nav:focus-visible {
  opacity: 1;
  transform: translateY(-50%) scale(1);
}

.photo-preview-nav.prev {
  left: 14px;
}

.photo-preview-nav.next {
  right: 14px;
}

.photo-preview-nav:hover {
  background: rgba(15, 23, 42, 0.76);
}

.photo-preview-nav:disabled {
  cursor: not-allowed;
  opacity: 0.22;
}

.upload-progress-card {
  position: fixed;
  right: 22px;
  bottom: 22px;
  width: min(420px, calc(100vw - 32px));
  z-index: 90;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.96);
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
}

.download-progress-card {
  bottom: 190px;
}

.upload-progress-head,
.upload-progress-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.progress-actions {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
}

.progress-close {
  width: 28px;
  height: 28px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #ffffff;
  color: var(--muted);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.progress-close:hover {
  color: var(--text);
  border-color: var(--line-strong);
}

.progress-secondary {
  min-height: 28px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #ffffff;
  color: var(--primary);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 850;
  white-space: nowrap;
}

.progress-secondary:hover {
  border-color: var(--primary);
  background: var(--primary-soft);
}

.upload-progress-title {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
  font-weight: 850;
}

.upload-progress-title span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.upload-progress-state {
  flex: 0 0 auto;
  border-radius: 999px;
  padding: 4px 9px;
  background: var(--primary-soft);
  color: var(--primary);
  font-size: 12px;
  font-weight: 850;
}

.upload-progress-state.success {
  background: var(--success-soft);
  color: var(--success);
}

.upload-progress-state.warning {
  background: var(--warning-soft);
  color: var(--warning);
}

.upload-progress-row {
  margin-top: 12px;
  color: var(--muted);
  font-size: 13px;
}

.upload-progress-row strong {
  color: var(--text);
  font-size: 22px;
  line-height: 1;
}

.upload-progress-track {
  height: 9px;
  margin-top: 10px;
  overflow: hidden;
  border-radius: 999px;
  background: #e8edf5;
}

.upload-progress-fill {
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--primary), #0f9f6e);
  transition: width 0.18s ease;
}

.upload-progress-detail {
  margin-top: 9px;
  color: var(--muted);
  font-size: 13px;
}

.upload-current-file {
  min-height: 18px;
  margin-top: 5px;
  overflow: hidden;
  color: #344054;
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.split-layout {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  gap: 14px;
}

.panel-block {
  padding: 15px;
}

.block-head {
  justify-content: space-between;
  margin-bottom: 12px;
}

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

.type-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  padding: 11px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #ffffff;
}

.type-item strong {
  display: block;
  white-space: nowrap;
}

.type-item small {
  color: var(--muted);
  white-space: nowrap;
}

.modal {
  width: min(960px, calc(100vw - 28px));
  border: 0;
  border-radius: var(--radius);
  padding: 0;
  box-shadow: var(--shadow);
}

.modal::backdrop {
  background: rgba(15, 23, 42, 0.38);
}

.modal-body {
  padding: 20px;
  display: grid;
  gap: 16px;
}

.modal-body.narrow {
  width: min(420px, calc(100vw - 28px));
}

.modal-head,
.modal-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.modal-actions {
  justify-content: flex-end;
  padding-top: 2px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.full-label {
  display: grid;
}

.modal-section {
  display: grid;
  gap: 10px;
  padding-top: 2px;
}

.product-rows {
  display: grid;
  gap: 10px;
}

.product-row {
  display: grid;
  grid-template-columns: minmax(170px, 1.2fr) 130px minmax(150px, 1fr) 82px 112px 126px 40px;
  gap: 10px;
  align-items: end;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-soft);
}

.product-row button {
  min-height: 40px;
}

.order-limit-hint {
  min-height: 20px;
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 750;
}

.order-limit-hint.error {
  color: var(--danger);
}

.field-error {
  border-color: var(--danger) !important;
  box-shadow: 0 0 0 3px var(--danger-soft);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%) translateY(30px);
  opacity: 0;
  pointer-events: none;
  background: #111827;
  color: #ffffff;
  border-radius: 6px;
  padding: 10px 14px;
  transition: opacity 0.18s ease, transform 0.18s ease;
  z-index: 100;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

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

  .product-row {
    grid-template-columns: repeat(3, minmax(0, 1fr)) 40px;
  }
}

@media (max-width: 860px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .side-nav {
    position: sticky;
    height: auto;
    top: 0;
    z-index: 10;
    flex-direction: row;
    align-items: center;
    overflow-x: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .brand {
    min-width: 170px;
    border-bottom: 0;
    margin-bottom: 0;
    padding-bottom: 0;
  }

  .nav-btn {
    min-width: 84px;
    justify-content: center;
  }

  .workspace {
    padding: 14px;
  }

  .upload-progress-card {
    right: 12px;
    bottom: 12px;
    width: calc(100vw - 24px);
  }

  .download-progress-card {
    bottom: 176px;
  }

  .topbar,
  .toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .top-actions,
  .search-box,
  .modal-actions {
    flex-wrap: wrap;
    justify-content: flex-start;
  }

  .search-box {
    max-width: none;
  }

  .search-box input {
    min-width: 0;
  }

  .form-grid,
  .product-row {
    grid-template-columns: 1fr;
  }

  label {
    white-space: normal;
  }
}
