/*
 * Sendiio forms: one quiet layout for the app's forms, first used by the API keys page, and for the
 * tables that list what the forms make (.sf-table, at the end of this file).
 *
 * Every rule is scoped to .sf-form or .sf-table, so loading this file on every page (partials.styles)
 * changes nothing until a form or table opts in. Bootstrap's .form-control and .btn keep working inside
 * it (select2 and the other plugins look for them); only their look changes.
 *
 *   <form class="sf-form">
 *     <p class="sf-intro">What the form does.</p>
 *
 *     <div class="sf-row">
 *       <div class="sf-row-head">
 *         <label class="sf-label" for="name">Name <span class="sf-optional">optional</span></label>
 *         <p class="sf-help">What the field is for.</p>
 *       </div>
 *       <div class="sf-row-body">
 *         <input type="text" class="form-control" id="name" name="name">
 *       </div>
 *     </div>
 *
 *     <div class="sf-footer">
 *       <p class="sf-footer-note">What happens next.</p>
 *       <button type="submit" class="btn btn-primary sf-button">Save changes</button>
 *     </div>
 *   </form>
 *
 * Also: .sf-section (a titled group of rows), .sf-row--top (the label level with the top of the
 * control: for switches and sub-labelled fields), .sf-fields with .sf-sublabel (several fields in one
 * row), .sf-inline (a field and its button), .sf-static (a value that can't be changed here),
 * .sf-choices with .sf-choice-item (radio tiles; .sf-reach inside shows a level of 1 to 3),
 * .sf-switch (a checkbox shown as a switch: put a hidden input of the same name with value 0 before
 * it, so "off" is sent too), .sf-tags, .sf-badge, and .sf-button--quiet / --danger.
 */

.sf-form,
.sf-table {
    --sf-ink: #2c2640;
    --sf-muted: #67637a;
    --sf-placeholder: #a09cb1;
    --sf-line: #e9e7f0;
    --sf-field-line: #d3d0de;
    --sf-field-hover: #b3afc4;
    --sf-surface: #fff;
    --sf-surface-sunk: #f8f7fb;
    --sf-track: #e1deea;
    --sf-accent: #975aff;
    --sf-accent-ink: #6b3fd6;
    --sf-accent-tint: #f7f2ff;
    --sf-caution: #d08700;
    --sf-positive: #16a06c;
    --sf-ring: 0 0 0 3px rgba(151, 90, 255, .24);
    --sf-radius: 8px;

    color: var(--sf-ink);
}

.sf-form .sf-intro {
    max-width: 68ch;
    margin: 0 0 20px;
    font-size: 14.5px;
    line-height: 1.6;
    color: var(--sf-muted);
}

/* Rows: the label and its help on the left, the control on the right; stacked on small screens */

.sf-form .sf-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    row-gap: 12px;
    padding: 22px 0;
    border-top: 1px solid var(--sf-line);
}

.sf-form .sf-row-head,
.sf-form .sf-row-body {
    min-width: 0;
}

.sf-form .sf-row-body {
    max-width: 600px;
}

.sf-form .sf-row-body--wide {
    max-width: 760px;
}

.sf-form .sf-label {
    display: block;
    margin: 0;
    font-size: 14px;
    font-weight: 600;
    line-height: 1.4;
    letter-spacing: 0;
    text-transform: none;
    color: var(--sf-ink);
}

.sf-form .sf-optional {
    margin-left: 4px;
    font-weight: 400;
    color: var(--sf-muted);
}

.sf-form .sf-help {
    max-width: 46ch;
    margin: 4px 0 0;
    font-size: 13px;
    line-height: 1.55;
    color: var(--sf-muted);
}

.sf-form .sf-static {
    margin: 0;
    font-size: 15px;
    line-height: 1.5;
    color: var(--sf-ink);
}

