:root {
  --bg: #eef1f4;
  --panel: #ffffff;
  --ink: #17202a;
  --muted: #667085;
  --line: #cfd6dd;
  --accent: #0f766e;
  --accent-dark: #115e59;
  --soft: #f6f7f9;
  --danger: #a33a3a;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Arial, sans-serif;
}

button, input, select {
  font: inherit;
}

button,
.button {
  border: 0;
  border-radius: 6px;
  padding: 9px 13px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  font-weight: 700;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

button:hover, .button:hover { background: var(--accent-dark); }
button.secondary, .button.secondary { background: #e5e9ed; color: #1f2933; }
button.secondary:hover, .button.secondary:hover { background: #d7dde3; }
button.danger { background: #f1dddd; color: var(--danger); }
button.wide { width: 100%; }

.app-header {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  padding: 18px 24px;
  background: #18212b;
  color: #fff;
  align-items: center;
}

.app-header h1, .app-header p { margin: 0; }
.app-header h1 { font-size: 24px; }
.app-header p { color: #d7dde3; margin-top: 4px; }
.header-actions { display: flex; gap: 10px; flex-wrap: wrap; }

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 16px;
  padding: 16px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
}

.section-title, .table-head, .preview-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

h2, h3 { margin: 0; }
h2 { font-size: 18px; }
h3 { font-size: 15px; }

.form-grid, .company-fields {
  display: grid;
  grid-template-columns: repeat(5, minmax(120px, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}

.company-fields {
  grid-template-columns: 1.5fr 1fr 1fr 1.5fr;
}

label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

input, select {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 9px;
  background: #fff;
  color: var(--ink);
}

.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 8px; }
table { border-collapse: collapse; width: 100%; }
.edit-table th, .edit-table td {
  border-bottom: 1px solid var(--line);
  padding: 7px;
  text-align: left;
  white-space: nowrap;
}
.edit-table th { background: var(--soft); color: #344054; font-size: 13px; }
.edit-table tr:last-child td { border-bottom: 0; }

.totals {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  margin-top: 14px;
}

.totals div {
  min-width: 160px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  background: var(--soft);
}

.totals span { display: block; color: var(--muted); font-size: 12px; font-weight: 700; }
.totals strong { font-size: 20px; }

.client-tools {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 14px;
  flex-wrap: wrap;
}

.hidden { display: none; }

.muted { color: var(--muted); margin-top: 0; font-size: 13px; line-height: 1.35; }
.coef-list { display: grid; gap: 8px; }
.coef-row {
  display: grid;
  grid-template-columns: 1fr 95px 36px;
  gap: 8px;
  align-items: end;
}
hr { border: 0; border-top: 1px solid var(--line); margin: 16px 0; }

.data-shell,
.preview-shell {
  padding: 0 16px 24px;
}

.data-shell {
  display: flex;
  justify-content: flex-end;
}

.archive-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfd;
  padding: 12px;
  margin-top: 12px;
}
.archive-list {
  display: grid;
  gap: 8px;
}
.archive-item {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 9px 10px;
  background: var(--soft);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.archive-item span { color: var(--muted); font-size: 13px; }
.archive-item a {
  color: #0b5cad;
  font-weight: 700;
  text-decoration: none;
  min-width: 0;
  overflow-wrap: anywhere;
  flex: 1;
}
.archive-item a:hover { text-decoration: underline; }
.link-button {
  padding: 0;
  border: 0;
  background: transparent;
  color: #0b5cad;
  font-weight: 700;
  text-align: left;
  justify-content: flex-start;
  overflow-wrap: anywhere;
}
.link-button:hover {
  background: transparent;
  color: #084782;
  text-decoration: underline;
}
.archive-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.preview-toolbar {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px 16px;
}

.paper {
  width: 210mm;
  min-height: 297mm;
  margin: 16px auto 0;
  background: #fff;
  box-shadow: 0 8px 30px rgba(20, 29, 39, 0.18);
  padding: 16mm 17mm;
  color: #000;
  font-family: Arial, sans-serif;
  font-size: 11pt;
}

.paper .top { font-weight: 700; }
.paper .title { text-align: center; font-weight: 700; margin: 16px 0 8px; }
.paper .box { width: 66%; border-collapse: collapse; margin-top: 20px; font-weight: 700; }
.paper .box td { border-bottom: 1.5px solid #000; padding: 5px 4px; }
.paper .hint { font-weight: 400; }
.paper h1 { text-align: center; font-size: 14pt; line-height: 1.65; margin: 20px 0 16px; letter-spacing: 1px; }
.paper .calc { table-layout: fixed; font-size: 11pt; }
.paper .calc th, .paper .calc td { border: 1px solid #000; padding: 5px 4px; text-align: center; height: 25px; }
.paper .calc th { background: #d9d9d9; font-weight: 700; }
.paper .strong { font-weight: 700; }
.paper .payment { margin: 18px 0 22px 64%; font-weight: 700; white-space: nowrap; }
.paper .footer { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; margin-top: 6px; }
.paper .director { text-align: center; font-weight: 700; }
.paper .signature { margin-top: 28px; display: flex; justify-content: space-around; align-items: end; }
.paper .phone { margin-top: 22px; font-weight: 700; }

@media (max-width: 1100px) {
  .layout { grid-template-columns: 1fr; }
  .form-grid, .company-fields { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 760px) {
  .app-header { align-items: stretch; flex-direction: column; }
  .form-grid, .company-fields { grid-template-columns: 1fr; }
  .paper { width: 100%; padding: 12mm 8mm; font-size: 10pt; }
}

@media print {
  body { background: #fff; }
  .app-header, .layout, .preview-toolbar { display: none; }
  .preview-shell { padding: 0; }
  .paper { box-shadow: none; margin: 0; width: auto; min-height: auto; padding: 0; }
}
