/*
   Configuration builders. Only the design tokens of Fluent UI are used (--neutral-*, --accent-*...), so the styles
   follow the theme of the host (light / dark, accent colour). The classes start with cb- so that they do not mix
   with the styles of the host.
*/

.cb {
    --cb-gap: 1rem;
    --cb-radius: calc(var(--control-corner-radius, 4) * 1px);
    --cb-card-radius: calc(var(--layer-corner-radius, 8) * 1px + 4px);
    /* Fills (with white text) and texts: the texts are mixed with the foreground, so they are readable in both themes */
    --cb-error: #c50f1f;
    --cb-success: #107c10;
    --cb-error-text: color-mix(in srgb, #d13438 75%, var(--neutral-foreground-rest));
    --cb-warning-text: color-mix(in srgb, #da7b1f 80%, var(--neutral-foreground-rest));
    --cb-success-text: color-mix(in srgb, #13a10e 70%, var(--neutral-foreground-rest));
    --cb-code: color-mix(in srgb, #c02d76 70%, var(--neutral-foreground-rest));
    color: var(--neutral-foreground-rest);
}

.cb code,
.cb pre {
    font-family: Consolas, "Cascadia Mono", monospace;
}

.cb code {
    color: var(--cb-code);
    font-size: 0.875em;
}

.cb details > summary {
    cursor: pointer;
}

/* ---------- Header of a builder ---------- */
.cb-header {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem 1rem;
    margin-bottom: 1.25rem;
}

.cb-header > div {
    margin-right: auto;
}

.cb-header h1 {
    font-size: clamp(1.5rem, 2.5vw, 1.9rem);
    font-weight: 700;
    line-height: 1.2;
    margin: 0;
}

.cb-header p {
    margin: 0.25rem 0 0;
    color: var(--neutral-foreground-hint);
}

/* ---------- Cards ---------- */
.cb-card {
    background: var(--neutral-layer-1);
    border: 1px solid var(--neutral-stroke-divider-rest);
    border-radius: var(--cb-card-radius);
    box-shadow: var(--elevation-shadow-card-rest);
    min-width: 0;
}

.cb-card + .cb-card {
    margin-top: var(--cb-gap);
}

/* Cards side by side in a grid are spaced by the grid */
.cb-columns > .cb-card + .cb-card {
    margin-top: 0;
}

.cb-card-header {
    display: flex;
    align-items: baseline;
    gap: 0.5rem 1rem;
    flex-wrap: wrap;
    padding: 0.85rem 1.25rem;
    border-bottom: 1px solid var(--neutral-stroke-divider-rest);
}

.cb-card-header h2 {
    font-size: 1rem;
    font-weight: 600;
    margin: 0;
    margin-right: auto;
}

.cb-card-body {
    padding: 1.25rem;
}

.cb-card-body > :first-child {
    margin-top: 0;
}

.cb-card-body > :last-child {
    margin-bottom: 0;
}

/* Cards of the start screen and of the list of builders */
.cb-choice {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.cb-choice h2 {
    font-size: 1.1rem;
    font-weight: 600;
    margin: 0;
}

.cb-choice p,
.cb-choice ol {
    margin: 0;
}

.cb-choice ol {
    padding-left: 1.25rem;
    font-size: 0.9rem;
}

.cb-choice .cb-actions,
.cb-choice .cb-drop-zone {
    margin-top: auto;
}

/* ---------- Layout ---------- */
.cb-columns {
    display: grid;
    gap: var(--cb-gap);
    align-items: start;
}

.cb-columns-2 {
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 30rem), 1fr));
}

.cb-columns-3 {
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 18rem), 1fr));
}

.cb-columns-equal {
    align-items: stretch;
}

/* Output tab: settings and checks on the left, the file on the right */
.cb-output {
    display: grid;
    gap: var(--cb-gap);
    grid-template-columns: minmax(0, 1fr);
    align-items: start;
}

@media (min-width: 1100px) {
    .cb-output {
        grid-template-columns: minmax(18rem, 1fr) minmax(0, 2fr);
    }
}

/* Form fields: a 12-column grid, the fields span 3, 4, 6, 8 or 12 columns */
.cb-fields {
    display: grid;
    grid-template-columns: repeat(12, minmax(0, 1fr));
    gap: 0.85rem 1rem;
    align-items: end;
}

.cb-fields > * {
    grid-column: span 12;
    min-width: 0;
}

@media (min-width: 576px) {
    .cb-fields > .cb-span-3 { grid-column: span 3; }
    .cb-fields > .cb-span-4 { grid-column: span 4; }
    .cb-fields > .cb-span-6 { grid-column: span 6; }
    .cb-fields > .cb-span-8 { grid-column: span 8; }
}

.cb-fields fluent-text-field,
.cb-fields fluent-number-field,
.cb-fields fluent-select,
.cb-full {
    width: 100%;
    min-width: 0;
}

