/* Сметыч — мини-приложение. Цвета и шрифт строго по docs/brand.md */
@font-face { font-family: Manrope; font-weight: 400; src: url(../fonts/Manrope-Regular.ttf) format("truetype"); }
@font-face { font-family: Manrope; font-weight: 500; src: url(../fonts/Manrope-Medium.ttf) format("truetype"); }
@font-face { font-family: Manrope; font-weight: 600; src: url(../fonts/Manrope-SemiBold.ttf) format("truetype"); }
@font-face { font-family: Manrope; font-weight: 700; src: url(../fonts/Manrope-Bold.ttf) format("truetype"); }

:root {
  --graphite: #202D33;
  --teal: #24A88A;
  --mint: #DDF3EC;
  --bg: #F5F8F7;
  --muted: #718087;
  --amber: #E6A23C;
  --white: #FFFFFF;
  --border: #E1E8E6;
  --danger: #C8553D;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(32, 45, 51, .04), 0 4px 14px rgba(32, 45, 51, .05);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--graphite); }
body {
  font: 400 15px/1.45 Manrope, system-ui, sans-serif;
  padding-bottom: calc(76px + var(--safe-bottom));
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }

.top { padding: 18px 16px 6px; }
.top h1 { margin: 0; font-size: 24px; font-weight: 700; letter-spacing: -.01em; }

main { padding: 8px 16px 16px; }

/* ---------- вкладки ---------- */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: grid; grid-template-columns: repeat(3, 1fr);
  background: var(--white); border-top: 1px solid var(--border);
  padding: 6px 8px calc(6px + var(--safe-bottom));
}
.tab {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  border: 0; background: none; padding: 6px 0; border-radius: 10px;
  color: var(--muted); font-size: 12px; font-weight: 500; cursor: pointer;
}
.tab svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8;
  stroke-linecap: round; stroke-linejoin: round; }
.tab.active { color: var(--teal); }

/* ---------- элементы ---------- */
.card {
  background: var(--white); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.section-title {
  margin: 20px 2px 8px; font-size: 12px; font-weight: 600; letter-spacing: .06em;
  text-transform: uppercase; color: var(--muted);
}
.muted { color: var(--muted); }
.small { font-size: 13px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 46px; padding: 0 18px; border-radius: var(--radius);
  border: 1px solid transparent; font-weight: 600; cursor: pointer; width: 100%;
}
.btn-primary { background: var(--teal); color: var(--white); }
.btn-primary:active { filter: brightness(.95); }
.btn-secondary { background: var(--white); border-color: var(--border); color: var(--graphite); }
.btn-ghost { background: none; color: var(--teal); min-height: 40px; width: auto; padding: 0 6px; }
.btn-danger { background: none; color: var(--danger); border-color: var(--border); }
.btn[disabled] { opacity: .55; pointer-events: none; }
.row-btns { display: flex; gap: 8px; }
.row-btns .btn { flex: 1; }

.segmented {
  display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 4px;
  background: var(--white); border: 1px solid var(--border); border-radius: var(--radius);
}
.segmented button {
  border: 0; background: none; border-radius: 9px; padding: 9px 0; font-weight: 600;
  color: var(--muted); cursor: pointer;
}
.segmented button.on { background: var(--mint); color: var(--graphite); }

/* ---------- списки ---------- */
.list { overflow: hidden; }
.item {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: left;
  padding: 13px 14px; background: none; border: 0; border-top: 1px solid var(--border); cursor: pointer;
}
.item:first-child { border-top: 0; }
.item .grow { flex: 1; min-width: 0; }
.item .name { font-weight: 500; overflow-wrap: anywhere; }
.item .sub { color: var(--muted); font-size: 13px; }
.item .price { font-weight: 700; white-space: nowrap; }
.item .chev { color: var(--border); font-size: 20px; line-height: 1; }

.empty { padding: 28px 18px; text-align: center; }
.empty .icon {
  width: 52px; height: 52px; margin: 0 auto 12px; border-radius: 14px;
  background: var(--mint); display: grid; place-items: center; color: var(--teal);
}
.empty .icon svg { width: 26px; height: 26px; fill: none; stroke: currentColor; stroke-width: 1.8;
  stroke-linecap: round; stroke-linejoin: round; }
.empty h3 { margin: 0 0 4px; font-size: 17px; font-weight: 700; }
.empty p { margin: 0 0 16px; color: var(--muted); }

/* ---------- сметы ---------- */
.search {
  width: 100%; height: 46px; padding: 0 14px 0 40px; border-radius: var(--radius);
  border: 1px solid var(--border); background: var(--white) no-repeat 13px 50% / 18px
  url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23718087' stroke-width='2' stroke-linecap='round'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='m20 20-3.5-3.5'/%3E%3C/svg%3E");
  outline: none;
}
.search:focus, .field input:focus, .field select:focus, .field textarea:focus {
  border-color: var(--teal); box-shadow: 0 0 0 3px var(--mint);
}
.est { padding: 14px; margin-top: 10px; }
.est-head { display: flex; justify-content: space-between; gap: 10px; align-items: baseline; }
.est-num { font-size: 12px; font-weight: 600; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); }
.est-total { font-size: 18px; font-weight: 700; white-space: nowrap; }
.est-title { margin: 4px 0 2px; font-weight: 600; overflow-wrap: anywhere; }
.est-actions { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-top: 12px; }
.est-actions .btn { min-height: 40px; padding: 0 6px; font-size: 13px; }
.est-actions.est4 { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 359px) { .est-actions.est4 { grid-template-columns: repeat(2, 1fr); } }

