/*  File: nivelacka.css — Description: layout of the application page — settings
    sidebar, result tiles, entry table, point-by-point mode, map and report.
    Note: cards, buttons, fields and overlays live in common.css. */

/* ====== WORKSPACE ====== */
.workspace {
    --sidebar-width: 380px;

    display: grid;
    grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
    gap: var(--space-large);
    align-items: start;
}

.settings {
    display: flex;
    flex-direction: column;
    gap: var(--space-small);
    position: sticky;
    top: 76px;                          /* below the sticky header */
    max-height: calc(100vh - 96px);
    overflow-y: auto;
    min-width: 0;
}

.settings-body {
    display: flex;
    flex-direction: column;
    gap: var(--space-large);
}

.settings-toggle { display: none; }

.results {
    display: flex;
    flex-direction: column;
    gap: var(--space-large);
    min-width: 0;
}

/* ====== RESULT TILES ====== */
.kpi-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: var(--space-small);
}

.kpi {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: var(--space-medium);
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-left: var(--border-strong) solid var(--panel-border);
    border-radius: var(--radius-md);
    box-shadow: var(--card-shadow);
    min-width: 0;
}

.kpi-accent { border-left-color: var(--accent-primary); }

.kpi-label {
    color: var(--muted-text);
    font-size: var(--font-xs);
    letter-spacing: var(--letter-spacing-sm);
    text-transform: uppercase;
}

.kpi-value {
    font-family: var(--font-mono);
    font-size: var(--font-lg);
    font-weight: 500;
    line-height: 1.2;
}

.kpi-note {
    color: var(--muted-text);
    font-size: var(--font-xs);
}

/* ====== WARNINGS ====== */
.warnings {
    display: flex;
    flex-direction: column;
    gap: var(--space-minimal);
}

.warnings:empty { display: none; }

.warning {
    padding: var(--space-small) var(--space-medium);
    background: var(--badge-warn-bg);
    color: var(--badge-warn-text);
    border-radius: var(--radius-sm);
    font-size: var(--font-sm);
}

/* ====== TABS ====== */
.tabs {
    display: flex;
    gap: var(--space-minimal);
    flex-wrap: wrap;
}

.tab {
    padding: var(--button-padding-block) var(--button-padding-inline);
    min-height: 44px;
    background: transparent;
    color: var(--muted-text);
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    font: inherit;
    font-size: var(--font-sm);
    cursor: pointer;
    transition: background-color var(--transition-fast) var(--ease-out),
                color var(--transition-fast) var(--ease-out);
}

.tab:hover { background: var(--accent-hover); color: var(--text-strong); }

.tab.is-active {
    background: var(--card-bg);
    border-color: var(--card-border);
    color: var(--text-strong);
    font-weight: 500;
}

.panel-toolbar {
    display: flex;
    gap: var(--space-medium);
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
}

/* ====== ENTRY TABLE ====== */
.entry-table-wrap {
    overflow: auto;
    max-height: 62vh;
    /* Hugs the table instead of leaving a strip of empty frame beside it. */
    width: max-content;
    max-width: 100%;
    border: 1px solid var(--panel-border);
    border-radius: var(--radius-sm);
}

.entry-table {
    border-collapse: separate;
    border-spacing: 0;
    font-size: var(--font-sm);
}

.entry-table th {
    position: sticky;
    z-index: 1;
    background: var(--panel-alt-bg);
    color: var(--muted-text);
    font-family: var(--font-mono);
    font-size: var(--font-xs);
    font-weight: 500;
    padding: 6px 8px;
    white-space: nowrap;
    border-bottom: 1px solid var(--panel-border);
    border-right: 1px solid var(--panel-border);
}

.entry-table thead th { top: 0; }

.entry-table .entry-axis {
    left: 0;
    z-index: 2;
    text-align: right;
}

.entry-table thead th:first-child { z-index: 3; left: 0; }

.entry-cell {
    padding: 0;
    border-bottom: 1px solid var(--panel-border);
    border-right: 1px solid var(--panel-border);
}

.entry-cell input {
    width: 88px;
    min-height: 34px;
    padding: 4px 6px;
    background: transparent;
    border: 0;
    border-radius: 0;
    font-family: var(--font-mono);
    text-align: right;
}

.entry-cell input:focus-visible {
    outline: 2px solid var(--accent-primary);
    outline-offset: -2px;
}

.entry-cell input[readonly] { color: var(--muted-text); }

