/* FBS shared workspace styles. Loaded before each page-specific stylesheet. */

/* 01 Foundations */
:root {
    color-scheme: light;
    --ink: #17211d;
    --muted: #66726c;
    --line: #dce5df;
    --surface: rgba(255, 255, 255, .88);
    --accent: #367c5d;
    --accent-deep: #23563f;
    --accent-pale: #e7f3ec;
    --danger: #a33a3a;
    --danger-pale: #fff0ef;
    --page-gutter: clamp(.75rem, 2vw, 2rem);
}

html,
body {
    width: 100%;
    height: 100%;
    max-width: 100%;
    overflow: hidden;
}

#app-main {
    width: 100%;
    height: 100%;
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.fbs-shell {
    max-width: 100%;
    overflow-x: hidden;
}

body {
    background:
        radial-gradient(circle at 15% 10%, rgba(111, 181, 145, .18), transparent 30rem),
        linear-gradient(145deg, #f7faf8, #eef4f0);
    color: var(--ink);
}

/* 02 Workspace chrome: shell, fixed header and action bar */
.fbs-shell {
    width: 100%;
    min-height: calc(100vh - 10rem);
    display: grid;
    align-content: center;
    gap: 1.5rem;
    padding-inline: var(--page-gutter);
}

.fbs-shell > * {
    min-width: 0;
}

.auth-card,
.metric-card,
.system-panel,
.source-panel,
.source-list-panel {
    border: 1px solid rgba(54, 124, 93, .13);
    border-radius: 1.25rem;
    background: var(--surface);
    box-shadow: 0 1.5rem 4rem rgba(28, 57, 43, .09);
    backdrop-filter: blur(1rem);
}

.fbs-shell.is-dashboard {
    align-content: start;
    padding-top: 4.4rem;
    padding-bottom: 5rem;
}

.fbs-shell.screen-dashboard {
    padding-bottom: 5rem;
}

.fbs-shell.screen-developer {
    padding-bottom: 2rem;
}

.screen-dashboard > .source-list-panel {
    order: -1;
}

.screen-dashboard > .registered-source-list {
    order: -2;
}

.screen-dashboard[data-dashboard-view="compact"] [data-management-only] {
    display: none;
}

.screen-dashboard[data-dashboard-view="compact"] #client-connections {
    display: block;
    height: 0;
    overflow: visible;
    border: 0;
    background: none;
    padding: 0;
    box-shadow: none;
}

.screen-dashboard[data-dashboard-view="compact"] > .registered-source-list {
    width: 100%;
}

.workspace-header,
.workspace-action-bar {
    position: fixed;
    z-index: 20;
    left: 0;
    width: 100%;
    border-color: rgba(54, 124, 93, .18);
    background: rgba(250, 252, 251, .94);
    box-shadow: 0 .4rem 1.5rem rgba(28, 57, 43, .08);
    backdrop-filter: blur(.8rem);
}

.workspace-header {
    top: 0;
    min-height: 3.5rem;
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto auto auto auto;
    align-items: center;
    gap: .7rem;
    border-bottom: 1px solid rgba(54, 124, 93, .18);
    padding: .45rem var(--page-gutter);
}

.workspace-brand {
    display: grid;
    width: 2.25rem;
    height: 2.25rem;
    place-items: center;
    border-radius: .65rem;
    background: var(--accent-pale);
    text-decoration: none;
}

.workspace-brand img {
    width: 1.75rem;
    height: 1.75rem;
    object-fit: contain;
}

.workspace-context {
    min-width: 0;
    display: flex;
    align-items: baseline;
    gap: .55rem;
}

.workspace-context strong,
.workspace-context span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.workspace-context span,
.workspace-save-state,
.workspace-sync-state {
    color: var(--muted);
    font-size: .75rem;
}

