:root {
    --bg: #f6f7f9;
    --fg: #17202a;
    --muted: #5c6670;
    --line: #d8dee5;
    --panel: #ffffff;
    --accent: #176b87;
    --accent-dark: #114f63;
    --danger: #a83232;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--fg);
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    line-height: 1.5;
}

a {
    color: var(--accent);
}

.site-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.9rem 1.25rem;
    background: var(--panel);
    border-bottom: 1px solid var(--line);
}

.brand {
    color: var(--fg);
    font-weight: 700;
    text-decoration: none;
}

.site-header nav,
.actions {
    display: flex;
    gap: 0.75rem;
    align-items: center;
    flex-wrap: wrap;
}

.container {
    width: min(1180px, calc(100% - 2rem));
    margin: 1.5rem auto;
}

.page-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1rem;
}

h1 {
    margin: 0 0 0.5rem;
    font-size: 1.8rem;
}

.muted,
.empty {
    color: var(--muted);
}

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

.narrow {
    max-width: 520px;
}

form label {
    display: grid;
    gap: 0.35rem;
    margin-bottom: 0.85rem;
}

input,
select,
button,
.button {
    min-height: 2.35rem;
    border-radius: 6px;
    border: 1px solid var(--line);
    padding: 0.45rem 0.7rem;
    font: inherit;
}

button,
.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
    text-decoration: none;
    cursor: pointer;
}

button:hover,
.button:hover {
    background: var(--accent-dark);
}

.secondary {
    background: #fff;
    color: var(--accent);
}

.danger {
    color: var(--danger);
}

button.danger,
.button.danger {
    border-color: var(--danger);
}

.inline-form {
    margin: 0;
}

.link-button {
    min-height: auto;
    padding: 0;
    border: 0;
    background: transparent;
    color: var(--accent);
}

.messages {
    display: grid;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.message {
    padding: 0.7rem 0.85rem;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: #fff;
}

.message.success {
    border-color: #6aa36f;
}

.message.error {
    border-color: var(--danger);
}

.filters {
    display: grid;
    grid-template-columns: repeat(4, minmax(140px, 1fr));
    gap: 0.85rem;
    align-items: end;
    margin-bottom: 1rem;
}

.filters fieldset {
    grid-column: 1 / -1;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 0.8rem;
}

.checkbox-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 0.4rem 0.8rem;
}

.checkbox-grid label {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    margin: 0;
}

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

table {
    width: 100%;
    border-collapse: collapse;
}

th,
td {
    padding: 0.65rem 0.75rem;
    border-bottom: 1px solid var(--line);
    text-align: left;
    vertical-align: top;
}

th {
    background: #eef2f4;
}

.sheet-table-wrap {
    max-height: calc(100vh - 190px);
}

.sheet-table {
    width: max-content;
    min-width: 100%;
    table-layout: fixed;
    font-size: 0.88rem;
}

.sheet-table th {
    position: sticky;
    top: 0;
    z-index: 2;
}

.sheet-table td,
.sheet-table th {
    min-width: 3.5rem;
    max-width: 24rem;
    height: 1.85rem;
    padding: 0.32rem 0.45rem;
    overflow-wrap: anywhere;
    white-space: pre-wrap;
}

.sheet-table td {
    background: #fff;
    user-select: text;
}

.sheet-table td.merged {
    background: #f7fafb;
    font-weight: 600;
    text-align: center;
    vertical-align: middle;
}

.sheet-table td.empty-cell {
    background: #fbfcfd;
}

.sheet-table td.formula-cell {
    color: var(--muted);
}

.sheet-table td.editable-cell {
    background: #fffdf4;
}

.sheet-table input {
    width: 100%;
    min-width: 4rem;
    height: 1.8rem;
    min-height: 1.8rem;
    padding: 0.2rem 0.35rem;
}

.row-action-col-template,
.row-number-col-template {
    width: 3rem;
}

.row-action-col,
.row-number-col {
    min-width: 2.25rem !important;
    max-width: 2.75rem !important;
    text-align: center;
    white-space: nowrap !important;
}

