:root {
    --bg: #f5f7fb;
    --surface: #ffffff;
    --line: #d9e1ee;
    --ink: #18211f;
    --muted: #64706b;
    --brand: #0033A0;
    --brand-2: #0B5CAD;
    --danger: #b42318;
    --soft: #eef4ff;
}

html,
body {
    min-height: 100%;
    background: var(--bg);
    color: var(--ink);
    font-family: Inter, "Segoe UI", Arial, sans-serif;
}

a {
    color: var(--brand);
}

.app-shell {
    min-height: 100vh;
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    min-height: 64px;
    display: flex;
    align-items: center;
    gap: 24px;
    padding: 10px 24px;
    background: rgba(255, 255, 255, .96);
    border-bottom: 1px solid var(--line);
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    color: var(--ink);
    font-weight: 700;
    text-decoration: none;
    white-space: nowrap;
}

.brand-logo {
    display: block;
    width: auto;
    height: 46px;
    max-width: 118px;
    object-fit: contain;
}

.login-logo {
    height: 58px;
    max-width: 140px;
}

.main-nav {
    display: flex;
    align-items: center;
    gap: 6px;
}

.main-nav a,
.user-block,
.topbar-note {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-height: 38px;
    padding: 7px 10px;
    border-radius: 6px;
    color: var(--muted);
    text-decoration: none;
    font-size: .94rem;
}

.main-nav a.active {
    background: var(--soft);
    color: var(--brand);
    font-weight: 700;
}

.user-block {
    margin-left: auto;
    color: var(--ink);
}

.app-content {
    padding: 24px;
}

.page-heading {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 18px;
}

.page-heading h1 {
    margin: 0;
    font-size: 1.65rem;
    line-height: 1.2;
}

.page-heading p,
.login-heading p {
    margin: 4px 0 0;
    color: var(--muted);
}

.workspace-grid {
    display: grid;
    grid-template-columns: minmax(280px, 36%) minmax(0, 1fr);
    gap: 18px;
    align-items: start;
}

.maintenance-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 18px;
}

.panel,
.login-panel {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(24, 33, 31, .05);
}

.panel {
    padding: 16px;
}

.panel-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 14px;
}

.panel-title h2 {
    margin: 0;
    font-size: 1.08rem;
}

.panel-title span {
    color: var(--muted);
    font-size: .9rem;
}

.toolbar {
    display: flex;
    gap: 8px;
    margin-bottom: 12px;
}

.btn {
    border-radius: 6px;
}

.btn-cle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    background: var(--brand);
    border-color: var(--brand);
    color: #fff;
    font-weight: 700;
}

.btn-cle:hover,
.btn-cle:focus {
    background: #002776;
    border-color: #002776;
    color: #fff;
}

.btn-outline-cle {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    border-color: var(--brand);
    color: var(--brand);
    font-weight: 700;
}

.btn-outline-cle:hover {
    background: var(--brand);
    color: #fff;
}

.icon-button {
    display: inline-grid;
    place-items: center;
    flex: 0 0 auto;
    width: 38px;
    height: 38px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: #fff;
    color: var(--brand);
}

.icon-button:hover {
    background: var(--soft);
}

.icon-button.danger {
    color: var(--danger);
}

.form-control,
.form-select,
.input-group-text {
    border-color: var(--line);
    border-radius: 6px;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
}

.form-grid.compact {
    grid-template-columns: repeat(4, minmax(0, 1fr));
}

.span-2 {
    grid-column: span 2;
}

.switch-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
    margin: 14px 0;
}

.switch-grid label {
    display: flex;
    align-items: center;
    gap: 8px;
    min-height: 38px;
    padding: 8px 10px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: #fbfcfa;
}

.compact-switches {
    grid-template-columns: minmax(0, 1fr);
}

.actions-row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 12px;
}

.product-list {
    display: grid;
    gap: 8px;
}

.product-row,
.result-row {
    width: 100%;
    display: grid;
    grid-template-columns: 72px minmax(0, 1fr) auto;
    gap: 10px;
    align-items: center;
    padding: 8px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    color: var(--ink);
    text-align: left;
}

.product-row.active,
.result-row.active {
    border-color: var(--brand);
    background: #eef4ff;
}

.thumb {
    width: 72px;
    aspect-ratio: 4 / 3;
    display: grid;
    place-items: center;
    overflow: hidden;
    border-radius: 6px;
    background: var(--soft);
    color: var(--muted);
}

