:root {
  --ink: #12221e;
  --muted: #6f7c77;
  --line: #dfe7e3;
  --canvas: #f4f6f3;
  --surface: #ffffff;
  --green: #0f6a51;
  --green-dark: #102d27;
  --mint: #d9f0e6;
  --lime: #c6ed55;
  --amber: #e69d28;
  --amber-soft: #fff1d8;
  --red: #ba3d42;
  --red-soft: #fde7e7;
  --shadow: 0 12px 28px rgba(25, 54, 45, .07);
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--canvas); color: var(--ink); font: 14px/1.45 Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }
button, input, select { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }

.shell { min-height: 100vh; display: grid; grid-template-columns: 236px minmax(0, 1fr); }
.sidebar { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; padding: 28px 22px; color: #f4faf7; background: var(--green-dark); }
.brand { display: flex; gap: 12px; align-items: center; color: inherit; text-decoration: none; margin-bottom: 44px; }
.brand-mark { width: 40px; height: 40px; display: grid; place-items: center; border-radius: 13px; background: var(--lime); color: var(--green-dark); font: 800 20px/1 Georgia, serif; }
.brand b { display: block; font-size: 17px; letter-spacing: .01em; }
.brand small { display: block; margin-top: -1px; color: #9eb7af; font-size: 10px; letter-spacing: .14em; text-transform: uppercase; }
nav { display: grid; gap: 8px; }
.nav-link { width: 100%; border: 0; border-radius: 11px; padding: 11px 12px; display: flex; gap: 12px; align-items: center; color: #aec1ba; background: transparent; text-align: left; cursor: pointer; }
.nav-link span { width: 21px; text-align: center; font-size: 18px; }
.nav-link:hover, .nav-link.active { color: #fff; background: rgba(255,255,255,.09); }
.source-card { margin-top: auto; padding: 17px 14px; border: 1px solid rgba(255,255,255,.1); border-radius: 14px; background: rgba(255,255,255,.04); }
.eyebrow { margin: 0 0 8px; color: var(--muted); font-size: 10px; font-weight: 800; letter-spacing: .14em; text-transform: uppercase; }
.source-card .eyebrow { color: #77958b; }
.source-line { display: grid; grid-template-columns: 8px 1fr auto; gap: 9px; align-items: center; padding: 7px 0; font-size: 12px; }
.source-line i { width: 8px; height: 8px; border-radius: 50%; background: #617b72; }
.source-line i.ok { background: var(--lime); box-shadow: 0 0 0 4px rgba(198,237,85,.09); }
.source-line i.warn { background: #f3b34a; }
.source-line i.error { background: #ff6f72; }
.source-line b { color: #89a39a; font-size: 10px; font-weight: 700; }
.sidebar-foot { margin-top: 18px; color: #67827a; font-size: 10px; line-height: 1.6; }

main { min-width: 0; padding: 32px 38px 48px; }
.topbar { display: flex; justify-content: space-between; gap: 24px; align-items: flex-end; margin-bottom: 26px; }
h1 { margin: 0; font: 500 35px/1.1 Georgia, "Times New Roman", serif; letter-spacing: -.02em; }
h2 { margin: 0; font: 600 19px/1.2 Georgia, serif; }
.actions, .filters { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.button, .import-button { min-height: 44px; padding: 10px 14px; border: 1px solid var(--line); border-radius: 10px; display: inline-flex; gap: 7px; align-items: center; justify-content: center; color: var(--ink); background: var(--surface); text-decoration: none; font-size: 12px; font-weight: 700; cursor: pointer; }
.button.primary { color: #fff; border-color: var(--green); background: var(--green); }
.button.primary:hover { background: #0b5a44; }
.button.secondary:hover, .import-button:hover { border-color: #b7c9c2; }
.button.danger { color: var(--red); background: var(--red-soft); border: 0; }
.button:disabled { opacity: .6; cursor: wait; }

.banner { margin: -10px 0 22px; padding: 13px 15px; border: 1px solid #ebc986; border-radius: 12px; color: #77511d; background: #fff8e8; }
.hidden { display: none !important; }
.view { display: none; }
.view.active { display: block; }

.metric-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 18px; }
.metric-card { position: relative; overflow: hidden; min-height: 132px; padding: 20px; border: 1px solid var(--line); border-radius: 15px; background: var(--surface); box-shadow: var(--shadow); }
.metric-card::after { content: ""; position: absolute; width: 84px; height: 84px; border-radius: 50%; right: -28px; top: -33px; background: var(--mint); opacity: .4; }
.metric-card.warning::after { background: var(--amber-soft); }
.metric-card.accent { color: #fff; border-color: var(--green-dark); background: var(--green-dark); }
.metric-card.accent::after { background: var(--lime); opacity: .85; }
.metric-card span { display: block; color: var(--muted); font-size: 11px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; }
.metric-card.accent span { color: #9ab5ac; }
.metric-card strong { position: relative; z-index: 1; display: block; margin: 12px 0 5px; font: 500 33px/1 Georgia, serif; }
.metric-card small { color: var(--muted); }
.metric-card.accent small { color: #9ab5ac; }

.panel { overflow: hidden; border: 1px solid var(--line); border-radius: 16px; background: var(--surface); box-shadow: var(--shadow); }
.page-panel { min-height: 500px; }
.panel-head { min-height: 82px; padding: 19px 22px; display: flex; justify-content: space-between; gap: 20px; align-items: center; border-bottom: 1px solid var(--line); }
.panel-head p { margin: 5px 0 0; color: var(--muted); font-size: 11px; }
.search { min-width: 220px; height: 38px; padding: 0 10px; display: flex; gap: 7px; align-items: center; border: 1px solid var(--line); border-radius: 9px; color: var(--muted); background: #fafbf9; }
.search.wide { width: 100%; margin: 18px 0; }
.search input { width: 100%; border: 0; outline: 0; background: transparent; color: var(--ink); font-size: 12px; }
select { height: 38px; padding: 0 30px 0 11px; border: 1px solid var(--line); border-radius: 9px; color: var(--ink); background: #fafbf9; font-size: 12px; }
.table-wrap { overflow-x: auto; }
table { width: 100%; min-width: 990px; border-collapse: collapse; }
th { height: 40px; padding: 0 14px; color: #84918c; background: #f8faf7; font-size: 9px; letter-spacing: .09em; text-align: left; text-transform: uppercase; }
td { padding: 13px 14px; border-top: 1px solid #edf1ef; vertical-align: middle; font-size: 12px; }
tbody tr:hover { background: #fbfcfa; }
.product-cell { max-width: 260px; }
.product-cell b { display: block; overflow: hidden; color: var(--ink); text-overflow: ellipsis; white-space: nowrap; cursor: help; }
.product-cell b:focus-visible { outline: 2px solid var(--green); outline-offset: 2px; }
.product-cell small { display: block; margin-top: 3px; color: var(--muted); }
.source-pill, .status-pill { display: inline-flex; padding: 4px 8px; border-radius: 999px; font-size: 10px; font-weight: 800; }
.source-pill.eco { color: #165944; background: #e0f1e9; }
.source-pill.av { color: #765414; background: #fff1c9; }
.status-pill.accepted, .status-pill.manual { color: var(--green); background: var(--mint); }
.status-pill.ambiguous { color: #9c6415; background: var(--amber-soft); }
.status-pill.unmatched { color: var(--red); background: var(--red-soft); }
.delta { font-weight: 800; }
.delta.negative { color: var(--red); }
.delta.positive { color: var(--green); }
.confidence { min-width: 95px; }
.confidence-track { height: 4px; border-radius: 4px; background: #e9efec; }
.confidence-track i { display: block; height: 100%; border-radius: inherit; background: var(--green); }
.confidence small { display: block; margin-top: 5px; color: #52635d; font-weight: 600; }
.edit-button { width: 38px; height: 38px; border: 1px solid var(--line); border-radius: 8px; color: var(--green); background: #fff; cursor: pointer; }
.pagination { min-height: 54px; padding: 10px 18px; display: flex; justify-content: space-between; align-items: center; border-top: 1px solid var(--line); color: var(--muted); font-size: 11px; }
.pagination div { display: flex; gap: 7px; align-items: center; }
.pagination button { width: 30px; height: 30px; border: 1px solid var(--line); border-radius: 7px; background: #fff; cursor: pointer; }
.empty { padding: 70px 20px; text-align: center; color: var(--muted); }
.empty > div { font-size: 30px; }
.empty h3 { margin: 9px 0 5px; color: var(--ink); font: 600 18px Georgia, serif; }
.empty p { margin: 0; }

.novelty-grid { padding: 20px; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
.novelty-card { min-width: 0; padding: 15px; border: 1px solid var(--line); border-radius: 12px; }
.novelty-card .thumb { height: 110px; margin-bottom: 12px; display: grid; place-items: center; border-radius: 9px; background: #eef3ef; overflow: hidden; }
.novelty-card img { width: 100%; height: 100%; object-fit: cover; }
.novelty-card h3 { height: 38px; margin: 8px 0; overflow: hidden; font-size: 13px; }
.novelty-card strong { font: 600 19px Georgia, serif; }
.runs-list { padding: 0 22px 22px; }
.run-item { padding: 17px 0; display: grid; grid-template-columns: 90px 180px 1fr auto; gap: 18px; align-items: center; border-bottom: 1px solid var(--line); }
.run-item time { color: var(--muted); font-size: 11px; }
.run-item p { margin: 0; color: var(--muted); font-size: 11px; }

dialog { width: min(620px, calc(100% - 30px)); max-height: 84vh; padding: 0; border: 0; border-radius: 18px; box-shadow: 0 24px 90px rgba(10,34,28,.3); }
dialog::backdrop { background: rgba(7,25,21,.52); backdrop-filter: blur(4px); }
.dialog-card { padding: 24px; }
.dialog-head { display: flex; justify-content: space-between; gap: 18px; align-items: flex-start; }
.dialog-head h2 { font-size: 18px; line-height: 1.22; }
.icon-button { width: 44px; height: 44px; border: 0; border-radius: 9px; background: #f0f3f1; font-size: 23px; cursor: pointer; }
.candidate-list { max-height: 390px; overflow-y: auto; display: grid; gap: 8px; }
.candidate { width: 100%; padding: 12px; display: grid; grid-template-columns: 1fr auto; gap: 12px; border: 1px solid var(--line); border-radius: 10px; background: #fff; text-align: left; cursor: pointer; }
.candidate:hover { border-color: var(--green); background: #f7fbf9; }
.candidate b { display: block; }
.candidate small { color: var(--muted); }
.toast { position: fixed; right: 24px; bottom: 24px; z-index: 10; max-width: 340px; padding: 13px 16px; border-radius: 10px; color: #fff; background: var(--green-dark); box-shadow: var(--shadow); opacity: 0; transform: translateY(10px); pointer-events: none; transition: .2s ease; }
.toast.show { opacity: 1; transform: none; }

@media (max-width: 1080px) {
  .metric-grid { grid-template-columns: repeat(2, 1fr); }
  .novelty-grid { grid-template-columns: repeat(3, 1fr); }
  .topbar, .panel-head { align-items: flex-start; flex-direction: column; }
}

@media (max-width: 760px) {
  .shell { display: block; }
  .sidebar { position: static; width: 100%; height: auto; padding: 15px 17px; display: grid; grid-template-columns: 1fr auto; gap: 10px; }
  .brand { margin: 0; }
  .brand-mark { width: 34px; height: 34px; }
  .sidebar nav { grid-column: 1 / -1; display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
  .nav-link { min-height: 44px; justify-content: center; padding: 8px 5px; font-size: 11px; }
  .nav-link span { display: none; }
  .source-card, .sidebar-foot { display: none; }
  main { padding: 22px 14px 36px; }
  .topbar { margin-bottom: 19px; }
  h1 { font-size: 29px; }
  .actions { width: 100%; display: grid; grid-template-columns: 1fr 1fr; }
  .actions .button.primary { grid-column: 1 / -1; }
  .metric-grid { grid-template-columns: 1fr 1fr; gap: 9px; }
  .metric-card { min-height: 116px; padding: 15px; }
  .metric-card strong { font-size: 28px; }
  .filters, .search { width: 100%; }
  .filters select { flex: 1; min-width: 0; height: 44px; }
  .search { height: 44px; }
  .panel-head { padding: 17px; }
  table { min-width: 0; }
  table thead { display: none; }
  table tbody { padding: 10px; display: grid; gap: 9px; }
  table tbody tr { position: relative; padding: 9px; display: grid; grid-template-columns: 1fr auto; gap: 0 10px; border: 1px solid var(--line); border-radius: 11px; background: #fff; }
  table tbody tr:hover { background: #fff; }
  table td { min-width: 0; padding: 6px 4px; border: 0; }
  table td:nth-child(1) { grid-column: 1; grid-row: 1; padding-right: 32px; }
  table td:nth-child(2) { grid-column: 2; grid-row: 1; align-self: start; }
  table td:nth-child(3) { grid-column: 1 / -1; grid-row: 2; margin-top: 3px; padding-top: 9px; border-top: 1px dashed var(--line); }
  table td:nth-child(4) { grid-column: 1; grid-row: 3; }
  table td:nth-child(4)::before { content: "Цена конкурента"; display: block; color: var(--muted); font-size: 8px; letter-spacing: .08em; text-transform: uppercase; }
  table td:nth-child(5), table td:nth-child(7) { display: none; }
  table td:nth-child(6) { grid-column: 2; grid-row: 3; align-self: end; text-align: right; }
  table td:nth-child(8) { position: absolute; right: 7px; top: 42px; }
  .product-cell { max-width: none; }
  .product-cell b { white-space: normal; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; cursor: pointer; }
  .product-cell b.expanded { display: block; overflow: visible; -webkit-line-clamp: initial; }
  .edit-button { width: 42px; height: 42px; }
  .novelty-grid { grid-template-columns: 1fr 1fr; padding: 13px; gap: 9px; }
  .run-item { grid-template-columns: 70px 1fr; gap: 5px 12px; }
  .run-item > :nth-child(n+3) { grid-column: 2; }
  .toast { left: 14px; right: 14px; bottom: 14px; }
  .dialog-head h2 { font-size: 16px; line-height: 1.2; }
}

@media (max-width: 390px) {
  .metric-grid { grid-template-columns: 1fr; }
  .novelty-grid { grid-template-columns: 1fr; }
}
