:root {
  --ink: #1d1d1f;
  --muted: #626771;
  --line: rgba(29, 29, 31, .1);
  --surface: rgba(255, 255, 255, .8);
  --highlight: rgba(255, 255, 255, .94);
  --blue: #0071e3;
  --accent: #8ca6bd;
  --card-shadow: 0 10px 34px rgba(15, 23, 42, .055), 0 1px 2px rgba(15, 23, 42, .03);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
  color: var(--ink);
}
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  min-height: 100vh;
  background: radial-gradient(at 12% 4%, rgba(219,234,254,.72), transparent 46%),
              radial-gradient(at 88% 8%, rgba(232,240,254,.78), transparent 42%),
              radial-gradient(at 50% 96%, rgba(241,245,249,.85), transparent 54%), #f4f6fa;
}
h1, h2, p { margin: 0; }
h1 { font-size: 25px; letter-spacing: -.035em; }
h2 { font-size: 16px; }
button, input, select { max-width: 100%; font: inherit; color: inherit; }
button, input:not([type=checkbox]), select {
  padding: 7px 11px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: rgba(255,255,255,.9);
}
button { cursor: pointer; transition: background .16s, transform .12s; }
button:hover:not(:disabled) { background: #eff4fa; }
button:active:not(:disabled) { transform: scale(.98); }
button:disabled { opacity: .43; cursor: default; }
button.primary, #emptyImport { background: var(--blue); color: white; border-color: transparent; font-weight: 600; }
button.primary:hover:not(:disabled), #emptyImport:hover { background: #0062c4; }
button[aria-pressed=true] { background: #e8f2ff; border-color: #90b9e7; color: #075598; }
:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }
a { color: #005dbb; overflow-wrap: anywhere; }
.topbar, .toolbar, .toolbar > div, .section, .viewbar, .actions, .status, .desktop-nav {
  display: flex; align-items: center; gap: 9px; flex-wrap: wrap;
}
.topbar {
  position: sticky; top: 0; z-index: 5;
  padding: 12px 22px;
  border-bottom: 1px solid rgba(29,29,31,.08);
  background: rgba(255,255,255,.76);
  -webkit-backdrop-filter: blur(22px) saturate(180%);
  backdrop-filter: blur(22px) saturate(180%);
}
.brand { display: flex; align-items: center; gap: 8px; margin-right: 10px; font-size: 17px; }
.brand-mark { display: grid; place-items: center; width: 30px; height: 30px; border-radius: 9px; background: var(--blue); color: white; font-size: 22px; }
.desktop-nav { gap: 3px; padding: 3px; border-radius: 999px; background: rgba(118,118,128,.1); }
.nav-pill, #logoutBtn { border-radius: 999px; font-weight: 600; }
.nav-pill { border: 0; background: transparent; padding: 6px 14px; }
.desktop-nav [aria-current=page] { background: white; box-shadow: 0 2px 8px rgba(15,23,42,.09); }
.status { margin-left: auto; color: var(--muted); font-size: 12px; }
.status span, .tag-pill, .badge, .overlap {
  display: inline-flex; align-items: center; gap: 5px; padding: 3px 8px;
  border-radius: 999px; font-size: 12px; background: #edf3fa;
}
.status span { background: var(--surface); border: 1px solid var(--line); }
.status span::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--blue); }
.status [data-state=ready]::before { background: #10b981; }
.status [data-state=warn]::before { background: #d69319; }
main { padding: 18px 22px; }
.toolbar, .section { justify-content: space-between; margin-bottom: 14px; }
.layout { display: grid; grid-template-columns: 205px minmax(0,1fr) 295px; gap: 14px; height: calc(100dvh - 156px); min-height: 490px; }
.glass-card, dialog, #empty {
  min-width: 0;
  border: 1px solid var(--highlight);
  border-radius: 20px;
  background: var(--surface);
  box-shadow: var(--card-shadow);
  -webkit-backdrop-filter: blur(22px) saturate(180%);
  backdrop-filter: blur(22px) saturate(180%);
}
aside { padding: 14px; overflow: auto; }
aside > h2 { margin-bottom: 10px; }
aside > h2:not(:first-child) { margin-top: 22px; }
.paletteRow button:first-child { flex: 1; min-width: 0; text-align: left; overflow-wrap: anywhere; }
.paletteRow button:first-child::before { content: ""; display: inline-block; width: 9px; height: 9px; background: var(--swatch); border-radius: 50%; margin-right: 7px; }
.paletteRow, .entity { display: flex; gap: 4px; margin: 5px 0; }
.entity button:first-child { flex: 1; text-align: left; border-left: 4px solid var(--swatch); overflow-wrap: anywhere; }
#modes { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 5px; margin-bottom: 14px; }
#modes button { text-align: left; padding: 7px 4px; font-size: 12px; }
kbd { color: var(--muted); font: 10px/1.3 monospace; margin-right: 3px; }
.history-actions { display: flex; gap: 4px; }
.history-actions button { flex: 1; padding: 6px 2px; font-size: 12px; }
.workflow-divider { height: 22px; width: 1px; background: var(--line); }
.status-menu, .filter-menu { position: relative; }
.status-menu summary, .filter-menu summary { border-radius: 999px; padding: 6px 12px; background: #f1f4f8; }
#systemSummary[data-state=ready] { color: #09694c; background: #ebf7f1; }
#systemSummary[data-state=warn] { color: #87530a; background: #fff1d4; }
.menu-panel { position: absolute; top: calc(100% + 6px); right: 0; z-index: 3; width: max-content; min-width: 140px; padding: 12px; display: grid; gap: 8px; border: 1px solid var(--line); background: #fff; border-radius: 14px; box-shadow: var(--card-shadow); }
.filter-menu label { display: flex; gap: 6px; align-items: center; }
.viewbar { position: relative; z-index: 2; }
.inspector-section { border-top: 1px solid var(--line); padding-top: 12px; }
.inspector-section summary { margin-bottom: 10px; }
.metrics small { color: var(--muted); font-size: 11px; font-weight: 500; }
.metrics b { overflow-wrap: anywhere; }
#loginForm > .brand-mark { width: 44px; height: 44px; margin: 0 auto 12px; border-radius: 14px; }
#loginForm h2, #loginForm > p { text-align: center; }
#loginForm h2 { font-size: 23px; }
#loginForm > p:not(.error) { color: var(--muted); }
#loginForm input, #loginForm button { min-height: 42px; }
.viewport { display: flex; flex-direction: column; overflow: hidden; border-top: 3px solid var(--accent); }
.viewbar { padding: 10px 12px; font-size: 12px; }
.viewbar strong { flex: 1; min-width: 70px; overflow-wrap: anywhere; }
#canvas { position: relative; flex: 1; min-height: 220px; background: radial-gradient(ellipse at 50% 30%, #f5f8fc, #dce5ef); }
#canvas canvas, .selection { position: absolute; }
#canvas canvas { inset: 0; }
#canvas.painting, #canvas.painting canvas { cursor: crosshair; }
.selection { z-index: 1; pointer-events: none; border: 1px solid var(--accent); background: rgba(58,124,194,.18); }
#empty {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%,-50%); z-index: 1;
  display: grid; gap: 14px; justify-items: center; width: min(245px,85%); padding: 26px 18px;
}
footer, #basis, #entityInfo, #message, .entity small { color: var(--muted); font-size: 12px; }
footer { padding: 7px 12px; }
#basis { margin: 8px 0 16px; }
#entityInfo, #message { overflow-wrap: anywhere; }
#message { margin: 0 22px 10px; }
#entitySearch { width: 100%; margin-bottom: 6px; }
#entityScope { margin-bottom: 6px; }
.entity > * { min-width: 0; font-size: 12px; }
.entity small { display: block; }
.entity .located, tr.located-row { color: #9d2340; background: #fff1f3; }
#draftRestoreBar, .overlap { color: #805000; background: #fff1cd; }
#draftRestoreBar { padding: 10px 14px; margin-bottom: 12px; border-radius: 12px; }
#delivery { max-width: 980px; margin: auto; }
#delivery section { padding: 18px; margin: 16px 0; }
#delivery :is(button,label,select,a) { margin: 4px; }
.delivery-item { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; padding: 12px 0; border-bottom: 1px solid var(--line); overflow-wrap: anywhere; }
.delivery-item > * { min-width: 0; max-width: 100%; }
#delivery-result a { display: inline-block; margin: 10px 12px 10px 0; }
dialog { width: min(450px,94vw); max-height: 90dvh; padding: 24px; color: inherit; background: rgba(255,255,255,.94); box-shadow: 0 24px 64px rgba(15,23,42,.24); }
dialog::backdrop { background: rgba(24,38,56,.28); -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px); }
dialog label { display: block; margin: 12px 0; }
dialog input:not([type=checkbox]), dialog select { width: 100%; display: block; margin-top: 5px; }
input[type=color] { height: 36px; }
.actions { justify-content: flex-end; margin-top: 16px; }
.error { color: #a72a38; }
#loginDialog { width: min(380px,92vw); padding: 30px; }
#loginForm label { margin: 16px 0; }
#loginForm button { width: 100%; margin-top: 10px; }
#imports input[type=file] { padding: 14px; background: #f2f7fe; border: 1px dashed #9ab8d9; }
#imports ::file-selector-button { padding: 6px 10px; border: 0; border-radius: 8px; margin-right: 8px; background: white; color: #075598; }
.hero-upload-progress { margin: 16px 0; color: var(--muted); font-variant-numeric: tabular-nums; }
.upload-progress-track { height: 7px; border-radius: 999px; overflow: hidden; background: #dfe7f2; }
.upload-progress-fill { width: 0; height: 100%; background: var(--blue); transition: width .2s ease-out; }
#uploadInfo { margin: 7px 0; }
#reportDialog, #displayStatesDialog { width: min(1000px,95vw); }
#reportDialog[open] { display: flex; flex-direction: column; overflow: hidden; }
#reportDialog .table-scroll { flex: 1; min-height: 150px; max-height: 44vh; }
.table-scroll { overflow: auto; max-height: 55vh; }
table { width: 100%; border-collapse: collapse; font-size: 12px; margin: 6px 0 15px; }
th, td { text-align: left; padding: 7px 4px; border-bottom: 1px solid var(--line); }
th { color: #586575; background: #f4f6fa; font-weight: 600; }
td button { font: inherit; padding: 3px 6px; }
#stateRows input[name=boxName] { min-width: 8em; }
#reportRows td { padding: 9px; }
summary { cursor: pointer; font-weight: 600; }
#reportDialog .table-scroll > table > thead th { position: sticky; top: 0; z-index: 1; background: rgba(243,247,252,.94); -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px); }
#reportDialog .table-scroll > table > thead th:nth-child(n+4), #reportRows > tr > td:nth-child(n+4),
#reportRows details :is(th,td):nth-child(n+3) { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
#reportRows details table { margin-bottom: 0; }
.tag-picker { min-width: 7em; position: relative; }
.tag-picker[open] { min-width: 15em; }
.tag-picker .tag-editor { padding: 9px; border-radius: 10px; box-shadow: var(--card-shadow); background: white; }
#delivery-history .delivery-item { display: grid; grid-template-columns: 1fr 1fr 1.1fr; gap: 16px; padding: 16px 0; }
#delivery-history strong, #delivery-history small { display: block; }
#delivery-history small { color: var(--muted); margin-top: 4px; }
.delivery-actions { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; }
.delivery-actions :is(a,button) { font-size: 12px; }
.delivery-actions a:first-child { background: var(--blue); color: white; border-radius: 9px; padding: 6px 10px; text-decoration: none; }
.kpi-grid, .metrics { display: grid; gap: 8px; }
.kpi-grid { grid-template-columns: repeat(4,minmax(0,1fr)); }
.metrics { grid-template-columns: repeat(2,minmax(0,1fr)); }
.kpi-grid > div, .metrics > div { padding: 12px; border-radius: 13px; background: #eff4fa; font-size: 12px; }
.kpi-grid b, .metrics b { display: block; font-variant-numeric: tabular-nums; font-size: 20px; }
.density-bar { display: flex; align-items: end; flex-wrap: wrap; gap: 10px; margin: 16px 0; }
.density-bar label { margin: 0; }
.tag-pill { color: #075598; background: #e9f3ff; font-size: 11px; margin: 2px; overflow-wrap: anywhere; }
.tag-editor { min-width: 9em; }
.tag-editor input { margin-bottom: 5px; }
.tag-editor button { margin: 2px; padding: 2px 7px; border-radius: 999px; font-size: 11px; }
#lockNames, #supplementBoxes { max-height: 45vh; overflow: auto; overflow-wrap: anywhere; }
.toast-stack { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); max-width: 90vw; z-index: 10; pointer-events: none; }
.toast-stack > div { padding: 10px 18px; border-radius: 18px; background: rgba(29,29,31,.9); color: white; box-shadow: var(--card-shadow); }
@media (min-width:761px) and (max-width:1179px) {
  .layout { grid-template-columns: min(30%,280px) minmax(0,1fr); grid-template-rows: minmax(0,auto) minmax(0,1fr); }
  .viewport { grid-column: 2; grid-row: 1 / 3; }
  .layout > aside:first-child { max-height: 52vh; }
}
@media (max-width:760px) {
  .topbar { padding: 10px; gap: 6px; }
  .brand, .status { margin: 0; }
  .status { gap: 3px; }
  .nav-pill { padding: 6px 9px; }
  .layout { display: flex; flex-direction: column; height: auto; }
  .viewport { order: -1; height: 72dvh; }
  aside { overflow: visible; }
  #delivery-history .delivery-item { grid-template-columns: minmax(0,1fr); gap: 7px; }
  .delivery-actions { justify-content: flex-start; }
  .status { margin-left: auto; }
  .toolbar > div { min-width: 0; max-width: 100%; }
  #modes, .kpi-grid { grid-template-columns: repeat(2,minmax(0,1fr)); }
  dialog { padding: 16px; }
}
@media (prefers-reduced-motion:reduce) {
  button, .upload-progress-fill { transition: none; }
}
