/* Component styles — flat, bordered, generous whitespace. Mobile-first.
 * No shadows, gradients, glow. Hierarchy comes from spacing + hairline borders. */

* { box-sizing: border-box; }

/* Inline SVG icons inherit text colour/size; nudge baseline so they sit on the
 * text line, and never shrink inside flex rows. */
.icon { display: inline-block; vertical-align: -0.18em; flex: none; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC", "Microsoft YaHei", "Hiragino Sans GB", system-ui, Arial, sans-serif;
  font-size: var(--fs-md);
  font-weight: var(--weight-regular);
  line-height: var(--line-height);
  color: var(--color-text);
  background: var(--color-bg);
  /* Honour mobile safe areas (notch / home indicator) for the DingTalk H5 shell. */
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

a { color: var(--color-primary); text-decoration: none; }
a:hover { text-decoration: underline; }

h1 { font-size: var(--fs-xl); font-weight: var(--weight-medium); margin: 0 0 var(--space-5); }
h2 { font-size: var(--fs-lg); font-weight: var(--weight-medium); margin: var(--space-6) 0 var(--space-3); }
h3 { font-size: var(--fs-md); font-weight: var(--weight-medium); margin: var(--space-4) 0 var(--space-2); }

/* ---------- App chrome: desktop top bar ---------- */
.appbar {
  display: flex;
  align-items: center;
  gap: var(--space-6);
  flex-wrap: nowrap;
  position: sticky;
  top: 0;
  z-index: 900;
  background: color-mix(in srgb, var(--color-surface) 92%, transparent);
  border-bottom: 1px solid var(--color-border);
  padding: 10px var(--space-6);
  min-height: 58px;
  backdrop-filter: saturate(180%) blur(18px);
}
.brand { display: flex; align-items: center; gap: var(--space-2); font-weight: var(--weight-medium); font-size: var(--fs-md); color: var(--color-text); }
.brand-mark {
  width: 32px; height: 32px; border-radius: 8px;
  background: var(--color-primary); color: var(--color-on-primary);
  display: grid; place-items: center; font-size: var(--fs-sm); font-weight: var(--weight-medium);
}
.mainnav { display: flex; gap: var(--space-5); flex-wrap: nowrap; align-items: center; }
.mainnav a { color: var(--color-text-muted); padding: var(--space-1) 0; border-bottom: 2px solid transparent; font-size: var(--fs-sm); }
.mainnav a:hover { color: var(--color-text); text-decoration: none; }
.mainnav a.active { color: var(--color-primary); border-bottom-color: var(--color-primary); font-weight: var(--weight-medium); }
.appbar .spacer { margin-left: auto; }
.appbar .user { color: var(--color-text-muted); font-size: var(--fs-sm); }
.appbar .logout { color: var(--color-danger); }
.icon-button {
  width: 34px; height: 34px; margin: 0; padding: 0;
  display: inline-grid; place-items: center;
  border-radius: var(--radius-pill);
  border: 1px solid transparent;
  background: transparent; color: var(--color-text-muted);
}
.icon-button:hover { background: var(--color-surface-muted); color: var(--color-text); }
.user-menu { position: relative; }
.user-menu > summary {
  list-style: none; cursor: pointer;
  display: inline-flex; align-items: center; gap: var(--space-2);
  color: var(--color-text-muted); font-size: var(--fs-sm);
}
.user-menu > summary::-webkit-details-marker { display: none; }
.user-menu > summary::after { content: "⌄"; color: var(--color-text-faint); }
.avatar {
  width: 32px; height: 32px; border-radius: var(--radius-pill);
  display: inline-grid; place-items: center;
  background: var(--color-primary-soft); color: var(--color-primary);
  font-weight: var(--weight-medium);
}
.user-menu[open] { z-index: 1001; }
.user-menu-panel {
  position: absolute; right: 0; top: calc(100% + var(--space-2)); z-index: 1000;
  min-width: 180px; background: var(--color-surface);
  border: 1px solid var(--color-border); border-radius: var(--radius-md);
  padding: var(--space-2); display: grid; gap: 2px;
}
.user-menu-panel a { display: block; padding: var(--space-2) var(--space-3); border-radius: var(--radius-sm); color: var(--color-text); }
.user-menu-panel a:hover { background: var(--color-primary-soft); text-decoration: none; }
/* Theme toggle rendered as a menu/drawer item rather than an always-visible
 * button, so it isn't fat-fingered next to 退出. */
.drawer .themed {
  margin: 0; width: 100%; text-align: left; background: transparent;
  color: var(--color-text); border: 0; border-top: 1px solid var(--color-border);
  padding: var(--space-2) var(--space-3); border-radius: 0; font: inherit; cursor: pointer;
}
.drawer .themed:hover { background: var(--color-primary-soft); transform: none; }
.drawer-section {
  padding: var(--space-4) var(--space-3) var(--space-1);
  color: var(--color-text-faint);
  font-size: var(--fs-xs);
  font-weight: var(--weight-medium);
}

/* Mobile lightweight header + hamburger + bottom tab bar (hidden on desktop) */
.mobilebar, .tabbar, .drawer-toggle, .drawer { display: none; }

main { max-width: 1440px; margin: 0 auto; padding: var(--space-6) var(--space-5); }

/* ---------- Surfaces ---------- */
.panel {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
  margin-bottom: var(--space-5);
}
.login-panel {
  max-width: 380px; margin: 8vh auto 0;
  background: var(--color-surface); border: 1px solid var(--color-border);
  border-radius: var(--radius-lg); padding: var(--space-6);
}
.login-divider {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  color: var(--color-text-faint);
  font-size: var(--fs-sm);
  margin: var(--space-5) 0;
}
.login-divider::before, .login-divider::after {
  content: "";
  height: 1px;
  flex: 1;
  background: var(--color-border);
}
.dingtalk-login-box {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--space-4);
  padding: var(--space-4);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface-muted);
}
.dingtalk-login-box strong { display: block; margin-bottom: var(--space-1); }
.dingtalk-login-box p { margin: 0; font-size: var(--fs-sm); }
.login-hint {
  margin: var(--space-3) 0 0;
  color: var(--color-text-muted);
  font-size: var(--fs-xs);
  line-height: 1.5;
}
.config-checklist {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin: var(--space-3) 0;
}
.config-check {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 30px;
  padding: 4px 10px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-pill);
  font-size: var(--fs-sm);
  background: var(--color-surface);
}
.config-check.ok { color: var(--color-on-success-soft); background: var(--state-done-bg); border-color: var(--color-success-border); }
.config-check.missing { color: var(--color-danger); background: var(--state-error-bg); border-color: var(--color-danger-border); }
.config-url { margin-bottom: 0; overflow-wrap: anywhere; }

