:root {
  --bg: #f4f7fb;
  --surface: #fff;
  --soft: #eef4fb;
  --line: #d6e1ee;
  --text: #071827;
  --muted: #53677c;
  --blue: #2f6adf;
  --green: #07834f;
  --amber: #a96700;
  --red: #c53030;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Arial, Helvetica, sans-serif;
  font-size: 16px;
}
button, input, select, textarea {
  font: inherit;
}
button {
  border: 1px solid var(--line);
  background: var(--surface);
  padding: 10px 14px;
  cursor: pointer;
}
button.primary {
  background: var(--blue);
  border-color: var(--blue);
  color: #fff;
  font-weight: 700;
}
button.danger {
  border-color: #f0b8b8;
  color: var(--red);
  background: #fff5f5;
}
button:disabled { opacity: .65; cursor: wait; }
input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--surface);
  padding: 11px 12px;
  border-radius: 6px;
}
textarea { min-height: 90px; resize: vertical; }
label { display: grid; gap: 6px; color: var(--muted); }

.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.login-card {
  width: min(480px, 100%);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 30px;
  box-shadow: 0 20px 60px rgba(15, 45, 75, .08);
}
.login-card h1 { margin: 0 0 20px; }
.login-card form { display: grid; gap: 16px; }
.error {
  border: 1px solid #f3a7a7;
  background: #fff0f0;
  color: var(--red);
  padding: 12px;
  border-radius: 6px;
  font-weight: 700;
}

.shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 220px 1fr;
}
.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--line);
  padding: 18px 12px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 22px;
  font-weight: 800;
}
.brand-mark {
  width: 38px;
  height: 38px;
  background: var(--blue);
}
.nav {
  display: grid;
  gap: 6px;
}
.nav button {
  text-align: left;
  border-color: transparent;
  border-radius: 7px;
}
.nav button.active {
  color: var(--blue);
  background: #eaf2ff;
  border-color: #b9d2ff;
  font-weight: 700;
}
.sidebar-bottom {
  margin-top: auto;
  display: grid;
  gap: 8px;
}
.user-name { color: var(--muted); }
.muted { color: var(--muted); }
.ok-text { color: var(--green); }
.bad-text { color: var(--red); }
.link-button {
  border: 0;
  padding: 0;
  background: transparent;
  color: var(--blue);
  font-weight: 800;
}
.client-cell {
  display: grid;
  grid-template-columns: 28px 1fr;
  gap: 8px;
  align-items: start;
}
.link-icon {
  width: 26px;
  height: 26px;
  min-height: 26px;
  padding: 0;
  border-radius: 6px;
  color: var(--blue);
  font-weight: 800;
  line-height: 1;
}
.link-icon:disabled {
  color: #9aadbf;
  background: #f2f5f8;
  cursor: default;
}
.links-list {
  display: grid;
  gap: 8px;
}
.links-list a {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 12px;
  color: var(--blue);
  font-weight: 800;
  text-decoration: none;
  background: #f8fbff;
}