/* Long parameter names (NOTIFICATION_PROCESS_ID...) wrap instead of running into the next field */
.cb-fields fluent-text-field,
.cb-fields fluent-number-field,
.cb-fields label {
    white-space: normal;
    overflow-wrap: anywhere;
}

.cb-section-title {
    font-size: 0.8rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--neutral-foreground-hint);
    margin: 1.75rem 0 0.75rem;
    padding-bottom: 0.4rem;
    border-bottom: 1px solid var(--neutral-stroke-divider-rest);
}

.cb-options {
    margin-top: 1rem;
}

.cb-options h3 {
    font-size: 0.9rem;
    font-weight: 600;
    margin: 0 0 0.5rem;
}

.cb-stack {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

/* A row of fields, the .cb-grow one takes the free space */
.cb-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.cb-grow {
    flex: 1 1 auto;
    min-width: 0;
}

.cb-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
}

.cb-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 0.75rem;
    margin-bottom: 0.75rem;
}

.cb-toolbar .cb-actions {
    margin-left: auto;
}

/* ---------- Texts ---------- */
.cb-help {
    font-size: 0.85rem;
    color: var(--neutral-foreground-hint);
    margin: 0.75rem 0;
    line-height: 1.5;
}

/* Also after the name of a parameter in a label: "LOCAL_IP network card for the BMS" */
.cb-hint {
    margin-left: 0.35rem;
    font-size: 0.8rem;
    font-weight: 400;
    color: var(--neutral-foreground-hint);
}

.cb-muted {
    color: var(--neutral-foreground-hint);
}

.cb-warning-text {
    color: var(--cb-warning-text);
}

.cb-success-text {
    color: var(--cb-success-text);
}

.cb-message {
    margin-bottom: var(--cb-gap);
}

.cb-message ul {
    margin: 0.25rem 0 0;
    padding-left: 1.2rem;
}

/* A message (fluent-message-bar) with a button at its end */
.cb-message-action {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem 1rem;
}

.cb-message-action > span {
    flex: 1 1 20rem;
}

/* ---------- Native fields (tables and grids) ---------- */
/*
   Fluent web components are too heavy for tables with hundreds of rows of fields, so the tables use native fields
   styled like the Fluent ones.
*/
.cb-input {
    box-sizing: border-box;
    font: inherit;
    font-size: 0.85rem;
    height: 1.9rem;
    padding: 0 0.45rem;
    color: var(--neutral-foreground-rest);
    background: var(--neutral-fill-input-rest, var(--neutral-layer-1));
    border: 1px solid var(--neutral-stroke-rest);
    border-bottom-color: var(--neutral-stroke-strong-rest, var(--neutral-stroke-rest));
    border-radius: var(--cb-radius);
    min-width: 0;
}

.cb-input:hover:not(:disabled) {
    border-color: var(--neutral-stroke-hover, var(--neutral-stroke-rest));
}

.cb-input:focus {
    outline: none;
    border-color: var(--accent-fill-rest);
    box-shadow: inset 0 -1px 0 var(--accent-fill-rest);
}

.cb-input:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

select.cb-input {
    padding-right: 0.2rem;
    cursor: pointer;
}

.cb-input::placeholder {
    color: var(--neutral-foreground-hint);
}

.cb .cb-check {
    width: 1rem;
    height: 1rem;
    margin: 0;
    accent-color: var(--accent-fill-rest);
    cursor: pointer;
    vertical-align: middle;
}

.cb .cb-check:disabled {
    cursor: not-allowed;
    opacity: 0.45;
}

.cb-field-label {
    display: block;
    font-size: 0.8rem;
    color: var(--neutral-foreground-hint);
    margin-bottom: 0.2rem;
}

/* An input with a text or a button after it */
.cb-input-group {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    white-space: nowrap;
}

.w-addr { width: 6rem; }
.w-sub { width: 4.5rem; }
.w-mv { width: 6.5rem; }
.w-states { width: 6rem; }
.w-text { width: 8rem; }
.w-template { width: 13rem; }
.w-desc { width: 20rem; }
.w-search { width: 14rem; }

/* ---------- Tables ---------- */
.cb-table-scroll {
    overflow-x: auto;
}

.cb-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}

.cb-table th {
    text-align: left;
    font-weight: 600;
    font-size: 0.8rem;
    color: var(--neutral-foreground-hint);
    white-space: nowrap;
    padding: 0.4rem 0.4rem;
    border-bottom: 1px solid var(--neutral-stroke-rest);
}

.cb-table td {
    padding: 0.2rem 0.4rem;
    border-bottom: 1px solid var(--neutral-stroke-divider-rest);
    vertical-align: middle;
}

.cb-table .cb-num {
    text-align: right;
}

.cb-table .cb-center {
    text-align: center;
}

.cb-table .cb-nowrap {
    white-space: nowrap;
}

.cb-table tr.cb-disabled > td {
    color: var(--neutral-foreground-hint);
}

/* The points: a scrolling grid with a sticky header */
.cb-points {
    max-height: calc(100vh - 20rem);
    min-height: 20rem;
    overflow: auto;
    border: 1px solid var(--neutral-stroke-divider-rest);
    border-radius: var(--cb-radius);
    background: var(--neutral-layer-1);
}

