:root {
    color-scheme: light;

    --brand: #03173d;
    --brand-bright: #1b6ec2;

    --surface: #ffffff;
    --surface-sunken: #f4f5f7;
    --border: #d6d5d5;
    --text: #16181d;
    --text-muted: #5b6068;
    --link: #0060a8;

    --danger: #b32121;
    --success: #1c8043;

    /* Deliberately generous: the primary use is a wet finger on a boat deck. */
    --touch-target: 3rem;
    --radius: 6px;
}

*, *::before, *::after {
    box-sizing: border-box;
}

html {
    -webkit-text-size-adjust: 100%;
}

body {
    margin: 0;
    background-color: var(--surface);
    color: var(--text);
    font-family: system-ui, -apple-system, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    font-size: 1rem;
    line-height: 1.5;
}

h1, h2, h3 {
    line-height: 1.2;
    margin: 0 0 0.5em;
}

h1 {
    font-size: clamp(1.5rem, 1.2rem + 1.5vw, 2rem);
}

h1:focus {
    outline: none;
}

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

code {
    color: #c02d76;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

/* --------------------------------------------------------------------- controls -- */

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

input,
select,
textarea {
    min-height: var(--touch-target);
    padding: 0.5rem 0.75rem;
    background-color: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

/* Depth, time and pressure are read at a glance and compared against a table, so they are
   tabular and larger than body text even on the narrowest screen. */
input[type="number"] {
    font-size: 1.125rem;
    font-variant-numeric: tabular-nums;
}

button {
    min-height: var(--touch-target);
    padding: 0.5rem 1.25rem;
    background-color: var(--brand-bright);
    border: 1px solid transparent;
    border-radius: var(--radius);
    color: #fff;
    cursor: pointer;
}

button:hover {
    background-color: #1861ac;
}

button:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

:focus-visible {
    outline: 3px solid var(--brand-bright);
    outline-offset: 2px;
}

/* ------------------------------------------------------------------- validation -- */

.valid.modified:not([type=checkbox]) {
    outline: 1px solid var(--success);
}

.invalid {
    outline: 1px solid var(--danger);
}

.validation-message {
    color: var(--danger);
    font-size: 0.875rem;
}

/* ------------------------------------------------------------------------ forms -- */

button.secondary {
    background-color: transparent;
    border-color: var(--border);
    color: var(--text);
}

button.secondary:hover {
    background-color: var(--surface-sunken);
}

.card {
    margin: 0 0 1rem;
    padding: 1rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.card h3 {
    margin: 1.25rem 0 0.5rem;
}

.field-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 14rem), 1fr));
    gap: 0.75rem 1rem;
    align-items: start;
}

.field {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    min-width: 0;
}

.field-label {
    color: var(--text-muted);
    font-size: 0.875rem;
}

