:root {
  --bg: #f2f5fa;
  --card: #ffffff;
  --ink: #17233a;
  --ink-soft: #5a6b85;
  --line: #dfe5ef;
  --brand: #1f3b5c;
  --brand-soft: #2b5286;
  --accent: #2f6fd0;
  --accent-soft: #eaf1fd;
  --ok: #1f8a5b;
  --ok-soft: #e6f6ee;
  --warn: #b8730a;
  --warn-soft: #fdf2e0;
  --bad: #c0392b;
  --bad-soft: #fdeceb;
  --radius: 14px;
  --shadow: 0 2px 6px rgba(23, 35, 58, .06), 0 10px 30px rgba(23, 35, 58, .05);
}

* { box-sizing: border-box; }
html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.45 "Segoe UI", system-ui, -apple-system, "Inter", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -.01em; }
.hidden { display: none !important; }

/* ------------------------------------------------------------- layout */
.app { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }

.sidebar {
  background: linear-gradient(180deg, #1f3b5c, #17293f);
  color: #e8eef8; display: flex; flex-direction: column; gap: 6px;
  padding: 20px 14px; position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 16px; }
.brand-mark { font-size: 24px; }
.brand-name { font-size: 13px; font-weight: 700; line-height: 1.25; }
.brand small { display: block; font-size: 11.5px; opacity: .7; }

#nav { display: flex; flex-direction: column; gap: 2px; flex: 0 0 auto; }
#nav a {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 10px;
  color: #cddbef; font-size: 13px; font-weight: 500; white-space: nowrap;
}
#nav a:hover { background: rgba(255, 255, 255, .07); color: #fff; }
#nav a.active { background: rgba(255, 255, 255, .14); color: #fff; }
#nav a .ico { width: 20px; text-align: center; font-size: 15px; }

