.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  padding: 9px 16px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-weight: 800;
  text-decoration: none;
}

.button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

.button-primary {
  background: var(--brand-cyan);
  color: var(--on-accent);
}

.button-primary:hover:not(:disabled) {
  background: var(--brand-sky);
}

.button-secondary {
  border-color: var(--line-strong);
  background: var(--surface-raised);
  color: var(--ink);
}

.button-secondary:hover:not(:disabled) {
  border-color: var(--brand-sky);
  background: var(--surface-strong);
}

.button-ghost {
  background: transparent;
  color: var(--muted);
}

.button-small {
  min-height: 40px;
  padding: 6px 11px;
  font-size: 12px;
}

.button-row,
.stack-actions,
.pagination {
  display: flex;
  gap: 10px;
}

.stack-actions {
  flex-direction: column;
}

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

.factory-card {
  position: relative;
  display: grid;
  min-height: 204px;
  padding: 12px 15px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}

.factory-card::before {
  position: absolute;
  top: 0;
  right: 0;
  left: 0;
  height: 4px;
  background: var(--card-accent);
  content: "";
}

.factory-card.selected {
  border-color: var(--card-accent);
  box-shadow:
    0 0 0 1px var(--card-accent),
    var(--shadow-sm);
}

.factory-card-header,
.factory-card-footer,
.workspace-title-row,
.workspace-meta,
.toolbar,
.table-footer,
.file-summary,
.result-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.factory-marker {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 42px;
  min-height: 30px;
  padding: 5px 11px;
  border-radius: 999px;
  border: 1px solid var(--line-strong);
  background: var(--surface-raised);
  box-shadow: inset 3px 0 0 var(--card-accent, var(--factory-accent));
  color: var(--ink);
  font-weight: 900;
}

.factory-card h3 {
  margin: 8px 0 0;
  color: var(--ink);
  font-size: 22px;
  line-height: 1.2;
}

.factory-description {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.sheet-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 8px 0;
}

.chip,
.badge {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  padding: 4px 8px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface-soft);
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}

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

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

.badge.error {
  background: var(--danger-soft);
  color: var(--danger);
}

.factory-card-footer {
  align-items: flex-end;
  margin-top: auto;
  padding-top: 8px;
  border-top: 1px solid var(--line);
}

.factory-meta {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.factory-meta strong,
.factory-meta small {
  overflow: hidden;
}

.factory-meta strong {
  display: -webkit-box;
  overflow-wrap: anywhere;
  font-size: 12px;
  line-height: 1.35;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.factory-meta small {
  text-overflow: ellipsis;
  white-space: nowrap;
}

.factory-meta small {
  color: var(--muted);
}

.upload-card {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(280px, 0.6fr);
  gap: 20px;
  margin-top: 20px;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  scroll-margin-top: 100px;
}

.upload-card h2 {
  margin: 0;
  font-size: 23px;
}

.file-drop {
  display: grid;
  gap: 6px;
  margin: 14px 0 10px;
  padding: 17px;
  border: 2px dashed var(--line-strong);
  border-radius: var(--radius-md);
  background: var(--surface-soft);
  cursor: pointer;
}

.file-drop:hover {
  border-color: var(--factory-accent);
}

.file-drop span,
.upload-help,
.technical-details {
  color: var(--muted);
  font-size: 13px;
}

.file-drop input {
  margin-top: 10px;
  color: var(--muted);
}

.file-drop input[type="file"]::file-selector-button {
  min-height: 40px;
  margin-right: 10px;
  padding: 7px 12px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--surface-raised);
  color: var(--ink);
  cursor: pointer;
  font-weight: 800;
}

.file-drop input[type="file"]::file-selector-button:hover {
  border-color: var(--brand-sky);
  background: var(--surface-strong);
}

.file-summary {
  align-items: flex-start;
  margin-bottom: 14px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface-soft);
}

.file-summary-text {
  display: grid;
  min-width: 0;
}

.file-summary-text strong {
  overflow-wrap: anywhere;
}

.upload-summary {
  padding: 18px;
  border-radius: var(--radius-md);
  border: 1px solid var(--line);
  background: var(--surface-soft);
  color: var(--ink);
}

.upload-summary h3 {
  margin-top: 0;
}

.upload-summary dl,
.qr-summary dl {
  margin: 0;
}

.upload-summary div,
.qr-summary dl div {
  display: grid;
  grid-template-columns: minmax(100px, 0.7fr) minmax(0, 1.3fr);
  gap: 12px;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
}