/* The cell background carries the height so the table reads as a map too. */
.entry-cell.is-shaded { background: var(--cell-shade, transparent); }

.entry-cell.is-empty input { background: var(--badge-danger-bg); }

/* ====== POINT-BY-POINT ENTRY ====== */
.point-entry {
    /* One point at a time reads best in a phone-sized column, whatever the
       screen; the card around it may be far wider. */
    --point-width: 520px;

    display: flex;
    flex-direction: column;
    gap: var(--space-medium);
    width: 100%;
    max-width: var(--point-width);
    align-self: center;
}

.point-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-small);
}

.point-coords {
    font-family: var(--font-mono);
    font-size: var(--font-md);
}

.point-field input {
    min-height: 64px;
    font-family: var(--font-mono);
    font-size: 32px;
    text-align: center;
}

.point-height {
    text-align: center;
    font-size: var(--font-sm);
}

/* The progress overview is a thumbnail, not a second grid to click through --
   the cells are square, so an unbounded width would make them huge. */
.mini-grid {
    display: grid;
    gap: 2px;
    width: 100%;
    max-width: 340px;
    align-self: center;
}

.mini-cell {
    width: 100%;
    aspect-ratio: 1;
    min-width: 0;
    padding: 0;
    background: var(--panel-alt-bg);
    border: 1px solid var(--panel-border);
    border-radius: 2px;
    cursor: pointer;
}

.mini-cell.is-measured { background: var(--accent-primary); border-color: var(--accent-primary); }

.mini-cell.is-current { outline: 2px solid var(--text-strong); outline-offset: 1px; }

/* ====== MAP ====== */
.map-figure {
    display: flex;
    flex-direction: column;
    gap: var(--space-small);
}

.map-figure img {
    width: 100%;
    height: auto;
    display: block;
    background: var(--card-bg);
    border-radius: var(--radius-sm);
}

/* ====== REPORT ====== */
.report {
    display: grid;
    /* Wide enough that a value like "15.2 mm · X 0.493 m, Y 0 m" fits on one line. */
    grid-template-columns: repeat(auto-fit, minmax(360px, 1fr));
    gap: var(--space-large);
}

.report-block {
    display: flex;
    flex-direction: column;
    gap: var(--space-small);
    padding: var(--space-medium);
    background: var(--panel-bg);
    border: 1px solid var(--panel-border);
    border-radius: var(--radius-sm);
    min-width: 0;
}

.report-title {
    color: var(--muted-text);
    font-size: var(--font-xs);
    letter-spacing: var(--letter-spacing-sm);
    text-transform: uppercase;
}

.report-rows {
    display: flex;
    flex-direction: column;
    gap: var(--space-minimal);
}

.report-row {
    display: flex;
    gap: var(--space-small);
    justify-content: space-between;
    align-items: baseline;
    font-size: var(--font-sm);
}

.report-row dt { color: var(--muted-text); min-width: 0; }

.report-row dd {
    font-family: var(--font-mono);
    text-align: right;
    min-width: 0;
}

/* ====== EXPORTS ====== */
.export-links {
    display: flex;
    gap: var(--space-small);
    flex-wrap: wrap;
}

/* ====== HOWTO ====== */
.howto {
    display: flex;
    flex-direction: column;
    gap: var(--space-small);
    font-size: var(--font-sm);
    padding-left: var(--space-large);
}

ol.howto { list-style: decimal; }
ul.howto { list-style: disc; }

/* ====== RESPONSIVE ====== */
@media (max-width: 1199px) {
    .workspace {
        grid-template-columns: minmax(0, 1fr);
        gap: var(--space-medium);
    }

    .settings {
        position: static;
        max-height: none;
        overflow: visible;
    }

    .settings-toggle { display: inline-flex; }

    .settings-body { display: none; }

    .settings.is-open .settings-body { display: flex; }

    .settings-body { gap: var(--space-medium); }
}

/* ====== UTILITIES ====== */
/* Last in the cascade on purpose: every component it hides is declared earlier
   at the same specificity, so no !important is needed. */
.is-hidden { display: none; }

@media (max-width: 767px) {
    .entry-table-wrap { max-height: 55vh; }

    .entry-cell input { width: 74px; }

    .panel-toolbar { gap: var(--space-small); }

    .segmented { width: 100%; }

    .segmented-btn { flex: 1 1 auto; }

    .export-links > .btn { flex: 1 1 140px; }
}
