:root {
  --graphite: #333a44;
  --graphite-2: #4b535c;
  --ink: #182029;
  --ink-on-dark: #f7f8f6;
  --lime: #77bc1f;
  --lime-2: #8bf50a;
  --light: #e4e5e5;
  --white: #fefefe;
  --muted: #69717a;
  --line: rgba(51, 58, 68, 0.14);
  --accent-soft: #eff9e4;
  --surface: #3e4650;
  --surface-soft: #f4f5f3;
  --surface-panel: #414952;
  --surface-panel-2: #353d46;
  --row-a: #d8ddda;
  --row-b: #c7cfca;
  --green-row: #c8ddb8;
  --green-row-strong: #bdd3ac;
  --soon: #f5edce;
  --danger: #f3d7d0;
  --bg: #333a44;
  --radius: 8px;
  --shadow: 0 18px 60px rgba(24, 32, 41, 0.16);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html,
body {
  min-height: 100%;
  background: #333a44;
}
body {
  margin: 0;
  color: var(--ink-on-dark);
  background:
    linear-gradient(180deg, rgba(51, 58, 68, .96), rgba(39, 45, 52, .98)),
    url("/assets/bg-dark-lines.webp") center / cover fixed;
  font: 14px/1.35 "Inter", "Segoe UI", Arial, sans-serif;
}
button, input, select, textarea { font: inherit; }
button {
  border: 0;
  background: var(--graphite);
  color: #fff;
  padding: 8px 13px;
  border-radius: var(--radius);
  cursor: pointer;
  font-weight: 700;
}
button:hover { background: var(--graphite-2); }
.filters > button,
.login-panel button,
.dialog-panel > button,
.stack-form button {
  background: var(--lime);
  color: var(--graphite);
}
.filters > button:hover,
.login-panel button:hover,
.dialog-panel > button:hover,
.stack-form button:hover {
  background: var(--lime-2);
}
label { display: grid; gap: 4px; color: var(--muted); font-size: 12px; }
.app-shell label,
dialog label {
  color: rgba(247, 248, 246, .68);
}
.login-panel label {
  color: var(--muted);
}
input, select, textarea {
  border: 1px solid rgba(228, 229, 229, 0.18);
  border-radius: var(--radius);
  padding: 7px 9px;
  min-width: 0;
  color: var(--ink-on-dark);
  background: rgba(24, 32, 41, 0.3);
  caret-color: var(--lime);
  accent-color: var(--lime);
}
select {
  background-color: #303842;
  color: var(--ink-on-dark);
}
select:focus,
input:focus,
textarea:focus {
  outline: 2px solid rgba(119, 188, 31, .45);
  outline-offset: 1px;
  border-color: rgba(119, 188, 31, .65);
}
select option {
  background: #303842;
  color: #eef2ee;
}
select option:checked {
  background: #46503f;
  color: #ffffff;
}
select option:hover {
  background: #414a54;
  color: #ffffff;
}
input::placeholder, textarea::placeholder { color: rgba(247, 248, 246, .52); }
textarea { min-height: 64px; resize: vertical; }
textarea.compact-note {
  min-height: 36px;
  height: 36px;
  resize: none;
  overflow: hidden;
}
textarea.compact-note.expanded {
  min-height: 92px;
  height: 92px;
  resize: vertical;
  overflow: auto;
}

.login-view {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background:
    radial-gradient(circle at 74% 18%, rgba(119, 188, 31, 0.16), transparent 30%),
    linear-gradient(135deg, #fefefe 0%, #e4e5e5 100%);
}
.login-panel {
  width: min(360px, calc(100vw - 32px));
  display: grid;
  gap: 16px;
  padding: 28px;
  background: rgba(254, 254, 254, 0.96);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.login-brand img {
  width: 164px;
  margin-bottom: 18px;
}
.login-panel h1 { margin: 0; font-size: 26px; }
.login-panel p { margin: 4px 0 0; color: var(--muted); }
.form-error { color: #a42323; min-height: 18px; }

.app-shell {
  height: 100vh;
  display: grid;
  grid-template-rows: auto auto auto minmax(0, 1fr);
  overflow: hidden;
  background:
    linear-gradient(180deg, rgba(51, 58, 68, .98), rgba(39, 45, 52, .98)),
    url("/assets/bg-dark-lines.webp") center / cover fixed;
}
.topbar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  padding: 12px 20px;
  background:
    linear-gradient(90deg, rgba(51, 58, 68, 0.98), rgba(75, 83, 92, 0.93)),
    url("/assets/bg-dark-lines.webp") center / cover;
  border-bottom: 1px solid rgba(228, 229, 229, 0.16);
  color: var(--white);
}
.app-brand {
  display: flex;
  align-items: center;
  gap: 18px;
}
.brand-logo-dark {
  width: 150px;
  height: auto;
  filter: drop-shadow(0 10px 22px rgba(0, 0, 0, .16));
}
.topbar h1 { margin: 0; font-size: 22px; }
.topbar p { margin: 2px 0 0; color: rgba(254, 254, 254, .72); }
.topbar nav { display: flex; gap: 8px; flex-wrap: wrap; }
.topbar button {
  background: rgba(254, 254, 254, 0.08);
  border: 1px solid rgba(254, 254, 254, 0.18);
}
.topbar button:hover {
  background: var(--lime);
  color: var(--graphite);
}
.filters {
  display: grid;
  grid-template-columns: 110px minmax(170px, 260px) minmax(120px, 180px) minmax(135px, 170px) minmax(155px, 220px) auto 1fr;
  align-items: end;
  gap: 12px;
  padding: 12px 20px;
  background: rgba(53, 61, 70, .96);
  border-bottom: 1px solid rgba(228, 229, 229, 0.12);
}
.period-filter {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: minmax(126px, 150px) minmax(150px, 180px) minmax(130px, 150px) minmax(130px, 150px) auto auto 1fr;
  align-items: end;
  gap: 10px;
  padding-top: 2px;
}
.period-filter button {
  height: 36px;
  background: rgba(254, 254, 254, 0.08);
  border: 1px solid rgba(254, 254, 254, 0.18);
  color: var(--ink-on-dark);
}
.period-filter button:hover {
  background: rgba(254, 254, 254, 0.14);
  color: #fff;
}
select.has-custom-select {
  display: none;
}
.custom-select {
  position: relative;
}
.custom-select-button {
  width: 100%;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 7px 34px 7px 12px;
  border: 1px solid rgba(254, 254, 254, 0.18);
  border-radius: var(--radius);
  background: rgba(254, 254, 254, 0.08);
  color: var(--ink-on-dark);
  text-align: left;
  font-weight: 700;
}
.custom-select-button::after {
  content: "⌄";
  position: absolute;
  right: 12px;
  top: 5px;
  color: rgba(247, 248, 246, .86);
  font-size: 20px;
  line-height: 1;
}
.custom-select.open .custom-select-button {
  border-color: rgba(254, 254, 254, 0.34);
  background: rgba(254, 254, 254, 0.12);
  box-shadow: 0 0 0 2px rgba(119, 188, 31, .34);
}
.custom-select-menu {
  position: absolute;
  z-index: 80;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  max-height: 280px;
  overflow: auto;
  padding: 4px;
  border: 1px solid rgba(254, 254, 254, 0.18);
  border-radius: 6px;
  background: #343c45;
  box-shadow: 0 18px 45px rgba(0, 0, 0, .28);
}
.custom-select-menu button {
  width: 100%;
  display: block;
  padding: 8px 10px;
  border-radius: 4px;
  background: transparent;
  color: #eef2ee;
  text-align: left;
  font-weight: 600;
}
.custom-select-menu button:hover,
.custom-select-menu button:focus {
  background: rgba(254, 254, 254, 0.10);
  color: #fff;
  outline: none;
}
.custom-select-menu button.selected {
  background: rgba(119, 188, 31, .18);
  color: #fff;
}
select option:checked,
select option:hover,
select option:focus {
  background: #46503f linear-gradient(#46503f, #46503f);
  color: #ffffff;
  box-shadow: 0 0 0 100px #46503f inset;
}
.metrics {
  display: grid;
  grid-template-columns: repeat(6, minmax(120px, 1fr));
  gap: 1px;
  background: rgba(228, 229, 229, 0.12);
  padding: 1px 20px;
}
.metric-card {
  display: grid;
  gap: 4px;
  padding: 10px 12px;
  background: rgba(65, 73, 82, .96);
  border-top: 3px solid rgba(254, 254, 254, 0.12);
  border-radius: 0;
  color: var(--ink-on-dark);
  text-align: left;
  min-width: 0;
}
.metric-card:hover {
  background: rgba(75, 83, 92, .98);
  color: var(--ink-on-dark);
  border-top-color: rgba(119, 188, 31, .76);
}
.metric-card:focus-visible {
  outline: 2px solid var(--lime);
  outline-offset: -2px;
  border-top-color: var(--lime);
}
.metrics span { color: rgba(247, 248, 246, .68); font-size: 12px; }
.metrics strong { font-size: 20px; }
.workspace {
  --side-pane-width: clamp(420px, 30vw, 560px);
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 10px var(--side-pane-width);
  gap: 0;
  padding: 10px 12px 14px;
  overflow: hidden;
  background: rgba(39, 45, 52, .92);
}
.workspace.resizing {
  cursor: col-resize;
  user-select: none;
}
.workspace.resizing * {
  user-select: none;
}
.workspace-splitter {
  position: relative;
  cursor: col-resize;
  min-width: 10px;
  border-radius: 8px;
}
.workspace-splitter::before {
  content: "";
  position: absolute;
  top: 8px;
  bottom: 8px;
  left: 50%;
  width: 2px;
  transform: translateX(-50%);
  border-radius: 999px;
  background: rgba(228, 229, 229, .18);
}
.workspace-splitter:hover::before,
.workspace-splitter:focus-visible::before,
.workspace.resizing .workspace-splitter::before {
  width: 3px;
  background: rgba(119, 188, 31, .72);
}
.workspace-splitter:focus-visible {
  outline: 1px solid rgba(119, 188, 31, .72);
  outline-offset: -1px;
}
.table-pane, .side-pane section {
  background: var(--surface-panel);
  border: 1px solid rgba(228, 229, 229, 0.12);
  border-radius: var(--radius);
}
.table-pane {
  overflow-y: auto;
  overflow-x: hidden;
}
.digest-table, .summary-table {
  width: 100%;
  border-collapse: collapse;
}
.digest-table {
  table-layout: fixed;
  width: calc(100% - 2px);
  max-width: 100%;
  font-size: clamp(10px, .72vw, 13px);
}
th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--graphite);
  color: #fff;
  font-weight: 700;
  text-align: center;
  padding: 8px;
  border-right: 1px solid rgba(255,255,255,.24);
}
td {
  height: 28px;
  padding: 4px 6px;
  border: 1px solid rgba(51, 58, 68, 0.08);
  text-align: center;
  white-space: normal;
  overflow-wrap: anywhere;
  color: var(--ink);
}
.digest-table th,
.digest-table td {
  line-height: 1.2;
  min-width: 0;
}
.digest-table th:nth-child(1), .digest-table td:nth-child(1) { width: 3.0%; }
.digest-table th:nth-child(2), .digest-table td:nth-child(2) { width: 9.2%; }
.digest-table th:nth-child(3), .digest-table td:nth-child(3) { width: 6.2%; }
.digest-table th:nth-child(4), .digest-table td:nth-child(4) { width: 5.4%; }
.digest-table th:nth-child(5), .digest-table td:nth-child(5) { width: 5.9%; }
.digest-table th:nth-child(6), .digest-table td:nth-child(6) { width: 3.1%; }
.digest-table th:nth-child(7), .digest-table td:nth-child(7) { width: 8.0%; }
.digest-table th:nth-child(8), .digest-table td:nth-child(8) { width: 3.3%; }
.digest-table th:nth-child(9), .digest-table td:nth-child(9) { width: 5.6%; }
.digest-table th:nth-child(10), .digest-table td:nth-child(10) { width: 4.0%; }
.digest-table th:nth-child(11), .digest-table td:nth-child(11) { width: 5.6%; }
.digest-table th:nth-child(12), .digest-table td:nth-child(12) { width: 4.1%; }
.digest-table th:nth-child(13), .digest-table td:nth-child(13) { width: 5.2%; }
.digest-table th:nth-child(14), .digest-table td:nth-child(14) { width: 3.1%; }
.digest-table th:nth-child(15), .digest-table td:nth-child(15) { width: 6.4%; }
.digest-table th:nth-child(16), .digest-table td:nth-child(16) { width: 5.4%; }
.digest-table th:nth-child(17), .digest-table td:nth-child(17) { width: 4.1%; }
.digest-table th:nth-child(18), .digest-table td:nth-child(18) { width: 3.5%; }
.row-number-cell {
  text-align: center;
  white-space: nowrap;
}
.row-select {
  width: 14px;
  height: 14px;
  margin: 0 3px 0 0;
  accent-color: var(--lime);
  cursor: pointer;
  vertical-align: middle;
}
.row-number-cell span {
  vertical-align: middle;
}
.bulk-selection-status {
  display: grid;
  gap: 4px;
  padding: 8px 10px;
  border: 1px solid rgba(119, 188, 31, .35);
  border-radius: 7px;
  background: rgba(119, 188, 31, .10);
  color: var(--ink-on-dark);
  font-size: 12px;
}
.bulk-selection-status span {
  color: rgba(247, 248, 246, .72);
}
.bulk-selection-status .selection-warning {
  color: #f3c8c4;
}
.digest-table td.shipped-cell {
  padding-left: 0;
  padding-right: 0;
  text-align: center;
}
.digest-table td.shipped-cell .ship-input {
  width: min(78px, calc(100% - 4px));
  height: 24px;
  padding: 2px 4px;
  text-align: center;
  display: block;
  box-sizing: border-box;
  margin: 0;
  position: relative;
  left: 50%;
  transform: translateX(-50%);
  color: var(--ink);
  background: rgba(254, 254, 254, .78);
  border-color: rgba(51, 58, 68, .12);
  font-variant-numeric: tabular-nums;
}
td .delete-line {
  width: 22px;
  height: 22px;
  padding: 0;
  border-radius: 4px;
  background: #9d3b3b;
  text-decoration: none;
}
.row-actions {
  text-align: center;
  white-space: nowrap;
}
.row-actions button { margin: 0 1px; vertical-align: middle; }
td .edit-line {
  width: 22px;
  height: 22px;
  padding: 0;
  border-radius: 4px;
  background: rgba(51, 58, 68, .88);
  color: var(--ink-on-dark);
  font-size: 18px;
  line-height: 1;
  text-decoration: none;
}
td .edit-line:hover {
  background: var(--lime);
  color: var(--graphite);
}
.doc-badges {
  display: inline-flex;
  justify-content: center;
  align-items: center;
  gap: 4px;
}
.doc-badge {
  display: inline-grid;
  place-items: center;
  min-width: 22px;
  height: 22px;
  padding: 0 5px;
  border-radius: 999px;
  color: var(--graphite);
  font-size: 11px;
  font-weight: 900;
  line-height: 1;
}
.doc-spec {
  background: #78bd1f;
}
.doc-shipment {
  background: #9fcb63;
  max-width: 52px;
  padding: 0 6px;
  border-radius: 999px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
td:nth-child(2) { text-align: left; }
.digest-table td:nth-child(7) { text-align: center; }
tr.group-a td { background: var(--row-a); }
tr.group-b td { background: var(--row-b); }
tr.done td {
  background: var(--green-row);
  color: #182029;
}
tr.overdue td:nth-child(11), tr.overdue td:nth-child(12) { background: var(--danger); }
tr.soon:not(.done) td {
  background: var(--soon);
  color: #182029;
}
td.delay-late {
  background: #f1ccc9 !important;
  color: #7f2525;
  font-weight: 800;
}
td.delay-early,
td.delay-ok {
  background: rgba(200, 221, 184, .92) !important;
  color: #203220;
  font-weight: 800;
}
tr.selected td {
  position: static;
  box-shadow: none;
}
tr.selected td::after {
  content: none;
}
tr.selected {
  outline: 1px solid rgba(119, 188, 31, .72);
  outline-offset: -1px;
}
tr.selected.done td {
  box-shadow: none;
}
tr.selected.done {
  outline-color: rgba(73, 129, 55, .76);
}
.side-pane {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 14px;
  min-height: 0;
}
.side-pane section {
  padding: 14px;
  overflow: auto;
}
.side-pane h2 {
  margin: 0 0 14px;
  font-size: 18px;
  line-height: 1.2;
  color: var(--ink-on-dark);
}
.active-row-number {
  display: inline-block;
  margin-left: 6px;
  color: rgba(247, 248, 246, .70);
  font-size: 13px;
  font-weight: 700;
}
.stack-form { display: grid; gap: 10px; }
.date-entry {
  position: relative;
  display: grid;
}
.date-entry input[type="text"] {
  width: 100%;
  padding-right: 42px;
}
.date-picker-button {
  position: absolute;
  right: 9px;
  top: 50%;
  width: 18px;
  height: 18px;
  min-width: 18px;
  padding: 0;
  transform: translateY(-50%);
  border: 0;
  border-radius: 3px;
  background: transparent !important;
  color: #05080a !important;
}
.date-picker-button::before {
  content: "";
  position: absolute;
  left: 3px;
  top: 4px;
  width: 12px;
  height: 11px;
  border: 2px solid currentColor;
  border-radius: 2px;
}
.date-picker-button::after {
  content: "";
  position: absolute;
  left: 5px;
  top: 8px;
  width: 8px;
  height: 2px;
  background: currentColor;
  box-shadow: 0 -4px 0 currentColor;
}
.date-picker-button:hover {
  background: rgba(254, 254, 254, 0.10) !important;
}
.visually-hidden-date {
  position: absolute;
  right: 5px;
  top: 50%;
  width: 30px;
  height: 30px;
  opacity: 0;
  pointer-events: none;
}
.note-field {
  gap: 5px;
}
.note-label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.note-toggle {
  height: 24px;
  padding: 0 8px;
  border-radius: 5px;
  background: rgba(254, 254, 254, 0.08);
  border: 1px solid rgba(254, 254, 254, 0.16);
  color: rgba(247, 248, 246, .82);
  font-size: 11px;
  font-weight: 700;
}
.note-toggle:hover {
  background: rgba(254, 254, 254, 0.14);
}
.stack-form .secondary-action {
  background: rgba(254, 254, 254, 0.08);
  border: 1px solid rgba(254, 254, 254, 0.18);
  color: var(--ink-on-dark);
}
.stack-form .secondary-action:hover {
  background: rgba(254, 254, 254, 0.14);
}
.compact-secondary-action {
  justify-self: start;
  width: auto;
  padding: 6px 10px;
  border: 1px solid rgba(254, 254, 254, 0.18);
  border-radius: 6px;
  background: rgba(254, 254, 254, 0.08) !important;
  color: rgba(247, 248, 246, .88) !important;
  font-size: 12px;
}
.compact-secondary-action:hover {
  background: rgba(254, 254, 254, 0.14) !important;
}
.selection-actions {
  display: grid;
  grid-template-columns: minmax(104px, .72fr) minmax(210px, 1.28fr);
  gap: 6px;
  align-items: center;
}
.selection-actions:empty {
  display: none;
}
.selection-actions .compact-secondary-action {
  width: 100%;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: clip;
  padding-left: 6px;
  padding-right: 6px;
  font-size: 11px;
}
#clearSelectedRowsButton[hidden] + #selectSpecRowsButton {
  grid-column: 1 / -1;
}
@container (max-width: 390px) {
  .selection-actions {
    grid-template-columns: 1fr;
  }
  .selection-actions .compact-secondary-action {
    white-space: normal;
    line-height: 1.2;
    min-height: 30px;
  }
}
.document-uploader {
  display: grid;
  gap: 9px;
  padding: 10px;
  border: 1px solid rgba(228, 229, 229, 0.14);
  border-radius: var(--radius);
  background: rgba(24, 32, 41, 0.22);
}
.document-targets:empty {
  display: none;
}
.document-targets {
  display: grid;
  gap: 7px;
}
.target-note,
.target-title {
  color: rgba(247, 248, 246, .72);
  font-size: 12px;
  font-weight: 700;
}
.target-list {
  display: grid;
  gap: 5px;
  max-height: 155px;
  overflow: auto;
  padding-right: 3px;
}
.target-row {
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr);
  align-items: center;
  gap: 8px;
  padding: 6px 7px;
  border: 1px solid rgba(228, 229, 229, 0.10);
  border-radius: 6px;
  background: rgba(254, 254, 254, 0.05);
  color: var(--ink-on-dark);
}
.target-row input {
  width: 16px;
  height: 16px;
  padding: 0;
}
.target-row span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.attached-documents:empty { display: none; }
.attached-documents {
  display: grid;
  gap: 8px;
  padding: 10px;
  border: 1px solid rgba(228, 229, 229, 0.14);
  border-radius: var(--radius);
  background: rgba(24, 32, 41, 0.24);
}
.attached-title {
  color: rgba(247, 248, 246, .68);
  font-size: 12px;
  font-weight: 700;
}
.attached-list {
  display: grid;
  gap: 6px;
}
.attached-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 28px;
  gap: 7px;
  align-items: center;
}
.attached-item a {
  display: grid;
  grid-template-columns: 92px minmax(0, 1fr);
  gap: 8px;
  align-items: center;
  color: var(--ink-on-dark);
  text-decoration: none;
  min-width: 0;
}
.attached-item a:hover strong { text-decoration: underline; }
.attached-item span {
  padding: 3px 6px;
  border-radius: 4px;
  background: var(--lime);
  color: var(--graphite);
  font-size: 11px;
  font-weight: 800;
  text-align: center;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.attached-item strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 600;
}
.attached-item button {
  width: 28px;
  height: 28px;
  padding: 0;
  border-radius: 6px;
  background: #9e3f3f;
  color: #fff;
  border: 1px solid rgba(255, 255, 255, .10);
  line-height: 1;
}
.attached-item button:hover {
  background: #b84a4a;
}
.summary-table {
  table-layout: fixed;
  background: var(--surface-panel-2);
  border: 0;
  border-radius: 6px;
  overflow: hidden;
}
.summary-table th {
  position: static;
  height: 42px;
  padding: 6px 6px;
  font-size: 12px;
  line-height: 1.12;
  vertical-align: middle;
  white-space: nowrap;
  background: var(--graphite);
  border: 0;
}
.summary-table th:nth-child(1),
.summary-table td:nth-child(1) {
  width: 42%;
}
.summary-table th:nth-child(2),
.summary-table td:nth-child(2) {
  width: 19%;
}
.summary-table th:nth-child(3),
.summary-table td:nth-child(3) {
  width: 23%;
}
.summary-table th:nth-child(4),
.summary-table td:nth-child(4) {
  width: 14%;
}
.summary-table td {
  height: 30px;
  text-align: center;
  background: #dfe4e1;
  border: 0;
  color: var(--ink);
}
.summary-table tr:nth-child(even) td {
  background: #c8d0cb;
}
.summary-table td:first-child {
  text-align: left;
  max-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

dialog {
  width: min(920px, calc(100vw - 32px));
  max-width: calc(100vw - 32px);
  border: 1px solid rgba(228, 229, 229, 0.16);
  border-radius: var(--radius);
  padding: 0;
  color: var(--ink-on-dark);
  background: var(--surface-panel);
  overflow-x: hidden;
}
dialog::backdrop { background: rgba(15, 30, 34, .62); }
.dialog-panel {
  box-sizing: border-box;
  min-width: 0;
  padding: 18px;
  display: grid;
  gap: 14px;
}
.dialog-panel header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}
.dialog-panel h2 { margin: 0; }
.dialog-panel,
.dialog-panel p,
.dialog-panel td {
  color: var(--ink-on-dark);
}
.dialog-panel input,
.dialog-panel select,
.dialog-panel textarea {
  color: var(--ink-on-dark);
  background: rgba(24, 32, 41, 0.24);
  border-color: rgba(228, 229, 229, 0.16);
}
.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}
.wide-field {
  grid-column: 1 / -1;
}
#manualDialog {
  width: min(1120px, calc(100vw - 32px));
  max-width: calc(100vw - 32px);
  overflow-x: hidden;
}
.manual-dialog {
  width: 100%;
  max-width: 100%;
  max-height: min(820px, calc(100vh - 48px));
  padding: 16px;
  overflow-x: hidden;
  overflow-y: auto;
}
.manual-dialog *,
.manual-dialog *::before,
.manual-dialog *::after {
  box-sizing: border-box;
  min-width: 0;
}
.manual-dialog .form-grid {
  grid-template-columns: minmax(0, 1.15fr) minmax(210px, 0.85fr);
}
.manual-dialog input,
.manual-dialog select {
  width: 100%;
}
.manual-section {
  display: grid;
  gap: 12px;
  padding: 14px;
  border: 1px solid rgba(228, 229, 229, 0.12);
  border-radius: 6px;
  background: rgba(24, 32, 41, 0.18);
}
.manual-section h3,
.manual-lines-header h3 {
  margin: 0;
  color: var(--ink-on-dark);
  font-size: 16px;
}
.manual-notice {
  padding: 12px 14px;
  border: 1px solid rgba(119, 188, 31, 0.45);
  border-radius: 6px;
  background: rgba(119, 188, 31, 0.10);
  color: var(--ink-on-dark);
  line-height: 1.45;
}
.manual-notice strong {
  color: #ffffff;
}
.manual-lines-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.manual-lines {
  display: grid;
  gap: 8px;
}
.manual-line {
  display: grid;
  grid-template-columns: minmax(170px, 1.8fr) minmax(58px, .45fr) minmax(96px, .65fr) minmax(78px, .52fr) minmax(108px, .72fr) minmax(102px, .72fr) 30px;
  gap: 8px;
  align-items: end;
  padding: 10px;
  border: 1px solid rgba(228, 229, 229, 0.10);
  border-radius: 6px;
  background: rgba(254, 254, 254, 0.04);
}
.manual-line label {
  min-width: 0;
}
.manual-line input {
  width: 100%;
}
.delete-manual-line {
  width: 32px;
  height: 36px;
  padding: 0;
  border-radius: 6px;
  background: #9e3f3f;
  color: #fff;
}
.delete-manual-line:hover {
  background: #b84a4a;
}
@media (max-width: 1040px) {
  #manualDialog {
    width: calc(100vw - 24px);
    max-width: calc(100vw - 24px);
  }
  .manual-dialog {
    padding: 14px;
  }
  .manual-dialog .form-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .manual-line {
    grid-template-columns: minmax(0, 1.6fr) minmax(70px, .55fr) minmax(110px, .85fr) minmax(92px, .72fr);
  }
  .manual-line .manual-period {
    grid-column: span 2;
  }
  .manual-line .delete-manual-line {
    grid-column: 4;
    grid-row: 2;
    justify-self: end;
  }
}
@media (max-width: 760px) {
  .manual-dialog .form-grid {
    grid-template-columns: 1fr;
  }
  .manual-line {
    grid-template-columns: minmax(0, 1fr) 32px;
  }
  .manual-line label,
  .manual-line .manual-period {
    grid-column: 1;
  }
  .manual-line .delete-manual-line {
    grid-column: 2;
    grid-row: 1;
  }
}
.preview {
  max-height: 320px;
  overflow: auto;
  border: 1px solid rgba(228, 229, 229, 0.14);
  border-radius: 6px;
  padding: 10px;
  background: rgba(24, 32, 41, 0.24);
}
.preview-source {
  display: grid;
  gap: 3px;
  margin-bottom: 10px;
  padding: 10px;
  border-radius: 6px;
  background: rgba(254, 254, 254, 0.06);
  color: var(--ink-on-dark);
}
.preview-source span {
  color: rgba(247, 248, 246, 0.72);
  font-size: 12px;
}
.preview-item {
  display: grid;
  gap: 10px;
  margin-top: 10px;
  padding: 10px;
  border: 1px solid rgba(228, 229, 229, 0.12);
  border-radius: 6px;
  background: rgba(24, 32, 41, 0.18);
}
.preview-item.warning {
  border: 1px solid rgba(119, 188, 31, 0.45);
  border-radius: 6px;
  padding: 8px 10px;
  background: rgba(119, 188, 31, 0.10);
}
.preview-title {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 10px;
}
.preview-title span,
.preview-warning {
  color: rgba(247, 248, 246, 0.76);
}
.preview-fields {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin: 0;
}
.preview-fields div {
  padding: 7px 8px;
  border-radius: 5px;
  background: rgba(254, 254, 254, 0.06);
}
.preview-fields dt {
  color: rgba(247, 248, 246, 0.62);
  font-size: 11px;
}
.preview-fields dd {
  margin: 2px 0 0;
  color: var(--ink-on-dark);
  font-weight: 700;
}
.preview-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}
.preview-table th,
.preview-table td {
  padding: 7px 8px;
  border-bottom: 1px solid rgba(228, 229, 229, 0.10);
  color: var(--ink-on-dark);
}
.preview-table th {
  background: #303842;
}
.preview-table td {
  background: rgba(254, 254, 254, 0.04);
}
.preview-table th:first-child,
.preview-table td:first-child {
  text-align: left;
  width: 38%;
}
.preview:empty { display: none; }
.tabs {
  display: flex;
  gap: 8px;
}
.tab {
  background: #e8eef1;
  color: var(--ink);
}
.tab.active {
  background: var(--lime);
  color: var(--graphite);
}
.reference-dialog {
  max-height: min(760px, calc(100vh - 48px));
}
.reference-panel {
  min-height: 0;
  max-height: 520px;
  overflow: auto;
  border: 1px solid rgba(228, 229, 229, 0.14);
  border-radius: 6px;
}
.reference-table {
  width: 100%;
  border-collapse: collapse;
}
.reference-table th {
  position: sticky;
  top: 0;
}
.reference-table td:first-child {
  text-align: left;
  white-space: normal;
  color: rgba(247, 248, 246, .88);
}
.reference-table input {
  width: 100%;
}
.reference-table button {
  padding: 6px 10px;
}
#settingsDialog,
.settings-dialog {
  width: min(620px, calc(100vw - 32px));
  max-width: calc(100vw - 32px);
}
.settings-section {
  display: grid;
  gap: 12px;
  padding: 14px;
  border: 1px solid rgba(228, 229, 229, 0.12);
  border-radius: 6px;
  background: rgba(24, 32, 41, 0.20);
}
.settings-section h3 {
  margin: 0;
  color: var(--ink-on-dark);
  font-size: 16px;
}
.settings-section label {
  color: rgba(247, 248, 246, .72);
}
.settings-section input {
  width: 160px;
}
.settings-section > button {
  justify-self: start;
}
.settings-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}
.settings-actions button {
  height: 42px;
  background: rgba(254, 254, 254, 0.08);
  border: 1px solid rgba(254, 254, 254, 0.18);
  color: var(--ink-on-dark);
}
.settings-actions button:hover {
  background: var(--lime);
  color: var(--graphite);
}
.metric-dialog {
  max-height: min(760px, calc(100vh - 48px));
}
.metric-list {
  max-height: 560px;
  overflow: auto;
  display: grid;
  gap: 14px;
}
.metric-money {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  grid-auto-rows: minmax(86px, auto);
  gap: 1px;
  min-height: 86px;
  overflow: hidden;
  border-radius: 6px;
  background: rgba(228, 229, 229, 0.12);
  align-items: stretch;
}
.metric-money button {
  display: grid;
  gap: 6px;
  align-content: center;
  min-height: 86px;
  padding: 12px;
  background: var(--surface-panel-2);
  border-radius: 0;
  color: var(--ink-on-dark);
  text-align: left;
  border: 0;
  border-top: 3px solid transparent;
}
.metric-money button:hover {
  background: rgba(75, 83, 92, .98);
}
.metric-money button.active {
  border-top-color: var(--lime);
}
.metric-money span {
  display: block;
  color: rgba(247, 248, 246, .68);
  font-size: 12px;
  line-height: 1.25;
}
.metric-money strong {
  display: block;
  color: var(--ink-on-dark);
  font-size: 18px;
  line-height: 1.2;
}
.money-detail {
  display: grid;
  gap: 8px;
  min-width: 0;
}
.money-detail h3 {
  margin: 0;
  color: var(--ink-on-dark);
  font-size: 16px;
}
.metric-section-title {
  margin: 2px 0 -2px;
  color: var(--ink-on-dark);
  font-size: 16px;
}
.metric-detail-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  overflow: hidden;
  border-radius: 6px;
}
.metric-detail-table th {
  position: sticky;
  top: 0;
}
.metric-detail-table th:nth-child(1),
.metric-detail-table td:nth-child(1) {
  width: 25%;
}
.metric-detail-table th:nth-child(2),
.metric-detail-table td:nth-child(2) {
  width: 16%;
}
.metric-detail-table th:nth-child(3),
.metric-detail-table td:nth-child(3) {
  width: 16%;
}
.metric-detail-table td {
  text-align: left;
  white-space: normal;
  vertical-align: top;
  background: #dfe4e1;
  color: var(--ink);
}
.metric-detail-table tr:nth-child(even) td {
  background: #c8d0cb;
}
.money-detail-table th:nth-child(1),
.money-detail-table td:nth-child(1) {
  width: 28%;
}
.money-detail-table th:nth-child(2),
.money-detail-table td:nth-child(2) {
  width: 16%;
}
.money-detail-table th:nth-child(3),
.money-detail-table td:nth-child(3) {
  width: auto;
}
.money-detail-table th:nth-child(4),
.money-detail-table td:nth-child(4) {
  width: 18%;
  text-align: right;
}
.history-dialog {
  max-height: min(760px, calc(100vh - 48px));
}
.history-list {
  max-height: 580px;
  overflow: auto;
}
.history-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}
.history-table th {
  position: sticky;
  top: 0;
}
.history-table th:nth-child(1),
.history-table td:nth-child(1) {
  width: 120px;
}
.history-table th:nth-child(2),
.history-table td:nth-child(2) {
  width: 110px;
}
.history-table th:nth-child(3),
.history-table td:nth-child(3) {
  width: 180px;
}
.history-table td {
  text-align: left;
  white-space: normal;
  vertical-align: top;
  background: #dfe4e1;
  color: var(--ink);
}
.history-table tr:nth-child(even) td {
  background: #c8d0cb;
}
.users-dialog {
  max-height: min(760px, calc(100vh - 48px));
  width: min(1100px, calc(100vw - 48px));
  max-width: calc(100vw - 48px);
  overflow-x: hidden;
  overflow-y: auto;
  box-sizing: border-box;
}
#usersForm {
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
}
.user-create {
  display: grid;
  gap: 12px;
  padding: 14px;
  border: 1px solid rgba(228, 229, 229, 0.12);
  border-radius: 6px;
  background: rgba(24, 32, 41, 0.22);
}
.user-create h3 {
  margin: 0;
  color: var(--ink-on-dark);
  font-size: 16px;
}
.password-note {
  margin: -4px 0 0;
  color: rgba(247, 248, 246, .68);
  font-size: 12px;
}
.user-create-grid {
  display: grid;
  grid-template-columns: minmax(110px, 150px) minmax(160px, 210px) minmax(130px, 150px) minmax(100px, 112px);
  gap: 10px;
  align-items: end;
  min-width: 0;
}
.users-list {
  max-height: 480px;
  overflow-y: auto;
  overflow-x: hidden;
  max-width: 100%;
  border: 1px solid rgba(228, 229, 229, 0.12);
  border-radius: 6px;
  background: rgba(24, 32, 41, 0.18);
}
.users-grid {
  display: grid;
  min-width: 0;
  width: 100%;
  overflow-x: hidden;
}
.users-dialog *,
.users-list *,
.user-create * {
  box-sizing: border-box;
}
.users-dialog input,
.users-dialog select,
.users-dialog button {
  max-width: 100%;
}
.users-grid-head,
.user-row {
  display: grid;
  grid-template-columns: minmax(0, 15%) minmax(0, 15%) minmax(0, 10%) minmax(0, 28%) minmax(0, 32%);
  gap: 0;
  align-items: center;
  min-width: 0;
  width: 100%;
  box-sizing: border-box;
}
.users-grid-head {
  position: sticky;
  top: 0;
  z-index: 2;
  padding: 11px 12px;
  background: #303842;
  color: var(--ink-on-dark);
  font-weight: 800;
  text-align: center;
  border-bottom: 1px solid rgba(254, 254, 254, .12);
}
.user-row {
  padding: 9px 10px;
  background: rgba(62, 70, 80, .76);
  border-bottom: 1px solid rgba(254, 254, 254, .08);
}
.user-row:nth-child(odd) {
  background: rgba(55, 64, 73, .86);
}
.user-row:last-child {
  border-bottom: 0;
}
.user-field {
  display: grid;
  gap: 5px;
  min-width: 0;
  padding-right: 10px;
}
.user-field > span {
  display: none;
}
.user-field input,
.user-field select {
  width: 100%;
  color: #f7f8f6;
  background: rgba(24, 32, 41, .42);
  border-color: rgba(254, 254, 254, .18);
  height: 36px;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}