.row-action-col {
    position: sticky;
    right: 0;
    z-index: 3;
    background: var(--panel);
}

.row-number-col {
    position: sticky;
    left: 0;
    z-index: 3;
}

.has-actions .row-number-col {
    left: 3rem;
}

td.row-action-col {
    background: var(--panel);
}

.sheet-table tbody .row-number-col {
    background: #eef2f4;
    color: var(--muted);
    font-weight: 600;
}

.editing-row td,
.editing-row th {
    background: #fff8df;
}

.icon-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.35rem;
    min-width: 1.35rem;
    height: 1.35rem;
    min-height: 1.35rem;
    padding: 0;
    border-radius: 999px;
    border: 1px solid var(--accent);
    background: var(--accent);
    color: #fff;
    text-decoration: none;
    line-height: 1;
    font-size: 0.8rem;
}

.secondary-icon {
    background: var(--accent);
    color: #fff;
}

.icon-button:hover,
.secondary-icon:hover {
    background: var(--accent-dark);
    border-color: var(--accent-dark);
}

.semantic-fields {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 0.75rem;
    margin-bottom: 1.25rem;
}

.field-pair {
    display: grid;
    gap: 0.2rem;
    padding: 0.75rem;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
}

.field-pair span {
    color: var(--muted);
    font-size: 0.85rem;
}

.field-pair strong {
    font-weight: 600;
}

.field-edit-form {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 0.5rem;
    align-items: center;
}

.field-edit-form[data-autosave-card] {
    grid-template-columns: minmax(0, 1fr);
}

.field-edit-form input,
.field-edit-form select {
    width: 100%;
    min-width: 0;
}

.compact-button {
    min-height: 2.2rem;
    padding: 0.4rem 0.65rem;
    font-size: 0.88rem;
}

.semantic-section {
    margin-top: 1.25rem;
}

.proforma-block {
    display: flex;
    flex-wrap: wrap;
    gap: 0.9rem 1rem;
    margin: 1rem 0 1.5rem;
    padding: 1rem;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
}

.proforma-block > h2 {
    flex: 0 0 100%;
    margin: 0 0 0.85rem;
    font-size: 1.2rem;
}

.proforma-block > .semantic-section {
    flex: 1 1 calc(50% - 0.5rem);
    min-width: min(100%, 420px);
    margin: 0;
}

.hydrobiology-block > .semantic-section {
    flex-basis: 100%;
}

.proforma-block > .eco-position-table-section {
    flex: 0 0 100%;
}

.eco-position-table-section .semantic-table-wrap {
    overflow-x: auto;
}

.proforma-block > .eco-sediment-eh-table-section,
.proforma-block > .eco-sediment-ph-table-section,
.proforma-block > .eco-replication-table-section,
.proforma-block > .eco-column-height-table-section {
    flex: 1 1 calc(50% - 0.5rem);
    min-width: min(100%, 360px);
}

.eco-position-table th:nth-child(1),
.eco-position-table td:nth-child(1) {
    width: 8%;
}

.eco-position-table th:nth-child(2),
.eco-position-table td:nth-child(2) {
    width: 9%;
}

.eco-position-table th:nth-child(3),
.eco-position-table td:nth-child(3),
.eco-position-table th:nth-child(4),
.eco-position-table td:nth-child(4) {
    width: 32%;
    min-width: 20rem;
}

.eco-position-table th:nth-child(5),
.eco-position-table td:nth-child(5) {
    width: 19%;
}

.eco-position-table {
    min-width: 78rem;
}

.eco-position-table .coordinate-inputs {
    gap: 0.18rem;
    width: max-content;
    min-width: max-content;
}

.eco-position-table .coordinate-inputs input {
    box-sizing: border-box;
    text-align: center;
}

.eco-position-table .coordinate-inputs input[data-coordinate-part="degrees"] {
    width: 5.25rem !important;
    min-width: 5.25rem;
}