.upload-summary dt,
.qr-summary dt {
  color: var(--muted);
  font-size: 12px;
}

.upload-summary dd,
.qr-summary dd {
  margin: 0;
  overflow-wrap: anywhere;
  font-weight: 750;
}

.progress-message {
  min-height: 24px;
  margin: 12px 0;
  font-weight: 700;
}

.progress-message.success {
  color: var(--success);
}

.progress-message.error {
  color: var(--danger);
}

.import-result {
  margin-top: 18px;
  padding: 18px;
  border: 1px solid var(--success);
  border-radius: var(--radius-md);
  background: var(--success-soft);
}

.import-result h3 {
  margin: 0;
}

.result-counts {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin: 14px 0;
}

.result-count {
  padding: 12px;
  border-radius: var(--radius-sm);
  background: var(--surface-raised);
}

.result-count strong {
  display: block;
  font-size: 22px;
}

.workspace-hero {
  padding: 18px 22px;
  border-top: 4px solid var(--factory-accent);
  border-radius: var(--radius-md);
  background: var(--navy-900);
  box-shadow: var(--shadow-sm);
  color: var(--ink);
}

.workspace-title {
  display: flex;
  align-items: center;
  gap: 14px;
}

.workspace-title h1 {
  margin: 0;
  font-size: clamp(28px, 3vw, 36px);
  line-height: 1.15;
}

.workspace-meta {
  display: grid;
  grid-template-columns:
    minmax(0, 2.2fr)
    minmax(110px, 0.7fr)
    minmax(180px, 1.1fr)
    minmax(140px, 0.8fr);
  gap: 10px;
  margin-top: 14px;
}

.meta-item {
  display: grid;
  min-width: 0;
  gap: 4px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface-soft);
}

.meta-item span:first-child {
  color: var(--muted);
  font-size: 11px;
}

.meta-item strong {
  overflow-wrap: anywhere;
  line-height: 1.35;
}

.meta-file strong {
  white-space: normal;
}

.table-card {
  margin-top: 16px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}

.table-tabs {
  display: flex;
  gap: 8px;
  padding: 14px 18px 0;
  overflow-x: auto;
}

.tab {
  padding: 10px 14px;
  border: 0;
  border-bottom: 3px solid transparent;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-weight: 800;
  white-space: nowrap;
}

.tab[aria-selected="true"] {
  border-color: var(--factory-accent);
  color: var(--ink);
}

.toolbar {
  align-items: flex-start;
  padding: 16px 18px;
  border-block: 1px solid var(--line);
}

.filter-area {
  display: grid;
  flex: 1;
  gap: 10px;
}

.filter-form {
  display: grid;
  grid-template-columns: minmax(220px, 440px) auto auto;
  gap: 8px;
}

.advanced-filter summary {
  width: fit-content;
  cursor: pointer;
  color: var(--brand-sky);
  font-size: 12px;
  font-weight: 800;
}

.advanced-filter .form-control {
  width: min(440px, 100%);
  margin-top: 8px;
}

.page-size {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
}

.table-status {
  padding: 8px 18px;
  color: var(--muted);
  font-size: 12px;
}

.table-status.error {
  color: var(--danger);
}

.table-scroll {
  width: 100%;
  height: clamp(560px, calc(100vh - 144px), 760px);
  height: clamp(560px, calc(100dvh - 144px), 760px);
  overflow: auto;
}

.data-table {
  width: 100%;
  min-width: 1160px;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 13px;
}

.data-table th,
.data-table td {
  padding: 12px 13px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
  text-align: left;
  vertical-align: top;
}