.cb-points thead th {
    position: sticky;
    top: 0;
    z-index: 1;
    background: var(--neutral-layer-2);
}

.cb-points tbody tr:hover > td {
    background: var(--neutral-fill-stealth-hover);
}

.cb-points .cb-issue {
    width: 1.5rem;
    text-align: center;
    cursor: help;
}

.cb-points tr.cb-row-error > td {
    background: color-mix(in srgb, var(--cb-error) 12%, var(--neutral-layer-1));
}

.cb-points tr.cb-row-warning > td {
    background: color-mix(in srgb, #eaa300 16%, var(--neutral-layer-1));
}

.cb-delete {
    font: inherit;
    border: 0;
    background: none;
    padding: 0.1rem 0.35rem;
    border-radius: var(--cb-radius);
    color: var(--cb-error-text);
    cursor: pointer;
}

.cb-delete:hover {
    background: color-mix(in srgb, var(--cb-error) 12%, transparent);
}

/* Bulk edit of the selected points */
.cb-bulk {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 0.5rem 0.75rem;
    padding: 0.6rem 0.9rem;
    margin-bottom: 0.75rem;
    border-radius: var(--cb-radius);
    background: var(--neutral-layer-3, var(--neutral-layer-2));
    border: 1px solid var(--neutral-stroke-rest);
}

.cb-bulk strong {
    align-self: center;
    margin-right: 0.5rem;
}

.cb-grid-info {
    font-size: 0.8rem;
    color: var(--neutral-foreground-hint);
    margin-bottom: 0.4rem;
}

/* ---------- Badges in the tabs ---------- */
.cb-badge {
    display: inline-block;
    min-width: 1.25rem;
    margin-left: 0.4rem;
    padding: 0 0.4rem;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
    line-height: 1.25rem;
    text-align: center;
    color: #fff;
    background: var(--neutral-foreground-hint);
}

.cb-badge-error {
    background: var(--cb-error);
}

.cb-badge-success {
    background: var(--cb-success);
}

/* ---------- Tabs and steps ---------- */
.cb-tabs {
    margin-bottom: var(--cb-gap);
}

.cb-tab-content {
    padding-top: var(--cb-gap);
}

.cb-steps {
    display: flex;
    gap: 0.5rem;
    margin-top: var(--cb-gap);
    padding-top: var(--cb-gap);
    border-top: 1px solid var(--neutral-stroke-divider-rest);
}

.cb-steps .cb-next {
    margin-left: auto;
}

/* ---------- Previews ---------- */
.cb-preview {
    max-height: 16rem;
    overflow: auto;
    font-size: 0.78rem;
    background: var(--neutral-layer-2);
    padding: 0.6rem 0.75rem;
    border-radius: var(--cb-radius);
    margin: 0.75rem 0;
}

.cb-file-preview {
    max-height: calc(100vh - 14rem);
    min-height: 16rem;
    overflow: auto;
    margin: 0;
    padding: 0.75rem 1.25rem;
    font-size: 0.78rem;
    white-space: pre;
}

.cb-issues {
    max-height: calc(100vh - 30rem);
    min-height: 10rem;
    overflow: auto;
}

/* ---------- Files ---------- */
/* The file input covers the whole zone, so that a file can be dropped anywhere on it or chosen by a click */
.cb-drop-zone {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    min-height: 8rem;
    padding: 1rem;
    border: 2px dashed var(--neutral-stroke-rest);
    border-radius: 0.75rem;
    color: var(--neutral-foreground-hint);
    transition: border-color 0.15s, background-color 0.15s;
}

.cb-drop-zone.cb-compact {
    min-height: 0;
    justify-content: flex-start;
}

.cb-drop-zone:hover,
.cb-drop-zone:focus-within,
.cb-drop-zone.cb-drag-over {
    border-color: var(--accent-fill-rest);
    background: var(--neutral-fill-stealth-hover);
}

.cb-drop-zone.cb-has-file {
    border-style: solid;
}

.cb-drop-zone input[type=file] {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    cursor: pointer;
}

.cb-drop-zone > span {
    display: flex;
    flex-direction: column;
    pointer-events: none;
}

.cb-drop-zone strong {
    color: var(--neutral-foreground-rest);
    word-break: break-all;
}

.cb-drop-zone small {
    font-size: 0.8rem;
}

/* ---------- List of problems ---------- */
.cb-issue-list ul {
    padding-left: 1.2rem;
    margin: 0.35rem 0 0.75rem;
    font-size: 0.85rem;
}

.cb-issue-list summary {
    font-weight: 600;
}

.cb-issue-list .cb-severity-error {
    color: var(--cb-error-text);
}

.cb-issue-list .cb-severity-warning {
    color: var(--cb-warning-text);
}

.cb-issue-list .cb-severity-info {
    color: var(--neutral-foreground-hint);
    font-weight: 400;
}