.sidebar-foot { margin-top: auto; padding-top: 14px; border-top: 1px solid rgba(255,255,255,.12); }
.sidebar-foot .hint { color: #9db0cc; font-size: 11.5px; line-height: 1.4; }

.copyright {
  font-size: 10.5px; color: #7f8ea6; line-height: 1.45;
}

/* вход */
.login {
  min-height: 100vh; display: grid; place-items: center; padding: 20px;
  background: radial-gradient(1200px 600px at 20% -10%, #dce8fb, transparent), var(--bg);
}
.login-card {
  width: 100%; max-width: 380px; background: var(--card); border-radius: 20px;
  padding: 30px; box-shadow: var(--shadow); border: 1px solid var(--line);
  display: grid; gap: 12px;
}
.login-card .brand.big { display: flex; align-items: center; gap: 10px; padding: 0 0 6px; }
.login-card .brand.big .brand-mark { font-size: 26px; }
.login-card .brand.big b { display: block; font-size: 17px; }
.login-card .brand.big small {
  display: block; font-size: 11px; letter-spacing: .06em; text-transform: uppercase;
  color: var(--ink-soft);
}
.login-hint { color: var(--bad); font-size: 13px; min-height: 18px; margin: 4px 0 0; }

/* пользователь в сайдбаре */
.user-box { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.user-name {
  font-size: 12.5px; color: #e8eef8; flex: 1; min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.user-box .btn {
  padding: 5px 9px; font-size: 11.5px; color: #cddbef;
  border-color: rgba(255, 255, 255, .25); background: transparent;
}
.user-box .btn:hover { background: rgba(255, 255, 255, .12); color: #fff; }
.copyright a { color: #9db4d6; text-decoration: none; border-bottom: 1px dotted #5b6f8e; }
.copyright a:hover { color: #fff; border-bottom-color: #9db4d6; }

/* сохранённые сметы в сайдбаре */
.sidebar-saved {
  margin-top: 12px; padding-top: 12px; border-top: 1px solid rgba(255,255,255,.12);
  display: flex; flex-direction: column; min-height: 0; flex: 1 1 auto;
}
.saved-title {
  font-size: 10.5px; text-transform: uppercase; letter-spacing: .06em;
  color: #8fa6c6; padding: 0 10px 8px;
}
.saved-list { display: flex; flex-direction: column; gap: 2px; overflow-y: auto; min-height: 0; }
.saved-item {
  display: block; width: 100%; text-align: left; background: none; border: 0;
  color: #cddbef; padding: 7px 10px; border-radius: 9px; cursor: pointer; font: inherit;
}
.saved-item:hover { background: rgba(255, 255, 255, .07); color: #fff; }
.saved-item.active { background: rgba(255, 255, 255, .14); color: #fff; }
.saved-item b {
  display: block; font-size: 12.5px; font-weight: 600;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.saved-item small { display: block; font-size: 10.5px; opacity: .65; margin-top: 1px; }
.saved-empty { color: #8fa6c6; font-size: 11.5px; padding: 2px 10px; }

/* таблица сохранённых смет */
.saved-table th:nth-child(1) { width: 68px; }
.saved-table th:nth-child(2) { width: 118px; }
.saved-table th:nth-child(3) { width: 34%; }
.saved-table th:nth-child(4) { width: 148px; }
.saved-table th:nth-child(5) { width: auto; }
.saved-table th:nth-child(6) { width: 98px; }
.saved-table td.obj { font-weight: 600; }
.saved-table input.note {
  width: 100%; padding: 6px 9px; border: 1px solid var(--line); border-radius: 8px;
  font: 13px "Segoe UI", Arial, sans-serif; color: var(--ink); background: #fff;
}
.saved-table input.note:focus { outline: 2px solid #b9d1f5; border-color: var(--accent); }
.saved-empty-row { padding: 34px 10px; text-align: center; color: var(--ink-soft); font-size: 13.5px; }
.mono { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 12px; padding: 16px 26px;
  background: rgba(255, 255, 255, .85); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20;
}
.topbar h1 { font-size: 20px; }
.topbar select {
  padding: 8px 11px; border: 1px solid var(--line); border-radius: 10px;
  background: #fff; font: inherit; font-size: 13.5px; color: var(--ink); max-width: 340px;
}
.topbar-actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.view { padding: 20px 22px 60px; display: grid; gap: 16px; align-content: start; min-width: 0; }

/* ------------------------------------------------------------- buttons */
.btn {
  appearance: none; border: 1px solid var(--line); background: #fff; color: var(--ink);
  padding: 9px 14px; border-radius: 10px; font: inherit; font-weight: 550; cursor: pointer;
  display: inline-flex; align-items: center; gap: 7px; transition: .15s; white-space: nowrap;
}
.btn:hover { border-color: #c3cee0; background: #f8fafd; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: #2a63ba; }
.btn.ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn.danger { color: var(--bad); border-color: #f0cdc9; }
.btn.danger:hover { background: var(--bad-soft); }
.btn.ghost { background: transparent; }
.btn.small { padding: 6px 10px; font-size: 13px; border-radius: 9px; }
.btn.wide { width: 100%; justify-content: center; }
.btn.big { padding: 11px 18px; font-size: 14px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ------------------------------------------------------------- fields */
.field { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--ink-soft); }
.field span { font-weight: 600; color: var(--ink-soft); }
.field input, .field select, .field textarea {
  font: inherit; color: var(--ink); padding: 9px 11px; border: 1px solid var(--line);
  border-radius: 10px; background: #fff; width: 100%;
}
.field input:focus, .field select:focus, .field textarea:focus, .btn:focus-visible {
  outline: 2px solid #b9d1f5; outline-offset: 1px; border-color: var(--accent);
}
.field textarea { min-height: 62px; resize: vertical; }
.field.grow { flex: 1 1 320px; }
.row { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; }

/* ------------------------------------------------------------- cards */
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 18px; min-width: 0;
}
.card-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.card-head h2 { font-size: 16px; }
.card-head .right { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }
.muted { color: var(--ink-soft); font-size: 13px; margin: 0 0 12px; }

/* ------------------------------------------------------------- chips / stats */
.stats { display: flex; gap: 6px; flex-wrap: wrap; margin-left: auto; }
.chip {
  border: 1px solid var(--line); background: #fff; border-radius: 20px;
  padding: 5px 12px; font-size: 12.5px; color: var(--ink-soft);
}
.chip.ok { background: var(--ok-soft); color: var(--ok); border-color: #bfe3c8; }
.chip.warn { background: var(--warn-soft); color: var(--warn); border-color: #f0d9a8; }
.chip.bad { background: var(--bad-soft); color: var(--bad); border-color: #f2c7c1; }

/* ------------------------------------------------------------- tables */
.table-wrap {
  overflow: auto; max-height: 62vh; border-radius: var(--radius);
  border: 1px solid var(--line); background: #fff; max-width: 100%;
}
.table-wrap.small { max-height: 40vh; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; }
th {
  font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-soft);
  background: #f8fafd; font-weight: 650; position: sticky; top: 0; z-index: 3; white-space: nowrap;
}

/* ширины колонок сметы */
#itemsTable { table-layout: fixed; min-width: 980px; }
#itemsTable th { white-space: normal; line-height: 1.2; }
#itemsTable th, #itemsTable td { padding: 8px 9px; }
#itemsTable th:nth-child(2) { width: 84px; }
#itemsTable th:nth-child(3) { width: auto; }
#itemsTable th:nth-child(4) { width: 44px; }
#itemsTable th:nth-child(5) { width: 76px; }
#itemsTable th:nth-child(6) { width: 96px; }
#itemsTable th:nth-child(7) { width: 92px; }
#itemsTable th:nth-child(8) { width: 172px; }
#itemsTable th:nth-child(9) { width: 84px; }
#itemsTable th:nth-child(10) { width: 34px; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fafcff; }
td.r, th.r { text-align: right; }
td.c, th.c { text-align: center; }
td.num, th.num { width: 42px; color: var(--ink-soft); text-align: right; }

td input.qty, td input.norm, td input.wq {
  width: 84px; padding: 6px 8px; text-align: right; font: inherit; font-size: 13px;
  border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--ink);
}
td input.qty:focus, td input.wq:focus { outline: 2px solid #b9d1f5; border-color: var(--accent); }

.name-cell { max-width: 520px; }
.name-cell .brand { color: var(--ink-soft); font-size: 11.5px; padding: 0; font-weight: 400; }

/* ------------------------------------------------------------- badges */
.badge {
  display: inline-flex; align-items: center; gap: 5px; padding: 3px 9px; border-radius: 20px;
  font-size: 12px; font-weight: 650; white-space: nowrap;
}
.badge.auto { background: var(--accent-soft); color: var(--brand-soft); }
.badge.saved { background: var(--ok-soft); color: var(--ok); }
.badge.manual { background: var(--warn-soft); color: var(--warn); }
.badge.consumable { background: #eef0f6; color: #6b7791; }
.badge.none { background: var(--bad-soft); color: var(--bad); }

/* ------------------------------------------------------------- upload */
.dropzone {
  display: flex; align-items: center; gap: 12px; padding: 16px; margin-bottom: 14px;
  border: 1.5px dashed #b9c6da; border-radius: 12px; background: #fbfcfe; transition: .15s;
}
.dropzone.over { border-color: var(--accent); background: var(--accent-soft); }
.msg { margin-top: 10px; font-size: 13px; }
.msg.err { color: var(--bad); }
.msg.ok { color: var(--ok); }

/* ------------------------------------------------------------- work distribution */
.works-cell { white-space: nowrap; }
.wt {
  display: inline-flex; align-items: center; gap: 6px;
  background: none; border: none; padding: 2px 4px; cursor: pointer;
  font: 13px "Segoe UI", Arial, sans-serif; color: var(--brand-soft);
}
.wt:hover { color: var(--accent); }
.wt .chev { display: inline-block; transition: transform .15s; font-size: 10px; color: #8a97a8; }
tr.open .wt .chev { transform: rotate(90deg); }
.wt .cnt { font-variant-numeric: tabular-nums; }
.mark { font-weight: 700; }
.mark.ok { color: var(--ok); }
.mark.bad { color: var(--bad); }
.works-none { color: var(--ink-soft); font-size: 12px; }

tr.sub-row > td { background: #fff !important; border-bottom: 1px solid var(--line); padding: 0; }
tr.sub-row:hover > td { background: #fff !important; }

.works-panel {
  margin: 2px 10px 10px 34px; padding: 8px 12px 6px;
  background: #f7faff; border-left: 3px solid var(--accent); border-radius: 0 10px 10px 0;
}
.work-line {
  display: flex; align-items: center; gap: 10px; padding: 5px 0;
  border-bottom: 1px dashed #e3e9f3;
}
.work-line:last-of-type { border-bottom: none; }
.work-line .nm { flex: 1; font-size: 13px; }
.work-line .un { width: 26px; color: var(--ink-soft); font-size: 12px; }
.work-line .wdel {
  border: none; background: none; color: var(--bad); font-size: 16px;
  line-height: 1; cursor: pointer; padding: 0 4px; border-radius: 6px;
}
.work-line .wdel:hover { background: var(--bad-soft); }
.works-foot {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  margin-top: 6px; padding-top: 6px; border-top: 1px dashed #dde4ef;
}
.add-work {
  border: 1px dashed #b9c6da; background: #fff; border-radius: 8px;
  padding: 5px 11px; font: 12.5px "Segoe UI", Arial, sans-serif; color: var(--brand-soft); cursor: pointer;
}
.add-work:hover { border-color: var(--accent); color: var(--accent); }
.balance { font-size: 11.5px; color: var(--ink-soft); }
.balance.ok { color: var(--ok); }
.balance.bad { color: var(--bad); }

.work-search { margin-top: 8px; }
.work-search input {
  width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 9px;
  font: 13px "Segoe UI", Arial, sans-serif;
}
.work-search-list {
  margin-top: 6px; background: #fff; border: 1px solid var(--line); border-radius: 10px;
  max-height: 260px; overflow: auto; box-shadow: var(--shadow);
}
.work-opt {
  display: flex; justify-content: space-between; gap: 12px; align-items: center;
  padding: 8px 11px; font-size: 13px; cursor: pointer; border-bottom: 1px solid #f0f3f8;
}
.work-opt:last-child { border-bottom: none; }
.work-opt:hover { background: var(--accent-soft); }
.wo-meta { color: var(--ink-soft); font-size: 11.5px; white-space: nowrap; }

.warning-bar {
  display: flex; align-items: center; gap: 10px;
  background: var(--bad-soft); border: 1px solid #f2c7c1; border-radius: 12px;
  padding: 11px 14px; margin: 4px 0 14px; font-size: 13.5px; color: #7a2019;
}
.warning-bar .btn { margin-left: auto; }

/* ------------------------------------------------------------- material search */
.mat-add { position: relative; margin-bottom: 14px; }
.ac-list {
  position: absolute; left: 0; right: 0; top: 100%; z-index: 30; margin-top: 6px;
  background: #fff; border: 1px solid var(--line); border-radius: 12px;
  box-shadow: var(--shadow); max-height: 320px; overflow: auto;
}
.ac-item { padding: 9px 12px; cursor: pointer; border-bottom: 1px solid #f0f3f8; }
.ac-item:last-child { border-bottom: none; }
.ac-item:hover { background: var(--accent-soft); }
.ac-name { font-size: 13px; }
.ac-meta { font-size: 11.5px; color: var(--ink-soft); margin-top: 2px; }
.ac-empty { padding: 12px; font-size: 13px; color: var(--ink-soft); }

/* ------------------------------------------------------------- extras */
.big-actions { display: flex; gap: 10px; flex-wrap: wrap; margin: 6px 0 14px; justify-content: flex-start; }
.big-actions .btn { padding: 11px 18px; font-size: 13.5px; font-weight: 600; }

table.extras-table { font-size: 13px; table-layout: fixed; }
table.extras-table th:nth-child(1) { width: 44%; }
table.extras-table th:nth-child(2) { width: 9%; }
table.extras-table th:nth-child(3) { width: 10%; }
table.extras-table th:nth-child(4) { width: 13%; }
table.extras-table th:nth-child(5) { width: 14%; }
table.extras-table th:nth-child(6) { width: 6%; }
table.extras-table input {
  width: 100%; padding: 6px 8px; border: 1px solid var(--line); border-radius: 8px;
  font: 13px "Segoe UI", Arial, sans-serif; color: var(--ink); background: #fff;
}
table.extras-table input.ex-unit,
table.extras-table input.ex-qty,
table.extras-table input.ex-price { text-align: right; }

/* ------------------------------------------------------------- totals */
.params {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px; margin: 4px 0 16px;
}
.totals { border-top: 1px solid var(--line); }
.total-row {
  display: flex; justify-content: space-between; gap: 16px;
  padding: 9px 2px; border-bottom: 1px solid #eef1f6; font-size: 14px;
}
.total-row .label { color: var(--ink-soft); }
.total-row .value { font-variant-numeric: tabular-nums; white-space: nowrap; }
.total-row.strong {
  font-weight: 700; color: var(--ink); background: #f8fafd;
  padding: 10px 12px; border-radius: 10px; margin: 6px 0; border: none;
}
.total-row.grand {
  font-size: 17px; font-weight: 750; color: var(--brand);
  border-top: 2px solid var(--brand); margin-top: 4px; padding-top: 12px;
}

.actions { display: flex; gap: 10px; margin-top: 18px; flex-wrap: wrap; }

/* ------------------------------------------------------------- info grid */
.info-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 12px; margin-bottom: 12px;
}
.info-grid .field.wide { grid-column: span 2; }
@media (max-width: 900px) { .info-grid .field.wide { grid-column: auto; } }

/* ------------------------------------------------------------- catalog pages */
.catalog-toolbar {
  display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; margin-bottom: 14px;
}
.catalog-toolbar .field { min-width: 180px; }
.catalog-table { table-layout: fixed; }
.catalog-table th:nth-child(1) { width: 64px; }
.catalog-table th:nth-child(2) { width: 30%; }
.catalog-table th:nth-child(3) { width: auto; }
.catalog-table th:nth-child(4) { width: 86px; }
.catalog-table th:nth-child(5) { width: 100px; }
.catalog-table th:nth-child(6) { width: 92px; }
.catalog-table input {
  width: 100%; padding: 6px 8px; border: 1px solid var(--line); border-radius: 8px;
  font: 12.5px "Segoe UI", Arial, sans-serif; color: var(--ink); background: #fff;
}
.catalog-table input.price { text-align: right; font-weight: 600; }
.catalog-table tr.archived td { opacity: .45; }
.catalog-table .section-cell { color: var(--ink-soft); font-size: 12px; }

.materials-table th:nth-child(1) { width: 92px; }
.materials-table th:nth-child(2) { width: 160px; }
.materials-table th:nth-child(3) { width: auto; }
.materials-table th:nth-child(4) { width: 110px; }
.materials-table th:nth-child(5) { width: 64px; }
.materials-table th:nth-child(6) { width: 92px; }
.materials-table th:nth-child(7) { width: 90px; }
.materials-table td.num input { font-size: 12px; color: var(--ink-soft); }

.add-grid {
  display: grid; grid-template-columns: 190px minmax(240px, 1fr) 150px 70px 110px 150px auto;
  gap: 10px; align-items: end;
}

.check {
  display: flex; align-items: center; gap: 8px; padding: 8px 0;
  font-size: 13px; color: var(--ink-soft); cursor: pointer; user-select: none;
}
.check input { width: 16px; height: 16px; accent-color: var(--brand); }

.row-del {
  border: none; background: transparent; color: var(--bad); font-size: 18px; line-height: 1;
  cursor: pointer; padding: 2px 7px; border-radius: 7px;
}
.row-del:hover { background: var(--bad-soft); }

/* ------------------------------------------------------------- works block */
.works-block { margin-top: 14px; }
.works-block summary {
  cursor: pointer; font-weight: 600; color: var(--brand-soft);
  padding: 8px 0; font-size: 13.5px;
}

/* ------------------------------------------------------------- планшеты */
@media (max-width: 1080px) {
  .app { grid-template-columns: 1fr; align-content: start; }
  .sidebar { align-self: start; }
  .sidebar {
    position: sticky; top: 0; z-index: 30; height: auto; max-width: 100vw;
    flex-direction: row; align-items: center; flex-wrap: nowrap; overflow: hidden;
    gap: 8px; padding: 8px 10px;
  }
  .brand { padding: 0; flex: 0 0 auto; }
  .brand-mark { font-size: 20px; }
  .brand-name { font-size: 12px; }
  #nav {
    flex-direction: row; flex-wrap: nowrap; gap: 4px;
    flex: 1 1 auto; min-width: 0; overflow-x: auto; scrollbar-width: none;
  }
  #nav::-webkit-scrollbar { display: none; }
  #nav a { padding: 8px 10px; font-size: 13px; white-space: nowrap; }
  .sidebar-saved { display: none; }
  .sidebar-foot {
    display: flex; align-items: center; gap: 8px; flex: 0 0 auto;
    margin-top: 0; padding-top: 0; border-top: 0;
  }
  .copyright { display: none; }
  .user-name { max-width: 120px; }
  .view { padding: 14px 12px 60px; }
  .topbar { padding: 12px 14px; }
  .topbar h1 { font-size: 17px; }
  .add-grid { grid-template-columns: 1fr 1fr; }
  .add-grid .btn { grid-column: span 2; }
  .table-wrap { max-height: none; }
}

/* ------------------------------------------------------------- телефоны и планшеты-портрет */
@media (max-width: 900px) {
  /* iOS не увеличивает страницу при фокусе в поле */
  input, select, textarea, .field input, .field select, .field textarea { font-size: 16px; }
  .view { padding: 10px 10px 70px; gap: 12px; }
  .card { padding: 14px 12px; }
  .card-head { gap: 8px; }
  .card-head h2 { font-size: 15px; }
  .muted { font-size: 12.5px; }
  .stats { margin-left: 0; width: 100%; }
  .chip { font-size: 11.5px; padding: 4px 9px; }

  .sidebar { padding: 8px 10px; gap: 8px; }
  .brand-name { display: none; }
  #nav a { font-size: 12.5px; padding: 7px 9px; }
  #nav a .ico { font-size: 14px; }
  .user-name { display: none; }
  .sidebar-foot .btn { padding: 6px 10px; font-size: 12px; }

  .topbar { flex-wrap: wrap; gap: 6px; }
  .topbar h1 { font-size: 16px; }
  .topbar-actions { width: 100%; margin-left: 0; }
  .topbar-actions .chip {
    max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  }

  /* --- смета: каждая позиция — карточка --- */
  #itemsTable { min-width: 0; table-layout: auto; }
  #itemsTable thead { display: none; }
  #itemsTable tbody, #itemsTable tr, #itemsTable td { display: block; width: auto; }
  #itemsTable tr.item-row {
    position: relative; display: flex; flex-wrap: wrap; align-items: baseline;
    background: #fff; border: 1px solid var(--line);
    border-radius: 12px; padding: 10px 42px 12px 12px; margin-bottom: 8px;
  }
  #itemsTable tr.item-row:hover { background: #fff; }
  #itemsTable td { border: 0; padding: 0; }
  #itemsTable td:nth-child(1) { display: none; }
  #itemsTable td:nth-child(2) {
    order: 0; font-size: 11px; color: var(--ink-soft); margin-right: 8px;
  }
  #itemsTable td:nth-child(4) {
    order: 0; margin-left: auto; font-size: 11.5px; color: var(--ink-soft);
  }
  #itemsTable td:nth-child(3) {
    order: 1; flex: 1 0 100%; max-width: none; font-size: 14.5px; font-weight: 600;
    line-height: 1.3; margin: 2px 0 8px;
  }
  #itemsTable td:nth-child(3) .brand { font-size: 11px; font-weight: 400; }
  #itemsTable td:nth-child(5),
  #itemsTable td:nth-child(6),
  #itemsTable td:nth-child(7) {
    order: 2; display: flex; align-items: center; gap: 5px;
    font-size: 12.5px; margin-right: 10px; margin-bottom: 4px;
  }
  #itemsTable td:nth-child(5)::before { content: "Кол-во"; color: var(--ink-soft); font-size: 11.5px; }
  #itemsTable td:nth-child(6)::before { content: "цена"; color: var(--ink-soft); font-size: 11.5px; }
  #itemsTable td:nth-child(7)::before { content: "сумма"; color: var(--ink-soft); font-size: 11.5px; }
  #itemsTable td:nth-child(7) { font-weight: 700; }
  #itemsTable td input.qty { width: 74px; padding: 5px 7px; }
  #itemsTable td:nth-child(8) { order: 3; flex: 1 0 100%; margin-top: 4px; }
  #itemsTable td.works-cell { white-space: normal; }
  #itemsTable td:nth-child(9) { order: 4; margin-top: 6px; }
  #itemsTable td:nth-child(10) { position: absolute; top: 4px; right: 4px; }
  #itemsTable .row-del { font-size: 20px; padding: 4px 9px; }

  /* раскрытая панель работ */
  #itemsTable tr.sub-row {
    border: 1px solid var(--line); border-top: 0; border-radius: 0 0 12px 12px;
    margin: -9px 0 10px; overflow: hidden; background: #fff;
  }
  #itemsTable tr.sub-row td { padding: 0; }
  #itemsTable .works-panel {
    margin: 0; border-left: 0; border-radius: 0; padding: 10px 12px 8px;
  }
  #itemsTable .work-line { flex-wrap: wrap; gap: 6px; padding: 6px 0; }
  #itemsTable .work-line .nm { flex: 1 0 100%; font-size: 12.5px; }
  #itemsTable .work-line .wq { width: 92px; margin-left: auto; }
  #itemsTable .works-foot { flex-wrap: wrap; gap: 8px; }
  #itemsTable .balance { font-size: 11px; }

  /* --- сохранённые сметы --- */
  .saved-table thead { display: none; }
  .saved-table tbody, .saved-table tr, .saved-table td { display: block; width: auto; }
  .saved-table tr {
    border: 1px solid var(--line); border-radius: 12px;
    padding: 10px 12px; margin-bottom: 8px; background: #fff;
  }
  .saved-table td { border: 0; padding: 0; }
  .saved-table td.num { display: none; }
  .saved-table td.mono {
    display: inline-block; font-size: 11.5px; color: var(--ink-soft); margin-right: 8px;
  }
  .saved-table td.obj { font-size: 14px; margin: 2px 0 4px; }
  .saved-table td.nowrap { font-size: 11.5px; color: var(--ink-soft); margin-bottom: 8px; }
  .saved-table td:nth-child(5) { margin-bottom: 8px; }
  .saved-table td:nth-child(6) { text-align: left; }
  .saved-table td:nth-child(6) .btn { width: 100%; justify-content: center; }

  /* --- справочники: строки как карточки --- */
  .catalog-table thead, .materials-table thead { display: none; }
  .catalog-table tbody, .catalog-table tr, .catalog-table td,
  .materials-table tbody, .materials-table tr, .materials-table td { display: block; width: auto; }
  .catalog-table tr, .materials-table tr {
    border: 1px solid var(--line); border-radius: 12px;
    padding: 10px 12px; margin-bottom: 8px; background: #fff;
  }
  .catalog-table td, .materials-table td { border: 0; padding: 0; margin-bottom: 6px; }
  .catalog-table td input, .materials-table td input { width: 100%; padding: 7px 9px; }

  .catalog-table td:nth-child(1), .materials-table td:nth-child(1) {
    font-size: 11.5px; color: var(--ink-soft); text-align: left;
  }
  .catalog-table td:nth-child(2), .materials-table td:nth-child(2) {
    font-size: 11.5px; color: var(--ink-soft); text-align: left;
  }
  .catalog-table td:nth-child(3), .materials-table td:nth-child(3) { margin: 2px 0 6px; }
  .materials-table td:nth-child(4) { margin-bottom: 6px; }
  .catalog-table:not(.materials-table) td:nth-child(4),
  .catalog-table:not(.materials-table) td:nth-child(5),
  .materials-table td:nth-child(5),
  .materials-table td:nth-child(6) {
    display: inline-block; width: 48%; vertical-align: top; margin-bottom: 8px;
  }
  .catalog-table:not(.materials-table) td:nth-child(5),
  .materials-table td:nth-child(6) { margin-left: 3%; }
  .materials-table td:nth-child(4) { display: block; width: auto; margin-bottom: 6px; }
  .catalog-table td:nth-child(6) .btn,
  .materials-table td:nth-child(7) .btn { width: 100%; justify-content: center; }

  /* --- работы в смете: горизонтальная прокрутка --- */
  .works-block table { min-width: 560px; }
  .works-block .table-wrap { overflow-x: auto; }

  /* --- транспорт и ПИР: карточки --- */
  .extras-table { min-width: 0; table-layout: auto; }
  .extras-table thead { display: none; }
  .extras-table tbody, .extras-table tr, .extras-table td { display: block; width: auto; }
  .extras-table tr {
    border: 1px solid var(--line); border-radius: 12px;
    padding: 10px 12px; margin-bottom: 8px; background: #fff;
  }
  .extras-table td { border: 0; padding: 0; margin-bottom: 6px; }
  .extras-table td:nth-child(2), .extras-table td:nth-child(3) {
    display: inline-block; width: 30%; vertical-align: top;
  }
  .extras-table td:nth-child(4) {
    display: inline-block; width: 36%; vertical-align: top;
  }
  .extras-table td:nth-child(5) {
    display: inline-block; font-weight: 700; margin-right: 10px;
  }
  .extras-table td:nth-child(5)::before {
    content: "сумма "; font-weight: 400; font-size: 11.5px; color: var(--ink-soft);
  }
  .extras-table td:nth-child(6) { display: inline-block; }

  /* --- формы --- */
  .info-grid { grid-template-columns: 1fr; }
  .params { grid-template-columns: 1fr 1fr; }
  .big-actions { flex-direction: column; }
  .big-actions .btn, .actions .btn { width: 100%; justify-content: center; }
  .catalog-toolbar { flex-direction: column; align-items: stretch; }
  .catalog-toolbar .field { min-width: 0; }
  .add-grid { grid-template-columns: 1fr; }
  .add-grid .btn { grid-column: auto; width: 100%; justify-content: center; }
  .dropzone { flex-direction: column; align-items: stretch; gap: 8px; }
  .field.grow { flex: 0 0 auto; }
  .row { flex-direction: column; align-items: stretch; }
  .row .btn { width: 100%; justify-content: center; }
  .mat-add .ac-list { max-height: 50vh; }
  .total-row { font-size: 13.5px; }
  .total-row.grand { font-size: 15.5px; }
}