/* подсказка при первом открытии экрана — тап закрывает */
.hint-tip { display: flex; gap: 10px; align-items: flex-start; width: 100%; text-align: left; padding: 12px 14px;
  margin-bottom: 12px; background: var(--mint); border-color: var(--mint); color: var(--graphite); font: inherit;
  font-size: 14px; line-height: 1.4; cursor: pointer; }
.hint-tip span:first-child { flex: 1; }
.hint-tip .x { color: var(--graphite); font-size: 14px; opacity: .7; }
.hint-tip.static { cursor: default; }
/* «доставлено клиенту»: графитовый текст (бирюзовый под текст не годится — контраст), бирюзовая метка */
.ok-text { font-weight: 600; }
.ok-text::before { content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 50%;
  background: var(--teal); margin-right: 6px; vertical-align: 1px; }
.pill.ok { box-shadow: inset 0 0 0 1px var(--teal); }

/* ---------- формы ---------- */
.form { padding: 14px; }
.field { display: block; margin-bottom: 14px; }
.field:last-child { margin-bottom: 0; }
.field > span { display: block; margin-bottom: 6px; font-size: 13px; font-weight: 500; color: var(--muted); }
.field input, .field select, .field textarea {
  width: 100%; min-height: 46px; padding: 10px 12px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--white); outline: none;
}
.field textarea { min-height: 96px; resize: vertical; }
.field .hint { margin-top: 6px; font-size: 12px; color: var(--muted); }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.logo-box { display: flex; align-items: center; gap: 14px; padding: 14px; }
.logo-prev {
  width: 64px; height: 64px; border-radius: 12px; flex: none; border: 1px dashed var(--border);
  background: var(--bg) center / contain no-repeat; display: grid; place-items: center;
  color: var(--muted); font-size: 11px; text-align: center;
}
.logo-box .grow { flex: 1; }

/* ---------- шаблон ---------- */
.tpl-row { display: grid; grid-template-columns: 1fr 108px; gap: 10px; align-items: center;
  padding: 10px 14px; border-top: 1px solid var(--border); }
.tpl-row:first-child { border-top: 0; }
.tpl-group { padding: 10px 14px 6px; background: var(--mint); color: var(--graphite); font-weight: 600;
  font-size: 13px; border-top: 1px solid var(--border); }
.tpl-group:first-child { border-top: 0; border-radius: var(--radius) var(--radius) 0 0; }
.tpl-row input { width: 100%; height: 40px; padding: 0 10px; border-radius: 10px; border: 1px solid var(--border);
  text-align: right; outline: none; }