/* ---------- Metric cards ---------- */
.metric-grid {
  display: grid; gap: var(--space-4); margin-bottom: var(--space-6);
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
}
.metric { background: var(--color-surface-muted); border-radius: var(--radius-lg); padding: var(--space-5); border: 1px solid rgba(23, 32, 51, 0.04); }
.metric .label { display: block; color: var(--color-text-muted); font-size: var(--fs-sm); margin-bottom: var(--space-2); }
.metric .value { font-size: var(--fs-2xl); font-weight: var(--weight-medium); line-height: 1.1; }
.metric.is-active .value { color: var(--color-primary); }
.metric.is-error .value { color: var(--color-danger); }

/* ---------- Workbench dashboard ---------- */
.mobile-dashboard { display: none; }
.desktop-dashboard { display: block; }
.dashboard-title { margin: calc(-1 * var(--space-4)) 0 var(--space-5); }
.dashboard-title .muted { margin-top: -12px; }
.stat-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: var(--space-4);
  margin-bottom: var(--space-5);
}
.stat-card {
  display: grid;
  grid-template-columns: 52px 1fr;
  grid-template-areas: "icon label" "icon value" "icon delta";
  column-gap: var(--space-4);
  align-items: center;
  min-height: 104px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-5);
}
.stat-icon {
  grid-area: icon;
  width: 44px;
  height: 44px;
  border-radius: var(--radius-pill);
  display: grid;
  place-items: center;
  font-size: 22px;
  font-weight: var(--weight-medium);
}
.stat-icon.blue { color: var(--color-primary); background: var(--color-primary-soft); }
.stat-icon.orange { color: var(--color-on-warn-soft); background: var(--color-warn-soft); }
.stat-icon.red { color: var(--color-danger); background: var(--state-error-bg); }
.stat-icon.green { color: var(--color-on-success-soft); background: var(--state-done-bg); }
.stat-card .label { grid-area: label; color: var(--color-text-muted); font-size: var(--fs-sm); }
.stat-card strong { grid-area: value; font-size: 30px; line-height: 1.08; font-weight: var(--weight-medium); letter-spacing: 0; }
.stat-card .delta { grid-area: delta; color: var(--color-text-faint); font-size: var(--fs-xs); }
.dashboard-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: var(--space-5);
  align-items: start;
}
.dashboard-main, .dashboard-aside { display: grid; gap: var(--space-4); }
.workbench-queue h2, .recent-panel h2, .side-panel h2 { margin: 0; }
.panel-title-row { display: flex; justify-content: space-between; align-items: center; gap: var(--space-3); margin-bottom: var(--space-4); }
.compact-filter-row {
  display: grid;
  grid-template-columns: minmax(140px, 1fr) minmax(140px, 1fr) minmax(240px, 1.5fr) auto;
  gap: var(--space-3);
  align-items: end;
  margin-bottom: var(--space-4);
}
.compact-filter-row label { margin: 0; display: grid; gap: var(--space-1); }
.compact-filter-row input, .compact-filter-row select { max-width: none; min-height: 36px; }
.compact-filter-row button { margin: 0; min-height: 36px; }
.clean-table { margin: 0; border-color: var(--color-border); }
.clean-table th { background: var(--color-surface-muted); color: var(--color-text-muted); font-size: var(--fs-xs); padding: 10px var(--space-3); }
.clean-table td { background: var(--color-surface); padding: 11px var(--space-3); }
.clean-table tr:last-child td { border-bottom: 0; }
.row-link { color: var(--color-primary); font-weight: var(--weight-medium); }
.table-action { display: flex; gap: var(--space-2); margin: 0; align-items: center; }
.table-action select { width: 150px; min-height: 32px; margin: 0; padding: 5px var(--space-3); }
.table-action button, .row-button { margin: 0; min-height: 32px; padding: 5px var(--space-3); white-space: nowrap; }
.empty-cell { text-align: center; color: var(--color-text-muted); padding: var(--space-6); }
.dashboard-aside .panel { padding: var(--space-5); border-radius: var(--radius-md); }
.mini-select {
  font-size: var(--fs-xs);
  color: var(--color-text-muted);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 4px var(--space-2);
  cursor: pointer;
}
.overview-range { margin: 0; }
.side-panel h3 { color: var(--color-text-muted); margin-top: var(--space-4); }
.bar-stat {
  display: grid;
  grid-template-columns: 78px 1fr 26px;
  gap: var(--space-3);
  align-items: center;
  margin: var(--space-3) 0;
  font-size: var(--fs-sm);
}
.bar-stat i {
  height: 5px;
  border-radius: var(--radius-pill);
  background: var(--color-surface-muted);
  overflow: hidden;
}
.bar-stat b { display: block; height: 100%; width: 0; background: var(--color-primary); border-radius: inherit; transition: width var(--dur-grow) var(--ease-out); }
.bar-stat em { color: var(--color-text-muted); font-style: normal; text-align: right; }
.side-actions { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-3); }
.quick-action {
  display: grid;
  place-items: center;
  min-height: 58px;
  padding: var(--space-3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  color: var(--color-text);
}
.quick-action:hover { text-decoration: none; border-color: var(--color-border-strong); }
.quick-action strong { font-weight: var(--weight-medium); }
.export-note { margin-left: var(--space-3); font-size: var(--fs-sm); }
.sample-detail-link { margin: 0 0 0 auto; padding: 2px var(--space-3); font-size: var(--fs-xs); }

/* ---------- Filters (sticky) ---------- */
.filters {
  position: sticky; top: 0; z-index: 10;
  display: flex; flex-wrap: wrap; gap: var(--space-3); align-items: flex-end;
  background: color-mix(in srgb, var(--color-bg) 92%, transparent);
  padding: var(--space-4) 0; margin-bottom: var(--space-5);
  backdrop-filter: saturate(160%) blur(12px);
}
.filters .field { display: flex; flex-direction: column; gap: var(--space-1); }
.filters label { color: var(--color-text-muted); font-size: var(--fs-sm); }
.search { position: relative; }
.search input { padding-left: var(--space-8); }
.search::before {
  content: ""; position: absolute; left: var(--space-3); top: 50%;
  width: 15px; height: 15px; transform: translateY(-50%); opacity: 0.5;
  background: var(--color-text-muted);
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='m21 21-4.3-4.3'/%3E%3C/svg%3E") center/contain no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='m21 21-4.3-4.3'/%3E%3C/svg%3E") center/contain no-repeat;
}

