@import url("/assets/analytics-theme.css");

* {
  box-sizing: border-box;
}

html {
  min-width: 980px;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", "Segoe UI Variable", "Segoe UI", Arial, sans-serif;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0;
  text-rendering: geometricPrecision;
}

.icon-sprite {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}

.icon {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
  fill: none;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  align-items: center;
  padding: 22px var(--page-pad) 18px;
  background: rgba(255, 255, 255, 0.86);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(10px);
}

.embedded .topbar {
  display: none;
}

.brand-lockup {
  display: flex;
  gap: 14px;
  align-items: center;
  min-width: 0;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 10px;
  background: var(--accent-soft);
  color: var(--accent-strong);
  border: 1px solid #c4e5dc;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  color: var(--text-strong);
  font-size: 28px;
  line-height: 1.05;
  font-weight: 760;
}

h2 {
  color: var(--text-strong);
  font-size: 18px;
  line-height: 1.2;
  font-weight: 720;
}

p {
  margin-top: 6px;
  color: var(--muted);
}

.app-version {
  display: inline-flex;
  margin-left: 10px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  vertical-align: middle;
}

.topbar-status {
  display: flex;
  gap: 8px;
  align-items: center;
}

.status {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 34px;
  padding: 7px 11px;
  white-space: nowrap;
  color: var(--muted-strong);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  font-size: 12px;
  font-weight: 650;
}

.status::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: #9aa9a6;
}

main {
  padding: 18px var(--page-pad) 28px;
}

.embedded main {
  padding: 0;
}

.query-panel,
.summary,
.table-actions,
.table-shell,
.print-preview {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.query-panel {
  margin-bottom: 12px;
  padding: 14px;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.8) inset;
}

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

.eyebrow {
  display: block;
  margin-bottom: 5px;
  color: var(--accent-strong);
  font-size: 11px;
  font-weight: 760;
  text-transform: uppercase;
}

.panel-hint {
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.query-primary {
  display: grid;
  grid-template-columns: auto minmax(156px, 190px) minmax(420px, 1fr) auto;
  gap: 12px;
  align-items: end;
}

.query-period {
  display: grid;
  grid-template-columns: 132px 132px 54px;
  gap: 8px;
  align-items: end;
}

label {
  display: grid;
  gap: 6px;
  min-width: 0;
}

label span,
.period-menu-field > span {
  color: var(--muted-strong);
  font-size: 12px;
  font-weight: 560;
}

input,
select,
button {
  min-height: var(--control-h);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: #fff;
  color: var(--text);
  font: inherit;
}

input,
select {
  padding: 8px 10px;
}

select {
  cursor: pointer;
}

input:hover,
select:hover,
.filter-popover summary:hover {
  border-color: #8fb1aa;
}

input:focus,
select:focus,
button:focus-visible,
summary:focus-visible,
a:focus-visible {
  outline: 3px solid rgba(21, 123, 112, 0.2);
  outline-offset: 2px;
}

.production-field {
  min-width: 150px;
}

.period-menu-field {
  position: relative;
  display: grid;
  gap: 6px;
}

.period-menu-button {
  width: 54px;
  padding: 0;
  font-size: 17px;
  line-height: 1;
}

.period-menu {
  position: absolute;
  top: calc(100% + 7px);
  right: 0;
  z-index: 30;
  display: grid;
  gap: 4px;
  min-width: 178px;
  padding: 6px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-tight);
}

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

.period-menu button {
  justify-content: flex-start;
  min-height: 32px;
  padding: 0 10px;
  border-color: transparent;
  background: transparent;
  color: var(--text);
  text-align: left;
  font-weight: 620;
}

.period-menu button:hover {
  background: var(--accent-tint);
  color: var(--accent-strong);
}

.filter-popovers {
  display: flex;
  gap: 8px;
  align-items: end;
  flex-wrap: wrap;
  min-width: 0;
}

.filter-popover {
  position: relative;
  min-width: 142px;
}

.filter-popover summary {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 7px 10px;
  align-items: center;
  min-height: 56px;
  padding: 8px 12px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--surface-raised);
  cursor: pointer;
  list-style: none;
  user-select: none;
  transition: border-color 120ms ease, background 120ms ease, box-shadow 120ms ease;
}

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