.main {
  min-width: 0;
}
.topbar {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 12px;
  padding: 18px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.content {
  padding: 24px;
  display: grid;
  gap: 18px;
}
.toolbar {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
}
.segmented {
  display: inline-flex;
  gap: 4px;
  padding: 5px;
  background: #eaf1f8;
  border: 1px solid var(--line);
  border-radius: 8px;
}
.segmented button {
  border-radius: 6px;
  border: 0;
}
.segmented button.active {
  color: var(--blue);
  font-weight: 700;
  box-shadow: inset 3px 0 0 var(--blue);
}
.sales-panel-tools {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.period-filter {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}
.period-filter select,
.period-filter input {
  width: auto;
  min-height: 36px;
  padding: 7px 10px;
  background: var(--surface);
}
.range-fields {
  display: inline-flex;
  gap: 6px;
  align-items: center;
}

.kpis {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
}
.compact-kpis .kpi {
  padding: 12px 14px;
}
.compact-kpis .kpi strong {
  font-size: 24px;
  margin: 6px 0;
}
.kpi {
  background: var(--surface);
  border: 1px solid var(--line);
  border-left: 4px solid var(--blue);
  border-radius: 7px;
  padding: 18px;
}
.kpi span { color: var(--muted); }
.kpi strong {
  display: block;
  margin: 10px 0;
  font-size: 28px;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}
.panel-head {
  padding: 16px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
}
.panel-head.sales-head {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 12px;
  align-items: center;
}
.panel-head.sales-head > span {
  justify-self: end;
  color: var(--muted);
}
.panel-body { padding: 16px; }

.product-grid,
.order-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(190px, 1fr));
  gap: 12px;
}
.product-card,
.order-card,
.info-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  display: grid;
  gap: 10px;
  min-height: 230px;
}
.order-card {
  min-height: 252px;
  align-content: start;
}
.support-card,
.task-card {
  grid-template-rows: auto auto auto auto 1fr auto;
}
.card-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
}
.subtitle-accent {
  margin-top: 4px;
  color: #174fba;
  font-weight: 800;
  line-height: 1.25;
}
.product-card {
  cursor: pointer;
}
.product-card:hover {
  border-color: #9fc0f8;
  box-shadow: 0 8px 22px rgba(38, 103, 216, .12);
}
.product-card img,
.photo-placeholder {
  height: 104px;
  display: grid;
  place-items: center;
  background: #eaf1f8;
  color: var(--muted);
  font-weight: 700;
  border-radius: 6px;
  overflow: hidden;
  object-fit: contain;
  max-width: 100%;
}
.product-title,
.order-title {
  color: #145bea;
  font-weight: 800;
  font-size: 18px;
}
.price-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.mini-box {
  background: #f8fbff;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px;
}
.mini-box span {
  display: block;
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 4px;
}
.stock-arrival {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  border-top: 1px solid var(--line);
  padding-top: 8px;
  font-weight: 700;
}
.stock-chip,
.arrival-chip {
  display: flex;
  justify-content: space-between;
  gap: 6px;
  padding: 8px;
  border-radius: 6px;
  background: #f8fbff;
  color: var(--text);
}
.arrival-chip {
  background: #f7fafc;
}
.arrival-chip.has-arrival {
  background: #eaf8f0;
  color: var(--green);
}
.product-detail-layout {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 14px;
}
.product-detail-photo {
  width: 100%;
  min-height: 220px;
  border: 1px solid var(--line);
  border-radius: 8px;
  object-fit: contain;
  background: #eaf1f8;
}
.product-detail-info {
  display: grid;
  gap: 12px;
}
.description-box,
.stock-detail,
.arrival-detail {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
}
.description-box span,
.stock-detail span,
.arrival-detail span,
.new-price span {
  display: block;
  color: var(--muted);
  margin-bottom: 4px;
}
.detail-alerts {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.stock-detail {
  border-left: 4px solid var(--green);
  background: #eefaf4;
}
.stock-detail.low-stock {
  border-left-color: var(--amber);
  background: #fff8eb;
}
.stock-detail b,
.arrival-detail b {
  font-size: 20px;
}
.arrival-detail {
  border-left: 4px solid var(--green);
  background: #eefaf4;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
}
.arrival-detail.muted-arrival {
  border-left-color: var(--line);
  background: #f8fbff;
}
.price-detail-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}
.price-detail {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #f8fbff;
}
.price-detail > div:first-child {
  border-right: 1px solid var(--line);
}
.new-price {
  color: var(--blue);
}
.sale-collapser {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
}
.sale-collapser summary {
  cursor: pointer;
  font-weight: 800;
}
.sale-collapser button {
  margin-top: 12px;
}

