:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-soft: #f8fafb;
  --ink: #17202a;
  --muted: #68737f;
  --line: #e2e7ec;
  --accent: #145a46;
  --accent-soft: #e8f3ef;
  --warning: #a35b13;
  --warning-soft: #fff3df;
  --danger: #a23b3b;
  --shadow: 0 18px 45px rgba(19, 32, 43, 0.09);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  min-width: 1080px;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.45 Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button, input, select { font: inherit; }
button { cursor: pointer; }

.app-shell { display: grid; grid-template-columns: 248px 1fr; min-height: 100vh; }

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: 248px;
  display: flex;
  flex-direction: column;
  padding: 28px 20px;
  background: #111b20;
  color: #eef4f1;
}

.nav { display: grid; gap: 5px; padding-top: 8px; }
.nav-item {
  display: flex; align-items: center; justify-content: space-between;
  width: 100%; padding: 11px 12px; border: 0; border-radius: 9px;
  background: transparent; color: #aebbb6; text-align: left;
  text-decoration: none;
}
.nav-item:hover:not(:disabled), .nav-item.active { background: #1d2b2f; color: #fff; }
.nav-item:disabled { cursor: default; opacity: .7; }
.nav-item kbd, .nav-item em {
  border: 0; border-radius: 10px; padding: 2px 7px; background: #2b3b3e;
  color: #9fb0aa; font: 10px/1.4 inherit;
}
.nav-item em { font-style: normal; }

.sync-card {
  display: flex; gap: 10px; margin-top: auto; padding: 14px 12px;
  border: 1px solid #29373a; border-radius: 10px; background: #172327;
}
.sync-card strong, .sync-card small { display: block; }
.sync-card strong { font-size: 12px; font-weight: 600; }
.sync-card small { margin-top: 3px; color: #82928d; font-size: 10px; }
.status-dot { width: 8px; height: 8px; margin-top: 5px; border-radius: 50%; background: #53b88b; box-shadow: 0 0 0 4px rgba(83,184,139,.12); }

.main { grid-column: 2; padding: 34px 38px 46px; overflow: hidden; }
.topbar { display: flex; align-items: end; justify-content: space-between; margin-bottom: 26px; }
.eyebrow { margin: 0 0 4px; color: var(--muted); font-size: 11px; font-weight: 700; letter-spacing: .11em; text-transform: uppercase; }
h1, h2 { margin: 0; letter-spacing: -.035em; }
h1 { font-size: 29px; }
h2 { font-size: 21px; }
.top-actions { display: flex; gap: 8px; }
.top-actions { align-items: center; }
.exchange-rate {
  display: grid;
  min-height: 38px;
  min-width: 116px;
  padding: 5px 11px;
  border: 1px solid #cfe1d9;
  border-radius: 8px;
  background: var(--accent-soft);
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}
.exchange-rate span {
  font-size: 9px;
  font-weight: 800;
  line-height: 1.1;
  letter-spacing: .08em;
}
.exchange-rate strong {
  font-size: 14px;
  line-height: 1.2;
}
.exchange-rate.error {
  border-color: #f0d9b5;
  background: #fff8eb;
  color: var(--warning);
}
.button {
  min-height: 38px; padding: 0 15px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--surface); color: var(--ink); font-weight: 600;
}
.button:hover:not(:disabled) { border-color: #bdc7cf; }
.button.primary { border-color: var(--accent); background: var(--accent); color: white; }
.button.primary:hover:not(:disabled) { background: #0f4938; }
.button:disabled { cursor: default; opacity: .45; }
.button.ghost { background: transparent; }
.button.compact { min-height: 32px; padding-inline: 11px; font-size: 11px; }

.metrics { display: grid; grid-template-columns: repeat(4, minmax(150px, 1fr)); gap: 12px; margin-bottom: 18px; }
.metric { padding: 17px 18px; border: 1px solid var(--line); border-radius: 11px; background: var(--surface); }
.metric > span, .metric > small { display: block; color: var(--muted); }
.metric > span { font-size: 12px; font-weight: 600; }
.metric > strong { display: block; margin: 7px 0 2px; font-size: 25px; letter-spacing: -.04em; }
.metric > small { font-size: 11px; }
.metric.warning { border-color: #f0d9b5; background: #fffdf8; }
.metric.warning > strong { color: var(--warning); }

.catalog-card { border: 1px solid var(--line); border-radius: 12px; background: var(--surface); overflow: hidden; }
.toolbar { display: grid; grid-template-columns: minmax(260px, 1fr) 180px 180px auto; gap: 9px; padding: 14px; border-bottom: 1px solid var(--line); }
.models-toolbar { grid-template-columns: minmax(280px, 1fr) 210px auto; }
input, select {
  width: 100%; height: 38px; padding: 0 11px; border: 1px solid #d7dde2;
  border-radius: 8px; outline: none; background: white; color: var(--ink);
}
input:focus, select:focus { border-color: #7aa494; box-shadow: 0 0 0 3px rgba(20,90,70,.08); }
.search input { padding-left: 13px; }
.checkbox { display: flex; align-items: center; gap: 8px; padding: 0 8px; white-space: nowrap; color: #4f5d67; }
.checkbox input { width: 16px; height: 16px; accent-color: var(--accent); }

.table-wrap { overflow: auto; }
table { width: 100%; border-collapse: collapse; }
th { padding: 11px 14px; background: var(--surface-soft); color: #71808a; font-size: 10px; letter-spacing: .08em; text-align: left; text-transform: uppercase; }
td { padding: 13px 14px; border-top: 1px solid #edf0f2; vertical-align: middle; }
tbody tr { cursor: pointer; transition: background .12s ease; }
tbody tr:hover { background: #f9fbfa; }
.product-name strong, .product-name small { display: block; }
.product-name strong { max-width: 560px; white-space: normal; line-height: 1.3; font-size: 13px; }
.product-name small { margin-top: 3px; color: #8b969e; font-size: 10px; }
.region-flag {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 18px;
  margin-left: 7px;
  padding: 0;
  border: 1px solid #dde5e1;
  border-radius: 4px;
  background: #fff;
  overflow: hidden;
  vertical-align: baseline;
  box-shadow: 0 1px 2px rgba(17, 24, 39, .06);
}
.region-flag img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.specs { display: flex; flex-wrap: wrap; gap: 4px; max-width: 270px; }
.tag { padding: 3px 7px; border-radius: 5px; background: #f0f3f5; color: #59666f; font-size: 10px; }
.tag.active-device { background: #fff1d6; color: #9a5a00; font-weight: 700; }
.stock { font-variant-numeric: tabular-nums; font-weight: 700; }
.stock.zero { color: #a6afb6; font-weight: 500; }
.money { white-space: nowrap; font-variant-numeric: tabular-nums; }
.money.effective { font-weight: 700; }
.price-mode { display: block; margin-top: 2px; color: #8b969e; font-size: 9px; }
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 4px 8px; border-radius: 12px; font-size: 10px; font-weight: 650; white-space: nowrap; }
.badge.recognized { background: var(--accent-soft); color: var(--accent); }
.badge.partial { background: #eef1f6; color: #56667d; }
.badge.review { background: var(--warning-soft); color: var(--warning); }
.empty-state { height: 220px; color: var(--muted); text-align: center; }
.table-footer { display: flex; justify-content: space-between; padding: 11px 14px; border-top: 1px solid var(--line); color: #7b8790; font-size: 10px; }
.pagination { display: flex; align-items: center; gap: 10px; }
.pagination .mini-button:disabled { cursor: default; opacity: .4; }

.telegram-heading {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 20px;
  padding: 18px 18px 14px;
  border-bottom: 1px solid var(--line);
}
.telegram-heading h2 { font-size: 18px; }
.telegram-heading p { margin: 5px 0 0; color: var(--muted); font-size: 12px; }
.telegram-actions { display: flex; align-items: center; gap: 10px; white-space: nowrap; }
.telegram-actions span { color: var(--muted); font-size: 11px; }
.price-bulk-panel {
  display: flex;
  width: fit-content;
  max-width: calc(100% - 36px);
  margin: 12px 18px 0 auto;
  gap: 10px;
  align-items: end;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fbfcfd;
}
.price-bulk-panel > strong {
  align-self: center;
  white-space: nowrap;
  font-size: 12px;
}
.price-tool-main {
  display: grid;
  grid-template-columns: repeat(3, 96px);
  gap: 7px;
}
.price-tool-main label { display: grid; gap: 5px; }
.price-tool-main label span {
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
}
.price-tool-actions { display: flex; gap: 6px; align-items: center; }
.price-tool-actions .mini-button {
  min-height: 32px;
  padding-inline: 8px;
  font-weight: 700;
}
.telegram-preview { display: grid; gap: 14px; padding: 16px; }
.telegram-message {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fbfcfd;
  overflow: hidden;
}
.telegram-message header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border-bottom: 1px solid #e7ecef;
  background: #fff;
}
.telegram-message header strong,
.telegram-message header small { display: block; }
.telegram-message header strong { font-size: 14px; }
.telegram-message header small { margin-top: 2px; color: var(--muted); font-size: 11px; }
.message-price-tools {
  display: flex;
  align-items: center;
  gap: 5px;
}
.message-price-tools span {
  margin-right: 3px;
  color: var(--muted);
  font-size: 10px;
}
.message-price-tools input {
  width: 74px;
  height: 28px;
  padding: 0 7px;
  text-align: right;
  font-size: 11px;
}
.message-price-tools .mini-button {
  min-width: 34px;
  min-height: 28px;
  padding: 5px 7px;
  font-weight: 700;
}
.telegram-lines { display: grid; }
.telegram-line {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 260px 112px;
  gap: 12px;
  align-items: center;
  padding: 8px 10px;
  border-top: 1px solid #edf1f3;
}
.telegram-line:first-child { border-top: 0; }
.telegram-line.section-gap {
  margin-top: 12px;
  border-top: 0;
}
.telegram-line.price-dirty {
  background: #fffaf0;
}
.telegram-line.price-dirty .telegram-price-editor input {
  border-color: #d99a35;
  background: #fffdf8;
}
.telegram-copy-line {
  min-width: 0;
  padding: 8px 10px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: #101820;
  font: 12px/1.35 "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  text-align: left;
  white-space: pre-wrap;
}
.telegram-copy-line:hover { border-color: #d7e1dc; background: #f5faf7; }
.hicatalog-price {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: center;
  justify-content: stretch;
  gap: 8px;
  min-height: 32px;
  padding: 0 8px;
  border-radius: 8px;
  background: #f5f7f8;
  font-size: 12px;
}
.hicatalog-price strong { font-size: 12px; }
.hicatalog-price em {
  min-width: 0;
  order: -1;
  color: var(--muted);
  font-size: 10px;
  font-style: normal;
  line-height: 1.15;
  white-space: normal;
}
.hicatalog-price small {
  padding: 2px 6px;
  border-radius: 999px;
  background: #edf1f3;
  color: var(--muted);
  font-size: 10px;
}
.hicatalog-price small.up { background: #fff3df; color: #9a5a00; }
.hicatalog-price small.down { background: #eaf7ef; color: #166237; }
.hicatalog-price small.same { background: #edf1f3; color: #6a747c; }
.hicatalog-price.empty { color: var(--muted); justify-content: center; }
.telegram-price-editor { display: flex; gap: 6px; align-items: center; }
.telegram-price-editor input { width: 112px; height: 32px; padding: 0 8px; text-align: right; }

.rules-layout { display: grid; grid-template-columns: minmax(330px, 410px) 1fr; gap: 15px; }
.rule-form-card, .rules-card { border: 1px solid var(--line); border-radius: 12px; background: var(--surface); padding: 20px; }
.section-heading { display: flex; align-items: start; justify-content: space-between; gap: 15px; margin-bottom: 18px; }
.section-heading h2 { font-size: 18px; }
.rule-form-card > label { display: block; margin-bottom: 13px; }
.rule-grid { margin-top: 0; }
.rule-active { margin-top: 16px; }
.rule-submit { width: 100%; margin-top: 15px; }
.form-hint { margin: 10px 3px 0; color: var(--muted); font-size: 10px; }
.manual-price-field { display: block; max-width: 240px; }
.rules-total { padding: 4px 8px; border-radius: 12px; background: var(--surface-soft); color: var(--muted); font-size: 10px; }
.rules-list { display: grid; gap: 8px; }
.rule-item {
  display: grid; grid-template-columns: 1fr auto auto; gap: 12px; align-items: center;
  padding: 13px 14px; border: 1px solid var(--line); border-radius: 9px;
}
.rule-item.inactive { opacity: .55; }
.rule-item strong, .rule-item small { display: block; }
.rule-item small { margin-top: 3px; color: var(--muted); font-size: 10px; }
.rule-value { text-align: right; }
.rule-value strong { color: var(--accent); font-size: 16px; }
.rule-actions { display: flex; gap: 5px; }
.mini-button { border: 0; border-radius: 6px; padding: 6px 8px; background: #f0f3f4; color: #53616a; font-size: 10px; }
.mini-button.danger { color: var(--danger); }

.drawer-backdrop { position: fixed; inset: 0; z-index: 10; background: rgba(14,24,28,.28); backdrop-filter: blur(1px); }
.drawer {
  position: fixed; z-index: 11; inset: 0 0 0 auto; width: min(510px, 44vw);
  padding: 25px 26px; overflow-y: auto; background: white; box-shadow: var(--shadow);
  transform: translateX(102%); transition: transform .2s ease;
}
.drawer.open { transform: translateX(0); }
.drawer-header { display: flex; justify-content: space-between; margin-bottom: 21px; }
.icon-button { width: 34px; height: 34px; border: 0; border-radius: 8px; background: #f2f4f5; color: #69757e; font-size: 22px; line-height: 1; }
.source-box { padding: 13px 14px; border-radius: 9px; background: var(--surface-soft); }
.source-box small, .source-box span { color: var(--muted); font-size: 10px; }
.source-box p { margin: 4px 0; font-weight: 600; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 13px 10px; margin-top: 19px; }
.form-grid .wide { grid-column: 1 / -1; }
form label > span, legend { display: block; margin-bottom: 5px; color: #5f6b74; font-size: 11px; font-weight: 650; }
hr { margin: 23px 0; border: 0; border-top: 1px solid var(--line); }
fieldset { margin: 0; padding: 0; border: 0; }
legend { margin-bottom: 10px; }
.segmented { display: grid; grid-template-columns: 1fr 1fr; padding: 3px; border-radius: 9px; background: #eef1f2; }
.segmented label { cursor: pointer; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented span { margin: 0; padding: 7px; border-radius: 7px; text-align: center; font-size: 11px; }
.segmented input:checked + span { background: white; color: var(--ink); box-shadow: 0 1px 4px rgba(25,37,44,.12); }
.price-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 9px; margin-top: 13px; }
.price-grid input:disabled { background: #f4f5f6; color: #7c878f; }
.price-preview { display: flex; align-items: center; justify-content: space-between; margin-top: 13px; padding: 12px 13px; border-radius: 8px; background: var(--accent-soft); color: var(--accent); }
.price-preview strong { font-size: 18px; }
.review-toggle { display: flex; align-items: center; gap: 10px; margin-top: 22px; padding: 13px; border: 1px solid var(--line); border-radius: 9px; }
.review-toggle input { width: 17px; height: 17px; accent-color: var(--accent); }
.review-toggle span, .review-toggle strong, .review-toggle small { display: block; margin: 0; }
.review-toggle small { margin-top: 2px; color: var(--muted); font-size: 10px; font-weight: 400; }
.history-section { margin-top: 22px; padding-top: 18px; border-top: 1px solid var(--line); }
.history-heading { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 10px; }
.history-heading strong { font-size: 12px; }
.history-heading small { color: var(--muted); font-size: 10px; }
.history-list { display: grid; gap: 7px; }
.history-item {
  display: grid; grid-template-columns: 92px 1fr auto; gap: 9px; align-items: center;
  padding: 9px 10px; border-radius: 7px; background: var(--surface-soft); font-size: 10px;
}
.history-item time { color: var(--muted); }
.history-item strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.history-item span { color: var(--muted); white-space: nowrap; }
.history-empty { margin: 0; padding: 12px; color: var(--muted); background: var(--surface-soft); border-radius: 7px; font-size: 10px; text-align: center; }
.drawer-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 25px; padding-top: 18px; border-top: 1px solid var(--line); }

.toast {
  position: fixed; z-index: 20; right: 24px; bottom: 24px; padding: 11px 15px;
  border-radius: 8px; background: #172429; color: white; box-shadow: var(--shadow);
  opacity: 0; transform: translateY(8px); pointer-events: none; transition: .18s ease;
}
.toast.show { opacity: 1; transform: translateY(0); }

.top-actions form { margin: 0; }
.auto-refresh-toggle {
  height: 38px;
  padding: 0 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  font-size: 12px;
  font-weight: 600;
}

.auth-page {
  min-width: 0;
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: 24px;
  background:
    radial-gradient(circle at 20% 20%, rgba(20, 90, 70, .12), transparent 34%),
    var(--bg);
}
.auth-shell { width: min(100%, 420px); }
.auth-card {
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--surface);
  box-shadow: var(--shadow);
}
.auth-heading {
  margin-bottom: 22px;
}
.auth-heading h1 { font-size: 24px; line-height: 1.2; }
.auth-form { display: grid; gap: 14px; }
.auth-form label span {
  display: block;
  margin-bottom: 6px;
  color: #59656f;
  font-size: 12px;
  font-weight: 700;
}
.auth-form input {
  width: 100%;
  height: 42px;
  padding: 0 12px;
  border: 1px solid #d8e0e6;
  border-radius: 9px;
  background: #fbfcfd;
}
.auth-form input:focus {
  outline: 2px solid rgba(20, 90, 70, .16);
  border-color: var(--accent);
}
.auth-error {
  margin-bottom: 14px;
  padding: 10px 12px;
  border-radius: 9px;
  background: #fff0f0;
  color: var(--danger);
  font-size: 12px;
  font-weight: 700;
}
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

@media (max-width: 1180px) {
  .main { padding-inline: 24px; }
  .toolbar { grid-template-columns: 1fr 160px 165px; }
  .checkbox { grid-column: 1 / -1; }
}
