:root {
  color-scheme: dark;
  --bg: #08131f;
  --bg-soft: #0d1b2b;
  --panel: rgba(13, 27, 43, 0.92);
  --panel-solid: #102236;
  --panel-elevated: #142a42;
  --ink: #eaf4ff;
  --muted: #8ea4ba;
  --muted-strong: #b8c8d8;
  --line: rgba(111, 151, 184, 0.22);
  --line-strong: rgba(139, 184, 219, 0.38);
  --blue: #2c8fd6;
  --blue-dark: #08131f;
  --cyan: #2ee6d6;
  --green: #39d98a;
  --red: #ff6b6b;
  --amber: #ffb84d;
  --input: #fff4cf;
  --row: rgba(255, 255, 255, 0.035);
  --table-line: #d8e4ef;
  --table-muted: #526579;
  --shadow: 0 22px 60px rgba(0, 0, 0, 0.34);
  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:
    radial-gradient(circle at 12% 0%, rgba(46, 230, 214, 0.13), transparent 26rem),
    radial-gradient(circle at 85% 12%, rgba(44, 143, 214, 0.16), transparent 30rem),
    linear-gradient(135deg, #07111c 0%, #0a1623 42%, #08131f 100%);
  color: var(--ink);
  font-size: 14px;
  letter-spacing: 0;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(rgba(120, 175, 215, 0.055) 1px, transparent 1px),
    linear-gradient(90deg, rgba(120, 175, 215, 0.055) 1px, transparent 1px);
  background-size: 42px 42px;
  mask-image: linear-gradient(to bottom, rgba(0, 0, 0, 0.72), transparent 78%);
}

html {
  height: 100%;
}

button,
input {
  font: inherit;
}

.auth-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(circle at top left, rgba(46, 230, 214, 0.14), transparent 24rem),
    radial-gradient(circle at bottom right, rgba(44, 143, 214, 0.17), transparent 28rem),
    #08131f;
}

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

.auth-footer {
  position: fixed;
  right: 16px;
  bottom: calc(14px + env(safe-area-inset-bottom));
  left: 16px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  align-items: center;
  justify-content: center;
  color: #8fa8c0;
  font-size: 12px;
}

.auth-footer a {
  color: #b7eff6;
  font-weight: 700;
  text-decoration: none;
}

.auth-footer a:hover {
  color: #ffffff;
  text-decoration: underline;
}

.auth-panel {
  width: min(100%, 380px);
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: linear-gradient(180deg, rgba(20, 42, 66, 0.96), rgba(10, 23, 37, 0.96));
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
}

.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;
}

.auth-entry-grid {
  display: grid;
  gap: 10px;
  margin: 0 0 18px;
}

.auth-entry {
  display: grid;
  gap: 3px;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  padding: 12px;
  background: rgba(255, 255, 255, 0.055);
  color: var(--ink);
  text-decoration: none;
}

.auth-entry.primary {
  border-color: rgba(46, 230, 214, 0.46);
  background: linear-gradient(135deg, rgba(31, 127, 204, 0.32), rgba(31, 185, 187, 0.22));
}

.auth-entry:hover {
  border-color: var(--cyan);
  background: rgba(46, 230, 214, 0.12);
}

.auth-entry strong {
  font-size: 15px;
}

.auth-entry span,
.auth-section-title {
  color: var(--muted-strong);
  font-size: 12px;
}

.auth-section-title {
  margin: 0 0 10px;
  font-weight: 800;
}

.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: var(--muted-strong);
  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;
  background: rgba(255, 255, 255, 0.08);
  color: var(--ink);
}

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

.auth-panel button {
  width: 100%;
  height: 42px;
  margin-top: 14px;
  border: 1px solid var(--blue-dark);
  border-radius: 6px;
  background: linear-gradient(135deg, #1f7fcc, #1fb9bb);
  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 {
  position: relative;
  display: flex;
  justify-content: space-between;
  gap: 24px;
  align-items: center;
  padding: calc(14px + env(safe-area-inset-top)) 18px 14px;
  background:
    linear-gradient(135deg, rgba(8, 19, 31, 0.98), rgba(15, 47, 73, 0.96)),
    var(--blue-dark);
  color: #ffffff;
  border-bottom: 1px solid rgba(46, 230, 214, 0.24);
  box-shadow: 0 14px 44px rgba(0, 0, 0, 0.28);
  overflow: hidden;
}

.topbar::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(115deg, transparent 0 42%, rgba(46, 230, 214, 0.12) 42.2%, transparent 43% 100%),
    linear-gradient(90deg, transparent 0 72%, rgba(44, 143, 214, 0.14) 72.2%, transparent 73% 100%);
}

.topbar > * {
  position: relative;
  z-index: 1;
}

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

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

.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;
  filter: drop-shadow(0 0 14px rgba(46, 230, 214, 0.26));
}

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

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

.topbar-home-link {
  height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 14px;
  border: 1px solid rgba(97, 213, 255, 0.36);
  border-radius: 6px;
  background: rgba(16, 36, 58, 0.74);
  color: #b7eff6;
  cursor: pointer;
  font-size: 13px;
  font-weight: 800;
  text-decoration: none;
  white-space: nowrap;
}

