@font-face {
  font-family: "Montserrat";
  src: url("/assets/fonts/Montserrat.ttf") format("truetype");
  font-weight: 100 900;
  font-style: normal;
}

:root {
  --ink: #141414;
  --red: #990000;
  --line: #e6e4e2;
  --paper: #f6f4f3;
  --muted: #8f8f8f;
  --bg: #fbfaf9;
  --radius: 10px;
}

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Montserrat", -apple-system, "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

.top {
  background: #fff;
  border-bottom: 1px solid var(--line);
  border-top: 4px solid var(--red);
}
.top-inner {
  max-width: 1160px;
  margin: 0 auto;
  padding: 14px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.brand { display: flex; align-items: center; gap: 14px; }
.brand img { height: 42px; width: auto; display: block; }
.brand-title { font-weight: 700; font-size: 16px; letter-spacing: 0.2px; }
.brand-sub { font-size: 11px; color: var(--muted); margin-top: 2px; letter-spacing: 0.3px; }
.top-right { display: flex; align-items: center; gap: 10px; }

.chip {
  font-size: 11px;
  font-weight: 600;
  padding: 6px 10px;
  border-radius: 999px;
  letter-spacing: 0.2px;
  white-space: nowrap;
}
.chip-ok { background: #e8f5e9; color: #1b5e20; }
.chip-muted { background: var(--paper); color: #6b6b6b; }
.chip-warn { background: #fff4e5; color: #8a5300; }

.wrap { max-width: 1160px; margin: 0 auto; padding: 22px 24px 60px; }

.card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 20px;
  margin-bottom: 16px;
}
.card-head {
  display: flex;
  align-items: baseline;
  gap: 14px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}
.card h2 {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 1.4px;
  text-transform: uppercase;
  margin: 0;
}
.hint { font-size: 11.5px; color: var(--muted); line-height: 1.4; }
.status { font-size: 12px; margin-top: 10px; min-height: 16px; color: #555; }
.status.error { color: #b00020; }
.status.ok { color: #1b5e20; }

.deal-row { display: flex; gap: 10px; }

.field { display: flex; flex-direction: column; gap: 5px; }
.field > span {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 1.6px;
  text-transform: uppercase;
  color: var(--muted);
}
.fields { display: flex; gap: 14px; flex-wrap: wrap; }
.fields .field { width: 150px; }
.fields .field-grow { flex: 1 1 380px; }

input[type="text"], input[type="date"], input[type="number"], textarea {
  font-family: inherit;
  font-size: 13.5px;
  color: var(--ink);
  background: #fff;
  border: 1px solid #dcd9d6;
  border-radius: 7px;
  padding: 9px 11px;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
  width: 100%;
}
input:focus, textarea:focus { border-color: var(--red); box-shadow: 0 0 0 3px rgba(153,0,0,.08); }
#dealUrl { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; }

.btn {
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 600;
  border-radius: 7px;
  padding: 10px 16px;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background .15s, border-color .15s, color .15s, opacity .15s;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  white-space: nowrap;
}
.btn-primary { background: var(--red); color: #fff; }
.btn-primary:hover { background: #7d0000; }
.btn-ghost { background: #fff; border-color: #dcd9d6; color: var(--ink); }
.btn-ghost:hover { border-color: #b9b4b0; }
.btn-lg { padding: 13px 22px; font-size: 13.5px; }
.btn-sm { padding: 6px 10px; font-size: 11.5px; }
.btn.disabled, .btn[disabled] { opacity: .45; pointer-events: none; }

/* ---------- позиции ---------- */
.items { display: flex; flex-direction: column; gap: 12px; }
.item {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fffdfc;
}
.item-top { display: grid; grid-template-columns: 26px 1fr 72px 74px 110px 30px; gap: 8px; align-items: center; }
.item-top .n {
  font-size: 14px;
  font-weight: 700;
  color: var(--red);
  text-align: center;
}
.item-top .del {
  border: none;
  background: transparent;
  color: #b5afaa;
  font-size: 16px;
  cursor: pointer;
  padding: 4px;
  line-height: 1;
}
.item-top .del:hover { color: var(--red); }
.item textarea {
  margin-top: 9px;
  min-height: 62px;
  resize: vertical;
  font-size: 12.5px;
  line-height: 1.5;
  background: #fff;
}
.item-foot {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 8px;
  font-size: 11.5px;
  color: var(--muted);
}
.item-foot b { color: var(--ink); font-size: 12.5px; }

.items-foot {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  margin-top: 14px;
  gap: 20px;
  flex-wrap: wrap;
}
.totals { text-align: right; min-width: 220px; }
.totals-line { display: flex; justify-content: space-between; gap: 18px; font-size: 12.5px; padding: 3px 0; }
.totals-line b { font-size: 16px; }
.totals-line.muted { color: var(--muted); font-size: 11.5px; }

/* ---------- условия ---------- */
.terms { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.terms .field > span { font-size: 9.5px; }

/* ---------- действия ---------- */
.actions {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 4px 0 18px;
  flex-wrap: wrap;
}
.grow { flex: 1 1 auto; }
.check { font-size: 12.5px; display: flex; align-items: center; gap: 7px; color: #444; }

/* ---------- предпросмотр ---------- */
.preview { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.preview-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .6px;
  text-transform: uppercase;
  color: var(--muted);
}
.preview iframe { width: 100%; height: 900px; border: none; display: block; }

/* ---------- модалка ---------- */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(18,18,18,.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 50;
}
.modal-box {
  background: #fff;
  border-radius: 12px;
  padding: 22px;
  width: min(560px, 100%);
  box-shadow: 0 20px 60px rgba(0,0,0,.25);
}
.modal-box h3 { margin: 0 0 10px; font-size: 15px; }
.modal-box .field { margin-top: 14px; }
.modal-actions { display: flex; gap: 10px; margin-top: 18px; }
code {
  background: var(--paper);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 11.5px;
}

@media (max-width: 860px) {
  .terms { grid-template-columns: repeat(2, 1fr); }
  .item-top { grid-template-columns: 22px 1fr 30px; grid-auto-rows: auto; }
  .item-top .unit, .item-top .qty, .item-top .price { grid-column: 2 / 3; }
  .top-inner { flex-direction: column; align-items: flex-start; }
}

/* ---------- режим встраивания в Битрикс24 ---------- */
body.embedded .top { display: none; }
body.embedded .wrap { max-width: 100%; padding: 12px 14px 40px; }
body.embedded .card { border-radius: 8px; padding: 14px 16px; margin-bottom: 12px; }
body.embedded .deal-card { display: none; }
body.embedded .actions { position: sticky; bottom: 0; background: var(--bg); padding: 10px 0; z-index: 5; }
body.embedded .preview iframe { height: 70vh; }
body.embedded .brand-sub { display: none; }

select {
  font-family: inherit;
  font-size: 12.5px;
  padding: 7px 9px;
  border: 1px solid #dcd9d6;
  border-radius: 7px;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
}
select:focus { outline: none; border-color: var(--red); box-shadow: 0 0 0 3px rgba(153,0,0,.08); }