/* The unit sits inside the box, so every input in a row is the same width whatever its unit. */
.field-input {
    display: flex;
    align-items: center;
    min-height: var(--touch-target);
    background-color: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.field-input:focus-within {
    outline: 3px solid var(--brand-bright);
    outline-offset: 2px;
}

.field-input:has(.invalid) {
    border-color: var(--danger);
}

.field-input input {
    flex: 1;
    min-width: 0;
    min-height: 0;
    border: 0;
    background: transparent;
    outline: none;
}

.unit {
    padding-right: 0.75rem;
    color: var(--text-muted);
    white-space: nowrap;
}

.field-check {
    flex-direction: row;
    align-items: center;
    min-height: var(--touch-target);
}

.field-check input {
    width: 1.5rem;
    height: 1.5rem;
    min-height: 0;
}

.field-check .field-label {
    color: var(--text);
    font-size: 1rem;
}

.button-row {
    display: flex;
    gap: 0.5rem;
}

.button-row button {
    flex: 1;
}

details {
    border-top: 1px solid var(--border);
}

summary {
    min-height: var(--touch-target);
    display: flex;
    align-items: center;
    cursor: pointer;
    font-weight: 600;
}

details[open] > summary {
    margin-bottom: 0.5rem;
}

details > .field-grid {
    padding-bottom: 1rem;
}

/* Levels and cylinders are edited as table rows: the header names each column once, so a row is
   one line on a phone. Fixed layout shares the width out instead of growing with the content. */
.input-table {
    margin: 0 0 0.75rem;
    table-layout: fixed;
}

.input-table.cylinders-imperial {
    min-width: 23rem;
}

.input-table th,
.input-table td {
    padding: 0.15rem;
    border-bottom: 0;
    white-space: normal;
}

.input-table th {
    padding-bottom: 0;
    font-weight: 400;
}

.input-table th .unit {
    padding: 0;
}

.input-table .col-remove {
    width: calc(var(--touch-target) + 0.3rem);
}

.input-table .col-role {
    width: 5.25rem;
}

.cell-input {
    width: 100%;
    padding: 0.5rem 0.25rem;
    font-size: 1rem;
}

.cell-input[type="number"] {
    appearance: textfield;
    -moz-appearance: textfield;
}

.cell-input::-webkit-inner-spin-button,
.cell-input::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.cell-input.invalid {
    outline: 0;
    border-color: var(--danger);
}

.cell-static {
    display: flex;
    align-items: center;
    min-height: var(--touch-target);
    padding: 0 0.35rem;
    color: var(--text-muted);
}

.row-issues td {
    padding-top: 0;
}

.row-issues p {
    margin: 0;
}

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
}

/* ----------------------------------------------------------------- page header -- */

.plan-header {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.75rem;
    margin: 0 0 1rem;
}

.plan-name {
    flex: 1;
    min-width: 0;
    font-size: 1.25rem;
    font-weight: 600;
}

.icon-button {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: var(--touch-target);
    padding: 0;
    background-color: transparent;
    border-color: var(--border);
    color: var(--text);
}

a.icon-button {
    flex-shrink: 0;
    min-height: var(--touch-target);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    text-decoration: none;
}

.icon-button:hover {
    background-color: var(--surface-sunken);
}

.icon-button svg {
    width: 1.5rem;
    height: 1.5rem;
    fill: currentColor;
}

.badge {
    position: absolute;
    top: 0.35rem;
    right: 0.35rem;
    width: 0.6rem;
    height: 0.6rem;
    border-radius: 50%;
    background-color: var(--danger);
}

/* ------------------------------------------------------------------------ chart -- */

.profile-chart {
    margin: 0 0 1rem;
}

.profile-chart svg {
    display: block;
    width: 100%;
    height: auto;
}

.chart-water {
    fill: #eef5fc;
}

.chart-grid {
    stroke: var(--border);
    stroke-width: 0.6;
}

.chart-label,
.chart-caption {
    fill: var(--text-muted);
    font-size: 10px;
    font-variant-numeric: tabular-nums;
}

.chart-dive {
    fill: rgba(27, 110, 194, 0.12);
}

.chart-line {
    fill: none;
    stroke: var(--brand-bright);
    stroke-width: 2;
    stroke-linejoin: round;
}

.chart-stop {
    stroke: #c98a00;
    stroke-width: 4;
    stroke-linecap: round;
}

.chart-switch {
    stroke: var(--success);
    stroke-width: 4;
    stroke-linecap: round;
}

.chart-switch-dot {
    fill: var(--success);
}

.chart-gas {
    fill: var(--success);
    font-size: 10px;
    font-weight: 600;
}

/* ------------------------------------------------------------------------ share -- */

.share-sheet {
    position: fixed;
    inset: auto 0 0 0;
    z-index: 11;
    max-height: 90vh;
    overflow-y: auto;
    padding: 1rem;
    background-color: var(--surface);
    border-radius: 12px 12px 0 0;
    box-shadow: 0 -2px 12px rgba(0, 0, 0, 0.25);
}

@media (min-width: 641px) {
    .share-sheet {
        inset: 15vh auto auto 50%;
        width: 24rem;
        transform: translateX(-50%);
        border-radius: var(--radius);
    }
}