.filter-popover summary::after {
  content: "";
  grid-column: 2;
  grid-row: 1;
  width: 8px;
  height: 8px;
  border-right: 1.5px solid var(--muted);
  border-bottom: 1.5px solid var(--muted);
  transform: rotate(45deg) translateY(-2px);
}

.filter-popover[open] summary {
  border-color: #7eb9ae;
  background: var(--accent-tint);
  box-shadow: 0 0 0 3px rgba(21, 123, 112, 0.08);
}

.filter-popover[open] summary::after {
  transform: rotate(225deg) translate(-1px, -1px);
}

.filter-label {
  display: flex;
  gap: 8px;
  align-items: center;
  color: var(--text-strong);
  font-size: 13px;
  font-weight: 720;
}

.filter-label .icon {
  width: 17px;
  height: 17px;
  color: var(--accent);
}

.filter-popover summary strong {
  grid-column: 1 / 3;
  color: var(--muted);
  font-size: 12px;
  font-weight: 560;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.filter-popover-panel {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  z-index: 28;
  display: grid;
  gap: 10px;
  width: min(380px, calc(100vw - 56px));
  padding: 12px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.filter-popover:nth-last-child(-n+2) .filter-popover-panel {
  right: 0;
  left: auto;
}

.filter-search {
  gap: 5px;
}

.check-list {
  height: 224px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface-soft);
  padding: 4px;
}

.check-list-wide {
  height: 246px;
}

.check-list label {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 7px 8px;
  border-radius: 5px;
  color: var(--text);
  line-height: 1.25;
}

.check-list label.is-hidden {
  display: none;
}

.check-list label:hover {
  background: var(--accent-tint);
}

.check-list label.focused {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  background: var(--accent-tint);
}

.check-list input {
  min-height: 0;
  margin-top: 2px;
  accent-color: var(--accent);
}

.inline-check {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 28px;
  margin-top: 0;
}

.inline-check input {
  min-height: 0;
  accent-color: var(--accent);
}

.inline-check span {
  color: var(--text);
  font-size: 13px;
}

.department-options {
  display: grid;
  gap: 2px;
  align-content: start;
}

button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 15px;
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
  font-weight: 720;
  cursor: pointer;
  transition: background 120ms ease, border-color 120ms ease, color 120ms ease, transform 120ms ease, box-shadow 120ms ease;
}

button:hover {
  background: var(--accent-strong);
  border-color: var(--accent-strong);
}

button:active {
  transform: translateY(1px);
}

button.secondary {
  border-color: var(--line-strong);
  background: #ffffff;
  color: var(--text);
}

button.secondary:hover {
  border-color: #8fb1aa;
  background: var(--surface-soft);
  color: var(--accent-strong);
}

button:disabled {
  opacity: 0.58;
  cursor: wait;
  transform: none;
}

.query-actions {
  display: grid;
  grid-template-columns: minmax(170px, 1fr) 104px 128px;
  gap: 8px;
  align-items: stretch;
}

.query-actions button {
  min-height: 40px;
  padding: 0 12px;
  white-space: nowrap;
}

.primary-action {
  box-shadow: 0 8px 18px rgba(21, 123, 112, 0.2);
}

.active-filter-strip {
  display: flex;
  align-items: center;
  min-height: 32px;
  margin-top: 12px;
  padding: 8px 11px;
  border-radius: var(--radius-sm);
  background: var(--surface-soft);
  color: var(--muted-strong);
  font-size: 12px;
  line-height: 1.35;
}

.active-filter-strip::before {
  content: "";
  width: 7px;
  height: 7px;
  margin-right: 8px;
  border-radius: 999px;
  background: var(--accent);
}

.summary {
  display: grid;
  grid-template-columns: repeat(7, minmax(132px, 1fr));
  gap: 1px;
  overflow: hidden;
  margin-bottom: 10px;
  background: var(--line);
}