.tpl-row input:focus { border-color: var(--teal); box-shadow: 0 0 0 3px var(--mint); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { border: 1px solid var(--border); background: var(--white); border-radius: 999px; padding: 9px 14px;
  font-weight: 600; cursor: pointer; }
.chip:active { background: var(--mint); }

.sticky-save {
  position: sticky; bottom: calc(76px + var(--safe-bottom)); padding: 12px 0 0;
  background: linear-gradient(to bottom, rgba(245, 248, 247, 0), var(--bg) 30%);
}

/* ---------- лист снизу ---------- */
.sheet { position: fixed; inset: 0; z-index: 30; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(32, 45, 51, .35); }
.sheet-body {
  position: absolute; left: 0; right: 0; bottom: 0; max-height: 88vh; overflow: auto;
  background: var(--bg); border-radius: 16px 16px 0 0; padding: 18px 16px calc(18px + var(--safe-bottom));
  box-shadow: 0 -8px 30px rgba(32, 45, 51, .12);
}
.sheet-body h2 { margin: 0 0 14px; font-size: 19px; font-weight: 700; }
.sheet-actions { display: grid; gap: 8px; margin-top: 16px; }

.toast {
  position: fixed; left: 16px; right: 16px; bottom: calc(86px + var(--safe-bottom)); z-index: 40;
  background: var(--graphite); color: var(--white); padding: 12px 14px; border-radius: var(--radius);
  box-shadow: var(--shadow); font-weight: 500;
}
.toast.warn { background: var(--amber); color: var(--graphite); }

/* ---------- объекты ---------- */
.obj { display: block; width: 100%; text-align: left; padding: 14px; margin-top: 10px; cursor: pointer; }
.obj-title { font-weight: 700; font-size: 16px; overflow-wrap: anywhere; }
.obj-meta { display: flex; justify-content: space-between; gap: 10px; margin-top: 4px; }
.pill { display: inline-block; padding: 2px 9px; border-radius: 999px; background: var(--mint); color: var(--graphite);
  font-size: 12px; font-weight: 600; }
.pill.warn { background: var(--amber); color: var(--graphite); }
.back { display: inline-flex; align-items: center; gap: 4px; margin: 0 0 6px -6px; }

/* ---------- редактор сметы ---------- */
.ed-head { padding: 14px; }
.ed-head .obj-title { font-size: 18px; }
.ed-group { padding: 9px 14px; background: var(--mint); color: var(--graphite); font-weight: 600; font-size: 13px;
  border-top: 1px solid var(--border); }
.ed-group:first-child { border-top: 0; border-radius: var(--radius) var(--radius) 0 0; }
.ed-item { display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; width: 100%; text-align: left;
  padding: 11px 14px; background: var(--white); border: 0; border-top: 1px solid var(--border); cursor: pointer; }
.ed-item:nth-of-type(even) { background: var(--bg); }
.ed-item:first-child { border-top: 0; }
.ed-name { grid-column: 1 / -1; font-weight: 500; overflow-wrap: anywhere; }
.ed-calc { color: var(--graphite); font-size: 13px; }
.ed-sum { font-weight: 700; white-space: nowrap; text-align: right; }
.ed-src { grid-column: 1 / -1; font-size: 12px; color: var(--muted); }
.ed-item.no-price { box-shadow: inset 3px 0 0 var(--amber); }
.ed-item.no-price .ed-sum { font-weight: 600; }
.ed-add { margin-top: 8px; }
.totals { padding: 14px; }
.totals .line { display: flex; justify-content: space-between; gap: 10px; padding: 3px 0; }
.totals .grand { margin: 8px -14px; padding: 12px 14px; background: var(--mint); font-weight: 700; font-size: 17px;
  border-top: 2px solid var(--teal); }
.warn-box { padding: 12px 14px; margin-top: 10px; border-left: 3px solid var(--amber); }
.seg3 { grid-template-columns: repeat(3, 1fr); }
.seg3 button { font-size: 13px; padding: 9px 4px; }

.ed-cells, .ed-thead { display: none; }
@media (min-width: 640px) {            /* широкий экран — строка таблицы: название, ед., кол-во, цена, сумма */
  .ed-item, .ed-thead { grid-template-columns: 1fr 64px 72px 100px 112px; align-items: center; }
  .ed-thead { display: grid; gap: 10px; padding: 9px 14px; background: var(--graphite); color: var(--white);
    font-size: 12px; font-weight: 600; letter-spacing: .04em; border-radius: var(--radius) var(--radius) 0 0; }
  .ed-thead span:not(:first-child) { text-align: right; }
  .ed-name { grid-column: auto; }
  .ed-calc { display: none; }
  .ed-cells { display: contents; }
  .ed-cells span { text-align: right; }
  .ed-group:first-child { border-radius: 0; }
}

.loading { padding: 40px 0; text-align: center; color: var(--muted); }
.error-box { padding: 16px; border-left: 3px solid var(--amber); }