.status-new { border-left: 4px solid var(--amber); background: #fff8eb; }
.status-work { border-left: 4px solid var(--blue); background: #f2f6ff; }
.status-ready, .status-done { border-left: 4px solid var(--green); background: #eefaf4; }
.change-pending {
  box-shadow: inset 0 0 0 2px rgba(169, 99, 0, 0.2), 0 10px 24px rgba(169, 99, 0, 0.08);
}
.support-groups {
  display: grid;
  gap: 12px;
}
.support-group {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  overflow: hidden;
}
.support-group > summary {
  list-style: none;
  cursor: pointer;
  padding: 12px;
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-weight: 800;
}
.support-group > summary::-webkit-details-marker { display: none; }
.support-group > summary::after {
  content: "Розгорнути";
  color: var(--blue);
  font-size: 13px;
}
.support-group[open] > summary {
  border-bottom: 1px solid var(--line);
}
.support-group[open] > summary::after {
  content: "Згорнути";
}
.support-group .order-grid {
  padding: 12px;
}
.support-group.is-new {
  border-color: #9fc4ff;
  background: #f4f8ff;
  box-shadow: inset 4px 0 0 var(--blue);
}
.support-group.is-new > summary {
  background: #eaf2ff;
  color: #174b9c;
}
.queue-badge {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding: 2px 8px;
  background: var(--blue);
  color: #fff;
  font-size: 12px;
  font-weight: 800;
}
.group-hint {
  padding: 0 12px 10px;
  color: var(--muted);
  font-size: 14px;
}
.date-strip {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 4px;
  border-top: 1px solid var(--line);
  padding-top: 8px;
}
.date-strip span {
  min-width: 0;
  color: #4f6278;
  font-size: 11px;
  line-height: 1.15;
  padding: 5px 4px;
  border-radius: 6px;
  border: 1px solid rgba(207, 220, 235, .85);
  background: rgba(255,255,255,.78);
  white-space: nowrap;
}
.date-strip b {
  display: block;
  margin-top: 3px;
  color: var(--text);
  font-size: 13px;
  line-height: 1.1;
  letter-spacing: 0;
}
.pill {
  width: max-content;
  padding: 5px 10px;
  border-radius: 999px;
  background: #edf4ff;
  color: #064fb8;
  font-size: 13px;
  font-weight: 800;
}
.meta {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  border-top: 1px solid var(--line);
  padding-top: 8px;
  color: var(--muted);
}
.table-wrap {
  overflow: auto;
}
table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
}
th, td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
}
th {
  background: #eaf1f8;
  color: var(--muted);
}
.row-green {
  background: #ecf9f2;
}
.row-amber {
  background: #fff8eb;
}
.status-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 30px;
  padding: 5px 10px;
  border-radius: 999px;
  font-weight: 800;
}
.status-pill.green {
  background: #e0f6ea;
  color: var(--green);
}
.status-pill.amber {
  background: #fff1d6;
  color: var(--amber);
}
.status-pill.red {
  background: #ffe8e8;
  color: var(--red);
}
.change-panel {
  display: grid;
  gap: 12px;
  padding: 14px;
  margin-bottom: 14px;
  border: 1px solid #f1d38e;
  border-left: 4px solid var(--amber);
  border-radius: 8px;
  background: #fff8eb;
}
.change-panel.is-rejected {
  border-color: #f3b8b8;
  border-left-color: var(--red);
  background: #fff0f0;
}
.change-panel p {
  margin: 0;
  white-space: pre-wrap;
}
.change-compare {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}
.change-compare > div {
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}
.change-compare span {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 13px;
}
.locked-note {
  padding: 10px 12px;
  border: 1px solid #cfe0f4;
  border-radius: 8px;
  background: #f4f8fd;
  color: var(--muted);
}
.is-hidden {
  display: none !important;
}
.actions-cell {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}
.info-toolbar {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  background: #fbfcfe;
}
.info-board {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 12px;
  padding: 14px;
}
.info-card {
  grid-template-rows: auto auto minmax(0, 1fr) auto auto;
  height: 286px;
  overflow: hidden;
  box-shadow: 0 4px 14px rgba(23, 33, 43, .05);
}
.info-card.is-pinned {
  border-color: #b7d7c3;
  box-shadow: inset 4px 0 0 var(--green), 0 4px 14px rgba(23, 33, 43, .05);
}
.info-card-head {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: flex-start;
}
.info-card h3 {
  margin: 0;
  font-size: 18px;
  line-height: 1.25;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.info-type {
  width: max-content;
  max-width: 100%;
  border-radius: 999px;
  padding: 4px 8px;
  font-size: 12px;
  font-weight: 800;
  color: #174c3b;
  background: #e7f7ef;
}
.info-type.important { color: #7b4b00; background: #fff1cc; }
.info-type.link { color: #1856ba; background: #eaf1ff; }
.info-type.guide { color: #5b5472; background: #f0eef8; }
.info-preview {
  min-height: 0;
  overflow: hidden;
  display: grid;
  gap: 8px;
  align-content: start;
  position: relative;
}
.info-preview::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 24px;
  background: linear-gradient(rgba(255,255,255,0), var(--surface));
  pointer-events: none;
}
.info-text {
  color: var(--text);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.info-preview .info-text {
  max-height: 128px;
  overflow: hidden;
}
.info-links {
  display: grid;
  gap: 6px;
}
.info-links a {
  color: var(--blue);
  font-weight: 800;
  text-decoration: none;
  overflow-wrap: anywhere;
}
.info-preview .info-links {
  max-height: 48px;
  overflow: hidden;
}
.info-footer {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: center;
  color: var(--muted);
  font-size: 12px;
  border-top: 1px solid var(--line);
  padding-top: 8px;
}
.info-card-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: flex-end;
}
.info-card-actions button {
  min-height: 30px;
  padding: 5px 8px;
  font-size: 12px;
}
.info-full {
  display: grid;
  gap: 12px;
}
.info-full .info-text {
  font-size: 15px;
  line-height: 1.55;
}
.info-full .info-links {
  border-top: 1px solid var(--line);
  padding-top: 10px;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(5, 17, 31, .36);
  display: grid;
  place-items: start center;
  padding: 36px;
  overflow: auto;
  z-index: 5;
}
.dialog {
  width: min(900px, 100%);
  background: var(--surface);
  border-radius: 10px;
  border: 1px solid var(--line);
  box-shadow: 0 24px 80px rgba(0,0,0,.18);
}
.dialog.small { width: min(560px, 100%); }
.dialog-head {
  padding: 18px 20px;
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  gap: 12px;
}
.dialog-body {
  padding: 20px;
  display: grid;
  gap: 14px;
}
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}
.hidden { display: none !important; }
.access-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(220px, 1fr));
  gap: 14px;
}
.summary-strip {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px;
}
.summary-strip > div {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #f8fbff;
}
.summary-strip span {
  display: block;
  color: var(--muted);
  margin-bottom: 5px;
}
.payments-list {
  display: grid;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #f8fbff;
}
.payments-list > div {
  display: grid;
  grid-template-columns: 1fr 140px 1fr;
  gap: 4px 12px;
  border-top: 1px solid var(--line);
  padding-top: 8px;
}
.payment-row input {
  min-height: 36px;
}
.payments-list small {
  grid-column: 1 / -1;
  color: var(--muted);
}
.full { grid-column: 1 / -1; }
.empty {
  padding: 40px;
  text-align: center;
  color: var(--muted);
}