label { display: block; margin-top: var(--space-3); color: var(--color-text-muted); font-size: var(--fs-sm); }
input, select, textarea {
  width: 100%; max-width: 520px; min-height: 40px; padding: 9px var(--space-3);
  border: 1px solid var(--color-border-strong); border-radius: var(--radius-md);
  font: inherit; color: var(--color-text); background: var(--color-surface);
  transition: border-color var(--dur-fast) var(--ease-out), background var(--dur-fast) var(--ease-out);
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--color-primary); background: var(--color-surface); }
.filters input, .filters select { width: 190px; }
select[multiple] { min-width: 180px; }
textarea { max-width: 900px; }

/* ---------- Buttons ---------- */
button, .button {
  display: inline-block; margin-top: var(--space-3); cursor: pointer;
  background: var(--color-primary); color: var(--color-on-primary);
  border: 1px solid transparent; padding: 9px var(--space-4);
  border-radius: var(--radius-md); font: inherit; font-weight: var(--weight-medium);
  transition: background var(--dur-fast) var(--ease-out), border-color var(--dur-fast) var(--ease-out);
}
button:hover, .button:hover { text-decoration: none; background: var(--color-primary-strong); }
.button.ghost, button.ghost {
  background: transparent; color: var(--color-primary); border-color: var(--color-border-strong);
}
.button[disabled], button[disabled] { opacity: 0.5; cursor: not-allowed; transform: none; }

