:root {
  --bg: #f5f7fa;
  --panel: #ffffff;
  --ink: #16202a;
  --muted: #64748b;
  --line: #d9e2ec;
  --brand: #194b73;
  --brand-2: #1f7a8c;
  --good: #0f766e;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Arial, Helvetica, sans-serif;
  font-size: 14px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 12px 20px;
  background: #ffffff;
  border-bottom: 1px solid var(--line);
}
.topbar strong { display: block; font-size: 16px; }
.topbar span { color: var(--muted); font-size: 12px; }
nav { display: flex; gap: 8px; flex-wrap: wrap; }

button, input, select, textarea {
  font: inherit;
}
button {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 12px;
  background: #fff;
  cursor: pointer;
}
button.primary { background: var(--brand); color: #fff; border-color: var(--brand); }
button.active { background: #e7f0f5; border-color: var(--brand-2); color: #12344d; }
button.ghost:hover, button:hover { border-color: var(--brand-2); }
button.danger { color: #b42318; }

main { max-width: 1480px; margin: 18px auto; padding: 0 18px 36px; }
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
}
.hidden { display: none; }

.grid { display: grid; gap: 12px; }
.meta-grid { grid-template-columns: repeat(5, minmax(150px, 1fr)); }
label { color: var(--muted); font-size: 12px; }
input, select, textarea {
  display: block;
  width: 100%;
  margin-top: 5px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 10px;
  color: var(--ink);
  background: #fff;
}
input.numeric-input {
  font-variant-numeric: tabular-nums;
}
td select {
  margin-top: 6px;
}
textarea {
  min-height: 72px;
  resize: vertical;
}

.summary-strip {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(145px, 1fr));
  gap: 10px;
  margin: 18px 0;
}
.metric {
  border: 1px solid var(--line);
  border-left: 4px solid var(--brand-2);
  border-radius: 6px;
  padding: 10px;
  background: #fbfdff;
}
.metric span { display: block; color: var(--muted); font-size: 12px; }
.metric strong { display: block; margin-top: 6px; font-size: 18px; }

.toolbar {
  display: grid;
  grid-template-columns: 240px minmax(260px, 1fr) auto;
  gap: 10px;
  margin-bottom: 16px;
}

.service {
  border-top: 1px solid var(--line);
  padding-top: 16px;
  margin-top: 18px;
}
.service-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 8px;
}
h2 { margin: 0 0 8px; font-size: 18px; }
.service-total { color: var(--good); font-weight: 700; font-size: 17px; }
.service-tools {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) minmax(260px, 1fr) auto 170px;
  gap: 10px;
  align-items: end;
  padding: 12px;
  margin-bottom: 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fbfdff;
}
.service-tools button {
  min-height: 37px;
}

table { width: 100%; border-collapse: collapse; }
th, td {
  border-bottom: 1px solid var(--line);
  padding: 8px;
  text-align: left;
  vertical-align: top;
}
th {
  background: #eef5f8;
  color: #17324d;
  font-size: 12px;
  position: sticky;
  top: 0;
  z-index: 2;
  line-height: 1.2;
  white-space: nowrap;
}
td input { margin: 0; padding: 6px 8px; }
td:nth-child(4), td:nth-child(5), td:nth-child(6), td:nth-child(7), td:nth-child(8), td:nth-child(9) { width: 96px; }
.money { text-align: right; white-space: nowrap; }
.muted { color: var(--muted); }
.split { display: grid; grid-template-columns: minmax(280px, 1fr) minmax(360px, 520px); gap: 24px; align-items: start; }
.split-head {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}
.import-box textarea { min-height: 110px; }
.import-box button { margin-top: 8px; width: 100%; }
.table-wrap { overflow: auto; max-height: calc(100vh - 260px); border: 1px solid var(--line); border-radius: 6px; }
.catalog-wrap { max-height: calc(100vh - 330px); margin-top: 16px; }
.workbook-wrap { max-height: calc(100vh - 220px); margin-top: 16px; }
.add-grid { grid-template-columns: repeat(2, minmax(150px, 1fr)); }
#catalogTable th {
  background: #e7f0f5;
  padding: 10px 8px;
  vertical-align: middle;
}
#catalogTable th:nth-child(1) { min-width: 150px; }
#catalogTable th:nth-child(2), #catalogTable th:nth-child(3) { min-width: 260px; }
#catalogTable th:nth-child(4) { min-width: 220px; }
#catalogTable th:nth-child(5) { min-width: 130px; }
#catalogTable th:nth-child(6), #catalogTable th:nth-child(7), #catalogTable th:nth-child(8) { min-width: 86px; text-align: center; }
#catalogTable textarea { min-width: 260px; min-height: 86px; }
#catalogTable input, #catalogTable select, #catalogTable textarea { margin-top: 0; }
.quote-actions {
  display: flex;
  gap: 6px;
  white-space: nowrap;
}
.preview-layout {
  display: grid;
  grid-template-columns: minmax(360px, 470px) minmax(520px, 1fr);
  gap: 18px;
  min-height: calc(100vh - 145px);
}
.proposal-editor {
  overflow: auto;
  max-height: calc(100vh - 145px);
  padding-right: 8px;
}
.proposal-editor details {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fbfdff;
  margin-bottom: 10px;
  padding: 10px;
}
.proposal-editor summary {
  cursor: pointer;
  font-weight: 700;
  color: #17324d;
}
.proposal-editor textarea {
  min-height: 120px;
}
.proposal-preview {
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
  background: #eef2f6;
}
.preview-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  background: #fff;
  border-bottom: 1px solid var(--line);
}
#proposalPreview {
  width: 100%;
  height: calc(100vh - 205px);
  border: 0;
  background: #fff;
}

@media (max-width: 900px) {
  .topbar { align-items: flex-start; flex-direction: column; }
  .meta-grid, .summary-strip, .toolbar, .split, .service-tools, .preview-layout { grid-template-columns: 1fr; }
  th { position: static; }
}
