:root {
  color-scheme: light;
  --bg: #f5f7fa;
  --panel: #ffffff;
  --ink: #17202a;
  --muted: #667085;
  --line: #d8dee8;
  --line-strong: #b8c2cf;
  --blue: #1f5f8b;
  --blue-dark: #17466a;
  --green: #1f7a55;
  --red: #b42318;
  --amber: #a15c07;
  --input: #fff4cf;
  --row: #fbfcfe;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", Arial, sans-serif;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
  letter-spacing: 0;
}

html {
  height: 100%;
}

button,
input {
  font: inherit;
}

.auth-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: #f5f7fa;
}

.auth-screen[hidden] {
  display: none;
}

.auth-panel {
  width: min(100%, 380px);
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  box-shadow: 0 16px 46px rgba(23, 32, 42, 0.12);
}

.auth-logo {
  display: block;
  width: 56px;
  height: 56px;
  object-fit: contain;
  margin-bottom: 14px;
}

.auth-panel h1 {
  margin: 0 0 18px;
  font-size: 22px;
  line-height: 1.25;
}

.bi-label {
  display: inline-grid;
  gap: 2px;
  line-height: 1.15;
}

.bi-label small,
.auth-panel h1 small,
.topbar h1 small {
  display: block;
  font-size: 0.74em;
  font-weight: 600;
  color: inherit;
  opacity: 0.78;
}

.auth-panel label {
  display: grid;
  gap: 6px;
  color: #344054;
  font-weight: 700;
}

.auth-panel input {
  width: 100%;
  height: 42px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  padding: 0 12px;
  outline: none;
  font-size: 16px;
}

.auth-panel input:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(31, 95, 139, 0.14);
}

.auth-panel button {
  width: 100%;
  height: 42px;
  margin-top: 14px;
  border: 1px solid var(--blue-dark);
  border-radius: 6px;
  background: var(--blue);
  color: #ffffff;
  cursor: pointer;
  font-weight: 700;
}

.auth-panel button:disabled {
  cursor: default;
  opacity: 0.62;
}

.auth-message {
  min-height: 20px;
  margin: 10px 0 0;
  color: var(--red);
}

.app-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.app-shell[hidden] {
  display: none;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  align-items: center;
  padding: calc(14px + env(safe-area-inset-top)) 18px 14px;
  background: var(--blue-dark);
  color: #ffffff;
  border-bottom: 1px solid #0f314a;
}

.topbar h1 {
  margin: 0;
  font-size: 20px;
  line-height: 1.2;
}

.topbar h1 small {
  margin-top: 2px;
  color: #d5e2ee;
}

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

.brand-logo {
  width: 44px;
  height: 44px;
  flex: 0 0 44px;
  object-fit: contain;
}

.topbar p {
  margin: 4px 0 0;
  color: #d5e2ee;
  font-size: 12px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.install-button {
  height: 34px;
  padding: 0 14px;
  border: 1px solid rgba(255, 255, 255, 0.34);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.14);
  color: #ffffff;
  cursor: pointer;
  font-weight: 700;
}

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

.stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(72px, 1fr));
  gap: 8px;
}

.stats div {
  min-width: 72px;
  padding: 7px 10px;
  border: 1px solid rgba(255, 255, 255, 0.24);
  background: rgba(255, 255, 255, 0.08);
  border-radius: 6px;
  text-align: right;
}

.stats span {
  display: block;
  font-weight: 700;
  font-size: 18px;
}

.stats small {
  color: #cfe0ec;
}

.query-panel {
  padding: 12px 18px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

.search-row {
  display: grid;
  grid-template-columns: minmax(240px, 680px) 38px;
  gap: 8px;
  align-items: end;
}

.search-box {
  display: grid;
  gap: 5px;
  color: #344054;
  font-weight: 700;
}

.search-box input {
  width: 100%;
  height: 38px;
  border: 1px solid var(--line-strong);
  background: var(--input);
  border-radius: 6px;
  padding: 0 12px;
  outline: none;
  font-size: 16px;
}

.search-box input:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(31, 95, 139, 0.14);
}

.icon-button {
  width: 38px;
  height: 38px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: #ffffff;
  color: #344054;
  cursor: pointer;
  font-size: 22px;
  line-height: 1;
}

.filter-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  margin-top: 10px;
}

.segmented {
  display: inline-flex;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  overflow: hidden;
  background: #ffffff;
}

.segmented button {
  min-height: 42px;
  min-width: 92px;
  padding: 4px 10px;
  border: 0;
  border-right: 1px solid var(--line-strong);
  background: #ffffff;
  color: #344054;
  cursor: pointer;
  line-height: 1.15;
}