/* ---------- Tables (collapse to cards on mobile) ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--color-border); border-radius: var(--radius-md); margin-bottom: var(--space-5); }
table { border-collapse: collapse; width: 100%; }
th, td { border-bottom: 1px solid var(--color-border); padding: var(--space-3); text-align: left; vertical-align: top; font-size: var(--fs-sm); }
th { color: var(--color-text-muted); background: var(--color-surface-muted); font-weight: var(--weight-medium); }
tr.is-inactive { opacity: 0.5; }
th.sortable { padding: 0; }
th.sortable > a {
  display: flex; align-items: center; gap: var(--space-2);
  padding: var(--space-3); color: inherit; text-decoration: none;
}
th.sortable > a:hover { color: var(--color-text); background: var(--color-border); }
th.sorted > a { color: var(--color-primary); }
.sort-caret { font-size: var(--fs-xs); opacity: 0.5; }
th.sorted .sort-caret { opacity: 1; }
.pager { display: flex; align-items: center; justify-content: center; gap: var(--space-4); margin: var(--space-4) 0 var(--space-6); }
.pager-status { color: var(--color-text-muted); font-size: var(--fs-sm); }
.button.is-disabled, .button.ghost.is-disabled { opacity: 0.4; cursor: not-allowed; pointer-events: none; }

/* ---------- Pills (status + category) ---------- */
.pill {
  display: inline-flex; align-items: center; gap: var(--space-1);
  padding: 2px var(--space-3); border-radius: var(--radius-pill);
  font-size: var(--fs-xs); white-space: nowrap;
}
.pill[data-semantic="done"]    { background: var(--state-done-bg);    color: var(--state-done-fg); }
.pill[data-semantic="active"]  { background: var(--state-active-bg);  color: var(--state-active-fg); }
.pill[data-semantic="pending"] { background: var(--state-pending-bg); color: var(--state-pending-fg); }
.pill[data-semantic="error"]   { background: var(--state-error-bg);   color: var(--state-error-fg); font-weight: var(--weight-medium); border: 1px solid var(--color-danger); }
.pill[data-semantic="success"] { background: var(--state-done-bg);    color: var(--state-done-fg); }
.pill[data-semantic="warn"]    { background: var(--color-warn-soft);  color: var(--color-on-warn-soft); border: 1px solid var(--color-warn); }
.pill .caret { opacity: 0.55; font-size: 10px; }
.tag { display: inline-flex; padding: 2px var(--space-3); border-radius: var(--radius-pill); font-size: var(--fs-xs); }
.tag[data-variant="a"] { background: var(--tag-a-bg); color: var(--tag-a-fg); }
.tag[data-variant="b"] { background: var(--tag-b-bg); color: var(--tag-b-fg); }

/* Breathing dot — the only persistent animation; marks "in progress now". */
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--state-active-dot); }
.pill[data-semantic="active"] .dot { animation: breathe 2.4s var(--ease-out) infinite; }
.pill[data-semantic="error"] .dot { background: var(--color-danger); }
@keyframes breathe { 0%, 100% { opacity: 0.4; } 50% { opacity: 1; } }

/* ---------- Sample card ---------- */
.sample-card { background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-lg); padding: var(--space-6); margin-bottom: var(--space-4); transition: border-color var(--dur-fast) var(--ease-out), background var(--dur-fast) var(--ease-out); }
.sample-card:hover { border-color: var(--color-border-strong); background: color-mix(in srgb, var(--color-surface) 96%, var(--color-primary-soft)); }
.sample-card .head { display: flex; justify-content: space-between; align-items: flex-start; gap: var(--space-4); }
.sample-card .ident { display: flex; align-items: center; gap: var(--space-3); flex-wrap: wrap; }
.sample-card .style-no { font-weight: var(--weight-medium); font-size: var(--fs-md); }
.sample-card .customer { color: var(--color-text-muted); font-size: var(--fs-sm); }
.sample-card .completion { text-align: right; }
.sample-card .completion .pct { font-size: var(--fs-xl); font-weight: var(--weight-medium); }
.sample-card .completion .cap { display: block; color: var(--color-text-muted); font-size: var(--fs-xs); }
.swatches { display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap; margin: var(--space-3) 0; }
.swatch { width: 24px; height: 24px; border-radius: var(--radius-md); border: 1px solid var(--color-border); }
.swatch.empty { display: grid; place-items: center; border-style: dashed; color: var(--color-text-faint); font-size: 12px; background: transparent; }
.pill-row { display: flex; gap: var(--space-2); flex-wrap: wrap; align-items: center; }
.inline-approve { display: inline; margin: 0; }
.inline-approve button { margin: 0; padding: 2px var(--space-3); font-size: var(--fs-xs); }