.share-options {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.share-status {
    margin: 1rem 0 0;
    color: var(--text-muted);
}

.print-only {
    display: none;
}

@media print {
    .no-print,
    .drawer,
    .drawer-backdrop,
    .share-sheet,
    #blazor-error-ui {
        display: none !important;
    }

    .print-only {
        display: block;
    }

    .card {
        border: 0;
        padding: 0;
    }

    .figures div,
    .gas-card,
    .row-stop td {
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

    .profile-chart,
    .gas-card,
    tr {
        break-inside: avoid;
    }
}

/* ----------------------------------------------------------------------- series -- */

.dive-tabs {
    display: flex;
    gap: 0.5rem;
    margin: 0 0 1rem;
    overflow-x: auto;
}

.dive-tab {
    position: relative;
    flex-shrink: 0;
    background-color: transparent;
    border-color: var(--border);
    color: var(--text);
}

.dive-tab:hover {
    background-color: var(--surface-sunken);
}

.dive-tab.selected {
    background-color: var(--brand-bright);
    border-color: var(--brand-bright);
    color: #fff;
}

.dive-tab.add {
    border-style: dashed;
}

.card-header {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    margin: 0 0 0.5rem;
}

.card-header h2 {
    margin: 0;
}

.surface-interval {
    margin: 0 0 1rem;
}

.series-row {
    cursor: pointer;
}

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

.series-waiting {
    color: var(--text-muted);
}

/* ------------------------------------------------------------------------ plans -- */

.page-title {
    flex: 1;
    margin: 0;
}

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

.app-banner {
    position: fixed;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 30;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 0.5rem 1rem;
    padding: 0.75rem 1rem calc(0.75rem + env(safe-area-inset-bottom));
    background-color: var(--brand);
    color: #fff;
}

.app-banner-actions {
    display: flex;
    gap: 0.5rem;
}

button.app-banner-dismiss {
    background-color: transparent;
    border-color: rgba(255, 255, 255, 0.5);
}

button.app-banner-dismiss:hover {
    background-color: rgba(255, 255, 255, 0.1);
}

/* The banner is fixed over the page, so the page ends above it instead of under it. */
body:has(.app-banner) {
    padding-bottom: 8rem;
}

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

.plan-list {
    margin: 0;
    padding: 0;
    list-style: none;
}

.plan-item {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    margin: 0 0 0.75rem;
    padding: 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.plan-link {
    display: flex;
    flex: 1 1 14rem;
    flex-direction: column;
    min-width: 0;
    color: inherit;
    text-decoration: none;
}

.plan-item-name {
    overflow: hidden;
    font-size: 1.1rem;
    font-weight: 600;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.plan-item-meta {
    color: var(--text-muted);
    font-size: 0.875rem;
}

/* ----------------------------------------------------------------------- drawer -- */

.drawer-backdrop {
    position: fixed;
    inset: 0;
    z-index: 10;
    background-color: rgba(0, 0, 0, 0.4);
}

.drawer {
    position: fixed;
    inset: 0 0 0 auto;
    z-index: 11;
    width: min(100%, 36rem);
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 1rem;
    background-color: var(--surface);
    box-shadow: -2px 0 12px rgba(0, 0, 0, 0.25);
}

.drawer-header {
    position: sticky;
    top: -1rem;
    z-index: 1;
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin: -1rem -1rem 1rem;
    padding: 0.75rem 1rem;
    background-color: var(--surface);
    border-bottom: 1px solid var(--border);
}

.drawer-header h2 {
    margin: 0;
}

.alert .secondary {
    margin-top: 0.75rem;
}

/* ---------------------------------------------------------------------- results -- */

.figures {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(8rem, 1fr));
    gap: 0.75rem;
    margin: 0 0 1rem;
}

.figures div {
    padding: 0.5rem 0.75rem;
    background-color: var(--surface-sunken);
    border-radius: var(--radius);
}

.figures dt {
    color: var(--text-muted);
    font-size: 0.875rem;
}

.figures dd {
    margin: 0;
    font-size: 1.25rem;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

.alert {
    margin: 0 0 1rem;
    padding: 0.75rem 1rem;
    border-left: 4px solid;
    border-radius: var(--radius);
    background-color: var(--surface-sunken);
}

.alert p,
.alert ul {
    margin: 0;
}

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

.alert-warning {
    border-color: #c98a00;
}

.table-scroll {
    overflow-x: auto;
}

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

th,
td {
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid var(--border);
    text-align: left;
    white-space: nowrap;
}

th {
    color: var(--text-muted);
    font-size: 0.875rem;
    font-weight: 600;
}

.number {
    font-variant-numeric: tabular-nums;
    text-align: right;
}

caption {
    caption-side: bottom;
    padding-top: 0.5rem;
    color: var(--text-muted);
    font-size: 0.875rem;
    text-align: left;
}

.row-stop td {
    background-color: var(--surface-sunken);
}

td.phase {
    width: 2rem;
    padding-right: 0;
    line-height: 0;
}

.phase-icon {
    width: 1.25rem;
    height: 1.25rem;
    fill: none;
    stroke: var(--text-muted);
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.phase-stop,
.phase-gasswitch {
    stroke: var(--brand-bright);
}

.gas-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 15rem), 1fr));
    gap: 0.75rem;
}