.segmented button:last-child {
  border-right: 0;
}

.segmented button.active {
  background: var(--blue);
  color: #ffffff;
  font-weight: 700;
}

.check-filter {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 32px;
  color: #344054;
  line-height: 1.15;
}

.check-filter input {
  width: 16px;
  height: 16px;
  accent-color: var(--blue);
}

.content-grid {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 0;
}

.table-wrap {
  min-width: 0;
  overflow: auto;
  background: var(--panel);
}

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

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

th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: #d9eaf7;
  font-weight: 700;
  color: #1f2937;
}

th .bi-label small {
  color: #475467;
  opacity: 1;
}

td {
  background: #ffffff;
}

tr:nth-child(even) td {
  background: var(--row);
}

tr.selected td {
  background: #e8f2fb;
}

tr:hover td {
  background: #eef6fd;
}

.result-row {
  cursor: pointer;
}

.product-cell {
  min-width: 280px;
  max-width: 420px;
  white-space: pre-line;
  line-height: 1.35;
}

.code-cell {
  width: 116px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.number-cell {
  width: 92px;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
}

.source-cell {
  max-width: 240px;
  color: var(--muted);
}

.status-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 22px;
  padding: 2px 7px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  line-height: 1.15;
  text-align: center;
  white-space: pre-line;
}

.status-ok {
  background: #e4f5ed;
  color: var(--green);
}

.status-review {
  background: #fff1e1;
  color: var(--amber);
}

.status-missing {
  background: #fee4e2;
  color: var(--red);
}

.empty-state {
  padding: 32px;
  color: var(--muted);
}

.result-pager {
  position: sticky;
  left: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 12px;
  border-top: 1px solid var(--line);
  background: #ffffff;
  color: var(--muted);
}

.result-pager button {
  min-height: 36px;
  padding: 0 14px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: #ffffff;
  color: #17466a;
  cursor: pointer;
  font-weight: 700;
}

.result-pager button:hover {
  background: #eef6fd;
}

.detail-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: rgba(15, 23, 42, 0.28);
  opacity: 0;
  transition: opacity 160ms ease;
}

.detail-backdrop.open {
  opacity: 1;
}

.detail-panel {
  position: fixed;
  top: calc(12px + env(safe-area-inset-top));
  right: 12px;
  bottom: calc(12px + env(safe-area-inset-bottom));
  z-index: 21;
  width: min(520px, calc(100vw - 24px));
  min-width: 0;
  background: #ffffff;
  overflow: auto;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 20px 60px rgba(15, 23, 42, 0.24);
  transform: translateX(calc(100% + 24px));
  visibility: hidden;
  transition: transform 180ms ease, visibility 180ms ease;
}

.detail-panel.open {
  transform: translateX(0);
  visibility: visible;
}

.detail-empty {
  color: var(--muted);
  padding: 18px 0;
}

.detail-head {
  display: flex;
  gap: 12px;
  justify-content: space-between;
  align-items: start;
  margin-bottom: 14px;
}

.detail-head h2 {
  margin: 0;
  font-size: 18px;
  line-height: 1.35;
  white-space: pre-line;
}

.detail-head-actions {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
}

.detail-close {
  width: 34px;
  height: 34px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: #ffffff;
  color: #344054;
  cursor: pointer;
  font-size: 22px;
  line-height: 1;
}

.detail-close:hover {
  background: #f3f6f9;
}

.business-summary {
  border: 1px solid #b9d6ea;
  border-radius: 8px;
  background: #f2f8fd;
  padding: 10px;
  margin-bottom: 14px;
}

.business-summary h3 {
  margin: 0 0 8px;
  font-size: 14px;
  color: #17466a;
}

.summary-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.summary-grid div {
  min-width: 0;
  padding: 8px;
  border: 1px solid #d5e6f2;
  border-radius: 6px;
  background: #ffffff;
}

.summary-grid dd {
  font-weight: 700;
  color: #111827;
}

.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 9px;
  margin: 0 0 15px;
}

.detail-grid div {
  min-width: 0;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fbfcfe;
}

dt {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.25;
  margin-bottom: 4px;
}

dd {
  margin: 0;
  word-break: break-word;
  white-space: pre-line;
}

.detail-panel section {
  border-top: 1px solid var(--line);
  padding-top: 12px;
  margin-top: 12px;
}

.detail-panel h3 {
  margin: 0 0 6px;
  font-size: 13px;
  color: #344054;
}