/* ---------- Forms: manual entry grid + color rows ---------- */
.form-grid { display: grid; gap: var(--space-3) var(--space-4); grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.form-grid label { margin-top: 0; }
.color-row { display: grid; grid-template-columns: repeat(6, minmax(90px, 1fr)); gap: var(--space-2); margin-bottom: var(--space-2); }
.split { display: grid; gap: var(--space-5); grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.checks { display: flex; flex-wrap: wrap; gap: var(--space-3); }
.check { margin: 0; display: inline-flex; align-items: center; gap: var(--space-1); }
.check input { width: auto; }
.inline-form { display: flex; flex-wrap: wrap; gap: var(--space-3); align-items: flex-end; }
.manual-workbench { display: grid; gap: var(--space-5); }
.manual-section { margin-bottom: 0; }
.section-head {
  display: flex; justify-content: space-between; align-items: flex-start; gap: var(--space-4);
  margin-bottom: var(--space-4);
}
.eyebrow {
  margin: 0 0 2px; font-size: var(--fs-xs); letter-spacing: 0; text-transform: uppercase;
  color: var(--color-text-faint);
}
.color-card-grid {
  display: grid; gap: var(--space-4);
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
}
.color-card {
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  background: var(--color-surface);
  padding: var(--space-4);
  display: grid;
  gap: var(--space-3);
}
.color-card-head {
  display: flex; justify-content: space-between; align-items: baseline; gap: var(--space-2);
}
.color-card-fields {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-2);
}
.color-card-fields input { max-width: none; }
.file-drop {
  display: grid; gap: var(--space-2);
  border: 1px dashed var(--color-border-strong);
  border-radius: var(--radius-md);
  padding: var(--space-3);
  background: color-mix(in srgb, var(--color-surface-muted) 70%, var(--color-surface));
}
.file-drop span { font-size: var(--fs-sm); color: var(--color-text-muted); }
.file-drop input[type="file"] { max-width: none; min-height: auto; padding: 0; border: 0; background: transparent; }
.file-drop-large { min-height: 92px; align-content: center; }
.manual-submit { justify-content: flex-start; }
.manual-submit .button { margin-top: 0; }
.project-action {
  display: inline-flex; align-items: center; margin: var(--space-3) 0; padding: 6px;
  background: color-mix(in srgb, var(--color-surface-muted) 74%, var(--color-surface));
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  gap: var(--space-2); max-width: 100%;
}
.project-action .muted { font-size: var(--fs-sm); padding: 0 var(--space-2); }
.project-action select { width: auto; min-width: 150px; max-width: 220px; margin: 0; min-height: 34px; padding: 5px var(--space-3); border-radius: var(--radius-md); }
.project-action button { margin: 0; white-space: nowrap; min-height: 34px; padding: 5px var(--space-4); border-radius: var(--radius-md); }
@media (max-width: 880px) { .color-row { grid-template-columns: 1fr 1fr; } }
@media (max-width: 880px) {
  .section-head { flex-direction: column; }
  .color-card-fields { grid-template-columns: 1fr; }
  .manual-submit {
    position: static;
    bottom: auto;
    z-index: auto;
    margin-top: var(--space-2);
    padding-bottom: calc(var(--space-3) + env(safe-area-inset-bottom));
  }
}

/* ---------- Thumbnails (sample images) ---------- */
.thumb-grid { display: grid; gap: var(--space-3); grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.thumb { display: block; background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-md); padding: var(--space-2); color: var(--color-text); }
.thumb:hover { text-decoration: none; border-color: var(--color-border-strong); }
.thumb img { width: 100%; height: 130px; object-fit: contain; background: var(--color-surface-muted); border-radius: var(--radius-sm); }
.thumb span { display: block; font-size: var(--fs-xs); margin-top: var(--space-1); overflow-wrap: anywhere; }
.phase-sep { width: 1px; align-self: stretch; background: var(--color-border); margin: 0 var(--space-1); }

/* Progress bar (grows from 0 on load) */
.progress-bar { height: 6px; border-radius: var(--radius-pill); background: var(--color-surface-muted); overflow: hidden; margin-top: var(--space-4); }
.progress-bar > i { display: block; height: 100%; width: 0; background: var(--color-primary); border-radius: var(--radius-pill); transition: width var(--dur-grow) var(--ease-out); }

/* Left-accent strip (no radius, per the single-side border rule) */
.accent-error { border-left: 3px solid var(--color-danger); border-radius: 0; }

/* ---------- Management hub cards ---------- */
.card-grid { display: grid; gap: var(--space-3); grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); margin-bottom: var(--space-5); }
.hub-card { display: flex; align-items: center; gap: var(--space-4); background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-lg); padding: var(--space-4) var(--space-5); color: var(--color-text); }
.hub-card:hover { text-decoration: none; transform: translateY(-2px); border-color: var(--color-border-strong); }
.hub-card .hub-ico { width: 40px; height: 40px; flex: none; border-radius: var(--radius-md); display: grid; place-items: center; background: var(--color-primary-soft); color: var(--color-primary); }
.hub-card .hub-body { flex: 1; min-width: 0; display: grid; gap: 2px; }
.hub-card .hub-body strong { font-weight: var(--weight-medium); }
.hub-card .hub-body .muted { font-size: var(--fs-sm); }
.hub-card .hub-arrow { flex: none; color: var(--color-text-faint); }
.hub-ico.chip-blue { background: var(--color-primary-soft); color: var(--color-primary); }
.hub-ico.chip-green { background: var(--state-done-bg); color: var(--color-on-success-soft); }
.hub-ico.chip-amber { background: var(--color-warn-soft); color: var(--color-on-warn-soft); }
.hub-ico.chip-neutral { background: var(--color-surface-muted); color: var(--color-text-muted); }
.manage-center-section .panel-title-row h2 { margin: 0; }
.manage-center-grid { margin-bottom: 0; }

@media (min-width: 881px) and (max-width: 1100px) {
  .appbar { gap: var(--space-4); padding-inline: var(--space-4); }
  .brand { font-size: var(--fs-sm); }
  .brand-mark { width: 28px; height: 28px; border-radius: 7px; }
  .mainnav { gap: var(--space-3); }
  .mainnav a { font-size: var(--fs-xs); }
}

/* ---------- Image-color match queue ---------- */
.match-row { display: flex; gap: var(--space-4); align-items: flex-start; }
.match-thumb img { width: 96px; height: 96px; object-fit: contain; background: var(--color-surface-muted); border-radius: var(--radius-sm); border: 1px solid var(--color-border); }
.match-info { flex: 1; display: flex; flex-direction: column; gap: var(--space-2); }
.match-loc { display: flex; gap: var(--space-2); flex-wrap: wrap; align-items: center; font-size: var(--fs-sm); }
.match-suggest { display: flex; gap: var(--space-2); align-items: center; flex-wrap: wrap; font-size: var(--fs-sm); }
.match-form { display: flex; gap: var(--space-2); align-items: center; margin: 0; }
.match-form .match-color { width: auto; min-width: 140px; margin: 0; }
.match-form button { margin: 0; }
@media (max-width: 880px) {
  .match-row { flex-direction: column; }
  .match-form { flex-direction: column; align-items: stretch; }
  .match-form .match-color { width: 100%; }
}