.workspace-save-state {
    max-width: 14rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.workspace-sync-state {
    color: var(--muted);
    font-size: .72rem;
    white-space: nowrap;
}

.workspace-sync-state.is-warning { color: #8a5a00; }
.workspace-sync-state.is-error { color: var(--danger); }

.sync-conflict-actions { display: flex; flex-wrap: wrap; gap: .55rem; }
.sync-conflict-actions form { margin: 0; }

.workspace-header form {
    margin: 0;
}

.workspace-screen-nav {
    display: flex;
    align-items: center;
    gap: .25rem;
}

.workspace-screen-nav a {
    border-radius: .5rem;
    padding: .35rem .5rem;
    color: var(--muted);
    font-size: .72rem;
    font-weight: 750;
    text-decoration: none;
    white-space: nowrap;
}

.workspace-screen-nav a[aria-current="page"] {
    background: var(--accent-pale);
    color: var(--accent-deep);
}

.workspace-header button,
.workspace-action-bar button {
    min-height: 2.15rem;
    padding: .35rem .65rem;
    font-size: .75rem;
}

.workspace-action-bar {
    bottom: 0;
    display: flex;
    justify-content: center;
    gap: .45rem;
    border-top: 1px solid rgba(54, 124, 93, .18);
    padding: .55rem var(--page-gutter) max(.55rem, env(safe-area-inset-bottom));
}

.workspace-action-bar form {
    display: contents;
}

.workspace-action-group {
    position: relative;
    display: flex;
    align-items: center;
    gap: .3rem;
    border-left: 1px solid var(--line);
    padding: .8rem .65rem 0;
}

.workspace-action-group:first-child {
    border-left: 0;
}

.workspace-action-group-label {
    position: absolute;
    top: -.05rem;
    left: .65rem;
    color: var(--muted);
    font-size: .62rem;
    font-weight: 800;
    letter-spacing: .04em;
}

.workspace-action-bar .auto-save-toggle.is-active {
    border-color: var(--accent);
    background: var(--accent);
    color: white;
}

.dashboard-status-item {
    border-radius: .5rem;
    background: var(--accent-pale);
    padding: .35rem .55rem;
    color: var(--accent-deep);
    font-size: .72rem;
    white-space: nowrap;
}

.dashboard-status-item strong {
    font-size: .82rem;
}

.dashboard-status-item.is-warning {
    background: #fff4dc;
    color: #8a5a00;
}

/* 07 Dialogs and option editor */
.app-dialog {
    width: min(32rem, calc(100% - 2rem));
    max-width: none;
    max-height: calc(100dvh - 2rem);
    overflow-x: hidden;
    overflow-y: auto;
    border: 0;
    border-radius: 1.1rem;
    background: transparent;
    padding: 0;
    color: var(--ink);
    box-shadow: 0 2rem 6rem rgba(23, 33, 29, .28);
}

.app-dialog::backdrop {
    background: rgba(23, 33, 29, .52);
    backdrop-filter: blur(.2rem);
}

.app-dialog-card {
    width: 100%;
    min-width: 0;
    display: grid;
    gap: 1.2rem;
    border: 1px solid rgba(54, 124, 93, .18);
    border-radius: 1.1rem;
    background: #fff;
    padding: clamp(1.25rem, 4vw, 2rem);
}

.app-dialog-heading {
    display: grid;
    gap: .35rem;
}

.app-dialog-heading h2,
.app-dialog-heading p,
.app-dialog-message {
    margin: 0;
}

.app-dialog-message {
    color: var(--muted);
    line-height: 1.75;
}

.app-dialog-actions {
    display: flex;
    justify-content: flex-end;
    gap: .6rem;
}

.dataset-dialog-form {
    display: grid;
    gap: .7rem;
}

.dataset-dialog-form label {
    display: grid;
    gap: .3rem;
    color: var(--muted);
    font-size: .78rem;
    font-weight: 750;
}

.dataset-dialog-form input,
.dataset-dialog-form select {
    width: 100%;
    min-width: 0;
    min-height: 2.4rem;
    border: 1px solid var(--line);
    border-radius: .55rem;
    padding: .4rem .55rem;
    font: inherit;
}

.form-toggle-setting {
    display: grid;
    justify-items: start;
    gap: .4rem;
    color: var(--muted);
    font-size: .78rem;
    font-weight: 750;
}

.toggle-control {
    display: inline-flex;
    align-items: center;
    gap: .45rem;
    cursor: pointer;
}

.toggle-control input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.toggle-control > span {
    width: 2.7rem;
    height: 1.5rem;
    position: relative;
    border-radius: 999px;
    background: #c8d1cc;
    transition: background .15s ease;
}

.toggle-control > span::after {
    content: '';
    width: 1.1rem;
    height: 1.1rem;
    position: absolute;
    top: .2rem;
    left: .2rem;
    border-radius: 50%;
    background: white;
    box-shadow: 0 .1rem .25rem rgba(23, 33, 29, .25);
    transition: transform .15s ease;
}

.toggle-control input:checked + span {
    background: var(--accent);
}

.toggle-control input:checked + span::after {
    transform: translateX(1.2rem);
}

.toggle-control input:focus-visible + span {
    outline: .2rem solid rgba(54, 124, 93, .18);
}

.form-toggle-setting .toggle-control {
    display: inline-flex;
}

.form-toggle-setting .toggle-state-label {
    width: auto;
    height: auto;
    position: static;
    background: transparent;
    color: var(--ink);
    font-size: .76rem;
}

.form-toggle-setting .toggle-state-label::after {
    content: none;
}

.option-dialog {
    width: min(46rem, calc(100% - 2rem));
}

.option-dialog-help {
    color: var(--muted);
    font-size: .78rem;
}

.option-editor-list {
    display: grid;
    gap: .35rem;
}

.option-editor-row {
    display: grid;
    grid-template-columns: 8rem minmax(8rem, 1fr) auto auto;
    align-items: center;
    gap: .35rem;
}

.option-editor-row input {
    width: 100%;
    min-width: 0;
    min-height: 2.35rem;
    border: 1px solid var(--line);
    border-radius: .5rem;
    padding: .4rem .55rem;
    font: inherit;
}

.option-editor-row .option-key-input[hidden] {
    display: none;
}

.option-editor-row:has(.option-key-input[hidden]) {
    grid-template-columns: minmax(8rem, 1fr) auto auto;
}

.option-usage {
    border-radius: 999px;
    background: #fff1cf;
    padding: .25rem .45rem;
    color: #7b5600;
    font-size: .68rem;
    font-weight: 800;
    white-space: nowrap;
}

.option-row-actions {
    display: flex;
    gap: .25rem;
}

.option-row-actions button {
    min-height: 2.35rem;
    padding: .35rem .5rem;
    white-space: nowrap;
}

.option-dialog-error {
    margin: 0;
    color: #a72f2f;
    font-size: .78rem;
    font-weight: 750;
}

.option-retain-confirm {
    display: flex;
    align-items: flex-start;
    gap: .45rem;
    border: 1px solid #e3bd61;
    border-radius: .65rem;
    background: #fff8e7;
    padding: .65rem .75rem;
    color: #704e00;
    font-size: .76rem;
    font-weight: 750;
}

.option-retain-confirm[hidden] {
    display: none;
}

.option-migrations {
    display: grid;
    gap: .4rem;
    border: 1px solid #e3bd61;
    border-radius: .65rem;
    background: #fff8e7;
    padding: .7rem .75rem;
    color: #704e00;
    font-size: .76rem;
}

.option-migrations[hidden] {
    display: none;
}

.option-migration-row {
    display: grid;
    grid-template-columns: minmax(8rem, 1fr) minmax(11rem, 1.4fr);
    align-items: center;
    gap: .5rem;
}

.option-migration-row select {
    width: 100%;
    min-width: 0;
    min-height: 2.25rem;
    border: 1px solid var(--line);
    border-radius: .45rem;
    background: white;
    padding: .3rem .4rem;
    font: inherit;
}

.option-dialog-spacer {
    flex: 1;
}

@media (max-width: 620px) {
    .option-editor-row,
    .option-editor-row:has(.option-key-input[hidden]) {
        grid-template-columns: 1fr;
    }

    .option-row-actions {
        justify-content: flex-end;
    }

    .option-dialog .app-dialog-actions {
        flex-wrap: wrap;
    }

    .option-migration-row {
        grid-template-columns: 1fr;
    }
}

body.has-open-dialog {
    overflow: hidden;
}

.data-table .empty-cell {
    color: var(--muted);
    text-align: center;
}

.block-form,
.row-form {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(10rem, 1fr));
    align-items: end;
    gap: .7rem;
}

.block-form label,
.row-form label,
.row-field {
    display: grid;
    gap: .35rem;
    color: var(--muted);
    font-size: .75rem;
    font-weight: 700;
}

.block-form input,
.row-form input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]),
.row-form select,
.row-form textarea {
    width: 100%;
    min-height: 2.7rem;
    border: 1px solid var(--line);
    border-radius: .65rem;
    padding: .6rem .75rem;
    font: inherit;
}

