:root {
  color-scheme: light;
  font-family: system-ui, -apple-system, sans-serif;
  color: #20283d;
  background: #f5f6fa;
  --surface: #fff;
  --border: #e1e4ee;
  --muted: #596278;
  --accent: #483bb1;
  --accent-dark: #372a91;
}

*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; }
[hidden] { display: none !important; }
button, input, select { font: inherit; }
button, select, input[type="checkbox"] { cursor: pointer; }
button:disabled { cursor: default; opacity: .5; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
h1, h2, p { margin: 0; }

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 56px;
  padding: 0 clamp(16px, 4vw, 56px);
  background: #232238;
  color: white;
  font-weight: 650;
}
.brand-mark {
  width: 21px;
  height: 21px;
  border: 2px solid #c9c1ff;
  border-radius: 5px;
  background: linear-gradient(#c9c1ff, #c9c1ff) center / 7px 2px no-repeat;
}
main { max-width: 1560px; margin: auto; padding: 0 clamp(16px, 4vw, 56px) 36px; }
nav { display: flex; flex-wrap: wrap; gap: 0 18px; min-height: 50px; border-bottom: 1px solid var(--border); }
nav a {
  display: grid;
  align-items: center;
  min-height: 50px;
  padding: 0 4px;
  border-bottom: 2px solid transparent;
  color: var(--muted);
  font-size: .875rem;
  font-weight: 650;
  text-decoration: none;
}
nav a:hover, nav a[aria-current="page"] { color: var(--accent); }
nav a[aria-current="page"] { border-color: var(--accent); }
.directory-tab { margin-inline-start: auto; }
.page-heading { display: flex; justify-content: space-between; align-items: center; gap: 16px; margin: 24px 0 18px; }
h1 { font-size: clamp(1.45rem, 3vw, 2rem); line-height: 1.2; letter-spacing: -.025em; }
h2 { font-size: 1rem; }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; overflow: hidden; }
.filters {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr)) minmax(250px, 1.4fr);
  gap: 12px 16px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
}
label, legend { font-size: .875rem; font-weight: 550; }
.filters label { display: grid; gap: 6px; }
.asset-filters {
  grid-template-columns: repeat(4, minmax(0, 1fr)) minmax(250px, 1.4fr);
}
.address-filters { grid-template-columns: repeat(2, minmax(0, 1fr)) minmax(250px, 1.4fr); }
.filters:has(.movement-filter:not([hidden])) fieldset { grid-column: span 2; }
.filters fieldset { min-width: 0; border: 0; margin: 0; padding: 0; }
.filters legend { padding: 0; margin-bottom: 6px; }
.date-range { display: flex; align-items: center; gap: 7px; }
.filter-actions { grid-column: 1 / -1; display: flex; justify-content: flex-end; gap: 8px; }
.location-filter { display: grid; gap: 6px; min-width: 0; }
.filter-primary { grid-column: 1 / -1; }
input:not([type="checkbox"]), select {
  min-width: 0;
  min-height: 37px;
  background: #fff;
  border: 1px solid #cdd2e0;
  border-radius: 6px;
  padding: 6px 9px;
  color: inherit;
  font-size: .875rem;
}
input:not([type="checkbox"]) { width: 100%; }
input::placeholder { color: var(--muted); opacity: 1; }
input[type="checkbox"] { width: 16px; height: 16px; margin: 0; accent-color: var(--accent); vertical-align: middle; }
button:not(.sort) { min-height: 36px; padding: 6px 12px; border: 1px solid transparent; border-radius: 6px; font-size: .875rem; font-weight: 600; }
.primary { background: var(--accent); color: white; }
.primary:hover:not(:disabled) { background: var(--accent-dark); }
button#create-movement { width: 100%; min-height: 54px; font-size: 1rem; }
button.secondary { background: white; color: #373451; border-color: #ccd0df; }
.quiet { background: transparent; color: var(--muted); }
.secondary:hover:not(:disabled), .quiet:hover:not(:disabled) { background: #efedf9; color: var(--accent-dark); }
button.icon-button { min-width: 36px; padding: 0 7px; font-size: 1.2rem; line-height: 1; }
.table-toolbar, .table-footer, .dialog-header, .dialog-footer {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 20px;
}
.table-toolbar .status { flex: 1; }
.receipt-actions { display: flex; gap: 12px; margin-inline-start: auto; }
.receipt-toolbar { flex-wrap: wrap; }
.receipt-toolbar .receipt-actions { flex-wrap: wrap; margin-inline-start: 0; }
.receipt-toolbar .status { flex-basis: 100%; }
.city-toolbar, .city-toolbar .receipt-actions { flex-wrap: wrap; }
.city-toolbar .status { flex-basis: 200px; }
.table-scroll { overflow: auto; }
table { width: 100%; border-collapse: collapse; font-size: .875rem; }
.inventory-table th.storage-group { padding-inline: 12px; }
.inventory-table tbody tr:hover { background: #faf9ff; }
.city-table .city-selected { background: #f1efff; }
.city-table .city-removed { color: #8c2834; background: #fff4f4; }
.city-table .city-removed td:not(:first-child, :last-child) { text-decoration: line-through; }
.city-removal-note { display: block; }
.city-control { position: relative; }
.city-control input { padding-inline-end: 42px; }
.city-control .city-toggle { position: absolute; inset: 1px 1px 1px auto; width: 37px; min-height: 0; display: grid; place-items: center; padding: 0; border: 0; border-inline-start: 1px solid var(--border); border-radius: 0 5px 5px 0; background: #f5f6fa; color: var(--muted); }
.city-control .city-toggle::before { content: ''; width: 7px; height: 7px; border: solid currentColor; border-width: 0 2px 2px 0; transform: translateY(-2px) rotate(45deg); }
.city-control .city-toggle[aria-expanded="true"]::before { transform: translateY(2px) rotate(225deg); }
.city-control .city-toggle:hover:not(:disabled) { background: #efedf9; color: var(--accent); }
.city-options { position: fixed; inset: auto; z-index: 4; margin: 0; padding: 0; list-style: none; max-height: 190px; overflow: auto; overscroll-behavior: contain; border: 1px solid var(--border); border-radius: 6px; background: var(--surface); color: inherit; box-shadow: 0 8px 22px #23223829; }
.city-options li { padding: 7px 9px; cursor: pointer; overflow-wrap: anywhere; }
.city-options li:hover, .city-options li[aria-selected="true"] { background: #efedf9; }
.city-options .city-options-empty { color: var(--muted); background: transparent; cursor: default; }
.city-options-inline { position: static; margin-top: 4px; max-height: 144px; }
.city-options-inline li { padding: 10px; }
.movement-item { margin-bottom: 12px; color: var(--muted); }
.context-menu { position: fixed; z-index: 2; padding: 4px; border: 1px solid var(--border); border-radius: 7px; background: var(--surface); box-shadow: 0 6px 20px #23223824; }
.context-menu button { width: 100%; text-align: left; }
#quick-movement { width: min(460px, calc(100% - 24px)); }
#qr-camera { display: block; width: 100%; max-height: 52dvh; object-fit: contain; border-radius: 7px; background: #232238; }
#quick-fields { display: grid; gap: 14px; }
#quick-fields label { display: grid; gap: 5px; }
.quick-location { display: grid; gap: 10px; min-inline-size: 0; margin: 0; padding: 8px 12px 12px; border: 1px solid var(--border); border-radius: 7px; }
.quick-location legend { padding-inline: 5px; font-weight: 650; }
.quick-location .city-control { margin-top: 5px; }
#quick-fields input { font-size: 1rem; min-height: 44px; }
#quick-fields input[readonly] { background: #f5f6fa; }
.quick-item { overflow-wrap: anywhere; font-weight: 650; }
#quick-movement .dialog-footer { justify-content: space-between; }
#quick-movement button:not(.city-toggle) { min-height: 44px; }
th { background: #eef0f8; font-weight: 650; }
th, td { padding: 11px 12px; border: 1px solid var(--border); text-align: center; }
td { height: 42px; overflow-wrap: anywhere; }
td input { text-align: center; }
td .city-control input { padding-inline-start: 42px; }
.code, .date { font-variant-numeric: tabular-nums; }
.code { white-space: nowrap; }
.date { white-space: nowrap; }
.column-grid { width: var(--grid-width); min-width: 100%; table-layout: fixed; }
.column-grid :is(th, td) { white-space: normal; overflow-wrap: anywhere; }
.column-grid th { position: relative; padding-inline: 17px; }
.column-resize { position: absolute; inset: 0 0 0 auto; width: 12px; cursor: col-resize; touch-action: none; }
.column-resize::after { content: ''; position: absolute; inset: 25% 2px 25% auto; width: 1px; background: #bcc4d6; }
.column-resize:hover::after, .column-resize:focus-visible::after, .column-resize:active::after { width: 2px; background: var(--accent); }
.column-resizing { cursor: col-resize; user-select: none; }
.sort { padding: 0; background: none; border: none; color: inherit; font-weight: inherit; }
.sort span { color: var(--accent); margin-left: 3px; }
.receipt-table tbody tr:hover { background: #faf9ff; }
.receipt-table tbody tr.selected { background: #f1efff; }
.empty { padding: 22px; text-align: center; color: var(--muted); }
.table-footer { justify-content: space-between; font-size: .875rem; color: var(--muted); }
.pagination { display: flex; align-items: center; gap: 8px; }
.pagination select { min-height: 32px; margin-left: 4px; }
.status { color: var(--muted); font-size: .875rem; }
.status.error { color: #9e2834; }
.status:empty { display: none; }

dialog { width: min(870px, calc(100% - 24px)); max-height: calc(100% - 24px); padding: 0; border: 1px solid var(--border); border-radius: 12px; color: inherit; box-shadow: 0 18px 70px #23223835; }
#receipt-dialog { width: min(980px, calc(100% - 24px)); }
dialog::backdrop { background: #17152c64; }
.dialog-header { justify-content: space-between; background: #f3f2fa; border-bottom: 1px solid var(--border); }
.dialog-header h2 { font-size: 1.125rem; }
.dialog-content { padding: 16px 20px; }
.draft-toolbar { display: flex; margin-bottom: 10px; }
.draft-scroll { border: 1px solid var(--border); border-radius: 7px; max-height: min(45vh, 365px); }
#receipt-dialog .draft-scroll { max-height: min(52dvh, 430px); }
.draft-table th, .history-table th { position: sticky; top: 0; z-index: 1; border-top: none; }
.draft-table tr:last-child td { border-bottom: none; }
.draft-table td { padding: 8px 12px; vertical-align: top; }
.draft-table td:nth-child(-n + 2) { padding-top: 17px; }
.dialog-content .status { margin-top: 10px; }
.dialog-footer { justify-content: flex-end; border-top: 1px solid var(--border); }
.visually-hidden { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

#qr-dialog { width: min(680px, calc(100% - 24px)); }
.qr-preview { display: flex; flex-direction: column; max-height: calc(100dvh - 26px); }
.qr-labels { display: flex; flex-wrap: wrap; gap: 12px; }
#qr-preview-labels { min-height: 0; overflow: auto; padding: 16px 20px; }
#qr-print-labels { display: none; }
.qr-label { width: 148px; margin: 0; padding: 8px; text-align: center; border: 1px solid var(--border); border-radius: 6px; }
.qr-label svg { display: block; width: 100%; aspect-ratio: 1; }
.qr-label figcaption { display: grid; gap: 2px; font-size: .875rem; overflow-wrap: anywhere; }

@media (max-width: 1100px) {
  .filters { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 760px) {
  .draft-table, .draft-table tbody { display: block; }
  .draft-table.column-grid { width: 100%; }
  .draft-table thead { display: none; }
  .draft-table tr { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)) auto; padding: 8px; border-bottom: 1px solid var(--border); }
  .draft-table td:nth-child(n) { border: 0; height: auto; min-width: 0; padding: 4px; }
  .draft-table td[data-label]::before { content: attr(data-label); display: block; color: var(--muted); font-size: .8125rem; }
  .draft-table td:nth-child(3), .draft-table td:nth-child(4), .draft-table td:nth-child(5) { grid-column: 1 / -1; }
  .draft-table td:last-child { grid-row: 1; grid-column: 3; }
}
@media (max-width: 560px) {
  nav { gap: 0 10px; }
  .directory-tab { margin-inline-start: 0; }
  .page-heading { flex-wrap: wrap; }
  .filters { grid-template-columns: minmax(0, 1fr); }
  .filters:has(.movement-filter:not([hidden])) fieldset { grid-column: auto; }
  .filters, .table-toolbar, .table-footer, .dialog-header, .dialog-content, .dialog-footer { padding-inline: 12px; }
  .table-footer { align-items: flex-start; flex-direction: column; gap: 8px; }
}
@media print {
  .topbar, nav, .page-heading button, .filters, .table-toolbar, .table-footer, .selection, dialog { display: none !important; }
  :root { background: white; }
  main { padding: 0; }
  .panel { border: 0; }
  .table-scroll { overflow: visible; }
  .column-grid { width: 100%; table-layout: auto; }
  .column-grid col { width: auto !important; }
  .column-resize { display: none; }
  th, td { padding: 5px; }
  body:has(#qr-dialog[open]) main { display: none; }
  body:has(#qr-dialog[open]) #qr-print-labels { display: block; }
  #qr-print-labels .qr-label {
    display: inline-block;
    vertical-align: top;
    break-inside: avoid;
    width: 41mm;
    margin: 0 2mm 2mm 0;
    padding: 2mm 3mm;
    border-color: #ccc;
    border-radius: 0;
    color: #000;
  }
  #qr-print-labels figcaption { font-size: 9pt; }
}