@media (min-width: 992px) {
    .sf-form .sf-row {
        grid-template-columns: minmax(200px, 16rem) minmax(0, 1fr);
        column-gap: 48px;
    }

    /* The label sits level with the text of a 42px field */
    .sf-form .sf-row-head {
        padding-top: 10px;
    }

    .sf-form .sf-static {
        padding-top: 9px;
    }

    .sf-form .sf-row--top .sf-row-head {
        padding-top: 0;
    }
}

/* Sections: a title and a line on what the group is for, then its rows */

.sf-form .sf-section + .sf-section {
    margin-top: 40px;
}

.sf-form .sf-section-head {
    padding-bottom: 18px;
}

.sf-form .sf-section-title {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 0;
    font-size: 17px;
    font-weight: 600;
    line-height: 1.35;
    letter-spacing: 0;
    text-transform: none;
    color: var(--sf-ink);
}

.sf-form .sf-section-desc {
    max-width: 68ch;
    margin: 4px 0 0;
    font-size: 13.5px;
    line-height: 1.55;
    color: var(--sf-muted);
}

.sf-form .sf-badge {
    padding: 2px 9px;
    font-size: 11.5px;
    font-weight: 600;
    line-height: 1.5;
    color: #8a5a00;
    background: #fff1d6;
    border-radius: 999px;
}

/* Several fields in one row, each with a sub-label */

.sf-form .sf-fields {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 14px 16px;
}

.sf-form .sf-fields--stack {
    grid-template-columns: minmax(0, 1fr);
}