.row-form textarea {
    min-height: 5.5rem;
    resize: vertical;
}

.row-field > span:first-child {
    color: var(--muted);
    font-size: .75rem;
    font-weight: 700;
}

/* 08 Authentication */
.auth-card {
    width: min(31rem, 100%);
    display: grid;
    gap: 1rem;
    padding: clamp(1.5rem, 4vw, 3rem);
    margin-inline: auto;
}

.brand-mark {
    width: 3rem;
    aspect-ratio: 1;
    display: grid;
    place-items: center;
    border-radius: .9rem;
    background: var(--accent-pale);
}

.brand-mark img {
    width: 2.35rem;
    height: 2.35rem;
    object-fit: contain;
}

.eyebrow {
    color: var(--accent);
    font-size: .72rem;
    font-weight: 800;
    letter-spacing: .16em;
}

.auth-card h1,
.dashboard-header h1,
.system-panel h2,
.source-panel h2,
.source-list-panel h2 {
    margin: 0;
    line-height: 1.12;
}

.lead,
.key-hint {
    color: var(--muted);
    line-height: 1.75;
}

.auth-form {
    display: grid;
    gap: .75rem;
}

.auth-form label {
    font-size: .82rem;
    font-weight: 700;
}

.auth-form input {
    width: 100%;
    min-height: 3.1rem;
    border: 1px solid var(--line);
    border-radius: .75rem;
    background: white;
    padding: .7rem .9rem;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 1rem;
    letter-spacing: .08em;
}

