:root {
  --bg: #f6f7f4;
  --panel: #ffffff;
  --ink: #18201d;
  --muted: #65716b;
  --line: #dde3dc;
  --primary: #176f5b;
  --primary-dark: #105140;
  --accent: #d55f35;
  --soft: #e9f2ed;
  --danger: #b83232;
  --shadow: 0 16px 36px rgba(30, 42, 35, 0.1);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Arial, "Microsoft YaHei", sans-serif;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.app {
  min-height: 100vh;
}

.app.locked {
  display: none;
}

.access-screen {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  gap: 14px;
  padding: 22px;
  background:
    linear-gradient(135deg, rgba(23, 111, 91, 0.9), rgba(213, 95, 53, 0.82)),
    url("../assets/hero-generators.jpg") center/cover;
}

.access-screen.hidden {
  display: none;
}

.access-card {
  width: min(520px, 100%);
  padding: 24px;
  background: rgba(255, 255, 255, 0.96);
  border: 1px solid rgba(255, 255, 255, 0.6);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.company-panel {
  display: grid;
  grid-template-columns: 52px minmax(0, 1fr);
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
}

.company-logo,
.brand-logo {
  display: inline-grid;
  place-items: center;
  overflow: hidden;
  background: var(--primary);
  color: #fff;
  font-weight: 700;
}

.company-logo {
  width: 52px;
  height: 52px;
  border-radius: 8px;
}

.company-logo img,
.brand-logo img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #fff;
}

.company-panel strong {
  display: block;
  color: var(--ink);
  font-size: 18px;
  line-height: 1.25;
}

.company-panel span {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 4px;
  color: var(--muted);
  line-height: 1.35;
}

.company-panel span a,
.contact-chip a {
  color: var(--primary-dark);
  text-decoration: none;
}

.company-panel span a:hover,
.contact-chip a:hover {
  text-decoration: underline;
}

.promo-strip {
  display: grid;
  width: min(920px, 100%);
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 10px;
}

.promo-strip.empty {
  display: none;
}

.promo-item {
  display: grid;
  grid-template-columns: 30px minmax(0, 1fr);
  align-items: center;
  min-height: 62px;
  padding: 10px 12px;
  background: rgba(255, 255, 255, 0.96);
  border: 1px solid rgba(255, 255, 255, 0.62);
  border-radius: 8px;
  box-shadow: 0 10px 24px rgba(30, 42, 35, 0.08);
}

.promo-item span {
  display: inline-grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 13px;
  font-weight: 700;
}

.promo-item strong {
  min-width: 0;
  color: var(--primary-dark);
  font-size: 14px;
  line-height: 1.35;
}

.access-brand small {
  color: var(--primary);
  font-weight: 700;
  text-transform: uppercase;
}

.access-brand h1 {
  margin: 8px 0 10px;
  font-size: 32px;
  line-height: 1.12;
}

.access-brand p {
  margin: 0 0 20px;
  color: var(--muted);
  line-height: 1.55;
}

.access-brand .catalog-scope {
  margin: -8px 0 18px;
  padding: 10px 12px;
  background: var(--soft);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--primary-dark);
  font-size: 14px;
  font-weight: 700;
}

.access-form {
  display: grid;
  gap: 13px;
}

.access-form label {
  display: grid;
  gap: 7px;
  color: var(--muted);
}

.access-form input {
  color: var(--ink);
}

.access-form select {
  color: var(--ink);
}

.phone-row {
  display: grid;
  grid-template-columns: minmax(150px, 0.55fr) minmax(0, 1fr);
  gap: 10px;
}

.access-message {
  min-height: 22px;
  margin: 0;
  color: var(--primary-dark);
}

.access-message.error {
  color: var(--danger);
}

.access-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.ghost-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  padding: 0 14px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--ink);
  text-align: center;
  text-decoration: none;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 14px;
  min-height: 72px;
  padding: 12px clamp(16px, 3vw, 34px);
  background: rgba(255, 255, 255, 0.92);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(12px);
}

.brand {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

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

.brand-logo {
  flex: 0 0 auto;
  width: 38px;
  height: 38px;
  border-radius: 7px;
  font-size: 13px;
}

.brand-row > div {
  min-width: 0;
}

.brand strong {
  font-size: 20px;
  line-height: 1.2;
}

.brand small,
.section-title small {
  color: var(--muted);
}

.top-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  margin-left: auto;
}