.summary .metric {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  grid-template-rows: 17px minmax(26px, auto);
  align-items: start;
  gap: 3px 9px;
  padding: 13px 13px 12px;
  background: var(--surface);
  min-width: 0;
}

.metric .icon {
  grid-row: 1 / 3;
  width: 24px;
  height: 24px;
  margin-top: 2px;
  padding: 4px;
  border-radius: 7px;
  background: var(--accent-soft);
  color: var(--accent-strong);
  stroke-width: 2;
}

.metric span {
  color: var(--muted-strong);
  font-size: 12px;
  font-weight: 560;
}

.metric strong {
  color: var(--text-strong);
  font-size: 20px;
  line-height: 25px;
  font-weight: 760;
  overflow-wrap: anywhere;
}

.metric-amount .icon,
.metric-cost .icon {
  background: var(--blue-soft);
  color: var(--blue);
}

.metric-accessories .icon,
.metric-works .icon {
  background: var(--amber-soft);
  color: var(--amber);
}

.summary.is-empty strong {
  color: #8b9b97;
  font-weight: 650;
}

.summary-sub {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 560;
  line-height: 16px;
}

.table-actions {
  display: flex;
  justify-content: flex-start;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 8px;
  padding: 8px;
}

.icon-text-button {
  min-height: 34px;
  padding: 7px 11px;
  border-radius: var(--radius-sm);
  font-size: 13px;
}

.icon-text-button .icon {
  width: 16px;
  height: 16px;
}

.order-search-field {
  display: grid;
  grid-template-columns: auto minmax(120px, 170px);
  align-items: center;
  gap: 8px;
  margin-left: 10px;
  color: var(--muted);
  font-size: 13px;
}

.order-search-field input {
  min-height: 34px;
  padding: 7px 10px;
}

.search-icon-button {
  width: 38px;
  padding-left: 0;
  padding-right: 0;
}

.table-shell {
  overflow: auto;
  min-height: 380px;
  max-height: calc(100vh - 330px);
}

.embedded .table-shell {
  max-height: calc(100vh - 300px);
}

table {
  width: 100%;
  min-width: 1220px;
  border-collapse: separate;
  border-spacing: 0;
}

th,
td {
  padding: 9px 11px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}

th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: #f3f7f6;
  color: var(--muted-strong);
  font-size: 12px;
  font-weight: 720;
  text-align: left;
  box-shadow: 0 1px 0 var(--line);
}

th.sortable {
  cursor: pointer;
  user-select: none;
}

th.sortable::after {
  content: "↕";
  display: inline-block;
  margin-left: 5px;
  color: #8a9993;
  font-size: 11px;
}

th.sortable.sorted-asc::after {
  content: "↑";
  color: var(--accent);
}

th.sortable.sorted-desc::after {
  content: "↓";
  color: var(--accent);
}

th.sortable:hover {
  color: var(--text);
  background: #e8f1ee;
}

tbody tr:not(.details-row):hover td {
  background: #fbfdfc;
}

.num {
  text-align: right;
}

.toggle {
  width: 30px;
  height: 30px;
  min-height: 30px;
  padding: 0;
  border: 1px solid #b9d7d1;
  border-radius: 9px;
  background: linear-gradient(180deg, #ffffff 0%, #f2f8f6 100%);
  color: var(--accent-strong);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.75);
}

.toggle:hover {
  border-color: #80b8ae;
  background: var(--accent-soft);
  color: var(--accent-strong);
  box-shadow: 0 6px 14px rgba(16, 95, 88, 0.12);
  transform: none;
}

.toggle-icon {
  width: 15px;
  height: 15px;
  stroke: currentColor;
  stroke-width: 2.35;
  stroke-linecap: round;
  stroke-linejoin: round;
  fill: none;
  transform-origin: center;
  transition: transform 140ms ease;
}

.toggle.is-open .toggle-icon {
  transform: rotate(90deg);
}

.group-row td {
  background: #e4f2ee;
  font-weight: 720;
}

.group-row .sub {
  font-weight: 500;
}

.employee-group-row td {
  background: #e8f1fb;
}

.client-group-row td {
  background: #fff4df;
}

.group-row .order-id {
  border-left: 4px solid var(--accent);
  padding-left: 10px;
}

