:root {
  --ink: #17202a;
  --muted: #5e6b78;
  --line: #d8e0e7;
  --panel: #ffffff;
  --soft: #f4f7f9;
  --answer-bg: #fff1f1;
  --answer-line: #f2caca;
  --brand: #0a6478;
  --brand-dark: #084b5d;
  --accent: #d86f2f;
  --ok: #176b3a;
  --shadow: 0 14px 34px rgba(23, 32, 42, 0.08);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  color: var(--ink);
  background: #edf2f5;
  font-family: "Segoe UI", "Malgun Gothic", Arial, sans-serif;
  line-height: 1.6;
}

button,
input,
select,
textarea {
  font: inherit;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  justify-content: space-between;
  gap: 24px;
  align-items: center;
  padding: 22px clamp(20px, 4vw, 48px);
  color: #fff;
  background: linear-gradient(110deg, #103845, #0a6478 58%, #225a63);
  box-shadow: 0 8px 20px rgba(12, 41, 51, 0.2);
}

.topbar h1 {
  margin: 4px 0 0;
  font-size: clamp(22px, 2.4vw, 34px);
  letter-spacing: 0;
}

.eyebrow {
  margin: 0;
  color: #d8eef3;
  font-size: 14px;
}

.status {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 12px;
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: 6px;
  color: #edf9fb;
  font-size: 14px;
}

.status a {
  color: #fff;
  font-weight: 800;
  text-decoration: none;
}

.status a:hover,
.status a:focus {
  text-decoration: underline;
}

.layout {
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
  gap: 26px;
  width: min(1480px, 100%);
  margin: 0 auto;
  padding: 28px clamp(16px, 3vw, 36px) 56px;
}

.layout.single {
  display: block;
  max-width: 1180px;
}

.side {
  align-self: start;
  position: sticky;
  top: 116px;
}

.side nav {
  display: grid;
  gap: 4px;
  padding: 10px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.side a {
  display: block;
  padding: 10px 12px;
  color: var(--muted);
  text-decoration: none;
  border-radius: 6px;
}

.side a:hover,
.side a:focus {
  color: var(--brand-dark);
  background: #e8f3f5;
}

.survey {
  display: grid;
  gap: 22px;
  min-width: 0;
}

.section {
  padding: clamp(22px, 3vw, 34px);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.section-head {
  margin-bottom: 20px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 16px;
}

.section-head p {
  margin: 0 0 4px;
  color: var(--brand);
  font-weight: 700;
}

.section-head h2 {
  margin: 0;
  font-size: clamp(20px, 2vw, 28px);
  letter-spacing: 0;
}

.notice-grid,
.definition-grid,
.field-grid {
  display: grid;
  gap: 14px;
}

.notice-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin-top: 20px;
}

.notice-grid span,
.definition-grid article,
.formula,
.reference-box,
.distance-panel,
.submit-note {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--soft);
}

.notice-grid span {
  padding: 14px;
  font-weight: 700;
}

.definition-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.definition-grid article {
  padding: 18px;
}

.definition-grid h3,
.distance-panel h3 {
  margin: 0 0 8px;
  font-size: 18px;
}

.definition-grid p {
  margin: 0;
  color: var(--muted);
}

.formula {
  margin-bottom: 16px;
  padding: 14px 16px;
  color: var(--brand-dark);
  font-weight: 800;
}

.field-grid.two {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.field-grid.four {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

label {
  display: grid;
  gap: 7px;
  font-weight: 700;
}

label span,
legend {
  color: #24313b;
}

input[type="text"],
input[type="number"],
select,
textarea {
  width: 100%;
  border: 1px solid var(--answer-line);
  border-radius: 6px;
  padding: 10px 11px;
  background: var(--answer-bg);
  color: var(--ink);
}

textarea {
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus,
button:focus {
  outline: 3px solid rgba(10, 100, 120, 0.2);
  outline-offset: 2px;
}

.is-invalid {
  border-color: #c83737 !important;
  box-shadow: 0 0 0 3px rgba(200, 55, 55, 0.14);
}

td.is-invalid {
  background: #ffe2e2 !important;
}

fieldset {
  margin: 18px 0;
  padding: 16px;
  border: 1px solid var(--answer-line);
  border-radius: 8px;
  background: var(--answer-bg);
}

legend {
  padding: 0 8px;
  font-weight: 800;
}

.choice-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 16px;
}

.choice-row label,
.inline-other {
  display: flex;
  align-items: center;
  gap: 7px;
  min-height: 38px;
  padding: 6px 8px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.56);
  font-weight: 600;
}

.inline-other input[type="text"] {
  width: min(180px, 42vw);
  padding: 7px 9px;
}

.question {
  margin: 22px 0 12px;
  font-weight: 800;
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 860px;
  background: #fff;
}

th,
td {
  border-bottom: 1px solid var(--line);
  border-right: 1px solid var(--line);
  padding: 10px;
  vertical-align: middle;
}

th:last-child,
td:last-child {
  border-right: 0;
}

tr:last-child td {
  border-bottom: 0;
}

th {
  color: #24313b;
  background: #e9f0f3;
  text-align: center;
  font-size: 14px;
}

td {
  min-width: 120px;
}

.decision-table tbody td,
.vessel-table tbody td {
  background: var(--answer-bg);
}

.decision-table .decision-meta,
.vessel-table td:first-child {
  font-weight: 800;
  background: #f8fafb;
}

.cell-options {
  display: flex;
  justify-content: center;
  gap: 12px;
  white-space: nowrap;
}

.cell-options label {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 6px 8px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.6);
  font-weight: 600;
}

.hint {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.reference-box {
  margin: 0 0 18px;
  padding: 14px 16px;
}

.combined-reference {
  display: grid;
  gap: 14px;
}

.reference-box ul {
  margin: 8px 0 0;
  padding-left: 22px;
}

.reference-box li {
  margin: 4px 0;
}

.field-grid em {
  color: var(--muted);
  font-style: normal;
  font-size: 14px;
}

.distance-panel {
  margin: 0;
  padding: 14px;
}

.combined-reference .distance-panel {
  border: 0;
  border-top: 1px solid var(--line);
  border-radius: 0;
  background: transparent;
  padding: 14px 0 0;
}

.distance-list {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.distance-list span {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 6px;
  background: #fff;
  border: 1px solid #dce4ea;
}

.port-tables {
  display: grid;
  gap: 16px;
}

.port-table-block {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.port-table-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  background: #f8fafb;
  border-bottom: 1px solid var(--line);
}

.port-table-head h3 {
  margin: 0;
  font-size: 17px;
}

.port-table-block .table-wrap {
  border: 0;
  border-radius: 0;
}

.table-actions {
  margin-top: 12px;
}

.additional-opinion-field {
  margin-top: 28px;
}

.vessel-table input,
.vessel-table select {
  min-width: 92px;
}

.vessel-table .pilot-port-row th,
.vessel-table .pilot-port-row td {
  background: var(--answer-bg);
}

.vessel-table .pilot-port-row th {
  width: 150px;
  color: #24313b;
  font-weight: 800;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 14px;
}

button {
  border: 0;
  border-radius: 6px;
  padding: 11px 16px;
  cursor: pointer;
  font-weight: 800;
}

.primary {
  color: #fff;
  background: var(--brand);
}

.primary:hover {
  background: var(--brand-dark);
}

.secondary {
  color: var(--brand-dark);
  background: #e5f1f3;
}

.secondary:hover {
  background: #d6e9ed;
}

.submit-note {
  padding: 13px 14px;
  color: #4c5964;
}

.result-summary {
  margin: 18px 0 12px;
  color: var(--brand-dark);
  font-size: 18px;
  font-weight: 800;
}

pre {
  display: none;
  max-height: 520px;
  overflow: auto;
  margin: 16px 0 0;
  padding: 16px;
  color: #e9fbff;
  background: #13252c;
  border-radius: 8px;
  white-space: pre-wrap;
}

pre.visible {
  display: block;
}

@media (max-width: 1100px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .side {
    position: static;
  }

  .side nav {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .notice-grid,
  .definition-grid,
  .field-grid.four,
  .distance-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 720px) {
  body {
    background: #f3f6f8;
    font-size: 16px;
  }

  .topbar {
    position: static;
    align-items: flex-start;
    flex-direction: column;
    gap: 14px;
    padding: 18px 16px;
  }

  .topbar h1 {
    font-size: 22px;
    line-height: 1.35;
  }

  .eyebrow {
    font-size: 13px;
  }

  .status {
    width: 100%;
    justify-content: space-between;
    flex-wrap: wrap;
  }

  .layout {
    gap: 16px;
    padding: 14px 12px 36px;
  }

  .side nav {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding: 8px;
    border-radius: 8px;
    box-shadow: none;
    scrollbar-width: thin;
  }

  .side a {
    flex: 0 0 auto;
    padding: 9px 11px;
    white-space: nowrap;
  }

  .section {
    padding: 18px 14px;
    box-shadow: none;
  }

  .section-head {
    margin-bottom: 16px;
    padding-bottom: 12px;
  }

  .section-head h2 {
    font-size: 21px;
    line-height: 1.35;
  }

  .notice-grid,
  .definition-grid,
  .field-grid.two,
  .field-grid.four,
  .distance-list {
    grid-template-columns: 1fr;
  }

  .notice-grid span,
  .definition-grid article,
  .formula,
  .reference-box,
  .distance-panel,
  .submit-note {
    border-radius: 6px;
  }

  input[type="text"],
  input[type="number"],
  select,
  textarea {
    min-height: 44px;
    padding: 11px 12px;
    font-size: 16px;
  }

  fieldset {
    margin: 14px 0;
    padding: 12px;
  }

  .choice-row {
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .choice-row label,
  .inline-other {
    min-height: 44px;
    align-items: center;
  }

  .inline-other {
    flex-wrap: wrap;
  }

  .inline-other input[type="text"] {
    width: 100%;
  }

  .question {
    margin: 18px 0 10px;
  }

  .table-wrap {
    overflow: visible;
    border: 0;
    border-radius: 0;
  }

  table,
  thead,
  tbody,
  tr,
  th,
  td {
    display: block;
  }

  table {
    min-width: 0;
    background: transparent;
  }

  thead {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
  }

  .vessel-table thead {
    position: static;
    width: auto;
    height: auto;
    overflow: visible;
    clip: auto;
    white-space: normal;
  }

  .vessel-table thead tr:not(.pilot-port-row) {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
  }

  .vessel-table .pilot-port-row {
    display: grid;
    grid-template-columns: 1fr;
  }

  .vessel-table .pilot-port-row th,
  .vessel-table .pilot-port-row td {
    display: block;
    width: 100%;
    border-right: 0;
    text-align: left;
  }

  .vessel-table .pilot-port-row th {
    min-height: 0;
    border-bottom: 0;
    padding: 12px 12px 4px;
    background: var(--answer-bg);
  }

  .vessel-table .pilot-port-row td {
    padding: 4px 12px 12px;
  }

  .vessel-table .pilot-port-row td::before {
    content: "";
    display: none;
  }

  tbody {
    display: grid;
    gap: 12px;
  }

  tr {
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
  }

  td {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    min-width: 0;
    min-height: 48px;
    border-right: 0;
    padding: 10px 12px;
    text-align: right;
  }

  td::before {
    content: attr(data-label);
    flex: 0 0 112px;
    color: var(--muted);
    font-size: 14px;
    font-weight: 800;
    text-align: left;
  }

  td:empty::before {
    content: "";
  }

  .decision-table .decision-meta,
  .vessel-table td:first-child {
    background: #f8fafb;
  }

  .vessel-table td:first-child,
  .result-table td:first-child {
    align-items: flex-start;
    text-align: right;
  }

  .vessel-table input,
  .vessel-table select {
    min-width: 0;
    max-width: 160px;
  }

  .vessel-table td:first-child input {
    max-width: 100%;
    margin-top: 6px;
  }

  .cell-options {
    justify-content: flex-end;
    flex-wrap: wrap;
    gap: 8px;
    white-space: normal;
  }

  .distance-list span {
    min-height: 42px;
  }

  button {
    min-height: 44px;
  }

  .actions button {
    width: 100%;
  }

  .port-table-head {
    align-items: stretch;
    flex-direction: column;
  }

  .port-table-head button,
  .table-actions button {
    width: 100%;
  }

  pre {
    max-height: 420px;
    padding: 12px;
    font-size: 13px;
  }
}