.thumb img,
.component-photo img,
.uploaded-preview img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.product-row-body {
    min-width: 0;
    display: grid;
    gap: 2px;
}

.product-row-body strong,
.product-row-body span,
.product-row-body small {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.product-row-body span,
.product-row-body small {
    color: var(--muted);
}

.status-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
}

.status-dot.on {
    background: #257a4a;
}

.status-dot.off {
    background: #a8b0aa;
}

.components-panel {
    margin-top: 18px;
}

.component-editor {
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fbfcfa;
    margin-bottom: 16px;
}

.uploaded-preview {
    display: grid;
    grid-template-columns: 96px minmax(0, 1fr);
    gap: 8px;
    align-items: center;
    margin-top: 8px;
}

.uploaded-preview img {
    width: 96px;
    aspect-ratio: 4 / 3;
    border-radius: 6px;
}

.component-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 12px;
}

.component-item {
    display: grid;
    grid-template-columns: 96px minmax(0, 1fr) auto;
    gap: 10px;
    align-items: center;
    padding: 8px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
}

.component-photo {
    width: 96px;
    aspect-ratio: 4 / 3;
    display: grid;
    place-items: center;
    overflow: hidden;
    border: 0;
    border-radius: 6px;
    background: var(--soft);
    color: var(--muted);
}

.component-body {
    min-width: 0;
    display: grid;
    gap: 2px;
}

.component-body span,
.component-body small {
    color: var(--muted);
    font-size: .86rem;
}

.component-actions {
    display: grid;
    gap: 6px;
}

.empty-state {
    min-height: 120px;
    display: grid;
    place-items: center;
    color: var(--muted);
    border: 1px dashed var(--line);
    border-radius: 8px;
    background: #fbfcfa;
    text-align: center;
}

.empty-state.compact {
    min-height: 64px;
}

.box-maintenance {
    grid-column: 1 / -1;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fbfcfa;
}

.table-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 10px;
}

.table-heading h3 {
    margin: 0;
    font-size: 1rem;
}

.maintenance-table {
    margin-bottom: 0;
}

.maintenance-table td:first-child {
    display: grid;
    gap: 2px;
}

.maintenance-table small {
    color: var(--muted);
}

.modal-title {
    font-size: 1.15rem;
}

.login-wrap {
    min-height: calc(100vh - 112px);
    display: grid;
    place-items: center;
}

.login-panel {
    width: min(420px, 100%);
    padding: 24px;
}

.login-heading {
    display: flex;
    gap: 12px;
    align-items: center;
    margin-bottom: 20px;
}

.login-heading h1 {
    margin: 0;
    font-size: 1.4rem;
}

.setup-footer {
    margin-top: 14px;
    text-align: center;
}

.stack-form {
    display: grid;
    gap: 8px;
}

.inline-fields {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.maintenance-list {
    display: grid;
    gap: 8px;
    margin-top: 14px;
}

.maintenance-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 8px;
    align-items: center;
}

.maintenance-row > button:first-child {
    min-height: 38px;
    padding: 7px 10px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: #fff;
    color: var(--ink);
    text-align: left;
}

#blazor-error-ui {
    display: none;
}

@media (max-width: 1050px) {
    .workspace-grid,
    .maintenance-grid {
        grid-template-columns: 1fr;
    }

    .form-grid.compact {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 720px) {
    .topbar {
        align-items: flex-start;
        flex-direction: column;
        gap: 10px;
        padding: 12px 16px;
    }

    .main-nav {
        width: 100%;
        flex-wrap: wrap;
    }

    .user-block {
        margin-left: 0;
        width: 100%;
        justify-content: space-between;
    }

    .app-content {
        padding: 16px;
    }

    .page-heading {
        flex-direction: column;
    }

    .form-grid,
    .form-grid.compact,
    .switch-grid {
        grid-template-columns: 1fr;
    }

    .span-2 {
        grid-column: span 1;
    }

    .product-row {
        grid-template-columns: 64px minmax(0, 1fr) auto;
    }

    .thumb {
        width: 64px;
    }

    .component-item {
        grid-template-columns: 88px minmax(0, 1fr);
    }

    .component-actions {
        grid-column: 1 / -1;
        display: flex;
    }
}