.topbar-home-link:hover {
  background: rgba(46, 230, 214, 0.14);
  color: #ffffff;
}

.install-button {
  height: 34px;
  padding: 0 14px;
  border: 1px solid rgba(255, 255, 255, 0.34);
  border-radius: 6px;
  background: rgba(46, 230, 214, 0.12);
  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(46, 230, 214, 0.26);
  background: rgba(255, 255, 255, 0.08);
  border-radius: 6px;
  text-align: right;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

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

.stats small {
  color: #a9c4d8;
}

.query-panel {
  padding: 14px 18px;
  background: rgba(8, 19, 31, 0.78);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(18px);
}

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

.search-box {
  display: grid;
  gap: 5px;
  color: var(--muted-strong);
  font-weight: 700;
}

.search-box input {
  width: 100%;
  height: 38px;
  border: 1px solid rgba(46, 230, 214, 0.48);
  background: var(--input);
  border-radius: 6px;
  padding: 0 12px;
  outline: none;
  font-size: 16px;
  color: #111827;
  color-scheme: light;
  box-shadow: 0 0 0 1px rgba(46, 230, 214, 0.1), 0 10px 28px rgba(0, 0, 0, 0.14);
}

.search-box input::placeholder {
  color: #6f7f8f;
}

.search-box input:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(46, 230, 214, 0.17), 0 14px 34px rgba(0, 0, 0, 0.22);
}

.icon-button {
  width: 38px;
  height: 38px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--ink);
  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: rgba(255, 255, 255, 0.055);
}

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

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

.segmented button.active {
  background: linear-gradient(135deg, #1f7fcc, #16a7a8);
  color: #ffffff;
  font-weight: 700;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.14);
}

.check-filter {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 32px;
  color: var(--muted-strong);
  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: rgba(7, 17, 28, 0.62);
}

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: #cfe6f7;
  font-weight: 700;
  color: #122235;
}

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

td {
  background: rgba(255, 255, 255, 0.965);
  color: #152333;
}

tr:nth-child(even) td {
  background: #f8fbff;
}

tr.selected td {
  background: #ddf4f6;
  box-shadow: inset 3px 0 0 #16a7a8;
}

tr:hover td {
  background: #eefbff;
}

.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;
  color: #0f4f78;
}

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

.cert-cell {
  min-width: 140px;
}

.honest-mark-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 22px;
  margin-left: 7px;
  padding: 2px 7px;
  border-radius: 999px;
  background: #ffe4e2;
  color: #b42318;
  box-shadow: inset 0 0 0 1px rgba(180, 35, 24, 0.12);
  font-size: 12px;
  font-weight: 800;
  line-height: 1.15;
  text-align: center;
  white-space: pre-line;
  vertical-align: middle;
}

.honest-mark-text {
  color: #ff6b6b !important;
  font-weight: 800;
}

.source-cell {
  max-width: 240px;
  color: var(--table-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: #dff8ec;
  color: #087447;
  box-shadow: inset 0 0 0 1px rgba(8, 116, 71, 0.08);
}

.status-review {
  background: #fff0d5;
  color: #9a5b00;
  box-shadow: inset 0 0 0 1px rgba(154, 91, 0, 0.08);
}

.status-missing {
  background: #ffe3e3;
  color: #b42318;
}

.empty-state {
  padding: 32px;
  color: #96aabd;
}

.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: rgba(8, 19, 31, 0.9);
  color: #9fb4c7;
}

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

.result-pager button:hover {
  background: rgba(46, 230, 214, 0.12);
}

.site-footer {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
  border-top: 1px solid rgba(46, 230, 214, 0.18);
  background: rgba(8, 19, 31, 0.96);
  color: #92a9be;
  font-size: 12px;
}

.site-footer a {
  color: #b7eff6;
  text-decoration: none;
  font-weight: 700;
}

.site-footer a:hover {
  color: #ffffff;
  text-decoration: underline;
}

.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:
    linear-gradient(180deg, rgba(20, 42, 66, 0.98), rgba(10, 23, 37, 0.98));
  overflow: auto;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  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: #9fb4c7;
  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: rgba(255, 255, 255, 0.07);
  color: var(--ink);
  cursor: pointer;
  font-size: 22px;
  line-height: 1;
}

.detail-close:hover {
  background: rgba(46, 230, 214, 0.12);
}

.business-summary {
  border: 1px solid rgba(46, 230, 214, 0.28);
  border-radius: 8px;
  background: rgba(46, 230, 214, 0.07);
  padding: 10px;
  margin-bottom: 14px;
}

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

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

.summary-grid div {
  min-width: 0;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.055);
}

.summary-grid dd {
  font-weight: 700;
  color: var(--ink);
}

.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: rgba(255, 255, 255, 0.055);
}

dt {
  color: #9fb4c7;
  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: var(--muted-strong);
}

.detail-panel p {
  margin: 0;
  color: #d7e4ef;
  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: rgba(255, 255, 255, 0.055);
    color: var(--muted-strong);
  }

  .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: transparent;
  }

  tr.result-row {
    border: 1px solid var(--table-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(--table-line);
    align-items: start;
  }

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

  td::before {
    color: var(--table-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;
  }
}