@media (min-width: 576px) {
    .sf-form .sf-fields--2 {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

.sf-form .sf-sublabel {
    display: block;
    margin: 0 0 6px;
    font-size: 13px;
    font-weight: 500;
    line-height: 1.4;
    letter-spacing: 0;
    text-transform: none;
    color: var(--sf-muted);
}

.sf-form .sf-inline {
    display: flex;
    align-items: center;
    gap: 8px;
}

.sf-form .sf-inline > .form-control {
    flex: 1 1 auto;
    min-width: 0;
}

.sf-form .sf-inline > .btn {
    flex: none;
}

.sf-form .sf-row-body > * + .sf-actions {
    margin-top: 14px;
}

.sf-form .sf-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin: 0;
    padding: 0;
    list-style: none;
}

.sf-form .sf-tags li {
    padding: 4px 11px;
    font-size: 13px;
    line-height: 1.5;
    color: var(--sf-accent-ink);
    background: var(--sf-accent-tint);
    border-radius: 999px;
}

@media (min-width: 992px) {
    .sf-form .sf-tags {
        padding-top: 7px;
    }
}

/* Fields */

.sf-form .form-control {
    height: 42px;
    padding: 9px 12px;
    font-size: 15px;
    line-height: 1.5;
    color: var(--sf-ink);
    background-color: var(--sf-surface);
    border: 1px solid var(--sf-field-line);
    border-radius: var(--sf-radius);
    box-shadow: none;
    transition: border-color .15s ease, box-shadow .15s ease;
}

.sf-form textarea.form-control {
    height: auto;
    min-height: 88px;
    resize: vertical;
}

.sf-form .form-control::placeholder {
    color: var(--sf-placeholder);
    opacity: 1;
}

/* The theme slides the placeholder sideways on focus */
.sf-form .form-control:focus::placeholder {
    transform: none;
}

.sf-form .form-control:hover {
    border-color: var(--sf-field-hover);
}

.sf-form .form-control:focus {
    border-color: var(--sf-accent);
    box-shadow: var(--sf-ring);
    outline: 0;
}

.sf-form select.form-control {
    padding-right: 38px;
    cursor: pointer;
    -webkit-appearance: none;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5l5 5 5-5' fill='none' stroke='%2367637a' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 14px center;
    background-size: 12px 8px;
}

/* A field shown but not changed here */
.sf-form .form-control[readonly],
.sf-form .form-control:disabled {
    color: var(--sf-ink);
    background-color: var(--sf-surface-sunk);
    border-color: var(--sf-line);
    cursor: default;
}

.sf-form .form-control[readonly]:focus {
    border-color: var(--sf-field-hover);
    box-shadow: none;
}

/* Select2 boxes (single), drawn like the fields; the dropdown itself is appended to <body> */
.sf-form .select2-container--default .select2-selection--single {
    height: 42px;
    background: var(--sf-surface);
    border: 1px solid var(--sf-field-line);
    border-radius: var(--sf-radius);
    outline: 0;
    transition: border-color .15s ease, box-shadow .15s ease;
}

.sf-form .select2-container--default .select2-selection--single .select2-selection__rendered {
    height: auto;
    padding: 0 38px 0 12px;
    font-size: 15px;
    line-height: 40px;
    color: var(--sf-ink);
}

.sf-form .select2-container--default .select2-selection--single .select2-selection__placeholder {
    color: var(--sf-placeholder);
}

.sf-form .select2-container--default .select2-selection--single .select2-selection__arrow {
    top: 0;
    right: 8px;
    width: 24px;
    height: 40px;
    background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5l5 5 5-5' fill='none' stroke='%2367637a' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") no-repeat center / 12px 8px;
}

.sf-form .select2-container--default .select2-selection--single .select2-selection__arrow b {
    display: none;
}

.sf-form .select2-container--default:hover .select2-selection--single {
    border-color: var(--sf-field-hover);
}

.sf-form .select2-container--default.select2-container--focus .select2-selection--single,
.sf-form .select2-container--default.select2-container--open .select2-selection--single {
    border-color: var(--sf-accent);
    box-shadow: var(--sf-ring);
}

/* For values typed as code: IP addresses, hosts, tokens */
.sf-form .sf-code {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
    font-size: 14px;
}

/* Radio tiles */

/* auto-fit: two tiles share the row's width instead of leaving a third column empty */
.sf-form .sf-choices {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 12px;
}

.sf-form .sf-choice-item {
    position: relative;
}

.sf-form .sf-choice-input {
    position: absolute;
    top: 0;
    left: 0;
    width: 1px;
    height: 1px;
    opacity: 0;
    pointer-events: none;
}

.sf-form .sf-choice {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 6px;
    height: 100%;
    margin: 0;
    padding: 14px 44px 16px 16px;
    font-size: 13px;
    font-weight: 400;
    line-height: 1.5;
    letter-spacing: 0;
    text-transform: none;
    color: var(--sf-muted);
    background: var(--sf-surface);
    border: 1px solid var(--sf-field-line);
    border-radius: 10px;
    cursor: pointer;
    transition: border-color .15s ease, background-color .15s ease, box-shadow .15s ease;
}

/* The radio mark */
.sf-form .sf-choice::after {
    content: "";
    position: absolute;
    top: 15px;
    right: 15px;
    width: 18px;
    height: 18px;
    border: 1.5px solid var(--sf-field-line);
    border-radius: 50%;
    background: var(--sf-surface);
    transition: border-color .15s ease, border-width .15s ease;
}

.sf-form .sf-choice:hover {
    border-color: var(--sf-field-hover);
}

.sf-form .sf-choice-input:checked + .sf-choice {
    background: var(--sf-accent-tint);
    border-color: var(--sf-accent);
    box-shadow: inset 0 0 0 1px var(--sf-accent);
}

.sf-form .sf-choice-input:checked + .sf-choice::after {
    border: 5px solid var(--sf-accent);
}

.sf-form .sf-choice-input:focus-visible + .sf-choice {
    box-shadow: inset 0 0 0 1px var(--sf-accent), var(--sf-ring);
}

.sf-form .sf-choice-title {
    font-size: 14px;
    font-weight: 600;
    line-height: 1.35;
    color: var(--sf-ink);
}

/* How far a choice reaches, as 1 to 3 rising bars; the third level is the one that can cost money.
   Tables show the same bars next to what a record may do. */
.sf-form .sf-reach,
.sf-table .sf-reach {
    display: inline-flex;
    align-items: flex-end;
    gap: 3px;
    height: 14px;
    margin-bottom: 4px;
}

.sf-form .sf-reach span,
.sf-table .sf-reach span {
    width: 5px;
    border-radius: 1.5px;
    background: var(--sf-track);
}

.sf-form .sf-reach span:nth-child(1),
.sf-table .sf-reach span:nth-child(1) {
    height: 6px;
}

.sf-form .sf-reach span:nth-child(2),
.sf-table .sf-reach span:nth-child(2) {
    height: 10px;
}

.sf-form .sf-reach span:nth-child(3),
.sf-table .sf-reach span:nth-child(3) {
    height: 14px;
}

.sf-form .sf-reach[data-level="1"] span:nth-child(-n+1),
.sf-form .sf-reach[data-level="2"] span:nth-child(-n+2),
.sf-table .sf-reach[data-level="1"] span:nth-child(-n+1),
.sf-table .sf-reach[data-level="2"] span:nth-child(-n+2) {
    background: var(--sf-accent);
}

.sf-form .sf-reach[data-level="3"] span,
.sf-table .sf-reach[data-level="3"] span {
    background: var(--sf-caution);
}

/* Switch: a checkbox with role="switch" */

.sf-form .sf-switch {
    display: flex;
    align-items: flex-start;
    gap: 12px;
}

.sf-form .sf-choices + .sf-switch {
    margin-top: 20px;
}

.sf-form .sf-switch-input {
    position: relative;
    flex: none;
    width: 36px;
    height: 20px;
    margin: 1px 0 0;
    border-radius: 999px;
    background: var(--sf-track);
    cursor: pointer;
    -webkit-appearance: none;
    appearance: none;
    transition: background-color .15s ease;
}

.sf-form .sf-switch-input::before {
    content: "";
    position: absolute;
    top: 2px;
    left: 2px;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 1px 2px rgba(44, 38, 64, .25);
    transition: transform .15s ease;
}

.sf-form .sf-switch-input:checked {
    background: var(--sf-accent);
}

.sf-form .sf-switch-input:checked::before {
    transform: translateX(16px);
}

.sf-form .sf-switch-input:focus-visible {
    outline: 0;
    box-shadow: var(--sf-ring);
}

.sf-form .sf-switch-label {
    display: block;
    margin: 0;
    font-size: 14px;
    font-weight: 600;
    line-height: 1.5;
    letter-spacing: 0;
    text-transform: none;
    color: var(--sf-ink);
    cursor: pointer;
}

.sf-form .sf-switch .sf-help {
    max-width: 60ch;
    margin-top: 2px;
}

/* Footer: what happens next, and the action */

.sf-form .sf-footer {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 14px 24px;
    padding-top: 20px;
    border-top: 1px solid var(--sf-line);
}

.sf-form .sf-footer-note {
    display: flex;
    align-items: flex-start;
    flex: 1 1 320px;
    gap: 8px;
    margin: 0;
    font-size: 13px;
    line-height: 1.55;
    color: var(--sf-muted);
}

.sf-form .sf-footer-note i {
    flex: none;
    margin-top: 2px;
    font-size: 14px;
    color: var(--sf-accent-ink);
}

.sf-form .sf-button {
    margin-left: auto;
    padding: 10px 22px;
    font-size: 14px;
    font-weight: 600;
    line-height: 1.5;
    letter-spacing: 0;
    text-transform: none;
    border-radius: var(--sf-radius);
}

.sf-form .sf-button:focus-visible {
    box-shadow: var(--sf-ring);
}

/* Secondary actions: a quiet button, and one for actions that undo something */
.sf-form .sf-button--quiet {
    margin-left: 0;
    padding: 9px 16px;
    color: var(--sf-ink);
    background: var(--sf-surface);
    border: 1px solid var(--sf-field-line);
}

.sf-form .sf-button--quiet:hover,
.sf-form .sf-button--quiet:focus {
    color: var(--sf-ink);
    background: var(--sf-surface-sunk);
    border-color: var(--sf-field-hover);
}

.sf-form .sf-button--danger {
    color: #b42318;
    border-color: #efc7c3;
}

.sf-form .sf-button--danger:hover,
.sf-form .sf-button--danger:focus {
    color: #912018;
    background: #fff5f4;
    border-color: #e4a29b;
}

.sf-form .sf-button--quiet i {
    margin-right: 6px;
}

@media (max-width: 575.98px) {
    .sf-form .sf-footer .sf-button {
        width: 100%;
    }
}

/*
 * Tables: the records a form made, one per row between hairlines, in the forms' type and colours.
 * Below 768px each row becomes a block, and each cell shows its column's name from data-label.
 *
 *   <div class="sf-table-wrap">
 *     <table class="sf-table">
 *       <thead><tr><th scope="col">Name</th> … <th scope="col"><span class="sr-only">Actions</span></th></tr></thead>
 *       <tbody>
 *         <tr>                                    (add .sf-table-row--off for a record that no longer works)
 *           <td><span class="sf-cell-title">The record</span><span class="sf-cell-sub">A quieter line</span></td>
 *           <td data-label="Status"><span class="sf-status" data-status="ok">Works</span></td>
 *           <td class="sf-cell-action"><button class="sf-table-button sf-table-button--danger">Revoke</button></td>
 *         </tr>
 *
 * The first cell names the record and needs no data-label; .sf-status takes data-status ok, warn or off;
 * .sf-mono is for keys, IPs and other values typed as code; .sf-quiet for "Never" and other blanks.
 */

.sf-table-wrap {
    overflow-x: auto;
}

.sf-table {
    width: 100%;
    margin: 0;
    font-size: 14px;
    line-height: 1.5;
    font-variant-numeric: tabular-nums;
    color: var(--sf-ink);
    border-collapse: collapse;
}

.sf-table th,
.sf-table td {
    padding: 14px 14px;
    text-align: left;
    vertical-align: top;
    border: 0;
    border-top: 1px solid var(--sf-line);
}

.sf-table th:first-child,
.sf-table td:first-child {
    padding-left: 0;
}

.sf-table th:last-child,
.sf-table td:last-child {
    padding-right: 0;
}

.sf-table thead th {
    padding-top: 0;
    padding-bottom: 10px;
    font-size: 12.5px;
    font-weight: 600;
    letter-spacing: 0;
    text-transform: none;
    white-space: nowrap;
    color: var(--sf-muted);
    background: none;
    border-top: 0;
    border-bottom: 1px solid var(--sf-line);
}

.sf-table .sf-cell-title {
    display: block;
    max-width: 28ch;
    font-weight: 600;
    color: var(--sf-ink);
    overflow-wrap: anywhere;
}

.sf-table .sf-cell-sub {
    display: block;
    margin-top: 2px;
    font-size: 12.5px;
    line-height: 1.5;
    color: var(--sf-muted);
}

.sf-table .sf-mono {
    padding: 0;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
    font-size: 12.5px;
    color: var(--sf-muted);
    background: none;
    border-radius: 0;
}

.sf-table .sf-quiet {
    color: var(--sf-muted);
}

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

/* What a record may do: the reach bars, then the words */
.sf-table .sf-cell-reach {
    display: flex;
    align-items: baseline;
    gap: 9px;
    min-width: 11rem;
}

.sf-table .sf-cell-reach .sf-reach {
    flex: none;
    margin: 0;
    transform: translateY(2px);
}

/* Status: a dot and a word; the word says it, the dot is for scanning down the column */
.sf-table .sf-status {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    font-weight: 500;
    white-space: nowrap;
}

.sf-table .sf-status::before {
    content: "";
    flex: none;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--sf-track);
}