.client-group-row .order-id {
  border-left-color: var(--amber);
  padding-left: 28px;
}

.employee-group-row .order-id {
  border-left-color: var(--blue);
  padding-left: 14px;
}

.group-toggle {
  border-color: #79aca3;
  color: #fff;
  background: var(--accent);
  box-shadow: 0 6px 14px rgba(16, 95, 88, 0.12);
}

.group-toggle:hover {
  color: #fff;
  background: var(--accent-strong);
  border-color: var(--accent-strong);
}

.group-spacer td {
  height: 8px;
  padding: 0;
  border-bottom: 0;
  background: var(--surface-soft);
}

.order-id {
  color: var(--text-strong);
  font-weight: 760;
}

.sub {
  color: var(--muted);
  font-size: 12px;
  margin-top: 3px;
}

.inline-state,
.order-status,
.badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 22px;
  padding: 0 !important;
  border: 0 !important;
  border-radius: 0 !important;
  background: transparent !important;
  font-size: 12px;
  font-weight: 700;
  line-height: 1;
  white-space: nowrap;
}

.inline-state-dot,
.order-status-dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  box-shadow: 0 0 0 3px rgba(22, 132, 81, 0.1);
}

.badge::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 999px;
  box-shadow: 0 0 0 3px rgba(22, 132, 81, 0.1);
}

.inline-state.is-ok,
.order-status.in-production {
  color: #196245;
}

.inline-state.is-ok .inline-state-dot,
.order-status.in-production .order-status-dot {
  background: var(--ok);
}

.badge.ok {
  color: #196245;
}

.badge.ok::before {
  background: var(--ok);
}

.inline-state.is-warn,
.order-status.not-production {
  color: #7f5a17;
}

.inline-state.is-warn .inline-state-dot,
.order-status.not-production .order-status-dot {
  background: var(--amber);
  box-shadow: 0 0 0 3px rgba(173, 106, 18, 0.12);
}

.badge.warn {
  color: #7f5a17;
}

.badge.warn::before {
  background: var(--amber);
  box-shadow: 0 0 0 3px rgba(173, 106, 18, 0.12);
}

.details-row td {
  padding: 0;
  background: var(--surface-soft);
}

.details {
  padding: 12px 14px 14px 48px;
  display: grid;
  gap: 10px;
}

.item {
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
  gap: 14px;
  align-items: start;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
}

.sketch {
  width: 210px;
  height: 210px;
  padding: 10px;
  border: 1px solid var(--line-strong);
  background: #fff;
  border-radius: var(--radius-sm);
  overflow: hidden;
  display: grid;
  place-items: center;
}

.sketch img,
.sketch > svg,
.sketch-svg,
.fallback-sketch svg {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: contain;
  object-position: center;
}

.item-title {
  color: var(--text-strong);
  font-weight: 760;
  margin-bottom: 5px;
}

.item-meta,
.item-spec,
.item-money {
  color: var(--muted);
  line-height: 1.45;
}

.item-spec {
  margin-top: 5px;
}

.item-money {
  text-align: left;
  border-top: 1px solid var(--line);
  margin-top: 6px;
  padding-top: 8px;
}

.empty,
.loading,
.error {
  padding: 34px;
  text-align: center;
  color: var(--muted);
}

.error {
  color: var(--red);
}

.empty-state {
  display: grid;
  justify-items: center;
  gap: 8px;
  color: var(--muted);
}

.empty-state .icon {
  width: 42px;
  height: 42px;
  padding: 9px;
  border-radius: 12px;
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.empty-state strong {
  color: var(--text-strong);
  font-size: 15px;
}

.loading .empty-state .icon {
  animation: spin 900ms linear infinite;
}

.error .empty-state .icon {
  background: var(--red-soft);
  color: var(--red);
}

@keyframes spin {
  from {
    transform: rotate(0deg);
  }

  to {
    transform: rotate(360deg);
  }
}

.print-preview {
  margin-bottom: 14px;
  overflow: auto;
}

.print-toolbar {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-soft);
}

