:root {
  --ink: #17222c;
  --muted: #8a97a3;
  --text: #5c6b78;
  --line: #e1e6ea;
  --line-soft: #eef1f4;
  --bg: #eef1f4;
  --paper: #ffffff;
  --brand: #1568a8;
  --brand-soft: #e8f1f9;
  --good: #1f8a4c;
  --good-bg: #e6f4ea;
  --flag: #c2410c;
  --flag-bg: #fdf1e0;
  --flag-text: #a15c00;
  --soon: #9aa6b1;
  --font: "Inter", "Helvetica Neue", Helvetica, Arial, sans-serif;
  --mono: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  --sidebar: 248px;
  --topbar: 64px;
  --content-pad: 28px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.45 var(--font);
}

body.app {
  display: flex;
  min-height: 100%;
}

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: #cfd6dc; border-radius: 4px; }

button, input {
  font: inherit;
}

/* Sidebar */
.sidebar {
  width: var(--sidebar);
  flex-shrink: 0;
  background: var(--paper);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
}

.sidebar-brand {
  padding: 22px 20px 18px;
  border-bottom: 1px solid var(--line-soft);
}

.sidebar-brand img {
  height: 30px;
  width: auto;
  display: block;
}

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 16px 12px;
}

body.is-user .sidebar-user {
  margin-top: auto;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 9px 10px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: #3d4a56;
  font-size: 13.5px;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
  margin-bottom: 2px;
}

.nav-item svg {
  flex-shrink: 0;
}

.nav-item.is-active {
  background: var(--brand);
  color: #fff;
}

.nav-item.is-soon {
  color: #aab3bc;
  cursor: default;
}

.nav-icon {
  width: 18px;
  height: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.nav-label { flex: 1; }

.nav-soon {
  font-size: 10px;
  font-weight: 700;
  background: var(--line-soft);
  color: var(--soon);
  padding: 2px 6px;
  border-radius: 4px;
}

.nav-heading {
  margin: 22px 8px 8px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: #9aa6b1;
  text-transform: uppercase;
}

.nav-request {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
  padding: 9px 10px;
  border-radius: 8px;
  border: 1px dashed #d7dde2;
  color: var(--text);
  background: transparent;
  font-size: 13px;
  cursor: default;
}

.sidebar-user {
  border-top: 1px solid var(--line-soft);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
}

.avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--brand);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 12px;
  flex-shrink: 0;
}

.avatar.soft {
  background: var(--brand-soft);
  color: var(--brand);
}

.sidebar-user strong {
  display: block;
  font-size: 13px;
  font-weight: 600;
}

.sidebar-user span {
  display: block;
  font-size: 11.5px;
  color: var(--muted);
}

.logout-form {
  width: 100%;
  margin-top: 4px;
}

.logout-btn {
  appearance: none;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  border-radius: 8px;
  padding: 7px 10px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  width: 100%;
}