/* 10 Shared controls, generated keys, messages and toast */
.auth-form input:focus {
    border-color: var(--accent);
    outline: .2rem solid rgba(54, 124, 93, .13);
}

.key-control {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: .6rem;
}

.generated-key {
    display: grid;
    gap: .55rem;
    border: 1px solid rgba(54, 124, 93, .25);
    border-radius: .8rem;
    background: var(--accent-pale);
    padding: .85rem;
}

.generated-key[hidden] {
    display: none;
}

.generated-key > span {
    font-size: .78rem;
    font-weight: 750;
}

.generated-key-control {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: .6rem;
}

.generated-key output {
    min-width: 0;
    overflow-wrap: anywhere;
    border-radius: .55rem;
    background: white;
    padding: .75rem;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: .92rem;
    letter-spacing: .06em;
    user-select: all;
}

.generated-key small {
    color: var(--accent-deep);
    line-height: 1.5;
}

.primary-button,
.secondary-button,
.danger-button {
    white-space: nowrap;
}

.primary-button,
.secondary-button {
    min-height: 2.8rem;
    border: 0;
    border-radius: .72rem;
    padding: .65rem 1rem;
    font: inherit;
    font-weight: 750;
    cursor: pointer;
}

.primary-button {
    background: var(--accent);
    color: white;
}

.primary-button:hover {
    background: var(--accent-deep);
}

.secondary-button {
    border: 1px solid var(--line);
    background: white;
    color: var(--ink);
}

.form-message {
    border-radius: .7rem;
    padding: .8rem 1rem;
    line-height: 1.5;
}

.form-message.is-error {
    background: var(--danger-pale);
    color: var(--danger);
}

.form-message.is-success {
    background: var(--accent-pale);
    color: var(--accent-deep);
}

.app-toast-stack {
    position: fixed;
    z-index: 1200;
    top: calc(4.5rem + env(safe-area-inset-top));
    right: max(1rem, env(safe-area-inset-right));
    display: grid;
    width: min(28rem, calc(100vw - 2rem));
    gap: .55rem;
    pointer-events: none;
}