.reports-page {
  display: grid;
  gap: 14px;
}
.report-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  width: max-content;
  max-width: 100%;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}
.report-toolbar label {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
}
.report-summary {
  display: grid;
  grid-template-columns: repeat(5, minmax(120px, 1fr));
  gap: 10px;
  max-width: 980px;
}
.report-summary > div {
  border: 1px solid var(--line);
  border-left: 4px solid var(--blue);
  border-radius: 8px;
  padding: 12px;
  background: #f8fbff;
}
.report-summary span,
.report-block h3 + .muted {
  color: var(--muted);
}
.report-summary b {
  display: block;
  margin-top: 6px;
  font-size: 24px;
}
.report-block {
  width: max-content;
  max-width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: var(--surface);
  overflow: auto;
}
.report-block-bonus {
  width: min(100%, 1120px);
  border-left: 4px solid var(--amber);
  background: #fffaf0;
}
.report-block-conversion {
  width: min(100%, 860px);
  border-left: 4px solid var(--blue);
  background: #f7fbff;
}
.report-block-matrix {
  width: max-content;
  background: #fff;
}
.report-block h3 {
  margin: 0 0 10px;
}
.compact-table table,
table.compact-table,
.report-matrix {
  font-size: 14px;
}
.compact-table th,
.compact-table td,
.report-matrix th,
.report-matrix td {
  padding: 7px 8px;
  white-space: nowrap;
}
.conversion-table th {
  background: #e7f0ff;
  color: #0c48a8;
  text-transform: uppercase;
  font-size: 12px;
}
.conversion-table tbody tr:nth-child(even) {
  background: #f7fbff;
}
.conversion-table span {
  color: var(--blue);
  font-weight: 800;
}
.total-row {
  background: #dcedff !important;
  font-weight: 800;
}
.report-matrix-wrap {
  overflow: auto;
}
.report-matrix th {
  background: #fff1c8;
  color: var(--text);
  text-align: center;
}
.report-matrix td {
  text-align: center;
}
.matrix-edit {
  min-height: 0;
  padding: 0;
  border: 0;
  color: var(--blue);
  background: transparent;
  font-weight: 800;
}
.admin-report-tools {
  width: min(100%, 920px);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfe;
  overflow: hidden;
}
.admin-report-tools > summary {
  cursor: pointer;
  list-style: none;
  padding: 12px;
  font-weight: 800;
}
.admin-report-tools > summary::-webkit-details-marker {
  display: none;
}
.admin-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(220px, 1fr));
  gap: 10px;
  padding: 12px;
  border-top: 1px solid var(--line);
}
.admin-grid h4,
.admin-grid button {
  grid-column: 1 / -1;
}

@media (max-width: 1100px) {
  .product-grid, .order-grid { grid-template-columns: repeat(3, minmax(190px, 1fr)); }
  .kpis { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 760px) {
  body { font-size: 17px; }
  .shell { grid-template-columns: 1fr; }
  .sidebar {
    position: static;
    height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
  .nav { grid-template-columns: repeat(3, 1fr); }
  .topbar { grid-template-columns: 1fr; padding: 12px; }
  .content { padding: 12px; }
  .kpis, .product-grid, .order-grid, .form-grid, .access-grid, .summary-strip, .report-summary, .admin-grid { grid-template-columns: 1fr; }
  .product-detail-layout, .detail-alerts, .price-detail-grid, .price-detail { grid-template-columns: 1fr; }
  .price-detail > div:first-child { border-right: 0; border-bottom: 1px solid var(--line); padding-bottom: 8px; }
  .modal { padding: 8px; }
  .dialog { width: 100%; }
}