.user-field input:focus,
.user-field select:focus {
  background: rgba(24, 32, 41, .56);
}
.user-field input::placeholder {
  color: rgba(247, 248, 246, .62);
}
.password-field {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 44px;
  gap: 10px;
  min-width: 0;
  width: 100%;
  align-items: center;
}
.user-password {
  display: grid !important;
  justify-self: center;
  width: min(100%, 250px);
  visibility: visible;
  opacity: 1;
}
.users-grid-head span:nth-child(4) {
  width: min(100%, 250px);
  justify-self: center;
  text-align: center;
}
.user-password .password-field {
  display: grid !important;
  visibility: visible;
  opacity: 1;
}
.user-password input[data-user-field="password"] {
  display: block !important;
  visibility: visible;
  opacity: 1;
  min-width: 0;
  background: rgba(24, 32, 41, .58);
  border-color: rgba(254, 254, 254, .24);
}
.password-field button {
  width: 38px;
  min-width: 38px;
  height: 36px;
  padding: 0;
  justify-self: center;
  align-self: center;
  background: #303842;
  border: 1px solid rgba(254, 254, 254, 0.24);
  color: #f7f8f6;
  line-height: 1;
  white-space: nowrap;
  position: relative;
}
.password-field .icon-eye {
  display: inline-grid;
  place-items: center;
}
.icon-eye::before {
  content: "";
  width: 20px;
  height: 12px;
  border: 2px solid currentColor;
  border-radius: 50% / 58%;
  transform: rotate(-2deg);
}
.icon-eye::after {
  content: "";
  position: absolute;
  width: 6px;
  height: 6px;
  border: 2px solid currentColor;
  border-radius: 50%;
}
.icon-eye.is-visible::before,
.icon-eye.is-visible::after {
  color: var(--lime);
}
.password-field button:hover {
  background: #414a54;
}
.user-active-toggle {
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: center;
  min-width: 0;
  padding-right: 8px;
  color: var(--ink-on-dark);
  font-size: 13px;
}
.user-active-toggle input {
  width: auto;
  min-width: 16px;
}
.user-actions {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 8px;
  justify-content: center;
  align-items: center;
  min-width: 0;
  padding-left: 8px;
}
.user-actions button {
  margin: 0;
  padding: 0 6px;
  min-width: 0;
  width: 100%;
  height: 36px;
  border-radius: 6px;
  background: rgba(24, 32, 41, .44);
  border: 1px solid rgba(254, 254, 254, .12);
  color: var(--ink-on-dark);
  font-size: 13px;
  line-height: 1;
  white-space: nowrap;
  overflow: visible;
  text-overflow: clip;
}
.user-actions button:hover {
  background: rgba(24, 32, 41, .62);
}
.danger-action {
  background: #9e3f3f;
  color: #fff;
  border-color: rgba(255, 255, 255, .10);
}
.danger-action:hover {
  background: #b84a4a;
}
#usersDialog,
.users-dialog {
  width: min(1040px, calc(100vw - 32px));
  max-width: calc(100vw - 32px);
}
.users-grid-head,
.user-row {
  grid-template-columns: minmax(120px, .85fr) minmax(130px, .72fr) minmax(104px, .52fr) minmax(210px, 1fr) minmax(230px, .95fr);
  column-gap: 8px;
  padding-left: 12px;
  padding-right: 12px;
}
.user-field {
  padding-right: 0;
}
.user-password {
  justify-self: stretch;
  width: 100%;
}
.users-grid-head span:nth-child(4) {
  width: auto;
}
.user-password .password-field,
.password-field {
  grid-template-columns: minmax(0, 1fr) 42px;
  gap: 8px;
  align-items: center;
}
.password-field button {
  width: 38px;
  min-width: 38px;
  justify-self: center;
}
.user-actions {
  padding-left: 0;
}
.user-actions button {
  padding: 0 8px;
  white-space: nowrap;
}
.reference-actions {
  display: grid;
  grid-template-columns: minmax(96px, 1fr) minmax(82px, 92px);
  gap: 8px;
}
.reference-actions button {
  min-width: 0;
  white-space: nowrap;
}
.empty-list {
  margin: 0;
  padding: 18px;
  color: rgba(247, 248, 246, .68);
}

