/* orkem · КП — mobile-first */
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: #f5f6f8;
  color: #1d1f23;
  font-size: 15px;
  line-height: 1.5;
  -webkit-tap-highlight-color: transparent;
}
a { color: #2563eb; text-decoration: none; }
a:hover { text-decoration: underline; }

input, select, textarea, button {
  font-family: inherit; font-size: inherit;
  -webkit-appearance: none; appearance: none;
  border-radius: 6px;
}

/* ---- Topbar ---- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px;
  background: #fff;
  border-bottom: 1px solid #e5e7eb;
  position: sticky; top: 0; z-index: 10;
}
.topbar .logo { font-weight: 700; color: #111; font-size: 15px; }
.topbar nav a { margin-left: 12px; color: #4b5563; font-size: 14px; }

/* ---- Page ---- */
.page { max-width: 1320px; margin: 0 auto; padding: 16px; padding-bottom: 100px; }
.page-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; flex-wrap: wrap;
  margin-bottom: 16px;
}
.page-head h1 {
  margin: 0; font-size: 22px; font-weight: 700;
  flex: 1; min-width: 200px;
}
.head-actions { display: flex; gap: 6px; flex-shrink: 0; }

/* ---- Buttons ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 9px 14px;
  border: 1px solid #d1d5db;
  background: #fff;
  border-radius: 6px;
  font-size: 14px;
  cursor: pointer;
  color: #1d1f23;
  white-space: nowrap;
  min-height: 38px;
  transition: background .12s, border-color .12s;
}
.btn:hover { background: #f3f4f6; }
.btn:active { transform: translateY(1px); }
.btn-primary { background: #2563eb; color: #fff; border-color: #2563eb; }
.btn-primary:hover { background: #1d4ed8; }
.btn-sm { padding: 5px 10px; font-size: 13px; min-height: 32px; }
.btn-danger { color: #dc2626; }
.btn-danger:hover { background: #fee2e2; border-color: #fca5a5; }
.btn-html { background: #f3e8ff; color: #7c3aed; border-color: #d8b4fe; }
.btn-html:hover { background: #ede9fe; }

/* ---- Index (proposal cards) ---- */
.proposal-cards {
  display: grid; gap: 10px;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
}
.prop-card {
  background: #fff; border-radius: 10px; padding: 14px;
  border: 1px solid #e5e7eb;
  display: flex; flex-direction: column; gap: 8px;
}
.prop-title { font-weight: 600; color: #111; font-size: 16px; }
.prop-meta { display: flex; justify-content: space-between; align-items: center; font-size: 14px; color: #4b5563; }
.prop-sum { font-weight: 600; color: #2563eb; }
.prop-date { font-size: 12px; }
.prop-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.prop-actions .btn { flex: 1; }
.iform { display: inline; margin: 0; }
.muted { color: #6b7280; font-size: 13px; }
.empty { color: #6b7280; padding: 30px 0; text-align: center; }

/* ---- Editable title ---- */
.inline-edit {
  outline: none; border: 1px dashed transparent; padding: 4px 8px; border-radius: 6px;
}
.inline-edit:hover, .inline-edit:focus {
  border-color: #d1d5db; background: #fff;
}

/* ---- Meta row ---- */
.meta-row {
  display: flex; align-items: flex-end; gap: 14px; flex-wrap: wrap;
  background: #fff; padding: 12px 14px; border-radius: 8px; margin-bottom: 16px;
}
.meta-label { display: flex; flex-direction: column; gap: 3px; font-size: 11px; color: #6b7280; }
.meta-label span { display: block; }
.meta-input {
  font-size: 15px; padding: 6px 10px; border: 1px solid #d1d5db; border-radius: 6px;
  color: #1d1f23; background: #fff; min-height: 36px;
}
.meta-caption { font-size: 12px; color: #6b7280; }
.sections-toggle { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.chk { display: inline-flex; align-items: center; gap: 4px; font-size: 14px; cursor: pointer; user-select: none; }
.chk input { margin: 0; width: 18px; height: 18px; }
.total { margin-left: auto; font-size: 16px; color: #111; padding-bottom: 4px; }
.total b { color: #2563eb; }

/* ---- Sections ---- */
.section {
  background: #fff;
  border-radius: 8px;
  padding: 14px;
  margin-bottom: 14px;
}
.section-disabled { opacity: 0.45; }
.section-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 12px; gap: 8px; flex-wrap: wrap;
}
.section-head h2 { margin: 0; font-size: 17px; }
.section-actions {
  display: flex; gap: 6px; align-items: center; flex-wrap: wrap;
}
.add-url-form { display: flex; gap: 4px; flex-wrap: wrap; }
.url-input {
  width: 250px; max-width: 100%;
  padding: 8px 10px; border: 1px solid #d1d5db; border-radius: 6px;
  font-size: 14px; min-height: 38px;
}

/* ---- Items ---- */
.items { display: flex; flex-direction: column; gap: 12px; }
.item {
  display: flex; gap: 14px;
  padding: 12px;
  background: #f9fafb; border-radius: 8px; border: 1px solid #e5e7eb;
}
.item-photo {
  width: 140px; flex-shrink: 0; text-align: center;
  display: flex; flex-direction: column; gap: 6px;
}
.item-photo img {
  width: 100%; max-height: 140px; object-fit: contain;
  border-radius: 6px; background: #fff;
}
.no-photo {
  height: 140px; background: #fff; border-radius: 6px; color: #d1d5db;
  display: flex; align-items: center; justify-content: center;
  font-size: 36px;
  border: 1px dashed #d1d5db;
}
.upload-btn {
  display: inline-block; padding: 6px 8px; background: #fff;
  border: 1px solid #d1d5db; border-radius: 6px; font-size: 12px;
  cursor: pointer; color: #4b5563; min-height: 32px;
  display: flex; align-items: center; justify-content: center;
}
.upload-btn:hover { background: #f3f4f6; }

.item-fields { flex: 1; display: flex; flex-direction: column; gap: 10px; min-width: 0; }

.field { display: flex; flex-direction: column; gap: 3px; }
.field-label { font-size: 11px; color: #6b7280; font-weight: 500; text-transform: uppercase; letter-spacing: 0.04em; }

.field-grid {
  display: grid;
  grid-template-columns: 1.6fr 1fr auto;
  gap: 10px;
  align-items: end;
}
.item-actions { display: flex; gap: 4px; padding-bottom: 2px; }
.iform { display: inline; margin: 0; }

.item-input {
  padding: 8px 10px; border: 1px solid #d1d5db; border-radius: 6px;
  font-size: 14px; background: #fff;
  min-height: 38px; width: 100%;
}
select.item-input {
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8' fill='none'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%236b7280' stroke-width='1.5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 30px;
}
.item-input.num { text-align: right; }

.specs-row { display: flex; gap: 6px; align-items: flex-start; }
.item-textarea {
  flex: 1;
  min-height: 80px;
  padding: 8px 10px;
  border: 1px solid #d1d5db; border-radius: 6px;
  font-family: inherit; font-size: 14px; line-height: 1.5;
  resize: vertical; background: #fff;
  width: 100%;
}
.rewrite-btn { flex-shrink: 0; font-size: 16px; padding: 8px 10px; }

.money-grid {
  display: grid;
  grid-template-columns: 1fr 90px 110px 110px auto auto;
  gap: 8px;
  align-items: end;
}
.money-grid .item-input { width: 100%; }
.item-sum { padding-bottom: 0; }
.sum-display {
  padding: 8px 10px;
  background: #ecfdf5;
  border: 1px solid #a7f3d0;
  border-radius: 6px;
  min-height: 38px;
  display: flex; align-items: center; justify-content: flex-end;
  font-weight: 600; color: #065f46;
  font-size: 14px;
  white-space: nowrap;
}
.show-slide { white-space: nowrap; }

/* ---- Modal ---- */
.modal {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
  padding: 16px;
}
.modal[hidden] { display: none; }
.modal-content {
  background: #fff;
  border-radius: 10px;
  padding: 20px;
  max-width: 600px;
  width: 100%;
  max-height: 90vh;
  overflow: auto;
}
.modal-content h3 { margin: 0 0 8px; }
.modal-content p.small { font-size: 13px; margin-bottom: 12px; }
.modal-actions {
  display: flex; gap: 8px; justify-content: flex-end;
  margin-top: 12px;
}

/* ---- Toast ---- */
.toast {
  position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%);
  padding: 10px 18px;
  background: #111; color: #fff; border-radius: 8px; font-size: 14px;
  opacity: 0; pointer-events: none; transition: opacity .2s;
  z-index: 1000; max-width: calc(100vw - 32px); text-align: center;
}
.toast.show { opacity: 0.95; }
.toast.error { background: #dc2626; }
.toast.ok { background: #16a34a; }

/* ============================================================ */
/*                       MOBILE BREAKPOINT                       */
/* ============================================================ */
@media (max-width: 768px) {
  body { font-size: 16px; }

  .topbar { padding: 10px 12px; }
  .topbar nav a { margin-left: 8px; font-size: 13px; }

  .page { padding: 12px; padding-bottom: 100px; }
  .page-head h1 { font-size: 20px; min-width: 100%; }
  .head-actions { width: 100%; }
  .head-actions .btn { flex: 1; }

  .meta-row {
    gap: 10px;
    padding: 12px;
  }
  .meta-label { flex: 1 1 calc(50% - 5px); min-width: 0; }
  .meta-label .meta-input { width: 100% !important; }
  .sections-toggle {
    width: 100%;
    padding-top: 8px;
    border-top: 1px solid #f0f0f0;
  }
  .total { width: 100%; text-align: right; font-size: 18px; }

  /* Section actions stack vertically on mobile */
  .section { padding: 12px; }
  .section-head { flex-direction: column; align-items: stretch; }
  .section-head h2 { font-size: 17px; }
  .section-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
  }
  .add-url-form {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 6px;
  }
  .add-url-form .url-input { width: 100%; }

  /* Items: photo on top, fields below */
  .item {
    flex-direction: column;
    gap: 10px;
  }
  .item-photo {
    width: 100%;
    flex-direction: row;
    gap: 10px;
    align-items: center;
  }
  .item-photo img, .item-photo .no-photo {
    width: 110px; height: 110px; flex-shrink: 0;
  }
  .item-photo .no-photo { font-size: 30px; }
  .upload-btn { flex: 1; }

  /* 2 rows: name+actions on top, model below */
  .field-grid {
    grid-template-columns: 1fr auto;
    grid-template-areas:
      "name actions"
      "model model";
    gap: 8px;
  }
  .field-grid .field:nth-child(1) { grid-area: name; }
  .field-grid .field:nth-child(2) { grid-area: model; }
  .field-grid .item-actions { grid-area: actions; align-self: end; padding-bottom: 4px; }

  /* Money grid: 2 cols */
  .money-grid {
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }
  .money-grid .item-sum { grid-column: 1 / -1; }
  .show-slide { grid-column: 1 / -1; padding: 6px 0; }

  .field-label { font-size: 11px; }

  /* Modal full screen on mobile */
  .modal { padding: 0; }
  .modal-content {
    max-width: 100%;
    max-height: 100%;
    height: 100%;
    border-radius: 0;
  }

  .url-input { width: 100%; }
}

/* Очень узкие экраны */
@media (max-width: 380px) {
  .field-grid { grid-template-columns: 1fr; grid-template-areas: "name" "model" "actions"; }
  .field-grid .item-actions { justify-self: end; padding: 0; }
  .head-actions { flex-direction: column; }
  .head-actions .btn { width: 100%; }
}