.eco-position-table .coordinate-inputs input[data-coordinate-part="minutes"] {
    width: 4.75rem !important;
    min-width: 4.75rem;
}

.eco-position-table .coordinate-inputs input[data-coordinate-part="seconds"] {
    width: 7rem !important;
    min-width: 7rem;
}

.eco-position-table .coordinate-inputs input::-webkit-outer-spin-button,
.eco-position-table .coordinate-inputs input::-webkit-inner-spin-button {
    margin: 0;
    appearance: none;
}

.eco-position-table .coordinate-inputs input[type="number"] {
    appearance: textfield;
}

.compact-fields {
    flex: 0 0 100%;
    margin-bottom: 0;
}

.semantic-section h2 {
    margin: 0 0 0.65rem;
    font-size: 1.15rem;
}

.semantic-section h3 {
    margin: 0 0 0.55rem;
    font-size: 1rem;
}

.table-stats {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin: 0 0 0.75rem;
}

.table-stat {
    display: inline-flex;
    align-items: baseline;
    gap: 0.45rem;
    padding: 0.45rem 0.65rem;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: #f7faf8;
}

.table-stat span {
    color: var(--muted);
    font-size: 0.9rem;
}

.table-stat strong {
    font-size: 1rem;
}

.semantic-table-wrap {
    margin-bottom: 1rem;
    overflow-x: visible;
}

.semantic-table {
    width: 100%;
    min-width: 0;
    table-layout: fixed;
}

.semantic-table th,
.semantic-table td {
    white-space: normal;
    overflow-wrap: anywhere;
    word-break: normal;
}

.semantic-table td.cell-with-action {
    position: relative;
    padding-right: 2.7rem;
}

.row-action-buttons {
    position: absolute;
    top: 50%;
    right: 0.45rem;
    transform: translateY(-50%);
    display: inline-flex;
    gap: 0.25rem;
    align-items: center;
}

.row-action-buttons form {
    display: inline-flex;
    gap: 0.25rem;
    align-items: center;
}

.semantic-table input,
.semantic-table select {
    width: 100%;
    min-width: 0;
}

.structured-input {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    flex-wrap: nowrap;
    width: 100%;
}

.structured-input input {
    min-width: 0;
}

.structured-input span {
    color: var(--muted);
    font-size: 0.85rem;
}

.date-inputs,
.time-inputs {
    width: max-content;
    min-width: max-content;
}

.date-inputs input[data-date-part="day"],
.date-inputs input[data-date-part="month"],
.time-inputs input[data-time-part="hour"],
.time-inputs input[data-time-part="minute"] {
    flex: 0 0 calc(2ch + 1.2rem);
    width: calc(2ch + 1.2rem) !important;
    inline-size: calc(2ch + 1.2rem);
    min-inline-size: calc(2ch + 1.2rem);
    max-inline-size: calc(2ch + 1.2rem);
    box-sizing: content-box;
    padding-inline: 0.25rem;
    text-align: center;
    font-variant-numeric: tabular-nums;
}

.date-inputs input[data-date-part="year"] {
    flex: 0 0 calc(4ch + 1.2rem);
    width: calc(4ch + 1.2rem) !important;
    inline-size: calc(4ch + 1.2rem);
    min-inline-size: calc(4ch + 1.2rem);
    max-inline-size: calc(4ch + 1.2rem);
    box-sizing: content-box;
    padding-inline: 0.25rem;
    text-align: center;
    font-variant-numeric: tabular-nums;
}

.meteo-observation-table {
    width: 100%;
    min-width: 0;
    max-width: 100%;
}

.meteo-observation-table th,
.meteo-observation-table td {
    padding-left: 0.45rem;
    padding-right: 0.45rem;
}

.meteo-observation-table .meteo-date-col {
    width: 12.5%;
}

.meteo-observation-table .meteo-time-col {
    width: 8%;
}

.meteo-observation-table .meteo-station-col {
    width: 9%;
}

