:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --text: #181c23;
  --muted: #667085;
  --line: #d9dee7;
  --primary: #1769ff;
  --primary-dark: #0f4fd1;
  --danger: #c62828;
  --success: #1d7a43;
  --shadow: 0 16px 40px rgba(15, 23, 42, 0.08);
  --radius: 18px;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
}
.hidden { display: none !important; }

:focus-visible { outline: 2px solid rgba(23, 105, 255, 0.45); outline-offset: 2px; }
.muted { color: var(--muted); }
.eyebrow { font-size: 12px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }
button, input, select, textarea { font: inherit; }
button {
  cursor: pointer;
  border: none;
  border-radius: 12px;
  padding: 12px 16px;
  transition: background-color 0.22s ease, color 0.22s ease, border-color 0.22s ease, box-shadow 0.22s ease;
}
button:disabled { cursor: not-allowed; opacity: 0.55; }
button.primary { background: var(--primary); color: white; }
button.primary:not(:disabled):hover { background: var(--primary-dark); color: white; }
button.secondary { background: #e8eefc; color: #183b80; }
button.secondary:not(:disabled):hover { background: #d4e1fb; color: #102f68; }
button.ghost { background: transparent; color: var(--text); }
button.ghost:not(:disabled):hover { background: #e7ebf1; color: #10141b; }
button.danger { background: #fee7e7; color: #9d1c1c; }
button.danger:not(:disabled):hover { background: #f9cccc; color: #7d1212; }
button.small { padding: 8px 10px; }
button.icon-btn { width: 44px; height: 44px; padding: 0; font-size: 22px; }
.auth-overlay {
  min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px;
  background: linear-gradient(135deg, #dee9ff, #f6f7fb 55%, #e9fff3);
}
.auth-card, .card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); }
.auth-card {
  width: min(420px, 100%); padding: 28px; display: grid; gap: 16px;
}
.auth-card label, .form-grid label, .line-form label, .inline-form label {
  display: grid; gap: 6px; font-size: 14px;
}
input, select, textarea, .input-like {
  border: 1px solid var(--line); border-radius: 12px; background: white; padding: 11px 12px;
}
select {
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns=\"http://www.w3.org/2000/svg\" width=\"12\" height=\"12\" viewBox=\"0 0 12 12\" fill=\"none\"%3E%3Cpath d=\"M2.25 4.5L6 8.25L9.75 4.5\" stroke=\"%23667085\" stroke-width=\"1.5\" stroke-linecap=\"round\" stroke-linejoin=\"round\"/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 38px;
}
.form-error { min-height: 20px; color: var(--danger); font-size: 14px; }
.auth-badge { display: inline-flex; width: fit-content; padding: 6px 10px; border-radius: 999px; background: #edf3ff; color: #244a92; font-weight: 600; }
.shell { min-height: 100vh; }
.topbar {
  display: flex; justify-content: space-between; align-items: center; gap: 16px;
  padding: 18px 24px; background: white; border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20;
}
.topbar h1 { margin: 2px 0 0; font-size: 28px; }
.topbar-left, .topbar-actions, .toolbar-actions { display: flex; align-items: center; gap: 12px; }
.user-badge { display: grid; padding: 8px 12px; border-radius: 12px; background: #f7f9fd; font-size: 12px; }
.main-shell { padding: 20px 24px 24px; }
.view-panel { display: block; }
.view-toolbar {
  display: grid; gap: 16px; margin-bottom: 16px;
}
.tabs { display: flex; flex-wrap: wrap; gap: 8px; }
.tab { background: #eef2f8; color: #314055; }
.tab:not(:disabled):hover { background: #dde5f0; color: #1f2e42; }
.tab.active { background: #dbe8ff; color: #1549ab; font-weight: 700; }
.tab.active:not(:disabled):hover { background: #c9dcff; color: #103f96; }
.search-input { min-width: 260px; }
.inline-checkbox, .form-grid label.inline-checkbox, .line-form label.inline-checkbox, .inline-form label.inline-checkbox { display: inline-flex; align-items: center; gap: 8px; font-size: 14px; color: var(--muted); }
.inline-checkbox input { margin: 0; }
.split-layout { display: grid; grid-template-columns: 380px 1fr; gap: 16px; align-items: start; }
.estimates-layout { grid-template-columns: 360px 1fr; }
.card { padding: 18px; }
.section-head { display: flex; justify-content: space-between; gap: 16px; align-items: flex-start; margin-bottom: 16px; }
.section-head.compact h2 { margin: 0 0 6px; font-size: 22px; }
.wrap-between { flex-wrap: wrap; }
.list { display: grid; gap: 10px; max-height: calc(100vh - 220px); overflow: auto; }
.list-item {
  border: 1px solid var(--line); border-radius: 14px; padding: 12px; background: white; display: grid; gap: 6px;
}
button.list-item:not(:disabled):hover { background: #f2f6ff; border-color: #a9c3f2; color: var(--text); }
.list-item.active { border-color: var(--primary); box-shadow: 0 0 0 2px rgba(23, 105, 255, 0.12); }
button.list-item.active:not(:disabled):hover { background: #eaf1ff; border-color: var(--primary); }
.list-item-meta { font-size: 12px; color: var(--muted); display: flex; gap: 8px; flex-wrap: wrap; }
.badge { display: inline-flex; padding: 4px 8px; border-radius: 999px; background: #eef2f8; font-size: 12px; }
.badge.success { background: #e2f7e9; color: var(--success); }
.badge.warning { background: #fff3d9; color: #8a5600; }
.badge.danger { background: #fee7e7; color: var(--danger); }
.detail-pane { min-height: 600px; }
.form-grid { display: grid; gap: 12px; }
.form-grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 16px; }
.related-block { margin-top: 18px; border-top: 1px solid var(--line); padding-top: 16px; }
.related-block h3 { margin: 0 0 10px; font-size: 16px; }
.stack { display: grid; }
.gap-s { gap: 8px; }
.gap-m { gap: 12px; }
.no-wrap { flex-wrap: nowrap; }
.wrap { flex-wrap: wrap; }
.empty-state {
  min-height: 420px; display: grid; place-content: center; text-align: center; gap: 12px; color: var(--muted);
}
.menu-drawer {
  position: fixed; inset: 0; background: rgba(15, 23, 42, 0.35); display: flex; justify-content: flex-end; z-index: 40;
  opacity: 0; pointer-events: none; transition: opacity 0.24s ease;
}
.menu-drawer.is-open { opacity: 1; pointer-events: auto; }
.menu-drawer-card {
  width: min(320px, 92vw); background: white; padding: 18px; display: grid; align-content: start; gap: 14px; box-shadow: var(--shadow);
  transform: translateX(28px); transition: transform 0.24s ease;
}
.menu-drawer.is-open .menu-drawer-card { transform: translateX(0); }
.menu-header { display: flex; justify-content: space-between; align-items: center; }
.menu-link { text-align: left; background: #f3f6fb; color: var(--text); width: min(220px, 100%); justify-self: start; padding: 18px 16px; }
.menu-link:not(:disabled):hover { background: #dfe7f3; color: #14233a; }
.side-panel {
  position: fixed; top: 0; right: 0; width: min(460px, 100vw); height: 100vh; background: white; box-shadow: var(--shadow); z-index: 45;
  display: grid; grid-template-rows: auto 1fr; opacity: 0; pointer-events: none; transform: translateX(32px); transition: transform 0.24s ease, opacity 0.24s ease;
}
.side-panel.is-open { opacity: 1; pointer-events: auto; transform: translateX(0); }
.side-panel-header { display: flex; justify-content: space-between; align-items: start; gap: 12px; padding: 18px; border-bottom: 1px solid var(--line); }
.side-panel-body { padding: 18px; overflow: auto; }
.estimate-search-block { display: grid; gap: 10px; }
.estimate-search-input { width: 100%; min-width: 0; }
.estimate-create-btn { width: fit-content; }
.estimate-status-filter { min-width: 170px; }
.estimate-filters-row { align-items: center; }
.line-form, .inline-form { display: grid; gap: 12px; }
.inline-form { grid-template-columns: repeat(4, minmax(0, 1fr)); align-items: end; }
.inline-form button { min-height: 44px; }
.note-box { padding: 12px; border-radius: 12px; background: #f6f8fc; color: var(--muted); font-size: 14px; }
.estimate-groups { display: grid; gap: 18px; }
.estimate-section { border: 1px solid var(--line); border-radius: 18px; padding: 14px; background: #fbfcff; }
.estimate-section h3 { margin: 0; }
.estimate-subtitle { margin: 10px 0 8px; color: var(--muted); font-weight: 700; }
.table-like { width: 100%; border-collapse: collapse; }
.table-like th, .table-like td { border-bottom: 1px solid var(--line); padding: 10px 8px; text-align: left; font-size: 14px; vertical-align: top; }
.table-like th { color: var(--muted); font-size: 12px; text-transform: uppercase; }
.line-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.summary-row { display: flex; justify-content: flex-end; margin-top: 10px; font-weight: 700; }
@media (max-width: 1100px) {
  .split-layout, .estimates-layout { grid-template-columns: 1fr; }
  .detail-pane { min-height: 0; }
  .list { max-height: none; }
}
@media (max-width: 760px) {
  .topbar { padding: 14px 16px; }
  .main-shell { padding: 16px; }
  .form-grid.two, .inline-form { grid-template-columns: 1fr; }
  .search-input { min-width: 0; width: 100%; }
  .toolbar-actions { flex-wrap: wrap; }
  .menu-link { width: 100%; }
  .estimate-create-btn { width: 100%; }
}


.inline-warning {
  margin-top: -6px;
  margin-bottom: 4px;
  padding: 10px 12px;
  border-radius: 12px;
  background: #fff4d6;
  color: #7a5a00;
  font-size: 14px;
  line-height: 1.35;
}

.estimate-parties { margin: 4px 0 18px; }
.estimate-parties-card {
  border: 1px solid var(--line);
  border-radius: 16px;
  background: #f8faff;
  padding: 14px;
  display: grid;
  gap: 10px;
}
.estimate-parties-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  flex-wrap: wrap;
}
.estimate-parties-head h3 { margin: 0 0 4px; }
.estimate-parties-head p { margin: 0; font-size: 13px; }
.estimate-party-row {
  display: grid;
  grid-template-columns: minmax(120px, 150px) 1fr;
  gap: 12px;
  align-items: start;
  padding: 10px 0;
  border-top: 1px solid #e5eaf2;
}
.party-role-tooltip {
  position: relative;
  display: inline-flex;
  width: fit-content;
  font-weight: 700;
  color: #204a96;
  cursor: help;
  border-bottom: 1px dashed #7d9bcf;
}
.party-tooltip {
  position: absolute;
  left: 0;
  top: calc(100% + 10px);
  z-index: 60;
  width: min(390px, 80vw);
  max-height: 420px;
  overflow: auto;
  padding: 12px;
  border: 1px solid #cdd7e8;
  border-radius: 14px;
  background: white;
  color: var(--text);
  box-shadow: 0 18px 44px rgba(15, 23, 42, 0.18);
  opacity: 0;
  visibility: hidden;
  transform: translateY(-4px);
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease, visibility 0.18s ease;
}
.party-role-tooltip:hover .party-tooltip,
.party-role-tooltip:focus-visible .party-tooltip {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}
.party-tooltip-card { display: grid; gap: 4px; font-size: 13px; line-height: 1.4; }
.party-tooltip-card + .party-tooltip-card { border-top: 1px solid var(--line); margin-top: 10px; padding-top: 10px; }
.party-tooltip-card strong { font-size: 14px; margin-bottom: 2px; }
.party-tooltip-card div span { color: var(--muted); }
.party-name-list { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.party-name-chip {
  display: inline-flex;
  padding: 6px 9px;
  border-radius: 999px;
  background: #e8eefc;
  color: #183b80;
  font-size: 13px;
  font-weight: 600;
}
.party-selector-block { margin-top: 0; }
.party-choice-list { display: grid; gap: 8px; }
.party-choice {
  display: grid !important;
  grid-template-columns: auto 1fr;
  align-items: start !important;
  gap: 10px !important;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: white;
  color: var(--text) !important;
}
.party-choice:hover { background: #f2f6ff; border-color: #a9c3f2; }
.party-choice input { margin-top: 3px; }
.party-choice span { display: grid; gap: 3px; }
.party-choice small { color: var(--muted); }

@media (max-width: 760px) {
  .estimate-party-row { grid-template-columns: 1fr; }
  .party-tooltip { width: min(360px, 88vw); }
}

.coeff-tooltip-trigger {
  position: relative;
  display: inline-flex;
  width: fit-content;
  white-space: nowrap;
  color: #204a96;
  cursor: help;
  border-bottom: 1px dashed #7d9bcf;
}
.coeff-tooltip {
  position: absolute;
  left: 0;
  top: calc(100% + 8px);
  z-index: 70;
  min-width: 230px;
  padding: 11px 12px;
  border: 1px solid #cdd7e8;
  border-radius: 12px;
  background: white;
  color: var(--text);
  box-shadow: 0 16px 38px rgba(15, 23, 42, 0.18);
  opacity: 0;
  visibility: hidden;
  transform: translateY(-4px);
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease, visibility 0.18s ease;
  display: grid;
  gap: 6px;
  white-space: normal;
  font-size: 13px;
  line-height: 1.35;
}
.coeff-tooltip strong { margin-bottom: 2px; font-size: 14px; }
.coeff-tooltip span { display: flex; justify-content: space-between; gap: 16px; }
.coeff-tooltip em { color: var(--muted); font-style: normal; }
.coeff-tooltip-trigger:hover .coeff-tooltip,
.coeff-tooltip-trigger:focus-visible .coeff-tooltip {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

/* Estimate parties and document details */
.party-choice-main {
  display: flex !important;
  align-items: flex-start !important;
  gap: 10px !important;
  min-width: 0;
}
.party-choice-main > span { min-width: 0; }
.party-primary-choice {
  display: inline-flex !important;
  align-items: center !important;
  justify-content: flex-end;
  gap: 7px !important;
  white-space: nowrap;
  color: var(--muted) !important;
  font-size: 13px !important;
}
.party-name-chip { gap: 6px; align-items: center; }
.party-name-chip small {
  padding: 2px 6px;
  border-radius: 999px;
  background: rgba(32, 74, 150, 0.12);
  color: #183b80;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}
.estimate-details-form .related-block {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}
.estimate-details-form .related-block > h3,
.estimate-details-form .related-block > .section-head {
  grid-column: 1 / -1;
}
.estimate-details-form .related-block label:has(textarea),
.estimate-details-form .related-block label:has(input[name="objectAddress"]) {
  grid-column: 1 / -1;
}
.estimate-workers-editor {
  grid-column: 1 / -1;
  display: grid;
  gap: 8px;
}
.estimate-worker-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
}
.autosave-status {
  position: sticky;
  bottom: 0;
  z-index: 2;
  margin-top: 4px;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(6px);
  font-size: 12px;
}

@media (max-width: 760px) {
  .party-choice { grid-template-columns: 1fr !important; }
  .party-primary-choice { justify-content: flex-start; padding-left: 28px; }
  .estimate-details-form .related-block { grid-template-columns: 1fr; }
  .estimate-details-form .related-block > h3,
  .estimate-details-form .related-block > .section-head,
  .estimate-details-form .related-block label:has(textarea),
  .estimate-details-form .related-block label:has(input[name="objectAddress"]) { grid-column: 1; }
}

/* Catalog list/detail UX */
.catalog-split-layout.catalog-list-only { grid-template-columns: minmax(0, 1fr); }
.catalog-detail-head { align-items: center; }
.catalog-toolbar-actions { flex-wrap: wrap; }
.catalog-filter { min-width: 190px; }
.catalog-filter:disabled { opacity: 0.55; cursor: not-allowed; background-color: #f3f5f8; }
.catalog-split-layout.catalog-list-only .list { max-height: calc(100vh - 220px); }
.catalog-draft-badge {
  display: inline-flex;
  width: fit-content;
  padding: 5px 9px;
  border-radius: 999px;
  background: #fff3d9;
  color: #8a5600;
  font-size: 12px;
  font-weight: 700;
  margin-bottom: 12px;
}
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(15, 23, 42, 0.42);
}
.modal-card {
  width: min(520px, 100%);
  padding: 22px;
  border-radius: 18px;
  background: white;
  box-shadow: 0 24px 70px rgba(15, 23, 42, 0.24);
}
.modal-card h2 { margin: 0 0 8px; }
.modal-card p { margin: 0; }

@media (max-width: 760px) {
  .catalog-filter { width: 100%; min-width: 0; }
  .catalog-detail-head { align-items: flex-start; }
}


/* Catalog card grid and destructive actions */
.catalog-split-layout.catalog-list-only #catalogList:not(.catalog-price-list) {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  align-items: stretch;
}
.catalog-split-layout:not(.catalog-list-only) #catalogList { grid-template-columns: 1fr; }
.catalog-split-layout.catalog-list-only #catalogList > .empty-state { grid-column: 1 / -1; }
.catalog-split-layout.catalog-list-only #catalogList > .list-item { min-height: 92px; align-content: start; }
.catalog-unsaved-indicator {
  display: inline-flex;
  width: fit-content;
  margin-bottom: 10px;
  padding: 5px 9px;
  border-radius: 999px;
  background: #fff3d9;
  color: #8a5600;
  font-size: 12px;
  font-weight: 700;
}

@media (max-width: 1100px) {
  .catalog-split-layout.catalog-list-only #catalogList:not(.catalog-price-list) {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
@media (max-width: 760px) {
  .catalog-split-layout.catalog-list-only #catalogList:not(.catalog-price-list) {
    grid-template-columns: 1fr;
  }
}
.variant-select-button {
  width: 100%;
  padding: 0;
  border-radius: 0;
  text-align: left;
  display: grid;
  gap: 6px;
}
.variant-select-button:not(:disabled):hover { background: transparent; color: var(--text); }