.data-table th {
  position: sticky;
  z-index: 4;
  top: 0;
  background: var(--surface-raised);
  color: var(--muted);
  font-size: 10px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.data-table tbody tr:hover td {
  background: var(--surface-soft);
}

.data-table .serial-column {
  position: sticky;
  z-index: 3;
  left: 0;
  width: 164px;
  min-width: 164px;
  box-shadow: 1px 0 0 var(--line);
}

.data-table .qr-column {
  position: sticky;
  z-index: 3;
  left: 164px;
  width: 112px;
  min-width: 112px;
  box-shadow: 5px 0 8px rgb(15 37 64 / 8%);
}

.data-table th.serial-column,
.data-table th.qr-column {
  z-index: 6;
  background: var(--surface-strong);
}

.cell-primary,
.cell-secondary {
  display: block;
}

.cell-primary {
  color: var(--ink);
  font-weight: 800;
}

.cell-secondary {
  margin-top: 3px;
  color: var(--muted);
  font-size: 11px;
}

.description-cell {
  min-width: 260px;
  max-width: 380px;
  white-space: normal;
}

.account-cell {
  min-width: 220px;
}

.copy-serial {
  min-height: 40px;
  margin-top: 7px;
  padding: 6px 0;
  border: 0;
  background: transparent;
  color: var(--brand-sky);
  cursor: pointer;
  font-size: 11px;
  font-weight: 800;
}

.table-footer {
  padding: 14px 18px;
  color: var(--muted);
  font-size: 12px;
}

.item-dialog {
  width: min(1020px, calc(100% - 28px));
  max-height: calc(100vh - 28px);
  padding: 0;
  overflow: hidden;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-lg);
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow-lg);
}

.item-dialog::backdrop {
  background: rgb(0 0 0 / 76%);
  backdrop-filter: blur(4px);
}

.dialog-shell {
  margin: 0;
  background: var(--surface);
  color: var(--ink);
}

.dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-soft);
}

.dialog-header h2 {
  margin: 0;
}

.icon-button {
  display: grid;
  width: 40px;
  height: 40px;
  place-items: center;
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  background: var(--surface-raised);
  color: var(--ink);
  cursor: pointer;
  font-size: 22px;
}

.dialog-content {
  max-height: calc(100vh - 118px);
  padding: 22px 24px 30px;
  overflow: auto;
}

.detail-section + .detail-section {
  margin-top: 26px;
}

.detail-section h3 {
  margin: 0 0 8px;
  color: var(--brand-sky);
}

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

.detail-grid div {
  min-width: 0;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}

.detail-grid dt {
  color: var(--muted);
  font-size: 11px;
}

.detail-grid dd {
  margin: 4px 0 0;
  overflow-wrap: anywhere;
  font-weight: 700;
}

.qr-dialog-body {
  display: grid;
  grid-template-columns: minmax(300px, 0.9fr) minmax(280px, 1.1fr);
  gap: 24px;
  max-height: calc(100vh - 118px);
  padding: 24px;
  overflow: auto;
}

.dialog-factory {
  margin-bottom: 5px;
  color: var(--brand-sky);
  font-size: 12px;
  font-weight: 900;
}

.qr-canvas {
  padding: 18px;
  border-radius: var(--radius-md);
  background: var(--surface-soft);
  text-align: center;
}

.qr-canvas img {
  display: block;
  width: min(100%, 320px);
  aspect-ratio: 1;
  margin: 0 auto 14px;
  background: #fff;
  border: 8px solid #fff;
}

.qr-canvas code {
  display: block;
  overflow-wrap: anywhere;
  color: var(--muted);
  font-size: 11px;
}

.qr-summary dl div {
  border-bottom-color: var(--line);
}

.qr-summary dt {
  color: var(--muted);
}

.toast-region {
  position: fixed;
  z-index: 100;
  right: 18px;
  bottom: 18px;
  display: grid;
  gap: 8px;
}

.toast {
  max-width: 380px;
  padding: 12px 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface-raised);
  color: var(--ink);
  box-shadow: var(--shadow-lg);
}

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

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

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

  .factory-card {
    min-height: 190px;
  }
}

@media (max-width: 760px) {
  .factory-card-footer,
  .workspace-title-row,
  .toolbar,
  .table-footer,
  .result-heading {
    align-items: stretch;
    flex-direction: column;
  }

  .workspace-title {
    align-items: flex-start;
  }

  .workspace-meta,
  .result-counts,
  .detail-grid {
    grid-template-columns: 1fr;
  }

  .filter-form {
    grid-template-columns: 1fr;
  }

  .button-row,
  .pagination {
    flex-wrap: wrap;
  }

  .qr-dialog-body {
    grid-template-columns: 1fr;
  }
}

@media print {
  body {
    background: #fff;
  }

  .app-header,
  body > main,
  .toast-region,
  #details-dialog,
  .dialog-header,
  .qr-summary .button {
    display: none !important;
  }

  #qr-dialog {
    position: static;
    display: block;
    width: 100%;
    max-height: none;
    box-shadow: none;
  }

  .qr-dialog-body {
    display: block;
    max-height: none;
    overflow: visible;
  }

  .qr-canvas {
    background: #fff;
  }
}