.detail-panel p {
  margin: 0;
  color: #26303b;
  line-height: 1.45;
  white-space: pre-line;
  word-break: break-word;
}

@media (max-width: 980px) {
  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

  .topbar-actions {
    align-items: stretch;
    justify-content: space-between;
  }

  .brand-logo {
    width: 40px;
    height: 40px;
    flex-basis: 40px;
  }

  .search-row {
    grid-template-columns: minmax(0, 1fr) 38px;
  }

  .content-grid {
    grid-template-columns: 1fr;
  }

  .table-wrap {
    max-height: 58vh;
    border-bottom: 1px solid var(--line);
  }
}

@media (max-width: 720px) {
  body {
    font-size: 13px;
  }

  .topbar {
    gap: 12px;
  }

  .topbar h1 {
    font-size: 18px;
  }

  .topbar-actions {
    flex-wrap: wrap;
  }

  .install-button {
    min-width: 76px;
  }

  .query-panel {
    position: sticky;
    top: 0;
    z-index: 4;
  }

  .search-box {
    gap: 4px;
  }

  .search-box input {
    height: 42px;
  }

  .icon-button {
    width: 42px;
    height: 42px;
  }

  .filter-row {
    gap: 8px;
  }

  .check-filter {
    flex: 1 1 calc(50% - 8px);
    min-height: 34px;
    padding: 0 8px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: #ffffff;
  }

  .content-grid {
    display: block;
  }

  .table-wrap {
    max-height: none;
    overflow: visible;
    border-bottom: 1px solid var(--line);
  }

  table,
  tbody,
  tr,
  td {
    display: block;
    width: 100%;
  }

  table {
    min-width: 0;
    border-collapse: collapse;
  }

  thead {
    display: none;
  }

  tbody {
    padding: 10px 10px 4px;
    display: grid;
    gap: 8px;
    background: var(--bg);
  }

  tr.result-row {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #ffffff;
    overflow: hidden;
  }

  tr:nth-child(even) td,
  tr:hover td,
  tr.selected td,
  td {
    background: #ffffff;
  }

  tr.selected {
    border-color: var(--blue);
    box-shadow: inset 3px 0 0 var(--blue);
  }

  td {
    display: grid;
    grid-template-columns: 88px minmax(0, 1fr);
    gap: 8px;
    min-height: 34px;
    padding: 8px 10px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    align-items: start;
  }

  td:last-child {
    border-bottom: 0;
  }

  td::before {
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
  }

  td:nth-child(1)::before {
    content: "产品 / Наим.";
  }

  td:nth-child(2)::before {
    content: "编码 / Код";
  }

  td:nth-child(3)::before {
    content: "最低限价 / ИТС";
  }

  td:nth-child(4)::before {
    content: "关税 / Пошлина";
  }

  td:nth-child(5)::before {
    content: "НДС";
  }

  td:nth-child(6)::before {
    content: "税费 / Налог";
  }

  td:nth-child(7)::before {
    content: "认证 / Сертификат";
  }

  td:nth-child(8)::before {
    content: "状态 / Статус";
  }

  td:nth-child(9)::before {
    content: "来源 / Источник";
  }

  .product-cell,
  .source-cell {
    min-width: 0;
    max-width: none;
  }

  .code-cell,
  .number-cell {
    width: auto;
  }

  .detail-panel {
    top: auto;
    right: 0;
    bottom: 0;
    left: 0;
    width: 100%;
    max-height: min(78vh, 720px);
    border-right: 0;
    border-bottom: 0;
    border-left: 0;
    border-radius: 12px 12px 0 0;
    padding: 14px 12px calc(18px + env(safe-area-inset-bottom));
    transform: translateY(calc(100% + 16px));
  }

  .detail-panel.open {
    transform: translateY(0);
  }

  .result-pager {
    align-items: stretch;
    flex-direction: column;
    padding: 12px 10px;
  }

  .result-pager button {
    width: 100%;
  }
}

@media (max-width: 560px) {
  .topbar,
  .query-panel {
    padding-left: 12px;
    padding-right: 12px;
  }

  .stats {
    grid-template-columns: repeat(2, 1fr);
    flex: 1 1 100%;
    width: 100%;
  }

  .stats div {
    text-align: left;
  }

  .segmented {
    width: 100%;
  }

  .segmented button {
    flex: 1;
    min-width: 0;
  }

  .detail-grid {
    grid-template-columns: 1fr;
  }

  .summary-grid {
    grid-template-columns: 1fr;
  }
}