.sf-table .sf-status[data-status="ok"]::before {
    background: var(--sf-positive);
}

.sf-table .sf-status[data-status="warn"]::before {
    background: var(--sf-caution);
}

.sf-table .sf-status[data-status="off"] {
    color: var(--sf-muted);
}

.sf-table .sf-status[data-status="off"]::before {
    background: transparent;
    box-shadow: inset 0 0 0 1.5px var(--sf-field-hover);
}

/* A record that no longer works: still listed, in grey */
.sf-table .sf-table-row--off td,
.sf-table .sf-table-row--off .sf-cell-title {
    color: var(--sf-muted);
}

.sf-table .sf-table-row--off .sf-reach {
    opacity: .5;
    filter: grayscale(1);
}

.sf-table .sf-cell-action {
    text-align: right;
    white-space: nowrap;
}

.sf-table form {
    margin: 0;
}

/* Level with the first line of text in the other cells */
.sf-table .sf-table-button {
    margin: -5px 0;
    padding: 5px 12px;
    font-family: inherit;
    font-size: 13px;
    font-weight: 600;
    line-height: 1.5;
    color: var(--sf-ink);
    background: var(--sf-surface);
    border: 1px solid var(--sf-field-line);
    border-radius: 7px;
    cursor: pointer;
    transition: color .15s ease, background-color .15s ease, border-color .15s ease, box-shadow .15s ease;
}