.logout-btn:hover { background: #f9fafb; }

/* Shell */
.shell {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.topbar {
  height: var(--topbar);
  flex-shrink: 0;
  background: var(--paper);
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 28px;
  gap: 16px;
}

.crumb {
  font-size: 11.5px;
  color: var(--muted);
  font-weight: 600;
}

.page-title {
  margin: 1px 0 0;
  font-size: 18px;
  font-weight: 700;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.status {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  margin: 0;
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
}

.status i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #64748b;
}

.status.is-ok i { background: #22c55e; }
.status.is-bad i { background: #ef4444; }
.status.is-busy i {
  background: var(--brand);
  box-shadow: 0 0 0 4px rgba(21, 104, 168, 0.18);
  animation: pulse 1.4s ease-in-out infinite;
}

@keyframes pulse {
  50% { opacity: 0.55; }
}

.actions {
  display: flex;
  gap: 0.45rem;
}

.actions a,
.actions button,
.pager-btn {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--paper);
  color: var(--ink);
  border-radius: 8px;
  padding: 9px 16px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.actions a,
.actions button,
a.pager-btn {
  text-decoration: none;
}

a.pager-btn {
  display: inline-block;
}

.actions a.primary,
.actions button.primary {
  background: var(--brand);
  color: #fff;
  border-color: var(--brand);
}

.actions button.stop {
  border-color: #e8b4b4;
  color: #b42318;
  background: #fff;
}

.actions button:disabled,
.pager-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.actions button[hidden] {
  display: none;
}

.icon-btn {
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 8px;
  background: #f4f6f8;
  color: var(--ink);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  cursor: default;
}

.icon-btn .dot {
  position: absolute;
  top: 7px;
  right: 8px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--flag);
}

.content {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: var(--content-pad, 28px);
}

.view[hidden] { display: none !important; }

/* Keep vertical padding as card margin; scroll inside the form, not the page */
.content:has(.is-file-detail) {
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.content:has(.is-file-detail) > .flash-host:empty {
  display: none;
}

.content:has(.is-file-detail) > .view:not([hidden]) {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Data nests the detail panel inside #data-card — pass height through */
#view-data:has(.is-file-detail) > #data-card {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 0;
  background: transparent;
}

.flash-host { min-height: 0; }

.flash {
  margin: 0 0 1.25rem;
  padding: 0.7rem 0.9rem;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
}

.flash.ok { background: var(--good-bg); color: var(--good); }
.flash.err { background: #fdecec; color: #b42318; }

/* Cards */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 18px;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 20px;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin-bottom: 20px;
}

.card {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 12px;
}

.card.pad { padding: 22px; }
.card.metric { padding: 16px 18px; }
.card.clickable {
  cursor: pointer;
  transition: box-shadow 0.15s;
}
.card.clickable:hover { box-shadow: 0 6px 18px rgba(23, 34, 44, 0.06); }
.card.is-soon { opacity: 0.6; }
.card.dashed {
  border-style: dashed;
  border-color: #d7dde2;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  text-align: center;
  min-height: 170px;
  background: transparent;
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.tool-icon {
  width: 38px;
  height: 38px;
  border-radius: 9px;
  background: var(--brand-soft);
  color: var(--brand);
  display: flex;
  align-items: center;
  justify-content: center;
}

.tool-icon.muted {
  background: #f4f6f8;
  color: var(--soon);
}

.pill {
  font-size: 11px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 20px;
  background: var(--good-bg);
  color: var(--good);
}

.pill.soon {
  background: #f4f6f8;
  color: var(--soon);
}

.card-title {
  font-size: 16px;
  font-weight: 700;
  margin-top: 14px;
}

.card-copy {
  font-size: 13px;
  color: var(--text);
  margin-top: 4px;
  line-height: 1.5;
}

.card.is-soon .card-title,
.card.is-soon .card-copy { color: var(--soon); }

.card-stats {
  display: flex;
  gap: 20px;
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--line-soft);
}

.card-stats strong {
  display: block;
  font-size: 20px;
  font-weight: 700;
}

.card-stats span {
  display: block;
  font-size: 11.5px;
  color: var(--muted);
}

.card-stats .is-flag { color: var(--flag); }

.metric-label {
  font-size: 11.5px;
  color: var(--muted);
}

.metric-value {
  font-size: 22px;
  font-weight: 700;
  margin-top: 4px;
}

.metric-value.is-flag { color: var(--flag); }
.metric-value.is-good { color: var(--good); }
.metric-value.path {
  font-size: 13px;
  font-weight: 600;
  margin-top: 6px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-family: var(--mono);
}

.plus { font-size: 24px; line-height: 1; }
.card.dashed small { font-size: 13px; margin-top: 8px; }

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

.panel-head {
  padding: 16px 20px;
  border-bottom: 1px solid var(--line-soft);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.panel-head h2 {
  margin: 0;
  font-size: 14.5px;
  font-weight: 700;
}

.panel-head .lede {
  margin: 2px 0 0;
  font-size: 11.5px;
  color: var(--muted);
}

.panel-meta {
  font-size: 12px;
  color: var(--muted);
}

.issues.is-empty { display: none; }

.issues.is-rerun .issues-count {
  background: #e7eef8;
  color: #1e3a5f;
}

.issues.is-rerun .issue {
  border-color: #d5deea;
  background: #f7f9fc;
}

.issues {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 16px 20px;
  margin-bottom: 18px;
}

.issues-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.issues-toggle-btn {
  appearance: none;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  font-size: 14.5px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 0;
  cursor: pointer;
}

.issues-chevron {
  color: var(--muted);
  display: inline-block;
  width: 0.8rem;
  transition: transform 0.15s ease;
}

.issues.is-open .issues-chevron {
  transform: rotate(90deg);
}

.issues-count {
  min-width: 1.4rem;
  height: 1.4rem;
  padding: 0 6px;
  border-radius: 999px;
  background: #fde8e6;
  color: #9b2c2c;
  font-size: 12px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.issues-bar .primary {
  appearance: none;
  border: 1px solid var(--brand);
  background: var(--brand);
  color: #fff;
  border-radius: 8px;
  padding: 8px 12px;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.issues-body {
  margin-top: 14px;
}

.issues h1 {
  margin: 0 0 0.35rem;
  font-size: 14.5px;
}

.lede {
  margin: 0 0 1rem;
  color: var(--muted);
}

.issue-list,
.files {
  list-style: none;
  margin: 0;
  padding: 0;
}

.issue {
  display: block;
  width: 100%;
  text-align: left;
  appearance: none;
  border: 1px solid #f0c7c2;
  background: #fff8f7;
  border-radius: 10px;
  padding: 0.85rem 1rem;
  font: inherit;
  cursor: pointer;
}

.issue-list li + li { margin-top: 0.55rem; }

.issue-row {
  display: flex;
  gap: 10px;
  align-items: stretch;
}

.issue-row .issue { flex: 1; min-width: 0; }

.issue-action {
  appearance: none;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  border-radius: 10px;
  padding: 0.7rem 0.9rem;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  align-self: center;
}

.issue-action:hover { background: #f9fafb; }

.issues h2 {
  margin: 1.1rem 0 0.5rem;
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
}

.issue strong { display: block; font-size: 14px; }
.issue span { display: block; margin-top: 0.15rem; color: #8a3b34; font-size: 13px; }
.issue em { display: block; margin-top: 0.35rem; color: var(--muted); font-style: normal; font-size: 12px; }

.run {
  border-top: 1px solid var(--line-soft);
}

.run:first-child { border-top: 0; }

.run summary {
  display: grid;
  grid-template-columns: minmax(8.5rem, auto) 1fr;
  gap: 0.65rem 1rem;
  align-items: baseline;
  padding: 0.95rem 1.1rem;
  cursor: pointer;
  list-style: none;
}

.run summary::-webkit-details-marker { display: none; }

.run[open] summary { background: #f9fafb; }

.when { font-weight: 650; }
.sum { color: var(--muted); font-size: 13px; font-weight: 600; }
.sum { justify-self: end; }

.files { padding: 0.2rem 0.55rem 0.55rem; }

.file {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr) auto;
  gap: 0.55rem;
  align-items: center;
  width: 100%;
  text-align: left;
  appearance: none;
  border: 1px solid var(--line-soft);
  background: #fafbfc;
  border-radius: 10px;
  padding: 0.7rem 0.85rem;
  font: inherit;
  cursor: pointer;
}

.files li + li { margin-top: 0.45rem; }

.file .from { color: var(--muted); overflow-wrap: anywhere; }
.file .to { font-weight: 600; overflow-wrap: anywhere; font-family: var(--mono); font-size: 12.5px; }
.file .arrow { color: #c5cad3; }

.tag {
  justify-self: end;
  padding: 3px 9px;
  border-radius: 20px;
  background: #eef0f4;
  color: #4b5563;
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
}

.tag.ok, .tag.updated { background: var(--good-bg); color: var(--good); }
.tag.bad, .tag.failed { background: var(--flag-bg); color: var(--flag-text); }
.tag.previewed { background: var(--brand-soft); color: var(--brand); }
.tag.pending { background: #f4f6f8; color: #4b5563; }

.empty {
  margin: 0;
  color: var(--muted);
  padding: 18px 20px;
}

.empty.nested { padding: 0.85rem 1.1rem 1.05rem; }

#folder-list.is-loading {
  opacity: 0.55;
  pointer-events: none;
}

.folder-files {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 520px;
  overflow-y: auto;
}

.folder-files li + li { border-top: 1px solid var(--line-soft); }

.folder-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 20px;
  text-align: left;
  appearance: none;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  text-decoration: none;
  cursor: pointer;
}

a.folder-item:hover,
button.folder-item:hover { background: #f9fafb; }

.folder-item.is-static { cursor: default; }

.pdf-badge {
  width: 32px;
  height: 32px;
  border-radius: 7px;
  background: var(--brand-soft);
  color: var(--brand);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 9px;
  font-weight: 700;
  flex-shrink: 0;
}

.file .cust,
.file .serial,
.folder-item .cust {
  color: var(--muted);
  font-size: 11px;
  font-weight: 500;
}

.file .cust,
.file .serial { grid-column: 1 / -1; }

.file .serial {
  color: #355e7a;
}

.sheet-colour {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  max-width: 100%;
}

.sheet-swatch {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 1px solid rgba(23, 34, 44, 0.12);
  flex-shrink: 0;
}

.sheet-swatch.is-pink { background: #f4b6c8; }
.sheet-swatch.is-blue { background: #8bb8e8; }
.sheet-swatch.is-green { background: #8fce8f; }
.sheet-swatch.is-orange { background: #f0b27a; }
.sheet-swatch.is-yellow { background: #f6e27a; }
.sheet-swatch.is-grey { background: #b8c0c7; }

.folder-item .file-main {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
  flex: 1;
}

.folder-item .name {
  font-weight: 600;
  font-family: var(--mono);
  font-size: 12.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.folder-item .meta {
  color: var(--muted);
  font-size: 11px;
  white-space: nowrap;
}

.flag-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--flag);
  flex-shrink: 0;
}

.folder-pager {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 12px 16px;
  border-top: 1px solid var(--line-soft);
}

.pager-status {
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}

.panel-head.customers-toolbar {
  gap: 16px;
  flex-wrap: wrap;
}

.customers-tools {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
}

.search-field {
  margin: 0;
  min-width: 180px;
  width: min(280px, 100%);
  flex: 0 1 280px;
}

.search-field.data-search-field {
  min-width: 0;
  width: auto;
  flex: 1 1 auto;
  margin: 0;
}

.data-search-cluster {
  display: flex;
  align-items: stretch;
  flex: 1 1 280px;
  min-width: min(280px, 100%);
  max-width: 440px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  overflow: hidden;
}

.data-search-cluster:focus-within {
  outline: 2px solid var(--brand-soft);
  border-color: var(--brand);
}

.data-search-cluster .search-field input {
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
}

.data-search-cluster .search-field input:focus {
  outline: none;
  border: 0;
  box-shadow: none;
}

.batch-advanced-check {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin: 0;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}

.batch-advanced-check input {
  margin: 0;
  accent-color: var(--brand);
}

.batch-advanced-check:has(input:checked) {
  color: var(--brand);
  border-color: var(--brand);
  background: color-mix(in srgb, var(--brand) 8%, #fff);
}

.batch-advanced-check:has(input:disabled) {
  opacity: 0.55;
  cursor: not-allowed;
}

.data-advanced-check {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
  margin: 0;
  padding: 0 12px;
  border-left: 1px solid var(--line-soft);
  font-size: 12.5px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
  background: #fafbfc;
}

.data-advanced-check input {
  margin: 0;
  accent-color: var(--brand);
}

.data-advanced-check:has(input:checked) {
  color: var(--brand);
  background: color-mix(in srgb, var(--brand) 8%, #fff);
}

.search-field input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 12px;
  font-size: 13.5px;
  color: var(--ink);
  background: #fff;
}

.search-field input:focus {
  outline: 2px solid var(--brand-soft);
  border-color: var(--brand);
}

.customer-pager {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.customer-pager[hidden] {
  display: none;
}

.customer-pager .pager-btn {
  width: 28px;
  height: 28px;
  padding: 0;
  border-radius: 6px;
  font-size: 16px;
  font-weight: 500;
  color: var(--muted);
  line-height: 1;
}

.customer-pager .pager-btn:hover:not(:disabled) {
  color: var(--ink);
  background: #f4f6f8;
}

.customer-pager .pager-status {
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
  min-width: 2.75em;
  text-align: center;
}

.data-tools {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-left: auto;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.data-tools-aside {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.data-select {
  margin: 0;
}

.data-select select {
  appearance: none;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 28px 9px 12px;
  font: inherit;
  font-size: 13.5px;
  color: var(--ink);
  background: #fff url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'><path fill='%238a97a3' d='M1 1l5 5 5-5'/></svg>") no-repeat right 10px center;
  min-width: 148px;
  max-width: 220px;
}

.data-select select:focus {
  outline: 2px solid var(--brand-soft);
  border-color: var(--brand);
}

.data-select select:disabled {
  color: var(--muted);
  background-color: #f7f8fa;
}

#view-data,
#data-card {
  max-width: 100%;
  min-width: 0;
}

#data-card .table-scroll {
  overflow-x: hidden;
  max-width: 100%;
}

.data-table.data-explorer {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  table-layout: fixed;
}

.data-table.data-explorer th,
.data-table.data-explorer td {
  overflow: hidden;
  vertical-align: middle;
}

.cell-clip {
  display: block;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

a.file-link {
  color: var(--ink);
  text-decoration: none;
  font: inherit;
}

a.file-link:hover {
  color: var(--brand);
  text-decoration: underline;
}

.data-table .is-sortable {
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}

.data-table th.is-draggable {
  cursor: grab;
}

.data-table th.is-dragging {
  opacity: 0.45;
}

.data-table th.is-drop-target {
  box-shadow: inset 2px 0 0 var(--brand);
}

.data-table .is-sortable:hover {
  color: var(--ink);
}

.data-table .tag {
  justify-self: auto;
  display: inline-block;
}

.data-table .udi {
  font-size: 11.5px;
  font-weight: 500;
}

.data-row {
  cursor: pointer;
}

.data-row:hover {
  background: #f4f8fb;
}

.text-btn {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--brand);
  font: inherit;
  font-weight: 600;
  padding: 0 0 8px;
  cursor: pointer;
}

.actions a.download-btn {
  background: var(--paper);
  color: var(--ink);
}

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

.file-detail > div {
  padding: 14px 20px;
  border-top: 1px solid var(--line-soft);
}

.file-detail dt {
  color: var(--muted);
  font-size: 11.5px;
  font-weight: 600;
  margin-bottom: 4px;
}

.file-detail dd {
  margin: 0;
  font-size: 14px;
  word-break: break-word;
}

.file-detail.is-editing dd input,
.file-detail.is-editing dd select {
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  font: inherit;
  background: #fff;
  color: var(--ink);
}

.file-detail.is-editing .serial-edit-row dd {
  display: flex;
  gap: 8px;
  align-items: center;
}

.file-detail.is-editing .serial-edit-row input {
  flex: 1;
}

.file-detail .udi-full {
  font-family: var(--mono);
  font-size: 13px;
  font-weight: 600;
  word-break: break-all;
}

#data-detail-panel.is-file-detail,
#tool-detail-panel.is-file-detail {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
  height: calc(100vh - var(--topbar) - (var(--content-pad, 28px) * 2));
  max-height: calc(100vh - var(--topbar) - (var(--content-pad, 28px) * 2));
  overflow: hidden;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 12px;
}

.is-file-detail > .panel-head {
  flex-shrink: 0;
}

.file-detail-split {
  display: grid;
  grid-template-columns: minmax(18rem, 1fr) minmax(20rem, 1fr);
  grid-template-rows: minmax(0, 1fr);
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
}

.file-detail-meta {
  overflow: hidden;
  border-right: 1px solid var(--line-soft);
  background: #fff;
  display: flex;
  flex-direction: column;
  min-height: 0;
  height: 100%;
  max-height: 100%;
}

.file-detail-meta > .file-detail-scroll {
  flex: 1 1 0;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.extracted-text {
  margin: 0;
  padding: 14px 20px 18px;
  border-top: 1px solid var(--line-soft);
  flex: 0 0 auto;
}

.extracted-text.is-empty .extracted-text-summary {
  display: block;
  font-size: 0.82rem;
  color: var(--muted, #6b7280);
}

.extracted-text > summary {
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  cursor: pointer;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--ink, #111827);
  user-select: none;
}

.extracted-text > summary::-webkit-details-marker {
  display: none;
}

.extracted-text-actions {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  flex-shrink: 0;
}

.extracted-text-copy {
  appearance: none;
  border: 1px solid var(--line, #e5e7eb);
  background: #fff;
  color: var(--ink, #111827);
  border-radius: 6px;
  padding: 3px 8px;
  font-size: 0.72rem;
  font-weight: 600;
  line-height: 1.2;
  cursor: pointer;
}

.extracted-text-copy:hover {
  background: #f8fafc;
}

.extracted-text-copy.is-copied {
  border-color: #86efac;
  background: #f0fdf4;
  color: #166534;
}

.extracted-text-chevron {
  font-size: 0.75rem;
  line-height: 1;
  color: var(--muted, #6b7280);
  transition: transform 0.15s ease;
}

.extracted-text[open] > summary .extracted-text-chevron {
  transform: rotate(180deg);
}

.extracted-text-body {
  margin: 0.55rem 0 0;
  max-height: 14rem;
  overflow: auto;
  padding: 0.65rem 0.75rem;
  border-radius: 8px;
  background: #f8fafc;
  border: 1px solid var(--line, #e5e7eb);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.75rem;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
  color: #334155;
}

.file-detail-form {
  display: flex;
  flex-direction: column;
  flex: 1 1 0;
  min-height: 0;
  height: 100%;
  max-height: 100%;
  overflow: hidden;
}

.file-detail-form .file-detail {
  flex: 1 1 0;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.file-detail-form-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  padding: 14px 20px 18px;
  border-top: 1px solid var(--line-soft);
  background: #fff;
  flex-shrink: 0;
}

.file-detail-form-actions .pager-btn,
.file-detail-form-actions .primary {
  width: 100%;
  justify-content: center;
  text-align: center;
  appearance: none;
  border: 1px solid var(--line);
  background: var(--paper);
  color: var(--ink);
  border-radius: 8px;
  padding: 9px 16px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.file-detail-form-actions .primary {
  background: var(--brand);
  color: #fff;
  border-color: var(--brand);
}

.file-detail-form-actions .primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

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

.file-detail-split .file-detail > div:first-child {
  border-top: 0;
}

.file-detail-split .file-detail > div:nth-child(2) {
  border-top: 0;
}

/* Full-width rows for long values / actions */
.file-detail-split .file-detail > div:has(.udi-full),
.file-detail-split .file-detail > div:has(#file-detail-add-sn),
.file-detail-split .file-detail.is-editing > div:has(input[name="serial_udi"]),
.file-detail-split .file-detail.is-editing > div:has(input[name="new_name"]) {
  grid-column: 1 / -1;
}

.file-detail-meta-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  flex: 1;
  min-height: 12rem;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}

.file-detail-preview {
  position: relative;
  min-height: 0;
  height: 100%;
  max-height: 100%;
  overflow: hidden;
  background: #edf0f3;
}

.file-detail-preview iframe {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
  background: #edf0f3;
}

.file-detail-preview-loading {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: #edf0f3;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}

.file-detail-preview.is-loading .file-detail-preview-loading {
  display: flex;
}

.file-detail-preview.is-loading iframe {
  opacity: 0;
}

.spinner {
  width: 28px;
  height: 28px;
  border: 3px solid #d5dbe3;
  border-top-color: var(--brand, #1f6feb);
  border-radius: 50%;
  animation: rms-spin 0.7s linear infinite;
}

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

@media (max-width: 960px) {
  .file-detail-split {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(0, 42%) minmax(0, 58%);
  }

  .file-detail-meta {
    border-right: 0;
    border-bottom: 1px solid var(--line-soft);
    max-height: none;
    height: auto;
  }

  .file-detail-preview {
    min-height: 0;
    height: auto;
  }

  .file-detail-split .file-detail {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 800px) {
  .file-detail {
    grid-template-columns: 1fr;
  }
}

.data-group + .data-group {
  border-top: 1px solid var(--line);
}

.data-group-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 20px;
  background: #f4f7fa;
  border-bottom: 1px solid var(--line-soft);
}

.data-group-head strong {
  font-size: 13.5px;
}

.data-group-head span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.data-group .data-table th {
  background: #fbfcfd;
}

@media (max-width: 1100px) {
  .data-tools {
    width: 100%;
    margin-left: 0;
    justify-content: flex-start;
  }

  .data-search-cluster {
    flex: 1 1 100%;
    max-width: none;
  }
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}

.data-table th {
  text-align: left;
  padding: 12px 20px;
  color: var(--muted);
  font-weight: 600;
  font-size: 11.5px;
  background: #f9fafb;
}

.data-table td {
  padding: 13px 20px;
  border-top: 1px solid var(--line-soft);
}

.data-table .num { font-weight: 600; }
.data-table .mono {
  font-family: var(--mono);
  font-size: 12.5px;
  font-weight: 600;
}

.cust-row {
  cursor: pointer;
}

.cust-row:hover { background: #f4f8fb; }

.cust-row.is-open {
  background: var(--brand-soft);
  box-shadow: inset 3px 0 0 var(--brand);
}

.cust-row.is-open td:first-child {
  font-weight: 700;
  color: var(--brand);
}

.cust-row .chevron {
  color: #aab3bc;
  text-align: right;
  font-size: 16px;
  line-height: 1;
  transition: transform 0.15s;
}

.cust-row.is-open .chevron {
  color: var(--brand);
  transform: none;
}

.cust-orders td {
  padding: 0 16px 16px 23px;
  background: #e8f1f9;
  border-top: 0;
}

.order-panel {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 6px 16px rgba(23, 34, 44, 0.08);
}

.order-panel-head {
  padding: 11px 16px;
  font-size: 12.5px;
  font-weight: 700;
  color: var(--brand);
  background: #f9fafb;
  border-bottom: 1px solid var(--line-soft);
}

.order-panel .empty {
  padding: 14px 16px;
}

.order-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.order-table th {
  text-align: left;
  padding: 9px 20px;
  color: var(--muted);
  font-weight: 600;
  font-size: 11.5px;
  background: #f4f6f8;
}

.order-table td {
  padding: 11px 20px;
  border-top: 1px solid var(--line-soft);
  background: #fff;
}

.order-table tr.order-row { cursor: pointer; }
.order-table tr.order-row:hover td { background: #f9fafb; }

.card.admin-add { margin-top: 16px; }

.admin-form {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px 16px;
  padding: 16px 20px 20px;
  align-items: end;
}

.admin-form label {
  display: block;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--muted);
}

.admin-form input[type="text"],
.admin-form input[type="email"],
.admin-form input[type="password"],
.admin-form select {
  display: block;
  width: 100%;
  margin-top: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 12px;
  font-size: 13.5px;
  color: var(--ink);
  background: #fff;
}

.admin-form label.check {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 500;
  color: var(--ink);
}

.admin-form label.check input {
  margin: 0;
}

.admin-form .primary {
  justify-self: start;
  appearance: none;
  border: 1px solid var(--brand);
  background: var(--brand);
  color: #fff;
  border-radius: 8px;
  padding: 9px 16px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.admin-form .primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.user-actions-col {
  width: 56px;
  text-align: right;
}

.user-menu {
  position: relative;
  display: inline-flex;
  justify-content: flex-end;
}

.user-more {
  cursor: pointer;
  background: transparent;
}

.user-more:hover,
.user-more[aria-expanded="true"] {
  background: #f4f6f8;
}

.user-menu-pop {
  position: absolute;
  right: 0;
  top: calc(100% + 4px);
  z-index: 8;
  min-width: 168px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(16, 24, 32, 0.12);
  padding: 4px;
  display: flex;
  flex-direction: column;
}

.user-menu-pop[hidden] {
  display: none;
}

.user-menu-pop button {
  appearance: none;
  border: 0;
  background: transparent;
  text-align: left;
  padding: 8px 10px;
  border-radius: 6px;
  font-size: 13px;
  color: var(--ink);
  cursor: pointer;
}

.user-menu-pop button:hover {
  background: #f4f6f8;
}

.admin-form.user-screen-form {
  grid-template-columns: minmax(0, 420px);
  max-width: 480px;
}

.user-reset-form label {
  display: block;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--muted);
}

.user-reset-form input[type="password"] {
  display: block;
  width: 100%;
  margin-top: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 12px;
  font-size: 13.5px;
  color: var(--ink);
  background: #fff;
}

.user-form-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.user-reset-form .primary,
.user-form-actions .primary {
  appearance: none;
  border: 1px solid var(--brand);
  background: var(--brand);
  color: #fff;
  border-radius: 8px;
  padding: 9px 16px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.user-form-actions .primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.switch {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
}

.switch input {
  accent-color: var(--brand);
  width: 16px;
  height: 16px;
}

.switch:has(input:checked) {
  color: var(--good);
}

@media (max-width: 1100px) {
  .stat-grid,
  .workspace,
  .metric-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 860px) {
  body.app { flex-direction: column; }
  .sidebar {
    width: 100%;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
  .sidebar-nav { display: flex; flex-wrap: wrap; gap: 4px; padding: 10px 12px; }
  .nav-heading, .nav-item.is-soon, .nav-request { display: none; }
  .sidebar-user { display: flex; }
  .nav-item { width: auto; margin: 0; }
  .topbar { height: auto; padding: 12px 16px; flex-wrap: wrap; }
  .content { --content-pad: 16px; padding: var(--content-pad); }
  .run summary, .file { grid-template-columns: 1fr; }
  .issue-row { flex-direction: column; }
  .admin-form { grid-template-columns: 1fr; }
}

body.login-page {
  min-height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px 16px;
  background: var(--bg);
}

.login-card {
  width: min(400px, 100%);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 32px 28px;
}

.login-logo {
  height: 30px;
  width: auto;
  display: block;
}

.login-card h1 {
  margin: 18px 0 6px;
  font-size: 22px;
  font-weight: 700;
}

.login-card p {
  margin: 0 0 18px;
  color: var(--text);
  font-size: 13.5px;
}

.login-form label {
  display: block;
  margin-bottom: 12px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text);
}

.login-form input {
  display: block;
  width: 100%;
  margin-top: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 14px;
  color: var(--ink);
  background: #fff;
}

.login-form input:focus {
  outline: 2px solid var(--brand-soft);
  border-color: var(--brand);
}

.login-form button.primary {
  appearance: none;
  width: 100%;
  margin-top: 8px;
  border: 0;
  border-radius: 8px;
  background: var(--brand);
  color: #fff;
  padding: 11px 16px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

.data-select input[type="number"] {
  appearance: textfield;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 12px;
  font: inherit;
  font-size: 13.5px;
  color: var(--ink);
  background: #fff;
  width: 7.5rem;
}

.data-select input[type="number"]:focus {
  outline: 2px solid var(--brand-soft);
  border-color: var(--brand);
}

.compare-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0;
  border-bottom: 1px solid var(--line-soft);
}

.compare-pane {
  padding: 18px 20px 20px;
}

.compare-pane + .compare-pane {
  border-left: 1px solid var(--line-soft);
}

.compare-kicker {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

.compare-title {
  font-size: 22px;
  font-weight: 700;
  margin-top: 4px;
}

.compare-stats {
  display: flex;
  gap: 18px;
  margin-top: 14px;
}

.compare-stats strong {
  display: block;
  font-size: 16px;
}

.compare-stats span {
  color: var(--muted);
  font-size: 11.5px;
}

.progress {
  margin-top: 14px;
  height: 6px;
  background: #eef1f4;
  border-radius: 99px;
  overflow: hidden;
}

.progress span {
  display: block;
  height: 100%;
  width: 0;
  background: var(--brand);
  transition: width 0.2s ease;
}

.compare-report {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 12px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--line-soft);
  background: #f7fafc;
}

.compare-report strong {
  display: block;
  font-size: 15px;
}

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

.compare-report > .empty {
  grid-column: 1 / -1;
  margin: 0;
}

@media (max-width: 900px) {
  .compare-grid,
  .compare-report {
    grid-template-columns: 1fr;
  }
  .compare-pane + .compare-pane {
    border-left: 0;
    border-top: 1px solid var(--line-soft);
  }
}