.print-toolbar-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.print-document {
  min-width: 1180px;
  padding: 16px;
  color: #111;
  font-size: 11px;
}

.print-document h2 {
  margin: 0 0 8px;
  font-size: 20px;
}

.print-meta {
  display: grid;
  grid-template-columns: 1.2fr 1fr;
  gap: 8px 18px;
  margin-bottom: 10px;
  color: #444;
}

.print-totals {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  margin: 10px 0 12px;
  border: 1px solid #bfc7c3;
}

.print-totals .total {
  padding: 7px;
  border-right: 1px solid #d8dfdb;
}

.print-totals .total:last-child {
  border-right: 0;
}

.print-totals span {
  display: block;
  color: #555;
  font-size: 10px;
}

.print-totals strong {
  display: block;
  margin-top: 2px;
  font-size: 13px;
}

.print-totals small {
  display: block;
  color: #555;
  font-size: 10px;
  line-height: 13px;
  margin-top: 1px;
}

.print-document table {
  min-width: 0;
}

.print-document th,
.print-document td {
  padding: 5px 6px;
}

.print-document th {
  position: static;
}

.print-document .group td {
  background: #dfece8;
  font-weight: 650;
}

.print-document .subgroup td {
  background: #f2f7f5;
  font-weight: 650;
}

.print-document .clientgroup td {
  background: #f8fbfa;
  font-weight: 650;
}

.print-document .print-details td {
  background: #fbfcfb;
  padding: 7px 8px;
}

.print-item {
  display: grid;
  grid-template-columns: 112px minmax(0, 1fr);
  gap: 8px;
  padding: 6px 0;
  border-bottom: 1px solid #e2e8e5;
}

.print-item:first-child {
  padding-top: 0;
}

.print-item:last-child {
  padding-bottom: 0;
  border-bottom: 0;
}

.print-item span {
  color: #333;
}

.print-sketch {
  width: 104px;
  height: 104px;
  display: grid;
  place-items: center;
  border: 1px solid #cfd8d4;
  background: #fff;
  overflow: hidden;
  padding: 5px;
}

.print-sketch-target {
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 0;
}

.print-sketch img,
.print-sketch svg,
.print-sketch-target svg,
.print-sketch .fallback-sketch svg {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: contain;
  object-position: center;
}

.print-item-text {
  display: grid;
  gap: 2px;
}

.nowrap {
  white-space: nowrap;
}

@media (max-width: 1280px) {
  .query-primary {
    grid-template-columns: 1fr 190px;
  }

  .filter-popovers,
  .query-actions {
    grid-column: 1 / -1;
  }

  .query-actions {
    grid-template-columns: minmax(190px, 240px) 120px 140px;
    justify-content: end;
  }

}

@media (max-width: 1100px) {
  :root {
    --page-pad: 20px;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .topbar-status {
    align-items: flex-start;
  }

  .query-primary {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .query-period,
  .query-actions {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .query-actions button {
    min-height: 42px;
  }

  .item {
    grid-template-columns: 180px minmax(0, 1fr);
  }

  .sketch {
    width: 168px;
    height: 168px;
  }
}

@media print {
  @page {
    size: A4 landscape;
    margin: 10mm;
  }

  body.has-print-preview {
    background: #fff;
  }

  body.has-print-preview > header,
  body.has-print-preview main > .query-panel,
  body.has-print-preview main > .summary,
  body.has-print-preview main > .table-actions,
  body.has-print-preview main > .table-shell {
    display: none;
  }

  body.has-print-preview main {
    padding: 0;
  }

  body.has-print-preview .print-preview {
    display: block;
    margin: 0;
    border: 0;
    border-radius: 0;
    overflow: visible;
  }

  body.has-print-preview .print-toolbar {
    display: none;
  }

  body.has-print-preview .print-document {
    min-width: 0;
    padding: 0;
    font-size: 10px;
  }

  body.has-print-preview .print-document h2 {
    margin-top: 0;
  }

  body.has-print-preview .print-document table {
    page-break-inside: auto;
  }

  body.has-print-preview .print-document tr {
    page-break-inside: avoid;
    page-break-after: auto;
  }
}