/* ---------- Notices / empty / loading ---------- */
.alert { background: var(--color-warn-soft); color: var(--color-on-warn-soft); border: 1px solid transparent; padding: var(--space-3) var(--space-4); border-radius: var(--radius-sm); margin-bottom: var(--space-3); }
.muted { color: var(--color-text-muted); }
.empty { text-align: center; color: var(--color-text-muted); padding: var(--space-8) var(--space-4); }
code { background: var(--color-surface-muted); padding: 2px 6px; border-radius: var(--radius-sm); font-size: var(--fs-sm); }

/* ---------- Charts ---------- */
.chart-legend { display: flex; flex-wrap: wrap; gap: var(--space-3); margin-bottom: var(--space-3); font-size: var(--fs-sm); color: var(--color-text-muted); }
.legend-item { display: inline-flex; align-items: center; gap: var(--space-2); }
.legend-item i { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }
.report-grid { display: grid; gap: var(--space-4); grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.report-partition { margin-bottom: var(--space-5); border: 1px solid var(--color-border); border-radius: var(--radius-lg); padding: var(--space-3) var(--space-4); background: var(--color-surface); }
.report-partition > summary { cursor: pointer; list-style: none; }
.report-partition > summary::-webkit-details-marker { display: none; }
.report-partition > summary h2 { display: inline-block; margin: var(--space-2) 0; }
.report-partition > summary::before { content: "▸ "; color: var(--color-text-muted); }
.report-partition[open] > summary::before { content: "▾ "; }
.bar-row { display: grid; grid-template-columns: 80px 1fr 60px; gap: var(--space-3); align-items: center; margin: var(--space-2) 0; font-size: var(--fs-sm); }
.bar-row .progress-bar { margin: 0; }
.bar-label { color: var(--color-text-muted); }
.bar-value { text-align: right; color: var(--color-text-muted); font-size: var(--fs-xs); }

/* ---------- Status switch menu (in-place pill editing) ---------- */
.status-menu { position: relative; display: inline-block; }
.pill[data-process] { cursor: pointer; }
.status-options {
  position: absolute; top: calc(100% + 4px); left: 0; z-index: 30;
  display: flex; flex-wrap: wrap; gap: 2px; min-width: 140px;
  background: var(--color-surface); border: 1px solid var(--color-border);
  border-radius: var(--radius-md); padding: var(--space-2);
}
.status-options[hidden] { display: none; }
.status-options form { display: inline; margin: 0; }
.status-options button { margin: 0; padding: 2px var(--space-2); font-size: var(--fs-xs); }

/* ---------- Entrance animation (staggered, subtle) ---------- */
.enter { opacity: 0; transform: translateY(8px); animation: enter var(--dur-enter) var(--ease-out) forwards; }
@keyframes enter { to { opacity: 1; transform: none; } }

/* ---------- Responsive: tablet / mobile ---------- */
@media (max-width: 880px) {
  .appbar { display: none; }
  .mobilebar {
    display: grid; align-items: center; gap: var(--space-2);
    grid-template-columns: 48px 1fr 36px 36px;
    background: color-mix(in srgb, var(--color-surface) 92%, transparent);
    border-bottom: 1px solid var(--color-border);
    padding: 10px var(--space-4); position: sticky; top: 0; z-index: 900;
    min-height: 56px; backdrop-filter: saturate(180%) blur(18px);
  }
  .mobilebar .title { font-weight: var(--weight-medium); margin: 0; text-align: center; font-size: var(--fs-lg); }
  .mobilebar-space { display: block; }
  .drawer-toggle, .mobile-add {
    width: 34px; height: 34px; display: inline-grid; place-items: center;
    background: transparent; border: 0; color: var(--color-text); font-size: 22px;
    margin: 0; padding: 0; min-height: 34px; border-radius: var(--radius-pill);
  }
  .drawer-toggle:hover { background: transparent; }
  .mobile-add:hover { text-decoration: none; background: var(--color-surface-muted); }
  main { padding: var(--space-6) var(--space-4) calc(72px + env(safe-area-inset-bottom)); }
  main > h1:first-child {
    position: absolute; width: 1px; height: 1px; overflow: hidden;
    clip: rect(0 0 0 0); white-space: nowrap; margin: 0;
  }

  /* Bottom tab bar for core entries */
  .tabbar {
    display: flex; position: fixed; bottom: 0; left: 0; right: 0; z-index: 880;
    background: color-mix(in srgb, var(--color-surface) 92%, transparent);
    border-top: 1px solid var(--color-border);
    padding: 4px 0 env(safe-area-inset-bottom);
    backdrop-filter: saturate(180%) blur(18px);
  }
  .tabbar a { flex: 1; text-align: center; padding: 6px 0 5px; color: var(--color-text-muted); font-size: var(--fs-xs); }
  .tabbar a:hover { text-decoration: none; }
  .tabbar a.active { color: var(--color-primary); font-weight: var(--weight-medium); }
  .tabbar .ico { display: block; font-size: 20px; line-height: 1.15; margin-bottom: 1px; }

  /* Slide-in drawer holds full nav + admin menu */
  .drawer { position: fixed; inset: 0; z-index: 1000; display: none; }
  .drawer[open] { display: block; }
  .drawer .scrim { position: absolute; inset: 0; background: rgba(0,0,0,0.28); }
  .drawer .sheet { position: absolute; top: 0; left: 0; bottom: 0; width: 78%; max-width: 320px; background: var(--color-surface); padding: var(--space-5); overflow-y: auto; display: grid; gap: var(--space-1); align-content: start; }
  .drawer .sheet a { padding: var(--space-3); border-radius: var(--radius-md); color: var(--color-text); }
  .drawer .sheet a:hover { background: var(--color-primary-soft); text-decoration: none; }

  .project-action { display: flex; width: 100%; align-items: stretch; padding: var(--space-2); }
  .project-action select { width: 100%; max-width: none; }
  .project-action .muted { padding: 0; }

  .desktop-dashboard { display: none; }
  .mobile-dashboard { display: grid; gap: var(--space-4); }
  .mobile-page-head { display: flex; justify-content: space-between; align-items: center; gap: var(--space-3); }
  .mobile-page-head h2 { margin: 0; font-size: var(--fs-lg); }
  .mobile-page-head .button { margin: 0; padding: 6px var(--space-3); background: transparent; color: var(--color-primary); border-color: var(--color-primary); }
  .mobile-stat-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: var(--space-2); }
  .mobile-stat-grid article {
    min-height: 86px;
    display: grid;
    gap: 2px;
    padding: var(--space-3);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    background: var(--color-surface);
  }
  .mobile-stat-grid span { color: var(--color-text-muted); font-size: var(--fs-xs); }
  .mobile-stat-grid strong { font-size: 28px; line-height: 1; color: var(--color-primary); font-weight: var(--weight-medium); letter-spacing: 0; }
  .mobile-stat-grid strong.danger { color: var(--color-danger); }
  .mobile-stat-grid i { justify-self: end; color: var(--color-primary); font-style: normal; opacity: 0.8; }
  .segment-tabs {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    background: var(--color-surface-muted);
    border-radius: var(--radius-md);
    overflow: hidden;
    border: 1px solid var(--color-border);
  }
  .segment-tabs a { text-align: center; color: var(--color-text-muted); padding: var(--space-3); border-bottom: 2px solid transparent; }
  .segment-tabs a.active { color: var(--color-primary); background: var(--color-surface); border-bottom-color: var(--color-primary); font-weight: var(--weight-medium); }
  .mobile-search-row { display: grid; grid-template-columns: 1fr auto; gap: var(--space-3); align-items: center; }
  .mobile-search-row input { max-width: none; }
  .mobile-search-row a { color: var(--color-primary); font-weight: var(--weight-medium); }
  .filter-chips { display: flex; gap: var(--space-2); overflow-x: auto; padding-bottom: 2px; }
  .filter-chips span { flex: 0 0 auto; border-radius: var(--radius-pill); background: var(--color-surface); border: 1px solid var(--color-border); padding: 7px var(--space-3); color: var(--color-text-muted); font-size: var(--fs-sm); }
  .mobile-sample-list { display: grid; gap: var(--space-3); }
  .mobile-sample-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: var(--space-4);
  }
  .mobile-card-head { display: flex; justify-content: space-between; gap: var(--space-3); align-items: start; }
  .mobile-card-head > div { display: grid; gap: var(--space-1); }
  .mobile-card-head strong { font-size: var(--fs-lg); font-weight: var(--weight-medium); }
  .mobile-card-head span { color: var(--color-text-muted); font-size: var(--fs-xs); }
  .mobile-card-head em { color: var(--color-danger); font-style: normal; font-weight: var(--weight-medium); }
  .mobile-card-head em.ok { color: var(--state-done-fg); }
  .mobile-card-body {
    display: grid;
    gap: var(--space-3);
    margin-top: var(--space-3);
    padding-top: var(--space-3);
    border-top: 1px solid var(--color-border);
    font-size: var(--fs-sm);
  }
  .mobile-color-row {
    display: grid;
    grid-template-columns: 42px minmax(0, 1fr) 86px;
    gap: var(--space-3);
    align-items: center;
  }
  .mobile-color-row > span, .mobile-progress-row > span { color: var(--color-text-muted); }
  .mobile-color-row dl { margin: 0; display: grid; gap: 4px; }
  .mobile-color-row dl div { display: flex; justify-content: space-between; gap: var(--space-2); }
  .mobile-color-row dt { color: var(--color-text-muted); }
  .mobile-color-row dd { margin: 0; color: var(--color-text); font-weight: var(--weight-medium); }
  .mobile-colors { display: flex; gap: var(--space-2); align-items: center; }
  .mobile-colors b {
    width: 34px; height: 34px;
    display: grid; place-items: center;
    border: 1px solid var(--color-border-strong);
    border-radius: var(--radius-sm);
    color: var(--color-text-muted);
    background: var(--color-surface-muted);
    font-size: var(--fs-xs);
    font-weight: var(--weight-regular);
  }
  .mobile-colors .more { border-style: dashed; background: var(--color-surface); color: var(--color-text); }
  .mobile-progress-row { display: grid; grid-template-columns: 42px minmax(0, 1fr) 42px; gap: var(--space-3); align-items: center; }
  .mobile-progress-row strong { color: var(--color-primary); font-weight: var(--weight-medium); text-align: right; }
  .mini-progress { height: 5px; background: var(--color-surface-muted); border-radius: var(--radius-pill); overflow: hidden; }
  .mini-progress i { display: block; height: 100%; width: 0; background: var(--color-primary); border-radius: inherit; transition: width var(--dur-grow) var(--ease-out); }

  .filters input, .filters select, .filters .field { width: 100%; }
  .metric-grid { grid-template-columns: repeat(2, 1fr); gap: var(--space-4); }
  .metric { padding: var(--space-6) var(--space-5); min-height: 108px; }
  .metric .value { font-size: 40px; }

  /* Tables collapse to stacked cards: each row a card, each cell label:value */
  table.responsive thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  table.responsive, table.responsive tbody, table.responsive tr, table.responsive td { display: block; width: 100%; }
  table.responsive tr { border: 1px solid var(--color-border); border-radius: var(--radius-md); margin-bottom: var(--space-3); padding: var(--space-2); }
  table.responsive td { border: 0; padding: var(--space-2); display: flex; justify-content: space-between; gap: var(--space-4); }
  table.responsive td::before { content: attr(data-label); color: var(--color-text-muted); font-size: var(--fs-xs); }

  /* Sticky bottom action bar (use normal flow within container, not fixed) */
  .actionbar { position: sticky; bottom: 0; background: var(--color-surface); border-top: 1px solid var(--color-border); padding: var(--space-3); display: flex; gap: var(--space-3); }
}