@media (max-width: 1380px) {
  .workspace {
    --side-pane-width: clamp(390px, 34vw, 480px);
  }
  .digest-table {
    font-size: 9px;
  }
  th { padding: 6px 3px; }
  td { padding: 3px 3px; }
  .side-pane section { padding: 10px; }
  .digest-table td.shipped-cell .ship-input {
    width: min(70px, calc(100% - 4px));
    padding-left: 2px;
    padding-right: 2px;
    font-size: 9px;
  }
  .attached-item a {
    grid-template-columns: 72px minmax(0, 1fr);
  }
  td .delete-line,
  td .edit-line {
    width: 20px;
    height: 20px;
    font-size: 15px;
  }
  .row-actions button {
    margin: 0;
  }
  .doc-badge {
    min-width: 18px;
    height: 20px;
    padding: 0 3px;
    font-size: 9px;
  }
}

@media (max-width: 1100px) {
  .workspace { grid-template-columns: 1fr; }
  .workspace-splitter { display: none; }
  .metrics { grid-template-columns: repeat(3, 1fr); }
  .filters { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .period-filter { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .manual-line {
    grid-template-columns: repeat(2, minmax(0, 1fr)) 32px;
  }
  .manual-equipment,
  .manual-period {
    grid-column: span 2;
  }
}
@media (max-width: 680px) {
  .topbar { align-items: flex-start; flex-direction: column; }
  .metrics { grid-template-columns: repeat(2, 1fr); }
  .form-grid { grid-template-columns: 1fr; }
  .manual-line {
    grid-template-columns: 1fr 32px;
  }
  .manual-line label {
    grid-column: 1;
  }
}

@media (max-width: 860px) {
  .user-create-grid {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 760px) {
  .user-create-grid {
    grid-template-columns: 1fr;
  }
  .users-grid-head {
    display: none;
  }
  .user-row {
    grid-template-columns: 1fr;
    gap: 10px;
  }
  .user-field > span {
    display: block;
    color: rgba(247, 248, 246, .68);
    font-size: 12px;
  }
  .user-active-toggle {
    justify-content: flex-start;
  }
  .user-actions {
    grid-template-columns: repeat(2, minmax(120px, 1fr));
  }
}