.language-toggle {
  display: inline-flex;
  align-items: center;
  padding: 3px;
  background: var(--soft);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.access-brand .language-toggle {
  width: max-content;
  margin-bottom: 14px;
}

.language-toggle button {
  min-height: 34px;
  padding: 0 11px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
}

.language-toggle button.active {
  background: #fff;
  color: var(--primary-dark);
  box-shadow: 0 4px 12px rgba(30, 42, 35, 0.08);
}

.contact-chip {
  display: flex;
  gap: 6px;
  max-width: 280px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--muted);
  font-size: 13px;
}

.layout {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  gap: 22px;
  padding: 22px clamp(16px, 3vw, 34px) 34px;
}

.tree-panel {
  position: sticky;
  top: 94px;
  align-self: start;
  height: calc(100vh - 116px);
  overflow: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.panel-head {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

.panel-head div {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
}

.panel-head strong {
  color: var(--primary);
}

.category-tree {
  padding: 10px;
}

.tree-item {
  margin: 3px 0;
}

.tree-row {
  display: grid;
  grid-template-columns: 26px minmax(0, 1fr) 34px;
  align-items: center;
  width: 100%;
  min-height: 40px;
  padding: 0 4px;
  border-radius: 7px;
  color: var(--ink);
}

.tree-row.active {
  background: var(--soft);
  color: var(--primary-dark);
  font-weight: 700;
}

.tree-row button {
  border: 0;
  background: transparent;
  color: inherit;
}

.tree-name {
  overflow: hidden;
  text-align: left;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tree-children {
  margin-left: 22px;
  border-left: 1px solid var(--line);
  padding-left: 8px;
}

.content {
  min-width: 0;
}

.referral-panel {
  display: grid;
  grid-template-columns: minmax(130px, auto) minmax(0, 1fr) auto;
  align-items: end;
  gap: 12px;
  margin-bottom: 16px;
  padding: 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 10px 24px rgba(30, 42, 35, 0.06);
}

.referral-panel small,
.referral-panel label {
  color: var(--muted);
}

.referral-panel strong {
  display: block;
  margin-top: 3px;
  color: var(--primary-dark);
  font-size: 20px;
}

.referral-panel label {
  display: grid;
  gap: 6px;
}

.referral-panel input {
  width: 100%;
}

.search-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 160px;
  gap: 12px;
  margin-bottom: 22px;
}

.search-box {
  display: flex;
  align-items: center;
  min-height: 48px;
  padding: 0 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.search-box svg {
  width: 21px;
  height: 21px;
  margin-right: 10px;
  fill: none;
  stroke: var(--muted);
  stroke-width: 2;
}

.search-box input {
  width: 100%;
  border: 0;
  outline: 0;
  background: transparent;
}

select,
input,
textarea {
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--ink);
}

textarea {
  padding: 10px;
  resize: vertical;
}

input,
select {
  padding: 0 11px;
}

.section-title {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.section-title h1 {
  margin: 4px 0 0;
  font-size: clamp(24px, 3vw, 36px);
  line-height: 1.12;
}

.section-title > span {
  flex: 0 0 auto;
  color: var(--muted);
}

.product-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 16px;
}

.product-card {
  overflow: hidden;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 10px 24px rgba(30, 42, 35, 0.06);
}

.product-image {
  display: grid;
  place-items: center;
  aspect-ratio: 4 / 3;
  background: linear-gradient(140deg, #edf1ee, #dbe7e1);
  color: var(--muted);
  font-weight: 700;
}

.product-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.product-body {
  padding: 14px;
}

.product-body h2 {
  margin: 0 0 8px;
  font-size: 18px;
}

.specs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 11px;
}

.specs span,
.tag {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 0 9px;
  border-radius: 999px;
  background: var(--soft);
  color: var(--primary-dark);
  font-size: 13px;
}

.product-body p {
  display: -webkit-box;
  min-height: 42px;
  margin: 0 0 12px;
  overflow: hidden;
  color: var(--muted);
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.card-actions {
  display: flex;
  gap: 8px;
}

.primary-button,
.ghost-button,
.danger-button,
.icon-button {
  min-height: 40px;
  border-radius: 7px;
  border: 1px solid transparent;
}

.primary-button {
  padding: 0 16px;
  background: var(--primary);
  color: #fff;
}

.primary-button:hover {
  background: var(--primary-dark);
}

.ghost-button {
  padding: 0 14px;
  background: #fff;
  border-color: var(--line);
  color: var(--ink);
}

.danger-button {
  padding: 0 14px;
  background: #fff;
  border-color: #e6b4b4;
  color: var(--danger);
}

.icon-button {
  display: inline-grid;
  place-items: center;
  width: 40px;
  padding: 0;
  background: #fff;
  border-color: var(--line);
  color: var(--ink);
  font-size: 24px;
  line-height: 1;
}

.mobile-only {
  display: none;
}

.mobile-only span {
  display: block;
  width: 18px;
  height: 2px;
  margin: 2px 0;
  background: currentColor;
}

.editor-dialog {
  width: min(640px, calc(100vw - 28px));
  padding: 0;
  border: 0;
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.settings-dialog {
  width: min(980px, calc(100vw - 28px));
}

.editor-dialog::backdrop {
  background: rgba(10, 16, 13, 0.38);
}

.editor-form {
  display: grid;
  gap: 14px;
  padding: 18px;
}

.dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.dialog-head h2 {
  margin: 0;
  font-size: 22px;
}

.editor-form label {
  display: grid;
  gap: 7px;
  color: var(--muted);
}

.editor-form label input,
.editor-form label select,
.editor-form label textarea {
  color: var(--ink);
}

.two-columns {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.form-actions {
  display: grid;
  grid-template-columns: auto 1fr auto auto;
  gap: 10px;
  align-items: center;
  margin-top: 6px;
}

.lead-table-wrap {
  max-height: 260px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.lead-table {
  width: 100%;
  border-collapse: collapse;
  background: #fff;
  font-size: 13px;
}

.lead-table th,
.lead-table td {
  padding: 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

.lead-table th {
  position: sticky;
  top: 0;
  background: var(--soft);
  color: var(--primary-dark);
  font-weight: 700;
}

.lead-table small {
  color: var(--muted);
}

.view-mode .edit-only,
.view-mode #newProduct,
.view-mode .edit-product {
  display: none;
}

.view-mode .admin-only {
  display: none;
}

.empty-state {
  display: grid;
  place-items: center;
  min-height: 260px;
  padding: 28px;
  background: var(--panel);
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  text-align: center;
}

@media (max-width: 760px) {
  .topbar {
    min-height: 64px;
    padding: 10px 12px;
  }

  .brand strong {
    font-size: 17px;
  }

  .brand small {
    display: none;
  }

  .contact-chip {
    display: none !important;
  }

  .top-actions {
    gap: 7px;
  }

  .top-actions button {
    min-height: 38px;
    padding-inline: 11px;
  }

  .top-actions .language-toggle {
    order: 10;
    width: 100%;
    justify-content: flex-end;
    background: transparent;
    border: 0;
    padding: 0;
  }

  .top-actions .language-toggle button {
    background: var(--soft);
  }

  .top-actions .language-toggle button.active {
    background: #fff;
  }

  .mobile-only {
    display: inline-grid;
  }

  .layout {
    display: block;
    padding: 14px 12px 26px;
  }

  .tree-panel {
    position: fixed;
    inset: 64px 0 0 0;
    z-index: 9;
    width: min(86vw, 360px);
    height: auto;
    border-radius: 0;
    transform: translateX(-105%);
    transition: transform 0.2s ease;
  }

  .tree-panel.open {
    transform: translateX(0);
  }

  .search-row {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .referral-panel {
    grid-template-columns: 1fr;
  }

  .section-title {
    align-items: start;
    flex-direction: column;
    gap: 8px;
  }

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

  .two-columns,
  .form-actions,
  .access-actions,
  .phone-row {
    grid-template-columns: 1fr;
  }

  .access-card {
    padding: 18px;
  }

  .promo-strip {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .promo-item {
    min-height: 52px;
    padding: 8px 10px;
  }

  .promo-item:nth-child(n + 2) {
    display: none;
  }

  .company-panel {
    grid-template-columns: 44px minmax(0, 1fr);
    margin-bottom: 12px;
    padding-bottom: 12px;
  }

  .company-logo {
    width: 44px;
    height: 44px;
  }

  .company-panel strong {
    font-size: 17px;
  }

  .company-panel span {
    gap: 4px;
    font-size: 14px;
  }

  .access-brand h1 {
    font-size: 27px;
  }

  .access-brand p {
    margin-bottom: 14px;
  }

  .access-brand .catalog-scope {
    margin: -4px 0 14px;
    font-size: 13px;
  }
}