.gas-card {
    padding: 0.75rem;
    background-color: var(--surface-sunken);
    border-left: 4px solid var(--border);
    border-radius: var(--radius);
}

.gas-card-danger {
    border-left-color: var(--danger);
}

.gas-missing dt,
.gas-missing dd {
    color: var(--danger);
    font-weight: 600;
}

.gas-card h4 {
    margin: 0 0 0.5rem;
    font-size: 1.1rem;
}

.gas-card h4 span {
    color: var(--text-muted);
    font-size: 0.875rem;
    font-weight: 400;
}

.gas-card dl {
    margin: 0;
}

.gas-card dl div {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.2rem 0;
}

.gas-card dt {
    color: var(--text-muted);
}

.gas-card dd {
    margin: 0;
    font-variant-numeric: tabular-nums;
}

/* ------------------------------------------------------------------------ phone -- */

.drawer > .card {
    margin: 0;
    padding: 0 0 1rem;
    border: 0;
    border-radius: 0;
}

.drawer > .card + .card {
    padding-top: 1rem;
    border-top: 1px solid var(--border);
}

@media (max-width: 640px) {
    .card {
        padding: 0.75rem;
    }

    th,
    td {
        padding: 0.45rem 0.4rem;
    }

    .profile td,
    .profile th {
        padding: 0.45rem 0.3rem;
        font-size: 0.875rem;
    }

    .figures {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* ------------------------------------------------------------------ blazor ui -- */

#blazor-error-ui {
    color-scheme: light only;
    background: lightyellow;
    color: #16181d;
    bottom: 0;
    box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.2);
    display: none;
    left: 0;
    padding: 0.6rem 1.25rem 0.7rem 1.25rem;
    position: fixed;
    width: 100%;
    z-index: 1000;
}

#blazor-error-ui .dismiss {
    cursor: pointer;
    position: absolute;
    right: 0.75rem;
    top: 0.5rem;
}

.blazor-error-boundary {
    background: var(--danger);
    padding: 1rem;
    color: #fff;
}

.blazor-error-boundary::after {
    content: "An error has occurred.";
}

/* Driven by --blazor-load-percentage, which the framework sets while the runtime downloads. */
.loading-progress {
    position: absolute;
    display: block;
    width: 8rem;
    height: 8rem;
    inset: 20vh 0 auto 0;
    margin: 0 auto;
}

.loading-progress circle {
    fill: none;
    stroke: var(--border);
    stroke-width: 0.6rem;
    transform-origin: 50% 50%;
    transform: rotate(-90deg);
}

.loading-progress circle:last-child {
    stroke: var(--brand-bright);
    stroke-dasharray: calc(3.141 * var(--blazor-load-percentage, 0%) * 0.8), 500%;
    transition: stroke-dasharray 0.05s ease-in-out;
}

.loading-progress-text {
    position: absolute;
    text-align: center;
    font-weight: bold;
    inset: calc(20vh + 3.25rem) 0 auto 0.2rem;
}

.loading-progress-text::after {
    content: var(--blazor-load-percentage-text, "Loading");
}