.meteo-observation-table .meteo-speed-col,
.meteo-observation-table .meteo-temperature-col,
.meteo-observation-table .meteo-direction-col,
.meteo-observation-table .meteo-wave-col,
.meteo-observation-table .meteo-cloud-col,
.meteo-observation-table .meteo-pressure-col {
    width: 9.5%;
}

.meteo-observation-table .meteo-precipitation-col {
    width: 13.5%;
}

.meteo-observation-table .date-cell {
    padding-right: 0.65rem;
}

.meteo-observation-table .time-cell {
    padding-left: 0.65rem;
}

.meteo-observation-table .date-inputs,
.meteo-observation-table .time-inputs {
    gap: 0.12rem;
    width: auto;
    min-width: 0;
}

.meteo-observation-table .date-inputs input[data-date-part="day"],
.meteo-observation-table .date-inputs input[data-date-part="month"],
.meteo-observation-table .time-inputs input[data-time-part="hour"],
.meteo-observation-table .time-inputs input[data-time-part="minute"] {
    flex: 0 0 2.2rem;
    width: 2.2rem !important;
    min-width: 2.2rem;
    max-width: 2.2rem;
    padding-left: 0.2rem;
    padding-right: 0.2rem;
    box-sizing: border-box;
}

.meteo-observation-table .date-inputs input[data-date-part="year"] {
    flex: 0 0 3.55rem;
    width: 3.55rem !important;
    min-width: 3.55rem;
    max-width: 3.55rem;
    padding-left: 0.2rem;
    padding-right: 0.2rem;
    box-sizing: border-box;
}

.coordinate-inputs input[data-coordinate-part="degrees"],
.coordinate-inputs input[data-coordinate-part="minutes"] {
    width: 3.75rem;
}

.coordinate-inputs input[data-coordinate-part="seconds"] {
    width: 5rem;
}

.semantic-table .summary-row td {
    background: #fffbd1;
    font-weight: 700;
}

.semantic-table .summary-row .row-action-col {
    background: #fffbd1;
}

.semantic-table td.invalid-reference-cell {
    background: #ffe8e8;
    color: var(--danger);
    font-weight: 700;
}

.semantic-table td.invalid-reference-cell input,
.semantic-table td.invalid-reference-cell select {
    border-color: var(--danger);
    color: var(--danger);
}

.report-table-section {
    margin-top: 1rem;
}

.report-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    justify-content: flex-end;
}

.report-table-title {
    margin: 0 0 0.6rem;
    font-size: 1.45rem;
    font-weight: 800;
}

.report-source-note {
    margin: 0 0 0.5rem;
}

.report-table-wrap {
    overflow: auto;
    max-height: calc(100vh - 220px);
    background: #fff;
    border: 1px solid #111;
}

.report-table {
    width: max-content;
    min-width: 100%;
    border-collapse: collapse;
    table-layout: fixed;
    font-family: Arial, sans-serif;
    font-size: 0.86rem;
    line-height: 1.05;
}

.report-table th,
.report-table td {
    min-width: 2.15rem;
    height: 1.25rem;
    padding: 0.1rem 0.25rem;
    border: 1px solid #111;
    color: #000;
    text-align: center;
    vertical-align: middle;
    white-space: nowrap;
}

.report-table th {
    background: #d9d9d9;
    font-weight: 700;
}

.report-table .station-col {
    min-width: 9.5rem;
    text-align: left;
}

.report-table .date-col {
    min-width: 6.5rem;
}

.report-table .description-col {
    min-width: 18rem;
    max-width: 36rem;
    white-space: normal;
    text-align: left;
}

.report-table th.station-col {
    text-align: center;
}

.report-table .vessel-row {
    background: #d9d9d9;
    text-align: center;
    font-weight: 700;
}

.report-table .empty-table-row {
    height: 3rem;
    color: var(--muted);
    text-align: center;
}

.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    margin-top: 1rem;
}

@media (max-width: 760px) {
    .page-title,
    .filters {
        display: grid;
        grid-template-columns: 1fr;
    }

    .proforma-block > .semantic-section {
        flex-basis: 100%;
    }
}