/* ---------- Respect reduced-motion ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
  .progress-bar > i, .bar-stat b, .mini-progress i { transition: none; }
  .enter { opacity: 1; transform: none; animation: none; }
}

/* ===================================================================
   Elevation + refinement pass — flat with restrained depth.
   Hierarchy still comes from spacing + hairline borders; shadows just add
   enough lift that surfaces read as layered. =========================== */

.panel, .login-panel, .metric, .stat-card, .sample-card, .hub-card, .color-card, .thumb, .quick-action {
  box-shadow: var(--shadow-sm);
  transition: box-shadow var(--dur-fast) var(--ease-out),
              border-color var(--dur-fast) var(--ease-out),
              transform var(--dur-fast) var(--ease-out),
              background var(--dur-fast) var(--ease-out);
}
.stat-card:hover, .sample-card:hover, .hub-card:hover, .thumb:hover, .quick-action:hover { box-shadow: var(--shadow-md); }

.appbar, .mobilebar, .tabbar { box-shadow: var(--shadow-sm); }
.user-menu-panel, .status-options, .drawer .sheet { box-shadow: var(--shadow-lg); }

button, .button { box-shadow: var(--shadow-sm); }
button.ghost, .button.ghost, .themed, .color-card-remove,
.status-options button, .row-actions button, .table-action button { box-shadow: none; }