.app-toast-stack:empty {
    display: none;
}

.app-toast-stack .form-message {
    margin: 0;
    border: 1px solid color-mix(in srgb, currentColor 18%, transparent);
    box-shadow: 0 .8rem 2rem rgb(25 44 37 / 18%);
    pointer-events: auto;
    cursor: pointer;
}

.app-toast-stack .form-message.is-hiding {
    opacity: 0;
    transform: translateY(-.4rem);
    transition: opacity .18s ease, transform .18s ease;
}

/* 12 Responsive overrides */
@media (max-width: 680px) {
    .record-add-trigger td {
        text-align: left;
    }

    .panel-heading-actions {
        align-items: flex-start;
    }

    .workspace-action-group {
        flex: 0 0 auto;
    }

    .dashboard-status-group {
        display: flex;
        flex: 0 0 auto;
    }

    .fbs-shell {
        --page-gutter: .6rem;
        gap: 1rem;
    }

    .editor-panel,
    .source-panel,
    .source-list-panel,
    .system-panel {
        border-radius: .85rem;
        padding: 1rem;
    }

    .dashboard-header,
    .editor-heading,
    .system-panel,
    .source-workspace {
        display: grid;
        grid-template-columns: 1fr;
    }

    .metric-grid {
        grid-template-columns: 1fr;
    }

    .lab-grid { grid-template-columns: 1fr; }
    .lab-intro { align-items: flex-start; flex-direction: column; }
    .lab-experiments > div { align-items: flex-start; flex-direction: column; }
    .lab-experiments button { margin-left: 0; }

    .source-row {
        align-items: flex-start;
        flex-direction: column;
    }

    .registered-source-list[data-source-list-view="compact"] .source-primary {
        gap: .35rem;
    }

    .source-file-context {
        max-width: 100%;
    }

    .source-file-context code {
        min-width: 0;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .source-datasets {
        width: 100%;
        max-width: 100%;
    }

    .source-datasets a {
        box-sizing: border-box;
        flex: 0 0 auto;
        justify-content: flex-start;
        min-width: 0;
        max-width: min(16rem, calc(100vw - 3.2rem));
        overflow: hidden;
    }

    .source-datasets a span {
        display: block;
        min-width: 0;
        max-width: 100%;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .source-meta {
        justify-content: flex-start;
    }

    .field-form {
        width: 100%;
    }

    .fbs-shell.is-dashboard {
        padding-top: 4rem;
        padding-bottom: 4.7rem;
    }

    .workspace-header {
        grid-template-columns: auto minmax(0, 1fr) auto auto;
        gap: .45rem;
    }

    .workspace-context {
        display: grid;
        gap: 0;
    }

    .workspace-save-state,
    .workspace-sync-state {
        display: none;
    }

    .workspace-screen-nav a {
        padding-inline: .35rem;
        font-size: .68rem;
    }

    .workspace-header button,
    .workspace-action-bar button {
        padding-inline: .5rem;
        font-size: .7rem;
    }

    .workspace-action-bar {
        justify-content: stretch;
        overflow-x: auto;
    }

    .workspace-save-notice {
        bottom: 4.4rem;
    }

    .workspace-action-bar button {
        flex: 1 0 auto;
    }
}

@media (min-width: 681px) {
    .source-datasets a,
    .registered-source-list[data-source-list-view="compact"] .source-datasets a {
        font-size: clamp(.84rem, calc(.78rem + .12vw), .96rem);
    }
}

/* 13 Local icon font */
@font-face {
    font-family: "Material Symbols Outlined";
    font-style: normal;
    font-weight: 400;
    font-display: block;
    src: url("../../assets/fonts/material-symbols-add-row-above.ttf") format("truetype");
}

.material-symbols-outlined {
    display: inline-block;
    font-family: "Material Symbols Outlined";
    font-size: 1.15rem;
    font-style: normal;
    font-weight: normal;
    line-height: 1;
    letter-spacing: normal;
    text-transform: none;
    white-space: nowrap;
    direction: ltr;
}