.sf-table .sf-table-button:hover {
    background: var(--sf-surface-sunk);
    border-color: var(--sf-field-hover);
}

.sf-table .sf-table-button:focus {
    outline: 0;
}

.sf-table .sf-table-button:focus-visible {
    box-shadow: var(--sf-ring);
}

.sf-table .sf-table-button--danger {
    color: #b42318;
    border-color: #efc7c3;
}

.sf-table .sf-table-button--danger:hover {
    color: #912018;
    background: #fff5f4;
    border-color: #e4a29b;
}

@media (max-width: 767.98px) {
    .sf-table-wrap {
        overflow: visible;
    }

    .sf-table,
    .sf-table tbody,
    .sf-table tr,
    .sf-table td {
        display: block;
        width: 100%;
    }

    /* The column names move into each cell; the header stays for screen readers */
    .sf-table thead {
        position: absolute;
        width: 1px;
        height: 1px;
        overflow: hidden;
        clip: rect(0 0 0 0);
        white-space: nowrap;
    }

    .sf-table tr {
        padding: 16px 0;
        border-top: 1px solid var(--sf-line);
    }

    .sf-table tbody tr:first-child {
        padding-top: 0;
        border-top: 0;
    }

    .sf-table td,
    .sf-table td:first-child,
    .sf-table td:last-child {
        position: relative;
        padding: 3px 0 3px calc(6.5rem + 12px);
        border: 0;
    }

    .sf-table td[data-label]::before {
        content: attr(data-label);
        position: absolute;
        top: 3px;
        left: 0;
        width: 6.5rem;
        font-size: 12.5px;
        font-weight: 600;
        line-height: 21px;
        color: var(--sf-muted);
    }

    .sf-table td:not([data-label]) {
        padding-left: 0;
    }

    .sf-table td:first-child {
        padding-bottom: 10px;
    }

    .sf-table .sf-cell-title {
        max-width: none;
    }

    .sf-table td.sf-cell-action {
        padding-top: 12px;
        text-align: left;
    }

    .sf-table .sf-table-button {
        margin: 0;
    }
}

@media (prefers-reduced-motion: reduce) {
    .sf-form *,
    .sf-form *::before,
    .sf-form *::after,
    .sf-table *,
    .sf-table *::before,
    .sf-table *::after {
        transition: none !important;
    }
}