:focus-visible { outline: 2px solid var(--color-primary); outline-offset: 2px; }
input:focus, select:focus, textarea:focus { box-shadow: 0 0 0 3px var(--color-primary-soft); }

.tag { background: var(--color-surface-muted); color: var(--color-text-muted); }

.empty { display: grid; justify-items: center; gap: var(--space-2); }
.empty .icon { color: var(--color-text-faint); }

/* Workflow timeline (sample detail) */
.timeline { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--space-4); }
.timeline li { position: relative; padding-left: var(--space-6); }
.timeline li::before { content: ""; position: absolute; left: 6px; top: 4px; width: 9px; height: 9px; border-radius: 50%; background: var(--color-primary); box-shadow: 0 0 0 3px var(--color-primary-soft); }
.timeline li::after { content: ""; position: absolute; left: 10px; top: 17px; bottom: calc(-1 * var(--space-4)); width: 1px; background: var(--color-border); }
.timeline li:last-child::after { display: none; }
.timeline strong { font-weight: var(--weight-medium); }
.timeline .muted { font-size: var(--fs-sm); margin-top: 2px; }

/* Table action column */
.row-actions { display: flex; gap: var(--space-2); align-items: center; flex-wrap: wrap; }
.row-actions form, .row-actions .inline-form { margin: 0; }
.row-actions .button, .row-actions button { margin: 0; min-height: 30px; padding: 4px var(--space-3); font-size: var(--fs-xs); }

/* Stacked form inside <details> editors */
.stack-form { display: grid; gap: var(--space-2); margin: var(--space-3) 0; max-width: 380px; }
.stack-form label { margin: 0; }

/* Manual entry: add/remove colour rows */
.color-card-actions { margin-top: var(--space-2); }
.color-card-remove { margin: 0; min-height: 28px; padding: 2px var(--space-3); font-size: var(--fs-xs); background: transparent; color: var(--color-text-muted); border-color: var(--color-border); }
.color-card-remove:hover { color: var(--color-danger); border-color: var(--color-danger); background: var(--color-danger-soft); }

/* Key/value detail grid (sample detail master — replaces the raw column dump) */
.kv-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 0 var(--space-6); margin: 0; }
.kv-grid > div { display: grid; grid-template-columns: 84px 1fr; gap: var(--space-3); align-items: baseline; padding: 10px 0; border-bottom: 1px solid var(--color-border); }
.kv-grid dt { color: var(--color-text-muted); font-size: var(--fs-sm); }
.kv-grid dd { margin: 0; overflow-wrap: anywhere; }
.kv-grid > div.kv-wide { grid-column: 1 / -1; }
